mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 19:27:58 +00:00
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:
@@ -17,19 +17,16 @@
|
||||
|
||||
//! State machine backends. These manage the code and storage of contracts.
|
||||
|
||||
use hash_db::Hasher;
|
||||
use codec::{Decode, Encode};
|
||||
use sp_core::{
|
||||
storage::{ChildInfo, well_known_keys, TrackedStorageKey}
|
||||
};
|
||||
use crate::{
|
||||
trie_backend::TrieBackend,
|
||||
trie_backend_essence::TrieBackendStorage,
|
||||
UsageInfo, StorageKey, StorageValue, StorageCollection, ChildStorageCollection,
|
||||
trie_backend::TrieBackend, trie_backend_essence::TrieBackendStorage, ChildStorageCollection,
|
||||
StorageCollection, StorageKey, StorageValue, UsageInfo,
|
||||
};
|
||||
use sp_std::vec::Vec;
|
||||
use codec::{Decode, Encode};
|
||||
use hash_db::Hasher;
|
||||
use sp_core::storage::{well_known_keys, ChildInfo, TrackedStorageKey};
|
||||
#[cfg(feature = "std")]
|
||||
use sp_core::traits::RuntimeCode;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
/// A state backend is used to read state data and can have changes committed
|
||||
/// to it.
|
||||
@@ -90,7 +87,7 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
fn next_child_storage_key(
|
||||
&self,
|
||||
child_info: &ChildInfo,
|
||||
key: &[u8]
|
||||
key: &[u8],
|
||||
) -> Result<Option<StorageKey>, Self::Error>;
|
||||
|
||||
/// Iterate over storage starting at key, for a given prefix and child trie.
|
||||
@@ -128,7 +125,6 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
/// call `f` for each of those keys.
|
||||
fn for_key_values_with_prefix<F: FnMut(&[u8], &[u8])>(&self, prefix: &[u8], f: F);
|
||||
|
||||
|
||||
/// Retrieve all child entries keys which start with the given prefix and
|
||||
/// call `f` for each of those keys.
|
||||
fn for_child_keys_with_prefix<F: FnMut(&[u8])>(
|
||||
@@ -143,8 +139,10 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
/// Does not include child storage updates.
|
||||
fn storage_root<'a>(
|
||||
&self,
|
||||
delta: impl Iterator<Item=(&'a [u8], Option<&'a [u8]>)>,
|
||||
) -> (H::Out, Self::Transaction) where H::Out: Ord;
|
||||
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
|
||||
) -> (H::Out, Self::Transaction)
|
||||
where
|
||||
H::Out: Ord;
|
||||
|
||||
/// Calculate the child storage root, with given delta over what is already stored in
|
||||
/// the backend, and produce a "transaction" that can be used to commit. The second argument
|
||||
@@ -152,8 +150,10 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
fn child_storage_root<'a>(
|
||||
&self,
|
||||
child_info: &ChildInfo,
|
||||
delta: impl Iterator<Item=(&'a [u8], Option<&'a [u8]>)>,
|
||||
) -> (H::Out, bool, Self::Transaction) where H::Out: Ord;
|
||||
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
|
||||
) -> (H::Out, bool, Self::Transaction)
|
||||
where
|
||||
H::Out: Ord;
|
||||
|
||||
/// Get all key/value pairs into a Vec.
|
||||
fn pairs(&self) -> Vec<(StorageKey, StorageValue)>;
|
||||
@@ -166,11 +166,7 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
}
|
||||
|
||||
/// Get all keys of child storage with given prefix
|
||||
fn child_keys(
|
||||
&self,
|
||||
child_info: &ChildInfo,
|
||||
prefix: &[u8],
|
||||
) -> Vec<StorageKey> {
|
||||
fn child_keys(&self, child_info: &ChildInfo, prefix: &[u8]) -> Vec<StorageKey> {
|
||||
let mut all = Vec::new();
|
||||
self.for_child_keys_with_prefix(child_info, prefix, |k| all.push(k.to_vec()));
|
||||
all
|
||||
@@ -186,18 +182,19 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
/// Does include child storage updates.
|
||||
fn full_storage_root<'a>(
|
||||
&self,
|
||||
delta: impl Iterator<Item=(&'a [u8], Option<&'a [u8]>)>,
|
||||
child_deltas: impl Iterator<Item = (
|
||||
&'a ChildInfo,
|
||||
impl Iterator<Item=(&'a [u8], Option<&'a [u8]>)>,
|
||||
)>,
|
||||
) -> (H::Out, Self::Transaction) where H::Out: Ord + Encode {
|
||||
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
|
||||
child_deltas: impl Iterator<
|
||||
Item = (&'a ChildInfo, impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>),
|
||||
>,
|
||||
) -> (H::Out, Self::Transaction)
|
||||
where
|
||||
H::Out: Ord + Encode,
|
||||
{
|
||||
let mut txs: Self::Transaction = Default::default();
|
||||
let mut child_roots: Vec<_> = Default::default();
|
||||
// child first
|
||||
for (child_info, child_delta) in child_deltas {
|
||||
let (child_root, empty, child_txs) =
|
||||
self.child_storage_root(&child_info, child_delta);
|
||||
let (child_root, empty, child_txs) = self.child_storage_root(&child_info, child_delta);
|
||||
let prefixed_storage_key = child_info.prefixed_storage_key();
|
||||
txs.consolidate(child_txs);
|
||||
if empty {
|
||||
@@ -206,13 +203,10 @@ pub trait Backend<H: Hasher>: sp_std::fmt::Debug {
|
||||
child_roots.push((prefixed_storage_key.into_inner(), Some(child_root.encode())));
|
||||
}
|
||||
}
|
||||
let (root, parent_txs) = self.storage_root(delta
|
||||
.map(|(k, v)| (k, v.as_ref().map(|v| &v[..])))
|
||||
.chain(
|
||||
child_roots
|
||||
.iter()
|
||||
.map(|(k, v)| (&k[..], v.as_ref().map(|v| &v[..])))
|
||||
)
|
||||
let (root, parent_txs) = self.storage_root(
|
||||
delta
|
||||
.map(|(k, v)| (k, v.as_ref().map(|v| &v[..])))
|
||||
.chain(child_roots.iter().map(|(k, v)| (&k[..], v.as_ref().map(|v| &v[..])))),
|
||||
);
|
||||
txs.consolidate(parent_txs);
|
||||
(root, txs)
|
||||
@@ -286,10 +280,7 @@ impl Consolidate for () {
|
||||
}
|
||||
}
|
||||
|
||||
impl Consolidate for Vec<(
|
||||
Option<ChildInfo>,
|
||||
StorageCollection,
|
||||
)> {
|
||||
impl Consolidate for Vec<(Option<ChildInfo>, StorageCollection)> {
|
||||
fn consolidate(&mut self, mut other: Self) {
|
||||
self.append(&mut other);
|
||||
}
|
||||
@@ -303,12 +294,15 @@ impl<H: Hasher, KF: sp_trie::KeyFunction<H>> Consolidate for sp_trie::GenericMem
|
||||
|
||||
/// Insert input pairs into memory db.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn insert_into_memory_db<H, I>(mdb: &mut sp_trie::MemoryDB<H>, input: I) -> Option<H::Out>
|
||||
where
|
||||
H: Hasher,
|
||||
I: IntoIterator<Item=(StorageKey, StorageValue)>,
|
||||
pub(crate) fn insert_into_memory_db<H, I>(
|
||||
mdb: &mut sp_trie::MemoryDB<H>,
|
||||
input: I,
|
||||
) -> Option<H::Out>
|
||||
where
|
||||
H: Hasher,
|
||||
I: IntoIterator<Item = (StorageKey, StorageValue)>,
|
||||
{
|
||||
use sp_trie::{TrieMut, trie_types::TrieDBMut};
|
||||
use sp_trie::{trie_types::TrieDBMut, TrieMut};
|
||||
|
||||
let mut root = <H as Hasher>::Out::default();
|
||||
{
|
||||
@@ -316,7 +310,7 @@ pub(crate) fn insert_into_memory_db<H, I>(mdb: &mut sp_trie::MemoryDB<H>, input:
|
||||
for (key, value) in input {
|
||||
if let Err(e) = trie.insert(&key, &value) {
|
||||
log::warn!(target: "trie", "Failed to write to trie: {}", e);
|
||||
return None;
|
||||
return None
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -332,8 +326,8 @@ pub struct BackendRuntimeCode<'a, B, H> {
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<'a, B: Backend<H>, H: Hasher> sp_core::traits::FetchRuntimeCode for
|
||||
BackendRuntimeCode<'a, B, H>
|
||||
impl<'a, B: Backend<H>, H: Hasher> sp_core::traits::FetchRuntimeCode
|
||||
for BackendRuntimeCode<'a, B, H>
|
||||
{
|
||||
fn fetch_runtime_code<'b>(&'b self) -> Option<std::borrow::Cow<'b, [u8]>> {
|
||||
self.backend.storage(well_known_keys::CODE).ok().flatten().map(Into::into)
|
||||
@@ -341,23 +335,27 @@ impl<'a, B: Backend<H>, H: Hasher> sp_core::traits::FetchRuntimeCode for
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<'a, B: Backend<H>, H: Hasher> BackendRuntimeCode<'a, B, H> where H::Out: Encode {
|
||||
impl<'a, B: Backend<H>, H: Hasher> BackendRuntimeCode<'a, B, H>
|
||||
where
|
||||
H::Out: Encode,
|
||||
{
|
||||
/// Create a new instance.
|
||||
pub fn new(backend: &'a B) -> Self {
|
||||
Self {
|
||||
backend,
|
||||
_marker: std::marker::PhantomData,
|
||||
}
|
||||
Self { backend, _marker: std::marker::PhantomData }
|
||||
}
|
||||
|
||||
/// Return the [`RuntimeCode`] build from the wrapped `backend`.
|
||||
pub fn runtime_code(&self) -> Result<RuntimeCode, &'static str> {
|
||||
let hash = self.backend.storage_hash(well_known_keys::CODE)
|
||||
let hash = self
|
||||
.backend
|
||||
.storage_hash(well_known_keys::CODE)
|
||||
.ok()
|
||||
.flatten()
|
||||
.ok_or("`:code` hash not found")?
|
||||
.encode();
|
||||
let heap_pages = self.backend.storage(well_known_keys::HEAP_PAGES)
|
||||
let heap_pages = self
|
||||
.backend
|
||||
.storage(well_known_keys::HEAP_PAGES)
|
||||
.ok()
|
||||
.flatten()
|
||||
.and_then(|d| Decode::decode(&mut &d[..]).ok());
|
||||
|
||||
Reference in New Issue
Block a user