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
app.get('/api/lnd/listpeers', (req, res) => {
const { lightning } = LightningServices.services
lightning.listPeers({}, async (err, response) => {
if (err) {
logger.debug('ListPeers Error:', err)
const health = await checkHealth()
if (health.LNDStatus.success) {
res.status(400).json({
field: 'listPeers',
errorMessage: sanitizeLNDError(err.message)
})
} else {
res.status(500)
res.json({ errorMessage: 'LND is down' })
}
}
logger.debug('ListPeers:', response)
res.json(response)
})
app.get('/api/lnd/listpeers', async (req, res) => {
try {
return res.json({
peers: await LV2.listPeers(req.body.latestError)
})
} catch (e) {
console.log(e)
return res.status(500).json({
errorMessage: e.message
})
}
})
// 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 = {
sendPaymentV2Keysend,
sendPaymentV2Invoice,
@ -498,5 +523,6 @@ module.exports = {
newAddress,
listUnspent,
listChannels,
getChanInfo
getChanInfo,
listPeers
}