Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

update abi-gen with new method interfaces #2325

Merged
merged 23 commits into from
Nov 14, 2019
Merged

Conversation

xianny
Copy link
Contributor

@xianny xianny commented Nov 8, 2019

Description

🚨This is a breaking change! 🚨

This PR changes wrapper method interfaces. Motivations:
a) Make wrapper docs size smaller. They are currently too large to upload
b) Make code smaller and more readable
c) Hopefully make methods easier to call and more abstractable

Old interface:

const result = await someContract.someMethod(args1, args2, args3, ...).callAsync();
const txReceipt = await someContract.someMethod(args1, args2, args3, ...).awaitTransactionSuccessAsync();

New interface:

const contractFn = someContract.someMethod(args1, args2, args3, ...);
const result = await contractFn.callAsync();
const txReceipt = await contractFn.awaitTransactionSuccessAsync();

🚨This is a breaking change! 🚨

This PR includes refactors to existing usages. We have a lot of open PRs right now in the leadup to V3 launch and code freeze. I've tried to reconcile changes as much as possible, but currently open PRs will have to be rebased and updated.

Useful regex-es for replacing (works in VisualStudio):

// first line is capture, second line is replace

// move args to before method call, repeat with sendTransactionAsync and awaitTransactionSuccessAsync
\.callAsync(\(.*[a-z]+.*\))
$1.callAsync()

// also use with getABIDecodedReturnData
\.(\w+)\.getABIDecodedTransactionData
.getABIDecodedTransactionData().$1

// all the rest can also be used with sendTransactionAsync
==========
// move multiline args (pair with the following regex!)
\.awaitTransactionSuccessAsync\((\n(\s+(.)+,\n)+\s+)\)
($1).awaitTransactionSuccessAsync()

// then move the txData captured from previous regex, back to method call
(\{ .* \}),\n\s+\).awaitTransactionSuccessAsync\(\)
).awaitTransactionSuccessAsync($1)

