Support V16 metadata and refactor metadata code (#1967)

* WIP integrate unstable v16 metadata into Subxt

* first pass moving retain to the CLI tool

* Remove otuer enum variant stripping and move now simpler strip_metadata to new crate. test it

* tidyup to use stripmetadata package etc

* Fix / comment out tests

* fmt

* clippy

* Fix wasm example

* wasm-example fix

* wasm-example fix

* Maske sure to move IDs around after types.retain()

* fmt

* Tweak comment

* Find dispatch error separately to avoid issues during mapping

* Expose associated type information in pallet metadata

* Hopefully fix flaky archive RPC

* remove unwanted temp file

* Address nits

* Add back commented-otu tests and address review comments

* use either, and simplify for_each
This commit is contained in:
James Wilson
2025-03-28 15:35:55 +00:00
committed by GitHub
parent 06396f8b1a
commit 72ac18491c
32 changed files with 2355 additions and 2274 deletions
+2 -3
View File
@@ -157,8 +157,6 @@ impl RuntimeGenerator {
.collect();
let runtime_api_names_len = runtime_api_names.len();
let metadata_hash = self.metadata.hasher().hash();
let modules = pallets_with_mod_names
.iter()
.map(|(pallet, mod_name)| {
@@ -219,7 +217,6 @@ impl RuntimeGenerator {
// Fetch the paths of the outer enums.
// Substrate exposes those under `kitchensink_runtime`, while Polkadot under `polkadot_runtime`.
let call_path = type_gen
.resolve_type_path(self.metadata.outer_enums().call_enum_ty())?
.to_token_stream(type_gen.settings());
@@ -230,6 +227,8 @@ impl RuntimeGenerator {
.resolve_type_path(self.metadata.outer_enums().error_enum_ty())?
.to_token_stream(type_gen.settings());
let metadata_hash = self.metadata.hasher().hash();
let custom_values = generate_custom_values(&self.metadata, &type_gen, &crate_path);
Ok(quote! {
+3 -9
View File
@@ -33,7 +33,7 @@ fn generate_runtime_api(
.then_some(quote! { #( #[doc = #docs ] )* })
.unwrap_or_default();
let structs_and_methods: Vec<_> = api
let structs_and_methods = api
.methods()
.map(|method| {
let method_name = format_ident!("{}", method.name());
@@ -126,13 +126,7 @@ fn generate_runtime_api(
}
);
let Some(call_hash) = api.method_hash(method.name()) else {
return Err(CodegenError::MissingRuntimeApiMetadata(
trait_name_str.to_owned(),
method_name_str.to_owned(),
))
};
let call_hash = method.hash();
let method = quote!(
#docs
pub fn #method_name(&self, #( #fn_params, )* ) -> #crate_path::runtime_api::payload::StaticPayload<types::#struct_name, types::#method_name::output::Output> {
@@ -147,7 +141,7 @@ fn generate_runtime_api(
Ok((struct_input, method))
})
.collect::<Result<_, _>>()?;
.collect::<Result<Vec<_>, CodegenError>>()?;
let trait_name = format_ident!("{}", trait_name_str);