soroban_cli/commands/tx/
mod.rs

1use super::global;
2
3pub mod args;
4
5pub mod decode;
6pub mod edit;
7pub mod encode;
8pub mod fetch;
9pub mod hash;
10pub mod help;
11pub mod new;
12pub mod op;
13pub mod send;
14pub mod sign;
15pub mod simulate;
16pub mod update;
17pub mod xdr;
18
19pub use args::Args;
20
21#[derive(Debug, clap::Subcommand)]
22pub enum Cmd {
23    /// Update the transaction
24    #[command(subcommand)]
25    Update(update::Cmd),
26    /// Edit a transaction envelope from stdin. This command respects the environment variables
27    /// `STELLAR_EDITOR`, `EDITOR` and `VISUAL`, in that order.
28    ///
29    /// Example: Start a new edit session
30    ///
31    /// $ stellar tx edit
32    ///
33    /// Example: Pipe an XDR transaction envelope
34    ///
35    /// $ stellar tx new manage-data --data-name hello --build-only | stellar tx edit
36    ///
37    Edit(edit::Cmd),
38    /// Calculate the hash of a transaction envelope
39    Hash(hash::Cmd),
40    /// Create a new transaction
41    #[command(subcommand)]
42    New(new::Cmd),
43    /// Manipulate the operations in a transaction, including adding new operations
44    #[command(subcommand, visible_alias = "op")]
45    Operation(op::Cmd),
46    /// Send a transaction envelope to the network
47    Send(send::Cmd),
48    /// Sign a transaction envelope appending the signature to the envelope
49    Sign(sign::Cmd),
50    /// Simulate a transaction envelope from stdin
51    Simulate(simulate::Cmd),
52    /// Fetch a transaction from the network by hash
53    /// If no subcommand is passed in, the transaction envelope will be returned
54    Fetch(fetch::Cmd),
55    Decode(decode::Cmd),
56    Encode(encode::Cmd),
57}
58
59#[derive(thiserror::Error, Debug)]
60pub enum Error {
61    #[error(transparent)]
62    Hash(#[from] hash::Error),
63    #[error(transparent)]
64    New(#[from] new::Error),
65    #[error(transparent)]
66    Edit(#[from] edit::Error),
67    #[error(transparent)]
68    Op(#[from] op::Error),
69    #[error(transparent)]
70    Send(#[from] send::Error),
71    #[error(transparent)]
72    Sign(#[from] sign::Error),
73    #[error(transparent)]
74    Args(#[from] args::Error),
75    #[error(transparent)]
76    Simulate(#[from] simulate::Error),
77    #[error(transparent)]
78    Update(#[from] update::Error),
79    #[error(transparent)]
80    Fetch(#[from] fetch::Error),
81    #[error(transparent)]
82    Decode(#[from] decode::Error),
83    #[error(transparent)]
84    Encode(#[from] encode::Error),
85}
86
87impl Cmd {
88    pub async fn run(&self, global_args: &global::Args) -> Result<(), Error> {
89        match self {
90            Cmd::Hash(cmd) => cmd.run(global_args)?,
91            Cmd::New(cmd) => cmd.run(global_args).await?,
92            Cmd::Edit(cmd) => cmd.run(global_args)?,
93            Cmd::Operation(cmd) => cmd.run(global_args).await?,
94            Cmd::Send(cmd) => cmd.run(global_args).await?,
95            Cmd::Sign(cmd) => cmd.run(global_args).await?,
96            Cmd::Simulate(cmd) => cmd.run(global_args).await?,
97            Cmd::Update(cmd) => cmd.run(global_args).await?,
98            Cmd::Fetch(cmd) => cmd.run(global_args).await?,
99            Cmd::Decode(cmd) => cmd.run()?,
100            Cmd::Encode(cmd) => cmd.run()?,
101        }
102        Ok(())
103    }
104}