Skip to content

Commit 0edfea9

Browse files
committed
feat: update client payment comfirmed
1 parent f18c16e commit 0edfea9

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

services/chronikService.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,9 @@ export class ChronikBlockchainClient {
414414
await new Promise(resolve => setTimeout(resolve, CHRONIK_INITIALIZATION_DELAY))
415415
}
416416
if (msg.type === 'Tx') {
417+
const transaction = await this.chronik.tx(msg.txid)
418+
const addressesWithTransactions = await this.getAddressesForTransaction(transaction)
419+
const inputAddresses = this.getSortedInputAddresses(transaction)
417420
if (msg.msgType === 'TX_REMOVED_FROM_MEMPOOL') {
418421
console.log(`${this.CHRONIK_MSG_PREFIX}: [${msg.msgType}] ${msg.txid}`)
419422
const transactionsToDelete = await fetchUnconfirmedTransactions(msg.txid)
@@ -428,6 +431,13 @@ export class ChronikBlockchainClient {
428431
} else if (msg.msgType === 'TX_CONFIRMED') {
429432
console.log(`${this.CHRONIK_MSG_PREFIX}: [${msg.msgType}] ${msg.txid}`)
430433
this.confirmedTxsHashesFromLastBlock = [...this.confirmedTxsHashesFromLastBlock, msg.txid]
434+
for (const addressWithTransaction of addressesWithTransactions) {
435+
const parsedOpReturn = parseOpReturnData(addressWithTransaction.transaction.opReturn ?? '')
436+
const paymentId = parsedOpReturn.paymentId
437+
const newClientPaymentStatus = 'COMFIRMED' as ClientPaymentStatus
438+
439+
await updatePaymentStatus(paymentId, newClientPaymentStatus)
440+
}
431441
} else if (msg.msgType === 'TX_ADDED_TO_MEMPOOL') {
432442
if (this.isAlreadyBeingProcessed(msg.txid, false)) {
433443
return
@@ -437,9 +447,7 @@ export class ChronikBlockchainClient {
437447
}
438448
this.mempoolTxsBeingProcessed += 1
439449
console.log(`${this.CHRONIK_MSG_PREFIX}: [${msg.msgType}] ${msg.txid}`)
440-
const transaction = await this.chronik.tx(msg.txid)
441-
const addressesWithTransactions = await this.getAddressesForTransaction(transaction)
442-
const inputAddresses = this.getSortedInputAddresses(transaction)
450+
443451
for (const addressWithTransaction of addressesWithTransactions) {
444452
const { created, tx } = await upsertTransaction(addressWithTransaction.transaction)
445453
if (tx !== undefined) {

0 commit comments

Comments
 (0)