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

View file

@ -131,3 +131,35 @@ export interface Services {
walletUnlocker: 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 = {
sendPaymentV2Keysend,
sendPaymentV2Invoice,
listPayments,
decodePayReq,
newAddress
newAddress,
listUnspent
}