Impl encodable traits for TapLeafhash

This commit is contained in:
sanket1729 2021-10-27 03:17:19 -07:00
parent c7478d8fd0
commit 108fc3d4db
2 changed files with 15 additions and 0 deletions

View File

@ -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<u8>);
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<S: io::Write>(&self, s: S) -> Result<usize, io::Error> {
self.into_inner().consensus_encode(s)
}
}
impl Decodable for TapLeafHash {
fn consensus_decode<D: io::Read>(d: D) -> Result<Self, Error> {
Ok(Self::from_inner(<<Self as Hash>::Inner>::consensus_decode(d)?))
}
}
// Tests
#[cfg(test)]
mod tests {

View File

@ -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 {