Skip to content

Commit 108fc3d

Browse files
committed
Impl encodable traits for TapLeafhash
1 parent c7478d8 commit 108fc3d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/consensus/encode.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use io::{self, Cursor, Read};
3939

4040
use util::endian;
4141
use util::psbt;
42+
use util::taproot::TapLeafHash;
4243
use hashes::hex::ToHex;
4344

4445
use blockdata::transaction::{TxOut, Transaction, TxIn};
@@ -594,6 +595,7 @@ impl_vec!(TxOut);
594595
impl_vec!(TxIn);
595596
impl_vec!(Vec<u8>);
596597
impl_vec!(u64);
598+
impl_vec!(TapLeafHash);
597599

598600
#[cfg(feature = "std")] impl_vec!(Inventory);
599601
#[cfg(feature = "std")] impl_vec!((u32, Address));
@@ -767,6 +769,18 @@ impl Decodable for sha256::Hash {
767769
}
768770
}
769771

772+
impl Encodable for TapLeafHash {
773+
fn consensus_encode<S: io::Write>(&self, s: S) -> Result<usize, io::Error> {
774+
self.into_inner().consensus_encode(s)
775+
}
776+
}
777+
778+
impl Decodable for TapLeafHash {
779+
fn consensus_decode<D: io::Read>(d: D) -> Result<Self, Error> {
780+
Ok(Self::from_inner(<<Self as Hash>::Inner>::consensus_decode(d)?))
781+
}
782+
}
783+
770784
// Tests
771785
#[cfg(test)]
772786
mod tests {

src/util/taproot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ macro_rules! sha256t_hash_newtype {
6868
#[doc = "The tag used for ["]
6969
#[doc = $sname]
7070
#[doc = "]"]
71+
#[derive(Copy, Clone, PartialEq, Eq, Default, PartialOrd, Ord, Hash)]
7172
pub struct $tag;
7273

7374
impl sha256t::Tag for $tag {

0 commit comments

Comments
 (0)