mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Metadata V15: Expose API to fetch metadata for version (#13287)
* impl_runtime_apis: Generate getters for `metadata_at` functions Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * runtime: Implement new `Metadata` runtime trait Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * runtime: Move `metadata_at` functions to construct_runtime macro Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * contruct_runtime: Use `OpaqueMetadata` from hidden imports Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Adjust testing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/tests: Add tests for the new API Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/tests: Adjust metdata naming Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Expose `metadata-v14` feature flag Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Expose metadata only under feature flags Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Expose v14 metadata by default Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Expose metadata feature for testing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Test metadata under different feature flags Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update primitives/api/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/api/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * client/tests: Adjust testing to reflect trait Metadata change Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/metadata-ir: Add intermediate representation types for metadata Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/metadata-ir: Convert metadata to V14 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/metadata-ir: Add API to convert metadata to multiple versions Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/metadata-ir: Expose V14 under feature flag Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Adjust to metadata IR Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: More adjustments Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Guard v14 details under feature flag Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Adjust testing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * CI: Ensure `quick-benchmarks` uses `metadata-v14` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Use `metadata-v14` for benchmarks Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Adjust cargo fmt Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * kitchensink-runtime: Add feature flag for `metadata-v14` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support/test: Adjust testing Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support/test: Check crates locally Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Activate metadata-v14 for pallets Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Remove metadata-v14 feature flag Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/metadata_ir: Move `api.rs` to `mod.rs` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Handle latest metadata conversion via IR Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/tests: Add constant for metadata version 14 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support/test: Fix merge conflict Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update frame/support/Cargo.toml Co-authored-by: Bastian Köcher <git@kchr.de> * Update frame/support/src/metadata_ir/mod.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update frame/support/test/Cargo.toml Co-authored-by: Bastian Köcher <git@kchr.de> * Update primitives/api/src/lib.rs Co-authored-by: Bastian Köcher <git@kchr.de> * frame/metadata: Collect pallet documentation for MetadataIR Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/tests: Check pallet documentation is propagated to MetadataIR Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * frame/support: Improve documentation Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: parity-processbot <> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -48,6 +48,7 @@ pub fn expand_runtime_metadata(
|
||||
let event = expand_pallet_metadata_events(&filtered_names, runtime, scrate, decl);
|
||||
let constants = expand_pallet_metadata_constants(runtime, decl);
|
||||
let errors = expand_pallet_metadata_errors(runtime, decl);
|
||||
let docs = expand_pallet_metadata_docs(runtime, decl);
|
||||
let attr = decl.cfg_pattern.iter().fold(TokenStream::new(), |acc, pattern| {
|
||||
let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original()))
|
||||
.expect("was successfully parsed before; qed");
|
||||
@@ -59,7 +60,7 @@ pub fn expand_runtime_metadata(
|
||||
|
||||
quote! {
|
||||
#attr
|
||||
#scrate::metadata::PalletMetadata {
|
||||
#scrate::metadata_ir::PalletMetadataIR {
|
||||
name: stringify!(#name),
|
||||
index: #index,
|
||||
storage: #storage,
|
||||
@@ -67,6 +68,7 @@ pub fn expand_runtime_metadata(
|
||||
event: #event,
|
||||
constants: #constants,
|
||||
error: #errors,
|
||||
docs: #docs,
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -74,10 +76,10 @@ pub fn expand_runtime_metadata(
|
||||
|
||||
quote! {
|
||||
impl #runtime {
|
||||
pub fn metadata() -> #scrate::metadata::RuntimeMetadataPrefixed {
|
||||
#scrate::metadata::RuntimeMetadataLastVersion::new(
|
||||
#scrate::sp_std::vec![ #(#pallets),* ],
|
||||
#scrate::metadata::ExtrinsicMetadata {
|
||||
fn metadata_ir() -> #scrate::metadata_ir::MetadataIR {
|
||||
#scrate::metadata_ir::MetadataIR {
|
||||
pallets: #scrate::sp_std::vec![ #(#pallets),* ],
|
||||
extrinsic: #scrate::metadata_ir::ExtrinsicMetadataIR {
|
||||
ty: #scrate::scale_info::meta_type::<#extrinsic>(),
|
||||
version: <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSION,
|
||||
signed_extensions: <
|
||||
@@ -86,15 +88,29 @@ pub fn expand_runtime_metadata(
|
||||
>::SignedExtensions as #scrate::sp_runtime::traits::SignedExtension
|
||||
>::metadata()
|
||||
.into_iter()
|
||||
.map(|meta| #scrate::metadata::SignedExtensionMetadata {
|
||||
.map(|meta| #scrate::metadata_ir::SignedExtensionMetadataIR {
|
||||
identifier: meta.identifier,
|
||||
ty: meta.ty,
|
||||
additional_signed: meta.additional_signed,
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
#scrate::scale_info::meta_type::<#runtime>()
|
||||
).into()
|
||||
ty: #scrate::scale_info::meta_type::<#runtime>()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata() -> #scrate::metadata::RuntimeMetadataPrefixed {
|
||||
#scrate::metadata_ir::into_latest(#runtime::metadata_ir())
|
||||
}
|
||||
|
||||
pub fn metadata_at_version(version: u32) -> Option<#scrate::OpaqueMetadata> {
|
||||
#scrate::metadata_ir::into_version(#runtime::metadata_ir(), version).map(|prefixed| {
|
||||
#scrate::OpaqueMetadata::new(prefixed.into())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn metadata_versions() -> #scrate::sp_std::vec::Vec<u32> {
|
||||
#scrate::metadata_ir::supported_versions()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,7 +173,7 @@ fn expand_pallet_metadata_events(
|
||||
|
||||
quote! {
|
||||
Some(
|
||||
#scrate::metadata::PalletEventMetadata {
|
||||
#scrate::metadata_ir::PalletEventMetadataIR {
|
||||
ty: #scrate::scale_info::meta_type::<#pallet_event>()
|
||||
}
|
||||
)
|
||||
@@ -184,3 +200,12 @@ fn expand_pallet_metadata_errors(runtime: &Ident, decl: &Pallet) -> TokenStream
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::error_metadata()
|
||||
}
|
||||
}
|
||||
|
||||
fn expand_pallet_metadata_docs(runtime: &Ident, decl: &Pallet) -> TokenStream {
|
||||
let path = &decl.path;
|
||||
let instance = decl.instance.as_ref().into_iter();
|
||||
|
||||
quote! {
|
||||
#path::Pallet::<#runtime #(, #path::#instance)*>::pallet_documentation_metadata()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user