Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE `Transaction` ADD COLUMN `orphaned` BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions prisma-local/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ model Transaction {
hash String @db.VarChar(255)
amount Decimal @db.Decimal(24, 8)
confirmed Boolean @default(false)
orphaned Boolean @default(false)
timestamp Int
addressId String
opReturn String @db.LongText @default("")
Expand Down
12 changes: 10 additions & 2 deletions services/chronikService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createManyTransactions,
deleteTransactions,
fetchUnconfirmedTransactions,
markTransactionsOrphaned,
upsertTransaction,
getSimplifiedTransactions,
getSimplifiedTrasaction
Expand Down Expand Up @@ -632,8 +633,15 @@ export class ChronikBlockchainClient {
const { amount, opReturn } = addressWithTransaction.transaction
await this.handleUpdateClientPaymentStatus(amount, opReturn, 'CONFIRMED' as ClientPaymentStatus, addressWithTransaction.address.address)
}
} catch (e) {
console.error(`${this.CHRONIK_MSG_PREFIX}: confirmed tx handler failed for ${msg.txid}`, e)
} catch (e: any) {
const msg404 = String(e?.message ?? e)
const is404 = /not found in the index|404/.test(msg404)
if (is404) {
console.log(`${this.CHRONIK_MSG_PREFIX}: [${msg.msgType}] tx ${msg.txid} not found in chronik, marking as orphaned`)
await markTransactionsOrphaned(msg.txid)
} else {
console.error(`${this.CHRONIK_MSG_PREFIX}: confirmed tx handler failed for ${msg.txid}`, e)
}
}
} else if (msg.msgType === 'TX_ADDED_TO_MEMPOOL') {
if (this.isAlreadyBeingProcessed(msg.txid, false)) return
Expand Down
11 changes: 11 additions & 0 deletions services/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ export async function deleteTransactions (transactions: TransactionWithAddressAn
))
}

export async function markTransactionsOrphaned (hash: string): Promise<void> {
await prisma.transaction.updateMany({
where: {
hash
},
data: {
orphaned: true
}
})
}

async function fetchAllTransactionsWithNoPrices (): Promise<TransactionWithNetwork[]> {
const x = await prisma.transaction.findMany({
where: {
Expand Down