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
@@ -22,10 +22,13 @@
//!
//! It is required that each extension implements the [`Extension`] trait.
use sp_std::{
collections::btree_map::{BTreeMap, Entry}, any::{Any, TypeId}, ops::DerefMut, boxed::Box,
};
use crate::Error;
use sp_std::{
any::{Any, TypeId},
boxed::Box,
collections::btree_map::{BTreeMap, Entry},
ops::DerefMut,
};
/// Marker trait for types that should be registered as [`Externalities`](crate::Externalities) extension.
///
@@ -101,7 +104,11 @@ pub trait ExtensionStore {
/// Register extension `extension` with specified `type_id`.
///
/// It should return error if extension is already registered.
fn register_extension_with_type_id(&mut self, type_id: TypeId, extension: Box<dyn Extension>) -> Result<(), Error>;
fn register_extension_with_type_id(
&mut self,
type_id: TypeId,
extension: Box<dyn Extension>,
) -> Result<(), Error>;
/// Deregister extension with speicifed 'type_id' and drop it.
///
@@ -129,10 +136,7 @@ impl Extensions {
}
/// Register the given extension.
pub fn register<E: Extension>(
&mut self,
ext: E,
) {
pub fn register<E: Extension>(&mut self, ext: E) {
let type_id = ext.type_id();
self.extensions.insert(type_id, Box::new(ext));
}
@@ -154,7 +158,10 @@ impl Extensions {
/// Return a mutable reference to the requested extension.
pub fn get_mut(&mut self, ext_type_id: TypeId) -> Option<&mut dyn Any> {
self.extensions.get_mut(&ext_type_id).map(DerefMut::deref_mut).map(Extension::as_mut_any)
self.extensions
.get_mut(&ext_type_id)
.map(DerefMut::deref_mut)
.map(Extension::as_mut_any)
}
/// Deregister extension for the given `type_id`.
@@ -165,7 +172,9 @@ impl Extensions {
}
/// Returns a mutable iterator over all extensions.
pub fn iter_mut<'a>(&'a mut self) -> impl Iterator<Item = (&'a TypeId, &'a mut Box<dyn Extension>)> {
pub fn iter_mut<'a>(
&'a mut self,
) -> impl Iterator<Item = (&'a TypeId, &'a mut Box<dyn Extension>)> {
self.extensions.iter_mut()
}
}
+15 -48
View File
@@ -25,12 +25,16 @@
//!
//! This crate exposes the main [`Externalities`] trait.
use sp_std::{any::{Any, TypeId}, vec::Vec, boxed::Box};
use sp_std::{
any::{Any, TypeId},
boxed::Box,
vec::Vec,
};
use sp_storage::{ChildInfo, TrackedStorageKey};
pub use extensions::{Extension, ExtensionStore, Extensions};
pub use scope_limited::{set_and_run_with_externalities, with_externalities};
pub use extensions::{Extension, Extensions, ExtensionStore};
mod extensions;
mod scope_limited;
@@ -68,20 +72,12 @@ pub trait Externalities: ExtensionStore {
/// This may be optimized for large values.
///
/// Returns an `Option` that holds the SCALE encoded hash.
fn child_storage_hash(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Option<Vec<u8>>;
fn child_storage_hash(&self, child_info: &ChildInfo, key: &[u8]) -> Option<Vec<u8>>;
/// Read child runtime storage.
///
/// Returns an `Option` that holds the SCALE encoded hash.
fn child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Option<Vec<u8>>;
fn child_storage(&self, child_info: &ChildInfo, key: &[u8]) -> Option<Vec<u8>>;
/// Set storage entry `key` of current contract being called (effective immediately).
fn set_storage(&mut self, key: Vec<u8>, value: Vec<u8>) {
@@ -89,12 +85,7 @@ pub trait Externalities: ExtensionStore {
}
/// Set child storage entry `key` of current contract being called (effective immediately).
fn set_child_storage(
&mut self,
child_info: &ChildInfo,
key: Vec<u8>,
value: Vec<u8>,
) {
fn set_child_storage(&mut self, child_info: &ChildInfo, key: Vec<u8>, value: Vec<u8>) {
self.place_child_storage(child_info, key, Some(value))
}
@@ -104,11 +95,7 @@ pub trait Externalities: ExtensionStore {
}
/// Clear a child storage entry (`key`) of current contract being called (effective immediately).
fn clear_child_storage(
&mut self,
child_info: &ChildInfo,
key: &[u8],
) {
fn clear_child_storage(&mut self, child_info: &ChildInfo, key: &[u8]) {
self.place_child_storage(child_info, key.to_vec(), None)
}
@@ -118,11 +105,7 @@ pub trait Externalities: ExtensionStore {
}
/// Whether a child storage entry exists.
fn exists_child_storage(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> bool {
fn exists_child_storage(&self, child_info: &ChildInfo, key: &[u8]) -> bool {
self.child_storage(child_info, key).is_some()
}
@@ -130,11 +113,7 @@ pub trait Externalities: ExtensionStore {
fn next_storage_key(&self, key: &[u8]) -> Option<Vec<u8>>;
/// Returns the key immediately following the given key, if it exists, in child storage.
fn next_child_storage_key(
&self,
child_info: &ChildInfo,
key: &[u8],
) -> Option<Vec<u8>>;
fn next_child_storage_key(&self, child_info: &ChildInfo, key: &[u8]) -> Option<Vec<u8>>;
/// Clear an entire child storage.
///
@@ -169,12 +148,7 @@ pub trait Externalities: ExtensionStore {
fn place_storage(&mut self, key: Vec<u8>, value: Option<Vec<u8>>);
/// Set or clear a child storage entry.
fn place_child_storage(
&mut self,
child_info: &ChildInfo,
key: Vec<u8>,
value: Option<Vec<u8>>,
);
fn place_child_storage(&mut self, child_info: &ChildInfo, key: Vec<u8>, value: Option<Vec<u8>>);
/// Get the trie root of the current storage map.
///
@@ -189,19 +163,12 @@ pub trait Externalities: ExtensionStore {
///
/// If the storage root equals the default hash as defined by the trie, the key in the top-level
/// storage map will be removed.
fn child_storage_root(
&mut self,
child_info: &ChildInfo,
) -> Vec<u8>;
fn child_storage_root(&mut self, child_info: &ChildInfo) -> Vec<u8>;
/// Append storage item.
///
/// This assumes specific format of the storage item. Also there is no way to undo this operation.
fn storage_append(
&mut self,
key: Vec<u8>,
value: Vec<u8>,
);
fn storage_append(&mut self, key: Vec<u8>, value: Vec<u8>);
/// Get the changes trie root of the current storage overlay at a block with given `parent`.
///
@@ -25,7 +25,8 @@ environmental::environmental!(ext: trait Externalities);
/// while executing the given closure [`with_externalities`] grants access to them. The externalities
/// are only set for the same thread this function was called from.
pub fn set_and_run_with_externalities<F, R>(ext: &mut dyn Externalities, f: F) -> R
where F: FnOnce() -> R
where
F: FnOnce() -> R,
{
ext::using(ext, f)
}