Metadata V16: Be more dynamic over which hasher is used. (#1974)

* Use DynamicHasher256 to support Blake2 or Keccack depending on chain

* remove Config::Hash associated type, replace with HashFor<Config> alias

* Fix doc links

* fix wasm tests

* Don't strip system pallet associated types. check System.Hashing, not Hash. Rename BlockHash trait to Hash

* Tweak comment

* fmt

* fix merge

* Fix typo
This commit is contained in:
James Wilson
2025-04-23 10:12:48 +01:00
committed by GitHub
parent a8ae55a61b
commit 21b3f52191
43 changed files with 573 additions and 371 deletions
+28 -2
View File
@@ -75,10 +75,36 @@ impl StripMetadata for v16::RuntimeMetadataV16 {
PalletFilter: Fn(&str) -> bool,
RuntimeApiFilter: Fn(&str) -> bool,
{
// Throw away pallets and runtime APIs we don't care about:
self.pallets.retain(|pallet| keep_pallet(&pallet.name));
// Throw away pallets and runtime APIs we don't care about.
// Keep the System pallet, because it has some associated types that we care about in Subxt.
self.pallets
.retain(|pallet| pallet.name == "System" || keep_pallet(&pallet.name));
self.apis.retain(|api| keep_runtime_api(&api.name));
// If the user asked to strip the System pallet, we'll strip most things from it but keep the
// associated types, because Subxt makes use of them.
if !keep_pallet("System") {
if let Some(system_pallet) = self.pallets.iter_mut().find(|p| p.name == "System") {
let index = system_pallet.index;
let associated_types = core::mem::take(&mut system_pallet.associated_types);
*system_pallet = v16::PalletMetadata {
name: "System".to_string(),
index,
associated_types,
// Everything else is empty:
storage: None,
calls: None,
event: None,
constants: vec![],
error: None,
view_functions: vec![],
docs: vec![],
deprecation_info: v16::DeprecationStatus::NotDeprecated,
};
}
}
// Now, only retain types we care about in the registry:
retain_types(self);
}