Skip to content

Commit

Permalink
Add tx decode subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Dec 10, 2024
1 parent ba4687c commit 4c3d24d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ path = "./cmd/crates/soroban-spec-tools"

# Dependencies from the rs-stellar-xdr repo:
[workspace.dependencies.stellar-xdr]
version = "=22.0.0-rc.1.1"
version = "22.0.0-rc.1.1"
default-features = true

# Dependencies from the rs-soroban-sdk repo:
Expand Down
30 changes: 30 additions & 0 deletions cmd/soroban-cli/src/commands/tx/decode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use stellar_xdr::cli::{decode::OutputFormat, Channel};

#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Cli(#[from] stellar_xdr::cli::decode::Error),
}

/// Command to simulate a transaction envelope via rpc
/// e.g. `cat file.txt | soroban tx simulate`
#[derive(Debug, clap::Parser, Clone, Default)]
#[group(skip)]
pub struct Cmd {
// Output format
#[arg(long, value_enum, default_value_t)]
pub output: OutputFormat,
}

impl Cmd {
pub fn run(&self) -> Result<(), Error> {
let cmd = stellar_xdr::cli::decode::Cmd {
files: vec![],
r#type: "TransactionEnvelope".to_string(),
input: stellar_xdr::cli::decode::InputFormat::SingleBase64,
output: self.output,
};
cmd.run(&Channel::Curr)?;
Ok(())
}
}
6 changes: 6 additions & 0 deletions cmd/soroban-cli/src/commands/tx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::global;

pub mod args;
pub mod decode;
pub mod hash;
pub mod help;
pub mod new;
Expand Down Expand Up @@ -28,6 +29,8 @@ pub enum Cmd {
Sign(sign::Cmd),
/// Simulate a transaction envelope from stdin
Simulate(simulate::Cmd),
/// Decode a transaction envelope to JSON
Decode(decode::Cmd),
}

#[derive(thiserror::Error, Debug)]
Expand All @@ -44,6 +47,8 @@ pub enum Error {
Sign(#[from] sign::Error),
#[error(transparent)]
Simulate(#[from] simulate::Error),
#[error(transparent)]
Decode(#[from] decode::Error),
}

impl Cmd {
Expand All @@ -55,6 +60,7 @@ impl Cmd {
Cmd::Send(cmd) => cmd.run(global_args).await?,
Cmd::Sign(cmd) => cmd.run(global_args).await?,
Cmd::Simulate(cmd) => cmd.run(global_args).await?,
Cmd::Decode(cmd) => cmd.run()?,
};
Ok(())
}
Expand Down

0 comments on commit 4c3d24d

Please sign in to comment.