Skip to content

Commit

Permalink
Merge pull request #176 from Ride-The-Lightning/Release-v0.10.3
Browse files Browse the repository at this point in the history
Release v0.10.3
  • Loading branch information
saubyk authored May 28, 2023
2 parents 342dda4 + b5a44d6 commit 2bf3fa0
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 124 deletions.
317 changes: 242 additions & 75 deletions controllers/channel.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions controllers/getBalance.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { isVersionCompatible } = require('../utils/utils');
//This controller houses the on-chain balance functions

//Function # 1
Expand Down Expand Up @@ -41,12 +42,14 @@ exports.getBalance = (req,res) => {
var confBalance = 0;
var unconfBalance = 0;
var totalBalance = 0;
const versionCompatible = global.version && isVersionCompatible(global.version, '23.02');

for (var i = 0; i < opArray.length; i++ )
{
if(opArray[i].status === 'confirmed')
confBalance = confBalance + opArray[i].value;
confBalance = confBalance + (versionCompatible ? (opArray[i].amount_msat/1000) : opArray[i].value);
else if(opArray[i].status === 'unconfirmed')
unconfBalance = unconfBalance + opArray[i].value;
unconfBalance = unconfBalance + (versionCompatible ? (opArray[i].amount_msat/1000) : opArray[i].value);
}
totalBalance = confBalance + unconfBalance;
const walBalance = {
Expand Down
5 changes: 3 additions & 2 deletions controllers/getFees.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { isVersionCompatible } = require('../utils/utils');
//This controller houses all the fee functions

//Function # 1
Expand Down Expand Up @@ -28,11 +29,11 @@
exports.getFees = (req,res) => {
function connFailed(err) { throw err }
ln.on('error', connFailed);
const versionCompatible = global.version && isVersionCompatible(global.version, '23.02');

//Call the getinfo command
ln.getinfo().then(data => {
const feeData = {
feeCollected: data.msatoshi_fees_collected};
const feeData = { feeCollected: (versionCompatible ? data.fees_collected_msat : data.msatoshi_fees_collected) };
global.logger.log('getFees success');
res.status(200).json(feeData);
}).catch(err => {
Expand Down
2 changes: 1 addition & 1 deletion controllers/getinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ exports.getinfoRtl = (req,res) => {
* type: string
* description: msatoshi_fees_collected
* fees_collected_msat:
* type: string
* type: number
* description: fees_collected_msat
* api_version:
* type: string
Expand Down
12 changes: 6 additions & 6 deletions controllers/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ exports.genInvoice = (req,res) => {
* type: integer
* description: msatoshi
* amount_msat:
* type: string
* type: number
* description: amount_msat
* status:
* type: string
Expand All @@ -146,7 +146,7 @@ exports.genInvoice = (req,res) => {
* type: integer
* description: msatoshi_received
* amount_received_msat:
* type: string
* type: number
* description: amount_received_msat
* paid_at:
* type: integer
Expand Down Expand Up @@ -335,7 +335,7 @@ exports.delInvoice = (req,res) => {
* type: string
* description: UNIX timestamp of when it will become / became unpayable
* amount_msat:
* type: string
* type: number
* description: the amount required to pay this invoice
* bolt11:
* type: string
Expand All @@ -347,7 +347,7 @@ exports.delInvoice = (req,res) => {
* type: string
* description: If status is "paid", unique incrementing index for this payment
* amount_received_msat:
* type: string
* type: number
* description: If status is "paid", the amount actually received
* paid_at:
* type: string
Expand Down Expand Up @@ -419,7 +419,7 @@ exports.waitInvoice = (req,res) => {
* type: string
* description: UNIX timestamp of when it will become / became unpayable
* amount_msat:
* type: string
* type: number
* description: the amount required to pay this invoice
* bolt11:
* type: string
Expand All @@ -431,7 +431,7 @@ exports.waitInvoice = (req,res) => {
* type: string
* description: If status is "paid", unique incrementing index for this payment
* amount_received_msat:
* type: string
* type: number
* description: If status is "paid", the amount actually received
* paid_at:
* type: string
Expand Down
6 changes: 3 additions & 3 deletions controllers/listfunds.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* type: integer
* description: value
* amount_msat:
* type: string
* type: number
* description: amount_msat
* address:
* type: string
Expand Down Expand Up @@ -63,13 +63,13 @@
* type: integer
* description: channel_sat
* our_amount_msat:
* type: string
* type: number
* description: our_amount_msat
* channel_total_sat:
* type: integer
* description: channel_total_sat
* amount_msat:
* type: string
* type: number
* description: amount_msat
* funding_txid:
* type: string
Expand Down
13 changes: 8 additions & 5 deletions controllers/localRemoteBal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { isVersionCompatible } = require('../utils/utils');
//This controller houses the local-remote channel balance functions

//Function # 1
Expand Down Expand Up @@ -45,17 +46,19 @@ exports.localRemoteBal = (req,res) => {
var remoteBalance = 0;
var pendingBalance = 0;
var inactiveBalance = 0;
const versionCompatible = global.version && isVersionCompatible(global.version, '23.02');

for (var i = 0; i < chanArray.length; i++ )
{
if((chanArray[i].state === 'CHANNELD_NORMAL') && chanArray[i].connected === true){
localBalance = localBalance + chanArray[i].channel_sat;
remoteBalance = remoteBalance + (chanArray[i].channel_total_sat - chanArray[i].channel_sat);
if((chanArray[i].state === 'CHANNELD_NORMAL') && chanArray[i].connected === true) {
localBalance = localBalance + (versionCompatible ? (chanArray[i].our_amount_msat/1000) : chanArray[i].channel_sat);
remoteBalance = remoteBalance + (versionCompatible ? (chanArray[i].amount_msat/1000) : (chanArray[i].channel_total_sat - chanArray[i].channel_sat));
}
else if((chanArray[i].state === 'CHANNELD_NORMAL') && chanArray[i].connected === false) {
inactiveBalance = inactiveBalance + chanArray[i].channel_sat;
inactiveBalance = inactiveBalance + (versionCompatible ? (chanArray[i].our_amount_msat/1000) : chanArray[i].channel_sat);
}
else if(chanArray[i].state === 'CHANNELD_AWAITING_LOCKIN') {
pendingBalance = pendingBalance + chanArray[i].channel_sat;
pendingBalance = pendingBalance + (versionCompatible ? (chanArray[i].our_amount_msat/1000) : chanArray[i].channel_sat);
}
}
global.logger.log('localbalance -> ' + localBalance);
Expand Down
12 changes: 6 additions & 6 deletions controllers/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var wsServer = require('../utils/webSocketServer');
* type: integer
* description: msatoshi
* amount_msat:
* type: string
* type: number
* description: amount_msat
* delay:
* type: integer
Expand Down Expand Up @@ -222,7 +222,7 @@ exports.listNode = (req,res) => {
* type: integer
* description: satoshis
* amount_msat:
* type: string
* type: number
* description: amount_msat
* message_flags:
* type: integer
Expand All @@ -246,10 +246,10 @@ exports.listNode = (req,res) => {
* type: integer
* description: delay
* htlc_minimum_msat:
* type: string
* type: number
* description: htlc_minimum_msat
* htlc_maximum_msat:
* type: string
* type: number
* description: htlc_maximum_msat
* 500:
* description: Server error
Expand Down Expand Up @@ -465,7 +465,7 @@ exports.estimateFees = (req,res) => {
* type: object
* properties:
* lease_fee_base_msat:
* type: string
* type: number
* description: lease_fee_base_msat
* lease_fee_basis:
* type: string
Expand All @@ -474,7 +474,7 @@ exports.estimateFees = (req,res) => {
* type: string
* description: funding_weight
* channel_fee_max_base_msat:
* type: string
* type: number
* description: channel_fee_max_base_msat
* channel_fee_max_proportional_thousandths:
* type: string
Expand Down
16 changes: 3 additions & 13 deletions controllers/offers.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
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
const { isVersionCompatible } = require('../utils/utils');
//This controller houses all the offers functions

//Function # 1
//Invoke the 'offer' command to setup an offer
Expand Down Expand Up @@ -77,7 +67,7 @@ const isVersionCompatible = (currentVersion, checkVersion) => {
* - in: body
* name: single_use
* description: Indicates that the offer is only valid once
* type: boolean
* type: string
* security:
* - MacaroonAuth: []
* responses:
Expand Down
18 changes: 9 additions & 9 deletions controllers/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ var wsServer = require('../utils/webSocketServer');
* type: integer
* description: msatoshi
* amount_msat:
* type: string
* type: number
* description: amount_msat
* msatoshi_sent:
* type: integer
* description: msatoshi_sent
* amount_sent_msat:
* type: string
* type: number
* description: amount_sent_msat
* created_at:
* type: integer
Expand Down Expand Up @@ -206,7 +206,7 @@ exports.payInvoice = (req,res) => {
* type: string
* description: preimage
* amount_sent_msat:
* type: string
* type: number
* description: amount_sent_msat
* description: pays
* 500:
Expand Down Expand Up @@ -284,13 +284,13 @@ exports.listPays = (req,res) => {
* type: integer
* description: msatoshi
* amount_msat:
* type: string
* type: number
* description: amount_msat
* msatoshi_sent:
* type: integer
* description: msatoshi_sent
* amount_sent_msat:
* type: string
* type: number
* description: amount_sent_msat
* created_at:
* type: integer
Expand Down Expand Up @@ -509,13 +509,13 @@ exports.decodePay = (req,res) => {
* type: integer
* description: msatoshi
* amount_msat:
* type: string
* type: number
* description: amount_msat
* msatoshi_sent:
* type: integer
* description: msatoshi_sent
* amount_sent_msat:
* type: string
* type: number
* description: amount_sent_msat
* payment_preimage:
* type: string
Expand Down Expand Up @@ -650,13 +650,13 @@ getMemoForPayment = (payment) => {
* type: integer
* description: msatoshi
* amount_msat:
* type: string
* type: number
* description: amount_msat
* msatoshi_sent:
* type: integer
* description: msatoshi_sent
* amount_sent_msat:
* type: string
* type: number
* description: amount_sent_msat
* created_at:
* type: integer
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "c-lightning-rest",
"version": "0.10.2",
"version": "0.10.3",
"description": "c-lightning REST API suite",
"main": "cl-rest.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions routes/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ router.post('/openChannel', tasteMacaroon, channelController.openChannel);
//List Channels
router.get('/listChannels', tasteMacaroon, channelController.listChannels);

//List Peer Channels
router.get('/listPeerChannels', tasteMacaroon, channelController.listPeerChannels);

//Update Channel Fee policy
router.post('/setChannelFee', tasteMacaroon, channelController.setChannelFee);

Expand Down
14 changes: 14 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const isVersionCompatible = (currentVersion, checkVersion) => {
if (currentVersion) {
const currentVersionArr = currentVersion.trim()?.replace('v', '').split('-')[0].split('.') || [];
currentVersionArr[1] = currentVersionArr[1].substring(0, 2);
const checkVersionsArr = checkVersion.split('.');
checkVersionsArr[1] = checkVersionsArr[1].substring(0, 2);
return (+currentVersionArr[0] > +checkVersionsArr[0]) ||
(+currentVersionArr[0] === +checkVersionsArr[0] && +currentVersionArr[1] > +checkVersionsArr[1]) ||
(+currentVersionArr[0] === +checkVersionsArr[0] && +currentVersionArr[1] === +checkVersionsArr[1] && +currentVersionArr[2] >= +checkVersionsArr[2]);
}
return false;
};

module.exports = { isVersionCompatible };

0 comments on commit 2bf3fa0

Please sign in to comment.