From 108fc3d4dbfa36531016d2357f9ab5914bb4b2d1 Mon Sep 17 00:00:00 2001 From: sanket1729 Date: Wed, 27 Oct 2021 03:17:19 -0700 Subject: [PATCH] Impl encodable traits for TapLeafhash --- src/consensus/encode.rs | 14 ++++++++++++++ src/util/taproot.rs | 1 + 2 files changed, 15 insertions(+) diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index eea64036..ec2aa198 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -39,6 +39,7 @@ use io::{self, Cursor, Read}; use util::endian; use util::psbt; +use util::taproot::TapLeafHash; use hashes::hex::ToHex; use blockdata::transaction::{TxOut, Transaction, TxIn}; @@ -594,6 +595,7 @@ impl_vec!(TxOut); impl_vec!(TxIn); impl_vec!(Vec); impl_vec!(u64); +impl_vec!(TapLeafHash); #[cfg(feature = "std")] impl_vec!(Inventory); #[cfg(feature = "std")] impl_vec!((u32, Address)); @@ -767,6 +769,18 @@ impl Decodable for sha256::Hash { } } +impl Encodable for TapLeafHash { + fn consensus_encode(&self, s: S) -> Result { + self.into_inner().consensus_encode(s) + } +} + +impl Decodable for TapLeafHash { + fn consensus_decode(d: D) -> Result { + Ok(Self::from_inner(<::Inner>::consensus_decode(d)?)) + } +} + // Tests #[cfg(test)] mod tests { diff --git a/src/util/taproot.rs b/src/util/taproot.rs index 1a824dfc..ad1baa62 100644 --- a/src/util/taproot.rs +++ b/src/util/taproot.rs @@ -68,6 +68,7 @@ macro_rules! sha256t_hash_newtype { #[doc = "The tag used for ["] #[doc = $sname] #[doc = "]"] + #[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)] pub struct $tag; impl sha256t::Tag for $tag {