From a0309dbd351d17541501f7d0f5399a85d984cedb Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Thu, 25 Jan 2024 13:33:38 -0500 Subject: [PATCH] feat: create soroban-rpc crate --- Cargo.lock | 56 ++++++++++++++++-- Cargo.toml | 4 ++ cmd/crates/soroban-rpc/Cargo.toml | 59 +++++++++++++++++++ cmd/crates/soroban-rpc/README.md | 3 + .../src}/fixtures/event_response.json | 0 .../mod.rs => crates/soroban-rpc/src/lib.rs} | 5 +- .../src/rpc => crates/soroban-rpc/src}/log.rs | 0 .../soroban-rpc/src}/log/diagnostic_events.rs | 0 .../src/rpc => crates/soroban-rpc/src}/txn.rs | 0 cmd/soroban-cli/Cargo.toml | 1 + cmd/soroban-cli/src/lib.rs | 5 +- 11 files changed, 122 insertions(+), 11 deletions(-) create mode 100644 cmd/crates/soroban-rpc/Cargo.toml create mode 100644 cmd/crates/soroban-rpc/README.md rename cmd/{soroban-cli/src/rpc => crates/soroban-rpc/src}/fixtures/event_response.json (100%) rename cmd/{soroban-cli/src/rpc/mod.rs => crates/soroban-rpc/src/lib.rs} (99%) rename cmd/{soroban-cli/src/rpc => crates/soroban-rpc/src}/log.rs (100%) rename cmd/{soroban-cli/src/rpc => crates/soroban-rpc/src}/log/diagnostic_events.rs (100%) rename cmd/{soroban-cli/src/rpc => crates/soroban-rpc/src}/txn.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 4cc4220dd..c202f710a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1943,7 +1943,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.11", "indexmap 2.1.0", "slab", "tokio", @@ -2040,6 +2040,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -2047,7 +2058,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.11", "pin-project-lite", ] @@ -2074,7 +2085,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.11", "http-body", "httparse", "httpdate", @@ -2094,7 +2105,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ "futures-util", - "http", + "http 0.2.11", "hyper", "log", "rustls", @@ -3050,7 +3061,7 @@ dependencies = [ "futures-core", "futures-util", "h2", - "http", + "http 0.2.11", "http-body", "hyper", "hyper-rustls", @@ -3562,7 +3573,7 @@ dependencies = [ "gix", "heck", "hex", - "http", + "http 0.2.11", "hyper", "hyper-tls", "itertools 0.10.5", @@ -3584,6 +3595,7 @@ dependencies = [ "shlex", "soroban-env-host", "soroban-ledger-snapshot", + "soroban-rpc", "soroban-sdk", "soroban-spec", "soroban-spec-json", @@ -3691,6 +3703,38 @@ dependencies = [ "thiserror", ] +[[package]] +name = "soroban-rpc" +version = "20.2.0" +dependencies = [ + "base64 0.21.5", + "clap", + "ed25519-dalek 2.0.0", + "ethnum", + "hex", + "http 1.0.0", + "itertools 0.10.5", + "jsonrpsee-core", + "jsonrpsee-http-client", + "serde", + "serde-aux", + "serde_json", + "sha2 0.10.8", + "soroban-env-host", + "soroban-sdk", + "soroban-spec", + "soroban-spec-tools", + "stellar-strkey 0.0.7", + "stellar-xdr", + "termcolor", + "termcolor_output", + "thiserror", + "tokio", + "tracing", + "wasmparser 0.90.0", + "which", +] + [[package]] name = "soroban-sdk" version = "20.1.0" diff --git a/Cargo.toml b/Cargo.toml index df5780093..11a74c9ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,6 +69,10 @@ rev = "e6c2c900ab82b5f6eec48f69cb2cb519e19819cb" version = "20.2.0" path = "cmd/soroban-cli" +[workspace.dependencies.soroban-rpc] +version = "20.2.0" +path = "cmd/crates/soroban-rpc" + [workspace.dependencies.stellar-xdr] version = "=20.0.2" default-features = true diff --git a/cmd/crates/soroban-rpc/Cargo.toml b/cmd/crates/soroban-rpc/Cargo.toml new file mode 100644 index 000000000..38b5ce3a4 --- /dev/null +++ b/cmd/crates/soroban-rpc/Cargo.toml @@ -0,0 +1,59 @@ +[package] +name = "soroban-rpc" +description = "Soroban RPC client for rust" +homepage = "https://github.com/stellar/soroban-tools" +repository = "https://github.com/stellar/soroban-tools" +authors = ["Stellar Development Foundation "] +license = "Apache-2.0" +readme = "README.md" +version.workspace = true +edition = "2021" +rust-version = "1.70" +autobins = false + + +[lib] +crate-type = ["rlib"] + + +[dependencies] +soroban-sdk = { workspace = true } +soroban-spec-tools = { workspace = true } + +soroban-env-host = { workspace = true } +stellar-strkey = { workspace = true } +stellar-xdr = { workspace = true, features = ["curr", "std", "serde"] } +soroban-spec = { workspace = true } + + +termcolor = { workspace = true } +termcolor_output = { workspace = true } +clap = { workspace = true } + +serde_json = { workspace = true } +serde-aux = { workspace = true } +itertools = { workspace = true } +ethnum = { workspace = true } +hex = { workspace = true } +wasmparser = { workspace = true } +base64 = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true } +tokio = { workspace = true } +sha2 = { workspace = true } +ed25519-dalek = { workspace = true } +tracing = { workspace = true } + + +# networking +jsonrpsee-http-client = { workspace = true } +jsonrpsee-core = { workspace = true } +http = { workspace = true } + +# soroban-ledger-snapshot = { workspace = true } +# soroban-sdk = { workspace = true } +# sep5 = { workspace = true } + + +[dev-dependencies] +which = { workspace = true } diff --git a/cmd/crates/soroban-rpc/README.md b/cmd/crates/soroban-rpc/README.md new file mode 100644 index 000000000..9185b7fd0 --- /dev/null +++ b/cmd/crates/soroban-rpc/README.md @@ -0,0 +1,3 @@ +# soroban-rpc + +Tools and utilities for soroban rpc. diff --git a/cmd/soroban-cli/src/rpc/fixtures/event_response.json b/cmd/crates/soroban-rpc/src/fixtures/event_response.json similarity index 100% rename from cmd/soroban-cli/src/rpc/fixtures/event_response.json rename to cmd/crates/soroban-rpc/src/fixtures/event_response.json diff --git a/cmd/soroban-cli/src/rpc/mod.rs b/cmd/crates/soroban-rpc/src/lib.rs similarity index 99% rename from cmd/soroban-cli/src/rpc/mod.rs rename to cmd/crates/soroban-rpc/src/lib.rs index 9a3974083..cc9eebe93 100644 --- a/cmd/soroban-cli/src/rpc/mod.rs +++ b/cmd/crates/soroban-rpc/src/lib.rs @@ -31,9 +31,8 @@ mod txn; pub use txn::*; -use soroban_spec_tools::contract::Spec as Contract; +use soroban_spec_tools::contract; -use crate::utils::contract_spec as contract; const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION"); pub type LogEvents = fn( @@ -958,7 +957,7 @@ soroban config identity fund {address} --helper-url "# xdr::ScVal::ContractInstance(xdr::ScContractInstance { executable: xdr::ContractExecutable::Wasm(hash), .. - }) => Ok(Contract::new(&self.get_remote_wasm_from_hash(hash).await?) + }) => Ok(contract::Spec::new(&self.get_remote_wasm_from_hash(hash).await?) .map_err(Error::CouldNotParseContractSpec)? .spec), xdr::ScVal::ContractInstance(xdr::ScContractInstance { diff --git a/cmd/soroban-cli/src/rpc/log.rs b/cmd/crates/soroban-rpc/src/log.rs similarity index 100% rename from cmd/soroban-cli/src/rpc/log.rs rename to cmd/crates/soroban-rpc/src/log.rs diff --git a/cmd/soroban-cli/src/rpc/log/diagnostic_events.rs b/cmd/crates/soroban-rpc/src/log/diagnostic_events.rs similarity index 100% rename from cmd/soroban-cli/src/rpc/log/diagnostic_events.rs rename to cmd/crates/soroban-rpc/src/log/diagnostic_events.rs diff --git a/cmd/soroban-cli/src/rpc/txn.rs b/cmd/crates/soroban-rpc/src/txn.rs similarity index 100% rename from cmd/soroban-cli/src/rpc/txn.rs rename to cmd/crates/soroban-rpc/src/txn.rs diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index 5f060be31..ea936d941 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -45,6 +45,7 @@ soroban-spec-typescript = { workspace = true } soroban-ledger-snapshot = { workspace = true } stellar-strkey = { workspace = true } soroban-sdk = { workspace = true } +soroban-rpc = { workspace = true } clap = { workspace = true, features = [ "derive", diff --git a/cmd/soroban-cli/src/lib.rs b/cmd/soroban-cli/src/lib.rs index 3aad487c8..6acf09224 100644 --- a/cmd/soroban-cli/src/lib.rs +++ b/cmd/soroban-cli/src/lib.rs @@ -3,16 +3,17 @@ clippy::must_use_candidate, clippy::missing_panics_doc )] +use std::path::Path; +pub(crate) use soroban_rpc as rpc; + pub mod commands; pub mod fee; pub mod key; pub mod log; -pub mod rpc; pub mod toid; pub mod utils; pub mod wasm; -use std::path::Path; pub use commands::Root;