Skip to main content

soroban_cli/commands/token/
mod.rs

1pub mod args;
2pub mod balance;
3pub mod transfer;
4
5use crate::commands::global;
6
7#[derive(Debug, clap::Subcommand)]
8pub enum Cmd {
9    /// Transfer tokens from one account to another
10    Transfer(transfer::Cmd),
11
12    /// Read the token balance of an account or contract
13    Balance(balance::Cmd),
14}
15
16#[derive(thiserror::Error, Debug)]
17pub enum Error {
18    #[error(transparent)]
19    Transfer(#[from] transfer::Error),
20    #[error(transparent)]
21    Balance(#[from] balance::Error),
22}
23
24impl Error {
25    /// Machine-readable discriminator for the JSON error envelope's `type` field.
26    #[must_use]
27    pub fn error_type(&self) -> &'static str {
28        match self {
29            Error::Transfer(e) => e.error_type(),
30            Error::Balance(e) => e.error_type(),
31        }
32    }
33}
34
35impl Cmd {
36    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
37        match self {
38            Cmd::Transfer(cmd) => cmd.run(global_args).await?,
39            Cmd::Balance(cmd) => cmd.run(global_args).await?,
40        }
41        Ok(())
42    }
43}