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

Commit

Permalink
frame: Abuse Deref to resolve runtime_metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandru Vasile <[email protected]>
  • Loading branch information
lexnv committed Feb 6, 2023
1 parent 78dcb67 commit 3ce25e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pub fn expand_runtime_metadata(
}

fn metadata_v15() -> #scrate::metadata::RuntimeMetadataPrefixed {
let rt = #runtime;

#scrate::metadata::v15::RuntimeMetadataLastVersion::new(
#scrate::sp_std::vec![ #(#pallets),* ],
#scrate::metadata::ExtrinsicMetadata {
Expand All @@ -130,7 +132,7 @@ pub fn expand_runtime_metadata(
.collect(),
},
#scrate::scale_info::meta_type::<#runtime>(),
#runtime::runtime_metadata(),
(&rt).runtime_metadata(),
).into()
}
}
Expand Down
8 changes: 8 additions & 0 deletions frame/support/procedural/src/construct_runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ fn construct_runtime_final_expansion(
type RuntimeBlock = #block;
}

trait InternalConstructRuntime {
#[inline(always)]
fn runtime_metadata(&self) -> #scrate::sp_std::vec::Vec<#scrate::metadata::v15::TraitMetadata> {
Default::default()
}
}
impl InternalConstructRuntime for &#name {}

#outer_event

#outer_origin
Expand Down
6 changes: 4 additions & 2 deletions primitives/api/proc-macro/src/runtime_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,13 @@ pub fn generate_runtime_metadata2(impls: &[ItemImpl], crate_: &TokenStream) -> R
}

Ok(quote!(
impl #runtime_name {
pub fn runtime_metadata() -> #crate_::vec::Vec<#crate_::metadata::v15::TraitMetadata> {
trait InternalImplRuntimeApis {
#[inline(always)]
fn runtime_metadata(&self) -> #crate_::vec::Vec<#crate_::metadata::v15::TraitMetadata> {
#crate_::vec![ #( #metadata, )* ]
}
}
impl InternalImplRuntimeApis for #runtime_name {}
))
}

Expand Down

0 comments on commit 3ce25e1

Please sign in to comment.