mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 10:21:04 +00:00
Implement StorageNMap (#8635)
* Implement StorageNMap * Change copyright date to 2021 * Rewrite keys to use impl_for_tuples instead of recursion * Implement prefix iteration on StorageNMap * Implement EncodeLike for key arguments * Rename KeyGenerator::Arg to KeyGenerator::KArg * Support StorageNMap in decl_storage and #[pallet::storage] macros * Use StorageNMap in assets pallet * Support migrate_keys in StorageNMap * Reduce line characters on select files * Refactor crate imports in decl_storage macros * Some more line char reductions and doc comment update * Update UI test expectations * Revert whitespace changes to untouched files * Generate Key struct instead of a 1-tuple when only 1 pair of key and hasher is provided * Revert formatting changes to unrelated files * Introduce KeyGeneratorInner * Add tests for StorageNMap in FRAMEv2 pallet macro * Small fixes to unit tests for StorageNMap * Bump runtime metadata version * Remove unused import * Update tests to use runtime metadata v13 * Introduce and use EncodeLikeTuple as a trait bound for KArg * Add some rustdocs * Revert usage of StorageNMap in assets pallet * Make use of ext::PunctuatedTrailing * Add rustdoc for final_hash * Fix StorageNMap proc macro expansions for single key cases * Create associated const in KeyGenerator for hasher metadata * Refactor code according to comments from Basti * Add module docs for generator/nmap.rs * Re-export storage::Key as NMapKey in pallet prelude * Seal the EncodeLikeTuple trait * Extract sealing code out of key.rs Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -90,6 +90,9 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
Metadata::DoubleMap { .. } => quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::storage::types::StorageDoubleMapMetadata
|
||||
),
|
||||
Metadata::NMap { .. } => quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::storage::types::StorageNMapMetadata
|
||||
),
|
||||
};
|
||||
|
||||
let ty = match &storage.metadata {
|
||||
@@ -126,6 +129,24 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
value: #frame_support::metadata::DecodeDifferent::Encode(#value),
|
||||
}
|
||||
)
|
||||
},
|
||||
Metadata::NMap { keys, value, .. } => {
|
||||
let keys = keys
|
||||
.iter()
|
||||
.map(|key| clean_type_string("e::quote!(#key).to_string()))
|
||||
.collect::<Vec<_>>();
|
||||
let value = clean_type_string("e::quote!(#value).to_string());
|
||||
quote::quote_spanned!(storage.attr_span =>
|
||||
#frame_support::metadata::StorageEntryType::NMap {
|
||||
keys: #frame_support::metadata::DecodeDifferent::Encode(&[
|
||||
#( #keys, )*
|
||||
]),
|
||||
hashers: #frame_support::metadata::DecodeDifferent::Encode(
|
||||
<#full_ident as #metadata_trait>::HASHERS,
|
||||
),
|
||||
value: #frame_support::metadata::DecodeDifferent::Encode(#value),
|
||||
}
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -227,6 +248,32 @@ pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream {
|
||||
}
|
||||
)
|
||||
},
|
||||
Metadata::NMap { keygen, value, .. } => {
|
||||
let query = match storage.query_kind.as_ref().expect("Checked by def") {
|
||||
QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span =>
|
||||
Option<#value>
|
||||
),
|
||||
QueryKind::ValueQuery => quote::quote!(#value),
|
||||
};
|
||||
quote::quote_spanned!(storage.attr_span =>
|
||||
#(#cfg_attrs)*
|
||||
impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause {
|
||||
#( #docs )*
|
||||
pub fn #getter<KArg>(key: KArg) -> #query
|
||||
where
|
||||
KArg: #frame_support::storage::types::EncodeLikeTuple<
|
||||
<#keygen as #frame_support::storage::types::KeyGenerator>::KArg
|
||||
>
|
||||
+ #frame_support::storage::types::TupleToEncodedIter,
|
||||
{
|
||||
<
|
||||
#full_ident as
|
||||
#frame_support::storage::StorageNMap<#keygen, #value>
|
||||
>::get(key)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Default::default()
|
||||
|
||||
Reference in New Issue
Block a user