Hash needs to be writeable for network serialization.

This commit is contained in:
Ignotus Peverell 2017-02-06 12:08:35 -08:00
parent 426f4e9d6b
commit dde54beb3f
No known key found for this signature in database
GPG key ID: 99CD25F39F8F8211
3 changed files with 8 additions and 3 deletions

View file

@ -125,7 +125,6 @@ impl Readable<BlockHeader> 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<Input>,
pub outputs: Vec<Output>,

View file

@ -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<Hash> for Hash {
fn read(reader: &mut Reader) -> Result<Hash, ser::Error> {
let v = try!(reader.read_fixed_bytes(32));
@ -62,6 +61,12 @@ impl Readable<Hash> 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,

View file

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