From 24e19b1e0feae0fea5c41d48e670ca9293da1c36 Mon Sep 17 00:00:00 2001 From: yjh Date: Sat, 25 Nov 2023 00:24:09 +0800 Subject: [PATCH] improve `substrate-compat` (#1265) * improve `substrate-compat` * From => Into --------- Co-authored-by: James Wilson --- 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 bd7fd3ec39..32101d9b72 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -129,51 +129,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, + ::Number: Into, { - 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) } } }