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
+38 -26
View File
@@ -17,14 +17,17 @@
//! Tool for creating the genesis block.
use std::collections::BTreeMap;
use sp_io::hashing::{blake2_256, twox_128};
use super::{AuthorityId, AccountId, wasm_binary_unwrap, system};
use codec::{Encode, KeyedVec, Joiner};
use sp_core::{ChangesTrieConfiguration, map};
use sp_core::storage::{well_known_keys, Storage};
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
use super::{system, wasm_binary_unwrap, AccountId, AuthorityId};
use codec::{Encode, Joiner, KeyedVec};
use sc_service::client::genesis;
use sp_core::{
map,
storage::{well_known_keys, Storage},
ChangesTrieConfiguration,
};
use sp_io::hashing::{blake2_256, twox_128};
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
use std::collections::BTreeMap;
/// Configuration of a general Substrate test genesis block.
pub struct GenesisConfig {
@@ -47,7 +50,7 @@ impl GenesisConfig {
) -> Self {
GenesisConfig {
changes_trie_config,
authorities: authorities,
authorities,
balances: endowed_accounts.into_iter().map(|a| (a, balance)).collect(),
heap_pages_override,
extra_storage,
@@ -56,16 +59,23 @@ impl GenesisConfig {
pub fn genesis_map(&self) -> Storage {
let wasm_runtime = wasm_binary_unwrap().to_vec();
let mut map: BTreeMap<Vec<u8>, Vec<u8>> = self.balances.iter()
.map(|&(ref account, balance)| (account.to_keyed_vec(b"balance:"), vec![].and(&balance)))
let mut map: BTreeMap<Vec<u8>, Vec<u8>> = self
.balances
.iter()
.map(|&(ref account, balance)| {
(account.to_keyed_vec(b"balance:"), vec![].and(&balance))
})
.map(|(k, v)| (blake2_256(&k[..])[..].to_vec(), v.to_vec()))
.chain(vec![
(well_known_keys::CODE.into(), wasm_runtime),
(
well_known_keys::HEAP_PAGES.into(),
vec![].and(&(self.heap_pages_override.unwrap_or(16 as u64))),
),
].into_iter())
.chain(
vec![
(well_known_keys::CODE.into(), wasm_runtime),
(
well_known_keys::HEAP_PAGES.into(),
vec![].and(&(self.heap_pages_override.unwrap_or(16 as u64))),
),
]
.into_iter(),
)
.collect();
if let Some(ref changes_trie_config) = self.changes_trie_config {
map.insert(well_known_keys::CHANGES_TRIE_CONFIG.to_vec(), changes_trie_config.encode());
@@ -75,28 +85,30 @@ impl GenesisConfig {
map.extend(self.extra_storage.top.clone().into_iter());
// Assimilate the system genesis config.
let mut storage = Storage { top: map, children_default: self.extra_storage.children_default.clone()};
let mut storage =
Storage { top: map, children_default: self.extra_storage.children_default.clone() };
let mut config = system::GenesisConfig::default();
config.authorities = self.authorities.clone();
config.assimilate_storage(&mut storage).expect("Adding `system::GensisConfig` to the genesis");
config
.assimilate_storage(&mut storage)
.expect("Adding `system::GensisConfig` to the genesis");
storage
}
}
pub fn insert_genesis_block(
storage: &mut Storage,
) -> sp_core::hash::H256 {
pub fn insert_genesis_block(storage: &mut Storage) -> sp_core::hash::H256 {
let child_roots = storage.children_default.iter().map(|(sk, child_content)| {
let state_root = <<<crate::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
);
let state_root =
<<<crate::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
child_content.data.clone().into_iter().collect(),
);
(sk.clone(), state_root.encode())
});
// add child roots to storage
storage.top.extend(child_roots);
let state_root = <<<crate::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
storage.top.clone().into_iter().collect()
storage.top.clone().into_iter().collect(),
);
let block: crate::Block = genesis::construct_genesis_block(state_root);
let genesis_hash = block.header.hash();