Skip to content

Commit

Permalink
fix: transaction status pending
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed Nov 30, 2021
1 parent 0e0f126 commit 198d82b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7,418 deletions.
12 changes: 6 additions & 6 deletions src/provider/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,24 +265,24 @@ export class Provider implements ProviderInterface {
});
}

public async waitForTx(txHash: BigNumberish, retryInterval: number = 10000) {
public async waitForTx(txHash: BigNumberish, retryInterval: number = 8000) {
let onchain = false;
let firstRun = true;
while (!onchain) {
// eslint-disable-next-line no-await-in-loop
await wait(retryInterval);
// eslint-disable-next-line no-await-in-loop
const res = await this.getTransactionStatus(txHash);

if (res.tx_status === 'ACCEPTED_ONCHAIN' || res.tx_status === 'PENDING') {
if (
res.tx_status === 'ACCEPTED_ONCHAIN' ||
(res.tx_status === 'PENDING' && res.block_hash !== 'pending') // This is needed as of today. In the future there will be a different status for pending transactions.
) {
onchain = true;
} else if (res.tx_status === 'REJECTED') {
throw Error('REJECTED');
} else if (res.tx_status === 'NOT_RECEIVED' && !firstRun) {
} else if (res.tx_status === 'NOT_RECEIVED') {
throw Error('NOT_RECEIVED');
}
firstRun = false;
}
await wait(retryInterval);
}
}
10 changes: 5 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export type CallContractResponse = {
export type GetBlockResponse = {
sequence_number: number;
state_root: string;
block_id: number;
block_hash: string;
transactions: {
[txHash: string]: Transaction;
};
timestamp: number;
transaction_receipts: {
[txHash: string]: {
block_id: number;
block_hash: string;
transaction_hash: string;
l2_to_l1_messages: {
to_address: string;
Expand All @@ -80,7 +80,7 @@ export type GetBlockResponse = {
transaction_index: number;
};
};
previous_block_id: number;
previous_block_hash: string;
status: Status;
};

Expand All @@ -91,13 +91,13 @@ export type GetCodeResponse = {

export type GetTransactionStatusResponse = {
tx_status: Status;
block_id: number;
block_hash: string;
};

export type GetTransactionResponse = {
status: Status;
transaction: Transaction;
block_id: number;
block_hash: string;
block_number: number;
transaction_index: number;
transaction_hash: string;
Expand Down
Loading

0 comments on commit 198d82b

Please sign in to comment.