Skip to content

Commit 2e01028

Browse files
authored
Merge pull request #158 from Ride-The-Lightning/Release-v0.10.0
Release v0.10.0
2 parents 3f8e608 + 24ed841 commit 2e01028

File tree

14 files changed

+186
-81
lines changed

14 files changed

+186
-81
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ For running the server, rename the file `sample-cl-rest-config.json` to `cl-rest
4646
- LNRPCPATH (Default: ` `)
4747
- RPCCOMMANDS (Default: `["*"]`)
4848
- DOMAIN (Default: `localhost`)
49+
- BIND (Default: `::`)
4950

5051
#### Option 2: With the plugin configuration, if used as a plugin
52+
53+
NOTE: Node.js plugins might not work with lightningd.service setting `MemoryDenyWriteExecute=true` as it denies the creation of writable and executable memory mappings. Ref: https://github.com/Ride-The-Lightning/c-lightning-REST/issues/116
54+
5155
If running as a plugin, configure the below options in your c-lightning `config` file:
5256
- `rest-port`
5357
- `rest-docport`
@@ -56,6 +60,7 @@ If running as a plugin, configure the below options in your c-lightning `config`
5660
- `rest-lnrpcpath`
5761
- `rest-rpc`
5862
- `rest-domain`
63+
- `rest-bind`
5964

6065
Defaults are the same as in option # 1 with the exception that `rest-rpc` is a comma separated string.
6166

@@ -72,15 +77,15 @@ Pass arguments when launching lightningd:
7277

7378
`$ lightningd --plugin=PATH_TO_PLUGIN [--rest-port=N] [--rest-protocol=http|https] [--rest-execmode=MODE]`
7479

75-
E.g. `$ lightningd --plugin=/Users/<user>/c-lightning-REST/plugin.js --rest-port=3003`
80+
E.g. `$ lightningd --plugin=/Users/<user>/c-lightning-REST/clrest.js --rest-port=3003`
7681

7782
OR
7883

7984
Set `plugin`, `[rest-port]`, `[rest-docport]`, `[rest-protocol]`, and `[rest-execmode]` in lightningd [config](https://github.com/ElementsProject/lightning/blob/master/doc/lightningd-config.5.md)
8085

8186
E.g. add below to the `config` file in `.lightning` folder
8287
```
83-
plugin=/Users/<user>/c-lightning-REST/plugin.js
88+
plugin=/Users/<user>/c-lightning-REST/clrest.js
8489
rest-port=3002
8590
rest-docport=4001
8691
rest-protocol=https
@@ -128,13 +133,13 @@ Providing a `DOMAIN` to the c-lightning-REST configuration will add the domain a
128133
If you are *upgrading* a server which is already configured, you should first backup and your entire `./certs` directory in case you need to restore it later.
129134
Following this you should delete *only* the `.certs/certificate.pem` and `.certs/key.pem` files, so that new SSL certificates can be generated which take the `subjectAltName` into consideration.
130135

131-
**WARNING**: Do not delete `access.macaroon`. If you do then your connection to remote applications will be lost, and need to be re-configured.
136+
**WARNING**: Do not delete `access.macaroon` or `rootKey.key`. If you do then your connection to remote applications will be lost, and need to be re-configured.
132137

133138
New certificates will be automatically generated as usual next time the program is started up.
134139

135140
### <a name="auth"></a>Authentication
136141
Authentication has been implemented with macaroons. Macaroons are bearer tokens, which will be verified by the server.
137-
A file `access.macaroon` will be generated in the `certs` folder in the application root.
142+
Two files, `access.macaroon` and `rootKey.key`, will be generated in the `certs` folder in the application root.
138143
The `access.macaroon` has to be read by the requesting application, converted to `base64` or `hex`, and passed in the header with key value `macaroon`.
139144

