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
@@ -16,7 +16,6 @@ use subxt::{
client::OnlineClient,
config::{Config, Hasher},
utils::AccountId32,
SubstrateConfig,
};
use subxt_rpcs::methods::chain_head::{
ArchiveStorageEventItem, Bytes, StorageQuery, StorageQueryType,
@@ -178,6 +177,7 @@ async fn archive_v1_storage() {
let ctx = test_context().await;
let rpc = ctx.chainhead_rpc_methods().await;
let api = ctx.client();
let hasher = api.hasher();
let mut blocks = fetch_finalized_blocks(&ctx, 3).await;
while let Some(block) = blocks.next().await {
@@ -236,9 +236,7 @@ async fn archive_v1_storage() {
ArchiveStorageEventItem {
key: Bytes(account_info_addr),
value: None,
hash: Some(<SubstrateConfig as Config>::Hasher::hash(
&subxt_account_info
)),
hash: Some(hasher.hash(&subxt_account_info)),
closest_descendant_merkle_value: None,
child_trie_key: None
}
@@ -15,7 +15,6 @@ use futures::Stream;
use subxt::{
config::Hasher,
utils::{AccountId32, MultiAddress},
SubstrateConfig,
};
use subxt_rpcs::methods::chain_head::{
FollowEvent, Initialized, MethodResponse, RuntimeEvent, RuntimeVersionEvent, StorageQuery,
@@ -329,6 +328,7 @@ async fn transaction_v1_broadcast() {
let ctx = test_context().await;
let api = ctx.client();
let hasher = api.hasher();
let rpc = ctx.chainhead_rpc_methods().await;
let tx_payload = node_runtime::tx()
@@ -374,7 +374,7 @@ async fn transaction_v1_broadcast() {
let Some(ext) = block_extrinsics
.iter()
.find(|ext| <SubstrateConfig as subxt::Config>::Hasher::hash(ext.bytes()) == tx_hash)
.find(|ext| hasher.hash(ext.bytes()) == tx_hash)
else {
continue;
};
@@ -12,7 +12,12 @@ use crate::{
subxt_test, test_context, TestClient, TestConfig, TestContext,
};
use subxt::ext::futures::StreamExt;
use subxt::{tx::TxProgress, utils::MultiAddress, Config, Error};
use subxt::{
config::{Config, HashFor},
tx::TxProgress,
utils::MultiAddress,
Error,
};
use subxt_signer::sr25519::{self, dev};
struct ContractsTestContext {
@@ -20,7 +25,7 @@ struct ContractsTestContext {
signer: sr25519::Keypair,
}
type Hash = <TestConfig as Config>::Hash;
type Hash = HashFor<TestConfig>;
type AccountId = <TestConfig as Config>::AccountId;
/// A dummy contract which does nothing at all.