From 29531ae72fc6869846ad24eb1a7295322208c52a Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Fri, 6 May 2016 17:16:03 +0400 Subject: [PATCH] binary for blockstatus, blockchaininfo --- Cargo.lock | 1 + ethcore/Cargo.toml | 1 + ethcore/src/lib.rs | 1 + ethcore/src/types/block_status.rs | 5 ++++- ethcore/src/types/blockchain_info.rs | 7 +++++-- util/bigint/src/uint.rs | 8 ++++---- util/src/hash.rs | 4 ++-- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1cd8383d8..df305aa8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -240,6 +240,7 @@ dependencies = [ "env_logger 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.2.0", "ethcore-devtools 1.2.0", + "ethcore-ipc 1.2.0", "ethcore-ipc-codegen 1.2.0", "ethcore-util 1.2.0", "ethjson 0.1.0", diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index 1b581959d..d0b1927f6 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -28,6 +28,7 @@ lazy_static = "0.1" ethcore-devtools = { path = "../devtools" } ethjson = { path = "../json" } bloomchain = "0.1" +"ethcore-ipc" = { path = "../ipc/rpc" } [features] jit = ["evmjit"] diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index b18efa54d..949b4100d 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -85,6 +85,7 @@ extern crate num_cpus; extern crate crossbeam; extern crate ethjson; extern crate bloomchain; +extern crate ethcore_ipc as ipc; #[cfg(test)] extern crate ethcore_devtools as devtools; #[cfg(feature = "jit" )] extern crate evmjit; diff --git a/ethcore/src/types/block_status.rs b/ethcore/src/types/block_status.rs index 60776748c..ca0f47227 100644 --- a/ethcore/src/types/block_status.rs +++ b/ethcore/src/types/block_status.rs @@ -16,8 +16,11 @@ //! Block status description module +use ipc::binary::BinaryConvertError; +use std::collections::VecDeque; + /// General block status -#[derive(Debug, Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq, Binary)] pub enum BlockStatus { /// Part of the blockchain. InChain, diff --git a/ethcore/src/types/blockchain_info.rs b/ethcore/src/types/blockchain_info.rs index aacf77baf..076225b27 100644 --- a/ethcore/src/types/blockchain_info.rs +++ b/ethcore/src/types/blockchain_info.rs @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -use util::*; +use util::numbers::*; use header::BlockNumber; +use ipc::binary::BinaryConvertError; +use std::mem; +use std::collections::VecDeque; /// Information about the blockchain gathered together. -#[derive(Debug)] +#[derive(Debug, Binary)] pub struct BlockChainInfo { /// Blockchain difficulty. pub total_difficulty: U256, diff --git a/util/bigint/src/uint.rs b/util/bigint/src/uint.rs index be9941589..f87b494a9 100644 --- a/util/bigint/src/uint.rs +++ b/util/bigint/src/uint.rs @@ -517,7 +517,7 @@ pub trait Uint: Sized + Default + FromStr + From + fmt::Debug + fmt::Displa /// Return single byte fn byte(&self, index: usize) -> u8; /// Get this Uint as slice of bytes - fn to_bytes(&self, bytes: &mut[u8]); + fn to_raw_bytes(&self, bytes: &mut[u8]); /// Create `Uint(10**n)` fn exp10(n: usize) -> Self; @@ -621,7 +621,7 @@ macro_rules! construct_uint { (arr[index / 8] >> (((index % 8)) * 8)) as u8 } - fn to_bytes(&self, bytes: &mut[u8]) { + fn to_raw_bytes(&self, bytes: &mut[u8]) { assert!($n_words * 8 == bytes.len()); let &$name(ref arr) = self; for i in 0..bytes.len() { @@ -780,7 +780,7 @@ macro_rules! construct_uint { where S: serde::Serializer { let mut hex = "0x".to_owned(); let mut bytes = [0u8; 8 * $n_words]; - self.to_bytes(&mut bytes); + self.to_raw_bytes(&mut bytes); let len = cmp::max((self.bits() + 7) / 8, 1); hex.push_str(bytes[bytes.len() - len..].to_hex().as_ref()); serializer.serialize_str(hex.as_ref()) @@ -1482,7 +1482,7 @@ mod tests { let hex = "8090a0b0c0d0e0f00910203040506077583a2cf8264910e1436bda32571012f0"; let uint = U256::from_str(hex).unwrap(); let mut bytes = [0u8; 32]; - uint.to_bytes(&mut bytes); + uint.to_raw_bytes(&mut bytes); let uint2 = U256::from(&bytes[..]); assert_eq!(uint, uint2); } diff --git a/util/src/hash.rs b/util/src/hash.rs index 69ed17c79..e1b82b14c 100644 --- a/util/src/hash.rs +++ b/util/src/hash.rs @@ -517,7 +517,7 @@ impl From for H256 { fn from(value: U256) -> H256 { unsafe { let mut ret: H256 = ::std::mem::uninitialized(); - value.to_bytes(&mut ret); + value.to_raw_bytes(&mut ret); ret } } @@ -527,7 +527,7 @@ impl<'_> From<&'_ U256> for H256 { fn from(value: &'_ U256) -> H256 { unsafe { let mut ret: H256 = ::std::mem::uninitialized(); - value.to_bytes(&mut ret); + value.to_raw_bytes(&mut ret); ret } }