mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-07 21:17:23 +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
@@ -18,6 +18,7 @@
|
||||
//! `decl_storage` input definition and expansion.
|
||||
|
||||
mod storage_struct;
|
||||
mod storage_info;
|
||||
mod parse;
|
||||
mod store_trait;
|
||||
mod getters;
|
||||
@@ -35,6 +36,8 @@ use frame_support_procedural_tools::{
|
||||
|
||||
/// All information contained in input of decl_storage
|
||||
pub struct DeclStorageDef {
|
||||
/// Whether to generate the storage info
|
||||
generate_storage_info: bool,
|
||||
/// Name of the module used to import hidden imports.
|
||||
hidden_crate: Option<syn::Ident>,
|
||||
/// Visibility of store trait.
|
||||
@@ -69,6 +72,8 @@ impl syn::parse::Parse for DeclStorageDef {
|
||||
|
||||
/// Extended version of `DeclStorageDef` with useful precomputed value.
|
||||
pub struct DeclStorageDefExt {
|
||||
/// Whether to generate the storage info
|
||||
generate_storage_info: bool,
|
||||
/// Name of the module used to import hidden imports.
|
||||
hidden_crate: proc_macro2::TokenStream,
|
||||
/// Hidden imports used by the module.
|
||||
@@ -154,6 +159,7 @@ impl From<DeclStorageDef> for DeclStorageDefExt {
|
||||
Self {
|
||||
hidden_crate,
|
||||
hidden_imports,
|
||||
generate_storage_info: def.generate_storage_info,
|
||||
visibility: def.visibility,
|
||||
store_trait: def.store_trait,
|
||||
module_name: def.module_name,
|
||||
@@ -193,6 +199,8 @@ pub struct StorageLineDef {
|
||||
getter: Option<syn::Ident>,
|
||||
/// The name of the field to be used in genesis config if any.
|
||||
config: Option<syn::Ident>,
|
||||
/// The given max values with `max_values` attribute, or a none if not specified.
|
||||
max_values: Option<syn::Expr>,
|
||||
/// The build function of the storage if any.
|
||||
build: Option<syn::Expr>,
|
||||
/// Default value of genesis config field and also for storage when no value available.
|
||||
@@ -210,6 +218,8 @@ pub struct StorageLineDefExt {
|
||||
getter: Option<syn::Ident>,
|
||||
/// The name of the field to be used in genesis config if any.
|
||||
config: Option<syn::Ident>,
|
||||
/// The given max values with `max_values` attribute, or a none if not specified.
|
||||
max_values: Option<syn::Expr>,
|
||||
/// The build function of the storage if any.
|
||||
build: Option<syn::Expr>,
|
||||
/// Default value of genesis config field and also for storage when no value available.
|
||||
@@ -333,6 +343,7 @@ impl StorageLineDefExt {
|
||||
name: storage_def.name,
|
||||
getter: storage_def.getter,
|
||||
config: storage_def.config,
|
||||
max_values: storage_def.max_values,
|
||||
build: storage_def.build,
|
||||
default_value: storage_def.default_value,
|
||||
storage_type: storage_def.storage_type,
|
||||
@@ -469,6 +480,7 @@ pub fn decl_storage_impl(input: proc_macro::TokenStream) -> proc_macro::TokenStr
|
||||
let instance_trait = instance_trait::decl_and_impl(&def_ext);
|
||||
let genesis_config = genesis_config::genesis_config_and_build_storage(&def_ext);
|
||||
let storage_struct = storage_struct::decl_and_impl(&def_ext);
|
||||
let storage_info = storage_info::impl_storage_info(&def_ext);
|
||||
|
||||
quote!(
|
||||
use #scrate::{
|
||||
@@ -489,5 +501,6 @@ pub fn decl_storage_impl(input: proc_macro::TokenStream) -> proc_macro::TokenStr
|
||||
#instance_trait
|
||||
#genesis_config
|
||||
#storage_struct
|
||||
#storage_info
|
||||
).into()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user