Skip to content

Commit

Permalink
Fixed receipt wait not throwing on reverted transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Aug 2, 2023
1 parent ff80b04 commit 25fef4f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
24 changes: 20 additions & 4 deletions src.ts/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,12 +1460,27 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
return;
};

const checkReceipt = (receipt: null | TransactionReceipt) => {
if (receipt == null || receipt.status !== 0) { return receipt; }
assert(false, "transaction execution reverted", "CALL_EXCEPTION", {
action: "sendTransaction",
data: null, reason: null, invocation: null, revert: null,
transaction: {
to: receipt.to,
from: receipt.from,
data: "" // @TODO: in v7, split out sendTransaction properties
}, receipt
});
};

const receipt = await this.provider.getTransactionReceipt(this.hash);

if (confirms === 0) { return receipt; }
if (confirms === 0) { return checkReceipt(receipt); }

if (receipt) {
if ((await receipt.confirmations()) >= confirms) { return receipt; }
if ((await receipt.confirmations()) >= confirms) {
return checkReceipt(receipt);
}

} else {
// Check for a replacement; throws if a replacement was found
Expand Down Expand Up @@ -1496,9 +1511,10 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
// Done; return it!
if ((await receipt.confirmations()) >= confirms) {
cancel();
resolve(receipt);
try {
resolve(checkReceipt(receipt));
} catch (error) { reject(error); }
}

};
cancellers.push(() => { this.provider.off(this.hash, txListener); });
this.provider.on(this.hash, txListener);
Expand Down
12 changes: 10 additions & 2 deletions src.ts/utils/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ export interface UnexpectedArgumentError extends EthersError<"UNEXPECTED_ARGUMEN
// Blockchain Errors

/**
* The action that resulted in the error.
* The action that resulted in the call exception.
*/
export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "unknown";
export type CallExceptionAction = "call" | "estimateGas" | "getTransactionResult" | "sendTransaction" | "unknown";

/**
* The related transaction that caused the error.
Expand All @@ -402,6 +402,7 @@ export type CallExceptionTransaction = {
* This **Error** indicates a transaction reverted.
*/
export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> {

/**
* The action being performed when the revert was encountered.
*/
Expand Down Expand Up @@ -439,8 +440,15 @@ export interface CallExceptionError extends EthersError<"CALL_EXCEPTION"> {
name: string;
args: Array<any>;
}

/**
* If the error occurred in a transaction that was mined
* (with a status of ``0``), this is the receipt.
*/
receipt?: TransactionReceipt; // @TODO: in v7, make this `null | TransactionReceipt`
}


/**
* The sending account has insufficient funds to cover the
* entire transaction cost.
Expand Down

0 comments on commit 25fef4f

Please sign in to comment.