Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
+118 -78
View File
@@ -24,34 +24,39 @@ mod state_light;
#[cfg(test)]
mod tests;
use jsonrpc_pubsub::{manager::SubscriptionManager, typed::Subscriber, SubscriptionId};
use rpc::{
futures::{future::result, Future},
Result as RpcResult,
};
use std::sync::Arc;
use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId, manager::SubscriptionManager};
use rpc::{Result as RpcResult, futures::{Future, future::result}};
use sc_rpc_api::{DenyUnsafe, state::ReadProof};
use sc_client_api::light::{RemoteBlockchain, Fetcher};
use sp_core::{Bytes, storage::{StorageKey, PrefixedStorageKey, StorageData, StorageChangeSet}};
use sp_version::RuntimeVersion;
use sc_client_api::light::{Fetcher, RemoteBlockchain};
use sc_rpc_api::{state::ReadProof, DenyUnsafe};
use sp_core::{
storage::{PrefixedStorageKey, StorageChangeSet, StorageData, StorageKey},
Bytes,
};
use sp_runtime::traits::Block as BlockT;
use sp_version::RuntimeVersion;
use sp_api::{Metadata, ProvideRuntimeApi, CallApiAt};
use sp_api::{CallApiAt, Metadata, ProvideRuntimeApi};
use self::error::{Error, FutureResult};
pub use sc_rpc_api::state::*;
pub use sc_rpc_api::child_state::*;
use sc_client_api::{
ExecutorProvider, StorageProvider, BlockchainEvents, Backend, BlockBackend, ProofProvider
Backend, BlockBackend, BlockchainEvents, ExecutorProvider, ProofProvider, StorageProvider,
};
use sp_blockchain::{HeaderMetadata, HeaderBackend};
pub use sc_rpc_api::{child_state::*, state::*};
use sp_blockchain::{HeaderBackend, HeaderMetadata};
const STORAGE_KEYS_PAGED_MAX_COUNT: u32 = 1000;
/// State backend API.
pub trait StateBackend<Block: BlockT, Client>: Send + Sync + 'static
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
{
/// Call runtime method at given block.
fn call(
@@ -129,7 +134,7 @@ pub trait StateBackend<Block: BlockT, Client>: Send + Sync + 'static
fn query_storage_at(
&self,
keys: Vec<StorageKey>,
at: Option<Block::Hash>
at: Option<Block::Hash>,
) -> FutureResult<Vec<StorageChangeSet<Block::Hash>>>;
/// Returns proof of storage entries at a specific block's state.
@@ -184,21 +189,30 @@ pub fn new_full<BE, Block: BlockT, Client>(
deny_unsafe: DenyUnsafe,
rpc_max_payload: Option<usize>,
) -> (State<Block, Client>, ChildState<Block, Client>)
where
Block: BlockT + 'static,
BE: Backend<Block> + 'static,
Client: ExecutorProvider<Block> + StorageProvider<Block, BE> + ProofProvider<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error> + BlockchainEvents<Block>
+ CallApiAt<Block> + HeaderBackend<Block>
+ BlockBackend<Block> + ProvideRuntimeApi<Block> + Send + Sync + 'static,
Client::Api: Metadata<Block>,
where
Block: BlockT + 'static,
BE: Backend<Block> + 'static,
Client: ExecutorProvider<Block>
+ StorageProvider<Block, BE>
+ ProofProvider<Block>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>
+ BlockchainEvents<Block>
+ CallApiAt<Block>
+ HeaderBackend<Block>
+ BlockBackend<Block>
+ ProvideRuntimeApi<Block>
+ Send
+ Sync
+ 'static,
Client::Api: Metadata<Block>,
{
let child_backend = Box::new(
self::state_full::FullState::new(
client.clone(), subscriptions.clone(), rpc_max_payload
)
);
let backend = Box::new(self::state_full::FullState::new(client, subscriptions, rpc_max_payload));
let child_backend = Box::new(self::state_full::FullState::new(
client.clone(),
subscriptions.clone(),
rpc_max_payload,
));
let backend =
Box::new(self::state_full::FullState::new(client, subscriptions, rpc_max_payload));
(State { backend, deny_unsafe }, ChildState { backend: child_backend })
}
@@ -210,27 +224,32 @@ pub fn new_light<BE, Block: BlockT, Client, F: Fetcher<Block>>(
fetcher: Arc<F>,
deny_unsafe: DenyUnsafe,
) -> (State<Block, Client>, ChildState<Block, Client>)
where
Block: BlockT + 'static,
BE: Backend<Block> + 'static,
Client: ExecutorProvider<Block> + StorageProvider<Block, BE>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>
+ ProvideRuntimeApi<Block> + HeaderBackend<Block> + BlockchainEvents<Block>
+ Send + Sync + 'static,
F: Send + Sync + 'static,
where
Block: BlockT + 'static,
BE: Backend<Block> + 'static,
Client: ExecutorProvider<Block>
+ StorageProvider<Block, BE>
+ HeaderMetadata<Block, Error = sp_blockchain::Error>
+ ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ BlockchainEvents<Block>
+ Send
+ Sync
+ 'static,
F: Send + Sync + 'static,
{
let child_backend = Box::new(self::state_light::LightState::new(
client.clone(),
subscriptions.clone(),
remote_blockchain.clone(),
fetcher.clone(),
client.clone(),
subscriptions.clone(),
remote_blockchain.clone(),
fetcher.clone(),
));
let backend = Box::new(self::state_light::LightState::new(
client,
subscriptions,
remote_blockchain,
fetcher,
client,
subscriptions,
remote_blockchain,
fetcher,
));
(State { backend, deny_unsafe }, ChildState { backend: child_backend })
}
@@ -243,9 +262,9 @@ pub struct State<Block, Client> {
}
impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
{
type Metadata = crate::Metadata;
@@ -281,25 +300,35 @@ impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
block: Option<Block::Hash>,
) -> FutureResult<Vec<StorageKey>> {
if count > STORAGE_KEYS_PAGED_MAX_COUNT {
return Box::new(result(Err(
Error::InvalidCount {
value: count,
max: STORAGE_KEYS_PAGED_MAX_COUNT,
}
)));
return Box::new(result(Err(Error::InvalidCount {
value: count,
max: STORAGE_KEYS_PAGED_MAX_COUNT,
})))
}
self.backend.storage_keys_paged(block, prefix, count, start_key)
}
fn storage(&self, key: StorageKey, block: Option<Block::Hash>) -> FutureResult<Option<StorageData>> {
fn storage(
&self,
key: StorageKey,
block: Option<Block::Hash>,
) -> FutureResult<Option<StorageData>> {
self.backend.storage(block, key)
}
fn storage_hash(&self, key: StorageKey, block: Option<Block::Hash>) -> FutureResult<Option<Block::Hash>> {
fn storage_hash(
&self,
key: StorageKey,
block: Option<Block::Hash>,
) -> FutureResult<Option<Block::Hash>> {
self.backend.storage_hash(block, key)
}
fn storage_size(&self, key: StorageKey, block: Option<Block::Hash>) -> FutureResult<Option<u64>> {
fn storage_size(
&self,
key: StorageKey,
block: Option<Block::Hash>,
) -> FutureResult<Option<u64>> {
self.backend.storage_size(block, key)
}
@@ -311,7 +340,7 @@ impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
&self,
keys: Vec<StorageKey>,
from: Block::Hash,
to: Option<Block::Hash>
to: Option<Block::Hash>,
) -> FutureResult<Vec<StorageChangeSet<Block::Hash>>> {
if let Err(err) = self.deny_unsafe.check_if_safe() {
return Box::new(result(Err(err.into())))
@@ -323,12 +352,16 @@ impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
fn query_storage_at(
&self,
keys: Vec<StorageKey>,
at: Option<Block::Hash>
at: Option<Block::Hash>,
) -> FutureResult<Vec<StorageChangeSet<Block::Hash>>> {
self.backend.query_storage_at(keys, at)
}
fn read_proof(&self, keys: Vec<StorageKey>, block: Option<Block::Hash>) -> FutureResult<ReadProof<Block::Hash>> {
fn read_proof(
&self,
keys: Vec<StorageKey>,
block: Option<Block::Hash>,
) -> FutureResult<ReadProof<Block::Hash>> {
self.backend.read_proof(block, keys)
}
@@ -336,12 +369,16 @@ impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
&self,
meta: Self::Metadata,
subscriber: Subscriber<StorageChangeSet<Block::Hash>>,
keys: Option<Vec<StorageKey>>
keys: Option<Vec<StorageKey>>,
) {
self.backend.subscribe_storage(meta, subscriber, keys);
}
fn unsubscribe_storage(&self, meta: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool> {
fn unsubscribe_storage(
&self,
meta: Option<Self::Metadata>,
id: SubscriptionId,
) -> RpcResult<bool> {
self.backend.unsubscribe_storage(meta, id)
}
@@ -349,7 +386,11 @@ impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
self.backend.runtime_version(at)
}
fn subscribe_runtime_version(&self, meta: Self::Metadata, subscriber: Subscriber<RuntimeVersion>) {
fn subscribe_runtime_version(
&self,
meta: Self::Metadata,
subscriber: Subscriber<RuntimeVersion>,
) {
self.backend.subscribe_runtime_version(meta, subscriber);
}
@@ -367,9 +408,10 @@ impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
/// Note: requires the node to run with `--rpc-methods=Unsafe`.
/// Note: requires runtimes compiled with wasm tracing support, `--features with-tracing`.
fn trace_block(
&self, block: Block::Hash,
&self,
block: Block::Hash,
targets: Option<String>,
storage_keys: Option<String>
storage_keys: Option<String>,
) -> FutureResult<sp_rpc::tracing::TraceBlockResponse> {
if let Err(err) = self.deny_unsafe.check_if_safe() {
return Box::new(result(Err(err.into())))
@@ -381,9 +423,9 @@ impl<Block, Client> StateApi<Block::Hash> for State<Block, Client>
/// Child state backend API.
pub trait ChildStateBackend<Block: BlockT, Client>: Send + Sync + 'static
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
{
/// Returns proof of storage for a child key entries at a specific block's state.
fn read_child_proof(
@@ -435,8 +477,7 @@ pub trait ChildStateBackend<Block: BlockT, Client>: Send + Sync + 'static
storage_key: PrefixedStorageKey,
key: StorageKey,
) -> FutureResult<Option<u64>> {
Box::new(self.storage(block, storage_key, key)
.map(|x| x.map(|x| x.0.len() as u64)))
Box::new(self.storage(block, storage_key, key).map(|x| x.map(|x| x.0.len() as u64)))
}
}
@@ -446,9 +487,9 @@ pub struct ChildState<Block, Client> {
}
impl<Block, Client> ChildStateApi<Block::Hash> for ChildState<Block, Client>
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
where
Block: BlockT + 'static,
Client: Send + Sync + 'static,
{
type Metadata = crate::Metadata;
@@ -465,7 +506,7 @@ impl<Block, Client> ChildStateApi<Block::Hash> for ChildState<Block, Client>
&self,
storage_key: PrefixedStorageKey,
key: StorageKey,
block: Option<Block::Hash>
block: Option<Block::Hash>,
) -> FutureResult<Option<StorageData>> {
self.backend.storage(block, storage_key, key)
}
@@ -474,7 +515,7 @@ impl<Block, Client> ChildStateApi<Block::Hash> for ChildState<Block, Client>
&self,
storage_key: PrefixedStorageKey,
key_prefix: StorageKey,
block: Option<Block::Hash>
block: Option<Block::Hash>,
) -> FutureResult<Vec<StorageKey>> {
self.backend.storage_keys(block, storage_key, key_prefix)
}
@@ -494,7 +535,7 @@ impl<Block, Client> ChildStateApi<Block::Hash> for ChildState<Block, Client>
&self,
storage_key: PrefixedStorageKey,
key: StorageKey,
block: Option<Block::Hash>
block: Option<Block::Hash>,
) -> FutureResult<Option<Block::Hash>> {
self.backend.storage_hash(block, storage_key, key)
}
@@ -503,11 +544,10 @@ impl<Block, Client> ChildStateApi<Block::Hash> for ChildState<Block, Client>
&self,
storage_key: PrefixedStorageKey,
key: StorageKey,
block: Option<Block::Hash>
block: Option<Block::Hash>,
) -> FutureResult<Option<u64>> {
self.backend.storage_size(block, storage_key, key)
}
}
fn client_err(err: sp_blockchain::Error) -> Error {