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

Feat: give output as json from abi-based methods #1

Merged
merged 1 commit into from Sep 21, 2022
Merged

Conversation

birchmd
Copy link
Member

@birchmd birchmd commented Sep 19, 2022

This allows nice output when calling from the NEAR CLI. Example:

$ near --networkId testnet --accountId birchmd.testnet call dev-1663014663747-27418521013742 multiply '{"a": 7, "b": 6}'

Scheduling a call: dev-1663014663747-27418521013742.multiply({"a": 7, "b": 6})
Doing account.functionCall()
Transaction Id 97g3DMfcZMyipJ5QLzRw46d6SvnjsTdyn1B1ZVH5w7fg
To see the transaction in the transaction explorer, please open this url in your browser
https://explorer.testnet.near.org/transactions/97g3DMfcZMyipJ5QLzRw46d6SvnjsTdyn1B1ZVH5w7fg
{ output: 42, status: 'SUCCESS' }

This feature is implemented by having environment functions like value_return and revert only update the internal EVM state (setting the exit status and return data), not call any external exit methods (like process::exit, or NEAR's host functions). Instead, the exit calls happen as part of a new function called post_exec. This gives a chance for the return data to be re-encoded from ABI into JSON before the value is returned.

The main files to focus on in the review are: compiler.rs, api.rs and encode.rs. Note that the code for decoding JSON into ABI input was simply moved from api.rs to decode.rs with no changes.

@birchmd birchmd added the enhancement New feature or request label Sep 19, 2022
@birchmd birchmd requested a review from artob September 19, 2022 16:34
@artob artob self-assigned this Sep 19, 2022
@artob artob merged commit 1f1ec0d into master Sep 21, 2022
@artob artob deleted the json-output branch September 21, 2022 09:11
birchmd pushed a commit to birchmd/evm2near that referenced this pull request Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants