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) + } + } +}