diff --git a/core/src/core/block.rs b/core/src/core/block.rs index 002d9cd327..a6b5f9f318 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -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. @@ -140,7 +139,7 @@ impl Readable 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())); } diff --git a/core/src/core/mod.rs b/core/src/core/mod.rs index 6be1e7c1d6..cffccadb2b 100644 --- a/core/src/core/mod.rs +++ b/core/src/core/mod.rs @@ -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}; diff --git a/core/src/core/ser.rs b/core/src/core/ser.rs deleted file mode 100644 index 49a6fae8a0..0000000000 --- a/core/src/core/ser.rs +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2016 The Grin Developers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Binary stream serialization and deserialzation for core types from trusted -//! Write or Read implementations. Issues like starvation or too big sends are -//! expected to be handled upstream. - -use time; - -use std::io::{Write, Read}; -use core::{self, hash}; -use ser::*; - -use secp::Signature; -use secp::key::SecretKey; -use secp::pedersen::{Commitment, RangeProof}; - -pub const MAX_IN_OUT_LEN: u64 = 50000; - -macro_rules! impl_slice_bytes { - ($byteable: ty) => { - impl AsFixedBytes for $byteable { - fn as_fixed_bytes(&self) -> &[u8] { - &self[..] - } - } - } -} - -impl_slice_bytes!(SecretKey); -impl_slice_bytes!(Signature); -impl_slice_bytes!(Commitment); -impl_slice_bytes!(Vec); - -impl AsFixedBytes for hash::Hash { - fn as_fixed_bytes(&self) -> &[u8] { - self.to_slice() - } -} - -impl AsFixedBytes for RangeProof { - fn as_fixed_bytes(&self) -> &[u8] { - &self.bytes() - } -} - diff --git a/core/src/core/transaction.rs b/core/src/core/transaction.rs index 2c615b48a9..777d55741c 100644 --- a/core/src/core/transaction.rs +++ b/core/src/core/transaction.rs @@ -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}; @@ -91,7 +90,7 @@ impl Readable 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())); } diff --git a/core/src/ser.rs b/core/src/ser.rs index a0c9a607a9..2671652192 100644 --- a/core/src/ser.rs +++ b/core/src/ser.rs @@ -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 { @@ -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); + +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() + } +} +