Skip to content

Commit

Permalink
core: move remaining contents of core/ser.rs into ser.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
merope07 committed Oct 23, 2016
1 parent 8b1c4eb commit afc5b9d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 62 deletions.
3 changes: 1 addition & 2 deletions core/src/core/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use core::{Input, Output, Proof, TxProof, Transaction};
use core::transaction::merkle_inputs_outputs;
use core::{PROOFSIZE, REWARD};
use core::hash::{Hash, Hashed, ZERO_HASH};
use core::ser::MAX_IN_OUT_LEN;
use ser::{self, Readable, Reader, Writeable, Writer, ser_vec};

/// Block header, fairly standard compared to other blockchains.
Expand Down Expand Up @@ -140,7 +139,7 @@ impl Readable<Block> for Block {
let input_len = try!(reader.read_u64());
let output_len = try!(reader.read_u64());
let proof_len = try!(reader.read_u64());
if input_len > MAX_IN_OUT_LEN || output_len > MAX_IN_OUT_LEN || proof_len > MAX_IN_OUT_LEN {
if input_len > ser::MAX_IN_OUT_LEN || output_len > ser::MAX_IN_OUT_LEN || proof_len > ser::MAX_IN_OUT_LEN {
return Err(ser::Error::TooLargeReadErr("Too many inputs, outputs or proofs.".to_string()));
}

Expand Down
1 change: 0 additions & 1 deletion core/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub mod hash;
pub mod transaction;
#[allow(dead_code)]
#[macro_use]
mod ser;

pub use self::block::{Block, BlockHeader};
pub use self::transaction::{Transaction, Input, Output, TxProof};
Expand Down
57 changes: 0 additions & 57 deletions core/src/core/ser.rs

This file was deleted.

3 changes: 1 addition & 2 deletions core/src/core/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use core::Committed;
use core::MerkleRow;
use core::hash::{Hashed, Hash};
use core::ser::MAX_IN_OUT_LEN;
use ser::{self, Reader, Writer, Readable, Writeable};

use secp::{self, Secp256k1, Message, Signature};
Expand Down Expand Up @@ -91,7 +90,7 @@ impl Readable<Transaction> for Transaction {
let output_len = try!(reader.read_u64());

// in case a facetious miner sends us more than what we can allocate
if input_len > MAX_IN_OUT_LEN || output_len > MAX_IN_OUT_LEN {
if input_len > ser::MAX_IN_OUT_LEN || output_len > ser::MAX_IN_OUT_LEN {
return Err(ser::Error::TooLargeReadErr("Too many inputs or outputs.".to_string()));
}

Expand Down
31 changes: 31 additions & 0 deletions core/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ use std::io;
use std::io::{Write, Read};
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};

/// Maximum number of inputs or outputs in a transaction
pub const MAX_IN_OUT_LEN: u64 = 50000;

/// Possible errors deriving from serializing or deserializing.
#[derive(Debug)]
pub enum Error {
Expand Down Expand Up @@ -170,3 +173,31 @@ impl<'a> Writer for BinWriter<'a> {
self.sink.write_all(bs).err().map(Error::IOErr)
}
}

macro_rules! impl_slice_bytes {
($byteable: ty) => {
impl AsFixedBytes for $byteable {
fn as_fixed_bytes(&self) -> &[u8] {
&self[..]
}
}
}
}

impl_slice_bytes!(::secp::key::SecretKey);
impl_slice_bytes!(::secp::Signature);
impl_slice_bytes!(::secp::pedersen::Commitment);
impl_slice_bytes!(Vec<u8>);

impl AsFixedBytes for ::core::hash::Hash {
fn as_fixed_bytes(&self) -> &[u8] {
self.to_slice()
}
}

impl AsFixedBytes for ::secp::pedersen::RangeProof {
fn as_fixed_bytes(&self) -> &[u8] {
&self.bytes()
}
}

0 comments on commit afc5b9d

Please sign in to comment.