-
Notifications
You must be signed in to change notification settings - Fork 113
feat: Add a stellar contract info wasm-hash command #1878
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
base: main
Are you sure you want to change the base?
feat: Add a stellar contract info wasm-hash command #1878
Conversation
leighmcculloch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏🏻 This looks good, thanks for contributing.
There's a few small things that need fixing up. I've left comments inline on each.
The other thing this needs is an test. Tests that use commands and interact with an RPC are located in the following directory:
cmd/crates/soroban-test/tests/it
The way the tests work may not be intuitive because it's pretty bespoke. Let me know if that's something that you get stuck on.
Thanks again!
|
|
||
| /// Contract ID to get the wasm hash for | ||
| #[arg(long)] | ||
| pub contract_id: stellar_strkey::Contract, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a string, that is then used with alias resolution. Worth looking at other commands that accept a contract ID to see how this works.
| if let xdr::ContractExecutable::Wasm(hash) = instance.executable { | ||
| println!("{}", hex::encode(hash.0)); | ||
| return Ok(()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Err(rpc::Error::InvalidResponse("Contract instance not found".into()).into()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code should handle the other contract executable types, and emit the name of the executable if not a wasm-hash. See my other comment here: #1878 (comment).
| /// Get the wasm hash of a deployed contract | ||
| WasmHash(wasm_hash::Cmd), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fnando wdyt naming this command executable? Technically contracts can have an executable that is either:
- stellar-asset
- wasm-hash
In the past when we've made commands that accepted a Contract ID and errored on stellar-assets, it's been annoying that the edge case wasn't supported.
The command could output not just the hash but the type of executable, maybe in a simple json format. Or just use xdr-json of the ContractExecutable xdr type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also might be fair that getting a wasm-hash explicitly as the only output could be more helpful when scripting in some cases. There might be a case for both commands co-existing.
What
Closes: #1877
This PR adds a new command wasm-hash to the stellar contract CLI, allowing developers to retrieve the Wasm hash of a deployed contract directly from the command line.
Why
Currently, developers have to rely on more complex methods, such as using RPC calls or parsing logs, to obtain the Wasm hash of a contract. This new command simplifies the process, making it more convenient and efficient for developers to access the Wasm hash directly. It enhances the usability of the CLI by providing a straightforward command that outputs the hash in a format suitable for scripting and automation.
Get the Wasm hash of a deployed contract.
Usage
Arguments
--network: The network to use (e.g.,testnet,futurenet,mainnet, or custom URL)--contract-id: The ID of the deployed contract to get the Wasm hash forExample
Notes