add [En|De]codable trait for sha256::Hash
This commit is contained in:
parent
df4d70a37e
commit
683b9c14ff
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue