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
+33 -104
View File
@@ -21,23 +21,17 @@
// NOTE: could replace unhashed by having only one kind of storage (top trie being the child info
// of null length parent storage key).
use crate::sp_std::prelude::*;
use codec::{Codec, Encode, Decode};
pub use sp_core::storage::{ChildInfo, ChildType};
pub use crate::sp_io::KillStorageResult;
use crate::sp_std::prelude::*;
use codec::{Codec, Decode, Encode};
pub use sp_core::storage::{ChildInfo, ChildType};
/// Return the value of the item in storage under `key`, or `None` if there is no explicit entry.
pub fn get<T: Decode + Sized>(
child_info: &ChildInfo,
key: &[u8],
) -> Option<T> {
pub fn get<T: Decode + Sized>(child_info: &ChildInfo, key: &[u8]) -> Option<T> {
match child_info.child_type() {
ChildType::ParentKeyId => {
let storage_key = child_info.storage_key();
sp_io::default_child_storage::get(
storage_key,
key,
).and_then(|v| {
sp_io::default_child_storage::get(storage_key, key).and_then(|v| {
Decode::decode(&mut &v[..]).map(Some).unwrap_or_else(|_| {
// TODO #3700: error should be handleable.
crate::runtime_print!(
@@ -54,20 +48,13 @@ pub fn get<T: Decode + Sized>(
/// Return the value of the item in storage under `key`, or the type's default if there is no
/// explicit entry.
pub fn get_or_default<T: Decode + Sized + Default>(
child_info: &ChildInfo,
key: &[u8],
) -> T {
pub fn get_or_default<T: Decode + Sized + Default>(child_info: &ChildInfo, key: &[u8]) -> T {
get(child_info, key).unwrap_or_else(Default::default)
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
/// explicit entry.
pub fn get_or<T: Decode + Sized>(
child_info: &ChildInfo,
key: &[u8],
default_value: T,
) -> T {
pub fn get_or<T: Decode + Sized>(child_info: &ChildInfo, key: &[u8], default_value: T) -> T {
get(child_info, key).unwrap_or(default_value)
}
@@ -82,27 +69,16 @@ pub fn get_or_else<T: Decode + Sized, F: FnOnce() -> T>(
}
/// Put `value` in storage under `key`.
pub fn put<T: Encode>(
child_info: &ChildInfo,
key: &[u8],
value: &T,
) {
pub fn put<T: Encode>(child_info: &ChildInfo, key: &[u8], value: &T) {
match child_info.child_type() {
ChildType::ParentKeyId => value.using_encoded(|slice|
sp_io::default_child_storage::set(
child_info.storage_key(),
key,
slice,
)
),
ChildType::ParentKeyId => value.using_encoded(|slice| {
sp_io::default_child_storage::set(child_info.storage_key(), key, slice)
}),
}
}
/// Remove `key` from storage, returning its value if it had an explicit entry or `None` otherwise.
pub fn take<T: Decode + Sized>(
child_info: &ChildInfo,
key: &[u8],
) -> Option<T> {
pub fn take<T: Decode + Sized>(child_info: &ChildInfo, key: &[u8]) -> Option<T> {
let r = get(child_info, key);
if r.is_some() {
kill(child_info, key);
@@ -112,20 +88,13 @@ pub fn take<T: Decode + Sized>(
/// Remove `key` from storage, returning its value, or, if there was no explicit entry in storage,
/// the default for its type.
pub fn take_or_default<T: Codec + Sized + Default>(
child_info: &ChildInfo,
key: &[u8],
) -> T {
pub fn take_or_default<T: Codec + Sized + Default>(child_info: &ChildInfo, key: &[u8]) -> T {
take(child_info, key).unwrap_or_else(Default::default)
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
/// explicit entry. Ensure there is no explicit entry on return.
pub fn take_or<T: Codec + Sized>(
child_info: &ChildInfo,
key: &[u8],
default_value: T,
) -> T {
pub fn take_or<T: Codec + Sized>(child_info: &ChildInfo, key: &[u8], default_value: T) -> T {
take(child_info, key).unwrap_or(default_value)
}
@@ -140,15 +109,11 @@ pub fn take_or_else<T: Codec + Sized, F: FnOnce() -> T>(
}
/// Check to see if `key` has an explicit entry in storage.
pub fn exists(
child_info: &ChildInfo,
key: &[u8],
) -> bool {
pub fn exists(child_info: &ChildInfo, key: &[u8]) -> bool {
match child_info.child_type() {
ChildType::ParentKeyId => sp_io::default_child_storage::read(
child_info.storage_key(),
key, &mut [0;0][..], 0,
).is_some(),
ChildType::ParentKeyId =>
sp_io::default_child_storage::read(child_info.storage_key(), key, &mut [0; 0][..], 0)
.is_some(),
}
}
@@ -171,86 +136,50 @@ pub fn exists(
/// not make much sense because it is not cumulative when called inside the same block.
/// Use this function to distribute the deletion of a single child trie across multiple
/// blocks.
pub fn kill_storage(
child_info: &ChildInfo,
limit: Option<u32>,
) -> KillStorageResult {
pub fn kill_storage(child_info: &ChildInfo, limit: Option<u32>) -> KillStorageResult {
match child_info.child_type() {
ChildType::ParentKeyId => sp_io::default_child_storage::storage_kill(
child_info.storage_key(),
limit
),
ChildType::ParentKeyId =>
sp_io::default_child_storage::storage_kill(child_info.storage_key(), limit),
}
}
/// Ensure `key` has no explicit entry in storage.
pub fn kill(
child_info: &ChildInfo,
key: &[u8],
) {
pub fn kill(child_info: &ChildInfo, key: &[u8]) {
match child_info.child_type() {
ChildType::ParentKeyId => {
sp_io::default_child_storage::clear(
child_info.storage_key(),
key,
);
sp_io::default_child_storage::clear(child_info.storage_key(), key);
},
}
}
/// Get a Vec of bytes from storage.
pub fn get_raw(
child_info: &ChildInfo,
key: &[u8],
) -> Option<Vec<u8>> {
pub fn get_raw(child_info: &ChildInfo, key: &[u8]) -> Option<Vec<u8>> {
match child_info.child_type() {
ChildType::ParentKeyId => sp_io::default_child_storage::get(
child_info.storage_key(),
key,
),
ChildType::ParentKeyId => sp_io::default_child_storage::get(child_info.storage_key(), key),
}
}
/// Put a raw byte slice into storage.
pub fn put_raw(
child_info: &ChildInfo,
key: &[u8],
value: &[u8],
) {
pub fn put_raw(child_info: &ChildInfo, key: &[u8], value: &[u8]) {
match child_info.child_type() {
ChildType::ParentKeyId => sp_io::default_child_storage::set(
child_info.storage_key(),
key,
value,
),
ChildType::ParentKeyId =>
sp_io::default_child_storage::set(child_info.storage_key(), key, value),
}
}
/// Calculate current child root value.
pub fn root(
child_info: &ChildInfo,
) -> Vec<u8> {
pub fn root(child_info: &ChildInfo) -> Vec<u8> {
match child_info.child_type() {
ChildType::ParentKeyId => sp_io::default_child_storage::root(
child_info.storage_key(),
),
ChildType::ParentKeyId => sp_io::default_child_storage::root(child_info.storage_key()),
}
}
/// Return the length in bytes of the value without reading it. `None` if it does not exist.
pub fn len(
child_info: &ChildInfo,
key: &[u8],
) -> Option<u32> {
pub fn len(child_info: &ChildInfo, key: &[u8]) -> Option<u32> {
match child_info.child_type() {
ChildType::ParentKeyId => {
let mut buffer = [0; 0];
sp_io::default_child_storage::read(
child_info.storage_key(),
key,
&mut buffer,
0,
)
}
sp_io::default_child_storage::read(child_info.storage_key(), key, &mut buffer, 0)
},
}
}