Skip to content

Commit

Permalink
Release 0.0.5 (#60)
Browse files Browse the repository at this point in the history
* Updated dependencies for vulnerabilities fixes

* Make env.sh compatible with zsh

* library updates

* Fix README.md typos

* Add react router
* Components breakup after root router added

* Fix empty transactions channel helper text

* Add tests

* Fixed warning and cleanup

* Adding local env.sh and indentation fixes

* Replace listpeers.channels with listpeerchannels

* Updated request to wait till node version available before fetching channels

* Updated types and actions for listChannels

* Updating store to aggregate channels from old listpeers.peers array

* Updated UI components for listChannel's latest field names

* Adjusted tests for listPeerChannels migration

* Updated the mock data and checks with more realistic dataset

* Remove msatoshi_received, msatoshi, msatoshi_sent from Payments and Invoices

* Callback warning fix

* RC Version compatibility check and tests

* Add grpc option on connect wallet modal

---------

Co-authored-by: evansmj <[email protected]>
  • Loading branch information
ShahanaFarooqui and evansmj committed May 20, 2024
1 parent b697973 commit 281f4db
Show file tree
Hide file tree
Showing 109 changed files with 11,425 additions and 6,219 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data/app/application-cln.log
data/app-2/*
application-cln.log
.commando-env
env.sh
.commando
data/app/config.json
release
release
env-local.sh
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Build Stage
FROM node:18-buster AS cln-app-builder

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev

# Create app directory
WORKDIR /app

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
```

- ### Environment Variables
This application accepts & depeneds upon these variables to be passed through environment:
This application accepts & depends upon these variables to be passed through environment:

```
- APP_CORE_LIGHTNING_IP: IP address of this application (cln-application) container (required)
Expand All @@ -52,7 +52,6 @@
- COMMANDO_CONFIG: Full Path including file name for commando auth with PUBKEY & RUNE (required)
- APP_BITCOIN_NODE_IP: IP address of bitcoin node container (required)
- APP_CORE_LIGHTNING_BITCOIN_NETWORK: Bitcoin network type (optional; for entrypoint.sh; valid values: bitcoin/signet/testnet/regtest)
- APP_CORE_LIGHTNING_REST_IP: IP address of the c-lightning-REST container (optional; for connect wallet screen)
- APP_CORE_LIGHTNING_REST_PORT: c-lightning-REST server port (optional; for connect wallet screen)
- APP_CORE_LIGHTNING_REST_CERT_DIR: Path for c-lightning-REST certificates (optional; for connect wallet screen)
- APP_CORE_LIGHTNING_DAEMON_GRPC_PORT: Core lightning's GRPC port (optional; future proofing for connect wallet screen)
Expand All @@ -65,7 +64,7 @@
- CORE_LIGHTNING_PATH: Path for core lightning (optional; required for entrypoint.sh)
```

Set these variables either via terminal OR by env.sh script OR by explicity loading varibles from .env files.
Set these variables either via terminal OR by env.sh script OR by explicitly loading variables from .env files.
Important Note: Environment variables take precedence over config.json variables. Like `SINGLE_SIGN_ON` will take higher precedence over
`singleSignOn` from config.json.

Expand Down Expand Up @@ -98,7 +97,7 @@
```

- ### Start The Application
- Setup envirnoment variables either via terminal OR by env.sh script OR by explicity loading varibles from .env files.
- Setup environment variables either via terminal OR by env.sh script OR by explicitly loading variables from .env files.
- Run `start` script for starting your application's server at port `APP_CORE_LIGHTNING_PORT`

```
Expand Down
44 changes: 4 additions & 40 deletions apps/backend/dist/controllers/lightning.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
import handleError from '../shared/error-handler.js';
import { LNMessage } from '../service/lightning.service.js';
import { logger } from '../shared/logger.js';
import { LightningError } from '../models/errors.js';
import { HttpStatusCode } from '../shared/consts.js';
const lnMessage = LNMessage;
export const getNodesInfo = (lightningPeers) => {
return Promise.all(lightningPeers.peers.map((peer) => {
return new Promise((resolve, reject) => {
lnMessage
.call('listnodes', [peer.id])
.then(data => {
peer.alias = data.nodes[0].alias || peer.id.substring(0, 20);
resolve(peer);
})
.catch(err => {
peer.alias = peer.id.substring(0, 20);
resolve(peer);
});
});
}))
.then(peersWithAliases => {
logger.info('Peers with Aliases: ' + JSON.stringify(peersWithAliases));
return { peers: peersWithAliases };
})
.catch(err => {
logger.error('Controller caught lightning error from list nodes: ' + JSON.stringify(err));
throw new LightningError('Controller caught lightning error from list nodes: ' + JSON.stringify(err), err, HttpStatusCode.LIGHTNING_SERVER, 'Get Network Nodes Information');
});
};
class LightningController {
callMethod(req, res, next) {
try {
Expand All @@ -40,20 +14,10 @@ class LightningController {
': ' +
JSON.stringify(commandRes));
if (req.body.method && req.body.method === 'listpeers') {
try {
// Filter out ln message pubkey from peers list
const lnmPubkey = lnMessage.getLNMsgPubkey();
commandRes.peers = commandRes.peers.filter((peer) => peer.id !== lnmPubkey);
// To get node aliases from liseNodes
getNodesInfo(commandRes).then((resWithAliases) => {
logger.info(resWithAliases);
res.status(200).json(resWithAliases);
});
}
catch (error) {
logger.error('Lightning error from Get Nodes Info : ' + JSON.stringify(error));
return handleError(error, req, res, next);
}
// Filter out ln message pubkey from peers list
const lnmPubkey = lnMessage.getLNMsgPubkey();
commandRes.peers = commandRes.peers.filter((peer) => peer.id !== lnmPubkey);
res.status(200).json(commandRes);
}
else {
res.status(200).json(commandRes);
Expand Down
29 changes: 29 additions & 0 deletions apps/backend/dist/controllers/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { logger } from '../shared/logger.js';
import handleError from '../shared/error-handler.js';
import { APIError } from '../models/errors.js';
import { setSharedApplicationConfig, overrideSettingsWithEnvVariables } from '../shared/utils.js';
import { sep } from 'path';
class SharedController {
getApplicationSettings(req, res, next) {
try {
Expand Down Expand Up @@ -37,7 +38,11 @@ class SharedController {
getWalletConnectSettings(req, res, next) {
try {
logger.info('Getting Connection Settings');
const CERTS_PATH = process.env.CORE_LIGHTNING_PATH + sep + process.env.APP_BITCOIN_NETWORK + sep;
let macaroon = '';
let clientKey = '';
let clientCert = '';
let caCert = '';
let packageData = '{ version: "0.0.4" }';
if (fs.existsSync(APP_CONSTANTS.MACAROON_PATH)) {
logger.info('Getting REST Access Macaroon from ' + process.env.APP_CORE_LIGHTNING_REST_CERT_DIR);
Expand All @@ -46,12 +51,36 @@ class SharedController {
if (fs.existsSync('package.json')) {
packageData = Buffer.from(fs.readFileSync('package.json')).toString();
}
if (fs.existsSync(CERTS_PATH + 'client-key.pem')) {
clientKey = fs.readFileSync(CERTS_PATH + 'client-key.pem').toString();
clientKey = clientKey
.replace(/(\r\n|\n|\r)/gm, '')
.replace('-----BEGIN PRIVATE KEY-----', '')
.replace('-----END PRIVATE KEY-----', '');
}
if (fs.existsSync(CERTS_PATH + 'client.pem')) {
clientCert = fs.readFileSync(CERTS_PATH + 'client.pem').toString();
clientCert = clientCert
.replace(/(\r\n|\n|\r)/gm, '')
.replace('-----BEGIN CERTIFICATE-----', '')
.replace('-----END CERTIFICATE-----', '');
}
if (fs.existsSync(CERTS_PATH + 'ca.pem')) {
caCert = fs.readFileSync(CERTS_PATH + 'ca.pem').toString();
caCert = caCert
.replace(/(\r\n|\n|\r)/gm, '')
.replace('-----BEGIN CERTIFICATE-----', '')
.replace('-----END CERTIFICATE-----', '');
}
const CONNECT_WALLET_SETTINGS = {
LOCAL_HOST: process.env.LOCAL_HOST || '',
DEVICE_DOMAIN_NAME: process.env.DEVICE_DOMAIN_NAME || '',
TOR_HOST: process.env.APP_CORE_LIGHTNING_REST_HIDDEN_SERVICE || '',
WS_PORT: process.env.APP_CORE_LIGHTNING_WEBSOCKET_PORT || '',
GRPC_PORT: process.env.APP_CORE_LIGHTNING_DAEMON_GRPC_PORT || '',
CLIENT_KEY: clientKey,
CLIENT_CERT: clientCert,
CA_CERT: caCert,
REST_PORT: process.env.APP_CORE_LIGHTNING_REST_PORT || '',
REST_MACAROON: macaroon,
CLN_NODE_IP: process.env.APP_CORE_LIGHTNING_DAEMON_IP || '',
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/dist/shared/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function handleError(error, req, res, next) {
? JSON.stringify(error)
: typeof error === 'string'
? error
: 'Unknow Error!';
: 'Unknown Error!';
logger.error(message, route, error.stack);
return res.status(error.statusCode || HttpStatusCode.INTERNAL_SERVER).json(message);
}
Expand Down
34 changes: 17 additions & 17 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cln-application-backend",
"version": "0.0.4",
"version": "0.0.5",
"description": "Core lightning application backend",
"private": true,
"license": "MIT",
Expand All @@ -11,28 +11,28 @@
"start": "tsc --project tsconfig.json --watch & prettier --write source/ & nodemon ./dist/server.js",
"watch": "tsc --project tsconfig.json --watch & prettier --write source/"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.3",
"@types/cors": "^2.8.13",
"@types/csurf": "^1.11.2",
"@types/express": "^4.17.15",
"@types/jsonwebtoken": "^9.0.2",
"@types/morgan": "^1.9.3",
"@types/node": "^18.11.18",
"nodemon": "^2.0.20",
"prettier": "^2.8.1",
"tslint": "^6.1.3",
"typescript": "^4.9.4"
},
"dependencies": {
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"csurf": "^1.11.0",
"express": "^4.18.2",
"express-winston": "^4.2.0",
"jsonwebtoken": "^9.0.1",
"lnmessage": "^0.2.2",
"jsonwebtoken": "^9.0.2",
"lnmessage": "^0.2.6",
"ts-node": "^10.9.1",
"winston": "^3.8.2"
"winston": "^3.11.0"
},
"devDependencies": {
"@types/cookie-parser": "^1.4.6",
"@types/cors": "^2.8.17",
"@types/csurf": "^1.11.5",
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.5",
"@types/morgan": "^1.9.9",
"@types/node": "^20.9.4",
"nodemon": "^3.0.1",
"prettier": "^3.1.0",
"tslint": "^6.1.3",
"typescript": "^5.3.2"
}
}
49 changes: 4 additions & 45 deletions apps/backend/source/controllers/lightning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,6 @@ import { HttpStatusCode } from '../shared/consts.js';

const lnMessage: LightningService = LNMessage;

export const getNodesInfo = (lightningPeers: any) => {
return Promise.all(
lightningPeers.peers.map((peer: any) => {
return new Promise((resolve, reject) => {
lnMessage
.call('listnodes', [peer.id])
.then(data => {
peer.alias = data.nodes[0].alias || peer.id.substring(0, 20);
resolve(peer);
})
.catch(err => {
peer.alias = peer.id.substring(0, 20);
resolve(peer);
});
});
}),
)
.then(peersWithAliases => {
logger.info('Peers with Aliases: ' + JSON.stringify(peersWithAliases));
return { peers: peersWithAliases };
})
.catch(err => {
logger.error('Controller caught lightning error from list nodes: ' + JSON.stringify(err));
throw new LightningError(
'Controller caught lightning error from list nodes: ' + JSON.stringify(err),
err,
HttpStatusCode.LIGHTNING_SERVER,
'Get Network Nodes Information',
);
});
};

class LightningController {
callMethod(req: Request, res: Response, next: NextFunction) {
try {
Expand All @@ -53,19 +21,10 @@ class LightningController {
JSON.stringify(commandRes),
);
if (req.body.method && req.body.method === 'listpeers') {
try {
// Filter out ln message pubkey from peers list
const lnmPubkey = lnMessage.getLNMsgPubkey();
commandRes.peers = commandRes.peers.filter((peer: any) => peer.id !== lnmPubkey);
// To get node aliases from liseNodes
getNodesInfo(commandRes).then((resWithAliases: any) => {
logger.info(resWithAliases);
res.status(200).json(resWithAliases);
});
} catch (error: any) {
logger.error('Lightning error from Get Nodes Info : ' + JSON.stringify(error));
return handleError(error, req, res, next);
}
// Filter out ln message pubkey from peers list
const lnmPubkey = lnMessage.getLNMsgPubkey();
commandRes.peers = commandRes.peers.filter((peer: any) => peer.id !== lnmPubkey);
res.status(200).json(commandRes);
} else {
res.status(200).json(commandRes);
}
Expand Down
31 changes: 30 additions & 1 deletion apps/backend/source/controllers/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { logger } from '../shared/logger.js';
import handleError from '../shared/error-handler.js';
import { APIError } from '../models/errors.js';
import { setSharedApplicationConfig, overrideSettingsWithEnvVariables } from '../shared/utils.js';
import { sep } from 'path';

class SharedController {
getApplicationSettings(req: Request, res: Response, next: NextFunction) {
Expand Down Expand Up @@ -44,9 +45,13 @@ class SharedController {
getWalletConnectSettings(req: Request, res: Response, next: NextFunction) {
try {
logger.info('Getting Connection Settings');
const CERTS_PATH =
process.env.CORE_LIGHTNING_PATH + sep + process.env.APP_BITCOIN_NETWORK + sep;
let macaroon = '';
let clientKey = '';
let clientCert = '';
let caCert = '';
let packageData = '{ version: "0.0.4" }';

if (fs.existsSync(APP_CONSTANTS.MACAROON_PATH)) {
logger.info(
'Getting REST Access Macaroon from ' + process.env.APP_CORE_LIGHTNING_REST_CERT_DIR,
Expand All @@ -56,12 +61,36 @@ class SharedController {
if (fs.existsSync('package.json')) {
packageData = Buffer.from(fs.readFileSync('package.json')).toString();
}
if (fs.existsSync(CERTS_PATH + 'client-key.pem')) {
clientKey = fs.readFileSync(CERTS_PATH + 'client-key.pem').toString();
clientKey = clientKey
.replace(/(\r\n|\n|\r)/gm, '')
.replace('-----BEGIN PRIVATE KEY-----', '')
.replace('-----END PRIVATE KEY-----', '');
}
if (fs.existsSync(CERTS_PATH + 'client.pem')) {
clientCert = fs.readFileSync(CERTS_PATH + 'client.pem').toString();
clientCert = clientCert
.replace(/(\r\n|\n|\r)/gm, '')
.replace('-----BEGIN CERTIFICATE-----', '')
.replace('-----END CERTIFICATE-----', '');
}
if (fs.existsSync(CERTS_PATH + 'ca.pem')) {
caCert = fs.readFileSync(CERTS_PATH + 'ca.pem').toString();
caCert = caCert
.replace(/(\r\n|\n|\r)/gm, '')
.replace('-----BEGIN CERTIFICATE-----', '')
.replace('-----END CERTIFICATE-----', '');
}
const CONNECT_WALLET_SETTINGS = {
LOCAL_HOST: process.env.LOCAL_HOST || '',
DEVICE_DOMAIN_NAME: process.env.DEVICE_DOMAIN_NAME || '',
TOR_HOST: process.env.APP_CORE_LIGHTNING_REST_HIDDEN_SERVICE || '',
WS_PORT: process.env.APP_CORE_LIGHTNING_WEBSOCKET_PORT || '',
GRPC_PORT: process.env.APP_CORE_LIGHTNING_DAEMON_GRPC_PORT || '',
CLIENT_KEY: clientKey,
CLIENT_CERT: clientCert,
CA_CERT: caCert,
REST_PORT: process.env.APP_CORE_LIGHTNING_REST_PORT || '',
REST_MACAROON: macaroon,
CLN_NODE_IP: process.env.APP_CORE_LIGHTNING_DAEMON_IP || '',
Expand Down
22 changes: 0 additions & 22 deletions apps/backend/source/models/lightning.ts

This file was deleted.

Loading

0 comments on commit 281f4db

Please sign in to comment.