From b7c5d768ce98ecbd46276609ea25cb2d5bfb2ff5 Mon Sep 17 00:00:00 2001 From: Tadeo Hepperle <62739623+tadeohepperle@users.noreply.github.com> Date: Thu, 27 Apr 2023 17:00:11 +0200 Subject: [PATCH] impl Header and Hasher for some substrate types behind the "substrate-compat" feature flag (#934) * impl Header and Hasher * qualify trait differently --- subxt/src/config/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/subxt/src/config/mod.rs b/subxt/src/config/mod.rs index 9652cca48c..8d3cddd6cc 100644 --- a/subxt/src/config/mod.rs +++ b/subxt/src/config/mod.rs @@ -120,3 +120,40 @@ 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 super::*; + use primitive_types::{H256, U256}; + + 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) + } + } +}