From dde54beb3ff015eb903ecc7e9016abafbea671bf Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Mon, 6 Feb 2017 12:08:35 -0800 Subject: [PATCH] Hash needs to be writeable for network serialization. --- core/src/core/block.rs | 1 - core/src/core/hash.rs | 9 +++++++-- core/src/ser.rs | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/src/core/block.rs b/core/src/core/block.rs index afdea2289..647c6dde8 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -125,7 +125,6 @@ impl Readable for BlockHeader { /// bitcoin's schedule) and expressed as a global transaction fee (added v.H), /// additive to the total of fees ever collected. pub struct Block { - // hash_mem: Hash, pub header: BlockHeader, pub inputs: Vec, pub outputs: Vec, diff --git a/core/src/core/hash.rs b/core/src/core/hash.rs index 7987e7803..440c350ee 100644 --- a/core/src/core/hash.rs +++ b/core/src/core/hash.rs @@ -21,7 +21,7 @@ use byteorder::{ByteOrder, BigEndian}; use std::fmt; use tiny_keccak::Keccak; -use ser::{self, AsFixedBytes, Reader, Readable, Error}; +use ser::{self, AsFixedBytes, Reader, Readable, Writer, Writeable, Error}; pub const ZERO_HASH: Hash = Hash([0; 32]); @@ -50,7 +50,6 @@ impl Hash { } } - impl Readable for Hash { fn read(reader: &mut Reader) -> Result { let v = try!(reader.read_fixed_bytes(32)); @@ -62,6 +61,12 @@ impl Readable for Hash { } } +impl Writeable for Hash { + fn write(&self, writer: &mut Writer) -> Result<(), Error> { + writer.write_fixed_bytes(&self.0) + } +} + /// Serializer that outputs a hash of the serialized object pub struct HashWriter { state: Keccak, diff --git a/core/src/ser.rs b/core/src/ser.rs index 2c0be6017..f3ad6a0b6 100644 --- a/core/src/ser.rs +++ b/core/src/ser.rs @@ -327,6 +327,7 @@ impl_slice_bytes!([u8; 1]); impl_slice_bytes!([u8; 2]); impl_slice_bytes!([u8; 4]); impl_slice_bytes!([u8; 8]); +impl_slice_bytes!([u8; 32]); impl<'a> AsFixedBytes for &'a [u8] { fn as_fixed_bytes(&self) -> &[u8] {