Skip to content

Commit

Permalink
fix(trigger): early return on lnd connection issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Feb 9, 2024
1 parent 58955fa commit 16d3972
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions core/api/src/app/wallets/update-single-pending-invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ const updatePendingInvoiceBeforeFinally = async ({
})

const lndService = LndService()
if (lndService instanceof Error) return lndService
if (lndService instanceof Error) {
pendingInvoiceLogger.error("Unable to initialize LndService")
recordExceptionInCurrentSpan({ error: lndService })
return false
}
const lnInvoiceLookup = await lndService.lookupInvoice({ pubkey, paymentHash })
if (lnInvoiceLookup instanceof InvoiceNotFoundError) {
const processingCompletedInvoice =
Expand Down Expand Up @@ -226,19 +230,6 @@ const lockedUpdatePendingInvoiceSteps = async ({
"invoices.finalRecipient": JSON.stringify(recipientWalletDescriptor),
})

if (!isSettledInLnd) {
const lndService = LndService()
if (lndService instanceof Error) return lndService
const invoiceSettled = await lndService.settleInvoice({
pubkey: walletInvoiceInsideLock.pubkey,
secret: walletInvoiceInsideLock.secret,
})
if (invoiceSettled instanceof Error) return invoiceSettled
}

const invoicePaid = await walletInvoices.markAsPaid(paymentHash)
if (invoicePaid instanceof Error) return invoicePaid

const recipientAccount = await AccountsRepository().findById(recipientAccountId)
if (recipientAccount instanceof Error) return recipientAccount
const { displayCurrency: recipientDisplayCurrency } = recipientAccount
Expand Down Expand Up @@ -280,6 +271,27 @@ const lockedUpdatePendingInvoiceSteps = async ({
displayCurrency: recipientDisplayCurrency,
})

if (!isSettledInLnd) {
const lndService = LndService()
if (lndService instanceof Error) {
logger.error("Unable to initialize LndService")
recordExceptionInCurrentSpan({ error: lndService })
return false
}
const invoiceSettled = await lndService.settleInvoice({
pubkey: walletInvoiceInsideLock.pubkey,
secret: walletInvoiceInsideLock.secret,
})
if (invoiceSettled instanceof Error) {
logger.error({ paymentHash }, "Unable to settleInvoice")
recordExceptionInCurrentSpan({ error: invoiceSettled })
return false
}
}

const invoicePaid = await walletInvoices.markAsPaid(paymentHash)
if (invoicePaid instanceof Error) return invoicePaid

//TODO: add displayCurrency: displayPaymentAmount.currency,
const journal = await LedgerFacade.recordReceiveOffChain({
description,
Expand Down

0 comments on commit 16d3972

Please sign in to comment.