mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 05:47:58 +00:00
Implement a proper generic resolution in decl_storage! (#2913)
* Add failing test case * move storage maps to blake2_128 (#2268) * remove default hash, introduce twox_128 and blake2 * use blake2_128 & create ext_blake2_128 * refactor code * add benchmark * factorize generator * fix * parameterizable hasher * some fix * fix * fix * fix * metadata * fix * remove debug print * map -> blake2_256 * fix test * fix test * Apply suggestions from code review Co-Authored-By: thiolliere <gui.thiolliere@gmail.com> * impl twox 128 concat (#2353) * impl twox_128_concat * comment addressed * fix * impl twox_128->64_concat * fix test * Fix compilation and cleanup some docs * Lol * Remove traits from storage types that are not generic * Get instance test almost working as wanted * Make `srml-support-test` compile again :) * Fixes test of srml-support * Fix compilation * Break some lines * Remove incorrect macro match arm * Integrates review feedback * Update documentation * Fix compilation
This commit is contained in:
@@ -61,9 +61,9 @@
|
||||
/// - `Module`
|
||||
/// - `Call`
|
||||
/// - `Storage`
|
||||
/// - `Event` or `Event<T>` (if the event is generic) or `Event<T, I>` (if also over instance)
|
||||
/// - `Origin` or `Origin<T>` (if the origin is generic) or `Origin<T, I>` (if also over instance)
|
||||
/// - `Config` or `Config<T>` (if the config is generic) or `Config<T, I>` (if also over instance)
|
||||
/// - `Event` or `Event<T>` (if the event is generic)
|
||||
/// - `Origin` or `Origin<T>` (if the origin is generic)
|
||||
/// - `Config` or `Config<T>` (if the config is generic)
|
||||
/// - `Inherent $( (CALL) )*` - If the module provides/can check inherents. The optional parameter
|
||||
/// is for modules that use a `Call` from a different module as
|
||||
/// inherent.
|
||||
@@ -101,6 +101,7 @@ macro_rules! construct_runtime {
|
||||
$( $rest )*
|
||||
);
|
||||
};
|
||||
// No modules given, expand to the default module set.
|
||||
(
|
||||
{ $( $preset:tt )* };
|
||||
{ $( $expanded:tt )* };
|
||||
@@ -114,6 +115,7 @@ macro_rules! construct_runtime {
|
||||
$( $rest )*
|
||||
);
|
||||
};
|
||||
// `default` identifier given, expand to default + given extra modules
|
||||
(
|
||||
{ $( $preset:tt )* };
|
||||
{ $( $expanded:tt )* };
|
||||
@@ -121,7 +123,7 @@ macro_rules! construct_runtime {
|
||||
default
|
||||
$(,
|
||||
$modules:ident
|
||||
$( <$modules_generic:ident $(, $modules_instance:ident)?> )*
|
||||
$( <$modules_generic:ident> )*
|
||||
$( ( $( $modules_args:ident ),* ) )*
|
||||
)*
|
||||
},
|
||||
@@ -129,21 +131,24 @@ macro_rules! construct_runtime {
|
||||
) => {
|
||||
$crate::construct_runtime!(
|
||||
{ $( $preset )* };
|
||||
{ $( $expanded )* };
|
||||
$name: $module::{
|
||||
Module, Call, Storage, Event<T>, Config<T>
|
||||
$(,
|
||||
$modules $( <$modules_generic $(, $modules_instance)?> )*
|
||||
$( ( $( $modules_args ),* ) )*
|
||||
)*
|
||||
},
|
||||
{
|
||||
$( $expanded )*
|
||||
$name: $module::{
|
||||
Module, Call, Storage, Event<T>, Config<T>
|
||||
$(,
|
||||
$modules $( <$modules_generic> )*
|
||||
$( ( $( $modules_args ),* ) )*
|
||||
)*
|
||||
},
|
||||
};
|
||||
$( $rest )*
|
||||
);
|
||||
};
|
||||
// Take all modules as given by the user.
|
||||
(
|
||||
{ $( $preset:tt )* };
|
||||
{ $( $expanded:tt )* };
|
||||
$name:ident: $module:ident::{
|
||||
$name:ident: $module:ident :: $( < $module_instance:ident >:: )? {
|
||||
$(
|
||||
$modules:ident
|
||||
$( <$modules_generic:ident> )*
|
||||
@@ -156,7 +161,7 @@ macro_rules! construct_runtime {
|
||||
{ $( $preset )* };
|
||||
{
|
||||
$( $expanded )*
|
||||
$name: $module::{
|
||||
$name: $module:: $( < $module_instance >:: )? {
|
||||
$(
|
||||
$modules $( <$modules_generic> )*
|
||||
$( ( $( $modules_args ),* ) )*
|
||||
@@ -166,35 +171,7 @@ macro_rules! construct_runtime {
|
||||
$( $rest )*
|
||||
);
|
||||
};
|
||||
( // Instance module: we indicate the generic instance `I` with the full instance path
|
||||
{ $( $preset:tt )* };
|
||||
{ $( $expanded:tt )* };
|
||||
$name:ident: $module:ident ::< $module_instance:ident >::{
|
||||
$(
|
||||
$modules:ident
|
||||
$( <$modules_generic:ident $(, $modules_instance:ident )?> )*
|
||||
$( ( $( $modules_args:ident ),* ) )*
|
||||
),*
|
||||
},
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
$crate::construct_runtime!(
|
||||
{ $( $preset )* };
|
||||
{
|
||||
$( $expanded )*
|
||||
$name: $module::<$module_instance>::{
|
||||
$(
|
||||
$modules $( <$modules_generic $(, $modules_instance=$module::$module_instance)?> )*
|
||||
$( ( $( $modules_args ),* ) )*
|
||||
),*
|
||||
},
|
||||
};
|
||||
$( $rest )*
|
||||
);
|
||||
};
|
||||
|
||||
// The main macro expansion that actually renders the Runtime code.
|
||||
|
||||
(
|
||||
{
|
||||
$runtime:ident;
|
||||
@@ -207,7 +184,7 @@ macro_rules! construct_runtime {
|
||||
$name:ident: $module:ident :: $( < $module_instance:ident >:: )? {
|
||||
$(
|
||||
$modules:ident
|
||||
$( <$modules_generic:ident $(, I=$modules_instance:path)?> )*
|
||||
$( <$modules_generic:ident> )*
|
||||
$( ( $( $modules_args:ident ),* ) )*
|
||||
),*
|
||||
},
|
||||
@@ -223,19 +200,20 @@ macro_rules! construct_runtime {
|
||||
impl $crate::runtime_primitives::traits::GetRuntimeBlockType for $runtime {
|
||||
type RuntimeBlock = $block;
|
||||
}
|
||||
$crate::__decl_instance_import!(
|
||||
$( $( $module < $module_instance > )? )*
|
||||
);
|
||||
$crate::__decl_outer_event!(
|
||||
$runtime;
|
||||
$(
|
||||
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic $(, $modules_instance)?> )* ),* }
|
||||
$name: $module:: $( < $module_instance >:: )? {
|
||||
$( $modules $( <$modules_generic> )* ),*
|
||||
}
|
||||
),*
|
||||
);
|
||||
$crate::__decl_outer_origin!(
|
||||
$runtime;
|
||||
$(
|
||||
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic $(, $modules_instance)?> )* ),* }
|
||||
$name: $module:: $( < $module_instance >:: )? {
|
||||
$( $modules $( <$modules_generic> )* ),*
|
||||
}
|
||||
),*
|
||||
);
|
||||
$crate::__decl_all_modules!(
|
||||
@@ -265,7 +243,7 @@ macro_rules! construct_runtime {
|
||||
{};
|
||||
$(
|
||||
$name: $module:: $( < $module_instance >:: )? {
|
||||
$( $modules $( <$modules_generic $(, $modules_instance)?> )* ),*
|
||||
$( $modules $( <$modules_generic> )* ),*
|
||||
},
|
||||
)*
|
||||
);
|
||||
@@ -307,7 +285,7 @@ macro_rules! __create_decl_macro {
|
||||
(
|
||||
$runtime:ident;
|
||||
$d( $name:ident : $module:ident:: $d( < $module_instance:ident >:: )? {
|
||||
$d( $modules:ident $d( <$modules_generic:ident $d(, $modules_instance:path)?> ),* ),*
|
||||
$d( $modules:ident $d( <$modules_generic:ident> ),* ),*
|
||||
}),*
|
||||
) => {
|
||||
$d crate::$macro_name!(@inner
|
||||
@@ -316,7 +294,7 @@ macro_rules! __create_decl_macro {
|
||||
{};
|
||||
$d(
|
||||
$name: $module:: $d( < $module_instance >:: )? {
|
||||
$d( $modules $d( <$modules_generic $d(, $modules_instance)?> )* ),*
|
||||
$d( $modules $d( <$modules_generic> )* ),*
|
||||
},
|
||||
)*
|
||||
);
|
||||
@@ -342,7 +320,7 @@ macro_rules! __create_decl_macro {
|
||||
$d( $system:ident )?;
|
||||
{ $d( $parsed:tt )* };
|
||||
$name:ident : $module:ident:: < $module_instance:ident >:: {
|
||||
$macro_enum_name <$event_generic:ident, $event_instance:path> $d(, $ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* )*
|
||||
$macro_enum_name <$event_generic:ident> $d(, $ingore:ident $d( <$ignor:ident> )* )*
|
||||
},
|
||||
$d( $rest:tt )*
|
||||
) => {
|
||||
@@ -351,33 +329,17 @@ macro_rules! __create_decl_macro {
|
||||
$d( $system )?;
|
||||
{
|
||||
$d( $parsed )*
|
||||
$module $module_instance <$event_generic, $event_instance>,
|
||||
$module $module_instance <$event_generic>,
|
||||
};
|
||||
$d( $rest )*
|
||||
);
|
||||
};
|
||||
(@inner
|
||||
$runtime:ident;
|
||||
$d( $system:ident )?;
|
||||
{ $d( $parsed:tt )* };
|
||||
$name:ident : $module:ident:: < $module_instance:ident >:: {
|
||||
$macro_enum_name $d( <$event_generic:ident> )* $d(, $ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* )*
|
||||
},
|
||||
$d( $rest:tt )*
|
||||
) => {
|
||||
compile_error!{concat!{
|
||||
"Module `", stringify!{$name}, "` must have `", stringify!{$macro_enum_name}, "<T, I>`",
|
||||
" but has `", stringify!{$macro_enum_name} $d(, "<", stringify!{$event_generic}, ">")*, "`",
|
||||
": Instantiated modules must have ", stringify!{$macro_enum_name},
|
||||
" generic over instance to be able to convert to outer ", stringify!{$macro_enum_name}
|
||||
}}
|
||||
};
|
||||
(@inner
|
||||
$runtime:ident;
|
||||
$d( $system:ident )?;
|
||||
{ $d( $parsed:tt )* };
|
||||
$name:ident : $module:ident:: {
|
||||
$macro_enum_name $d( <$event_generic:ident $d(, $event_instance:path)?> )* $d(, $ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* )*
|
||||
$macro_enum_name $d( <$event_generic:ident> )* $d(, $ignore:ident $d( <$ignor:ident> )* )*
|
||||
},
|
||||
$d( $rest:tt )*
|
||||
) => {
|
||||
@@ -386,7 +348,7 @@ macro_rules! __create_decl_macro {
|
||||
$d( $system )?;
|
||||
{
|
||||
$d( $parsed )*
|
||||
$module $d( <$event_generic $d(, $event_instance)?> )*,
|
||||
$module $d( <$event_generic> )*,
|
||||
};
|
||||
$d( $rest )*
|
||||
);
|
||||
@@ -396,7 +358,7 @@ macro_rules! __create_decl_macro {
|
||||
$d( $system:ident )?;
|
||||
{ $d( $parsed:tt )* };
|
||||
$name:ident : $module:ident:: $d( < $module_instance:ident >:: )? {
|
||||
$ignore:ident $d( <$ignor:ident $d(, $ignore_instance:path)?> )* $d(, $modules:ident $d( <$modules_generic:ident $d(, $modules_instance:path)?> )* )*
|
||||
$ingore:ident $d( <$ignor:ident> )* $d(, $modules:ident $d( <$modules_generic:ident> )* )*
|
||||
},
|
||||
$d( $rest:tt )*
|
||||
) => {
|
||||
@@ -404,7 +366,7 @@ macro_rules! __create_decl_macro {
|
||||
$runtime;
|
||||
$d( $system )?;
|
||||
{ $d( $parsed )* };
|
||||
$name: $module:: $d( < $module_instance >:: )? { $d( $modules $d( <$modules_generic $d(, $modules_instance)?> )* ),* },
|
||||
$name: $module:: $d( < $module_instance >:: )? { $d( $modules $d( <$modules_generic> )* ),* },
|
||||
$d( $rest )*
|
||||
);
|
||||
};
|
||||
@@ -425,16 +387,13 @@ macro_rules! __create_decl_macro {
|
||||
(@inner
|
||||
$runtime:ident;
|
||||
$system:ident;
|
||||
{ $d( $parsed_modules:ident $d( $instance:ident )? $d( <$parsed_generic:ident $d(, $parsed_instance_full_path:path)?> )* ,)* };
|
||||
{ $d( $parsed_modules:ident $d( $instance:ident )? $d( <$parsed_generic:ident> )? ,)* };
|
||||
) => {
|
||||
$d crate::paste::item! {
|
||||
$d crate::$macro_outer_name! {
|
||||
|
||||
pub enum $macro_enum_name for $runtime where system = $system {
|
||||
$d(
|
||||
[< $parsed_modules $d(_ $instance )? >] $d( <$parsed_generic $d(, $parsed_instance_full_path)?> )*,
|
||||
)*
|
||||
}
|
||||
$d crate::$macro_outer_name! {
|
||||
pub enum $macro_enum_name for $runtime where system = $system {
|
||||
$d(
|
||||
$parsed_modules $d( $instance )? $d( <$parsed_generic> )?,
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -668,7 +627,7 @@ macro_rules! __decl_runtime_metadata {
|
||||
}
|
||||
}
|
||||
|
||||
/// A private macro that generates GenesisConfig for the runtime. See impl_outer_config macro.
|
||||
/// A private macro that generates GenesisConfig for the runtime. See `impl_outer_config!` macro.
|
||||
#[macro_export]
|
||||
#[doc(hidden)]
|
||||
macro_rules! __decl_outer_config {
|
||||
@@ -676,7 +635,8 @@ macro_rules! __decl_outer_config {
|
||||
$runtime:ident;
|
||||
{ $( $parsed:tt )* };
|
||||
$name:ident: $module:ident:: $( < $module_instance:ident >:: )? {
|
||||
Config $(< $config_generic:ident $(, $config_instance:path)?>)? $(, $modules:ident $( <$modules_generic:ident $(, $modules_instance:path)?> )* )*
|
||||
Config $( <$config_generic:ident> )?
|
||||
$(, $modules:ident $( <$modules_generic:ident> )* )*
|
||||
},
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
@@ -684,7 +644,7 @@ macro_rules! __decl_outer_config {
|
||||
$runtime;
|
||||
{
|
||||
$( $parsed )*
|
||||
$module::$name $( $module_instance )? $(<$config_generic $(, $config_instance)?>)?,
|
||||
$module::$name $( $module_instance )? $( <$config_generic> )?,
|
||||
};
|
||||
$( $rest )*
|
||||
);
|
||||
@@ -693,14 +653,15 @@ macro_rules! __decl_outer_config {
|
||||
$runtime:ident;
|
||||
{ $( $parsed:tt )* };
|
||||
$name:ident: $module:ident:: $( < $module_instance:ident >:: )? {
|
||||
$ignore:ident $( <$ignor:ident $(, $ignore_instance:path)?> )* $(, $modules:ident $( <$modules_generic:ident $(, $modules_instance:path)?> )* )*
|
||||
$ingore:ident $( <$ignore_gen:ident> )*
|
||||
$(, $modules:ident $( <$modules_generic:ident> )* )*
|
||||
},
|
||||
$( $rest:tt )*
|
||||
) => {
|
||||
$crate::__decl_outer_config!(
|
||||
$runtime;
|
||||
{ $( $parsed )* };
|
||||
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic $(, $modules_instance)?> )* ),* },
|
||||
$name: $module:: $( < $module_instance >:: )? { $( $modules $( <$modules_generic> )* ),* },
|
||||
$( $rest )*
|
||||
);
|
||||
};
|
||||
@@ -718,13 +679,21 @@ macro_rules! __decl_outer_config {
|
||||
};
|
||||
(
|
||||
$runtime:ident;
|
||||
{$( $parsed_modules:ident :: $parsed_name:ident $( $parsed_instance:ident )? $( < $parsed_generic:ident $(, $parsed_instance_full_path:path)? > )* ,)* };
|
||||
{
|
||||
$(
|
||||
$parsed_modules:ident :: $parsed_name:ident $( $parsed_instance:ident )?
|
||||
$(
|
||||
<$parsed_generic:ident>
|
||||
)*
|
||||
,)*
|
||||
};
|
||||
) => {
|
||||
$crate::paste::item! {
|
||||
$crate::runtime_primitives::impl_outer_config!(
|
||||
pub struct GenesisConfig for $runtime {
|
||||
$(
|
||||
[< $parsed_name Config >] => [< $parsed_modules $( _ $parsed_instance)? >] $( < $parsed_generic $(, $parsed_instance_full_path)? > )*,
|
||||
[< $parsed_name Config >] =>
|
||||
$parsed_modules $( $parsed_instance )? $( <$parsed_generic> )*,
|
||||
)*
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user