Skip to content

Commit

Permalink
Merge pull request #159 from Ride-The-Lightning/Release-v0.10.1
Browse files Browse the repository at this point in the history
Release v0.10.1
  • Loading branch information
ShahanaFarooqui committed Feb 22, 2023
2 parents 2e01028 + d6c959d commit 3113ffb
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 45 deletions.
2 changes: 1 addition & 1 deletion cl-rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ server.listen(PORT, BIND, function() {

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

exports.closeServer = function(){
Expand Down
1 change: 1 addition & 0 deletions controllers/getinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ exports.getinfo = (req,res) => {

//Call the getinfo command
ln.getinfo().then(data => {
global.version = data.version;
data.api_version = require('../package.json').version;
global.logger.log('getinfo success');
res.status(200).json(data);
Expand Down
71 changes: 46 additions & 25 deletions controllers/offers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
//This controller houses all the offers functions
const isVersionCompatible = (currentVersion, checkVersion) => {
if (currentVersion) {
const versionsArr = currentVersion.trim()?.replace('v', '').split('-')[0].split('.') || [];
const checkVersionsArr = checkVersion.split('.');
return (+versionsArr[0] > +checkVersionsArr[0]) ||
(+versionsArr[0] === +checkVersionsArr[0] && +versionsArr[1] > +checkVersionsArr[1]) ||
(+versionsArr[0] === +checkVersionsArr[0] && +versionsArr[1] === +checkVersionsArr[1] && +versionsArr[2] >= +checkVersionsArr[2]);
}
return false;
};

//This controller houses all the offers functions

//Function # 1
//Invoke the 'offer' command to setup an offer
Expand Down Expand Up @@ -28,7 +39,7 @@
* required:
* - description
* - in: body
* name: vendor
* name: vendor/issuer
* description: Reflects who is issuing this offer
* type: string
* - in: body
Expand All @@ -37,11 +48,11 @@
* type: string
* - in: body
* name: quantity_min
* 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
* 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.
* type: number
* - in: body
* name: quantity_max
* 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
* description: The presence of quantity_max indicates that the invoice can specify more than one of the items within this (inclusive) range
* type: number
* - in: body
* name: absolute_expiry
Expand Down Expand Up @@ -89,7 +100,7 @@
* description: The bolt12 offer, starting with "lno1"
* bolt12_unsigned:
* type: string
* description: The bolt12 encoding of the offer, without a signature
* description: Available only in versions < 22.11.x. The bolt12 encoding of the offer, without a signature.
* used:
* type: boolean
* description: true if an associated invoice has been paid
Expand All @@ -107,41 +118,51 @@ exports.offer = (req,res) => {

function connFailed(err) { throw err }
ln.on('error', connFailed);

//Set required params
var amnt = req.body.amount;
var desc = req.body.description;
//Set optional params
var vndr = (req.body.vendor) ? req.body.vendor : null;
var issuer = req.body.issuer ? req.body.issuer : req.body.vendor ? req.body.vendor : null;
var lbl = (req.body.label) ? req.body.label : null;
var qty_min = (req.body.quantity_min) ? req.body.quantity_min : null;
var qty_max = (req.body.quantity_max) ? req.body.quantity_max : null;
var abs_expry = (req.body.absolute_expiry) ? req.body.absolute_expiry : null;
var rcrnc = (req.body.recurrence) ? req.body.recurrence : null;
var rcrnc_base = (req.body.recurrence_base) ? req.body.recurrence_base : null;
var rcrnc_wndw = (req.body.recurrence_paywindow) ? req.body.recurrence_paywindow : null;
var rcrnc_lmt = (req.body.recurrence_limit) ? req.body.recurrence_limit : null;
var sngl_use = (req.body.single_use === '0' || req.body.single_use === 'false' || !req.body.single_use) ? false : true;
var qty_min = (req.body.quantity_min) ? req.body.quantity_min : null;

//Call the fundchannel command with the pub key and amount specified
ln.offer(amount=amnt,
description=desc,
vendor=vndr,
label=lbl,
quantity_min=qty_min,
quantity_max=qty_max,
absolute_expiry=abs_expry,
recurrence=rcrnc,
recurrence_base=rcrnc_base,
recurrence_paywindow=rcrnc_wndw,
recurrence_limit=rcrnc_lmt,
single_use=sngl_use
if (!(global.version && isVersionCompatible(global.version, '22.11.1'))) {
ln.offer(
amount=amnt, description=desc, vendor=issuer, label=lbl,
quantity_min=qty_min, quantity_max=qty_max, absolute_expiry=abs_expry,
recurrence=rcrnc, recurrence_base=rcrnc_base, recurrence_paywindow=rcrnc_wndw,
recurrence_limit=rcrnc_lmt, single_use=sngl_use
).then(data => {
global.logger.log('offer creation success');
res.status(201).json(data);
}).catch(err => {
global.logger.warn(err);
res.status(500).json({error: err});
});
global.logger.log('offer creation success');
res.status(201).json(data);
}).catch(err => {
global.logger.warn(err);
res.status(500).json({error: err});
});
} else {
ln.offer(
amount=amnt, description=desc, issuer=issuer, label=lbl,
quantity_max=qty_max, absolute_expiry=abs_expry,
recurrence=rcrnc, recurrence_base=rcrnc_base, recurrence_paywindow=rcrnc_wndw,
recurrence_limit=rcrnc_lmt, single_use=sngl_use
).then(data => {
global.logger.log('offer creation success');
res.status(201).json(data);
}).catch(err => {
global.logger.warn(err);
res.status(500).json({error: err});
});
}

ln.removeListener('error', connFailed);
}

Expand Down
4 changes: 3 additions & 1 deletion lightning-client-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ class LightningClient extends EventEmitter {
if (typeof global.REST_PLUGIN_CONFIG === 'undefined') {
this.parser.write(data)
} else {
somedata += data
if(data.length && data.length > 0) {
somedata += data
}
if (somedata.length > 1 && somedata.slice(-2) === "\n\n") {
this.parser.write(somedata)
somedata = ''
Expand Down
100 changes: 84 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "c-lightning-rest",
"version": "0.10.0",
"version": "0.10.1",
"description": "c-lightning REST API suite",
"main": "cl-rest.js",
"scripts": {
Expand All @@ -17,7 +17,7 @@
"license": "MIT",
"dependencies": {
"atob": "^2.1.2",
"body-parser": "^1.19.0",
"body-parser": "^1.20.1",
"clightningjs": "^0.2.2",
"error": "^7.0.2",
"express": "^4.16.4",
Expand Down

0 comments on commit 3113ffb

Please sign in to comment.