From dd22eb0cad88772dd934be1c2ea64d6a89dc8518 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Tue, 5 Dec 2023 12:16:15 -0500 Subject: [PATCH] feat: use stellar_xdr::cli at top level `xdr` --- Cargo.lock | 33 ++++++++++++++++++++++------- cmd/soroban-cli/Cargo.toml | 10 ++++++++- cmd/soroban-cli/src/commands/mod.rs | 9 ++++++++ cmd/soroban-cli/src/commands/xdr.rs | 28 ++++++++++++++++++++++++ docs/soroban-cli-full-docs.md | 14 ++++++++++++ 5 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 cmd/soroban-cli/src/commands/xdr.rs diff --git a/Cargo.lock b/Cargo.lock index b4d9a25bce..bd959e17d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2535,6 +2535,7 @@ dependencies = [ "soroban-spec-tools", "soroban-spec-typescript", "stellar-strkey 0.0.7", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=5dcb7a4549a2901e4040641710c5fdef5cbd526d)", "strsim", "termcolor", "termcolor_output", @@ -2563,7 +2564,7 @@ dependencies = [ "soroban-env-macros", "soroban-wasmi", "static_assertions", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", ] [[package]] @@ -2611,7 +2612,7 @@ dependencies = [ "quote", "serde", "serde_json", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", "syn 2.0.39", ] @@ -2666,7 +2667,7 @@ dependencies = [ "soroban-env-common", "soroban-spec", "soroban-spec-rust", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", "syn 2.0.39", ] @@ -2676,7 +2677,7 @@ version = "20.0.0-rc2" source = "git+https://github.com/stellar/rs-soroban-sdk?rev=e35bace9de5addae7c32f405cdc11bb459cb1d61#e35bace9de5addae7c32f405cdc11bb459cb1d61" dependencies = [ "base64 0.13.1", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", "thiserror", "wasmparser 0.88.0", ] @@ -2691,7 +2692,7 @@ dependencies = [ "serde_json", "sha2 0.9.9", "soroban-spec", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", "thiserror", ] @@ -2705,7 +2706,7 @@ dependencies = [ "quote", "sha2 0.10.8", "soroban-spec", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", "syn 2.0.39", "thiserror", ] @@ -2721,7 +2722,7 @@ dependencies = [ "serde_json", "soroban-spec", "stellar-strkey 0.0.7", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", "thiserror", "tokio", "wasmparser 0.90.0", @@ -2743,7 +2744,7 @@ dependencies = [ "serde_json", "sha2 0.9.9", "soroban-spec", - "stellar-xdr", + "stellar-xdr 20.0.0-rc1 (git+https://github.com/stellar/rs-stellar-xdr?rev=d6f8ece2c89809d5e2800b9df64ae60787ee492b)", "temp-dir", "thiserror", "walkdir", @@ -2827,6 +2828,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "stellar-xdr" +version = "20.0.0-rc1" +source = "git+https://github.com/stellar/rs-stellar-xdr?rev=5dcb7a4549a2901e4040641710c5fdef5cbd526d#5dcb7a4549a2901e4040641710c5fdef5cbd526d" +dependencies = [ + "base64 0.13.1", + "clap", + "crate-git-revision 0.0.6", + "hex", + "serde", + "serde_json", + "serde_with", + "stellar-strkey 0.0.8", + "thiserror", +] + [[package]] name = "stellar-xdr" version = "20.0.0-rc1" diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index f6f6c757e7..969d1e870b 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -44,6 +44,7 @@ soroban-spec-typescript = { workspace = true } soroban-ledger-snapshot = { workspace = true } stellar-strkey = { workspace = true } soroban-sdk = { workspace = true } + clap = { version = "4.1.8", features = [ "derive", "env", @@ -69,7 +70,7 @@ csv = "1.1.6" ed25519-dalek = "2.0.0" jsonrpsee-http-client = "0.20.1" jsonrpsee-core = "0.20.1" -hyper = "0.14.27" +hyper = "0.14.27" hyper-tls = "0.5" http = "0.2.9" regex = "1.6.0" @@ -92,6 +93,13 @@ tracing-subscriber = { workspace = true, features = ["env-filter"] } cargo_metadata = "0.15.4" pathdiff = "0.2.1" dotenvy = "0.15.7" + +[dependencies.stellar-xdr] +version = "20.0.0-rc1" +git = "https://github.com/stellar/rs-stellar-xdr" +rev = "5dcb7a4549a2901e4040641710c5fdef5cbd526d" +features = ["cli"] + # For hyper-tls [target.'cfg(unix)'.dependencies] openssl = { version = "0.10.55", features = ["vendored"] } diff --git a/cmd/soroban-cli/src/commands/mod.rs b/cmd/soroban-cli/src/commands/mod.rs index b1be084100..2cf587a397 100644 --- a/cmd/soroban-cli/src/commands/mod.rs +++ b/cmd/soroban-cli/src/commands/mod.rs @@ -11,6 +11,7 @@ pub mod keys; pub mod network; pub mod plugin; pub mod version; +pub mod xdr; pub const HEADING_RPC: &str = "Options (RPC)"; const ABOUT: &str = "Build, deploy, & interact with contracts; set identities to sign with; configure networks; generate keys; and more. @@ -61,6 +62,7 @@ pub struct Root { impl Root { pub fn new() -> Result { + xdr::try_cmd()?; Self::try_parse().map_err(|e| { if std::env::args().any(|s| s == "--list") { let plugins = plugin::list().unwrap_or_default(); @@ -96,6 +98,9 @@ impl Root { Cmd::Network(network) => network.run()?, Cmd::Version(version) => version.run(), Cmd::Keys(id) => id.run().await?, + // This is never actually run because we handle it in `new` above + // It is here to satisfy the help generator which uses the enum + Cmd::Xdr(lab) => lab.run()?, }; Ok(()) } @@ -127,6 +132,8 @@ pub enum Cmd { Network(network::Cmd), /// Print version information Version(version::Cmd), + /// Encode and Decode XDR values + Xdr(xdr::Cmd), } #[derive(thiserror::Error, Debug)] @@ -146,4 +153,6 @@ pub enum Error { Plugin(#[from] plugin::Error), #[error(transparent)] Network(#[from] network::Error), + #[error(transparent)] + Xdr(#[from] xdr::Error), } diff --git a/cmd/soroban-cli/src/commands/xdr.rs b/cmd/soroban-cli/src/commands/xdr.rs new file mode 100644 index 0000000000..9ec9a76941 --- /dev/null +++ b/cmd/soroban-cli/src/commands/xdr.rs @@ -0,0 +1,28 @@ +use clap::Parser; +use std::ffi::OsString; +use stellar_xdr::cli; + +pub use cli::Error; + +#[derive(Parser, Debug)] +pub struct Cmd { + pub slop: Vec, +} + +impl Cmd { + pub fn run(&self) -> Result<(), Error> { + cli::run(&self.slop) + } +} + +pub fn try_cmd() -> Result<(), Error> { + let mut args = std::env::args().peekable(); + args.next().unwrap(); + if let Some(s) = args.peek() { + if s == "xdr" { + stellar_xdr::cli::run(args)?; + std::process::exit(0); + } + } + Ok(()) +} diff --git a/docs/soroban-cli-full-docs.md b/docs/soroban-cli-full-docs.md index 4fece96e59..42456af6be 100644 --- a/docs/soroban-cli-full-docs.md +++ b/docs/soroban-cli-full-docs.md @@ -40,6 +40,7 @@ This document contains the help content for the `soroban` command-line program. * [`soroban network rm`↴](#soroban-network-rm) * [`soroban network ls`↴](#soroban-network-ls) * [`soroban version`↴](#soroban-version) +* [`soroban xdr`↴](#soroban-xdr) ## `soroban` @@ -78,6 +79,7 @@ Full CLI reference: https://github.com/stellar/soroban-tools/tree/main/docs/soro * `keys` — Create and manage identities including keys and addresses * `network` — Start and configure networks * `version` — Print version information +* `xdr` — Encode and Decode XDR values ###### **Options:** @@ -831,6 +833,18 @@ Print version information +## `soroban xdr` + +Encode and Decode XDR values + +**Usage:** `soroban xdr [SLOP]...` + +###### **Arguments:** + +* `` + + +