Skip to content

Commit

Permalink
ABI v2 added (#1820)
Browse files Browse the repository at this point in the history
* wip adding new decoder

* improved web3.js readme

* reworked decodeParameters

* bumped ethers version

* fixed tests

* fixed decode Log tests

* fixed decoding tests

* fixed encoding tests

* removed old encoder/decoder

* fixed all tests

* updated ether-js

* struct encoding and decoding

* decoding index params separate

* improved log decoding for indexed paramaters

* removed lock files

* fixed tests

* fixed test

* add components to contract

* Added some struct tests

* Finished decodeParameters testing

* Finished encodeParameter and encodeParameters tests

* fixed ABICoder decodeParameters

* fixed ABICoder decodeParameters

* removed console.log

* removed out commented code

* console.log removed

* decodeParameter in ABICoder fixed

* codestyle improvement

* new version of ethersjs abiCoder implemented and tested

* testcases added for structs

* package-lock removed

* encodeParameters extended for simplified format

* codestyle improvement

* simplified types added to decodeParameters

* types mapping fixed

* Started with updating of the documentation for encoding and decoding of parameters

* new abi lib tested and documentation updated

* decodeParameter/s tested and documentation updated

* package-locks fixed

* web3-eth-abi package version fixed

* gitignore updated

* web3.js removed

* modified package.lock

* documentation updated
  • Loading branch information
nivida authored and frozeman committed Aug 7, 2018
1 parent ff61411 commit 0ef6ee8
Show file tree
Hide file tree
Showing 45 changed files with 8,055 additions and 3,585 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ bower_components
/bower
.idea/
.npm/
.vscode/
.vscode/
dist/
!./dist/web3.min.js
1 change: 1 addition & 0 deletions dist/web3.min.js

Large diffs are not rendered by default.

150 changes: 145 additions & 5 deletions docs/web3-eth-abi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Encodes a parameter based on its type to its ABI representation.
Parameters
----------

1. ``type`` - ``String``: The type of the parameter, see the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
1. ``type`` - ``String|Object``: The type of the parameter, see the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``parameter`` - ``Mixed``: The actual parameter to encode.

-------
Expand Down Expand Up @@ -153,6 +153,27 @@ Example
web3.eth.abi.encodeParameter('bytes32[]', ['0xdf3234', '0xfdfd']);
> "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002df32340000000000000000000000000000000000000000000000000000000000fdfd000000000000000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameter(
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"childStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
},
{
"propertyOne": 42,
"propertyTwo": 56,
"childStruct": {
"propertyOne": 45,
"propertyTwo": 78
}
}
);
> "0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e"
------------------------------------------------------------------------------

encodeParameters
Expand All @@ -168,7 +189,7 @@ Encodes a function parameters based on its :ref:`JSON interface <glossary-json-i
Parameters
----------

1. ``typesArray`` - ``Array|Object``: An array with types or a :ref:`JSON interface <glossary-json-interface>` of a function. See the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
1. ``typesArray`` - ``Array<String|Object>|Object``: An array with types or a :ref:`JSON interface <glossary-json-interface>` of a function. See the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``parameters`` - ``Array``: The parameters to encode.

-------
Expand All @@ -187,7 +208,35 @@ Example
> "0x000000000000000000000000000000000000000000000000000000008bd02b7b0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000748656c6c6f212500000000000000000000000000000000000000000000000000"
web3.eth.abi.encodeParameters(['uint8[]','bytes32'], [['34','434'], '0x324567fff']);
> "0x0000000000000000000000000000000000000000000000000000000000000040324567fff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000001b2"
> "0x0
web3.eth.abi.encodeParameters(
[
'uint8[]',
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"ChildStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
}
],
[
['34','434'],
{
"propertyOne": '42',
"propertyTwo": '56',
"ChildStruct": {
"propertyOne": '45',
"propertyTwo": '78'
}
}
]
);
> "0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000018"
------------------------------------------------------------------------------
Expand Down Expand Up @@ -247,7 +296,7 @@ Decodes an ABI encoded parameter to its JavaScript type.
Parameters
----------
1. ``type`` - ``String``: The type of the parameter, see the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
1. ``type`` - ``String|Object``: The type of the parameter, see the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``hexString`` - ``String``: The ABI byte code to decode.
-------
Expand All @@ -268,6 +317,61 @@ Example
web3.eth.abi.decodeParameter('string', '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000');
> "Hello!%!"
web3.eth.abi.decodeParameter('string', '0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000848656c6c6f212521000000000000000000000000000000000000000000000000');
> "Hello!%!"
web3.eth.abi.decodeParameter(
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"childStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
},
, '0x000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e');
> {
'0': {
'0': '42',
'1': '56',
'2': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'childStruct': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'propertyOne': '42',
'propertyTwo': '56'
},
'ParentStruct': {
'0': '42',
'1': '56',
'2': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'childStruct': {
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'propertyOne': '42',
'propertyTwo': '56'
}
}
------------------------------------------------------------------------------
decodeParameters
Expand All @@ -283,7 +387,7 @@ Decodes ABI encoded parameters to its JavaScript types.
Parameters
----------
1. ``typesArray`` - ``Array|Object``: An array with types or a :ref:`JSON interface <glossary-json-interface>` outputs array. See the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
1. ``typesArray`` - ``Array<String|Object>|Object``: An array with types or a :ref:`JSON interface <glossary-json-interface>` outputs array. See the `solidity documentation <http://solidity.readthedocs.io/en/develop/types.html>`_ for a list of types.
2. ``hexString`` - ``String``: The ABI byte code to decode.
-------
Expand Down Expand Up @@ -315,6 +419,42 @@ Example
myNumber: '234'
}
web3.eth.abi.decodeParameters([
'uint8[]',
{
"ParentStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256',
"childStruct": {
"propertyOne": 'uint256',
"propertyTwo": 'uint256'
}
}
}
], '0x00000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000002d000000000000000000000000000000000000000000000000000000000000004e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000018');
> Result {
'0': ['42', '24'],
'1': {
'0': '42',
'1': '56',
'2':
{
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'childStruct':
{
'0': '45',
'1': '78',
'propertyOne': '45',
'propertyTwo': '78'
},
'propertyOne': '42',
'propertyTwo': '56'
}
}
------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 0ef6ee8

@nujabes403
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Please sign in to comment.