From 683b9c14ff853562fee0932684205db20ad94180 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Fri, 9 Jul 2021 15:46:28 +0200 Subject: [PATCH] add [En|De]codable trait for sha256::Hash --- src/consensus/encode.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index a2f5bcf5..cdf4496d 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -34,7 +34,7 @@ use prelude::*; use core::{fmt, mem, u32, convert::From}; #[cfg(feature = "std")] use std::error; -use hashes::{sha256d, Hash}; +use hashes::{sha256d, Hash, sha256}; use hash_types::{BlockHash, FilterHash, TxMerkleNode, FilterHeader}; use io::{self, Cursor, Read}; @@ -756,6 +756,18 @@ impl Decodable for sha256d::Hash { } } +impl Encodable for sha256::Hash { + fn consensus_encode(&self, s: S) -> Result { + self.into_inner().consensus_encode(s) + } +} + +impl Decodable for sha256::Hash { + fn consensus_decode(d: D) -> Result { + Ok(Self::from_inner(<::Inner>::consensus_decode(d)?)) + } +} + // Tests #[cfg(test)] mod tests {