soroban_cli/commands/tx/
mod.rs

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