mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 04:37:57 +00:00
Allow to specify some max number of values for storages in pallet macro. (#8735)
* implement max_values + storages info * some formatting + doc * rename StoragesInfo -> PalletStorageInfo * merge both StorageInfoTrait and PalletStorageInfo I think it is more future proof. In the future some storage could make use of multiple prefix. Like one to store how much value has been inserted, etc... * Update frame/support/procedural/src/storage/parse.rs Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com> * Update frame/support/procedural/src/storage/storage_struct.rs Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com> * Fix max_size using hasher information hasher now expose `max_len` which allows to computes their maximum len. For hasher without concatenation, it is the size of the hash part, for hasher with concatenation, it is the size of the hash part + max encoded len of the key. * fix tests * fix ui tests Co-authored-by: Peter Goodspeed-Niklaus <coriolinus@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
59f34ab8bc
commit
9bf62ef65d
@@ -17,6 +17,8 @@
|
||||
|
||||
//! Traits for encoding data related to pallet's storage items.
|
||||
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// An instance of a pallet in the storage.
|
||||
///
|
||||
/// It is required that these instances are unique, to support multiple instances per pallet in the same runtime!
|
||||
@@ -45,3 +47,30 @@ pub trait StorageInstance {
|
||||
/// Prefix given to a storage to isolate from other storages in the pallet.
|
||||
const STORAGE_PREFIX: &'static str;
|
||||
}
|
||||
|
||||
/// Some info about an individual storage in a pallet.
|
||||
#[derive(codec::Encode, codec::Decode, crate::RuntimeDebug, Eq, PartialEq, Clone)]
|
||||
pub struct StorageInfo {
|
||||
/// The prefix of the storage. All keys after the prefix are considered part of the storage
|
||||
pub prefix: [u8; 32],
|
||||
/// The maximum number of values in the storage, or none if no maximum specified.
|
||||
pub max_values: Option<u32>,
|
||||
/// The maximum size of key/values in the storage, or none if no maximum specified.
|
||||
pub max_size: Option<u32>,
|
||||
}
|
||||
|
||||
/// A trait to give information about storage.
|
||||
///
|
||||
/// It can be used to calculate PoV worst case size.
|
||||
pub trait StorageInfoTrait {
|
||||
fn storage_info() -> Vec<StorageInfo>;
|
||||
}
|
||||
|
||||
#[impl_trait_for_tuples::impl_for_tuples(30)]
|
||||
impl StorageInfoTrait for Tuple {
|
||||
fn storage_info() -> Vec<StorageInfo> {
|
||||
let mut res = vec![];
|
||||
for_tuples!( #( res.extend_from_slice(&Tuple::storage_info()); )* );
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user