From d6cdba227693ffb0da7b6a2079bdadd8f4ef09a5 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sun, 10 Jan 2021 16:54:54 -0400 Subject: [PATCH] pending channels --- src/routes.js | 29 +++++++++-------------------- utils/lightningServices/types.ts | 22 ++++++++++++++++++++++ utils/lightningServices/v2.js | 25 ++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 21 deletions(-) diff --git a/src/routes.js b/src/routes.js index 99ed7dcf..9697d46d 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1134,26 +1134,15 @@ module.exports = async ( } }) - // get lnd node pending channels list - app.get('/api/lnd/pendingchannels', (req, res) => { - const { lightning } = LightningServices.services - lightning.pendingChannels({}, async (err, response) => { - if (err) { - logger.debug('PendingChannels Error:', err) - const health = await checkHealth() - if (health.LNDStatus.success) { - res.status(400).json({ - field: 'pendingChannels', - errorMessage: sanitizeLNDError(err.message) - }) - } else { - res.status(500) - res.json({ errorMessage: 'LND is down' }) - } - } - logger.debug('PendingChannels:', response) - res.json(response) - }) + app.get('/api/lnd/pendingchannels', async (req, res) => { + try { + return res.json(await LV2.pendingChannels()) + } catch (e) { + console.log(e) + return res.status(500).json({ + errorMessage: e.message + }) + } }) app.get('/api/lnd/unifiedTrx', (req, res) => { diff --git a/utils/lightningServices/types.ts b/utils/lightningServices/types.ts index faa7f0b9..c390d545 100644 --- a/utils/lightningServices/types.ts +++ b/utils/lightningServices/types.ts @@ -144,3 +144,25 @@ export interface ListChannelsReq { */ peer: Common.Bytes } + +/** + * https://api.lightning.community/#pendingchannels + */ +export interface PendingChannelsRes { + /** + * The balance in satoshis encumbered in pending channels. + */ + total_limbo_balance: string + /** + * Channels pending opening. + */ + pending_open_channels: Common.PendingOpenChannel[] + /** + * Channels pending force closing. + */ + pending_force_closing_channels: Common.ForceClosedChannel[] + /** + * Channels waiting for closing tx to confirm. + */ + waiting_close_channels: Common.WaitingCloseChannel[] +} diff --git a/utils/lightningServices/v2.js b/utils/lightningServices/v2.js index a158aed1..07c5574a 100644 --- a/utils/lightningServices/v2.js +++ b/utils/lightningServices/v2.js @@ -515,6 +515,28 @@ const listPeers = latestError => ) }) +/** + * @typedef {import('./types').PendingChannelsRes} PendingChannelsRes + */ + +/** + * @returns {Promise} + */ +const pendingChannels = () => + Common.makePromise((res, rej) => { + const { lightning } = lightningServices.getServices() + + lightning.pendingChannels({}, (err, resp) => { + if (err) { + rej(new Error(err.message)) + } else { + // Needs cast because typescript refuses to assign Record + // to an actual object :shrugs + res(/** @type {PendingChannelsRes} */ (resp)) + } + }) + }) + module.exports = { sendPaymentV2Keysend, sendPaymentV2Invoice, @@ -524,5 +546,6 @@ module.exports = { listUnspent, listChannels, getChanInfo, - listPeers + listPeers, + pendingChannels }