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