mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-21 21:31:02 +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:
@@ -17,7 +17,7 @@
|
||||
|
||||
//! Implementation of the `storage_alias` attribute macro.
|
||||
|
||||
use crate::counter_prefix;
|
||||
use crate::{counter_prefix, pallet::parse::helper};
|
||||
use frame_support_procedural_tools::generate_crate_access_2018;
|
||||
use proc_macro2::{Span, TokenStream};
|
||||
use quote::{quote, ToTokens};
|
||||
@@ -619,6 +619,7 @@ fn generate_storage_instance(
|
||||
let counter_code = is_counted_map.then(|| {
|
||||
let counter_name = Ident::new(&counter_prefix(&name_str), Span::call_site());
|
||||
let counter_storage_name_str = counter_prefix(&storage_name_str);
|
||||
let storage_prefix_hash = helper::two128_str(&counter_storage_name_str);
|
||||
|
||||
quote! {
|
||||
#visibility struct #counter_name< #impl_generics >(
|
||||
@@ -633,6 +634,9 @@ fn generate_storage_instance(
|
||||
}
|
||||
|
||||
const STORAGE_PREFIX: &'static str = #counter_storage_name_str;
|
||||
fn storage_prefix_hash() -> [u8; 16] {
|
||||
#storage_prefix_hash
|
||||
}
|
||||
}
|
||||
|
||||
impl<#impl_generics> #crate_::storage::types::CountedStorageMapInstance
|
||||
@@ -643,6 +647,8 @@ fn generate_storage_instance(
|
||||
}
|
||||
});
|
||||
|
||||
let storage_prefix_hash = helper::two128_str(&storage_name_str);
|
||||
|
||||
// Implement `StorageInstance` trait.
|
||||
let code = quote! {
|
||||
#[allow(non_camel_case_types)]
|
||||
@@ -658,6 +664,9 @@ fn generate_storage_instance(
|
||||
}
|
||||
|
||||
const STORAGE_PREFIX: &'static str = #storage_name_str;
|
||||
fn storage_prefix_hash() -> [u8; 16] {
|
||||
#storage_prefix_hash
|
||||
}
|
||||
}
|
||||
|
||||
#counter_code
|
||||
|
||||
Reference in New Issue
Block a user