soroban_cli/commands/token/
args.rs1use crate::{
2 commands::contract::invoke, config::token::ResolvedToken, get_spec, output::Format, rpc,
3};
4
5#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum, Default)]
7pub enum OutputFormat {
8 #[default]
10 Text,
11 Json,
13 JsonFormatted,
15}
16
17impl From<OutputFormat> for Format {
18 fn from(value: OutputFormat) -> Self {
19 match value {
20 OutputFormat::Text => Format::Readable,
21 OutputFormat::Json => Format::Json,
22 OutputFormat::JsonFormatted => Format::JsonFormatted,
23 }
24 }
25}
26
27#[derive(thiserror::Error, Debug)]
28pub enum Error {
29 #[error(
30 "the Stellar Asset Contract {0} is not deployed on this network.\n\
31 Deploy it first with `stellar contract asset deploy --asset <ASSET>`, then retry."
32 )]
33 SacNotDeployed(String),
34
35 #[error("contract {0} was not found on this network")]
36 ContractNotFound(String),
37}
38
39impl Error {
40 #[must_use]
42 pub fn error_type(&self) -> &'static str {
43 match self {
44 Error::SacNotDeployed(_) => "sac_not_deployed",
45 Error::ContractNotFound(_) => "contract_not_found",
46 }
47 }
48}
49
50#[must_use]
56pub fn not_deployed_error(token: &ResolvedToken, err: &invoke::Error) -> Option<Error> {
57 let invoke::Error::GetSpecError(get_spec::Error::Rpc(rpc::Error::NotFound(kind, _))) = err
58 else {
59 return None;
60 };
61 if kind != "Contract" {
62 return None;
63 }
64 let contract_id = token.contract_id;
65 Some(if token.is_sac() {
66 Error::SacNotDeployed(format!("{contract_id}"))
67 } else {
68 Error::ContractNotFound(format!("{contract_id}"))
69 })
70}