Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let _description
if (boltwallConfig && boltwallConfig.getInvoiceDescription)
_description = await boltwallConfig.getInvoiceDescription(req)
let invoice: InvoiceResponse
if (lnd) {
const {
request: payreq,
id,
description = _description,
created_at: createdAt,
tokens: amount,
} = await lnService.createInvoice({
lnd: lnd,
description: _description,
expires_at: expiresAt,
tokens,
})
invoice = { payreq, id, description, createdAt, amount }
} else if (opennode) {
const {
lightning_invoice: { payreq },
id,
description,
created_at: createdAt,
amount,
} = await opennode.createCharge({
description: _description,
amount: tokens,
createInvoice: ['getChannel', ({l}, cbk) => createInvoice({lnd}, cbk)],
if (args.tokens > getLimits.max_tokens) {
return cbk([400, 'AmountTooHighToSwap', {max: getLimits.max_tokens}]);
}
if (args.tokens < getLimits.min_tokens) {
return cbk([400, 'AmountTooLowToSwap', {min: getLimits.min_tokens}]);
}
const {fee} = getQuote;
if (!!args.max_fee && fee > args.max_fee) {
return cbk([400, 'MaxFeeExceededForSwap', {required_fee: fee}]);
}
return createInvoice({
description: `Submarine swap. Service fee: ${fee}`,
expires_at: new Date(now() + msPerYear).toISOString(),
is_including_private_channels: true,
lnd: getLnd.lnd,
tokens: args.tokens - fee,
},
cbk);
}],
({parsedInvoice, lnd}, cbk) =>
{
const {id} = parsedInvoice;
return createInvoice({
lnd,
expires_at: new Date(Date.now() + paymentTimeoutMs).toISOString(),
secret: id,
tokens: dummyLockingInvoiceValue,
},
cbk);
}],
invoice: ['channels', 'findRoute', 'lnd', ({findRoute, lnd}, cbk) => {
return createInvoice({
lnd,
cltv_delta: cltvDelta,
description: 'Rebalance',
tokens: min(maxRebalanceTokens, findRoute.route_maximum),
},
cbk);
}],