Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
frame::support: macro generating GenesisBuild::build for RuntimeGenes…
Browse files Browse the repository at this point in the history
…isConfig
  • Loading branch information
michalkucharczyk committed Jun 6, 2023
1 parent 692de3a commit 98398b4
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions frame/support/procedural/src/construct_runtime/expand/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub fn expand_outer_config(
let mut types = TokenStream::new();
let mut fields = TokenStream::new();
let mut build_storage_calls = TokenStream::new();
let mut genesis_build_calls = TokenStream::new();
let mut query_genesis_config_part_macros = Vec::new();

for decl in pallet_decls {
Expand All @@ -54,6 +55,9 @@ pub fn expand_outer_config(
fields.extend(quote!(#attr pub #field_name: #config,));
build_storage_calls
.extend(expand_config_build_storage_call(scrate, attr, runtime, decl, field_name));
genesis_build_calls.extend(expand_config_genesis_build_call(
scrate, &config, attr, runtime, decl, field_name,
));
query_genesis_config_part_macros.push(quote! {
#path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name);
#[cfg(feature = "std")]
Expand Down Expand Up @@ -95,6 +99,12 @@ pub fn expand_outer_config(
Ok(())
}
}

impl<T> #scrate::traits::GenesisBuild<T> for RuntimeGenesisConfig {
fn build(&self) {
#genesis_build_calls
}
}
}
}

Expand Down Expand Up @@ -143,3 +153,24 @@ fn expand_config_build_storage_call(
<#runtime, #instance>::build_module_genesis_storage(&self.#field_name, storage)?;
}
}

fn expand_config_genesis_build_call(
scrate: &TokenStream,
pallet_genesis_config: &Ident,
attr: &TokenStream,
runtime: &Ident,
decl: &Pallet,
field_name: &Ident,
) -> TokenStream {
let path = &decl.path;
let instance = if let Some(inst) = decl.instance.as_ref() {
quote!(#path::#inst)
} else {
quote!(#path::__InherentHiddenInstance)
};

quote! {
#attr
<#pallet_genesis_config as #scrate::traits::GenesisBuild::<#runtime, #instance>>::build(&self.#field_name);
}
}

0 comments on commit 98398b4

Please sign in to comment.