fix timeout send analitics

This commit is contained in:
Adrian Brzeziński 2024-07-05 02:09:26 +02:00
parent 82587453da
commit 67029d46ff
1 changed files with 30 additions and 24 deletions

View File

@ -3,6 +3,7 @@ import { BorshInstructionCoder } from '@project-serum/anchor'
import { Connection } from '@solana/web3.js' import { Connection } from '@solana/web3.js'
import { MANGO_DATA_API_URL } from './constants' import { MANGO_DATA_API_URL } from './constants'
import { TxCallbackOptions } from '@blockworks-foundation/mango-v4/dist/types/src/client' import { TxCallbackOptions } from '@blockworks-foundation/mango-v4/dist/types/src/client'
import { awaitTransactionSignatureConfirmation } from '@blockworks-foundation/mangolana/lib/transactions'
const coder = new BorshInstructionCoder(IDL) const coder = new BorshInstructionCoder(IDL)
@ -17,14 +18,14 @@ export function collectTxConfirmationData(
rpcEndpoint, rpcEndpoint,
prioritizationFee, prioritizationFee,
txCallbackOptions, txCallbackOptions,
).catch((e) => ).catch(() => {
txConfirmationInner( return txConfirmationInner(
start, start,
rpcEndpoint, rpcEndpoint,
prioritizationFee, prioritizationFee,
txCallbackOptions, txCallbackOptions,
), )
) })
} }
async function txConfirmationInner( async function txConfirmationInner(
@ -35,24 +36,31 @@ async function txConfirmationInner(
) { ) {
const connection = new Connection(rpcEndpoint, 'processed') const connection = new Connection(rpcEndpoint, 'processed')
const { txid: signature, txSignatureBlockHash } = txCallbackOptions const { txid: signature, txSignatureBlockHash } = txCallbackOptions
await connection.confirmTransaction( try {
{ await awaitTransactionSignatureConfirmation({
signature, txid: signature,
blockhash: txSignatureBlockHash.blockhash, confirmLevel: 'processed',
lastValidBlockHeight: txSignatureBlockHash.lastValidBlockHeight, connection: connection,
}, timeoutStrategy: {
'processed', block: txSignatureBlockHash,
) },
})
// eslint-disable-next-line no-empty
} catch (e) {}
const elapsed = new Date().getTime() - startTime const elapsed = new Date().getTime() - startTime
await connection.confirmTransaction( try {
{ await awaitTransactionSignatureConfirmation({
signature, txid: signature,
blockhash: txSignatureBlockHash.blockhash, confirmLevel: 'confirmed',
lastValidBlockHeight: txSignatureBlockHash.lastValidBlockHeight, connection: connection,
}, timeoutStrategy: {
'confirmed', block: txSignatureBlockHash,
) },
})
// eslint-disable-next-line no-empty
} catch (e) {}
const confirmedTxn = await connection.getTransaction(signature, { const confirmedTxn = await connection.getTransaction(signature, {
commitment: 'confirmed', commitment: 'confirmed',
@ -65,7 +73,7 @@ async function txConfirmationInner(
confirmedTxn?.transaction.message.compiledInstructions confirmedTxn?.transaction.message.compiledInstructions
const instructionNames = [] const instructionNames = []
if (messageInstructions) { if (messageInstructions) {
for (let ix of messageInstructions) { for (const ix of messageInstructions) {
const parsedInstruction = coder.decode(Buffer.from(ix.data)) const parsedInstruction = coder.decode(Buffer.from(ix.data))
if (parsedInstruction) { if (parsedInstruction) {
instructionNames.push(parsedInstruction.name) instructionNames.push(parsedInstruction.name)
@ -99,13 +107,11 @@ async function txConfirmationInner(
fee_lamports: confirmedTxn?.meta?.fee, fee_lamports: confirmedTxn?.meta?.fee,
} }
const resp = await fetch(`${MANGO_DATA_API_URL}/transaction-confirmation`, { await fetch(`${MANGO_DATA_API_URL}/transaction-confirmation`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },
body: JSON.stringify(data), body: JSON.stringify(data),
}) })
const body = await resp.json()
// console.log(body)
} }