mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-22 05:37:58 +00:00
Metadata: Retain a subset of metadata pallets (#879)
* Update cargo.lock to use scale-info v2.4.0 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Retain only a subset of the metadata Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * codegen: Generate top level Event Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Only retain DispatchError Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Export just the retain method Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * cli: Retain pallets Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * metadata: Do not include extrinsic metadata Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * retain: Fix clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * test-runtime: Generate per pallet metadata and rs file Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * ui-tests: Check per metadata generated files Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Revert "test-runtime: Generate per pallet metadata and rs file" This reverts commit 725a2e5f8339a795892dbbd2df19e49330ae3a9b. Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * ui-tests: Adjust path to metadata file Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * ui-tests: Change drop order to keep `PalletMetadata` around Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update metadata/src/retain.rs Co-authored-by: James Wilson <james@jsdw.me> * Address feedback Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * retain: Keep extrinsic type Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * cli: Introduce `MetadataSource` Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * cli: Use `MetadataSource` helper Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * cli: Use `FileOrUrl` flatten command argument Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * retain: Do not include generic type params in retained metadata Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Adjust subxt to scale-info v2.5.0 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Update scaleinfo to v2.5.0 Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * Remove deprecated fn Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * testing: Fix clippy Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * benches: Use inner fields of scale info Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> * address nits, and strip RuntimeCall type instead of trying to filter out use of it for better overall wins/clarity * fix UI test * move utils out of commands folder and fix clippy etc * address nits --------- Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io> Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
+23
-28
@@ -235,12 +235,13 @@ impl RuntimeGenerator {
|
||||
) -> Result<TokenStream2, CodegenError> {
|
||||
let item_mod_attrs = item_mod.attrs.clone();
|
||||
let item_mod_ir = ir::ItemMod::try_from(item_mod)?;
|
||||
let default_derives = derives.default_derives();
|
||||
|
||||
let type_gen = TypeGenerator::new(
|
||||
&self.metadata.types,
|
||||
"runtime_types",
|
||||
type_substitutes,
|
||||
derives,
|
||||
derives.clone(),
|
||||
crate_path.clone(),
|
||||
should_gen_docs,
|
||||
);
|
||||
@@ -258,28 +259,6 @@ impl RuntimeGenerator {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Get the path to the `Runtime` struct. We assume that the same path contains
|
||||
// RuntimeCall and RuntimeEvent.
|
||||
let runtime_type_id = self.metadata.ty.id;
|
||||
let runtime_path_segments = self
|
||||
.metadata
|
||||
.types
|
||||
.resolve(runtime_type_id)
|
||||
.ok_or(CodegenError::TypeNotFound(runtime_type_id))?
|
||||
.path
|
||||
.namespace()
|
||||
.iter()
|
||||
.map(|part| syn::PathSegment::from(format_ident!("{}", part)));
|
||||
let runtime_path_suffix = syn::Path {
|
||||
leading_colon: None,
|
||||
segments: syn::punctuated::Punctuated::from_iter(runtime_path_segments),
|
||||
};
|
||||
let runtime_path = if runtime_path_suffix.segments.is_empty() {
|
||||
quote!(#types_mod_ident)
|
||||
} else {
|
||||
quote!(#types_mod_ident::#runtime_path_suffix)
|
||||
};
|
||||
|
||||
// Pallet names and their length are used to create PALLETS array.
|
||||
// The array is used to identify the pallets composing the metadata for
|
||||
// validation of just those pallets.
|
||||
@@ -344,6 +323,26 @@ impl RuntimeGenerator {
|
||||
})
|
||||
.collect::<Result<Vec<_>, CodegenError>>()?;
|
||||
|
||||
let outer_event_variants = self.metadata.pallets.iter().filter_map(|p| {
|
||||
let variant_name = format_ident!("{}", p.name);
|
||||
let mod_name = format_ident!("{}", p.name.to_string().to_snake_case());
|
||||
let index = proc_macro2::Literal::u8_unsuffixed(p.index);
|
||||
|
||||
p.event.as_ref().map(|_| {
|
||||
quote! {
|
||||
#[codec(index = #index)]
|
||||
#variant_name(#mod_name::Event),
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let outer_event = quote! {
|
||||
#default_derives
|
||||
pub enum Event {
|
||||
#( #outer_event_variants )*
|
||||
}
|
||||
};
|
||||
|
||||
let root_event_if_arms = self.metadata.pallets.iter().filter_map(|p| {
|
||||
let variant_name_str = &p.name;
|
||||
let variant_name = format_ident!("{}", variant_name_str);
|
||||
@@ -402,14 +401,10 @@ impl RuntimeGenerator {
|
||||
// Identify the pallets composing the static metadata by name.
|
||||
pub static PALLETS: [&str; #pallet_names_len] = [ #(#pallet_names,)* ];
|
||||
|
||||
/// The statically generated runtime call type.
|
||||
pub type Call = #runtime_path::RuntimeCall;
|
||||
|
||||
/// The error type returned when there is a runtime issue.
|
||||
pub type DispatchError = #types_mod_ident::sp_runtime::DispatchError;
|
||||
|
||||
// Make the runtime event type easily accessible, and impl RootEvent to help decode into it.
|
||||
pub type Event = #runtime_path::RuntimeEvent;
|
||||
#outer_event
|
||||
|
||||
impl #crate_path::events::RootEvent for Event {
|
||||
fn root_event(pallet_bytes: &[u8], pallet_name: &str, pallet_ty: u32, metadata: &#crate_path::Metadata) -> Result<Self, #crate_path::Error> {
|
||||
|
||||
Reference in New Issue
Block a user