add [En|De]codable trait for sha256::Hash

This commit is contained in:
Riccardo Casatta 2021-07-09 15:46:28 +02:00
parent df4d70a37e
commit 683b9c14ff
No known key found for this signature in database
GPG Key ID: FD986A969E450397
1 changed files with 13 additions and 1 deletions

View File

@ -34,7 +34,7 @@ use prelude::*;
use core::{fmt, mem, u32, convert::From}; use core::{fmt, mem, u32, convert::From};
#[cfg(feature = "std")] use std::error; #[cfg(feature = "std")] use std::error;
use hashes::{sha256d, Hash}; use hashes::{sha256d, Hash, sha256};
use hash_types::{BlockHash, FilterHash, TxMerkleNode, FilterHeader}; use hash_types::{BlockHash, FilterHash, TxMerkleNode, FilterHeader};
use io::{self, Cursor, Read}; use io::{self, Cursor, Read};
@ -756,6 +756,18 @@ impl Decodable for sha256d::Hash {
} }
} }
impl Encodable for sha256::Hash {
fn consensus_encode<S: io::Write>(&self, s: S) -> Result<usize, io::Error> {
self.into_inner().consensus_encode(s)
}
}
impl Decodable for sha256::Hash {
fn consensus_decode<D: io::Read>(d: D) -> Result<Self, Error> {
Ok(Self::from_inner(<<Self as Hash>::Inner>::consensus_decode(d)?))
}
}
// Tests // Tests
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {