From 8739c8c8fefa0fb566137c0728052c2f3fae2ac5 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Wed, 26 Apr 2023 19:11:37 +0200 Subject: [PATCH 1/2] impl Header and Hasher --- subxt/src/config/mod.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index 9652cca48c..c35d2f6887 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -120,3 +120,42 @@ impl> Config type Header = T::Header; type ExtrinsicParams = E; } + +/// implement subxt's Hasher and Header traits for some substrate structs +#[cfg(feature = "substrate-compat")] +mod substrate_impls { + use primitive_types::{H256, U256}; + use sp_core::Hasher as SpHasher; + + use super::*; + + impl Header for sp_runtime::generic::Header + where + Self: Encode, + N: Copy + Into + Into + TryFrom, + H: sp_runtime::traits::Hash + Hasher, + { + type Number = N; + type Hasher = H; + + fn number(&self) -> Self::Number { + self.number + } + } + + impl Hasher for sp_core::Blake2Hasher { + type Output = H256; + + fn hash(s: &[u8]) -> Self::Output { + ::hash(s) + } + } + + impl Hasher for sp_core::KeccakHasher { + type Output = H256; + + fn hash(s: &[u8]) -> Self::Output { + ::hash(s) + } + } +} From 9ba17c3fad392b0338c4d0edd120b01b74abebaf Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Wed, 26 Apr 2023 19:15:19 +0200 Subject: [PATCH 2/2] qualify trait differently --- subxt/src/config/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index c35d2f6887..8d3cddd6cc 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -124,10 +124,8 @@ impl> Config /// implement subxt's Hasher and Header traits for some substrate structs #[cfg(feature = "substrate-compat")] mod substrate_impls { - use primitive_types::{H256, U256}; - use sp_core::Hasher as SpHasher; - use super::*; + use primitive_types::{H256, U256}; impl Header for sp_runtime::generic::Header where @@ -147,7 +145,7 @@ mod substrate_impls { type Output = H256; fn hash(s: &[u8]) -> Self::Output { - ::hash(s) + ::hash(s) } } @@ -155,7 +153,7 @@ mod substrate_impls { type Output = H256; fn hash(s: &[u8]) -> Self::Output { - ::hash(s) + ::hash(s) } } }