Merge branch 'master' into mining

This commit is contained in:
Gav Wood
2016-03-02 00:59:39 +01:00
35 changed files with 343 additions and 185 deletions

View File

@@ -19,10 +19,9 @@
pub use standard::*;
pub use from_json::*;
pub use error::*;
pub use hash::*;
pub use uint::*;
pub use bytes::*;
pub use vector::*;
pub use numbers::*;
pub use sha3::*;
#[macro_export]

View File

@@ -16,9 +16,8 @@
//! Ethcore crypto.
use hash::*;
use numbers::*;
use bytes::*;
use uint::*;
use secp256k1::{key, Secp256k1};
use rand::os::OsRng;
@@ -151,8 +150,7 @@ impl KeyPair {
/// EC functions
pub mod ec {
use hash::*;
use uint::*;
use numbers::*;
use standard::*;
use crypto::*;
use crypto::{self};

View File

@@ -17,6 +17,7 @@
//! Coversion from json.
use standard::*;
use bigint::uint::*;
#[macro_export]
macro_rules! xjson {
@@ -30,3 +31,20 @@ pub trait FromJson {
/// Convert a JSON value to an instance of this type.
fn from_json(json: &Json) -> Self;
}
impl FromJson for U256 {
fn from_json(json: &Json) -> Self {
match *json {
Json::String(ref s) => {
if s.len() >= 2 && &s[0..2] == "0x" {
FromStr::from_str(&s[2..]).unwrap_or_else(|_| Default::default())
} else {
Uint::from_dec_str(s).unwrap_or_else(|_| Default::default())
}
},
Json::U64(u) => From::from(u),
Json::I64(i) => From::from(i as u64),
_ => Uint::zero(),
}
}
}

View File

@@ -23,7 +23,7 @@ use rand::Rng;
use rand::os::OsRng;
use bytes::{BytesConvertable,Populatable};
use from_json::*;
use uint::{Uint, U256};
use bigint::uint::{Uint, U256};
use rustc_serialize::hex::ToHex;
use serde;
@@ -304,6 +304,8 @@ macro_rules! impl_hash {
}
}
impl Copy for $from {}
#[cfg_attr(feature="dev", allow(expl_impl_clone_on_copy))]
impl Clone for $from {
fn clone(&self) -> $from {
unsafe {
@@ -595,7 +597,7 @@ pub fn h256_from_hex(s: &str) -> H256 {
/// Convert `n` to an `H256`, setting the rightmost 8 bytes.
pub fn h256_from_u64(n: u64) -> H256 {
use uint::U256;
use bigint::uint::U256;
H256::from(&U256::from(n))
}
@@ -631,7 +633,7 @@ pub static ZERO_H256: H256 = H256([0x00; 32]);
#[cfg(test)]
mod tests {
use hash::*;
use uint::*;
use bigint::uint::*;
use std::str::FromStr;
#[test]

View File

@@ -16,8 +16,7 @@
//! Calculates heapsize of util types.
use uint::*;
use hash::*;
known_heap_size!(0, H32, H64, H128, Address, H256, H264, H512, H520, H1024, H2048);
known_heap_size!(0, U128, U256);

View File

@@ -16,7 +16,6 @@
#![warn(missing_docs)]
#![cfg_attr(feature="dev", feature(plugin))]
#![cfg_attr(x64asm, feature(asm))]
#![cfg_attr(feature="dev", plugin(clippy))]
// Clippy settings
@@ -111,15 +110,16 @@ extern crate libc;
extern crate rustc_version;
extern crate target_info;
extern crate vergen;
extern crate bigint;
pub mod standard;
#[macro_use]
pub mod from_json;
#[macro_use]
pub mod common;
pub mod numbers;
pub mod error;
pub mod hash;
pub mod uint;
pub mod bytes;
pub mod rlp;
pub mod misc;

20
util/src/numbers.rs Normal file
View File

@@ -0,0 +1,20 @@
// 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/>.
//! Utils number types.
pub use hash::*;
pub use bigint::uint::*;

View File

@@ -21,7 +21,7 @@ use std::mem;
use std::fmt;
use std::cmp::Ordering;
use std::error::Error as StdError;
use uint::{Uint, U128, U256};
use bigint::uint::{Uint, U128, U256};
use hash::FixedHash;
use elastic_array::*;

View File

@@ -21,7 +21,7 @@ use std::{fmt, cmp};
use std::str::FromStr;
use rlp;
use rlp::{UntrustedRlp, RlpStream, View, Stream, DecoderError};
use uint::U256;
use bigint::uint::U256;
#[test]
fn rlp_at() {

File diff suppressed because it is too large Load Diff