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

Add sub-command cargo contract info #783

Closed
cmichi opened this issue Oct 14, 2022 · 0 comments · Fixed by #993
Closed

Add sub-command cargo contract info #783

cmichi opened this issue Oct 14, 2022 · 0 comments · Fixed by #993
Assignees
Labels
enhancement New feature or request OpenZeppelin

Comments

@cmichi
Copy link
Collaborator

cmichi commented Oct 14, 2022

Big Picture

We should add an additional sub-command cargo contract info to display information regarding contracts on a chain. This is required to ease the friction for building third-party tooling.

What to implement

The new sub-command cargo contract info should take an argument --contract AccountId, as well as support the alternative CONTRACT environment variable (which we already do for cargo contract instantiate/call). Invoked like this, information regarding the specified contract should be returned.

For this ticket it is sufficient to display just ContractInfo. This is a struct in pallet-contracts that contains information about the contract (like its Wasm code hash). You can take a look at it here: https://github.com/paritytech/substrate/blob/2eb8ad273eeabea380fce00c10893ac788b1cbde/frame/contracts/src/storage.rs#L42-L64.

For most of this ticket you should be able to reuse existing code. I would start by copying the functionality for cargo contract call and modify it to fit the needs of cargo contract info. You will automatically get the same cli flags as cargo contract call/instantiate/upload, so e.g. --suri, --ws-url, etc.

You can throw out everything regarding transaction submission, for cargo contract info you will only need to do RPC queries. In our code those are often behind functions called dry_run, as dry runs of e.g. a contract call happen to estimate the gas costs. This is done via RPC.

We don't have logic to query storage of a contract yet in cargo-contract, but it should be similar to this code here: https://github.com/paritytech/subxt/blob/master/testing/integration-tests/src/frame/contracts.rs#L214-L219.

let info_addr = node_runtime::storage()
    .contracts()
    .contract_info_of(&contract);

let contract_info = cxt.client().storage().fetch(&info_addr, None).await;
assert!(contract_info.is_ok());

polkadot-js supports getting this data. This is how it looks there:

Screenshot 2022-10-26 at 01 18 58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OpenZeppelin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants