Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rpc client(fix #157) #158

Merged
merged 8 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion bindings/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ reqwest = { version = "0.11", default-features = false, features = ["blocking",

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
jsonrpsee = { version = "0.20.1", features = ["macros","jsonrpsee-types","client-core"] }
jsonrpsee = { version = "0.21", features = ["macros","jsonrpsee-types","client-core"] }
uuid = "0.8"

[features]
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ macro_rules! rpc_request {
($method:expr,$builder:expr, $server_url:expr, $resp_type: ty) => {{
let params = $builder
.to_rpc_params()
.map_err(RpcError::ParseParamsError)?;
.map_err(|e| RpcError::InvalidArgument(e))?;
let request = Request::new(
$method.into(),
params.as_ref().map(|p| p.as_ref()),
Expand Down
9 changes: 6 additions & 3 deletions provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ edition = "2021"
bigdecimal = { version = "0.3.0", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"] }
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls"] }
serde = "1.0.137"
serde = "1.0"
serde_json = "1.0"
thiserror = "1.0"
wasm-bindgen = { version = "0.2.87", features = ["serde-serialize"] }
zklink_sdk_signers = { path = "../signers" }
zklink_sdk_types = { path = "../types" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
jsonrpsee = { version = "0.20.1", features = ["http-client","macros"] }
jsonrpsee = { version = "0.21", features = ["http-client","macros"] }
jsonrpsee-core = "0.21"
jsonrpsee-http-client = "0.21"

[target.'cfg(target_arch = "wasm32")'.dependencies]
jsonrpsee = { version = "0.20.1", features = ["macros","jsonrpsee-types","client-core"] }
jsonrpsee = { version = "0.21", features = ["macros","jsonrpsee-types","client-core"] }
getrandom = { version = "0.2.11", features = ["js"] }
uuid = "0.8"

Expand Down
5 changes: 2 additions & 3 deletions provider/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use jsonrpsee::core::error::Error as jsonrpseeError;
use thiserror::Error;
use wasm_bindgen::JsValue;

Expand All @@ -8,8 +7,8 @@ pub enum RpcError {
InvalidNetwork,
#[error("Invalid input parameter")]
InvalidInputParameter,
#[error("Parse params error: {0}")]
ParseParamsError(jsonrpseeError),
#[error("Invalid argument: {0}")]
InvalidArgument(serde_json::Error),
#[error("HTTP request error: {0}")]
RequestError(reqwest::Error),
#[error("Parse response error: {0}")]
Expand Down
4 changes: 2 additions & 2 deletions provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pub mod network;
pub mod response;
#[cfg(not(any(feature = "ffi", target_arch = "wasm32")))]
pub mod rpc;
#[cfg(not(target_arch = "wasm32"))]
pub mod rpc_client;

#[cfg(not(any(feature = "ffi", target_arch = "wasm32")))]
mod not_ffi {
Expand Down Expand Up @@ -39,6 +41,4 @@ mod not_ffi {
#[cfg(not(any(feature = "ffi", target_arch = "wasm32")))]
pub use crate::rpc::ZkLinkRpcClient;
#[cfg(not(any(feature = "ffi", target_arch = "wasm32")))]
pub use jsonrpsee::core::Error as RpcError;
#[cfg(not(any(feature = "ffi", target_arch = "wasm32")))]
pub use not_ffi::*;
Loading
Loading