Skip to content

Commit

Permalink
TransactionRevertInstructionError added and related types updated
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida committed Dec 4, 2019
1 parent fbcde45 commit cce490a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
7 changes: 7 additions & 0 deletions packages/web3-core-helpers/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ module.exports = {
error.reason = reason;
error.signature = signature;

return error;
},
TransactionRevertInstructionError: function(reason, signature, receipt) {
var error = new Error('Transaction has been reverted by the EVM:\n' + JSON.stringify(receipt, null, 2));
error.reason = reason;
error.signature = signature;

return error;
}
};
6 changes: 6 additions & 0 deletions packages/web3-core-helpers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class errors {
static InvalidResponse(result: Error): Error;
static ConnectionTimeout(ms: string): Error;
static RevertInstructionError(reason: string, signature: string): RevertInstructionError
static TransactionRevertInstructionError(reason: string, signature: string, receipt: object): TransactionRevertInstructionError
}

export class WebsocketProviderBase {
Expand Down Expand Up @@ -188,3 +189,8 @@ export interface RevertInstructionError extends Error {
reason: string;
signature: string;
}

export interface TransactionRevertInstructionError extends Error {
reason: string;
signature: string;
}
3 changes: 3 additions & 0 deletions packages/web3-core-helpers/types/tests/errors-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ errors.ConnectionTimeout('timeout');

// $ExpectType RevertInstructionError
errors.RevertInstructionError('reason', 'signature');

// $ExpectType TransactionRevertInstructionError
errors.TransactionRevertInstructionError('reason', 'signature', {});
2 changes: 1 addition & 1 deletion packages/web3-core-method/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ Method.prototype._confirmTransaction = function (defer, result, payload) {

if (revertMessage) { // Only throw a revert error if a revert reason is existing
utils._fireError(
errors.RevertInstructionError(revertMessage.reason, revertMessage.signature),
errors.TransactionRevertInstructionError(revertMessage.reason, revertMessage.signature, receipt),
defer.eventEmitter,
defer.reject,
null,
Expand Down
6 changes: 3 additions & 3 deletions packages/web3-eth/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
LogsOptions,
PastLogsOptions
} from 'web3-core';
import {RevertInstructionError} from 'web3-core-helpers';
import {RevertInstructionError, TransactionRevertInstructionError} from 'web3-core-helpers';
import {Subscription} from 'web3-core-subscriptions';
import {AbiCoder} from 'web3-eth-abi';
import {Accounts} from 'web3-eth-accounts';
Expand Down Expand Up @@ -295,12 +295,12 @@ export class Eth {
sendTransaction(
transactionConfig: TransactionConfig,
callback?: (error: Error, hash: string) => void
): PromiEvent<TransactionReceipt | RevertInstructionError>;
): PromiEvent<TransactionReceipt | TransactionRevertInstructionError>;

sendSignedTransaction(
signedTransactionData: string,
callback?: (error: Error, hash: string) => void
): PromiEvent<TransactionReceipt | RevertInstructionError>;
): PromiEvent<TransactionReceipt>;

sign(
dataToSign: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/web3-eth/types/tests/eth.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,9 @@ eth.sendTransaction(
(error: Error, hash: string) => {}
);

// $ExpectType PromiEvent<TransactionReceipt | RevertInstructionError>
// $ExpectType PromiEvent<TransactionReceipt>
eth.sendSignedTransaction('0xf889808609184e72a0008227109');
// $ExpectType PromiEvent<TransactionReceipt | RevertInstructionError>
// $ExpectType PromiEvent<TransactionReceipt>
eth.sendSignedTransaction(
'0xf889808609184e72a0008227109',
(error: Error, hash: string) => {}
Expand Down

0 comments on commit cce490a

Please sign in to comment.