Merge branch 'master' of github.com:ethcore/parity into chain_generator
This commit is contained in:
commit
4571df9fc6
13
Cargo.lock
generated
13
Cargo.lock
generated
@ -44,6 +44,18 @@ dependencies = [
|
|||||||
"syntex_syntax 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syntex_syntax 0.29.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bigint"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"arrayvec 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"heapsize 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"serde 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@ -220,6 +232,7 @@ name = "ethcore-util"
|
|||||||
version = "0.9.99"
|
version = "0.9.99"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayvec 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"bigint 0.1.0",
|
||||||
"clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clippy 0.0.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"crossbeam 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
"crossbeam 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"elastic-array 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"elastic-array 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -92,10 +92,10 @@ impl Account {
|
|||||||
|
|
||||||
/// Create a new contract account.
|
/// Create a new contract account.
|
||||||
/// NOTE: make sure you use `init_code` on this before `commit`ing.
|
/// NOTE: make sure you use `init_code` on this before `commit`ing.
|
||||||
pub fn new_contract(balance: U256) -> Account {
|
pub fn new_contract(balance: U256, nonce: U256) -> Account {
|
||||||
Account {
|
Account {
|
||||||
balance: balance,
|
balance: balance,
|
||||||
nonce: U256::from(0u8),
|
nonce: nonce,
|
||||||
storage_root: SHA3_NULL_RLP,
|
storage_root: SHA3_NULL_RLP,
|
||||||
storage_overlay: RefCell::new(HashMap::new()),
|
storage_overlay: RefCell::new(HashMap::new()),
|
||||||
code_hash: None,
|
code_hash: None,
|
||||||
@ -261,7 +261,7 @@ mod tests {
|
|||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
let rlp = {
|
let rlp = {
|
||||||
let mut a = Account::new_contract(U256::from(69u8));
|
let mut a = Account::new_contract(x!(69), x!(0));
|
||||||
a.set_storage(H256::from(&U256::from(0x00u64)), H256::from(&U256::from(0x1234u64)));
|
a.set_storage(H256::from(&U256::from(0x00u64)), H256::from(&U256::from(0x1234u64)));
|
||||||
a.commit_storage(&mut db);
|
a.commit_storage(&mut db);
|
||||||
a.init_code(vec![]);
|
a.init_code(vec![]);
|
||||||
@ -281,7 +281,7 @@ mod tests {
|
|||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
|
|
||||||
let rlp = {
|
let rlp = {
|
||||||
let mut a = Account::new_contract(U256::from(69u8));
|
let mut a = Account::new_contract(x!(69), x!(0));
|
||||||
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
||||||
a.commit_code(&mut db);
|
a.commit_code(&mut db);
|
||||||
a.rlp()
|
a.rlp()
|
||||||
@ -296,7 +296,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn commit_storage() {
|
fn commit_storage() {
|
||||||
let mut a = Account::new_contract(U256::from(69u8));
|
let mut a = Account::new_contract(x!(69), x!(0));
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(x!(0), x!(0x1234));
|
a.set_storage(x!(0), x!(0x1234));
|
||||||
@ -307,7 +307,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn commit_remove_commit_storage() {
|
fn commit_remove_commit_storage() {
|
||||||
let mut a = Account::new_contract(U256::from(69u8));
|
let mut a = Account::new_contract(x!(69), x!(0));
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(x!(0), x!(0x1234));
|
a.set_storage(x!(0), x!(0x1234));
|
||||||
@ -321,7 +321,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn commit_code() {
|
fn commit_code() {
|
||||||
let mut a = Account::new_contract(U256::from(69u8));
|
let mut a = Account::new_contract(x!(69), x!(0));
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
||||||
|
@ -15,9 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Evm input params.
|
//! Evm input params.
|
||||||
use util::hash::*;
|
use common::*;
|
||||||
use util::uint::*;
|
|
||||||
use util::bytes::*;
|
|
||||||
|
|
||||||
/// Transaction value
|
/// Transaction value
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::hash::H256;
|
use util::numbers::{U256,H256};
|
||||||
use util::uint::U256;
|
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
|
|
||||||
/// Best block info.
|
/// Best block info.
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::hash::H256;
|
use util::numbers::{U256,H256};
|
||||||
use util::uint::U256;
|
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
|
|
||||||
/// Brief info about inserted block.
|
/// Brief info about inserted block.
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::hash::H256;
|
use util::numbers::H256;
|
||||||
use chainfilter::BloomIndex;
|
use chainfilter::BloomIndex;
|
||||||
|
|
||||||
/// Represents location of block bloom in extras database.
|
/// Represents location of block bloom in extras database.
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::hash::H256;
|
use util::numbers::H256;
|
||||||
|
|
||||||
/// Represents a tree route between `from` block and `to` block:
|
/// Represents a tree route between `from` block and `to` block:
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use util::hash::H256;
|
use util::numbers::H256;
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
use blockchain::block_info::BlockInfo;
|
use blockchain::block_info::BlockInfo;
|
||||||
use extras::{BlockDetails, BlockReceipts, TransactionAddress, BlocksBlooms};
|
use extras::{BlockDetails, BlockReceipts, TransactionAddress, BlocksBlooms};
|
||||||
|
@ -16,9 +16,7 @@
|
|||||||
|
|
||||||
//! Interface for Evm externalities.
|
//! Interface for Evm externalities.
|
||||||
|
|
||||||
use common::Bytes;
|
use util::common::*;
|
||||||
use util::hash::*;
|
|
||||||
use util::uint::*;
|
|
||||||
use evm::{Schedule, Error};
|
use evm::{Schedule, Error};
|
||||||
use env_info::*;
|
use env_info::*;
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ impl State {
|
|||||||
/// Create a new contract at address `contract`. If there is already an account at the address
|
/// Create a new contract at address `contract`. If there is already an account at the address
|
||||||
/// it will have its code reset, ready for `init_code()`.
|
/// it will have its code reset, ready for `init_code()`.
|
||||||
pub fn new_contract(&mut self, contract: &Address, balance: U256) {
|
pub fn new_contract(&mut self, contract: &Address, balance: U256) {
|
||||||
self.insert_cache(&contract, Some(Account::new_contract(balance)));
|
self.insert_cache(&contract, Some(Account::new_contract(balance, self.account_start_nonce)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove an existing account.
|
/// Remove an existing account.
|
||||||
@ -204,7 +204,7 @@ impl State {
|
|||||||
/// Initialise the code of account `a` so that it is `value` for `key`.
|
/// Initialise the code of account `a` so that it is `value` for `key`.
|
||||||
/// NOTE: Account should have been created with `new_contract`.
|
/// NOTE: Account should have been created with `new_contract`.
|
||||||
pub fn init_code(&mut self, a: &Address, code: Bytes) {
|
pub fn init_code(&mut self, a: &Address, code: Bytes) {
|
||||||
self.require_or_from(a, true, || Account::new_contract(U256::from(0u8)), |_|{}).init_code(code);
|
self.require_or_from(a, true, || Account::new_contract(x!(0), self.account_start_nonce), |_|{}).init_code(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Execute a given transaction.
|
/// Execute a given transaction.
|
||||||
@ -335,10 +335,9 @@ impl fmt::Debug for State {
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use util::hash::*;
|
use util::common::*;
|
||||||
use util::trie::*;
|
use util::trie::*;
|
||||||
use util::rlp::*;
|
use util::rlp::*;
|
||||||
use util::uint::*;
|
|
||||||
use account::*;
|
use account::*;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use devtools::*;
|
use devtools::*;
|
||||||
@ -349,7 +348,7 @@ fn code_from_database() {
|
|||||||
let temp = RandomTempPath::new();
|
let temp = RandomTempPath::new();
|
||||||
let (root, db) = {
|
let (root, db) = {
|
||||||
let mut state = get_temp_state_in(temp.as_path());
|
let mut state = get_temp_state_in(temp.as_path());
|
||||||
state.require_or_from(&a, false, ||Account::new_contract(U256::from(42u32)), |_|{});
|
state.require_or_from(&a, false, ||Account::new_contract(x!(42), x!(0)), |_|{});
|
||||||
state.init_code(&a, vec![1, 2, 3]);
|
state.init_code(&a, vec![1, 2, 3]);
|
||||||
assert_eq!(state.code(&a), Some([1u8, 2, 3].to_vec()));
|
assert_eq!(state.code(&a), Some([1u8, 2, 3].to_vec()));
|
||||||
state.commit();
|
state.commit();
|
||||||
|
@ -100,10 +100,10 @@ impl FromJson for SignedTransaction {
|
|||||||
v: match json.find("v") { Some(ref j) => u16::from_json(j) as u8, None => 0 },
|
v: match json.find("v") { Some(ref j) => u16::from_json(j) as u8, None => 0 },
|
||||||
r: match json.find("r") { Some(j) => xjson!(j), None => x!(0) },
|
r: match json.find("r") { Some(j) => xjson!(j), None => x!(0) },
|
||||||
s: match json.find("s") { Some(j) => xjson!(j), None => x!(0) },
|
s: match json.find("s") { Some(j) => xjson!(j), None => x!(0) },
|
||||||
hash: RefCell::new(None),
|
hash: Cell::new(None),
|
||||||
sender: match json.find("sender") {
|
sender: match json.find("sender") {
|
||||||
Some(&Json::String(ref sender)) => RefCell::new(Some(address_from_hex(clean(sender)))),
|
Some(&Json::String(ref sender)) => Cell::new(Some(address_from_hex(clean(sender)))),
|
||||||
_ => RefCell::new(None),
|
_ => Cell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,8 +127,8 @@ impl Transaction {
|
|||||||
r: r,
|
r: r,
|
||||||
s: s,
|
s: s,
|
||||||
v: v + 27,
|
v: v + 27,
|
||||||
hash: RefCell::new(None),
|
hash: Cell::new(None),
|
||||||
sender: RefCell::new(None)
|
sender: Cell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,8 +140,8 @@ impl Transaction {
|
|||||||
r: U256::zero(),
|
r: U256::zero(),
|
||||||
s: U256::zero(),
|
s: U256::zero(),
|
||||||
v: 0,
|
v: 0,
|
||||||
hash: RefCell::new(None),
|
hash: Cell::new(None),
|
||||||
sender: RefCell::new(None)
|
sender: Cell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,9 +171,9 @@ pub struct SignedTransaction {
|
|||||||
/// The S field of the signature; helps describe the point on the curve.
|
/// The S field of the signature; helps describe the point on the curve.
|
||||||
s: U256,
|
s: U256,
|
||||||
/// Cached hash.
|
/// Cached hash.
|
||||||
hash: RefCell<Option<H256>>,
|
hash: Cell<Option<H256>>,
|
||||||
/// Cached sender.
|
/// Cached sender.
|
||||||
sender: RefCell<Option<Address>>
|
sender: Cell<Option<Address>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for SignedTransaction {
|
impl PartialEq for SignedTransaction {
|
||||||
@ -208,8 +208,8 @@ impl Decodable for SignedTransaction {
|
|||||||
v: try!(d.val_at(6)),
|
v: try!(d.val_at(6)),
|
||||||
r: try!(d.val_at(7)),
|
r: try!(d.val_at(7)),
|
||||||
s: try!(d.val_at(8)),
|
s: try!(d.val_at(8)),
|
||||||
hash: RefCell::new(None),
|
hash: Cell::new(None),
|
||||||
sender: RefCell::new(None),
|
sender: Cell::new(None),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,12 +238,13 @@ impl SignedTransaction {
|
|||||||
|
|
||||||
/// Get the hash of this header (sha3 of the RLP).
|
/// Get the hash of this header (sha3 of the RLP).
|
||||||
pub fn hash(&self) -> H256 {
|
pub fn hash(&self) -> H256 {
|
||||||
let mut hash = self.hash.borrow_mut();
|
let hash = self.hash.get();
|
||||||
match &mut *hash {
|
match hash {
|
||||||
&mut Some(ref h) => h.clone(),
|
Some(h) => h,
|
||||||
hash @ &mut None => {
|
None => {
|
||||||
*hash = Some(self.rlp_sha3());
|
let h = self.rlp_sha3();
|
||||||
hash.as_ref().unwrap().clone()
|
self.hash.set(Some(h));
|
||||||
|
h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,12 +266,13 @@ impl SignedTransaction {
|
|||||||
|
|
||||||
/// Returns transaction sender.
|
/// Returns transaction sender.
|
||||||
pub fn sender(&self) -> Result<Address, Error> {
|
pub fn sender(&self) -> Result<Address, Error> {
|
||||||
let mut sender = self.sender.borrow_mut();
|
let sender = self.sender.get();
|
||||||
match &mut *sender {
|
match sender {
|
||||||
&mut Some(ref h) => Ok(h.clone()),
|
Some(s) => Ok(s),
|
||||||
sender @ &mut None => {
|
None => {
|
||||||
*sender = Some(From::from(try!(ec::recover(&self.signature(), &self.unsigned.hash())).sha3()));
|
let s = Address::from(try!(ec::recover(&self.signature(), &self.unsigned.hash())).sha3());
|
||||||
Ok(sender.as_ref().unwrap().clone())
|
self.sender.set(Some(s));
|
||||||
|
Ok(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,8 +18,7 @@
|
|||||||
use std::sync::{Arc, Weak};
|
use std::sync::{Arc, Weak};
|
||||||
use ethsync::{EthSync, SyncState};
|
use ethsync::{EthSync, SyncState};
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
use util::hash::*;
|
use util::numbers::*;
|
||||||
use util::uint::*;
|
|
||||||
use util::sha3::*;
|
use util::sha3::*;
|
||||||
use ethcore::client::*;
|
use ethcore::client::*;
|
||||||
use ethcore::views::*;
|
use ethcore::views::*;
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
use util::hash::*;
|
use util::numbers::*;
|
||||||
use util::uint::*;
|
|
||||||
use v1::types::{Bytes, Transaction, OptionalValue};
|
use v1::types::{Bytes, Transaction, OptionalValue};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -71,8 +70,7 @@ pub struct Block {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use util::hash::*;
|
use util::numbers::*;
|
||||||
use util::uint::*;
|
|
||||||
use v1::types::{Transaction, Bytes, OptionalValue};
|
use v1::types::{Transaction, Bytes, OptionalValue};
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
use serde::{Deserialize, Deserializer, Error};
|
use serde::{Deserialize, Deserializer, Error};
|
||||||
use serde_json::value;
|
use serde_json::value;
|
||||||
use jsonrpc_core::Value;
|
use jsonrpc_core::Value;
|
||||||
use util::hash::*;
|
use util::numbers::*;
|
||||||
use v1::types::BlockNumber;
|
use v1::types::BlockNumber;
|
||||||
use ethcore::filter::Filter as EthFilter;
|
use ethcore::filter::Filter as EthFilter;
|
||||||
use ethcore::client::BlockId;
|
use ethcore::client::BlockId;
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::hash::*;
|
use util::numbers::*;
|
||||||
use util::uint::*;
|
|
||||||
use ethcore::log_entry::LocalizedLogEntry;
|
use ethcore::log_entry::LocalizedLogEntry;
|
||||||
use v1::types::Bytes;
|
use v1::types::Bytes;
|
||||||
|
|
||||||
@ -55,8 +54,7 @@ impl From<LocalizedLogEntry> for Log {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use util::hash::*;
|
use util::numbers::*;
|
||||||
use util::uint::*;
|
|
||||||
use v1::types::{Bytes, Log};
|
use v1::types::{Bytes, Log};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use serde::{Serialize, Serializer};
|
use serde::{Serialize, Serializer};
|
||||||
use util::uint::*;
|
use util::numbers::*;
|
||||||
|
|
||||||
#[derive(Default, Debug, Serialize, PartialEq)]
|
#[derive(Default, Debug, Serialize, PartialEq)]
|
||||||
pub struct SyncInfo {
|
pub struct SyncInfo {
|
||||||
|
@ -14,8 +14,7 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use util::hash::*;
|
use util::numbers::*;
|
||||||
use util::uint::*;
|
|
||||||
use ethcore::transaction::{LocalizedTransaction, Action};
|
use ethcore::transaction::{LocalizedTransaction, Action};
|
||||||
use v1::types::{Bytes, OptionalValue};
|
use v1::types::{Bytes, OptionalValue};
|
||||||
|
|
||||||
|
@ -1171,8 +1171,8 @@ impl ChainSync {
|
|||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// propagades latest block to lagging peers
|
/// propagates latest block to lagging peers
|
||||||
fn propagade_blocks(&mut self, local_best: &H256, best_number: BlockNumber, io: &mut SyncIo) -> usize {
|
fn propagate_blocks(&mut self, local_best: &H256, best_number: BlockNumber, io: &mut SyncIo) -> usize {
|
||||||
let updated_peers = {
|
let updated_peers = {
|
||||||
let lagging_peers = self.get_lagging_peers(io);
|
let lagging_peers = self.get_lagging_peers(io);
|
||||||
|
|
||||||
@ -1198,8 +1198,8 @@ impl ChainSync {
|
|||||||
sent
|
sent
|
||||||
}
|
}
|
||||||
|
|
||||||
/// propagades new known hashes to all peers
|
/// propagates new known hashes to all peers
|
||||||
fn propagade_new_hashes(&mut self, local_best: &H256, best_number: BlockNumber, io: &mut SyncIo) -> usize {
|
fn propagate_new_hashes(&mut self, local_best: &H256, best_number: BlockNumber, io: &mut SyncIo) -> usize {
|
||||||
let updated_peers = self.get_lagging_peers(io);
|
let updated_peers = self.get_lagging_peers(io);
|
||||||
let mut sent = 0;
|
let mut sent = 0;
|
||||||
let last_parent = HeaderView::new(&io.chain().block_header(BlockId::Hash(local_best.clone())).unwrap()).parent_hash();
|
let last_parent = HeaderView::new(&io.chain().block_header(BlockId::Hash(local_best.clone())).unwrap()).parent_hash();
|
||||||
@ -1234,8 +1234,8 @@ impl ChainSync {
|
|||||||
pub fn chain_blocks_verified(&mut self, io: &mut SyncIo) {
|
pub fn chain_blocks_verified(&mut self, io: &mut SyncIo) {
|
||||||
let chain = io.chain().chain_info();
|
let chain = io.chain().chain_info();
|
||||||
if (((chain.best_block_number as i64) - (self.last_send_block_number as i64)).abs() as BlockNumber) < MAX_PEER_LAG_PROPAGATION {
|
if (((chain.best_block_number as i64) - (self.last_send_block_number as i64)).abs() as BlockNumber) < MAX_PEER_LAG_PROPAGATION {
|
||||||
let blocks = self.propagade_blocks(&chain.best_block_hash, chain.best_block_number, io);
|
let blocks = self.propagate_blocks(&chain.best_block_hash, chain.best_block_number, io);
|
||||||
let hashes = self.propagade_new_hashes(&chain.best_block_hash, chain.best_block_number, io);
|
let hashes = self.propagate_new_hashes(&chain.best_block_hash, chain.best_block_number, io);
|
||||||
if blocks != 0 || hashes != 0 {
|
if blocks != 0 || hashes != 0 {
|
||||||
trace!(target: "sync", "Sent latest {} blocks and {} hashes to peers.", blocks, hashes);
|
trace!(target: "sync", "Sent latest {} blocks and {} hashes to peers.", blocks, hashes);
|
||||||
}
|
}
|
||||||
@ -1419,7 +1419,7 @@ mod tests {
|
|||||||
let best_number = client.chain_info().best_block_number;
|
let best_number = client.chain_info().best_block_number;
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
let peer_count = sync.propagade_new_hashes(&best_hash, best_number, &mut io);
|
let peer_count = sync.propagate_new_hashes(&best_hash, best_number, &mut io);
|
||||||
|
|
||||||
// 1 message should be send
|
// 1 message should be send
|
||||||
assert_eq!(1, io.queue.len());
|
assert_eq!(1, io.queue.len());
|
||||||
@ -1439,7 +1439,7 @@ mod tests {
|
|||||||
let best_number = client.chain_info().best_block_number;
|
let best_number = client.chain_info().best_block_number;
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
let peer_count = sync.propagade_blocks(&best_hash, best_number, &mut io);
|
let peer_count = sync.propagate_blocks(&best_hash, best_number, &mut io);
|
||||||
|
|
||||||
// 1 message should be send
|
// 1 message should be send
|
||||||
assert_eq!(1, io.queue.len());
|
assert_eq!(1, io.queue.len());
|
||||||
@ -1545,7 +1545,7 @@ mod tests {
|
|||||||
let best_number = client.chain_info().best_block_number;
|
let best_number = client.chain_info().best_block_number;
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
sync.propagade_new_hashes(&best_hash, best_number, &mut io);
|
sync.propagate_new_hashes(&best_hash, best_number, &mut io);
|
||||||
|
|
||||||
let data = &io.queue[0].data.clone();
|
let data = &io.queue[0].data.clone();
|
||||||
let result = sync.on_peer_new_hashes(&mut io, 0, &UntrustedRlp::new(&data));
|
let result = sync.on_peer_new_hashes(&mut io, 0, &UntrustedRlp::new(&data));
|
||||||
@ -1564,7 +1564,7 @@ mod tests {
|
|||||||
let best_number = client.chain_info().best_block_number;
|
let best_number = client.chain_info().best_block_number;
|
||||||
let mut io = TestIo::new(&mut client, &mut queue, None);
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
sync.propagade_blocks(&best_hash, best_number, &mut io);
|
sync.propagate_blocks(&best_hash, best_number, &mut io);
|
||||||
|
|
||||||
let data = &io.queue[0].data.clone();
|
let data = &io.queue[0].data.clone();
|
||||||
let result = sync.on_peer_new_block(&mut io, 0, &UntrustedRlp::new(&data));
|
let result = sync.on_peer_new_block(&mut io, 0, &UntrustedRlp::new(&data));
|
||||||
|
@ -121,7 +121,7 @@ fn status_packet() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn propagade_hashes() {
|
fn propagate_hashes() {
|
||||||
let mut net = TestNet::new(6);
|
let mut net = TestNet::new(6);
|
||||||
net.peer_mut(1).chain.add_blocks(10, false);
|
net.peer_mut(1).chain.add_blocks(10, false);
|
||||||
net.sync();
|
net.sync();
|
||||||
@ -147,7 +147,7 @@ fn propagade_hashes() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn propagade_blocks() {
|
fn propagate_blocks() {
|
||||||
let mut net = TestNet::new(2);
|
let mut net = TestNet::new(2);
|
||||||
net.peer_mut(1).chain.add_blocks(10, false);
|
net.peer_mut(1).chain.add_blocks(10, false);
|
||||||
net.sync();
|
net.sync();
|
||||||
|
@ -35,6 +35,7 @@ ethcore-devtools = { path = "../devtools" }
|
|||||||
libc = "0.2.7"
|
libc = "0.2.7"
|
||||||
vergen = "0.1"
|
vergen = "0.1"
|
||||||
target_info = "0.1"
|
target_info = "0.1"
|
||||||
|
bigint = { path = "bigint" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
23
util/bigint/Cargo.toml
Normal file
23
util/bigint/Cargo.toml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
[package]
|
||||||
|
description = "Rust-assembler implementation of big integers arithmetic"
|
||||||
|
homepage = "http://ethcore.io"
|
||||||
|
license = "GPL-3.0"
|
||||||
|
name = "bigint"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Ethcore <admin@ethcore.io>"]
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
rustc_version = "0.1"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
rustc-serialize = "0.3"
|
||||||
|
arrayvec = "0.3"
|
||||||
|
rand = "0.3.12"
|
||||||
|
serde = "0.7.0"
|
||||||
|
clippy = { version = "0.0.44", optional = true }
|
||||||
|
heapsize = "0.3"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
x64asm_arithmetic=[]
|
||||||
|
rust_arithmetic=[]
|
25
util/bigint/build.rs
Normal file
25
util/bigint/build.rs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
extern crate rustc_version;
|
||||||
|
|
||||||
|
use rustc_version::{version_meta, Channel};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if let Channel::Nightly = version_meta().channel {
|
||||||
|
println!("cargo:rustc-cfg=asm_available");
|
||||||
|
}
|
||||||
|
}
|
23
util/bigint/src/lib.rs
Normal file
23
util/bigint/src/lib.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
#![cfg_attr(asm_available, feature(asm))]
|
||||||
|
|
||||||
|
extern crate rustc_serialize;
|
||||||
|
extern crate serde;
|
||||||
|
#[macro_use] extern crate heapsize;
|
||||||
|
|
||||||
|
pub mod uint;
|
@ -36,10 +36,26 @@
|
|||||||
//! The functions here are designed to be fast.
|
//! The functions here are designed to be fast.
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use standard::*;
|
use std::fmt;
|
||||||
use from_json::*;
|
use std::cmp;
|
||||||
use rustc_serialize::hex::ToHex;
|
|
||||||
|
use std::mem;
|
||||||
|
use std::ops;
|
||||||
|
use std::slice;
|
||||||
|
use std::result;
|
||||||
|
use std::option;
|
||||||
|
use std::str::{FromStr};
|
||||||
|
use std::convert::From;
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
use std::ops::*;
|
||||||
|
use std::cmp::*;
|
||||||
|
use std::collections::*;
|
||||||
|
|
||||||
use serde;
|
use serde;
|
||||||
|
use rustc_serialize::json::Json;
|
||||||
|
use rustc_serialize::base64::FromBase64;
|
||||||
|
use rustc_serialize::hex::{FromHex, FromHexError, ToHex};
|
||||||
|
|
||||||
|
|
||||||
macro_rules! impl_map_from {
|
macro_rules! impl_map_from {
|
||||||
($thing:ident, $from:ty, $to:ty) => {
|
($thing:ident, $from:ty, $to:ty) => {
|
||||||
@ -51,7 +67,7 @@ macro_rules! impl_map_from {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(all(x64asm, target_arch="x86_64")))]
|
#[cfg(not(all(asm_available, target_arch="x86_64")))]
|
||||||
macro_rules! uint_overflowing_add {
|
macro_rules! uint_overflowing_add {
|
||||||
($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ({
|
($name:ident, $n_words:expr, $self_expr: expr, $other: expr) => ({
|
||||||
uint_overflowing_add_reg!($name, $n_words, $self_expr, $other)
|
uint_overflowing_add_reg!($name, $n_words, $self_expr, $other)
|
||||||
@ -88,8 +104,7 @@ macro_rules! uint_overflowing_add_reg {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(all(asm_available, target_arch="x86_64"))]
|
||||||
#[cfg(all(x64asm, target_arch="x86_64"))]
|
|
||||||
macro_rules! uint_overflowing_add {
|
macro_rules! uint_overflowing_add {
|
||||||
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
||||||
@ -165,7 +180,7 @@ macro_rules! uint_overflowing_add {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(all(x64asm, target_arch="x86_64")))]
|
#[cfg(not(all(asm_available, target_arch="x86_64")))]
|
||||||
macro_rules! uint_overflowing_sub {
|
macro_rules! uint_overflowing_sub {
|
||||||
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let res = overflowing!((!$other).overflowing_add(From::from(1u64)));
|
let res = overflowing!((!$other).overflowing_add(From::from(1u64)));
|
||||||
@ -174,7 +189,7 @@ macro_rules! uint_overflowing_sub {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(x64asm, target_arch="x86_64"))]
|
#[cfg(all(asm_available, target_arch="x86_64"))]
|
||||||
macro_rules! uint_overflowing_sub {
|
macro_rules! uint_overflowing_sub {
|
||||||
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
||||||
@ -250,7 +265,7 @@ macro_rules! uint_overflowing_sub {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(x64asm, target_arch="x86_64"))]
|
#[cfg(all(asm_available, target_arch="x86_64"))]
|
||||||
macro_rules! uint_overflowing_mul {
|
macro_rules! uint_overflowing_mul {
|
||||||
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
||||||
@ -370,7 +385,7 @@ macro_rules! uint_overflowing_mul {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(all(x64asm, target_arch="x86_64")))]
|
#[cfg(not(all(asm_available, target_arch="x86_64")))]
|
||||||
macro_rules! uint_overflowing_mul {
|
macro_rules! uint_overflowing_mul {
|
||||||
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
uint_overflowing_mul_reg!($name, $n_words, $self_expr, $other)
|
uint_overflowing_mul_reg!($name, $n_words, $self_expr, $other)
|
||||||
@ -381,7 +396,6 @@ macro_rules! uint_overflowing_mul_reg {
|
|||||||
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
($name:ident, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut res = $name::from(0u64);
|
let mut res = $name::from(0u64);
|
||||||
let mut overflow = false;
|
let mut overflow = false;
|
||||||
// TODO: be more efficient about this
|
|
||||||
for i in 0..(2 * $n_words) {
|
for i in 0..(2 * $n_words) {
|
||||||
let v = overflowing!($self_expr.overflowing_mul_u32(($other >> (32 * i)).low_u32()), overflow);
|
let v = overflowing!($self_expr.overflowing_mul_u32(($other >> (32 * i)).low_u32()), overflow);
|
||||||
let res2 = overflowing!(v.overflowing_shl(32 * i as u32), overflow);
|
let res2 = overflowing!(v.overflowing_shl(32 * i as u32), overflow);
|
||||||
@ -416,7 +430,7 @@ macro_rules! panic_on_overflow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Large, fixed-length unsigned integer type.
|
/// Large, fixed-length unsigned integer type.
|
||||||
pub trait Uint: Sized + Default + FromStr + From<u64> + FromJson + fmt::Debug + fmt::Display + PartialOrd + Ord + PartialEq + Eq + Hash {
|
pub trait Uint: Sized + Default + FromStr + From<u64> + fmt::Debug + fmt::Display + PartialOrd + Ord + PartialEq + Eq + Hash {
|
||||||
|
|
||||||
/// Returns new instance equalling zero.
|
/// Returns new instance equalling zero.
|
||||||
fn zero() -> Self;
|
fn zero() -> Self;
|
||||||
@ -779,22 +793,6 @@ macro_rules! construct_uint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJson for $name {
|
|
||||||
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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_map_from!($name, u8, u64);
|
impl_map_from!($name, u8, u64);
|
||||||
impl_map_from!($name, u16, u64);
|
impl_map_from!($name, u16, u64);
|
||||||
@ -1100,7 +1098,7 @@ construct_uint!(U128, 2);
|
|||||||
impl U256 {
|
impl U256 {
|
||||||
/// Multiplies two 256-bit integers to produce full 512-bit integer
|
/// Multiplies two 256-bit integers to produce full 512-bit integer
|
||||||
/// No overflow possible
|
/// No overflow possible
|
||||||
#[cfg(all(x64asm, target_arch="x86_64"))]
|
#[cfg(all(asm_available, target_arch="x86_64"))]
|
||||||
pub fn full_mul(self, other: U256) -> U512 {
|
pub fn full_mul(self, other: U256) -> U512 {
|
||||||
let self_t: &[u64; 4] = unsafe { &mem::transmute(self) };
|
let self_t: &[u64; 4] = unsafe { &mem::transmute(self) };
|
||||||
let other_t: &[u64; 4] = unsafe { &mem::transmute(other) };
|
let other_t: &[u64; 4] = unsafe { &mem::transmute(other) };
|
||||||
@ -1239,7 +1237,7 @@ impl U256 {
|
|||||||
|
|
||||||
/// Multiplies two 256-bit integers to produce full 512-bit integer
|
/// Multiplies two 256-bit integers to produce full 512-bit integer
|
||||||
/// No overflow possible
|
/// No overflow possible
|
||||||
#[cfg(not(all(x64asm, target_arch="x86_64")))]
|
#[cfg(not(all(asm_available, target_arch="x86_64")))]
|
||||||
pub fn full_mul(self, other: U256) -> U512 {
|
pub fn full_mul(self, other: U256) -> U512 {
|
||||||
let self_512 = U512::from(self);
|
let self_512 = U512::from(self);
|
||||||
let other_512 = U512::from(other);
|
let other_512 = U512::from(other);
|
||||||
@ -1338,6 +1336,9 @@ pub const ZERO_U256: U256 = U256([0x00u64; 4]);
|
|||||||
/// Constant value of `U256::one()` that can be used for a reference saving an additional instance creation.
|
/// Constant value of `U256::one()` that can be used for a reference saving an additional instance creation.
|
||||||
pub const ONE_U256: U256 = U256([0x01u64, 0x00u64, 0x00u64, 0x00u64]);
|
pub const ONE_U256: U256 = U256([0x01u64, 0x00u64, 0x00u64, 0x00u64]);
|
||||||
|
|
||||||
|
|
||||||
|
known_heap_size!(0, U128, U256);
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use uint::{Uint, U128, U256, U512};
|
use uint::{Uint, U128, U256, U512};
|
@ -1,13 +1,7 @@
|
|||||||
extern crate vergen;
|
extern crate vergen;
|
||||||
extern crate rustc_version;
|
|
||||||
|
|
||||||
use vergen::*;
|
use vergen::*;
|
||||||
use rustc_version::{version_meta, Channel};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
vergen(OutputFns::all()).unwrap();
|
vergen(OutputFns::all()).unwrap();
|
||||||
|
|
||||||
if let Channel::Nightly = version_meta().channel {
|
|
||||||
println!("cargo:rustc-cfg=x64asm");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,10 +19,9 @@
|
|||||||
pub use standard::*;
|
pub use standard::*;
|
||||||
pub use from_json::*;
|
pub use from_json::*;
|
||||||
pub use error::*;
|
pub use error::*;
|
||||||
pub use hash::*;
|
|
||||||
pub use uint::*;
|
|
||||||
pub use bytes::*;
|
pub use bytes::*;
|
||||||
pub use vector::*;
|
pub use vector::*;
|
||||||
|
pub use numbers::*;
|
||||||
pub use sha3::*;
|
pub use sha3::*;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
//! Ethcore crypto.
|
//! Ethcore crypto.
|
||||||
|
|
||||||
use hash::*;
|
use numbers::*;
|
||||||
use bytes::*;
|
use bytes::*;
|
||||||
use uint::*;
|
|
||||||
use secp256k1::{key, Secp256k1};
|
use secp256k1::{key, Secp256k1};
|
||||||
use rand::os::OsRng;
|
use rand::os::OsRng;
|
||||||
|
|
||||||
@ -151,8 +150,7 @@ impl KeyPair {
|
|||||||
|
|
||||||
/// EC functions
|
/// EC functions
|
||||||
pub mod ec {
|
pub mod ec {
|
||||||
use hash::*;
|
use numbers::*;
|
||||||
use uint::*;
|
|
||||||
use standard::*;
|
use standard::*;
|
||||||
use crypto::*;
|
use crypto::*;
|
||||||
use crypto::{self};
|
use crypto::{self};
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
//! Coversion from json.
|
//! Coversion from json.
|
||||||
|
|
||||||
use standard::*;
|
use standard::*;
|
||||||
|
use bigint::uint::*;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! xjson {
|
macro_rules! xjson {
|
||||||
@ -30,3 +31,20 @@ pub trait FromJson {
|
|||||||
/// Convert a JSON value to an instance of this type.
|
/// Convert a JSON value to an instance of this type.
|
||||||
fn from_json(json: &Json) -> Self;
|
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(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,7 +23,7 @@ use rand::Rng;
|
|||||||
use rand::os::OsRng;
|
use rand::os::OsRng;
|
||||||
use bytes::{BytesConvertable,Populatable};
|
use bytes::{BytesConvertable,Populatable};
|
||||||
use from_json::*;
|
use from_json::*;
|
||||||
use uint::{Uint, U256};
|
use bigint::uint::{Uint, U256};
|
||||||
use rustc_serialize::hex::ToHex;
|
use rustc_serialize::hex::ToHex;
|
||||||
use serde;
|
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 {
|
impl Clone for $from {
|
||||||
fn clone(&self) -> $from {
|
fn clone(&self) -> $from {
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -595,7 +597,7 @@ pub fn h256_from_hex(s: &str) -> H256 {
|
|||||||
|
|
||||||
/// Convert `n` to an `H256`, setting the rightmost 8 bytes.
|
/// Convert `n` to an `H256`, setting the rightmost 8 bytes.
|
||||||
pub fn h256_from_u64(n: u64) -> H256 {
|
pub fn h256_from_u64(n: u64) -> H256 {
|
||||||
use uint::U256;
|
use bigint::uint::U256;
|
||||||
H256::from(&U256::from(n))
|
H256::from(&U256::from(n))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,7 +633,7 @@ pub static ZERO_H256: H256 = H256([0x00; 32]);
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use hash::*;
|
use hash::*;
|
||||||
use uint::*;
|
use bigint::uint::*;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
//! Calculates heapsize of util types.
|
//! Calculates heapsize of util types.
|
||||||
|
|
||||||
use uint::*;
|
|
||||||
use hash::*;
|
use hash::*;
|
||||||
|
|
||||||
known_heap_size!(0, H32, H64, H128, Address, H256, H264, H512, H520, H1024, H2048);
|
known_heap_size!(0, H32, H64, H128, Address, H256, H264, H512, H520, H1024, H2048);
|
||||||
known_heap_size!(0, U128, U256);
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![cfg_attr(feature="dev", feature(plugin))]
|
#![cfg_attr(feature="dev", feature(plugin))]
|
||||||
#![cfg_attr(x64asm, feature(asm))]
|
|
||||||
#![cfg_attr(feature="dev", plugin(clippy))]
|
#![cfg_attr(feature="dev", plugin(clippy))]
|
||||||
|
|
||||||
// Clippy settings
|
// Clippy settings
|
||||||
@ -111,15 +110,16 @@ extern crate libc;
|
|||||||
extern crate rustc_version;
|
extern crate rustc_version;
|
||||||
extern crate target_info;
|
extern crate target_info;
|
||||||
extern crate vergen;
|
extern crate vergen;
|
||||||
|
extern crate bigint;
|
||||||
|
|
||||||
pub mod standard;
|
pub mod standard;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod from_json;
|
pub mod from_json;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
pub mod numbers;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod hash;
|
pub mod hash;
|
||||||
pub mod uint;
|
|
||||||
pub mod bytes;
|
pub mod bytes;
|
||||||
pub mod rlp;
|
pub mod rlp;
|
||||||
pub mod misc;
|
pub mod misc;
|
||||||
|
20
util/src/numbers.rs
Normal file
20
util/src/numbers.rs
Normal 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::*;
|
@ -21,7 +21,7 @@ use std::mem;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
use uint::{Uint, U128, U256};
|
use bigint::uint::{Uint, U128, U256};
|
||||||
use hash::FixedHash;
|
use hash::FixedHash;
|
||||||
use elastic_array::*;
|
use elastic_array::*;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ use std::{fmt, cmp};
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use rlp;
|
use rlp;
|
||||||
use rlp::{UntrustedRlp, RlpStream, View, Stream, DecoderError};
|
use rlp::{UntrustedRlp, RlpStream, View, Stream, DecoderError};
|
||||||
use uint::U256;
|
use bigint::uint::U256;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn rlp_at() {
|
fn rlp_at() {
|
||||||
|
Loading…
Reference in New Issue
Block a user