Skip to content

Commit

Permalink
Fix tx overriding
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed Aug 2, 2024
1 parent a8890f9 commit a5d0a16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 9 additions & 2 deletions apps/api/src/app/jobs/updatePendingTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Transaction, TransactionDocument } from '@thxnetwork/api/models/Transac
import SafeService from '../services/SafeService';
import TransactionService from '../services/TransactionService';
import { logger } from '../util/logger';
import { Wallet } from '../models/Wallet';

export async function updatePendingTransactions() {
const transactions: TransactionDocument[] = await Transaction.find({
Expand All @@ -21,8 +22,14 @@ export async function updatePendingTransactions() {
}
case TransactionState.Sent: {
if (tx.type == TransactionType.Relayed) {
logger.debug(`Update transaction: ${tx.transactionHash}`);
await TransactionService.queryTransactionStatusReceipt(tx);
logger.debug(`Update transaction: ${tx.safeTxHash}`);
const wallet = await Wallet.findById(tx.walletId);
if (!wallet) {
logger.debug(`Wallet removed: ${tx.walletId}`);
continue;
}

await SafeService.updateTransactionState(wallet, tx.safeTxHash);
}
break;
}
Expand Down
16 changes: 12 additions & 4 deletions apps/api/src/app/services/SafeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,19 @@ class SafeService {

try {
const response = await safe.executeTransaction(safeTx);
const receipt = await response.transactionResponse.wait();
const receipt = await response.transactionResponse.wait(2);
if (!receipt) throw new Error(`No receipt found for ${tx.safeTxHash}`);
if (!receipt.transactionHash) throw new Error(`No transactionHash found for ${tx.safeTxHash}`);

await tx.updateOne({ transactionHash: receipt.transactionHash, state: TransactionState.Sent });

logger.debug('Transaction executed', {
safeTxHash: tx.safeTxHash,
transactionHash: receipt.transactionHash,
});
} catch (error) {
// Suppress non breaking gas estimation error and start polling for state
if (error.message.includes('GS026')) {
// Suppress non breaking gas estimation error on Hardhat and start polling for state
if (tx.chainId === ChainId.Hardhat && error.message.includes('GS026')) {
await tx.updateOne({ state: TransactionState.Sent });
} else {
throw error;
Expand All @@ -242,7 +248,9 @@ class SafeService {
const isSent = tx.state === TransactionState.Sent;

if (isSent && safeTx.isExecuted && safeTx.isSuccessful) {
await TransactionService.queryTransactionStatusReceipt(tx);
await TransactionService.queryTransactionStatusReceipt(
await tx.updateOne({ transactionHash: tx.transactionHash }, { new: true }),
);
logger.debug('Transaction success', { safeTx });
}

Expand Down

0 comments on commit a5d0a16

Please sign in to comment.