diff --git a/sube/Cargo.toml b/sube/Cargo.toml index 9267fe1..9fcb04c 100644 --- a/sube/Cargo.toml +++ b/sube/Cargo.toml @@ -24,7 +24,7 @@ twox-hash = { version = "1.6.2", default-features = false } url = "2.5.0" # http backend -surf = { version = "2.3.2", default-features = false, optional = true } +reqwest = { version = "0.12.5", optional = true, features = ["json"]} # ws backend futures-channel = { version = "0.3.21", default-features = false, features = ["alloc"], optional = true } @@ -33,8 +33,8 @@ async-mutex = { version = "1.4.0", optional = true } async-tls = { version = "0.11.0", default-features = false, optional = true } # bin target -async-std = { version = "1.11.0", default-features = false, optional = true } -paste = { version = "1.0", optional = true } +async-std = { version = "1.11.0", optional = true } +paste = { version = "1.0" } wasm-bindgen = { version = "0.2.91", optional = true } once_cell = { version = "1.17.1", optional = true } heapless = { version = "0.7.16", optional = true } @@ -44,7 +44,7 @@ ewebsock = { git = "https://github.com/S0c5/ewebsock.git", optional = true, bran env_logger = "0.11.3" [dev-dependencies] -async-std = { version = "1.11.0", features = ["attributes"] } +async-std = { version = "1.11.0", features = ["attributes", "tokio1"] } hex-literal = "0.3.4" libwallet = { path = "../libwallet", default-features=false, features=["substrate", "mnemonic", "sr25519", "util_pin", "rand", "std" ] } rand_core = "0.6.3" @@ -52,8 +52,8 @@ rand_core = "0.6.3" [features] default = ["v14"] test = ["std", "wss", "http", "json", "v14", "dep:async-std", "dep:rand_core"] -http = ["dep:jsonrpc", "surf/h1-client-rustls"] -http-web = ["dep:jsonrpc", "dep:wasm-bindgen", "surf/wasm-client"] +http = ["dep:jsonrpc", "dep:reqwest"] +http-web = ["dep:jsonrpc", "dep:wasm-bindgen", "dep:reqwest"] json = ["scales/json"] std = [] no_std = [] @@ -71,7 +71,4 @@ features = ["http"] members = [ "sube-js", "cli" -] - -[patch.crates-io] -cookie = { git = "https://github.com/S0c5/cookie-rs.git" } +] \ No newline at end of file diff --git a/sube/examples/pallet_communities.rs b/sube/examples/pallet_communities.rs index a6c84a0..7746399 100644 --- a/sube/examples/pallet_communities.rs +++ b/sube/examples/pallet_communities.rs @@ -1,5 +1,3 @@ -use async_trait::async_trait; - use env_logger; use serde_json; use sube::{sube, ExtrinsicBody, Response, Result, SubeBuilder}; @@ -8,14 +6,14 @@ use sube::{sube, ExtrinsicBody, Response, Result, SubeBuilder}; async fn main() -> Result<()> { env_logger::init(); - let response = sube!("ws://127.0.0.1:12281/communityMemberships/collection").await?; + // let response = sube!("ws://127.0.0.1:12281/communityMemberships/collection").await?; - if let Response::ValueSet(value) = result { - let data = serde_json::to_value(&value).expect("to be serializable"); - println!("Collection {}", serde_json::to_string_pretty(&data).expect("it must return an str")); - } + // if let Response::ValueSet(value) = response { + // let data = serde_json::to_value(&value).expect("to be serializable"); + // println!("Collection {}", serde_json::to_string_pretty(&data).expect("it must return an str")); + // } - let result = sube!("ws://127.0.0.1:12281/system/account/0x12840f0626ac847d41089c4e05cf0719c5698af1e3bb87b66542de70b2de4b2b").await?; + let result = sube!("https://kreivo.io/system/account/0x12840f0626ac847d41089c4e05cf0719c5698af1e3bb87b66542de70b2de4b2b").await?; if let Response::Value(value) = result { let data = serde_json::to_value(&value).expect("to be serializable"); diff --git a/sube/examples/query_balance.rs b/sube/examples/query_balance.rs index fb9965e..250e8ab 100644 --- a/sube/examples/query_balance.rs +++ b/sube/examples/query_balance.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use core::future::{Future, IntoFuture}; use sube::{sube, Response, Result}; diff --git a/sube/examples/query_balance_builder.rs b/sube/examples/query_balance_builder.rs index 85c5409..f21e763 100644 --- a/sube/examples/query_balance_builder.rs +++ b/sube/examples/query_balance_builder.rs @@ -1,5 +1,3 @@ -use async_trait::async_trait; - use env_logger; use sube::{sube, ExtrinsicBody, Response, Result, SubeBuilder}; diff --git a/sube/src/http.rs b/sube/src/http.rs index d485de0..377108a 100644 --- a/sube/src/http.rs +++ b/sube/src/http.rs @@ -1,13 +1,13 @@ use crate::prelude::*; +use crate::rpc::{self, Rpc, RpcResult}; use core::{convert::TryInto, fmt}; use jsonrpc::{ error::{standard_error, StandardError}, - serde_json::{to_string, value::to_raw_value}, + serde_json::value::to_raw_value, }; +use reqwest::Client; use serde::Deserialize; -pub use surf::Url; - -use crate::rpc::{self, Rpc, RpcResult}; +use url::Url; #[derive(Debug)] pub struct Backend(Url); @@ -29,24 +29,22 @@ impl Rpc for Backend { T: for<'de> Deserialize<'de>, { log::info!("RPC `{}` to {}", method, &self.0); - let req = surf::post(&self.0).content_type("application/json").body( - to_string(&rpc::Request { + + let res = Client::new() + .post(self.0.to_string()) + .json(&rpc::Request { id: 1.into(), jsonrpc: Some("2.0"), method, params: &Self::convert_params(params), }) - .unwrap(), - ); - let client = surf::client().with(surf::middleware::Redirect::new(2)); - let mut res = client - .send(req) + .send() .await - .map_err(|err| rpc::Error::Transport(err.into_inner().into()))?; + .map_err(|err| rpc::Error::Transport(Box::new(err)))?; let status = res.status(); let res = if status.is_success() { - res.body_json::() + res.json::() .await .map_err(|err| { standard_error( @@ -58,9 +56,10 @@ impl Rpc for Backend { } else { log::debug!("RPC HTTP status: {}", res.status()); let err = res - .body_string() + .text() .await - .unwrap_or_else(|_| status.canonical_reason().into()); + .unwrap_or_else(|_| status.canonical_reason().expect("to have a message").into()); + let err = to_raw_value(&err).expect("error string"); return Err(if status.is_client_error() { diff --git a/sube/src/rpc.rs b/sube/src/rpc.rs index 58cfef8..f98ded2 100644 --- a/sube/src/rpc.rs +++ b/sube/src/rpc.rs @@ -106,7 +106,7 @@ impl Backend for RpcClient { log::debug!("Extrinsic: {}", extrinsic); self.0 - .rpc("author_submitExtrinsic", &[&format!("\"{}\"", &extrinsic)]) + .rpc::("author_submitExtrinsic", &[&format!("\"{}\"", &extrinsic)]) .await .map_err(|e| crate::Error::Node(e.to_string()))?; Ok(())