Skip to content

Commit

Permalink
Merge cce490a into efc0a9b
Browse files Browse the repository at this point in the history
  • Loading branch information
nivida committed Dec 4, 2019
2 parents efc0a9b + cce490a commit 6caedc6
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 220 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Released with 1.0.0-beta.37 code base.
- ``eth_getProof`` as ``getProof`` added to web3-eth package (#3220)
- ``BN`` and ``BigNumber`` objects are now supported by the ``abi.encodeParameter(s)`` method (#3238)
- ``getPendingTransactions`` added to web3-eth package (#3239)
- Revert instruction handling added which can get activated with the ``handleRevert`` module property (#3248)

### Changed

Expand Down
20 changes: 20 additions & 0 deletions docs/web3-eth-contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,26 @@ Returns

------------------------------------------------------------------------------

.. _eth-contract-module-handlerevert:

handleRevert
============

.. code-block:: javascript
web3.eth.Contract.handleRevert
contract.handleRevert // on contract instance
The ``handleRevert`` options property does default to ``false`` and will return the revert reason string if enabled on :ref:`send <contract-send>` or :ref:`call <contract-call>` of a contract method.

-------
Returns
-------

``boolean``: The current value of ``handleRevert`` (default: false)

------------------------------------------------------------------------------

options
=========

Expand Down
26 changes: 26 additions & 0 deletions docs/web3-eth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,32 @@ Returns

------------------------------------------------------------------------------

.. _web3-module-handlerevert:

handleRevert
============

.. code-block:: javascript
web3.eth.handleRevert
The ``handleRevert`` options property does default to ``false`` and will return the revert reason string if enabled for the following methods:

- :ref:`web3.eth.call() <eth-call>`
- :ref:`web3.eth.sendTransaction() <eth-sendtransaction>`
- :ref:`web3.eth.sendSignedTransaction() <eth-sendsignedtransaction>`
- :ref:`contract.methods.myMethod(...).send(...) <contract-send>`
- :ref:`contract.methods.myMethod(...).call(...) <contract-call>`


-------
Returns
-------

``boolean``: The current value of ``handleRevert`` (default: false)

------------------------------------------------------------------------------

getProtocolVersion
=====================

Expand Down
14 changes: 14 additions & 0 deletions packages/web3-core-helpers/src/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,19 @@ module.exports = {
},
ConnectionTimeout: function (ms){
return new Error('CONNECTION TIMEOUT: timeout of ' + ms + ' ms achived');
},
RevertInstructionError: function(reason, signature) {
var error = new Error('Your request got reverted with the following reason string: ' + reason);
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;
}
};
12 changes: 12 additions & 0 deletions packages/web3-core-helpers/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class errors {
static InvalidProvider(): Error;
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 @@ -182,3 +184,13 @@ export interface JsonRpcResponse {
result?: any;
error?: string;
}

export interface RevertInstructionError extends Error {
reason: string;
signature: string;
}

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

// $ExpectType Error
errors.ConnectionTimeout('timeout');

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

// $ExpectType TransactionRevertInstructionError
errors.TransactionRevertInstructionError('reason', 'signature', {});
Loading

0 comments on commit 6caedc6

Please sign in to comment.