diff --git a/cmd/soroban-cli/src/commands/tx/decode.rs b/cmd/soroban-cli/src/commands/tx/decode.rs index c660ceac1..ceec13d10 100644 --- a/cmd/soroban-cli/src/commands/tx/decode.rs +++ b/cmd/soroban-cli/src/commands/tx/decode.rs @@ -1,5 +1,8 @@ use clap::ValueEnum; -use stellar_xdr::cli::{decode::InputFormat, Channel}; +use stellar_xdr::{ + cli::{decode::InputFormat, Channel}, + curr::TypeVariant, +}; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -7,9 +10,8 @@ pub enum Error { Cli(#[from] stellar_xdr::cli::decode::Error), } -/// Decode a transaction envelope to JSON +/// Decode a transaction envelope from XDR to JSON #[derive(Debug, clap::Parser, Clone, Default)] -#[group(skip)] pub struct Cmd { // Output format #[arg(long, value_enum, default_value_t)] @@ -36,7 +38,7 @@ impl Cmd { pub fn run(&self) -> Result<(), Error> { let cmd = stellar_xdr::cli::decode::Cmd { files: vec![], - r#type: "TransactionEnvelope".to_string(), + r#type: TypeVariant::TransactionEnvelope.to_string(), input: InputFormat::SingleBase64, output: self.output.into(), }; diff --git a/cmd/soroban-cli/src/commands/tx/encode.rs b/cmd/soroban-cli/src/commands/tx/encode.rs new file mode 100644 index 000000000..d627b4adb --- /dev/null +++ b/cmd/soroban-cli/src/commands/tx/encode.rs @@ -0,0 +1,30 @@ +use stellar_xdr::{ + cli::{ + encode::{InputFormat, OutputFormat}, + Channel, + }, + curr::TypeVariant, +}; + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error(transparent)] + Cli(#[from] stellar_xdr::cli::encode::Error), +} + +/// Encode a transaction envelope from JSON to XDR +#[derive(Debug, clap::Parser, Clone, Default)] +pub struct Cmd; + +impl Cmd { + pub fn run(&self) -> Result<(), Error> { + let cmd = stellar_xdr::cli::encode::Cmd { + files: vec![], + r#type: TypeVariant::TransactionEnvelope.to_string(), + input: InputFormat::Json, + output: OutputFormat::SingleBase64, + }; + cmd.run(&Channel::Curr)?; + Ok(()) + } +} diff --git a/cmd/soroban-cli/src/commands/tx/mod.rs b/cmd/soroban-cli/src/commands/tx/mod.rs index 1c1c62adc..8ea554975 100644 --- a/cmd/soroban-cli/src/commands/tx/mod.rs +++ b/cmd/soroban-cli/src/commands/tx/mod.rs @@ -10,6 +10,7 @@ pub mod send; pub mod sign; pub mod simulate; pub mod xdr; +pub mod encode; pub use args::Args; @@ -29,8 +30,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), + Encode(encode::Cmd), } #[derive(thiserror::Error, Debug)] @@ -49,6 +50,8 @@ pub enum Error { Simulate(#[from] simulate::Error), #[error(transparent)] Decode(#[from] decode::Error), + #[error(transparent)] + Encode(#[from] encode::Error), } impl Cmd { @@ -61,6 +64,7 @@ impl Cmd { Cmd::Sign(cmd) => cmd.run(global_args).await?, Cmd::Simulate(cmd) => cmd.run(global_args).await?, Cmd::Decode(cmd) => cmd.run()?, + Cmd::Encode(cmd) => cmd.run()?, }; Ok(()) }