Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds revert instruction handling #3248

Merged
merged 25 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
30cf8af
revert reason string handling added
nivida Nov 27, 2019
d74843e
method.isRevertReasonString simplified
nivida Nov 28, 2019
182783e
method.getRevertReason funcDoc added and return values improved
nivida Nov 28, 2019
854e579
types extended with RevertInstructionError in core-helpers module
nivida Nov 28, 2019
8dcc9d7
web3-eth types updated
nivida Nov 28, 2019
7c246cb
error handling in Method object of the web3-core-method module fixed
nivida Nov 28, 2019
3c2b6b2
Method.isRevertReasonString updated
nivida Nov 28, 2019
523c811
Merge branch '1.x' into feature/revert-reason-string
nivida Dec 2, 2019
b63fca3
console.log added to test case to check the solely remotely failing t…
nivida Dec 2, 2019
04156ae
handleRevert module option added to eth and eth-contract. Duplicated …
nivida Dec 2, 2019
357b59e
Basic contract updated, handleRevert option handling fixed, and e2e.m…
nivida Dec 2, 2019
5f67c48
revert instruction test cases added to e2e.method.call and assertions…
nivida Dec 2, 2019
2561b81
eth.handleRevert test added
nivida Dec 2, 2019
62a8214
Inline comments added to the Method object because of the code comple…
nivida Dec 2, 2019
4e5f4c8
web3-eth and web3-eth-contract documentation extended with 'handleRev…
nivida Dec 2, 2019
842e2b8
CHANGELOG.md updated
nivida Dec 2, 2019
9db572c
Contract options extended to be able to configure singles contracts w…
nivida Dec 2, 2019
ec5f803
Merge branch '1.x' into feature/revert-reason-string
nivida Dec 4, 2019
d76c6eb
'eth_sendRawTransaction' does get ignored for the revert handling, in…
nivida Dec 4, 2019
fbcde45
Merge branch 'feature/revert-reason-string' of github.com:ethereum/we…
nivida Dec 4, 2019
cce490a
TransactionRevertInstructionError added and related types updated
nivida Dec 4, 2019
eba77c2
logic checked if the transaction does get signed locally on call of '…
nivida Dec 4, 2019
0623f2c
contract options handling improved, contract test extended, and relat…
nivida Dec 4, 2019
7fb7b0c
web3-eth.rst updated
nivida Dec 4, 2019
b0b7f3a
hint about the 'reason' and 'signature' property of the returnd error…
nivida Dec 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 29 additions & 0 deletions docs/web3-eth-contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,28 @@ 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.

.. note:: The revert reason string and the signature does exist as property on the returned error.

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

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

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

options
=========

Expand All @@ -383,6 +405,13 @@ Properties
- ``from`` - ``String``: The address transactions should be made from.
- ``gasPrice`` - ``String``: The gas price in wei to use for transactions.
- ``gas`` - ``Number``: The maximum gas provided for a transaction (gas limit).
- ``handleRevert`` - ``Boolean``: It will otherwise use the default value provided from the Eth module. See :ref:`handleRevert <eth-contract-module-handlerevert>`.
- ``transactionBlockTimeout`` - ``Number``: It will otherwise use the default value provided from the Eth module. See :ref:`transactionBlockTimeout <eth-contract-transactionblocktimeout>`.
- ``transactionConfirmationBlocks`` - ``Number``: It will otherwise use the default value provided from the Eth module. See :ref:`transactionConfirmationBlocks <eth-contract-module-transactionconfirmationblocks>`.
- ``transactionPollingTimeout`` - ``Number``: It will otherwise use the default value provided from the Eth module. See :ref:`transactionPollingTimeout <eth-contract-module-transactionpollingtimeout>`.
- ``chain`` - ``Number``: It will otherwise use the default value provided from the Eth module. See :ref:`defaultChain <eth-contract-defaultchain>`.
- ``hardfork`` - ``Number``: It will otherwise use the default value provided from the Eth module. See :ref:`defaultHardfork <eth-contract-defaulthardfork>`.
- ``common`` - ``Number``: It will otherwise use the default value provided from the Eth module. See :ref:`defaultCommon <eth-contract-defaultcommon>`.


-------
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:`contract.methods.myMethod(...).send(...) <contract-send>`
- :ref:`contract.methods.myMethod(...).call(...) <contract-call>`

.. note:: The revert reason string and the signature does exist as property on the returned error.

-------
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);
nivida marked this conversation as resolved.
Show resolved Hide resolved
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