pending payment from hash

This commit is contained in:
boufni95 2024-10-01 15:00:26 +00:00
parent 6aa76f8881
commit d321297480
2 changed files with 25 additions and 19 deletions

View file

@ -14,7 +14,7 @@ import { AddInvoiceReq } from './addInvoiceReq.js';
import { PayInvoiceReq } from './payInvoiceReq.js';
import { SendCoinsReq } from './sendCoinsReq.js';
import { LndSettings, AddressPaidCb, InvoicePaidCb, NodeInfo, Invoice, DecodedInvoice, PaidInvoice, NewBlockCb, HtlcCb, BalanceInfo } from './settings.js';
import { getLogger } from '../helpers/logger.js';
import { ERROR, getLogger } from '../helpers/logger.js';
import { HtlcEvent_EventType } from '../../../proto/lnd/router.js';
import { LiquidityProvider, LiquidityRequest } from '../main/liquidityProvider.js';
import { Utils } from '../helpers/utilsWrapper.js';
@ -464,6 +464,25 @@ export default class {
return res.response
}
async GetPaymentFromHash(paymentHash: string): Promise<Payment | null> {
const abortController = new AbortController()
const stream = this.router.trackPaymentV2({
paymentHash: Buffer.from(paymentHash, 'hex'),
noInflightUpdates: false
}, { abort: abortController.signal })
return new Promise((res, rej) => {
stream.responses.onError(error => {
this.log(ERROR, "error with trackPaymentV2", error.message)
rej(null)
})
stream.responses.onMessage(payment => {
abortController.abort()
res(payment)
})
})
}
async ListPeers() {
const res = await this.lightning.listPeers({ latestError: true }, DeadLineMetadata())
return res.response

View file

@ -6,7 +6,7 @@ import { MainSettings } from './settings.js'
import { InboundOptionals, defaultInvoiceExpiry } from '../storage/paymentStorage.js'
import LND from '../lnd/lnd.js'
import { Application } from '../storage/entity/Application.js'
import { getLogger, PubLogger } from '../helpers/logger.js'
import { ERROR, getLogger, PubLogger } from '../helpers/logger.js'
import { UserReceivingAddress } from '../storage/entity/UserReceivingAddress.js'
import { AddressPaidCb, InvoicePaidCb, PaidInvoice } from '../lnd/settings.js'
import { UserReceivingInvoice, ZapInfo } from '../storage/entity/UserReceivingInvoice.js'
@ -124,23 +124,10 @@ export default class {
}
checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => {
if (p.paymentIndex === 0 || p.paymentIndex === -1) {
log("found a pending payment with no payment index, skipping", p.serial_id)
//const fullAmount = p.paid_amount + p.service_fees + p.routing_fees
//log("found a pending payment with no payment index, refunding", fullAmount, "sats to user", p.user.user_id)
//await this.storage.txQueue.PushToQueue({
// dbTx: true, description: "refund failed pending payment", exec: async tx => {
// await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
// await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
// }
//})
return
}
console.log({ p })
const paymentRes = await this.lnd.GetPayment(p.paymentIndex)
const payment = paymentRes.payments[0]
if (!payment || Number(payment.paymentIndex) !== p.paymentIndex) {
log("lnd payment not found for pending payment", p.serial_id, "with index", p.paymentIndex)
const decoded = await this.lnd.DecodeInvoice(p.invoice)
const payment = await this.lnd.GetPaymentFromHash(decoded.paymentHash)
if (!payment || payment.paymentHash !== decoded.paymentHash) {
log(ERROR, "lnd payment not found for pending payment hash ", decoded.paymentHash)
return
}