new listChannels()
This commit is contained in:
parent
4665e9332b
commit
bb0941d6e9
3 changed files with 47 additions and 20 deletions
|
|
@ -1144,25 +1144,17 @@ module.exports = async (
|
|||
})
|
||||
|
||||
// get lnd node opened channels list
|
||||
app.get('/api/lnd/listchannels', (req, res) => {
|
||||
const { lightning } = LightningServices.services
|
||||
lightning.listChannels({}, async (err, response) => {
|
||||
if (err) {
|
||||
logger.debug('ListChannels Error:', err)
|
||||
const health = await checkHealth()
|
||||
if (health.LNDStatus.success) {
|
||||
res.status(400).json({
|
||||
field: 'listChannels',
|
||||
errorMessage: sanitizeLNDError(err.message)
|
||||
})
|
||||
} else {
|
||||
res.status(500)
|
||||
res.json({ errorMessage: 'LND is down' })
|
||||
}
|
||||
}
|
||||
logger.debug('ListChannels:', response)
|
||||
res.json(response)
|
||||
})
|
||||
app.get('/api/lnd/listchannels', async (_, res) => {
|
||||
try {
|
||||
return res.json({
|
||||
channels: await LV2.listChannels()
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return res.status(500).json({
|
||||
errorMessage: e.message
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// get lnd node pending channels list
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/**
|
||||
* @format
|
||||
*/
|
||||
import * as Common from 'shock-common'
|
||||
|
||||
export interface PaymentV2 {
|
||||
payment_hash: string
|
||||
|
|
@ -131,3 +132,15 @@ export interface Services {
|
|||
walletUnlocker: 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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
sendPaymentV2Keysend,
|
||||
sendPaymentV2Invoice,
|
||||
listPayments,
|
||||
decodePayReq,
|
||||
newAddress,
|
||||
listUnspent
|
||||
listUnspent,
|
||||
listChannels
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue