Skip to main content

soroban_cli/commands/contract/
info.rs

1use std::fmt::Debug;
2
3use crate::commands::global;
4
5pub mod build;
6pub mod env_meta;
7pub mod hash;
8pub mod interface;
9pub mod meta;
10pub mod shared;
11
12#[derive(Debug, clap::Subcommand)]
13pub enum Cmd {
14    /// Output the interface of a contract.
15    ///
16    /// A contract's interface describes the functions, parameters, and
17    /// types that the contract makes accessible to be called.
18    ///
19    /// The data outputted by this command is a stream of `SCSpecEntry` XDR values.
20    /// See the type definitions in [stellar-xdr](https://github.com/stellar/stellar-xdr).
21    /// [See also XDR data format](https://developers.stellar.org/docs/learn/encyclopedia/data-format/xdr).
22    ///
23    /// Outputs no data when no data is present in the contract.
24    Interface(interface::Cmd),
25
26    /// Output the metadata stored in a contract.
27    ///
28    /// A contract's meta is a series of key-value pairs that the contract
29    /// developer can set with any values to provided metadata about the
30    /// contract. The meta also contains some information like the version
31    /// of Rust SDK, and Rust compiler version.
32    ///
33    /// The data outputted by this command is a stream of `SCMetaEntry` XDR values.
34    /// See the type definitions in [stellar-xdr](https://github.com/stellar/stellar-xdr).
35    /// [See also XDR data format](https://developers.stellar.org/docs/learn/encyclopedia/data-format/xdr).
36    ///
37    /// Outputs no data when no data is present in the contract.
38    Meta(meta::Cmd),
39
40    /// Output the env required metadata stored in a contract.
41    ///
42    /// Env-meta is information stored in all contracts, in the
43    /// `contractenvmetav0` WASM custom section, about the environment
44    /// that the contract was built for. Env-meta allows the Soroban Env
45    /// to know whether the contract is compatibility with the network in
46    /// its current configuration.
47    ///
48    /// The data outputted by this command is a stream of `SCEnvMetaEntry` XDR values.
49    /// See the type definitions in [stellar-xdr](https://github.com/stellar/stellar-xdr).
50    /// [See also XDR data format](https://developers.stellar.org/docs/learn/encyclopedia/data-format/xdr).
51    ///
52    /// Outputs no data when no data is present in the contract.
53    EnvMeta(env_meta::Cmd),
54
55    /// Output the contract build information, if available.
56    ///
57    /// If the contract has a meta entry like `source_repo=github:user/repo`, this command will try
58    /// to fetch the attestation information for the WASM file.
59    Build(build::Cmd),
60
61    /// Output the SHA-256 hash of a contract's Wasm.
62    ///
63    /// The hash can be computed from a local .wasm file (`--wasm`) or read from a deployed
64    /// contract (`--id`). The two flags are mutually exclusive.
65    ///
66    /// Stellar Asset Contracts have no Wasm and therefore no hash; using `--id` against a
67    /// SAC will return an error.
68    Hash(hash::Cmd),
69}
70
71#[derive(thiserror::Error, Debug)]
72pub enum Error {
73    #[error(transparent)]
74    Interface(#[from] interface::Error),
75
76    #[error(transparent)]
77    Meta(#[from] meta::Error),
78
79    #[error(transparent)]
80    EnvMeta(#[from] env_meta::Error),
81
82    #[error(transparent)]
83    Build(#[from] build::Error),
84
85    #[error(transparent)]
86    Hash(#[from] hash::Error),
87}
88
89impl Cmd {
90    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
91        match &self {
92            Cmd::Interface(interface) => interface.run(global_args).await?,
93            Cmd::Meta(meta) => meta.run(global_args).await?,
94            Cmd::EnvMeta(env_meta) => env_meta.run(global_args).await?,
95            Cmd::Build(build) => build.run(global_args).await?,
96            Cmd::Hash(hash) => hash.run(global_args).await?,
97        }
98
99        Ok(())
100    }
101}