mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
add wasm support (#700)
* get started * make it work again * make it compile again * Use async-wasm-feature of jsonrpsee from the master branch * Ensure we enable JS feature of getrandom for the wasm target * Update subxt/src/lib.rs * update jsonrpsee * fix CI * cargo fmt * fix wasm test * fix grumbles * exclude wasm-tests from workspace To avoid leaking `jsonrpsee-web` feature into the workspace Co-authored-by: Igor Matuszewski <xanewok@gmail.com>
This commit is contained in:
@@ -12,18 +12,24 @@ use futures::stream::{
|
||||
StreamExt,
|
||||
TryStreamExt,
|
||||
};
|
||||
use jsonrpsee::{
|
||||
core::client::{
|
||||
use jsonrpsee::core::{
|
||||
client::{
|
||||
Client,
|
||||
ClientT,
|
||||
SubscriptionClientT,
|
||||
},
|
||||
types::ParamsSer,
|
||||
};
|
||||
use serde_json::value::{
|
||||
RawValue,
|
||||
Value,
|
||||
traits::ToRpcParams,
|
||||
Error as JsonRpseeError,
|
||||
};
|
||||
use serde_json::value::RawValue;
|
||||
|
||||
struct Params(Option<Box<RawValue>>);
|
||||
|
||||
impl ToRpcParams for Params {
|
||||
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, JsonRpseeError> {
|
||||
Ok(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl RpcClientT for Client {
|
||||
fn request_raw<'a>(
|
||||
@@ -32,8 +38,7 @@ impl RpcClientT for Client {
|
||||
params: Option<Box<RawValue>>,
|
||||
) -> RpcFuture<'a, Box<RawValue>> {
|
||||
Box::pin(async move {
|
||||
let params = prep_params_for_jsonrpsee(params);
|
||||
let res = ClientT::request(self, method, Some(params))
|
||||
let res = ClientT::request(self, method, Params(params))
|
||||
.await
|
||||
.map_err(|e| RpcError::ClientError(Box::new(e)))?;
|
||||
Ok(res)
|
||||
@@ -47,11 +52,10 @@ impl RpcClientT for Client {
|
||||
unsub: &'a str,
|
||||
) -> RpcFuture<'a, RpcSubscription> {
|
||||
Box::pin(async move {
|
||||
let params = prep_params_for_jsonrpsee(params);
|
||||
let sub = SubscriptionClientT::subscribe::<Box<RawValue>>(
|
||||
let sub = SubscriptionClientT::subscribe::<Box<RawValue>, _>(
|
||||
self,
|
||||
sub,
|
||||
Some(params),
|
||||
Params(params),
|
||||
unsub,
|
||||
)
|
||||
.await
|
||||
@@ -62,21 +66,3 @@ impl RpcClientT for Client {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// This is ugly; we have to encode to Value's to be compat with the jsonrpc interface.
|
||||
// Remove and simplify this once something like https://github.com/paritytech/jsonrpsee/issues/862 is in:
|
||||
fn prep_params_for_jsonrpsee(params: Option<Box<RawValue>>) -> ParamsSer<'static> {
|
||||
let params = match params {
|
||||
Some(params) => params,
|
||||
// No params? avoid any work and bail early.
|
||||
None => return ParamsSer::Array(Vec::new()),
|
||||
};
|
||||
let val = serde_json::to_value(¶ms).expect("RawValue guarantees valid JSON");
|
||||
let arr = match val {
|
||||
Value::Array(arr) => arr,
|
||||
_ => {
|
||||
panic!("RPC Params are expected to be an array but got {params}");
|
||||
}
|
||||
};
|
||||
ParamsSer::Array(arr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user