mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Hash needs to be writeable for network serialization.
This commit is contained in:
parent
426f4e9d6b
commit
dde54beb3f
3 changed files with 8 additions and 3 deletions
|
@ -125,7 +125,6 @@ impl Readable<BlockHeader> for BlockHeader {
|
||||||
/// bitcoin's schedule) and expressed as a global transaction fee (added v.H),
|
/// bitcoin's schedule) and expressed as a global transaction fee (added v.H),
|
||||||
/// additive to the total of fees ever collected.
|
/// additive to the total of fees ever collected.
|
||||||
pub struct Block {
|
pub struct Block {
|
||||||
// hash_mem: Hash,
|
|
||||||
pub header: BlockHeader,
|
pub header: BlockHeader,
|
||||||
pub inputs: Vec<Input>,
|
pub inputs: Vec<Input>,
|
||||||
pub outputs: Vec<Output>,
|
pub outputs: Vec<Output>,
|
||||||
|
|
|
@ -21,7 +21,7 @@ use byteorder::{ByteOrder, BigEndian};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use tiny_keccak::Keccak;
|
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]);
|
pub const ZERO_HASH: Hash = Hash([0; 32]);
|
||||||
|
|
||||||
|
@ -50,7 +50,6 @@ impl Hash {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Readable<Hash> for Hash {
|
impl Readable<Hash> for Hash {
|
||||||
fn read(reader: &mut Reader) -> Result<Hash, ser::Error> {
|
fn read(reader: &mut Reader) -> Result<Hash, ser::Error> {
|
||||||
let v = try!(reader.read_fixed_bytes(32));
|
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
|
/// Serializer that outputs a hash of the serialized object
|
||||||
pub struct HashWriter {
|
pub struct HashWriter {
|
||||||
state: Keccak,
|
state: Keccak,
|
||||||
|
|
|
@ -327,6 +327,7 @@ impl_slice_bytes!([u8; 1]);
|
||||||
impl_slice_bytes!([u8; 2]);
|
impl_slice_bytes!([u8; 2]);
|
||||||
impl_slice_bytes!([u8; 4]);
|
impl_slice_bytes!([u8; 4]);
|
||||||
impl_slice_bytes!([u8; 8]);
|
impl_slice_bytes!([u8; 8]);
|
||||||
|
impl_slice_bytes!([u8; 32]);
|
||||||
|
|
||||||
impl<'a> AsFixedBytes for &'a [u8] {
|
impl<'a> AsFixedBytes for &'a [u8] {
|
||||||
fn as_fixed_bytes(&self) -> &[u8] {
|
fn as_fixed_bytes(&self) -> &[u8] {
|
||||||
|
|
Loading…
Reference in a new issue