new newAddress
This commit is contained in:
parent
34264db895
commit
a2fe681e18
2 changed files with 30 additions and 20 deletions
|
|
@ -1090,25 +1090,16 @@ module.exports = async (
|
|||
})
|
||||
|
||||
// newaddress
|
||||
app.post('/api/lnd/newaddress', (req, res) => {
|
||||
const { lightning } = LightningServices.services
|
||||
lightning.newAddress({ type: req.body.type }, async (err, response) => {
|
||||
if (err) {
|
||||
logger.debug('NewAddress Error:', err)
|
||||
const health = await checkHealth()
|
||||
if (health.LNDStatus.success) {
|
||||
res.status(400).json({
|
||||
field: 'newAddress',
|
||||
errorMessage: sanitizeLNDError(err.message)
|
||||
})
|
||||
} else {
|
||||
res.status(500)
|
||||
res.json({ errorMessage: 'LND is down' })
|
||||
}
|
||||
}
|
||||
logger.debug('NewAddress:', response)
|
||||
res.json(response)
|
||||
})
|
||||
app.post('/api/lnd/newaddress', async (req, res) => {
|
||||
try {
|
||||
return res.json({
|
||||
address: await LV2.newAddress(req.body.type)
|
||||
})
|
||||
} catch (e) {
|
||||
return res.status(500).json({
|
||||
errorMessage: e.message
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// connect peer to lnd node
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
sendPaymentV2Keysend,
|
||||
sendPaymentV2Invoice,
|
||||
listPayments,
|
||||
decodePayReq
|
||||
decodePayReq,
|
||||
newAddress
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue