2016-02-05 13:40:41 +01:00
|
|
|
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-01-19 17:02:01 +01:00
|
|
|
#![warn(missing_docs)]
|
2016-02-12 22:01:23 +01:00
|
|
|
#![cfg_attr(feature="dev", feature(plugin))]
|
|
|
|
#![cfg_attr(feature="dev", plugin(clippy))]
|
2016-02-19 11:57:52 +01:00
|
|
|
|
2016-02-15 00:51:50 +01:00
|
|
|
// Clippy settings
|
|
|
|
// TODO [todr] not really sure
|
2016-02-19 11:57:52 +01:00
|
|
|
#![cfg_attr(feature="dev", allow(needless_range_loop))]
|
2016-02-15 00:51:50 +01:00
|
|
|
// Shorter than if-else
|
2016-02-19 11:57:52 +01:00
|
|
|
#![cfg_attr(feature="dev", allow(match_bool))]
|
2016-02-15 00:51:50 +01:00
|
|
|
// We use that to be more explicit about handled cases
|
2016-02-19 11:57:52 +01:00
|
|
|
#![cfg_attr(feature="dev", allow(match_same_arms))]
|
2016-02-15 00:51:50 +01:00
|
|
|
// Keeps consistency (all lines with `.clone()`) and helpful when changing ref to non-ref.
|
2016-02-19 11:57:52 +01:00
|
|
|
#![cfg_attr(feature="dev", allow(clone_on_copy))]
|
2016-03-11 10:57:58 +01:00
|
|
|
// In most cases it expresses function flow better
|
2016-03-11 19:17:09 +01:00
|
|
|
#![cfg_attr(feature="dev", allow(if_not_else))]
|
2016-02-10 12:50:27 +01:00
|
|
|
|
2016-01-17 13:11:25 +01:00
|
|
|
//! Ethcore-util library
|
|
|
|
//!
|
|
|
|
//! ### Rust version:
|
|
|
|
//! - nightly
|
|
|
|
//!
|
|
|
|
//! ### Supported platforms:
|
|
|
|
//! - OSX
|
|
|
|
//! - Linux
|
|
|
|
//!
|
2016-02-01 14:48:38 +01:00
|
|
|
//! ### Building:
|
2016-01-17 13:11:25 +01:00
|
|
|
//!
|
2016-02-01 14:48:38 +01:00
|
|
|
//! - Ubuntu 14.04 and later:
|
2016-01-17 13:11:25 +01:00
|
|
|
//!
|
2016-02-01 14:48:38 +01:00
|
|
|
//! ```bash
|
|
|
|
//! # install rocksdb
|
|
|
|
//! add-apt-repository "deb http://ppa.launchpad.net/giskou/librocksdb/ubuntu trusty main"
|
|
|
|
//! apt-get update
|
|
|
|
//! apt-get install -y --force-yes librocksdb
|
|
|
|
//!
|
|
|
|
//! # install multirust
|
|
|
|
//! curl -sf https://raw.githubusercontent.com/brson/multirust/master/blastoff.sh | sh -s -- --yes
|
|
|
|
//!
|
|
|
|
//! # install nightly and make it default
|
|
|
|
//! multirust update nightly && multirust default nightly
|
|
|
|
//!
|
|
|
|
//! # export rust LIBRARY_PATH
|
|
|
|
//! export LIBRARY_PATH=/usr/local/lib
|
|
|
|
//!
|
|
|
|
//! # download and build parity
|
|
|
|
//! git clone https://github.com/ethcore/parity
|
|
|
|
//! cd parity
|
|
|
|
//! cargo build --release
|
|
|
|
//! ```
|
2016-02-09 16:47:21 +01:00
|
|
|
//!
|
2016-01-17 13:11:25 +01:00
|
|
|
//! - OSX:
|
|
|
|
//!
|
|
|
|
//! ```bash
|
2016-02-01 14:48:38 +01:00
|
|
|
//! # install rocksdb && multirust
|
|
|
|
//! brew update
|
2016-01-17 13:11:25 +01:00
|
|
|
//! brew install rocksdb
|
2016-02-01 14:48:38 +01:00
|
|
|
//! brew install multirust
|
2016-01-17 13:11:25 +01:00
|
|
|
//!
|
2016-02-01 14:48:38 +01:00
|
|
|
//! # install nightly and make it default
|
|
|
|
//! multirust update nightly && multirust default nightly
|
2016-01-17 13:11:25 +01:00
|
|
|
//!
|
2016-02-01 14:48:38 +01:00
|
|
|
//! # export rust LIBRARY_PATH
|
|
|
|
//! export LIBRARY_PATH=/usr/local/lib
|
|
|
|
//!
|
|
|
|
//! # download and build parity
|
|
|
|
//! git clone https://github.com/ethcore/parity
|
|
|
|
//! cd parity
|
|
|
|
//! cargo build --release
|
2016-01-17 13:11:25 +01:00
|
|
|
//! ```
|
|
|
|
|
|
|
|
extern crate slab;
|
|
|
|
extern crate rustc_serialize;
|
|
|
|
extern crate mio;
|
|
|
|
extern crate rand;
|
|
|
|
extern crate rocksdb;
|
|
|
|
extern crate tiny_keccak;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate heapsize;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate lazy_static;
|
|
|
|
#[macro_use]
|
|
|
|
extern crate itertools;
|
|
|
|
extern crate env_logger;
|
|
|
|
extern crate time;
|
|
|
|
extern crate crypto as rcrypto;
|
|
|
|
extern crate secp256k1;
|
|
|
|
extern crate arrayvec;
|
|
|
|
extern crate elastic_array;
|
2016-01-21 16:48:37 +01:00
|
|
|
extern crate crossbeam;
|
2016-01-26 19:24:33 +01:00
|
|
|
extern crate serde;
|
2016-01-29 15:01:39 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log as rlog;
|
2016-02-10 18:11:10 +01:00
|
|
|
extern crate igd;
|
2016-02-19 15:18:20 +01:00
|
|
|
extern crate ethcore_devtools as devtools;
|
2016-02-16 02:05:36 +01:00
|
|
|
extern crate libc;
|
2016-02-22 09:04:44 +01:00
|
|
|
extern crate target_info;
|
2016-02-29 22:21:15 +01:00
|
|
|
extern crate bigint;
|
2016-03-04 14:23:00 +01:00
|
|
|
extern crate chrono;
|
2016-01-17 13:11:25 +01:00
|
|
|
|
|
|
|
pub mod standard;
|
|
|
|
#[macro_use]
|
|
|
|
pub mod from_json;
|
|
|
|
#[macro_use]
|
|
|
|
pub mod common;
|
2016-02-29 22:21:15 +01:00
|
|
|
pub mod numbers;
|
2016-01-17 13:11:25 +01:00
|
|
|
pub mod error;
|
|
|
|
pub mod hash;
|
|
|
|
pub mod bytes;
|
|
|
|
pub mod rlp;
|
|
|
|
pub mod misc;
|
2016-03-24 08:49:54 +01:00
|
|
|
pub mod using_queue;
|
2016-02-01 15:22:42 +01:00
|
|
|
mod json_aid;
|
2016-01-17 13:11:25 +01:00
|
|
|
pub mod vector;
|
|
|
|
pub mod sha3;
|
|
|
|
pub mod hashdb;
|
|
|
|
pub mod memorydb;
|
|
|
|
pub mod overlaydb;
|
2016-01-18 12:41:31 +01:00
|
|
|
pub mod journaldb;
|
2016-02-18 03:46:24 +01:00
|
|
|
pub mod kvdb;
|
2016-02-01 15:22:42 +01:00
|
|
|
mod math;
|
2016-01-17 13:11:25 +01:00
|
|
|
pub mod crypto;
|
|
|
|
pub mod triehash;
|
|
|
|
pub mod trie;
|
|
|
|
pub mod nibbleslice;
|
2016-02-01 14:48:38 +01:00
|
|
|
mod heapsizeof;
|
2016-01-17 13:11:25 +01:00
|
|
|
pub mod squeeze;
|
|
|
|
pub mod semantic_version;
|
|
|
|
pub mod io;
|
|
|
|
pub mod network;
|
2016-01-29 15:01:39 +01:00
|
|
|
pub mod log;
|
2016-02-09 16:47:21 +01:00
|
|
|
pub mod panics;
|
2016-02-15 16:01:52 +01:00
|
|
|
pub mod keys;
|
2016-02-18 19:30:58 +01:00
|
|
|
pub mod table;
|
2016-04-21 19:19:42 +02:00
|
|
|
pub mod network_settings;
|
2016-01-17 13:11:25 +01:00
|
|
|
|
|
|
|
pub use common::*;
|
|
|
|
pub use misc::*;
|
2016-03-24 08:49:54 +01:00
|
|
|
pub use using_queue::*;
|
2016-01-17 13:11:25 +01:00
|
|
|
pub use json_aid::*;
|
|
|
|
pub use rlp::*;
|
|
|
|
pub use hashdb::*;
|
|
|
|
pub use memorydb::*;
|
|
|
|
pub use overlaydb::*;
|
2016-03-11 14:45:19 +01:00
|
|
|
pub use journaldb::JournalDB;
|
2016-01-17 13:11:25 +01:00
|
|
|
pub use math::*;
|
|
|
|
pub use crypto::*;
|
|
|
|
pub use triehash::*;
|
|
|
|
pub use trie::*;
|
|
|
|
pub use nibbleslice::*;
|
|
|
|
pub use squeeze::*;
|
|
|
|
pub use semantic_version::*;
|
|
|
|
pub use network::*;
|
|
|
|
pub use io::*;
|
2016-01-29 15:01:39 +01:00
|
|
|
pub use log::*;
|
2016-02-18 03:46:24 +01:00
|
|
|
pub use kvdb::*;
|
2016-02-15 16:01:52 +01:00
|
|
|
|
2016-03-07 16:26:35 +01:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::numbers::*;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn u256_multi_muls() {
|
|
|
|
|
|
|
|
let (result, _) = U256([0, 0, 0, 0]).overflowing_mul(U256([0, 0, 0, 0]));
|
|
|
|
assert_eq!(U256([0, 0, 0, 0]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([1, 0, 0, 0]).overflowing_mul(U256([1, 0, 0, 0]));
|
|
|
|
assert_eq!(U256([1, 0, 0, 0]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([5, 0, 0, 0]).overflowing_mul(U256([5, 0, 0, 0]));
|
|
|
|
assert_eq!(U256([25, 0, 0, 0]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([0, 5, 0, 0]).overflowing_mul(U256([0, 5, 0, 0]));
|
|
|
|
assert_eq!(U256([0, 0, 25, 0]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([0, 0, 0, 1]).overflowing_mul(U256([1, 0, 0, 0]));
|
|
|
|
assert_eq!(U256([0, 0, 0, 1]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([0, 0, 0, 5]).overflowing_mul(U256([2, 0, 0, 0]));
|
|
|
|
assert_eq!(U256([0, 0, 0, 10]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([0, 0, 1, 0]).overflowing_mul(U256([0, 5, 0, 0]));
|
|
|
|
assert_eq!(U256([0, 0, 0, 5]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([0, 0, 8, 0]).overflowing_mul(U256([0, 0, 7, 0]));
|
|
|
|
assert_eq!(U256([0, 0, 0, 0]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([2, 0, 0, 0]).overflowing_mul(U256([0, 5, 0, 0]));
|
|
|
|
assert_eq!(U256([0, 10, 0, 0]), result);
|
|
|
|
|
|
|
|
let (result, _) = U256([1, 0, 0, 0]).overflowing_mul(U256([0, 0, 0, ::std::u64::MAX]));
|
|
|
|
assert_eq!(U256([0, 0, 0, ::std::u64::MAX]), result);
|
|
|
|
|
|
|
|
let x1 = U256::from_str("0000000000000000000000000000000000000000000000000000012365124623").unwrap();
|
|
|
|
let x2sqr_right = U256::from_str("000000000000000000000000000000000000000000014baeef72e0378e2328c9").unwrap();
|
|
|
|
let x1sqr = x1 * x1;
|
|
|
|
assert_eq!(H256::from(x2sqr_right), H256::from(x1sqr));
|
|
|
|
let x1cube = x1sqr * x1;
|
|
|
|
let x1cube_right = U256::from_str("0000000000000000000000000000000001798acde139361466f712813717897b").unwrap();
|
|
|
|
assert_eq!(H256::from(x1cube_right), H256::from(x1cube));
|
|
|
|
let x1quad = x1cube * x1;
|
|
|
|
let x1quad_right = U256::from_str("000000000000000000000001adbdd6bd6ff027485484b97f8a6a4c7129756dd1").unwrap();
|
|
|
|
assert_eq!(H256::from(x1quad_right), H256::from(x1quad));
|
|
|
|
let x1penta = x1quad * x1;
|
|
|
|
let x1penta_right = U256::from_str("00000000000001e92875ac24be246e1c57e0507e8c46cc8d233b77f6f4c72993").unwrap();
|
|
|
|
assert_eq!(H256::from(x1penta_right), H256::from(x1penta));
|
|
|
|
let x1septima = x1penta * x1;
|
|
|
|
let x1septima_right = U256::from_str("00022cca1da3f6e5722b7d3cc5bbfb486465ebc5a708dd293042f932d7eee119").unwrap();
|
|
|
|
assert_eq!(H256::from(x1septima_right), H256::from(x1septima));
|
|
|
|
}
|
|
|
|
}
|