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
+11 -7
View File
@@ -45,7 +45,11 @@ use derive_where::derive_where;
use scale_decode::{DecodeAsFields, DecodeAsType};
use subxt_metadata::PalletMetadata;
use crate::{error::MetadataError, Config, Error, Metadata};
use crate::{
config::{Config, HashFor},
error::MetadataError,
Error, Metadata,
};
/// Create a new [`Events`] instance from the given bytes.
///
@@ -232,7 +236,7 @@ pub struct EventDetails<T: Config> {
// end of everything (fields + topics)
end_idx: usize,
metadata: Metadata,
topics: Vec<T::Hash>,
topics: Vec<HashFor<T>>,
}
impl<T: Config> EventDetails<T> {
@@ -281,7 +285,7 @@ impl<T: Config> EventDetails<T> {
let event_fields_end_idx = all_bytes.len() - input.len();
// topics come after the event data in EventRecord.
let topics = Vec::<T::Hash>::decode(input)?;
let topics = Vec::<HashFor<T>>::decode(input)?;
// what bytes did we skip over in total, including topics.
let end_idx = all_bytes.len() - input.len();
@@ -413,7 +417,7 @@ impl<T: Config> EventDetails<T> {
}
/// Return the topics associated with this event.
pub fn topics(&self) -> &[T::Hash] {
pub fn topics(&self) -> &[HashFor<T>] {
&self.topics
}
}
@@ -430,7 +434,7 @@ pub struct EventMetadataDetails<'a> {
#[cfg(test)]
pub(crate) mod test_utils {
use super::*;
use crate::config::{Config, SubstrateConfig};
use crate::config::{HashFor, SubstrateConfig};
use codec::Encode;
use frame_metadata::{
v15::{
@@ -463,12 +467,12 @@ pub(crate) mod test_utils {
pub struct EventRecord<E: Encode> {
phase: Phase,
event: AllEvents<E>,
topics: Vec<<SubstrateConfig as Config>::Hash>,
topics: Vec<HashFor<SubstrateConfig>>,
}
impl<E: Encode> EventRecord<E> {
/// Create a new event record with the given phase, event, and topics.
pub fn new(phase: Phase, event: E, topics: Vec<<SubstrateConfig as Config>::Hash>) -> Self {
pub fn new(phase: Phase, event: E, topics: Vec<HashFor<SubstrateConfig>>) -> Self {
Self {
phase,
event: AllEvents::Test(event),