Vyper: Vyper compiler ABI output produces invalid JSON (due to using single quotes & camel case boolean literals)

Created on 10 Aug 2018  路  7Comments  路  Source: vyperlang/vyper

Version Information

  • vyper Version: master from2018-07-31T13:27:06Z (from ethereum/vyper Docker image)
  • pyethereum Version: ?? (sorry, can't figure it out...)
  • OS: osx (running on Docker)
  • Python Version: (python --version): 3.6
  • Environment (output of pip freeze): N/A

What's your issue about?

Vyper ABI output uses:

  1. single quotes as string wrappers
  2. camel case literals as boolean values

This isn't valid JSON according to the specification for strings:

double quotes are valid string wrappers

and booleans:

boolean values are all lowercase string literals

See example:

Highgarden:vyper_quotes kkom$ curl https://raw.githubusercontent.com/ethereum/vyper/master/examples/auctions/simple_open_auction.vy > simple_open_auction.vy
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2255  100  2255    0     0  11912      0 --:--:-- --:--:-- --:--:-- 11931
Highgarden:vyper_quotes kkom$ docker run -v $PWD:$PWD -w $PWD ethereum/vyper -f abi simple_open_auction.vy 
[{'name': '__init__', 'outputs': [], 'inputs': [{'type': 'address', 'name': '_beneficiary'}, {'type': 'uint256', 'name': '_bidding_time'}], 'constant': False, 'payable': False, 'type': 'constructor'}, {'name': 'bid', 'outputs': [], 'inputs': [], 'constant': False, 'payable': True, 'type': 'function', 'gas': 106241}, {'name': 'end_auction', 'outputs': [], 'inputs': [], 'constant': False, 'payable': False, 'type': 'function', 'gas': 71101}, {'name': 'beneficiary', 'outputs': [{'type': 'address', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 543}, {'name': 'auction_start', 'outputs': [{'type': 'uint256', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 573}, {'name': 'auction_end', 'outputs': [{'type': 'uint256', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 603}, {'name': 'highest_bidder', 'outputs': [{'type': 'address', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 633}, {'name': 'highest_bid', 'outputs': [{'type': 'uint256', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 663}, {'name': 'ended', 'outputs': [{'type': 'bool', 'name': 'out'}], 'inputs': [], 'constant': True, 'payable': False, 'type': 'function', 'gas': 693}]

The ABI output isn't accepted by the Parity UI:

invalid json in parity ui

How can it be fixed?

Single quotes and uppercase boolean values are a Python convention, so I presume a slightly more sophisticated printing method needs to be used. If there is consensus that this issue should be fixed in this way, I'm happy to look into it more.

This demonstrates that, in the case of the simple_open_auction.vy contract, fixing these two issues produces valid JSON:

Highgarden:vyper_quotes kkom$ docker run -v $PWD:$PWD -w $PWD ethereum/vyper -f abi simple_open_auction.vy | sed 's/'\''/"/g' | sed 's/True/true/g' | sed 's/False/false/g'
[{"name": "__init__", "outputs": [], "inputs": [{"type": "address", "name": "_beneficiary"}, {"type": "uint256", "name": "_bidding_time"}], "constant": false, "payable": false, "type": "constructor"}, {"name": "bid", "outputs": [], "inputs": [], "constant": false, "payable": true, "type": "function", "gas": 106241}, {"name": "end_auction", "outputs": [], "inputs": [], "constant": false, "payable": false, "type": "function", "gas": 71101}, {"name": "beneficiary", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 543}, {"name": "auction_start", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 573}, {"name": "auction_end", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 603}, {"name": "highest_bidder", "outputs": [{"type": "address", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 633}, {"name": "highest_bid", "outputs": [{"type": "uint256", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 663}, {"name": "ended", "outputs": [{"type": "bool", "name": "out"}], "inputs": [], "constant": true, "payable": false, "type": "function", "gas": 693}]

valid json in parity ui

Cute Animal Picture

This is actually my dog, Yoshi!

yoshi

Easy Pickings enhancement

All 7 comments

@kkom the -f json output produces the ABI you are looking for, the -f abi produces a python format (we kept this, so one can easily paste it into your web3.py setup).

What a beautiful dog! :dog: :smile:

Thanks @jacqueswww, this works!

I'm wondering what can be done to avoid confusion like this in the future.

  1. Update -f abi to produce legal JSON and use something else for the Python output. My intuition is that vanilla options should produce the most standards compliant results (granted I have zero experience with the conventions of the web3.py stack). This is obviously a breaking change, but Vyper is in development. :)
  2. Add more documentation to the vyper command line program. I assume there will always be just a few output formats, so enumerating them shouldn't clutter things too much.

What do you think?

Yes agree, we could opt to just rename the current -f abi to -f python_abi perhaps, as it does seem a bit confusing.

Cool! What's the decision-making process here? Submit a pull request and discuss there? Or should we wait for a few more people to chime in on this issue?

This isn't too big of a change, so you are welcome to create a PR or I will pick it up at some point ;-)

Sure! I gave it a try: PR https://github.com/ethereum/vyper/pull/995 :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ben-kaufman picture ben-kaufman  路  4Comments

jakerockland picture jakerockland  路  4Comments

fubuloubu picture fubuloubu  路  3Comments

nrryuya picture nrryuya  路  3Comments

jacqueswww picture jacqueswww  路  4Comments