new listUnspent

This commit is contained in:
Daniel Lugo 2021-01-09 17:11:46 -04:00
parent a2fe681e18
commit f164efd2d0
3 changed files with 75 additions and 17 deletions

View file

@ -1946,22 +1946,19 @@ module.exports = async (
) )
}) })
app.post('/api/lnd/listunspent', (req, res) => { app.post('/api/lnd/listunspent', async (req, res) => {
const { lightning } = LightningServices.services try {
const { minConfirmations = 3, maxConfirmations = 6 } = req.body return res.status(200).json({
lightning.listUnspent( utxos: await LV2.listUnspent(
{ req.body.minConfirmations,
min_confs: minConfirmations, req.body.maxConfirmations
max_confs: maxConfirmations )
}, })
(err, unspent) => { } catch (e) {
if (err) { return res.status(500).json({
return handleError(res, err) errorMessage: e.message
} })
logger.debug('ListUnspent:', unspent) }
res.json(unspent)
}
)
}) })
app.get('/api/lnd/transactions', (req, res) => { app.get('/api/lnd/transactions', (req, res) => {

View file

@ -131,3 +131,35 @@ export interface Services {
walletUnlocker: Record<string, LightningMethod> walletUnlocker: Record<string, LightningMethod>
router: Record<string, LightningMethod> router: Record<string, LightningMethod>
} }
export interface Utxo {
/**
* The type of address.
*/
address_type: unknown
/**
* The address.
*/
address: string
/**
* The value of the unspent coin in satoshis.
*/
amount_sat: number
/**
* The pkscript in hex.
*/
pk_script: string
/**
* The outpoint in format txid:n.
*/
outpoint: unknown
/**
* The number of confirmations for the Utxo.
*/
confirmations: number
}

View file

@ -420,10 +420,39 @@ const newAddress = (type = 0) => {
}) })
} }
/**
* @typedef {import('./types').Utxo} Utxo
*/
/**
* @param {number} minConfs
* @param {number} maxConfs
* @returns {Promise<Utxo[]>}
*/
const listUnspent = (minConfs = 3, maxConfs = 6) =>
Common.makePromise((res, rej) => {
const { lightning } = lightningServices.getServices()
lightning.listUnspent(
{
min_confs: minConfs,
max_confs: maxConfs
},
(err, unspent) => {
if (err) {
rej(new Error(err.message))
} else {
res(unspent.utxos)
}
}
)
})
module.exports = { module.exports = {
sendPaymentV2Keysend, sendPaymentV2Keysend,
sendPaymentV2Invoice, sendPaymentV2Invoice,
listPayments, listPayments,
decodePayReq, decodePayReq,
newAddress newAddress,
listUnspent
} }