// move single line args and preserve multiline txdata
.awaitTransactionSuccessAsync\((.*), \{\n
($1).awaitTransactionSuccessAsync({\n

// move multiline args with multiline tx data
\.awaitTransactionSuccessAsync\(((\n\s+.+,)+)
($1\n).awaitTransactionSuccessAsync(

Do Ctrl + Shift + H and select the Regex option. Use at your own risk! I recommend previewing changes before large batch replaces.
Some gotchas:

  • ignore web3Wrapper.awaitTransactionSuccessAsync, web3Wrapper.sendTransactionAsync
  • funky stuff can happen with multi-line args
  • funky stuff can happen with special chars in args, especially multiple closing parens, e.g. someContract.someMethod(..., new BigNumber(1)).callAsync()

Impact on markdown size

BEFORE ALL:

contract-wrappers: 825kb
0x.js: 523kb
order-utils: 129kb

BEFORE (after cut more wrappers):

contract-wrappers: 694kb
0x.js: 505kb
order-utils: 89kb

AFTER (wrappers re-factor):

contract-wrappers: 344kb
0x.js: 274kb
order-utils: 89kb

contract-wrappers overall decline: 58%
0x.js: 47%

Testing instructions

CI should pass 🤞

Reviewers should give more attention to unusual function call patterns as there are more likely to be mistakes there. e.g. function calls abstracted away by test helpers.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.
  • Update documentation as needed.
  • Add new entries to the relevant CHANGELOG.jsons.

@xianny xianny force-pushed the refactor/abi-gen-wrappers branch 2 times, most recently from bcb5686 to 9d37c22 Compare November 13, 2019 01:45
@xianny xianny force-pushed the refactor/abi-gen-wrappers branch from 9d37c22 to d58b770 Compare November 13, 2019 01:55
@xianny xianny force-pushed the refactor/abi-gen-wrappers branch from d58b770 to 1ee22b3 Compare November 13, 2019 12:26
@buildsize
Copy link

buildsize bot commented Nov 13, 2019

File name Previous Size New Size Change
init.py 26.91 KB 26.91 KB 0 bytes (0%)
abi_gen_dummy.ts 184.89 KB [deleted]
lib_dummy.ts 5.23 KB [deleted]
test_lib_dummy.ts 14.8 KB [deleted]
environment.pickle 1.61 MB 1.61 MB 0 bytes (0%)
index.doctree 184.8 KB 184.8 KB 0 bytes (0%)
.buildinfo 230 bytes 230 bytes 0 bytes (0%)
genindex.html 5.6 KB 5.6 KB 0 bytes (0%)
index.html 2.52 KB 2.52 KB 0 bytes (0%)
objects.inv 375 bytes 375 bytes 0 bytes (0%)
py-modindex.html 3.07 KB 3.07 KB 0 bytes (0%)
search.html 2.84 KB 2.84 KB 0 bytes (0%)
searchindex.js 6.28 KB 6.28 KB 0 bytes (0%)
index.rst.txt 415 bytes 415 bytes 0 bytes (0%)
alabaster.css 10.92 KB 10.92 KB 0 bytes (0%)
basic.css 11.89 KB 11.89 KB 0 bytes (0%)
custom.css 42 bytes 42 bytes 0 bytes (0%)
doctools.js 9.05 KB 9.05 KB 0 bytes (0%)
documentation_options.js 303 bytes 303 bytes 0 bytes (0%)
file.png 286 bytes 286 bytes 0 bytes (0%)
jquery-[version].js 273.79 KB 273.79 KB 0 bytes (0%)
jquery.js 86.08 KB 86.08 KB 0 bytes (0%)
language_data.js 10.59 KB 10.59 KB 0 bytes (0%)
minus.png 90 bytes 90 bytes 0 bytes (0%)
plus.png 90 bytes 90 bytes 0 bytes (0%)
pygments.css 4.69 KB 4.69 KB 0 bytes (0%)
searchtools.js 15.61 KB 15.61 KB 0 bytes (0%)
underscore-[version].js 34.34 KB 34.34 KB 0 bytes (0%)
underscore.js 11.86 KB 11.86 KB 0 bytes (0%)
contract_addresses.html 16.8 KB 16.8 KB 0 bytes (0%)
contract_artifacts.html 8.24 KB 8.24 KB 0 bytes (0%)
json_schemas.html 12.55 KB 12.55 KB 0 bytes (0%)
order_utils.html 46.85 KB 46.85 KB 0 bytes (0%)
erc20_token.html 93.31 KB 93.31 KB 0 bytes (0%)
exchange.html 678.51 KB 678.51 KB 0 bytes (0%)
tx_params.html 9.41 KB 9.41 KB 0 bytes (0%)
local_message_signer.html 15.07 KB 15.07 KB 0 bytes (0%)
asset_data_utils.html 22.65 KB 22.65 KB 0 bytes (0%)
default_api.html 113.16 KB 113.16 KB 0 bytes (0%)
asset_proxy_owner.html 350.44 KB 350.44 KB 0 bytes (0%)
coordinator.html 133.77 KB 133.77 KB 0 bytes (0%)
coordinator_registry.html 39.72 KB 39.72 KB 0 bytes (0%)
dutch_auction.html 59.6 KB 59.6 KB 0 bytes (0%)
erc20_proxy.html 111 KB 111 KB 0 bytes (0%)
erc721_proxy.html 111.12 KB 111.12 KB 0 bytes (0%)
erc721_token.html 148.29 KB 148.29 KB 0 bytes (0%)
forwarder.html 110.46 KB 110.46 KB 0 bytes (0%)
i_asset_proxy.html 39.32 KB 39.32 KB 0 bytes (0%)
i_validator.html 30.37 KB 30.37 KB 0 bytes (0%)
i_wallet.html 27.63 KB 27.63 KB 0 bytes (0%)
multi_asset_proxy.html 148.59 KB 148.59 KB 0 bytes (0%)
order_validator.html 120.52 KB 120.52 KB 0 bytes (0%)
weth9.html 133.98 KB 133.98 KB 0 bytes (0%)
zrx_token.html 111.93 KB 111.93 KB 0 bytes (0%)
dev_utils.html 580.48 KB 580.48 KB 0 bytes (0%)
types.html 8.68 KB 8.68 KB 0 bytes (0%)
erc1155_mintable.html 288.23 KB 288.23 KB 0 bytes (0%)
erc1155_proxy.html 129.7 KB 129.7 KB 0 bytes (0%)
static_call_proxy.html 39.44 KB 39.44 KB 0 bytes (0%)

@xianny xianny force-pushed the refactor/abi-gen-wrappers branch from 74ad8cf to 85388fe Compare November 13, 2019 22:17
@xianny xianny force-pushed the refactor/abi-gen-wrappers branch from 85388fe to c61ada8 Compare November 13, 2019 22:51
@xianny xianny marked this pull request as ready for review November 14, 2019 05:43
@xianny xianny force-pushed the refactor/abi-gen-wrappers branch from c4d62d4 to 2fce39b Compare November 14, 2019 05:56
@xianny xianny force-pushed the refactor/abi-gen-wrappers branch from 2fce39b to ac6ab0b Compare November 14, 2019 06:24
@coveralls
Copy link

coveralls commented Nov 14, 2019

Coverage Status

Coverage remained the same at 75.743% when pulling 8f6b274 on refactor/abi-gen-wrappers into 9d4d9ce on development.

Copy link
Member

@dekz dekz left a comment

Choose a reason for hiding this comment

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

Changes look good, size reduction is great and ultimately I think the outcome is more readable.

One discrepancy in types CHANGELOG which may have already been published.

I think we should have a CHANGELOG for contract-wrappers,abi-gen and perhaps abi-gen-wrappers, but I don't think many people use those directly. Do you think it's worth calling out the changes in any other packages?

packages/types/CHANGELOG.json Outdated Show resolved Hide resolved
Copy link
Contributor

@fabioberger fabioberger left a comment

Choose a reason for hiding this comment

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

Once the reference.mdx file changes are removed, LGTM

@fabioberger
Copy link
Contributor

Made the changes suggested by @dekz and myself.

@xianny xianny merged commit f0d7d10 into development Nov 14, 2019
@xianny xianny deleted the refactor/abi-gen-wrappers branch November 14, 2019 16:22
dorothy-zbornak pushed a commit that referenced this pull request Feb 27, 2020
* update abi-gen with new method interfaces

* wip: get all packages to build

* wip: get all packages to build

* Fix two contract wrapper calls

* Export necessary types part of the contract wrapper public interfaces

* Revive and fix wrapper_unit_tests

* Remove duplicate type

* Fix lib_exchange_rich_error_decoder tests

* Fix remaining test failures in contracts-* packages

* Prettier fixes

* remove transactionHelper

* lint and update changelogs

* Fix prettier

* Revert changes to reference docs

* Add back changelog already published and add revert changelog entry

* Add missing CHANGELOG entries

* Add missing comma

* Update mesh-rpc-client dep

* Update Mesh RPC logic in @0x/orderbook to v6.0.1-beta

* Align package versions
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants