Skip to content

Commit

Permalink
arc define failure and success statuses
Browse files Browse the repository at this point in the history
Signed-off-by: Deggen <[email protected]>
  • Loading branch information
sirdeggen committed Feb 21, 2025
1 parent 6e14944 commit 0832a97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions back/src/functions/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import { Request, Response } from 'express'
import db from '../db'
import { MerklePath, Beef, Transaction } from '@bsv/sdk'
import { MerklePath, Beef } from '@bsv/sdk'

const defineFailure = ['SEEN_IN_ORPHAN_MEMPOOL', 'DOUBLE_SPEND_ATTEMPTED', 'REJECTED']

export default async function (req: Request, res: Response) {
try {
Expand All @@ -30,7 +32,7 @@ export default async function (req: Request, res: Response) {

const { txid, merklePath, txStatus } = req.body

if (txStatus === 'REJECTED') {
if (defineFailure.includes(txStatus)) {
// delete utxos associated with the txid
await db.collection('utxos').deleteMany({ txid })
await db.collection('txs').updateOne({ txid }, { $addToSet: { arc: req.body } })
Expand Down
12 changes: 9 additions & 3 deletions back/src/functions/integrity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ const { NETWORK } = process.env

const blockHeaderService = new WhatsOnChain(NETWORK as "main" | "test" | "stn")

const defineSuccess = ['SENT_TO_NETWORK', 'ACCEPTED_BY_NETWORK', 'SEEN_ON_NETWORK', 'MINED']
const defineFailure = ['SEEN_IN_ORPHAN_MEMPOOL', 'DOUBLE_SPEND_ATTEMPTED', 'REJECTED']

/**
*
* @method verifyTipScript
Expand Down Expand Up @@ -103,9 +106,12 @@ export default async function (req: Request, res: Response) {
}
if (!inBlock) {
try {
let arcStatus = arc[0].status === 'success'
console.log({ arcStatus })
broadcast = await verifyTipScript(tx) || arcStatus
let arcSuccess = false
if (defineSuccess.includes(arc?.[0]?.message)) {
arcSuccess = true
}
console.log({ arcSuccess, status: arc?.[0] })
broadcast = await verifyTipScript(tx) || arcSuccess
} catch (error) {
console.error('Broadcast verification error:', error)
}
Expand Down

0 comments on commit 0832a97

Please sign in to comment.