Skip to content

Commit 3113ffb

Browse files
Merge pull request #159 from Ride-The-Lightning/Release-v0.10.1
Release v0.10.1
2 parents 2e01028 + d6c959d commit 3113ffb

File tree

6 files changed

+137
-45
lines changed

6 files changed

+137
-45
lines changed

cl-rest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ server.listen(PORT, BIND, function() {
141141

142142
//Start the docserver
143143
docserver.listen(DOCPORT, BIND, function() {
144-
global.logger.warn('--- cl-rest doc server is ready and listening on ' + BIND + ':' + PORT + ' ---');
144+
global.logger.warn('--- cl-rest doc server is ready and listening on ' + BIND + ':' + DOCPORT + ' ---');
145145
})
146146

147147
exports.closeServer = function(){

controllers/getinfo.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ exports.getinfo = (req,res) => {
127127

128128
//Call the getinfo command
129129
ln.getinfo().then(data => {
130+
global.version = data.version;
130131
data.api_version = require('../package.json').version;
131132
global.logger.log('getinfo success');
132133
res.status(200).json(data);

controllers/offers.js

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
//This controller houses all the offers functions
1+
const isVersionCompatible = (currentVersion, checkVersion) => {
2+
if (currentVersion) {
3+
const versionsArr = currentVersion.trim()?.replace('v', '').split('-')[0].split('.') || [];
4+
const checkVersionsArr = checkVersion.split('.');
5+
return (+versionsArr[0] > +checkVersionsArr[0]) ||
6+
(+versionsArr[0] === +checkVersionsArr[0] && +versionsArr[1] > +checkVersionsArr[1]) ||
7+
(+versionsArr[0] === +checkVersionsArr[0] && +versionsArr[1] === +checkVersionsArr[1] && +versionsArr[2] >= +checkVersionsArr[2]);
8+
}
9+
return false;
10+
};
11+
12+
//This controller houses all the offers functions
213

314
//Function # 1
415
//Invoke the 'offer' command to setup an offer
@@ -28,7 +39,7 @@
2839
* required:
2940
* - description
3041
* - in: body
31-
* name: vendor
42+
* name: vendor/issuer
3243
* description: Reflects who is issuing this offer
3344
* type: string
3445
* - in: body
@@ -37,11 +48,11 @@
3748
* type: string
3849
* - in: body
3950
* name: quantity_min
40-
* description: The presence of quantity_min or quantity_max indicates that the invoice can specify more than one of the items within this (inclusive) range
51+
* description: Available only in versions < 22.11.x. The presence of quantity_min or quantity_max indicates that the invoice can specify more than one of the items within this (inclusive) range.
4152
* type: number
4253
* - in: body
4354
* name: quantity_max
44-
* description: The presence of quantity_min or quantity_max indicates that the invoice can specify more than one of the items within this (inclusive) range
55+
* description: The presence of quantity_max indicates that the invoice can specify more than one of the items within this (inclusive) range
4556
* type: number
4657
* - in: body
4758
* name: absolute_expiry
@@ -89,7 +100,7 @@
89100
* description: The bolt12 offer, starting with "lno1"
90101
* bolt12_unsigned:
91102
* type: string
92-
* description: The bolt12 encoding of the offer, without a signature
103+
* description: Available only in versions < 22.11.x. The bolt12 encoding of the offer, without a signature.
93104
* used:
94105
* type: boolean
95106
* description: true if an associated invoice has been paid
@@ -107,41 +118,51 @@ exports.offer = (req,res) => {
107118

108119
function connFailed(err) { throw err }
109120
ln.on('error', connFailed);
121+
110122
//Set required params
111123
var amnt = req.body.amount;
112124
var desc = req.body.description;
113125
//Set optional params
114-
var vndr = (req.body.vendor) ? req.body.vendor : null;
126+
var issuer = req.body.issuer ? req.body.issuer : req.body.vendor ? req.body.vendor : null;
115127
var lbl = (req.body.label) ? req.body.label : null;
116-
var qty_min = (req.body.quantity_min) ? req.body.quantity_min : null;
117128
var qty_max = (req.body.quantity_max) ? req.body.quantity_max : null;
118129
var abs_expry = (req.body.absolute_expiry) ? req.body.absolute_expiry : null;
119130
var rcrnc = (req.body.recurrence) ? req.body.recurrence : null;
120131
var rcrnc_base = (req.body.recurrence_base) ? req.body.recurrence_base : null;
121132
var rcrnc_wndw = (req.body.recurrence_paywindow) ? req.body.recurrence_paywindow : null;
122133
var rcrnc_lmt = (req.body.recurrence_limit) ? req.body.recurrence_limit : null;
123134
var sngl_use = (req.body.single_use === '0' || req.body.single_use === 'false' || !req.body.single_use) ? false : true;
135+
var qty_min = (req.body.quantity_min) ? req.body.quantity_min : null;
124136

125137
//Call the fundchannel command with the pub key and amount specified
126-
ln.offer(amount=amnt,
127-
description=desc,
128-
vendor=vndr,
129-
label=lbl,
130-
quantity_min=qty_min,
131-
quantity_max=qty_max,
132-
absolute_expiry=abs_expry,
133-
recurrence=rcrnc,
134-
recurrence_base=rcrnc_base,
135-
recurrence_paywindow=rcrnc_wndw,
136-
recurrence_limit=rcrnc_lmt,
137-
single_use=sngl_use
138+
if (!(global.version && isVersionCompatible(global.version, '22.11.1'))) {
139+
ln.offer(
140+
amount=amnt, description=desc, vendor=issuer, label=lbl,
141+
quantity_min=qty_min, quantity_max=qty_max, absolute_expiry=abs_expry,
142+
recurrence=rcrnc, recurrence_base=rcrnc_base, recurrence_paywindow=rcrnc_wndw,
143+
recurrence_limit=rcrnc_lmt, single_use=sngl_use
138144
).then(data => {
139-
global.logger.log('offer creation success');
140-
res.status(201).json(data);
141-
}).catch(err => {
142-
global.logger.warn(err);
143-
res.status(500).json({error: err});
144-
});
145+
global.logger.log('offer creation success');
146+
res.status(201).json(data);
147+
}).catch(err => {
148+
global.logger.warn(err);
149+
res.status(500).json({error: err});
150+
});
151+
} else {
152+
ln.offer(
153+
amount=amnt, description=desc, issuer=issuer, label=lbl,
154+
quantity_max=qty_max, absolute_expiry=abs_expry,
155+
recurrence=rcrnc, recurrence_base=rcrnc_base, recurrence_paywindow=rcrnc_wndw,
156+
recurrence_limit=rcrnc_lmt, single_use=sngl_use
157+
).then(data => {
158+
global.logger.log('offer creation success');
159+
res.status(201).json(data);
160+
}).catch(err => {
161+
global.logger.warn(err);
162+
res.status(500).json({error: err});
163+
});
164+
}
165+
145166
ln.removeListener('error', connFailed);
146167
}
147168

lightning-client-js.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ class LightningClient extends EventEmitter {
148148
if (typeof global.REST_PLUGIN_CONFIG === 'undefined') {
149149
this.parser.write(data)
150150
} else {
151-
somedata += data
151+
if(data.length && data.length > 0) {
152+
somedata += data
153+
}
152154
if (somedata.length > 1 && somedata.slice(-2) === "\n\n") {
153155
this.parser.write(somedata)
154156
somedata = ''

package-lock.json

Lines changed: 84 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "c-lightning-rest",
3-
"version": "0.10.0",
3+
"version": "0.10.1",
44
"description": "c-lightning REST API suite",
55
"main": "cl-rest.js",
66
"scripts": {
@@ -17,7 +17,7 @@
1717
"license": "MIT",
1818
"dependencies": {
1919
"atob": "^2.1.2",
20-
"body-parser": "^1.19.0",
20+
"body-parser": "^1.20.1",
2121
"clightningjs": "^0.2.2",
2222
"error": "^7.0.2",
2323
"express": "^4.16.4",

0 commit comments

Comments
 (0)