cargo fmt with stable defaults (#876)

This commit is contained in:
James Wilson
2023-03-21 16:53:47 +00:00
committed by GitHub
parent c63ff6ec6d
commit 7c252fccf7
110 changed files with 663 additions and 1949 deletions
+3 -15
View File
@@ -2,24 +2,12 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use super::{
RpcClientT,
RpcFuture,
RpcSubscription,
};
use super::{RpcClientT, RpcFuture, RpcSubscription};
use crate::error::RpcError;
use futures::stream::{
StreamExt,
TryStreamExt,
};
use futures::stream::{StreamExt, TryStreamExt};
use jsonrpsee::{
core::{
client::{
Client,
ClientT,
SubscriptionClientT,
SubscriptionKind,
},
client::{Client, ClientT, SubscriptionClientT, SubscriptionKind},
traits::ToRpcParams,
Error as JsonRpseeError,
},
+2 -12
View File
@@ -58,17 +58,7 @@ pub mod types;
pub use rpc::*;
pub use rpc_client_t::{
RawValue,
RpcClientT,
RpcFuture,
RpcSubscription,
RpcSubscriptionId,
RpcSubscriptionStream,
RawValue, RpcClientT, RpcFuture, RpcSubscription, RpcSubscriptionId, RpcSubscriptionStream,
};
pub use rpc_client::{
rpc_params,
RpcClient,
RpcParams,
Subscription,
};
pub use rpc_client::{rpc_params, RpcClient, RpcParams, Subscription};
+11 -43
View File
@@ -33,25 +33,11 @@
use super::{
rpc_params,
types::{
self,
ChainHeadEvent,
FollowEvent,
},
RpcClient,
RpcClientT,
Subscription,
};
use crate::{
error::Error,
utils::PhantomDataSendSync,
Config,
Metadata,
};
use codec::{
Decode,
Encode,
types::{self, ChainHeadEvent, FollowEvent},
RpcClient, RpcClientT, Subscription,
};
use crate::{error::Error, utils::PhantomDataSendSync, Config, Metadata};
use codec::{Decode, Encode};
use frame_metadata::RuntimeMetadataPrefixed;
use serde::Serialize;
use std::sync::Arc;
@@ -222,10 +208,7 @@ impl<T: Config> Rpc<T> {
}
/// Get a header
pub async fn header(
&self,
hash: Option<T::Hash>,
) -> Result<Option<T::Header>, Error> {
pub async fn header(&self, hash: Option<T::Hash>) -> Result<Option<T::Header>, Error> {
let params = rpc_params![hash];
let header = self.client.request("chain_getHeader", params).await?;
Ok(header)
@@ -300,9 +283,7 @@ impl<T: Config> Rpc<T> {
}
/// Subscribe to all new best block headers.
pub async fn subscribe_best_block_headers(
&self,
) -> Result<Subscription<T::Header>, Error> {
pub async fn subscribe_best_block_headers(&self) -> Result<Subscription<T::Header>, Error> {
let subscription = self
.client
.subscribe(
@@ -319,9 +300,7 @@ impl<T: Config> Rpc<T> {
}
/// Subscribe to all new block headers.
pub async fn subscribe_all_block_headers(
&self,
) -> Result<Subscription<T::Header>, Error> {
pub async fn subscribe_all_block_headers(&self) -> Result<Subscription<T::Header>, Error> {
let subscription = self
.client
.subscribe(
@@ -374,10 +353,7 @@ impl<T: Config> Rpc<T> {
}
/// Create and submit an extrinsic and return corresponding Hash if successful
pub async fn submit_extrinsic<X: Encode>(
&self,
extrinsic: X,
) -> Result<T::Hash, Error> {
pub async fn submit_extrinsic<X: Encode>(&self, extrinsic: X) -> Result<T::Hash, Error> {
let bytes: types::Bytes = extrinsic.encode().into();
let params = rpc_params![bytes];
let xt_hash = self
@@ -448,10 +424,7 @@ impl<T: Config> Rpc<T> {
/// `session_keys` is the SCALE encoded session keys object from the runtime.
///
/// Returns `true` iff all private keys could be found.
pub async fn has_session_keys(
&self,
session_keys: types::Bytes,
) -> Result<bool, Error> {
pub async fn has_session_keys(&self, session_keys: types::Bytes) -> Result<bool, Error> {
let params = rpc_params![session_keys];
self.client.request("author_hasSessionKeys", params).await
}
@@ -459,11 +432,7 @@ impl<T: Config> Rpc<T> {
/// Checks if the keystore has private keys for the given public key and key type.
///
/// Returns `true` if a private key could be found.
pub async fn has_key(
&self,
public_key: types::Bytes,
key_type: String,
) -> Result<bool, Error> {
pub async fn has_key(&self, public_key: types::Bytes, key_type: String) -> Result<bool, Error> {
let params = rpc_params![public_key, key_type];
self.client.request("author_hasKey", params).await
}
@@ -477,8 +446,7 @@ impl<T: Config> Rpc<T> {
at: Option<T::Hash>,
) -> Result<types::DryRunResult, Error> {
let params = rpc_params![to_hex(encoded_signed), at];
let result_bytes: types::Bytes =
self.client.request("system_dryRun", params).await?;
let result_bytes: types::Bytes = self.client.request("system_dryRun", params).await?;
Ok(types::decode_dry_run_result(&mut &*result_bytes.0)?)
}
+6 -21
View File
@@ -2,26 +2,12 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use super::{
RpcClientT,
RpcSubscription,
RpcSubscriptionId,
};
use super::{RpcClientT, RpcSubscription, RpcSubscriptionId};
use crate::error::Error;
use futures::{
Stream,
StreamExt,
};
use serde::{
de::DeserializeOwned,
Serialize,
};
use futures::{Stream, StreamExt};
use serde::{de::DeserializeOwned, Serialize};
use serde_json::value::RawValue;
use std::{
pin::Pin,
sync::Arc,
task::Poll,
};
use std::{pin::Pin, sync::Arc, task::Poll};
/// A concrete wrapper around an [`RpcClientT`] which exposes the udnerlying interface via some
/// higher level methods that make it a little easier to work with.
@@ -214,9 +200,8 @@ impl<Res: DeserializeOwned> Stream for Subscription<Res> {
// Decode the inner RawValue to the type we're expecting and map
// any errors to the right shape:
let res = res.map(|r| {
r.map_err(|e| e.into()).and_then(|raw_val| {
serde_json::from_str(raw_val.get()).map_err(|e| e.into())
})
r.map_err(|e| e.into())
.and_then(|raw_val| serde_json::from_str(raw_val.get()).map_err(|e| e.into()))
});
Poll::Ready(res)
+2 -6
View File
@@ -4,10 +4,7 @@
use crate::error::RpcError;
use futures::Stream;
use std::{
future::Future,
pin::Pin,
};
use std::{future::Future, pin::Pin};
// Re-exporting for simplicity since it's used a bunch in the trait definition.
pub use serde_json::value::RawValue;
@@ -56,8 +53,7 @@ pub trait RpcClientT: Send + Sync + 'static {
}
/// A boxed future that is returned from the [`RpcClientT`] methods.
pub type RpcFuture<'a, T> =
Pin<Box<dyn Future<Output = Result<T, RpcError>> + Send + 'a>>;
pub type RpcFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, RpcError>> + Send + 'a>>;
/// The RPC subscription returned from [`RpcClientT`]'s `subscription` method.
pub struct RpcSubscription {
+25 -76
View File
@@ -5,15 +5,9 @@
//! Types sent to/from the Substrate RPC interface.
use crate::Config;
use codec::{
Decode,
Encode,
};
use codec::{Decode, Encode};
use primitive_types::U256;
use serde::{
Deserialize,
Serialize,
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
// Subscription types are returned from some calls, so expose it with the rest of the returned types.
@@ -334,17 +328,7 @@ pub struct BlockStats {
/// Storage key.
#[derive(
Serialize,
Deserialize,
Hash,
PartialOrd,
Ord,
PartialEq,
Eq,
Clone,
Encode,
Decode,
Debug,
Serialize, Deserialize, Hash, PartialOrd, Ord, PartialEq, Eq, Clone, Encode, Decode, Debug,
)]
pub struct StorageKey(#[serde(with = "impl_serde::serialize")] pub Vec<u8>);
impl AsRef<[u8]> for StorageKey {
@@ -355,17 +339,7 @@ impl AsRef<[u8]> for StorageKey {
/// Storage data.
#[derive(
Serialize,
Deserialize,
Hash,
PartialOrd,
Ord,
PartialEq,
Eq,
Clone,
Encode,
Decode,
Debug,
Serialize, Deserialize, Hash, PartialOrd, Ord, PartialEq, Eq, Clone, Encode, Decode, Debug,
)]
pub struct StorageData(#[serde(with = "impl_serde::serialize")] pub Vec<u8>);
impl AsRef<[u8]> for StorageData {
@@ -709,14 +683,10 @@ impl<Hash> From<TransactionEvent<Hash>> for TransactionEventIR<Hash> {
TransactionEventIR::NonBlock(TransactionEventNonBlockIR::Validated)
}
TransactionEvent::Broadcasted(event) => {
TransactionEventIR::NonBlock(TransactionEventNonBlockIR::Broadcasted(
event,
))
TransactionEventIR::NonBlock(TransactionEventNonBlockIR::Broadcasted(event))
}
TransactionEvent::BestChainBlockIncluded(event) => {
TransactionEventIR::Block(
TransactionEventBlockIR::BestChainBlockIncluded(event),
)
TransactionEventIR::Block(TransactionEventBlockIR::BestChainBlockIncluded(event))
}
TransactionEvent::Finalized(event) => {
TransactionEventIR::Block(TransactionEventBlockIR::Finalized(event))
@@ -737,33 +707,21 @@ impl<Hash> From<TransactionEvent<Hash>> for TransactionEventIR<Hash> {
impl<Hash> From<TransactionEventIR<Hash>> for TransactionEvent<Hash> {
fn from(value: TransactionEventIR<Hash>) -> Self {
match value {
TransactionEventIR::NonBlock(status) => {
match status {
TransactionEventNonBlockIR::Validated => TransactionEvent::Validated,
TransactionEventNonBlockIR::Broadcasted(event) => {
TransactionEvent::Broadcasted(event)
}
TransactionEventNonBlockIR::Error(event) => {
TransactionEvent::Error(event)
}
TransactionEventNonBlockIR::Invalid(event) => {
TransactionEvent::Invalid(event)
}
TransactionEventNonBlockIR::Dropped(event) => {
TransactionEvent::Dropped(event)
}
TransactionEventIR::NonBlock(status) => match status {
TransactionEventNonBlockIR::Validated => TransactionEvent::Validated,
TransactionEventNonBlockIR::Broadcasted(event) => {
TransactionEvent::Broadcasted(event)
}
}
TransactionEventIR::Block(block) => {
match block {
TransactionEventBlockIR::Finalized(event) => {
TransactionEvent::Finalized(event)
}
TransactionEventBlockIR::BestChainBlockIncluded(event) => {
TransactionEvent::BestChainBlockIncluded(event)
}
TransactionEventNonBlockIR::Error(event) => TransactionEvent::Error(event),
TransactionEventNonBlockIR::Invalid(event) => TransactionEvent::Invalid(event),
TransactionEventNonBlockIR::Dropped(event) => TransactionEvent::Dropped(event),
},
TransactionEventIR::Block(block) => match block {
TransactionEventBlockIR::Finalized(event) => TransactionEvent::Finalized(event),
TransactionEventBlockIR::BestChainBlockIncluded(event) => {
TransactionEvent::BestChainBlockIncluded(event)
}
}
},
}
}
}
@@ -773,9 +731,7 @@ mod as_string {
use super::*;
use serde::Deserializer;
pub fn deserialize<'de, D: Deserializer<'de>>(
deserializer: D,
) -> Result<usize, D::Error> {
pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result<usize, D::Error> {
String::deserialize(deserializer)?
.parse()
.map_err(|e| serde::de::Error::custom(format!("Parsing failed: {e}")))
@@ -789,10 +745,7 @@ mod test {
/// A util function to assert the result of serialization and deserialization is the same.
pub fn assert_deser<T>(s: &str, expected: T)
where
T: std::fmt::Debug
+ serde::ser::Serialize
+ serde::de::DeserializeOwned
+ PartialEq,
T: std::fmt::Debug + serde::ser::Serialize + serde::de::DeserializeOwned + PartialEq,
{
assert_eq!(serde_json::from_str::<T>(s).unwrap(), expected);
assert_eq!(serde_json::to_string(&expected).unwrap(), s);
@@ -820,10 +773,8 @@ mod test {
..Default::default()
};
let json = serde_json::to_string(&substrate_runtime_version)
.expect("serializing failed");
let val: RuntimeVersion =
serde_json::from_str(&json).expect("deserializing failed");
let json = serde_json::to_string(&substrate_runtime_version).expect("serializing failed");
let val: RuntimeVersion = serde_json::from_str(&json).expect("deserializing failed");
// We ignore any other properties.
assert_eq!(val.spec_version, 123);
@@ -873,8 +824,7 @@ mod test {
InvalidTransaction as SpInvalidTransaction,
TransactionValidityError as SpTransactionValidityError,
},
ApplyExtrinsicResult as SpApplyExtrinsicResult,
DispatchError as SpDispatchError,
ApplyExtrinsicResult as SpApplyExtrinsicResult, DispatchError as SpDispatchError,
};
let pairs = vec![
@@ -915,8 +865,7 @@ mod test {
#[test]
fn storage_types_are_substrate_compatible() {
use sp_core::storage::{
StorageChangeSet as SpStorageChangeSet,
StorageData as SpStorageData,
StorageChangeSet as SpStorageChangeSet, StorageData as SpStorageData,
StorageKey as SpStorageKey,
};