From 2d36fa5bc2f3a33c969b17f2efc089b9e526c3c9 Mon Sep 17 00:00:00 2001 From: Feliciss <10203-feliciss@users.noreply.0xacab.org> Date: Sat, 24 Aug 2024 21:43:40 +0900 Subject: [PATCH] [gh-2406] add proxy config to env file. --- Cargo.lock | 241 +++++++++++++----- Cargo.toml | 1 + crates/rooch-rpc-client/Cargo.toml | 2 + crates/rooch-rpc-client/src/client_config.rs | 7 + crates/rooch-rpc-client/src/lib.rs | 47 ++++ crates/rooch/src/commands/env/commands/add.rs | 11 +- .../rooch/src/commands/env/commands/list.rs | 12 +- crates/rooch/src/commands/init.rs | 2 + .../src/commands/rpc/commands/request.rs | 10 +- 9 files changed, 254 insertions(+), 79 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e2a61baf9b..8fed3b0b7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1740,7 +1740,7 @@ dependencies = [ "num-traits 0.2.19", "serde 1.0.208", "wasm-bindgen", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -4783,23 +4783,6 @@ dependencies = [ "tokio-rustls 0.24.1", ] -[[package]] -name = "hyper-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" -dependencies = [ - "futures-util", - "http 1.1.0", - "hyper 1.3.1", - "hyper-util", - "rustls 0.22.4", - "rustls-pki-types", - "tokio", - "tokio-rustls 0.25.0", - "tower-service", -] - [[package]] name = "hyper-rustls" version = "0.27.2" @@ -4816,6 +4799,7 @@ dependencies = [ "tokio", "tokio-rustls 0.26.0", "tower-service", + "webpki-roots 0.26.1", ] [[package]] @@ -4843,6 +4827,22 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.3.1", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + [[package]] name = "hyper-util" version = "0.1.3" @@ -5758,7 +5758,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.5", + "windows-targets 0.48.5", ] [[package]] @@ -7443,7 +7443,7 @@ dependencies = [ "percent-encoding", "quick-xml 0.31.0", "reqsign", - "reqwest 0.12.4", + "reqwest 0.12.7", "serde 1.0.208", "serde_json", "tokio", @@ -7662,7 +7662,7 @@ dependencies = [ "libc", "redox_syscall 0.5.1", "smallvec", - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -8512,6 +8512,54 @@ dependencies = [ "serde 1.0.208", ] +[[package]] +name = "quinn" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b22d8e7369034b9a7132bc2008cac12f2013c8132b45e0554e6e20e2617f2156" +dependencies = [ + "bytes", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash 2.0.0", + "rustls 0.23.10", + "socket2", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "quinn-proto" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba92fb39ec7ad06ca2582c0ca834dfeadcaf06ddfc8e635c80aa7e1c05315fdd" +dependencies = [ + "bytes", + "rand 0.8.5", + "ring 0.17.8", + "rustc-hash 2.0.0", + "rustls 0.23.10", + "slab", + "thiserror", + "tinyvec", + "tracing", +] + +[[package]] +name = "quinn-udp" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bffec3605b73c6f1754535084a85229fa8a30f86014e6c81aeec4abb68b0285" +dependencies = [ + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.52.0", +] + [[package]] name = "quote" version = "0.6.13" @@ -8838,7 +8886,7 @@ dependencies = [ "log", "percent-encoding", "rand 0.8.5", - "reqwest 0.12.4", + "reqwest 0.12.7", "rsa 0.9.6", "serde 1.0.208", "serde_json", @@ -8862,7 +8910,7 @@ dependencies = [ "http-body 0.4.6", "hyper 0.14.28", "hyper-rustls 0.24.2", - "hyper-tls", + "hyper-tls 0.5.0", "ipnet", "js-sys", "log", @@ -8878,7 +8926,7 @@ dependencies = [ "serde_json", "serde_urlencoded", "sync_wrapper 0.1.2", - "system-configuration", + "system-configuration 0.5.1", "tokio", "tokio-native-tls", "tokio-rustls 0.24.1", @@ -8891,41 +8939,48 @@ dependencies = [ "wasm-streams", "web-sys", "webpki-roots 0.25.4", - "winreg 0.50.0", + "winreg", ] [[package]] name = "reqwest" -version = "0.12.4" +version = "0.12.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" +checksum = "f8f4955649ef5c38cc7f9e8aa41761d48fb9677197daea9984dc54f56aad5e63" dependencies = [ "base64 0.22.1", "bytes", + "encoding_rs", "futures-core", "futures-util", + "h2 0.4.5", "http 1.1.0", "http-body 1.0.0", "http-body-util", "hyper 1.3.1", - "hyper-rustls 0.26.0", + "hyper-rustls 0.27.2", + "hyper-tls 0.6.0", "hyper-util", "ipnet", "js-sys", "log", "mime", + "native-tls", "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.22.4", + "quinn", + "rustls 0.23.10", "rustls-pemfile 2.1.2", "rustls-pki-types", "serde 1.0.208", "serde_json", "serde_urlencoded", - "sync_wrapper 0.1.2", + "sync_wrapper 1.0.1", + "system-configuration 0.6.1", "tokio", - "tokio-rustls 0.25.0", + "tokio-native-tls", + "tokio-rustls 0.26.0", "tokio-util", "tower-service", "url", @@ -8934,7 +8989,7 @@ dependencies = [ "wasm-streams", "web-sys", "webpki-roots 0.26.1", - "winreg 0.52.0", + "windows-registry", ] [[package]] @@ -9720,6 +9775,7 @@ name = "rooch-rpc-client" version = "0.6.9" dependencies = [ "anyhow", + "axum 0.7.5", "bcs", "futures", "hex", @@ -9727,6 +9783,7 @@ dependencies = [ "log", "move-core-types", "moveos-types", + "reqwest 0.12.7", "rooch-config", "rooch-key", "rooch-rpc-api", @@ -11343,6 +11400,9 @@ name = "sync_wrapper" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" +dependencies = [ + "futures-core", +] [[package]] name = "synthez" @@ -11385,7 +11445,18 @@ checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ "bitflags 1.3.2", "core-foundation", - "system-configuration-sys", + "system-configuration-sys 0.5.0", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.5.0", + "core-foundation", + "system-configuration-sys 0.6.0", ] [[package]] @@ -11398,6 +11469,16 @@ dependencies = [ "libc", ] +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tap" version = "1.0.1" @@ -13060,7 +13141,37 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-registry" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e400001bb720a623c1c69032f8e3e4cf09984deec740f007dd2b03ec864804b0" +dependencies = [ + "windows-result", + "windows-strings", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-result" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d1043d8214f791817bab27572aaa8af63732e11bf84aa21a45a78d6c317ae0e" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-strings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd9b125c486025df0eabcb585e62173c6c9eddcec5d117d3b6e8c30e2ee4d10" +dependencies = [ + "windows-result", + "windows-targets 0.52.6", ] [[package]] @@ -13091,7 +13202,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", + "windows-targets 0.52.6", ] [[package]] @@ -13111,18 +13222,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -13133,9 +13244,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -13151,9 +13262,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -13169,15 +13280,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -13193,9 +13304,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -13211,9 +13322,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -13223,9 +13334,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -13241,9 +13352,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.5" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" @@ -13273,16 +13384,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "winreg" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - [[package]] name = "ws_stream_wasm" version = "0.7.4" diff --git a/Cargo.toml b/Cargo.toml index 65f7223ac8..456bccc40a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -212,6 +212,7 @@ tonic = { version = "0.8", features = ["gzip"] } tracing = "0.1.37" tracing-appender = "0.2.2" tracing-subscriber = { version = "0.3.15" } +reqwest = { version = "0.12.7", features = ["json"] } codespan-reporting = "0.11.1" codespan = "0.11.1" diff --git a/crates/rooch-rpc-client/Cargo.toml b/crates/rooch-rpc-client/Cargo.toml index b2d7526b24..44c37a0012 100644 --- a/crates/rooch-rpc-client/Cargo.toml +++ b/crates/rooch-rpc-client/Cargo.toml @@ -23,6 +23,8 @@ jsonrpsee = { workspace = true } serde_json = { workspace = true } log = { workspace = true } hex = { workspace = true } +reqwest = { workspace = true } +axum = { workspace = true } move-core-types = { workspace = true } diff --git a/crates/rooch-rpc-client/src/client_config.rs b/crates/rooch-rpc-client/src/client_config.rs index 39b60a39ba..2e11960eaf 100644 --- a/crates/rooch-rpc-client/src/client_config.rs +++ b/crates/rooch-rpc-client/src/client_config.rs @@ -71,6 +71,7 @@ pub struct Env { pub alias: String, pub rpc: String, pub ws: Option, + pub proxy: Option, } impl Env { @@ -83,6 +84,9 @@ impl Env { if let Some(ws_url) = &self.ws { builder = builder.ws_url(ws_url); } + if let Some(proxy_url) = &self.proxy { + builder = builder.proxy_url(proxy_url); + } builder.build(&self.rpc).await } @@ -92,6 +96,7 @@ impl Env { alias: BuiltinChainID::Dev.chain_name(), rpc: ROOCH_DEV_NET_URL.into(), ws: None, + proxy: None, } } @@ -100,6 +105,7 @@ impl Env { alias: BuiltinChainID::Test.chain_name(), rpc: ROOCH_TEST_NET_URL.into(), ws: None, + proxy: None, } } @@ -121,6 +127,7 @@ impl Default for Env { alias: BuiltinChainID::Local.chain_name(), rpc: ServerConfig::default().url(false), ws: None, + proxy: None, } } } diff --git a/crates/rooch-rpc-client/src/lib.rs b/crates/rooch-rpc-client/src/lib.rs index 3c85628058..dc9ae52bf8 100644 --- a/crates/rooch-rpc-client/src/lib.rs +++ b/crates/rooch-rpc-client/src/lib.rs @@ -15,7 +15,9 @@ use moveos_types::{ function_return_value::FunctionResult, module_binding::MoveFunctionCaller, moveos_std::tx_context::TxContext, transaction::FunctionCall, }; +use reqwest::Proxy; use rooch_client::RoochRpcClient; +use serde_json::json; use std::sync::Arc; use std::time::Duration; use tokio::runtime::Handle; @@ -27,6 +29,7 @@ pub mod wallet_context; pub struct ClientBuilder { request_timeout: Duration, ws_url: Option, + proxy_url: Option, } impl ClientBuilder { @@ -40,6 +43,11 @@ impl ClientBuilder { self } + pub fn proxy_url(mut self, url: impl AsRef) -> Self { + self.proxy_url = Some(url.as_ref().to_string()); + self + } + pub async fn build(self, http: impl AsRef) -> Result { // TODO: add verison info @@ -50,9 +58,24 @@ impl ClientBuilder { .build(http)?, ); + if let Some(proxy_url) = self.proxy_url { + let reqwest_client = Some(Arc::new( + reqwest::Client::builder() + .proxy(Proxy::https(proxy_url.clone())?) + .proxy(Proxy::all(proxy_url)?) + .build()?, + )); + return Ok(Client { + http: http_client.clone(), + rooch: RoochRpcClient::new(http_client.clone()), + reqwest: reqwest_client, + }); + }; + Ok(Client { http: http_client.clone(), rooch: RoochRpcClient::new(http_client.clone()), + reqwest: None, }) } } @@ -62,6 +85,7 @@ impl Default for ClientBuilder { Self { request_timeout: Duration::from_secs(60), ws_url: None, + proxy_url: None, } } } @@ -69,6 +93,7 @@ impl Default for ClientBuilder { #[derive(Clone)] pub struct Client { http: Arc, + reqwest: Option>, pub rooch: RoochRpcClient, } @@ -86,6 +111,28 @@ impl Client { ) -> Result { Ok(self.http.request(method, params).await?) } + + pub async fn request_by_proxy( + &self, + url: &str, + method: &str, + params: Vec, + ) -> Result { + if let Some(reqwest) = &self.reqwest { + let response = reqwest + .post(url) + .header("Content-Type", "application/json") + .json(&json!({ + "method": method, + "params": params, + })) + .send() + .await?; + return Ok(response.json::().await?); + }; + + Ok(serde_json::Value::Null) + } } impl MoveFunctionCaller for Client { diff --git a/crates/rooch/src/commands/env/commands/add.rs b/crates/rooch/src/commands/env/commands/add.rs index fc8447b647..3eea1140b2 100644 --- a/crates/rooch/src/commands/env/commands/add.rs +++ b/crates/rooch/src/commands/env/commands/add.rs @@ -18,14 +18,23 @@ pub struct AddCommand { pub rpc: String, #[clap(long, value_hint = ValueHint::Url)] pub ws: Option, + #[clap(long, value_hint = ValueHint::Url)] + pub proxy: Option, } impl AddCommand { pub async fn execute(self) -> RoochResult<()> { let mut context = self.context_options.build()?; - let AddCommand { alias, rpc, ws, .. } = self; + let AddCommand { + alias, + rpc, + ws, + proxy, + .. + } = self; let env = Env { ws, + proxy, rpc, alias: alias.clone(), }; diff --git a/crates/rooch/src/commands/env/commands/list.rs b/crates/rooch/src/commands/env/commands/list.rs index 8547a192e6..9949aad182 100644 --- a/crates/rooch/src/commands/env/commands/list.rs +++ b/crates/rooch/src/commands/env/commands/list.rs @@ -17,10 +17,10 @@ impl ListCommand { let context = self.context_options.build()?; println!( - "{:^24} | {:^48} | {:^48} | {:^12}", - "Env Alias", "RPC URL", "Websocket URL", "Active Env" + "{:^24} | {:^48} | {:^48} | {:^48} | {:^12}", + "Env Alias", "RPC URL", "Websocket URL", "Proxy", "Active Env" ); - println!("{}", ["-"; 153].join("")); + println!("{}", ["-"; 203].join("")); for env in context.client_config.envs.iter() { let mut active = ""; @@ -29,9 +29,11 @@ impl ListCommand { } let ws = env.ws.clone().unwrap_or("Null".to_owned()); + let proxy = env.proxy.clone().unwrap_or("Null".to_owned()); + println!( - "{:^24} | {:^48} | {:^48} | {:^12}", - env.alias, env.rpc, ws, active + "{:^24} | {:^48} | {:^48} | {:^48} | {:^12}", + env.alias, env.rpc, ws, proxy, active ) } diff --git a/crates/rooch/src/commands/init.rs b/crates/rooch/src/commands/init.rs index 55433b4acc..1a638a9232 100644 --- a/crates/rooch/src/commands/init.rs +++ b/crates/rooch/src/commands/init.rs @@ -77,6 +77,7 @@ impl CommandAction<()> for Init { alias: "custom".to_string(), rpc: chain_url[1].to_owned(), ws: None, + proxy: None, }) } @@ -112,6 +113,7 @@ impl CommandAction<()> for Init { alias, rpc: url, ws: None, + proxy: None, } }) } diff --git a/crates/rooch/src/commands/rpc/commands/request.rs b/crates/rooch/src/commands/rpc/commands/request.rs index 0ae7c0d1aa..129fbfb448 100644 --- a/crates/rooch/src/commands/rpc/commands/request.rs +++ b/crates/rooch/src/commands/rpc/commands/request.rs @@ -27,7 +27,6 @@ pub struct RequestCommand { #[clap(flatten)] pub(crate) context_options: WalletContextOptions, - /// Return command outputs in json format #[clap(long, default_value = "false")] json: bool, @@ -36,7 +35,8 @@ pub struct RequestCommand { #[async_trait] impl CommandAction for RequestCommand { async fn execute(self) -> RoochResult { - let client = self.context_options.build()?.get_client().await?; + let context = self.context_options.build()?; + let client = context.get_client().await?; let params = match self.params { Some(serde_json::Value::Array(array)) => array, Some(value) => { @@ -51,7 +51,11 @@ impl CommandAction for RequestCommand { } None => vec![], }; - Ok(client.request(self.method.as_str(), params).await?) + let active_env = context.client_config.get_active_env()?; + + Ok(client + .request_by_proxy(&active_env.rpc, self.method.as_str(), params) + .await?) } /// Executes the command, and serializes it to the common JSON output type