soroban_cli/commands/contract/id/
asset.rs

1use clap::{arg, command, Parser};
2
3use crate::config;
4
5use crate::tx::builder;
6use crate::utils::contract_id_hash_from_asset;
7
8#[derive(Parser, Debug, Clone)]
9#[group(skip)]
10pub struct Cmd {
11    /// ID of the Stellar classic asset to wrap, e.g. "native", "USDC:G...5", "USDC:alias"
12    #[arg(long)]
13    pub asset: builder::Asset,
14
15    #[command(flatten)]
16    pub config: config::ArgsLocatorAndNetwork,
17}
18#[derive(thiserror::Error, Debug)]
19pub enum Error {
20    #[error(transparent)]
21    ConfigError(#[from] config::Error),
22    #[error(transparent)]
23    Xdr(#[from] crate::xdr::Error),
24    #[error(transparent)]
25    Asset(#[from] builder::asset::Error),
26}
27impl Cmd {
28    pub fn run(&self) -> Result<(), Error> {
29        println!("{}", self.contract_address()?);
30        Ok(())
31    }
32
33    pub fn contract_address(&self) -> Result<stellar_strkey::Contract, Error> {
34        let network = self.config.get_network()?;
35        let contract_id = contract_id_hash_from_asset(
36            &self.asset.resolve(&self.config.locator)?,
37            &network.network_passphrase,
38        );
39        Ok(stellar_strkey::Contract(contract_id.0))
40    }
41}