new newAddress

This commit is contained in:
Daniel Lugo 2021-01-09 16:29:52 -04:00
parent 34264db895
commit a2fe681e18
2 changed files with 30 additions and 20 deletions

View file

@ -1090,25 +1090,16 @@ module.exports = async (
}) })
// newaddress // newaddress
app.post('/api/lnd/newaddress', (req, res) => { app.post('/api/lnd/newaddress', async (req, res) => {
const { lightning } = LightningServices.services try {
lightning.newAddress({ type: req.body.type }, async (err, response) => { return res.json({
if (err) { address: await LV2.newAddress(req.body.type)
logger.debug('NewAddress Error:', err)
const health = await checkHealth()
if (health.LNDStatus.success) {
res.status(400).json({
field: 'newAddress',
errorMessage: sanitizeLNDError(err.message)
}) })
} else { } catch (e) {
res.status(500) return res.status(500).json({
res.json({ errorMessage: 'LND is down' }) errorMessage: e.message
}
}
logger.debug('NewAddress:', response)
res.json(response)
}) })
}
}) })
// connect peer to lnd node // connect peer to lnd node

View file

@ -402,9 +402,28 @@ const decodePayReq = payReq =>
) )
}) })
/**
* @param {0|1} type
* @returns {Promise<string>}
*/
const newAddress = (type = 0) => {
const { lightning } = lightningServices.getServices()
return Common.Utils.makePromise((res, rej) => {
lightning.newAddress({ type }, (err, response) => {
if (err) {
rej(new Error(err.message))
} else {
res(response.address)
}
})
})
}
module.exports = { module.exports = {
sendPaymentV2Keysend, sendPaymentV2Keysend,
sendPaymentV2Invoice, sendPaymentV2Invoice,
listPayments, listPayments,
decodePayReq decodePayReq,
newAddress
} }