soroban_cli/commands/tx/
mod.rs

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