new listChannels()

This commit is contained in:
Daniel Lugo 2021-01-10 09:55:19 -04:00
parent 4665e9332b
commit bb0941d6e9
3 changed files with 47 additions and 20 deletions

View file

@ -1144,25 +1144,17 @@ module.exports = async (
}) })
// get lnd node opened channels list // get lnd node opened channels list
app.get('/api/lnd/listchannels', (req, res) => { app.get('/api/lnd/listchannels', async (_, res) => {
const { lightning } = LightningServices.services try {
lightning.listChannels({}, async (err, response) => { return res.json({
if (err) { channels: await LV2.listChannels()
logger.debug('ListChannels Error:', err)
const health = await checkHealth()
if (health.LNDStatus.success) {
res.status(400).json({
field: 'listChannels',
errorMessage: sanitizeLNDError(err.message)
}) })
} else { } catch (e) {
res.status(500) console.log(e)
res.json({ errorMessage: 'LND is down' }) return res.status(500).json({
} errorMessage: e.message
}
logger.debug('ListChannels:', response)
res.json(response)
}) })
}
}) })
// get lnd node pending channels list // get lnd node pending channels list

View file

@ -1,6 +1,7 @@
/** /**
* @format * @format
*/ */
import * as Common from 'shock-common'
export interface PaymentV2 { export interface PaymentV2 {
payment_hash: string payment_hash: string
@ -131,3 +132,15 @@ export interface Services {
walletUnlocker: Record<string, LightningMethod> walletUnlocker: Record<string, LightningMethod>
router: Record<string, LightningMethod> router: Record<string, LightningMethod>
} }
export interface ListChannelsReq {
active_only: boolean
inactive_only: boolean
public_only: boolean
private_only: boolean
/**
* Filters the response for channels with a target peer's pubkey. If peer is
* empty, all channels will be returned.
*/
peer: Common.Bytes
}

View file

@ -444,11 +444,33 @@ const listUnspent = (minConfs = 3, maxConfs = 6) =>
) )
}) })
/**
* @typedef {import('./types').ListChannelsReq} ListChannelsReq
*/
/**
* @param {ListChannelsReq} req
* @returns {Promise<Common.Channel[]>}
*/
const listChannels = req =>
Common.makePromise((res, rej) => {
const { lightning } = lightningServices.getServices()
lightning.listChannels(req, (err, resp) => {
if (err) {
rej(new Error(err.message))
} else {
res(resp.channels)
}
})
})
module.exports = { module.exports = {
sendPaymentV2Keysend, sendPaymentV2Keysend,
sendPaymentV2Invoice, sendPaymentV2Invoice,
listPayments, listPayments,
decodePayReq, decodePayReq,
newAddress, newAddress,
listUnspent listUnspent,
listChannels
} }