Skip to content

Commit

Permalink
impl Header and Hasher for some substrate types behind the "substrate…
Browse files Browse the repository at this point in the history
…-compat" feature flag (#934)

* impl Header and Hasher

* qualify trait differently
  • Loading branch information
tadeohepperle authored Apr 27, 2023
1 parent 40339b3 commit b7c5d76
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions subxt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,40 @@ impl<T: Config, E: extrinsic_params::ExtrinsicParams<T::Index, T::Hash>> 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<N, H> Header for sp_runtime::generic::Header<N, H>
where
Self: Encode,
N: Copy + Into<U256> + Into<u64> + TryFrom<U256>,
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 {
<Self as sp_core::Hasher>::hash(s)
}
}

impl Hasher for sp_core::KeccakHasher {
type Output = H256;

fn hash(s: &[u8]) -> Self::Output {
<Self as sp_core::Hasher>::hash(s)
}
}
}

0 comments on commit b7c5d76

Please sign in to comment.