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

refactor: new abi #81

Merged
merged 2 commits into from
Aug 18, 2022
Merged

refactor: new abi #81

merged 2 commits into from
Aug 18, 2022

Conversation

moraleinside
Copy link
Contributor

@moraleinside moraleinside commented Aug 14, 2022

Breaking change

  • Function abi.encodeParameter will return complete encoding including the dynamic prefix. Compared with the old version, the result will be the same as abi.encodeParameters with one parameter.
    Similarly, abi.decodeParameter will accept the decoding data including the dynamic prefix.
    This only affects on dynamic types. e.g. dynamic array(uint256[], bytes32[], address[], tokenId[]… etc.), string and bytes.

Old behavior: encodeParameter and decodeParameter did not take dynamic prefix into account.

  • For types with <M>, e.g. int<M>/uint<M>/bytes<M>, decoding of such types will strictly follow the type length, the extra-long data will be cut off.
    Example:
    Decoding ‘fffffffffffff38dd0f10627f5529bdb2c52d4846810af0ac000000000000001’ to int8 will result in 1.

Old behavior: Throw an error.

  • Function utils.isHexString
    will return false for non-string input such as integers.
    Example:
    isHexString(1) will result in false.

Old behavior: isHexString(1) returned true.

  • Function abi.decodeLog will not be used to decode function data. As the name indicates, it should only decode event logs.

Old behavior: This function can also be used to decode function calls, which makes it confusing to use.

New feature

  • Encoding and decoding of dynamic arrays, e.g. string[]
  • Encoding and decoding of multi-dimension arrays, e.g. int256[2][][3]
  • Encoding and decoding of structs
  • Creating log filters
  • More abi types

New function export

  • abi.decodeFunctionCall
  • abi.decodeFunctionOutput
  • abi.encodeOffchainCall
  • abi.decodeOffchainOutput
  • abi.encodeConstructor
  • abi.encodeLogFilter

New module export

  • abi.Abi
  • abi.utils

Known issue

When calling abi.encodeLogFilter, using arrays (esp. dynamic arrays) as indexed topic may cause different encoding results at the moment. You should avoid using arrays as indexed event parameter in your contract. If an array must be used, use static array.


See test/package/abi.js for more specific usage and examples.

re #77

@coveralls
Copy link

coveralls commented Aug 14, 2022

Pull Request Test Coverage Report for Build 2877659064

  • 1348 of 1480 (91.08%) changed or added relevant lines in 18 files are covered.
  • 81 unchanged lines in 11 files lost coverage.
  • Overall coverage increased (+0.05%) to 86.786%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/abi/coder/boolean.ts 9 10 90.0%
src/abi/coder/gid.ts 12 13 92.31%
src/abi/coder/null.ts 12 13 92.31%
src/abi/coder/number.ts 30 31 96.77%
src/abi/coder/tokenId.ts 12 13 92.31%
src/abi/coder/bytes.ts 32 34 94.12%
src/abi/coder/tuple.ts 40 42 95.24%
src/abi/index.ts 75 77 97.4%
src/abi/utils.ts 91 93 97.85%
src/accountBlock/utils.ts 29 31 93.55%
Files with Coverage Reduction New Missed Lines %
src/keystore/tools.ts 1 88.57%
src/wallet/index.ts 2 78.57%
src/utils/ed25519.ts 3 81.82%
src/wallet/hdKey.ts 3 79.45%
src/keystore/decrypt.ts 5 70.31%
src/wallet/address.ts 6 89.08%
src/wallet/wallet.ts 6 78.87%
src/utils/index.ts 8 86.96%
src/keystore/encrypt.ts 9 83.33%
src/keystore/validated.ts 16 76.43%
Totals Coverage Status
Change from base Build 2766952115: 0.05%
Covered Lines: 2202
Relevant Lines: 2423

💛 - Coveralls

@moraleinside moraleinside merged commit 69ca52a into dev/2.3.19 Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants