new listPeers()

This commit is contained in:
Daniel Lugo 2021-01-10 13:27:03 -04:00
parent c5e48b1eb5
commit 5cab6deeb1
2 changed files with 38 additions and 20 deletions

View file

@ -1053,25 +1053,17 @@ module.exports = async (
}) })
// get lnd node active channels list // get lnd node active channels list
app.get('/api/lnd/listpeers', (req, res) => { app.get('/api/lnd/listpeers', async (req, res) => {
const { lightning } = LightningServices.services try {
lightning.listPeers({}, async (err, response) => { return res.json({
if (err) { peers: await LV2.listPeers(req.body.latestError)
logger.debug('ListPeers Error:', err)
const health = await checkHealth()
if (health.LNDStatus.success) {
res.status(400).json({
field: 'listPeers',
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('ListPeers:', response)
res.json(response)
}) })
}
}) })
// newaddress // newaddress

View file

@ -490,6 +490,31 @@ const getChanInfo = chanID =>
) )
}) })
/**
* https://api.lightning.community/#listpeers
* @param {boolean=} latestError If true, only the last error that our peer sent
* us will be returned with the peer's information, rather than the full set of
* historic errors we have stored.
* @returns {Promise<Common.Peer[]>}
*/
const listPeers = latestError =>
Common.makePromise((res, rej) => {
const { lightning } = lightningServices.getServices()
lightning.listPeers(
{
latest_error: latestError
},
(err, resp) => {
if (err) {
rej(new Error(err.message))
} else {
res(resp.peers)
}
}
)
})
module.exports = { module.exports = {
sendPaymentV2Keysend, sendPaymentV2Keysend,
sendPaymentV2Invoice, sendPaymentV2Invoice,
@ -498,5 +523,6 @@ module.exports = {
newAddress, newAddress,
listUnspent, listUnspent,
listChannels, listChannels,
getChanInfo getChanInfo,
listPeers
} }