140145
Encoding Options for passing macaroon in the header:
@@ -179,7 +184,7 @@ C-Lightning commands covered by this API suite is [here](docs/CLTCommandCoverage
179184
- disconnect (/v1/peer/disconnect) - `DEL`: Disconnect from a connected network peer
180185
### Channel management
181186
- fundchannel (/v1/channel/openChannel) - `POST`: Open channel with a connected peer node
182-
- listchannels (/v1/channel/listChannels) - `GET`: Get the list of channels open on the node
187+
- listchannels (/v1/channel/listChannels) - `GET`: Get the list of channels that are known to the node.
183188
- setchannelfee (/v1/channel/setChannelFee) - `POST`: Update the fee policy for a channel
184189
- close (/v1/channel/closeChannel) - `DEL`: Close channel
185190
- listforwards (/v1/channel/listForwards) - `GET`: Get the list of forwarded htlcs by the node

cl-rest.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const PORT = config.PORT;
3030
const EXECMODE = config.EXECMODE;
3131
const DOCPORT = config.DOCPORT;
3232
const DOMAIN = config.DOMAIN || "localhost";
33+
const BIND = config.BIND || "::";
3334

3435
//Create certs folder
3536
try {
@@ -46,7 +47,7 @@ if ( ! fs.existsSync( key ) || ! fs.existsSync( certificate ) ) {
4647
try {
4748
execSync( 'openssl version', execOptions );
4849
execSync(
49-
`openssl req -x509 -newkey rsa:2048 -keyout ./certs/key.tmp.pem -out ${ certificate } -days 365 -nodes -subj "/C=US/ST=Foo/L=Bar/O=Baz/CN=c-lightning-rest" --addext "subjectAltName = DNS:${ DOMAIN }"`,
50+
`openssl req -x509 -newkey rsa:2048 -keyout ./certs/key.tmp.pem -out ${ certificate } -days 365 -nodes -subj "/C=US/ST=Foo/L=Bar/O=Baz/CN=c-lightning-rest" -addext "subjectAltName = DNS:${ DOMAIN }"`,
5051
execOptions
5152
);
5253
execSync( `openssl rsa -in ./certs/key.tmp.pem -out ${ key }`, execOptions );
@@ -134,13 +135,13 @@ try {
134135
docserver = require( 'http' ).createServer( docapp );
135136

136137
//Start the server
137-
server.listen(PORT, function() {
138-
global.logger.warn('--- cl-rest api server is ready and listening on port: ' + PORT + ' ---');
138+
server.listen(PORT, BIND, function() {
139+
global.logger.warn('--- cl-rest api server is ready and listening on ' + BIND + ':' + PORT + ' ---');
139140
})
140141

141142
//Start the docserver
142-
docserver.listen(DOCPORT, function() {
143-
global.logger.warn('--- cl-rest doc server is ready and listening on port: ' + DOCPORT + ' ---');
143+
docserver.listen(DOCPORT, BIND, function() {
144+
global.logger.warn('--- cl-rest doc server is ready and listening on ' + BIND + ':' + PORT + ' ---');
144145
})
145146

146147
exports.closeServer = function(){
@@ -158,3 +159,5 @@ process.on('SIGTERM', () => {
158159
docserver.close();
159160
process.exit(0);
160161
})
162+
163+
module.exports = { server, wsServer };

plugin.js renamed to clrest.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ restPlugin.addOption('rest-execmode', 'production', 'rest exec mode', 'string');
1212
restPlugin.addOption('rest-rpc', ' ', 'allowed rpc commands', 'string');
1313
restPlugin.addOption('rest-lnrpcpath', ' ', 'path for lightning-rpc', 'string');
1414
restPlugin.addOption('rest-domain', ' ', 'domain name for self-signed cert', 'string');
15+
restPlugin.addOption('rest-bind', ' ', 'Binding address', 'string');
1516

1617
restPlugin.onInit = params => {
1718
process.env.LN_PATH = `${params.configuration['lightning-dir']}/${params.configuration['rpc-file']}`
@@ -24,11 +25,11 @@ restPlugin.onInit = params => {
2425
RPCCOMMANDS: params.options['rest-rpc'].trim().split(",").map(s => s.trim()),
2526
LNRPCPATH: params.options['rest-lnrpcpath'],
2627
DOMAIN: params.options['rest-domain'].trim(),
28+
BIND: params.options['rest-bind'].trim(),
2729
PLUGIN: restPlugin
2830
}
2931

3032
srvr = require('./cl-rest');
31-
3233
};
3334

3435
const EVENTS = [
@@ -44,9 +45,9 @@ const EVENTS = [
4445
EVENTS.forEach(event => {
4546
restPlugin.subscribe(event);
4647
restPlugin.notifications[event].on(event, (msg) => {
47-
if(srvr && srvr.broadcastToClients) {
48+
if(srvr && srvr.wsServer && srvr.wsServer.broadcastToClients) {
4849
updatedMessage = { event: event, data: msg };
49-
srvr.broadcastToClients(updatedMessage);
50+
srvr.wsServer.broadcastToClients(updatedMessage);
5051
}
5152
});
5253
});

controllers/channel.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ exports.openChannel = (req,res) => {
131131
* tags:
132132
* - Channel Management
133133
* name: listchannel
134-
* summary: Returns a list of channels on the node
134+
* summary: Returns data on channels that are known to the node
135135
* description: Core documentation - https://lightning.readthedocs.io/lightning-listchannels.7.html
136136
* security:
137137
* - MacaroonAuth: []
@@ -478,6 +478,10 @@ exports.listForwards = (req,res) => {
478478
* name: maxLen
479479
* description: maximum range after the offset you want to forward.
480480
* type: integer
481+
* - in: query
482+
* name: sort_by
483+
* description: Sort criteria, 'received_time' or 'resolved_time'.
484+
* type: string
481485
* security:
482486
* - MacaroonAuth: []
483487
* responses:
@@ -534,7 +538,7 @@ exports.listForwards = (req,res) => {
534538
*/
535539
exports.listForwardsPaginated = (req,res) => {
536540
try {
537-
var { status, offset, maxLen } = req.query;
541+
var { status, offset, maxLen, sort_by } = req.query;
538542
if (appCache.has('listForwards' + status)) {
539543
global.logger.log('Reading ' + status + ' listForwards from cache');
540544
var forwards = appCache.get('listForwards' + status);
@@ -547,7 +551,10 @@ exports.listForwardsPaginated = (req,res) => {
547551
ln.listforwards(status=status).then(data => {
548552
// Deleting failed and local_failed transactions after latest 1000 records
549553
const forwards = !data.forwards ? [] : (req.query.status === 'failed' || req.query.status === 'local_failed') ? data.forwards.slice(Math.max(0, data.forwards.length - 1000), Math.max(1000, data.forwards.length)).reverse() : data.forwards.reverse();
550-
// Caching data for subsequent pages
554+
if (sort_by !== undefined) {
555+
forwards.sort((a, b) => a[sort_by] - b[sort_by]);
556+
}
557+
// Caching data for subsequent pages
551558
appCache.set('listForwards' + status, forwards);
552559
res.status(200).json(getRequestedPage(forwards, offset, maxLen, status));
553560
}).catch(err => {
@@ -599,6 +606,7 @@ getAliasForChannels = (peer) => {
599606
our_channel_reserve_satoshis: channel.our_channel_reserve_satoshis,
600607
spendable_msatoshi: channel.spendable_msatoshi,
601608
funding_allocation_msat: channel.funding_allocation_msat,
609+
opener: channel.opener,
602610
direction: channel.direction
603611
});
604612
return acc;
@@ -623,6 +631,7 @@ getAliasForChannels = (peer) => {
623631
our_channel_reserve_satoshis: channel.our_channel_reserve_satoshis,
624632
spendable_msatoshi: channel.spendable_msatoshi,
625633
funding_allocation_msat: channel.funding_allocation_msat,
634+
opener: channel.opener,
626635
direction: channel.direction
627636
});
628637
return acc;
@@ -818,4 +827,4 @@ exports.funderUpdate = (req,res) => {
818827
res.status(500).json({error: err});
819828
});
820829
ln.removeListener('error', connFailed);
821-
}
830+
}

controllers/invoice.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ var wsServer = require('../utils/webSocketServer');
4242
* name: private
4343
* description: Include routing hints for private channels (true or 1)
4444
* type: string
45+
* - in: body
46+
* name: fallbacks
47+
* description: The fallbacks array is one or more fallback addresses to include in the invoice (in order from most-preferred to least).
48+
* type: array
49+
* items:
50+
* type: string
51+
* - in: body
52+
* name: preimage
53+
* description: 64-digit hex string to be used as payment preimage for the created invoice. IMPORTANT> if you specify the preimage, you are responsible, to ensure appropriate care for generating using a secure pseudorandom generator seeded with sufficient entropy, and keeping the preimage secret. This parameter is an advanced feature intended for use with cutting-edge cryptographic protocols and should not be used unless explicitly needed.
54+
* type: string
4555
* security:
4656
* - MacaroonAuth: []
4757
* responses:
@@ -65,26 +75,15 @@ var wsServer = require('../utils/webSocketServer');
6575
exports.genInvoice = (req,res) => {
6676
function connFailed(err) { throw err }
6777
ln.on('error', connFailed);
68-
//Set required params
69-
var amount = req.body.amount;
70-
if(req.body.amount == 0)
71-
amount = 'any';
72-
var label = req.body.label;
73-
var desc = req.body.description;
74-
//Set optional params
75-
var expiry = (req.body.expiry) ? req.body.expiry : null;
76-
var exposePvt = (req.body.private === '1' || req.body.private === 'true') ? !!req.body.private : null;
77-
//Set unexposed params
78-
var fallback = null;
79-
var preimage = null;
80-
81-
ln.invoice(msatoshi=amount,
82-
label=label,
83-
description=desc,
84-
expiry=expiry,
85-
fallback=fallback,
86-
preimage=preimage,
87-
exposeprivatechannels=exposePvt).then(data => {
78+
ln.invoice(
79+
msatoshi=((req.body.amount == 0) ? 'any' : req.body.amount),
80+
label=req.body.label,
81+
description=req.body.description,
82+
expiry=(req.body.expiry || null),
83+
fallbacks=(req.body.fallbacks || null),
84+
preimage=(req.body.preimage || null),
85+
exposeprivatechannels=(!!req.body.private || null)
86+
).then(data => {
8887
global.logger.log('bolt11 -> '+ data.bolt11);
8988
global.logger.log('genInvoice success');
9089
res.status(201).json(data);

controllers/peers.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,7 @@ exports.listPeers = (req,res) => {
9292
ln.listpeers().then(data => {
9393
Promise.all(
9494
data.peers.map(peer => {
95-
peerData = {};
96-
peerData = {
97-
id: peer.id,
98-
connected: peer.connected,
99-
netaddr: peer.netaddr
100-
};
101-
return getAliasForPeer(peerData);
95+
return getAliasForPeer(peer);
10296
})
10397
).then(function(peerList) {
10498
res.status(200).json(peerList);
@@ -126,7 +120,7 @@ exports.listPeers = (req,res) => {
126120
* parameters:
127121
* - in: route
128122
* name: pubKey
129-
* description: Pubket of the connected peer
123+
* description: Pubkey of the connected peer
130124
* type: string
131125
* required:
132126
* - pubKey
@@ -184,4 +178,4 @@ getAliasForPeer = (peer) => {
184178
resolve(peer);
185179
});
186180
});
187-
}
181+
}

0 commit comments

Comments
 (0)