mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 10:01:17 +00:00
update jsonrpsee to 0.2.0-alpha.6 (#266)
* update jsonrpsee to 0.2.0-alpha.5 * downgrade subxt client * cleanup * make subxt-client compile again * update jsonrpsee v0.2.0-alpha.6 * fix build again * remove needless type hints * cargo fmt * address grumbles * remove remaining type hints * cargo fmt
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use jsonrpsee_types::error::Error as RequestError;
|
||||
use jsonrpsee_ws_client::Error as RequestError;
|
||||
use sp_core::crypto::SecretStringError;
|
||||
use sp_runtime::{
|
||||
transaction_validity::TransactionValidityError,
|
||||
|
||||
+9
-11
@@ -51,14 +51,10 @@ use codec::{
|
||||
Decode,
|
||||
};
|
||||
use futures::future;
|
||||
use jsonrpsee_http_client::{
|
||||
HttpClient,
|
||||
HttpConfig,
|
||||
};
|
||||
use jsonrpsee_http_client::HttpClientBuilder;
|
||||
use jsonrpsee_ws_client::{
|
||||
WsClient,
|
||||
WsConfig,
|
||||
WsSubscription as Subscription,
|
||||
Subscription,
|
||||
WsClientBuilder,
|
||||
};
|
||||
use sp_core::{
|
||||
storage::{
|
||||
@@ -212,11 +208,13 @@ impl<T: Runtime> ClientBuilder<T> {
|
||||
} else {
|
||||
let url = self.url.as_deref().unwrap_or("ws://127.0.0.1:9944");
|
||||
if url.starts_with("ws://") || url.starts_with("wss://") {
|
||||
let mut config = WsConfig::with_url(&url);
|
||||
config.max_notifs_per_subscription = 4096;
|
||||
RpcClient::WebSocket(Arc::new(WsClient::new(config).await?))
|
||||
let client = WsClientBuilder::default()
|
||||
.max_notifs_per_subscription(4096)
|
||||
.build(&url)
|
||||
.await?;
|
||||
RpcClient::WebSocket(Arc::new(client))
|
||||
} else {
|
||||
let client = HttpClient::new(url, HttpConfig::default())?;
|
||||
let client = HttpClientBuilder::default().build(&url)?;
|
||||
RpcClient::Http(Arc::new(client))
|
||||
}
|
||||
};
|
||||
|
||||
+44
-63
@@ -31,22 +31,18 @@ use core::{
|
||||
marker::PhantomData,
|
||||
};
|
||||
use frame_metadata::RuntimeMetadataPrefixed;
|
||||
use jsonrpsee_http_client::HttpClient;
|
||||
use jsonrpsee_types::{
|
||||
error::Error as RpcError,
|
||||
jsonrpc::{
|
||||
to_value as to_json_value,
|
||||
DeserializeOwned,
|
||||
Params,
|
||||
},
|
||||
traits::{
|
||||
Client,
|
||||
SubscriptionClient,
|
||||
},
|
||||
use jsonrpsee_http_client::{
|
||||
to_json_value,
|
||||
traits::Client,
|
||||
DeserializeOwned,
|
||||
Error as RpcError,
|
||||
HttpClient,
|
||||
JsonValue,
|
||||
};
|
||||
use jsonrpsee_ws_client::{
|
||||
traits::SubscriptionClient,
|
||||
Subscription,
|
||||
WsClient,
|
||||
WsSubscription as Subscription,
|
||||
};
|
||||
use serde::{
|
||||
Deserialize,
|
||||
@@ -176,28 +172,32 @@ pub enum RpcClient {
|
||||
|
||||
impl RpcClient {
|
||||
/// Start a JSON-RPC request.
|
||||
pub async fn request<T: DeserializeOwned>(
|
||||
pub async fn request<'a, T: DeserializeOwned + std::fmt::Debug>(
|
||||
&self,
|
||||
method: &str,
|
||||
params: Params,
|
||||
params: &[JsonValue],
|
||||
) -> Result<T, Error> {
|
||||
match self {
|
||||
let params = params.into();
|
||||
let data = match self {
|
||||
Self::WebSocket(inner) => {
|
||||
inner.request(method, params).await.map_err(Into::into)
|
||||
}
|
||||
Self::Http(inner) => inner.request(method, params).await.map_err(Into::into),
|
||||
#[cfg(feature = "client")]
|
||||
Self::Subxt(inner) => inner.request(method, params).await.map_err(Into::into),
|
||||
}
|
||||
};
|
||||
log::debug!("{}: {:?}", method, data);
|
||||
data
|
||||
}
|
||||
|
||||
/// Start a JSON-RPC Subscription.
|
||||
pub async fn subscribe<T: DeserializeOwned>(
|
||||
pub async fn subscribe<'a, T: DeserializeOwned>(
|
||||
&self,
|
||||
subscribe_method: &str,
|
||||
params: Params,
|
||||
params: &[JsonValue],
|
||||
unsubscribe_method: &str,
|
||||
) -> Result<Subscription<T>, Error> {
|
||||
let params = params.into();
|
||||
match self {
|
||||
Self::WebSocket(inner) => {
|
||||
inner
|
||||
@@ -294,9 +294,8 @@ impl<T: Runtime> Rpc<T> {
|
||||
key: &StorageKey,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Option<StorageData>, Error> {
|
||||
let params = Params::Array(vec![to_json_value(key)?, to_json_value(hash)?]);
|
||||
let params = &[to_json_value(key)?, to_json_value(hash)?];
|
||||
let data = self.client.request("state_getStorage", params).await?;
|
||||
log::debug!("state_getStorage {:?}", data);
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
@@ -310,14 +309,13 @@ impl<T: Runtime> Rpc<T> {
|
||||
start_key: Option<StorageKey>,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Vec<StorageKey>, Error> {
|
||||
let params = Params::Array(vec![
|
||||
let params = &[
|
||||
to_json_value(prefix)?,
|
||||
to_json_value(count)?,
|
||||
to_json_value(start_key)?,
|
||||
to_json_value(hash)?,
|
||||
]);
|
||||
];
|
||||
let data = self.client.request("state_getKeysPaged", params).await?;
|
||||
log::debug!("state_getKeysPaged {:?}", data);
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
@@ -328,11 +326,11 @@ impl<T: Runtime> Rpc<T> {
|
||||
from: T::Hash,
|
||||
to: Option<T::Hash>,
|
||||
) -> Result<Vec<StorageChangeSet<<T as System>::Hash>>, Error> {
|
||||
let params = Params::Array(vec![
|
||||
let params = &[
|
||||
to_json_value(keys)?,
|
||||
to_json_value(from)?,
|
||||
to_json_value(to)?,
|
||||
]);
|
||||
];
|
||||
self.client
|
||||
.request("state_queryStorage", params)
|
||||
.await
|
||||
@@ -345,7 +343,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
keys: &[StorageKey],
|
||||
at: Option<T::Hash>,
|
||||
) -> Result<Vec<StorageChangeSet<<T as System>::Hash>>, Error> {
|
||||
let params = Params::Array(vec![to_json_value(keys)?, to_json_value(at)?]);
|
||||
let params = &[to_json_value(keys)?, to_json_value(at)?];
|
||||
self.client
|
||||
.request("state_queryStorageAt", params)
|
||||
.await
|
||||
@@ -355,7 +353,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
/// Fetch the genesis hash
|
||||
pub async fn genesis_hash(&self) -> Result<T::Hash, Error> {
|
||||
let block_zero = Some(ListOrValue::Value(NumberOrHex::Number(0)));
|
||||
let params = Params::Array(vec![to_json_value(block_zero)?]);
|
||||
let params = &[to_json_value(block_zero)?];
|
||||
let list_or_value: ListOrValue<Option<T::Hash>> =
|
||||
self.client.request("chain_getBlockHash", params).await?;
|
||||
match list_or_value {
|
||||
@@ -368,10 +366,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
|
||||
/// Fetch the metadata
|
||||
pub async fn metadata(&self) -> Result<Metadata, Error> {
|
||||
let bytes: Bytes = self
|
||||
.client
|
||||
.request("state_getMetadata", Params::None)
|
||||
.await?;
|
||||
let bytes: Bytes = self.client.request("state_getMetadata", &[]).await?;
|
||||
let meta: RuntimeMetadataPrefixed = Decode::decode(&mut &bytes[..])?;
|
||||
let metadata: Metadata = meta.try_into()?;
|
||||
Ok(metadata)
|
||||
@@ -379,10 +374,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
|
||||
/// Fetch system properties
|
||||
pub async fn system_properties(&self) -> Result<SystemProperties, Error> {
|
||||
Ok(self
|
||||
.client
|
||||
.request("system_properties", Params::None)
|
||||
.await?)
|
||||
Ok(self.client.request("system_properties", &[]).await?)
|
||||
}
|
||||
|
||||
/// Get a header
|
||||
@@ -390,7 +382,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
&self,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Option<T::Header>, Error> {
|
||||
let params = Params::Array(vec![to_json_value(hash)?]);
|
||||
let params = &[to_json_value(hash)?];
|
||||
let header = self.client.request("chain_getHeader", params).await?;
|
||||
Ok(header)
|
||||
}
|
||||
@@ -401,7 +393,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
block_number: Option<BlockNumber>,
|
||||
) -> Result<Option<T::Hash>, Error> {
|
||||
let block_number = block_number.map(ListOrValue::Value);
|
||||
let params = Params::Array(vec![to_json_value(block_number)?]);
|
||||
let params = &[to_json_value(block_number)?];
|
||||
let list_or_value = self.client.request("chain_getBlockHash", params).await?;
|
||||
match list_or_value {
|
||||
ListOrValue::Value(hash) => Ok(hash),
|
||||
@@ -411,10 +403,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
|
||||
/// Get a block hash of the latest finalized block
|
||||
pub async fn finalized_head(&self) -> Result<T::Hash, Error> {
|
||||
let hash = self
|
||||
.client
|
||||
.request("chain_getFinalizedHead", Params::None)
|
||||
.await?;
|
||||
let hash = self.client.request("chain_getFinalizedHead", &[]).await?;
|
||||
Ok(hash)
|
||||
}
|
||||
|
||||
@@ -423,7 +412,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
&self,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<Option<ChainBlock<T>>, Error> {
|
||||
let params = Params::Array(vec![to_json_value(hash)?]);
|
||||
let params = &[to_json_value(hash)?];
|
||||
let block = self.client.request("chain_getBlock", params).await?;
|
||||
Ok(block)
|
||||
}
|
||||
@@ -434,7 +423,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
keys: Vec<StorageKey>,
|
||||
hash: Option<T::Hash>,
|
||||
) -> Result<ReadProof<T::Hash>, Error> {
|
||||
let params = Params::Array(vec![to_json_value(keys)?, to_json_value(hash)?]);
|
||||
let params = &[to_json_value(keys)?, to_json_value(hash)?];
|
||||
let proof = self.client.request("state_getReadProof", params).await?;
|
||||
Ok(proof)
|
||||
}
|
||||
@@ -444,7 +433,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
&self,
|
||||
at: Option<T::Hash>,
|
||||
) -> Result<RuntimeVersion, Error> {
|
||||
let params = Params::Array(vec![to_json_value(at)?]);
|
||||
let params = &[to_json_value(at)?];
|
||||
let version = self
|
||||
.client
|
||||
.request("state_getRuntimeVersion", params)
|
||||
@@ -458,7 +447,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
/// `subscribe_finalized_events` to ensure events are finalized.
|
||||
pub async fn subscribe_events(&self) -> Result<EventStorageSubscription<T>, Error> {
|
||||
let keys = Some(vec![StorageKey::from(SystemEvents::new())]);
|
||||
let params = Params::Array(vec![to_json_value(keys)?]);
|
||||
let params = &[to_json_value(keys)?];
|
||||
|
||||
let subscription = self
|
||||
.client
|
||||
@@ -483,11 +472,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
pub async fn subscribe_blocks(&self) -> Result<Subscription<T::Header>, Error> {
|
||||
let subscription = self
|
||||
.client
|
||||
.subscribe(
|
||||
"chain_subscribeNewHeads",
|
||||
Params::None,
|
||||
"chain_unsubscribeNewHeads",
|
||||
)
|
||||
.subscribe("chain_subscribeNewHeads", &[], "chain_unsubscribeNewHeads")
|
||||
.await?;
|
||||
|
||||
Ok(subscription)
|
||||
@@ -501,7 +486,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
.client
|
||||
.subscribe(
|
||||
"chain_subscribeFinalizedHeads",
|
||||
Params::None,
|
||||
&[],
|
||||
"chain_unsubscribeFinalizedHeads",
|
||||
)
|
||||
.await?;
|
||||
@@ -514,7 +499,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
extrinsic: E,
|
||||
) -> Result<T::Hash, Error> {
|
||||
let bytes: Bytes = extrinsic.encode().into();
|
||||
let params = Params::Array(vec![to_json_value(bytes)?]);
|
||||
let params = &[to_json_value(bytes)?];
|
||||
let xt_hash = self
|
||||
.client
|
||||
.request("author_submitExtrinsic", params)
|
||||
@@ -527,7 +512,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
extrinsic: E,
|
||||
) -> Result<Subscription<TransactionStatus<T::Hash, T::Hash>>, Error> {
|
||||
let bytes: Bytes = extrinsic.encode().into();
|
||||
let params = Params::Array(vec![to_json_value(bytes)?]);
|
||||
let params = &[to_json_value(bytes)?];
|
||||
let subscription = self
|
||||
.client
|
||||
.subscribe(
|
||||
@@ -641,21 +626,18 @@ impl<T: Runtime> Rpc<T> {
|
||||
suri: String,
|
||||
public: Bytes,
|
||||
) -> Result<(), Error> {
|
||||
let params = Params::Array(vec![
|
||||
let params = &[
|
||||
to_json_value(key_type)?,
|
||||
to_json_value(suri)?,
|
||||
to_json_value(public)?,
|
||||
]);
|
||||
];
|
||||
self.client.request("author_insertKey", params).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Generate new session keys and returns the corresponding public keys.
|
||||
pub async fn rotate_keys(&self) -> Result<Bytes, Error> {
|
||||
Ok(self
|
||||
.client
|
||||
.request("author_rotateKeys", Params::None)
|
||||
.await?)
|
||||
Ok(self.client.request("author_rotateKeys", &[]).await?)
|
||||
}
|
||||
|
||||
/// Checks if the keystore has private keys for the given session public keys.
|
||||
@@ -664,7 +646,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
///
|
||||
/// Returns `true` iff all private keys could be found.
|
||||
pub async fn has_session_keys(&self, session_keys: Bytes) -> Result<bool, Error> {
|
||||
let params = Params::Array(vec![to_json_value(session_keys)?]);
|
||||
let params = &[to_json_value(session_keys)?];
|
||||
Ok(self.client.request("author_hasSessionKeys", params).await?)
|
||||
}
|
||||
|
||||
@@ -676,8 +658,7 @@ impl<T: Runtime> Rpc<T> {
|
||||
public_key: Bytes,
|
||||
key_type: String,
|
||||
) -> Result<bool, Error> {
|
||||
let params =
|
||||
Params::Array(vec![to_json_value(public_key)?, to_json_value(key_type)?]);
|
||||
let params = &[to_json_value(public_key)?, to_json_value(key_type)?];
|
||||
Ok(self.client.request("author_hasKey", params).await?)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use jsonrpsee_ws_client::WsSubscription as Subscription;
|
||||
use jsonrpsee_ws_client::Subscription;
|
||||
use sp_core::{
|
||||
storage::{
|
||||
StorageChangeSet,
|
||||
|
||||
Reference in New Issue
Block a user