From 33459bb9a1bfe724cc700283a861c26ba61e5d32 Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 15 Apr 2024 14:41:49 +0200 Subject: [PATCH] fix: updating run-bridge to use skip auth, organizing imports --- Cargo.lock | 12 ++++++------ ci/run-bridge.sh | 1 + rpc/Cargo.toml | 8 ++++---- rpc/src/client.rs | 44 ++++++++++++++++++-------------------------- 4 files changed, 29 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7941ce26b..53ab567d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1697,9 +1697,9 @@ checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "gloo-net" -version = "0.3.1" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a66b4e3c7d9ed8d315fd6b97c8b1f74a7c6ecbbc2320e65ae7ed38b7068cc620" +checksum = "8ac9e8288ae2c632fa9f8657ac70bfe38a1530f345282d7ba66a1f70b72b7dc4" dependencies = [ "futures-channel", "futures-core", @@ -1742,9 +1742,9 @@ dependencies = [ [[package]] name = "gloo-utils" -version = "0.1.7" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037fcb07216cb3a30f7292bd0176b050b7b9a052ba830ef7d5d65f6dc64ba58e" +checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa" dependencies = [ "js-sys", "serde", @@ -2255,9 +2255,9 @@ dependencies = [ [[package]] name = "jsonrpsee-wasm-client" -version = "0.20.0" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "051742038473f3aaada8fc1eb19c76a5354e37e886999d60061f1f303cfc45e8" +checksum = "7c7cbb3447cf14fd4d2f407c3cc96e6c9634d5440aa1fbed868a31f3c02b27f0" dependencies = [ "jsonrpsee-client-transport", "jsonrpsee-core", diff --git a/ci/run-bridge.sh b/ci/run-bridge.sh index 0b6b4f70d..ec010fd49 100755 --- a/ci/run-bridge.sh +++ b/ci/run-bridge.sh @@ -67,6 +67,7 @@ main() { # Start the bridge node echo "Configuration finished. Running a bridge node..." celestia bridge start \ + --rpc.skip-auth \ --rpc.addr 0.0.0.0 \ --core.ip validator \ --keyring.accname "$NODE_NAME" \ diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 9f8930047..3f5036bcc 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -33,10 +33,6 @@ jsonrpsee = { version = "0.20", features = ["http-client", "ws-client"] } [target.'cfg(target_arch = "wasm32")'.dependencies] jsonrpsee = { version = "0.20", features = ["wasm-client"] } -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] -getrandom = { version = "0.2", features = ["js"] } -wasm-bindgen-test = "0.3.0" - [dev-dependencies] libp2p = { workspace = true, features = [ "tokio", @@ -46,6 +42,10 @@ libp2p = { workspace = true, features = [ "yamux", ] } +[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +getrandom = { version = "0.2", features = ["js"] } +wasm-bindgen-test = "0.3.0" + anyhow = "1.0.71" dotenvy = "0.15.7" futures = "0.3.28" diff --git a/rpc/src/client.rs b/rpc/src/client.rs index 199f36e5c..e8acc2a5a 100644 --- a/rpc/src/client.rs +++ b/rpc/src/client.rs @@ -12,10 +12,8 @@ pub use self::wasm::Client; #[cfg(not(target_arch = "wasm32"))] mod native { - use std::fmt; - use std::result::Result as StdResult; + use std::{fmt, result::Result}; - use crate::{Error, Result}; use async_trait::async_trait; use http::{header, HeaderValue}; use jsonrpsee::core::client::{BatchResponse, ClientT, Subscription, SubscriptionClientT}; @@ -26,6 +24,8 @@ mod native { use jsonrpsee::ws_client::{WsClient, WsClientBuilder}; use serde::de::DeserializeOwned; + use crate::Error; + /// Json RPC client. pub enum Client { /// A client using 'http\[s\]' protocol. @@ -43,7 +43,7 @@ mod native { /// /// Please note that currently the celestia-node supports only 'http' and 'ws'. /// For a secure connection you have to hide it behind a proxy. - pub async fn new(conn_str: &str, auth_token: Option<&str>) -> Result { + pub async fn new(conn_str: &str, auth_token: Option<&str>) -> Result { let mut headers = HeaderMap::new(); if let Some(token) = auth_token { @@ -73,11 +73,7 @@ mod native { #[async_trait] impl ClientT for Client { - async fn notification( - &self, - method: &str, - params: Params, - ) -> StdResult<(), JrpcError> + async fn notification(&self, method: &str, params: Params) -> Result<(), JrpcError> where Params: ToRpcParams + Send, { @@ -87,7 +83,7 @@ mod native { } } - async fn request(&self, method: &str, params: Params) -> StdResult + async fn request(&self, method: &str, params: Params) -> Result where R: DeserializeOwned, Params: ToRpcParams + Send, @@ -101,7 +97,7 @@ mod native { async fn batch_request<'a, R>( &self, batch: BatchRequestBuilder<'a>, - ) -> StdResult, JrpcError> + ) -> Result, JrpcError> where R: DeserializeOwned + fmt::Debug + 'a, { @@ -119,7 +115,7 @@ mod native { subscribe_method: &'a str, params: Params, unsubscribe_method: &'a str, - ) -> StdResult, JrpcError> + ) -> Result, JrpcError> where Params: ToRpcParams + Send, N: DeserializeOwned, @@ -141,7 +137,7 @@ mod native { async fn subscribe_to_method<'a, N>( &self, method: &'a str, - ) -> StdResult, JrpcError> + ) -> Result, JrpcError> where N: DeserializeOwned, { @@ -155,10 +151,8 @@ mod native { #[cfg(target_arch = "wasm32")] mod wasm { - use std::fmt; - use std::result::Result as StdResult; + use std::{fmt, result::Result}; - use crate::{Error, Result}; use async_trait::async_trait; use jsonrpsee::core::client::{BatchResponse, ClientT, Subscription, SubscriptionClientT}; use jsonrpsee::core::params::BatchRequestBuilder; @@ -167,12 +161,14 @@ mod wasm { use jsonrpsee::wasm_client::{Client as WasmClient, WasmClientBuilder}; use serde::de::DeserializeOwned; + use crate::Error; + pub struct Client { client: WasmClient, } impl Client { - pub async fn new(conn_str: &str) -> Result { + pub async fn new(conn_str: &str) -> Result { // Since headers are not supported in the current version of `jsonrpsee-wasm-client`, // celestia-node requires disabling authentication (--rpc.skip-auth) to use wasm. let protocol = conn_str.split_once(':').map(|(proto, _)| proto); @@ -187,18 +183,14 @@ mod wasm { #[async_trait] impl ClientT for Client { - async fn notification( - &self, - method: &str, - params: Params, - ) -> StdResult<(), JrpcError> + async fn notification(&self, method: &str, params: Params) -> Result<(), JrpcError> where Params: ToRpcParams + Send, { self.client.notification(method, params).await } - async fn request(&self, method: &str, params: Params) -> StdResult + async fn request(&self, method: &str, params: Params) -> Result where R: DeserializeOwned, Params: ToRpcParams + Send, @@ -209,7 +201,7 @@ mod wasm { async fn batch_request<'a, R>( &self, batch: BatchRequestBuilder<'a>, - ) -> StdResult, JrpcError> + ) -> Result, JrpcError> where R: DeserializeOwned + fmt::Debug + 'a, { @@ -224,7 +216,7 @@ mod wasm { subscribe_method: &'a str, params: Params, unsubscribe_method: &'a str, - ) -> StdResult, JrpcError> + ) -> Result, JrpcError> where Params: ToRpcParams + Send, N: DeserializeOwned, @@ -237,7 +229,7 @@ mod wasm { async fn subscribe_to_method<'a, N>( &self, method: &'a str, - ) -> StdResult, JrpcError> + ) -> Result, JrpcError> where N: DeserializeOwned, {