Skip to content

Commit

Permalink
fix: updating run-bridge to use skip auth, organizing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd committed Apr 15, 2024
1 parent 9774fb0 commit 33459bb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 36 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ci/run-bridge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
8 changes: 4 additions & 4 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
44 changes: 18 additions & 26 deletions rpc/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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.
Expand All @@ -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<Self> {
pub async fn new(conn_str: &str, auth_token: Option<&str>) -> Result<Self, Error> {
let mut headers = HeaderMap::new();

if let Some(token) = auth_token {
Expand Down Expand Up @@ -73,11 +73,7 @@ mod native {

#[async_trait]
impl ClientT for Client {
async fn notification<Params>(
&self,
method: &str,
params: Params,
) -> StdResult<(), JrpcError>
async fn notification<Params>(&self, method: &str, params: Params) -> Result<(), JrpcError>
where
Params: ToRpcParams + Send,
{
Expand All @@ -87,7 +83,7 @@ mod native {
}
}

async fn request<R, Params>(&self, method: &str, params: Params) -> StdResult<R, JrpcError>
async fn request<R, Params>(&self, method: &str, params: Params) -> Result<R, JrpcError>
where
R: DeserializeOwned,
Params: ToRpcParams + Send,
Expand All @@ -101,7 +97,7 @@ mod native {
async fn batch_request<'a, R>(
&self,
batch: BatchRequestBuilder<'a>,
) -> StdResult<BatchResponse<'a, R>, JrpcError>
) -> Result<BatchResponse<'a, R>, JrpcError>
where
R: DeserializeOwned + fmt::Debug + 'a,
{
Expand All @@ -119,7 +115,7 @@ mod native {
subscribe_method: &'a str,
params: Params,
unsubscribe_method: &'a str,
) -> StdResult<Subscription<N>, JrpcError>
) -> Result<Subscription<N>, JrpcError>
where
Params: ToRpcParams + Send,
N: DeserializeOwned,
Expand All @@ -141,7 +137,7 @@ mod native {
async fn subscribe_to_method<'a, N>(
&self,
method: &'a str,
) -> StdResult<Subscription<N>, JrpcError>
) -> Result<Subscription<N>, JrpcError>
where
N: DeserializeOwned,
{
Expand All @@ -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;
Expand All @@ -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<Self> {
pub async fn new(conn_str: &str) -> Result<Self, Error> {
// 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);
Expand All @@ -187,18 +183,14 @@ mod wasm {

#[async_trait]
impl ClientT for Client {
async fn notification<Params>(
&self,
method: &str,
params: Params,
) -> StdResult<(), JrpcError>
async fn notification<Params>(&self, method: &str, params: Params) -> Result<(), JrpcError>
where
Params: ToRpcParams + Send,
{
self.client.notification(method, params).await
}

async fn request<R, Params>(&self, method: &str, params: Params) -> StdResult<R, JrpcError>
async fn request<R, Params>(&self, method: &str, params: Params) -> Result<R, JrpcError>
where
R: DeserializeOwned,
Params: ToRpcParams + Send,
Expand All @@ -209,7 +201,7 @@ mod wasm {
async fn batch_request<'a, R>(
&self,
batch: BatchRequestBuilder<'a>,
) -> StdResult<BatchResponse<'a, R>, JrpcError>
) -> Result<BatchResponse<'a, R>, JrpcError>
where
R: DeserializeOwned + fmt::Debug + 'a,
{
Expand All @@ -224,7 +216,7 @@ mod wasm {
subscribe_method: &'a str,
params: Params,
unsubscribe_method: &'a str,
) -> StdResult<Subscription<N>, JrpcError>
) -> Result<Subscription<N>, JrpcError>
where
Params: ToRpcParams + Send,
N: DeserializeOwned,
Expand All @@ -237,7 +229,7 @@ mod wasm {
async fn subscribe_to_method<'a, N>(
&self,
method: &'a str,
) -> StdResult<Subscription<N>, JrpcError>
) -> Result<Subscription<N>, JrpcError>
where
N: DeserializeOwned,
{
Expand Down

0 comments on commit 33459bb

Please sign in to comment.