Skip to content

Commit

Permalink
fix: preserve transaction hash when creating new process (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov authored Jan 14, 2025
1 parent ec7ab5c commit 7e8c829
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
11 changes: 8 additions & 3 deletions src/core/EVM/EVMStepExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ export class EVMStepExecutor extends BaseStepExecutor {
}

// Wait for the transaction status on the destination chain
const transactionHash = process.txHash
if (!transactionHash) {
throw new Error('Transaction hash is undefined.')
}
if (isBridgeExecution) {
process = this.statusManager.findOrCreateProcess({
step,
Expand All @@ -426,9 +430,10 @@ export class EVMStepExecutor extends BaseStepExecutor {

await waitForDestinationChainTransaction(
step,
process,
this.statusManager,
toChain
process.type,
transactionHash,
toChain,
this.statusManager
)

// DONE
Expand Down
11 changes: 8 additions & 3 deletions src/core/Solana/SolanaStepExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ export class SolanaStepExecutor extends BaseStepExecutor {
}

// Wait for the transaction status on the destination chain
const transactionHash = process.txHash
if (!transactionHash) {
throw new Error('Transaction hash is undefined.')
}
if (isBridgeExecution) {
process = this.statusManager.findOrCreateProcess({
step,
Expand All @@ -229,9 +233,10 @@ export class SolanaStepExecutor extends BaseStepExecutor {

await waitForDestinationChainTransaction(
step,
process,
this.statusManager,
toChain
process.type,
transactionHash,
toChain,
this.statusManager
)

// DONE
Expand Down
9 changes: 7 additions & 2 deletions src/core/UTXO/UTXOStepExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ export class UTXOStepExecutor extends BaseStepExecutor {
}

// Wait for the transaction status on the destination chain
const transactionHash = process.txHash
if (!transactionHash) {
throw new Error('Transaction hash is undefined.')
}
if (isBridgeExecution) {
process = this.statusManager.findOrCreateProcess({
step,
Expand All @@ -275,9 +279,10 @@ export class UTXOStepExecutor extends BaseStepExecutor {

await waitForDestinationChainTransaction(
step,
process,
this.statusManager,
process.type,
transactionHash,
toChain,
this.statusManager,
10_000
)

Expand Down
24 changes: 12 additions & 12 deletions src/core/waitForDestinationChainTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
ExtendedChain,
ExtendedTransactionInfo,
FullStatusData,
Process,
ProcessType,
} from '@lifi/types'
import { LiFiErrorCode } from '../errors/constants.js'
import { getTransactionFailedMessage } from '../utils/getTransactionMessage.js'
Expand All @@ -12,28 +12,25 @@ import { waitForTransactionStatus } from './waitForTransactionStatus.js'

export async function waitForDestinationChainTransaction(
step: LiFiStepExtended,
process: Process,
statusManager: StatusManager,
processType: ProcessType,
transactionHash: string,
toChain: ExtendedChain,
statusManager: StatusManager,
pollingInterval?: number
): Promise<LiFiStepExtended> {
if (!process.txHash) {
throw new Error('Transaction hash is undefined.')
}

try {
const statusResponse = (await waitForTransactionStatus(
process.txHash,
transactionHash,
statusManager,
process.type,
processType,
step,
pollingInterval
)) as FullStatusData

const statusReceiving = statusResponse.receiving as ExtendedTransactionInfo

// Update process status
statusManager.updateProcess(step, process.type, 'DONE', {
statusManager.updateProcess(step, processType, 'DONE', {
substatus: statusResponse.substatus,
substatusMessage: statusResponse.substatusMessage,
txHash: statusReceiving?.txHash,
Expand Down Expand Up @@ -62,9 +59,12 @@ export async function waitForDestinationChainTransaction(

return step
} catch (e: unknown) {
const htmlMessage = await getTransactionFailedMessage(step, process.txLink)
const htmlMessage = await getTransactionFailedMessage(
step,
`${toChain.metamask.blockExplorerUrls[0]}tx/${transactionHash}`
)

statusManager.updateProcess(step, process.type, 'FAILED', {
statusManager.updateProcess(step, processType, 'FAILED', {
error: {
code: LiFiErrorCode.TransactionFailed,
message:
Expand Down

0 comments on commit 7e8c829

Please sign in to comment.