Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function checkInvoiceStatus(
lnd: any,
opennode: any,
invoiceId: string
): Promise {
if (!invoiceId) throw new Error('Missing invoice id.')
let status, amount, payreq, createdAt
if (lnd) {
const invoiceDetails = await lnService.getInvoice({
id: invoiceId,
lnd: lnd,
})
// for hodl invoices, status might be "is_held"
status = invoiceDetails['is_confirmed']
? 'paid'
: invoiceDetails['is_held']
? 'held'
: 'unpaid'
amount = invoiceDetails.tokens
payreq = invoiceDetails.request
createdAt = invoiceDetails.created_at
} else if (opennode) {
const data = await opennode.chargeInfo(invoiceId)
amount = data.amount
return (async () => {
try {
const {id} = await decodeSwapRecovery({recovery: args.recovery});
return getInvoice({id, lnd: getLnd.lnd}, cbk);
} catch (err) {
return cbk([400, 'FailedToDecodeSwapRecovery', {err}]);
}
})();
}