mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
feat: compute pallet/storage prefix hash at compile time (#1539)
Since the hash rules of this part of the `pallet_prefix/storage_prefix` are always fixed, we can put the runtime calculation into compile time. --- polkadot address: 15ouFh2SHpGbHtDPsJ6cXQfes9Cx1gEFnJJsJVqPGzBSTudr --------- Co-authored-by: Juan <juangirini@gmail.com> Co-authored-by: command-bot <> Co-authored-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
This commit is contained in:
@@ -33,7 +33,7 @@ use sp_std::prelude::*;
|
||||
///
|
||||
/// Thus value for (key1, key2) is stored at:
|
||||
/// ```nocompile
|
||||
/// Twox128(module_prefix) ++ Twox128(storage_prefix) ++ Hasher1(encode(key1)) ++ Hasher2(encode(key2))
|
||||
/// Twox128(pallet_prefix) ++ Twox128(storage_prefix) ++ Hasher1(encode(key1)) ++ Hasher2(encode(key2))
|
||||
/// ```
|
||||
///
|
||||
/// # Warning
|
||||
@@ -53,18 +53,15 @@ pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
|
||||
/// Hasher for the second key.
|
||||
type Hasher2: StorageHasher;
|
||||
|
||||
/// Module prefix. Used for generating final key.
|
||||
fn module_prefix() -> &'static [u8];
|
||||
/// Pallet prefix. Used for generating final key.
|
||||
fn pallet_prefix() -> &'static [u8];
|
||||
|
||||
/// Storage prefix. Used for generating final key.
|
||||
fn storage_prefix() -> &'static [u8];
|
||||
|
||||
/// The full prefix; just the hash of `module_prefix` concatenated to the hash of
|
||||
/// The full prefix; just the hash of `pallet_prefix` concatenated to the hash of
|
||||
/// `storage_prefix`.
|
||||
fn prefix_hash() -> Vec<u8> {
|
||||
let result = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
result.to_vec()
|
||||
}
|
||||
fn prefix_hash() -> [u8; 32];
|
||||
|
||||
/// Convert an optional value retrieved from storage to the type queried.
|
||||
fn from_optional_value_to_query(v: Option<V>) -> Self::Query;
|
||||
@@ -77,7 +74,7 @@ pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
|
||||
where
|
||||
KArg1: EncodeLike<K1>,
|
||||
{
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
let key_hashed = k1.using_encoded(Self::Hasher1::hash);
|
||||
|
||||
let mut final_key = Vec::with_capacity(storage_prefix.len() + key_hashed.as_ref().len());
|
||||
@@ -94,7 +91,7 @@ pub trait StorageDoubleMap<K1: FullEncode, K2: FullEncode, V: FullCodec> {
|
||||
KArg1: EncodeLike<K1>,
|
||||
KArg2: EncodeLike<K2>,
|
||||
{
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
let key1_hashed = k1.using_encoded(Self::Hasher1::hash);
|
||||
let key2_hashed = k2.using_encoded(Self::Hasher2::hash);
|
||||
|
||||
@@ -334,7 +331,7 @@ where
|
||||
key2: KeyArg2,
|
||||
) -> Option<V> {
|
||||
let old_key = {
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
|
||||
let key1_hashed = key1.using_encoded(OldHasher1::hash);
|
||||
let key2_hashed = key2.using_encoded(OldHasher2::hash);
|
||||
@@ -419,7 +416,7 @@ where
|
||||
}
|
||||
|
||||
fn iter() -> Self::Iterator {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
Self::Iterator {
|
||||
prefix: prefix.clone(),
|
||||
previous_key: prefix,
|
||||
@@ -442,7 +439,7 @@ where
|
||||
}
|
||||
|
||||
fn iter_keys() -> Self::FullKeyIterator {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
Self::FullKeyIterator {
|
||||
prefix: prefix.clone(),
|
||||
previous_key: prefix,
|
||||
@@ -470,7 +467,7 @@ where
|
||||
}
|
||||
|
||||
fn translate<O: Decode, F: FnMut(K1, K2, O) -> Option<V>>(mut f: F) {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
let mut previous_key = prefix.clone();
|
||||
while let Some(next) =
|
||||
sp_io::storage::next_key(&previous_key).filter(|n| n.starts_with(&prefix))
|
||||
@@ -561,7 +558,7 @@ mod test_iterators {
|
||||
type DoubleMap = self::frame_system::DoubleMap<Runtime>;
|
||||
|
||||
// All map iterator
|
||||
let prefix = DoubleMap::prefix_hash();
|
||||
let prefix = DoubleMap::prefix_hash().to_vec();
|
||||
|
||||
unhashed::put(&key_before_prefix(prefix.clone()), &1u64);
|
||||
unhashed::put(&key_after_prefix(prefix.clone()), &1u64);
|
||||
@@ -621,7 +618,7 @@ mod test_iterators {
|
||||
assert_eq!(unhashed::get(&key_after_prefix(prefix.clone())), Some(1u64));
|
||||
|
||||
// Translate
|
||||
let prefix = DoubleMap::prefix_hash();
|
||||
let prefix = DoubleMap::prefix_hash().to_vec();
|
||||
|
||||
unhashed::put(&key_before_prefix(prefix.clone()), &1u64);
|
||||
unhashed::put(&key_after_prefix(prefix.clone()), &1u64);
|
||||
|
||||
@@ -28,7 +28,7 @@ use sp_std::prelude::*;
|
||||
///
|
||||
/// By default each key value is stored at:
|
||||
/// ```nocompile
|
||||
/// Twox128(module_prefix) ++ Twox128(storage_prefix) ++ Hasher(encode(key))
|
||||
/// Twox128(pallet_prefix) ++ Twox128(storage_prefix) ++ Hasher(encode(key))
|
||||
/// ```
|
||||
///
|
||||
/// # Warning
|
||||
@@ -42,18 +42,15 @@ pub trait StorageMap<K: FullEncode, V: FullCodec> {
|
||||
/// Hasher. Used for generating final key.
|
||||
type Hasher: StorageHasher;
|
||||
|
||||
/// Module prefix. Used for generating final key.
|
||||
fn module_prefix() -> &'static [u8];
|
||||
/// Pallet prefix. Used for generating final key.
|
||||
fn pallet_prefix() -> &'static [u8];
|
||||
|
||||
/// Storage prefix. Used for generating final key.
|
||||
fn storage_prefix() -> &'static [u8];
|
||||
|
||||
/// The full prefix; just the hash of `module_prefix` concatenated to the hash of
|
||||
/// The full prefix; just the hash of `pallet_prefix` concatenated to the hash of
|
||||
/// `storage_prefix`.
|
||||
fn prefix_hash() -> Vec<u8> {
|
||||
let result = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
result.to_vec()
|
||||
}
|
||||
fn prefix_hash() -> [u8; 32];
|
||||
|
||||
/// Convert an optional value retrieved from storage to the type queried.
|
||||
fn from_optional_value_to_query(v: Option<V>) -> Self::Query;
|
||||
@@ -66,7 +63,7 @@ pub trait StorageMap<K: FullEncode, V: FullCodec> {
|
||||
where
|
||||
KeyArg: EncodeLike<K>,
|
||||
{
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
let key_hashed = key.using_encoded(Self::Hasher::hash);
|
||||
|
||||
let mut final_key = Vec::with_capacity(storage_prefix.len() + key_hashed.as_ref().len());
|
||||
@@ -128,7 +125,7 @@ where
|
||||
|
||||
/// Enumerate all elements in the map.
|
||||
fn iter() -> Self::Iterator {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
PrefixIterator {
|
||||
prefix: prefix.clone(),
|
||||
previous_key: prefix,
|
||||
@@ -150,7 +147,7 @@ where
|
||||
|
||||
/// Enumerate all keys in the map.
|
||||
fn iter_keys() -> Self::KeyIterator {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
KeyPrefixIterator {
|
||||
prefix: prefix.clone(),
|
||||
previous_key: prefix,
|
||||
@@ -190,7 +187,7 @@ where
|
||||
previous_key: Option<Vec<u8>>,
|
||||
mut f: F,
|
||||
) -> Option<Vec<u8>> {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
let previous_key = previous_key.unwrap_or_else(|| prefix.clone());
|
||||
|
||||
let current_key =
|
||||
@@ -339,7 +336,7 @@ impl<K: FullEncode, V: FullCodec, G: StorageMap<K, V>> storage::StorageMap<K, V>
|
||||
|
||||
fn migrate_key<OldHasher: StorageHasher, KeyArg: EncodeLike<K>>(key: KeyArg) -> Option<V> {
|
||||
let old_key = {
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
let key_hashed = key.using_encoded(OldHasher::hash);
|
||||
|
||||
let mut final_key =
|
||||
@@ -398,7 +395,7 @@ mod test_iterators {
|
||||
type Map = self::frame_system::Map<Runtime>;
|
||||
|
||||
// All map iterator
|
||||
let prefix = Map::prefix_hash();
|
||||
let prefix = Map::prefix_hash().to_vec();
|
||||
|
||||
unhashed::put(&key_before_prefix(prefix.clone()), &1u64);
|
||||
unhashed::put(&key_after_prefix(prefix.clone()), &1u64);
|
||||
@@ -420,7 +417,7 @@ mod test_iterators {
|
||||
assert_eq!(unhashed::get(&key_after_prefix(prefix.clone())), Some(1u64));
|
||||
|
||||
// Translate
|
||||
let prefix = Map::prefix_hash();
|
||||
let prefix = Map::prefix_hash().to_vec();
|
||||
|
||||
unhashed::put(&key_before_prefix(prefix.clone()), &1u64);
|
||||
unhashed::put(&key_after_prefix(prefix.clone()), &1u64);
|
||||
|
||||
@@ -61,18 +61,15 @@ pub trait StorageNMap<K: KeyGenerator, V: FullCodec> {
|
||||
/// The type that get/take returns.
|
||||
type Query;
|
||||
|
||||
/// Module prefix. Used for generating final key.
|
||||
fn module_prefix() -> &'static [u8];
|
||||
/// Pallet prefix. Used for generating final key.
|
||||
fn pallet_prefix() -> &'static [u8];
|
||||
|
||||
/// Storage prefix. Used for generating final key.
|
||||
fn storage_prefix() -> &'static [u8];
|
||||
|
||||
/// The full prefix; just the hash of `module_prefix` concatenated to the hash of
|
||||
/// The full prefix; just the hash of `pallet_prefix` concatenated to the hash of
|
||||
/// `storage_prefix`.
|
||||
fn prefix_hash() -> Vec<u8> {
|
||||
let result = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
result.to_vec()
|
||||
}
|
||||
fn prefix_hash() -> [u8; 32];
|
||||
|
||||
/// Convert an optional value retrieved from storage to the type queried.
|
||||
fn from_optional_value_to_query(v: Option<V>) -> Self::Query;
|
||||
@@ -85,7 +82,7 @@ pub trait StorageNMap<K: KeyGenerator, V: FullCodec> {
|
||||
where
|
||||
K: HasKeyPrefix<KP>,
|
||||
{
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
let key_hashed = <K as HasKeyPrefix<KP>>::partial_key(key);
|
||||
|
||||
let mut final_key = Vec::with_capacity(storage_prefix.len() + key_hashed.len());
|
||||
@@ -102,7 +99,7 @@ pub trait StorageNMap<K: KeyGenerator, V: FullCodec> {
|
||||
KG: KeyGenerator,
|
||||
KArg: EncodeLikeTuple<KG::KArg> + TupleToEncodedIter,
|
||||
{
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
let key_hashed = KG::final_key(key);
|
||||
|
||||
let mut final_key = Vec::with_capacity(storage_prefix.len() + key_hashed.len());
|
||||
@@ -299,7 +296,7 @@ where
|
||||
KArg: EncodeLikeTuple<K::KArg> + TupleToEncodedIter,
|
||||
{
|
||||
let old_key = {
|
||||
let storage_prefix = storage_prefix(Self::module_prefix(), Self::storage_prefix());
|
||||
let storage_prefix = storage_prefix(Self::pallet_prefix(), Self::storage_prefix());
|
||||
let key_hashed = K::migrate_key(&key, hash_fns);
|
||||
|
||||
let mut final_key = Vec::with_capacity(storage_prefix.len() + key_hashed.len());
|
||||
@@ -386,11 +383,11 @@ impl<K: ReversibleKeyGenerator, V: FullCodec, G: StorageNMap<K, V>>
|
||||
}
|
||||
|
||||
fn iter() -> Self::Iterator {
|
||||
Self::iter_from(G::prefix_hash())
|
||||
Self::iter_from(G::prefix_hash().to_vec())
|
||||
}
|
||||
|
||||
fn iter_from(starting_raw_key: Vec<u8>) -> Self::Iterator {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
Self::Iterator {
|
||||
prefix,
|
||||
previous_key: starting_raw_key,
|
||||
@@ -404,11 +401,11 @@ impl<K: ReversibleKeyGenerator, V: FullCodec, G: StorageNMap<K, V>>
|
||||
}
|
||||
|
||||
fn iter_keys() -> Self::KeyIterator {
|
||||
Self::iter_keys_from(G::prefix_hash())
|
||||
Self::iter_keys_from(G::prefix_hash().to_vec())
|
||||
}
|
||||
|
||||
fn iter_keys_from(starting_raw_key: Vec<u8>) -> Self::KeyIterator {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
Self::KeyIterator {
|
||||
prefix,
|
||||
previous_key: starting_raw_key,
|
||||
@@ -427,7 +424,7 @@ impl<K: ReversibleKeyGenerator, V: FullCodec, G: StorageNMap<K, V>>
|
||||
}
|
||||
|
||||
fn translate<O: Decode, F: FnMut(K::Key, O) -> Option<V>>(mut f: F) {
|
||||
let prefix = G::prefix_hash();
|
||||
let prefix = G::prefix_hash().to_vec();
|
||||
let mut previous_key = prefix.clone();
|
||||
while let Some(next) =
|
||||
sp_io::storage::next_key(&previous_key).filter(|n| n.starts_with(&prefix))
|
||||
@@ -537,7 +534,7 @@ mod test_iterators {
|
||||
type NMap = self::frame_system::NMap<Runtime>;
|
||||
|
||||
// All map iterator
|
||||
let prefix = NMap::prefix_hash();
|
||||
let prefix = NMap::prefix_hash().to_vec();
|
||||
|
||||
unhashed::put(&key_before_prefix(prefix.clone()), &1u64);
|
||||
unhashed::put(&key_after_prefix(prefix.clone()), &1u64);
|
||||
@@ -594,7 +591,7 @@ mod test_iterators {
|
||||
assert_eq!(unhashed::get(&key_after_prefix(prefix.clone())), Some(1u64));
|
||||
|
||||
// Translate
|
||||
let prefix = NMap::prefix_hash();
|
||||
let prefix = NMap::prefix_hash().to_vec();
|
||||
|
||||
unhashed::put(&key_before_prefix(prefix.clone()), &1u64);
|
||||
unhashed::put(&key_after_prefix(prefix.clone()), &1u64);
|
||||
|
||||
@@ -25,14 +25,14 @@ use codec::{Decode, Encode, EncodeLike, FullCodec};
|
||||
///
|
||||
/// By default value is stored at:
|
||||
/// ```nocompile
|
||||
/// Twox128(module_prefix) ++ Twox128(storage_prefix)
|
||||
/// Twox128(pallet_prefix) ++ Twox128(storage_prefix)
|
||||
/// ```
|
||||
pub trait StorageValue<T: FullCodec> {
|
||||
/// The type that get/take returns.
|
||||
type Query;
|
||||
|
||||
/// Module prefix. Used for generating final key.
|
||||
fn module_prefix() -> &'static [u8];
|
||||
/// Pallet prefix. Used for generating final key.
|
||||
fn pallet_prefix() -> &'static [u8];
|
||||
|
||||
/// Storage prefix. Used for generating final key.
|
||||
fn storage_prefix() -> &'static [u8];
|
||||
@@ -44,9 +44,7 @@ pub trait StorageValue<T: FullCodec> {
|
||||
fn from_query_to_optional_value(v: Self::Query) -> Option<T>;
|
||||
|
||||
/// Generate the full key used in top storage.
|
||||
fn storage_value_final_key() -> [u8; 32] {
|
||||
crate::storage::storage_prefix(Self::module_prefix(), Self::storage_prefix())
|
||||
}
|
||||
fn storage_value_final_key() -> [u8; 32];
|
||||
}
|
||||
|
||||
impl<T: FullCodec, G: StorageValue<T>> storage::StorageValue<T> for G {
|
||||
@@ -97,10 +95,6 @@ impl<T: FullCodec, G: StorageValue<T>> storage::StorageValue<T> for G {
|
||||
}
|
||||
}
|
||||
|
||||
fn kill() {
|
||||
unhashed::kill(&Self::storage_value_final_key())
|
||||
}
|
||||
|
||||
fn mutate<R, F: FnOnce(&mut G::Query) -> R>(f: F) -> R {
|
||||
Self::try_mutate(|v| Ok::<R, Never>(f(v))).expect("`Never` can not be constructed; qed")
|
||||
}
|
||||
@@ -142,6 +136,10 @@ impl<T: FullCodec, G: StorageValue<T>> storage::StorageValue<T> for G {
|
||||
ret
|
||||
}
|
||||
|
||||
fn kill() {
|
||||
unhashed::kill(&Self::storage_value_final_key())
|
||||
}
|
||||
|
||||
fn take() -> G::Query {
|
||||
let key = Self::storage_value_final_key();
|
||||
let value = unhashed::get(&key);
|
||||
|
||||
@@ -191,7 +191,7 @@ pub trait StorageList<V: FullCodec> {
|
||||
|
||||
/// Append a single element.
|
||||
///
|
||||
/// Should not be called repeatedly; use `append_many` instead.
|
||||
/// Should not be called repeatedly; use `append_many` instead.
|
||||
/// Worst case linear `O(len)` with `len` being the number if elements in the list.
|
||||
fn append_one<EncodeLikeValue>(item: EncodeLikeValue)
|
||||
where
|
||||
@@ -202,7 +202,7 @@ pub trait StorageList<V: FullCodec> {
|
||||
|
||||
/// Append many elements.
|
||||
///
|
||||
/// Should not be called repeatedly; use `appender` instead.
|
||||
/// Should not be called repeatedly; use `appender` instead.
|
||||
/// Worst case linear `O(len + items.count())` with `len` beings the number if elements in the
|
||||
/// list.
|
||||
fn append_many<EncodeLikeValue, I>(items: I)
|
||||
@@ -1273,15 +1273,15 @@ impl<T> Iterator for ChildTriePrefixIterator<T> {
|
||||
|
||||
/// Trait for storage types that store all its value after a unique prefix.
|
||||
pub trait StoragePrefixedContainer {
|
||||
/// Module prefix. Used for generating final key.
|
||||
fn module_prefix() -> &'static [u8];
|
||||
/// Pallet prefix. Used for generating final key.
|
||||
fn pallet_prefix() -> &'static [u8];
|
||||
|
||||
/// Storage prefix. Used for generating final key.
|
||||
fn storage_prefix() -> &'static [u8];
|
||||
|
||||
/// Final full prefix that prefixes all keys.
|
||||
fn final_prefix() -> [u8; 32] {
|
||||
crate::storage::storage_prefix(Self::module_prefix(), Self::storage_prefix())
|
||||
crate::storage::storage_prefix(Self::pallet_prefix(), Self::storage_prefix())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1289,18 +1289,18 @@ pub trait StoragePrefixedContainer {
|
||||
///
|
||||
/// By default the final prefix is:
|
||||
/// ```nocompile
|
||||
/// Twox128(module_prefix) ++ Twox128(storage_prefix)
|
||||
/// Twox128(pallet_prefix) ++ Twox128(storage_prefix)
|
||||
/// ```
|
||||
pub trait StoragePrefixedMap<Value: FullCodec> {
|
||||
/// Module prefix. Used for generating final key.
|
||||
fn module_prefix() -> &'static [u8]; // TODO move to StoragePrefixedContainer
|
||||
/// Pallet prefix. Used for generating final key.
|
||||
fn pallet_prefix() -> &'static [u8]; // TODO move to StoragePrefixedContainer
|
||||
|
||||
/// Storage prefix. Used for generating final key.
|
||||
fn storage_prefix() -> &'static [u8];
|
||||
|
||||
/// Final full prefix that prefixes all keys.
|
||||
fn final_prefix() -> [u8; 32] {
|
||||
crate::storage::storage_prefix(Self::module_prefix(), Self::storage_prefix())
|
||||
crate::storage::storage_prefix(Self::pallet_prefix(), Self::storage_prefix())
|
||||
}
|
||||
|
||||
/// Remove all values in the overlay and up to `limit` in the backend.
|
||||
@@ -1624,7 +1624,7 @@ mod test {
|
||||
TestExternalities::default().execute_with(|| {
|
||||
struct MyStorage;
|
||||
impl StoragePrefixedMap<u64> for MyStorage {
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
b"MyModule"
|
||||
}
|
||||
|
||||
@@ -1701,7 +1701,7 @@ mod test {
|
||||
impl generator::StorageValue<Digest> for Storage {
|
||||
type Query = Digest;
|
||||
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
b"MyModule"
|
||||
}
|
||||
|
||||
@@ -1716,6 +1716,10 @@ mod test {
|
||||
fn from_query_to_optional_value(v: Self::Query) -> Option<Digest> {
|
||||
Some(v)
|
||||
}
|
||||
|
||||
fn storage_value_final_key() -> [u8; 32] {
|
||||
storage_prefix(Self::pallet_prefix(), Self::storage_prefix())
|
||||
}
|
||||
}
|
||||
|
||||
Storage::append(DigestItem::Other(Vec::new()));
|
||||
@@ -1736,7 +1740,7 @@ mod test {
|
||||
type Query = u64;
|
||||
type Hasher = Twox64Concat;
|
||||
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
b"MyModule"
|
||||
}
|
||||
|
||||
@@ -1744,6 +1748,10 @@ mod test {
|
||||
b"MyStorageMap"
|
||||
}
|
||||
|
||||
fn prefix_hash() -> [u8; 32] {
|
||||
storage_prefix(Self::pallet_prefix(), Self::storage_prefix())
|
||||
}
|
||||
|
||||
fn from_optional_value_to_query(v: Option<u64>) -> Self::Query {
|
||||
v.unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ where
|
||||
/// The prefix used to generate the key of the map.
|
||||
pub fn map_storage_final_prefix() -> Vec<u8> {
|
||||
use crate::storage::generator::StorageMap;
|
||||
<Self as MapWrapper>::Map::prefix_hash()
|
||||
<Self as MapWrapper>::Map::prefix_hash().to_vec()
|
||||
}
|
||||
|
||||
/// Get the storage key used to fetch a value corresponding to a specific key.
|
||||
|
||||
@@ -104,7 +104,7 @@ where
|
||||
/// The prefix used to generate the key of the map.
|
||||
pub fn map_storage_final_prefix() -> Vec<u8> {
|
||||
use crate::storage::generator::StorageNMap;
|
||||
<Self as MapWrapper>::Map::prefix_hash()
|
||||
<Self as MapWrapper>::Map::prefix_hash().to_vec()
|
||||
}
|
||||
|
||||
/// Get the storage key used to fetch a value corresponding to a specific key.
|
||||
|
||||
@@ -117,12 +117,17 @@ where
|
||||
type Query = QueryKind::Query;
|
||||
type Hasher1 = Hasher1;
|
||||
type Hasher2 = Hasher2;
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
Prefix::pallet_prefix().as_bytes()
|
||||
}
|
||||
|
||||
fn storage_prefix() -> &'static [u8] {
|
||||
Prefix::STORAGE_PREFIX.as_bytes()
|
||||
}
|
||||
fn prefix_hash() -> [u8; 32] {
|
||||
Prefix::prefix_hash()
|
||||
}
|
||||
|
||||
fn from_optional_value_to_query(v: Option<Value>) -> Self::Query {
|
||||
QueryKind::from_optional_value_to_query(v)
|
||||
}
|
||||
@@ -145,8 +150,8 @@ where
|
||||
OnEmpty: Get<QueryKind::Query> + 'static,
|
||||
MaxValues: Get<Option<u32>>,
|
||||
{
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageDoubleMap<Key1, Key2, Value>>::module_prefix()
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageDoubleMap<Key1, Key2, Value>>::pallet_prefix()
|
||||
}
|
||||
fn storage_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageDoubleMap<Key1, Key2, Value>>::storage_prefix()
|
||||
@@ -691,7 +696,7 @@ where
|
||||
{
|
||||
fn storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::final_prefix().to_vec(),
|
||||
max_values: MaxValues::get(),
|
||||
@@ -722,7 +727,7 @@ where
|
||||
{
|
||||
fn partial_storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::final_prefix().to_vec(),
|
||||
max_values: MaxValues::get(),
|
||||
|
||||
@@ -83,12 +83,15 @@ where
|
||||
{
|
||||
type Query = QueryKind::Query;
|
||||
type Hasher = Hasher;
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
Prefix::pallet_prefix().as_bytes()
|
||||
}
|
||||
fn storage_prefix() -> &'static [u8] {
|
||||
Prefix::STORAGE_PREFIX.as_bytes()
|
||||
}
|
||||
fn prefix_hash() -> [u8; 32] {
|
||||
Prefix::prefix_hash()
|
||||
}
|
||||
fn from_optional_value_to_query(v: Option<Value>) -> Self::Query {
|
||||
QueryKind::from_optional_value_to_query(v)
|
||||
}
|
||||
@@ -108,8 +111,8 @@ where
|
||||
OnEmpty: Get<QueryKind::Query> + 'static,
|
||||
MaxValues: Get<Option<u32>>,
|
||||
{
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageMap<Key, Value>>::module_prefix()
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageMap<Key, Value>>::pallet_prefix()
|
||||
}
|
||||
fn storage_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageMap<Key, Value>>::storage_prefix()
|
||||
@@ -469,7 +472,7 @@ where
|
||||
{
|
||||
fn storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::final_prefix().to_vec(),
|
||||
max_values: MaxValues::get(),
|
||||
@@ -497,7 +500,7 @@ where
|
||||
{
|
||||
fn partial_storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::final_prefix().to_vec(),
|
||||
max_values: MaxValues::get(),
|
||||
|
||||
@@ -72,12 +72,15 @@ where
|
||||
MaxValues: Get<Option<u32>>,
|
||||
{
|
||||
type Query = QueryKind::Query;
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
Prefix::pallet_prefix().as_bytes()
|
||||
}
|
||||
fn storage_prefix() -> &'static [u8] {
|
||||
Prefix::STORAGE_PREFIX.as_bytes()
|
||||
}
|
||||
fn prefix_hash() -> [u8; 32] {
|
||||
Prefix::prefix_hash()
|
||||
}
|
||||
fn from_optional_value_to_query(v: Option<Value>) -> Self::Query {
|
||||
QueryKind::from_optional_value_to_query(v)
|
||||
}
|
||||
@@ -96,8 +99,8 @@ where
|
||||
OnEmpty: Get<QueryKind::Query> + 'static,
|
||||
MaxValues: Get<Option<u32>>,
|
||||
{
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageNMap<Key, Value>>::module_prefix()
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageNMap<Key, Value>>::pallet_prefix()
|
||||
}
|
||||
fn storage_prefix() -> &'static [u8] {
|
||||
<Self as crate::storage::generator::StorageNMap<Key, Value>>::storage_prefix()
|
||||
@@ -581,7 +584,7 @@ where
|
||||
{
|
||||
fn storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::final_prefix().to_vec(),
|
||||
max_values: MaxValues::get(),
|
||||
@@ -607,7 +610,7 @@ where
|
||||
{
|
||||
fn partial_storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::final_prefix().to_vec(),
|
||||
max_values: MaxValues::get(),
|
||||
|
||||
@@ -49,7 +49,7 @@ where
|
||||
OnEmpty: crate::traits::Get<QueryKind::Query> + 'static,
|
||||
{
|
||||
type Query = QueryKind::Query;
|
||||
fn module_prefix() -> &'static [u8] {
|
||||
fn pallet_prefix() -> &'static [u8] {
|
||||
Prefix::pallet_prefix().as_bytes()
|
||||
}
|
||||
fn storage_prefix() -> &'static [u8] {
|
||||
@@ -61,6 +61,9 @@ where
|
||||
fn from_query_to_optional_value(v: Self::Query) -> Option<Value> {
|
||||
QueryKind::from_query_to_optional_value(v)
|
||||
}
|
||||
fn storage_value_final_key() -> [u8; 32] {
|
||||
Prefix::prefix_hash()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Prefix, Value, QueryKind, OnEmpty> StorageValue<Prefix, Value, QueryKind, OnEmpty>
|
||||
@@ -251,7 +254,7 @@ where
|
||||
{
|
||||
fn storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::hashed_key().to_vec(),
|
||||
max_values: Some(1),
|
||||
@@ -271,7 +274,7 @@ where
|
||||
{
|
||||
fn partial_storage_info() -> Vec<StorageInfo> {
|
||||
vec![StorageInfo {
|
||||
pallet_name: Self::module_prefix().to_vec(),
|
||||
pallet_name: Self::pallet_prefix().to_vec(),
|
||||
storage_name: Self::storage_prefix().to_vec(),
|
||||
prefix: Self::hashed_key().to_vec(),
|
||||
max_values: Some(1),
|
||||
|
||||
Reference in New Issue
Block a user