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

fix: return contract Addresses and allow passing hex when used as an contract arg #668

Merged
merged 12 commits into from
Jun 1, 2023

Conversation

paulbellamy
Copy link
Contributor

@paulbellamy paulbellamy commented May 30, 2023

What

fixes #661
fixes #662
fixes #403
replaces #663

Why

#663 missed a few other commands were we take contract IDs as args. Also, we cannot generically accept hex for strval::scaddress_from_json, because with just 32-byte hex, we cannot tell if it is a user address or a contract address.

Incidentally, making this more consistent also fixed a bug in soroban events --id 1, where the given contract id was not padded out to the full 32 bytes. Now, these are all equivalent:

soroban events --id 1
soroban events --id 0000000000000000000000000000000000000000000000000000000000000001
soroban events --id CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM

Those ids all also work for invoke, deploy, and read

Known limitations

  • We should also update soroban-rpc to take a contract strkey in it's params, wherever it currently accepts a contract hex (e.g. getEvents). Then we can update this to pass that in.

There is one case where you cannot use a hex (padded or unpadded) as a contract Address. That is when you are passing an Address argument to a contract. For example:

# Deploy cross_contract contract 'a'
$ soroban contract deploy \
    --wasm ./soroban_cross_contract_a_contract.wasm \
    --source-account default \
    --id a
CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVAX5

# Deploy cross-contract contract 'b'
$ soroban contract deploy \
    --wasm ./soroban_cross_contract_b_contract.wasm \
    --source-account default \
    --id b
CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAXI7N

# Here, we are required to pass the full contract strkey. Passing
# `a`, or `0a`, would not work, because there is no generic way
# to convert a 32-byte hex string to an `ScAddress`. An `ScAddress`
# might be either a user address or a contract address, and the hex
# doesn't have enough information to infer that.
$ soroban contract invoke --source default \
    --id b -- \
    add_with \
    --x 2 --y 3 \
    --contract CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVAX5

@tsachiherman
Copy link
Contributor

Please create a fix for that in the system tests first, and then use the updated version of the system test in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants