new listUnspent
This commit is contained in:
parent
a2fe681e18
commit
f164efd2d0
3 changed files with 75 additions and 17 deletions
|
|
@ -1946,23 +1946,20 @@ 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) => {
|
|
||||||
if (err) {
|
|
||||||
return handleError(res, err)
|
|
||||||
}
|
|
||||||
logger.debug('ListUnspent:', unspent)
|
|
||||||
res.json(unspent)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
} catch (e) {
|
||||||
|
return res.status(500).json({
|
||||||
|
errorMessage: e.message
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/api/lnd/transactions', (req, res) => {
|
app.get('/api/lnd/transactions', (req, res) => {
|
||||||
const { lightning } = LightningServices.services
|
const { lightning } = LightningServices.services
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue