// Copyright 2021 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see .
//! Helper method for RPC.
use super::*;
use jsonrpsee_ws_client::types::traits::Client;
pub(crate) use jsonrpsee_ws_client::types::v2::params::JsonRpcParams;
#[macro_export]
macro_rules! params {
($($param:expr),*) => {
{
let mut __params = vec![];
$(
__params.push(serde_json::to_value($param).expect("json serialization infallible; qed."));
)*
$crate::rpc_helpers::JsonRpcParams::Array(__params)
}
};
() => {
$crate::rpc::JsonRpcParams::NoParams,
}
}
/// Make the rpc request, returning `Ret`.
pub(crate) async fn rpc<'a, Ret: serde::de::DeserializeOwned>(
client: &WsClient,
method: &'a str,
params: JsonRpcParams<'a>,
) -> Result {
client.request::(method, params).await.map_err(Into::into)
}
/// Make the rpc request, decode the outcome into `Dec`. Don't use for storage, it will fail for
/// non-existent storage items.
pub(crate) async fn rpc_decode<'a, Dec: codec::Decode>(
client: &WsClient,
method: &'a str,
params: JsonRpcParams<'a>,
) -> Result {
let bytes = rpc::(client, method, params).await?;
::decode(&mut &*bytes.0).map_err(Into::into)
}
/// Get the storage item.
pub(crate) async fn get_storage<'a, T: codec::Decode>(
client: &WsClient,
params: JsonRpcParams<'a>,
) -> Result