From 628800c9e682ca2a52cdd68ad57b489b4a8e745c Mon Sep 17 00:00:00 2001 From: yjhmelody Date: Wed, 15 Nov 2023 15:11:38 +0800 Subject: [PATCH 1/2] improve `substrate-compat` --- subxt/src/config/mod.rs | 43 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index 542ea9874d..d45248ddbf 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -128,51 +128,24 @@ pub trait Header: Sized + Encode + Decode { #[cfg(feature = "substrate-compat")] mod substrate_impls { use super::*; - use primitive_types::{H256, U256}; - impl Header for sp_runtime::generic::Header + impl Header for T where - Self: Encode + Decode, - N: Copy + Into + Into + TryFrom, - H: sp_runtime::traits::Hash + Hasher, + u64: From<::Number>, { - type Number = N; - type Hasher = H; + type Number = T::Number; + type Hasher = T::Hashing; fn number(&self) -> Self::Number { - self.number + *self.number() } } - impl Hasher for sp_core::Blake2Hasher { - type Output = H256; + impl Hasher for T { + type Output = T::Output; fn hash(s: &[u8]) -> Self::Output { - ::hash(s) - } - } - - impl Hasher for sp_runtime::traits::BlakeTwo256 { - 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) - } - } - - impl Hasher for sp_runtime::traits::Keccak256 { - type Output = H256; - - fn hash(s: &[u8]) -> Self::Output { - ::hash(s) + ::hash(s) } } } From dce54bba8e66d123b505cb7b2b3c0fdeb7b039a3 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Tue, 21 Nov 2023 15:59:34 +0000 Subject: [PATCH 2/2] From => Into --- subxt/src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index b83037de4e..32101d9b72 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -132,7 +132,7 @@ mod substrate_impls { impl Header for T where - u64: From<::Number>, + ::Number: Into, { type Number = T::Number; type Hasher = T::Hashing;