ADD: /getchaninfo/:chanid

This commit is contained in:
Overtorment 2021-04-03 12:35:45 +01:00
parent d47f03501d
commit 17e9bd30c8
3 changed files with 614 additions and 463 deletions

View File

@ -109,6 +109,17 @@ subscribeInvoicesCall.on('end', function () {
// The server has closed the stream.
});
let lightningDescribeGraph = {};
function updateDescribeGraph() {
console.log('updateDescribeGraph()');
lightning.describeGraph({ include_unannounced: true }, function (err, response) {
if (!err) lightningDescribeGraph = response;
console.log('updated graph');
});
}
updateDescribeGraph();
setInterval(updateDescribeGraph, 120000);
// ######################## ROUTES ########################
const rateLimit = require('express-rate-limit');
@ -489,6 +500,20 @@ router.get('/queryroutes/:source/:dest/:amt', async function (req, res) {
});
});
router.get('/getchaninfo/:chanid', async function (req, res) {
logger.log('/getchaninfo', [req.id]);
if (lightningDescribeGraph && lightningDescribeGraph.edges) {
for (const edge of lightningDescribeGraph.edges) {
console.log('edge.channel_id = ' + edge.channel_id);
if (edge.channel_id == req.params.chanid) {
return res.send(JSON.stringify(edge, null, 2));
}
}
}
res.send('');
});
module.exports = router;
// ################# HELPERS ###########################

View File

@ -14,6 +14,7 @@ function updateLightning() {
lightning.getInfo({}, function (err, info) {
if (err) {
console.error('lnd failure:', err);
return;
}
lightningGetInfo = info;
});
@ -23,6 +24,7 @@ function updateLightning() {
console.error('lnd failure:', err);
return;
}
console.log('updated');
lightningListChannels = response;
let channels = [];
let max_chan_capacity = -1;
@ -47,7 +49,6 @@ function updateLightning() {
} catch (Err) {
console.log(Err);
}
console.log('updated');
}
updateLightning();
setInterval(updateLightning, 60000);

1049
package-lock.json generated

File diff suppressed because it is too large Load Diff