Merge branch 'master' into jsonrpc
This commit is contained in:
commit
9c3317620d
@ -1,11 +1,13 @@
|
|||||||
# ethcore
|
# ethcore
|
||||||
|
|
||||||
[![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url]
|
[![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Join the chat at https://gitter.im/trogdoro/xiki][gitter-image]][gitter-url]
|
||||||
|
|
||||||
[travis-image]: https://travis-ci.com/ethcore/parity.svg?token=DMFvZu71iaTbUYx9UypX&branch=master
|
[travis-image]: https://travis-ci.com/ethcore/parity.svg?token=DMFvZu71iaTbUYx9UypX&branch=master
|
||||||
[travis-url]: https://travis-ci.com/ethcore/parity
|
[travis-url]: https://travis-ci.com/ethcore/parity
|
||||||
[coveralls-image]: https://coveralls.io/repos/github/ethcore/parity/badge.svg?branch=master&t=Fk0OuQ
|
[coveralls-image]: https://coveralls.io/repos/github/ethcore/parity/badge.svg?branch=master&t=Fk0OuQ
|
||||||
[coveralls-url]: https://coveralls.io/r/ethcore/parity?branch=master
|
[coveralls-url]: https://coveralls.io/r/ethcore/parity?branch=master
|
||||||
|
[gitter-image]: https://badges.gitter.im/Join%20Chat.svg
|
||||||
|
[gitter-url]: https://gitter.im/ethcore/parity?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
|
||||||
|
|
||||||
### Building from source
|
### Building from source
|
||||||
|
|
||||||
|
6
add_license.sh
Executable file
6
add_license.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
for f in $(find . -name '*.rs'); do
|
||||||
|
cat license_header $f > $f.new
|
||||||
|
mv $f.new $f
|
||||||
|
done
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethash implementation
|
//! Ethash implementation
|
||||||
//! See https://github.com/ethereum/wiki/wiki/Ethash
|
//! See https://github.com/ethereum/wiki/wiki/Ethash
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethash implementation
|
//! Ethash implementation
|
||||||
//! See https://github.com/ethereum/wiki/wiki/Ethash
|
//! See https://github.com/ethereum/wiki/wiki/Ethash
|
||||||
extern crate sha3;
|
extern crate sha3;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
// 2048 Epochs (~20 years) worth of tabulated DAG sizes
|
// 2048 Epochs (~20 years) worth of tabulated DAG sizes
|
||||||
|
|
||||||
// Generated with the following Mathematica Code:
|
// Generated with the following Mathematica Code:
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit c670b1d8c9f09593a6758ab2c099360e16c7c25b
|
Subproject commit 3116f85a499ceaf4dfdc46726060fc056e2d7829
|
@ -1,7 +1,24 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Single account in the system.
|
//! Single account in the system.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use pod_account::*;
|
use pod_account::*;
|
||||||
|
use account_db::*;
|
||||||
|
|
||||||
/// Single account in the system.
|
/// Single account in the system.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -99,7 +116,7 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get (and cache) the contents of the trie's storage at `key`.
|
/// Get (and cache) the contents of the trie's storage at `key`.
|
||||||
pub fn storage_at(&self, db: &HashDB, key: &H256) -> H256 {
|
pub fn storage_at(&self, db: &AccountDB, key: &H256) -> H256 {
|
||||||
self.storage_overlay.borrow_mut().entry(key.clone()).or_insert_with(||{
|
self.storage_overlay.borrow_mut().entry(key.clone()).or_insert_with(||{
|
||||||
(Filth::Clean, H256::from(SecTrieDB::new(db, &self.storage_root).get(key.bytes()).map_or(U256::zero(), |v| -> U256 {decode(v)})))
|
(Filth::Clean, H256::from(SecTrieDB::new(db, &self.storage_root).get(key.bytes()).map_or(U256::zero(), |v| -> U256 {decode(v)})))
|
||||||
}).1.clone()
|
}).1.clone()
|
||||||
@ -147,7 +164,7 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Provide a database to lookup `code_hash`. Should not be called if it is a contract without code.
|
/// Provide a database to lookup `code_hash`. Should not be called if it is a contract without code.
|
||||||
pub fn cache_code(&mut self, db: &HashDB) -> bool {
|
pub fn cache_code(&mut self, db: &AccountDB) -> bool {
|
||||||
// TODO: fill out self.code_cache;
|
// TODO: fill out self.code_cache;
|
||||||
trace!("Account::cache_code: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty());
|
trace!("Account::cache_code: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty());
|
||||||
self.is_cached() ||
|
self.is_cached() ||
|
||||||
@ -184,7 +201,7 @@ impl Account {
|
|||||||
pub fn sub_balance(&mut self, x: &U256) { self.balance = self.balance - *x; }
|
pub fn sub_balance(&mut self, x: &U256) { self.balance = self.balance - *x; }
|
||||||
|
|
||||||
/// Commit the `storage_overlay` to the backing DB and update `storage_root`.
|
/// Commit the `storage_overlay` to the backing DB and update `storage_root`.
|
||||||
pub fn commit_storage(&mut self, db: &mut HashDB) {
|
pub fn commit_storage(&mut self, db: &mut AccountDBMut) {
|
||||||
let mut t = SecTrieDBMut::from_existing(db, &mut self.storage_root);
|
let mut t = SecTrieDBMut::from_existing(db, &mut self.storage_root);
|
||||||
for (k, &mut (ref mut f, ref mut v)) in self.storage_overlay.borrow_mut().iter_mut() {
|
for (k, &mut (ref mut f, ref mut v)) in self.storage_overlay.borrow_mut().iter_mut() {
|
||||||
if f == &Filth::Dirty {
|
if f == &Filth::Dirty {
|
||||||
@ -200,7 +217,7 @@ impl Account {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Commit any unsaved code. `code_hash` will always return the hash of the `code_cache` after this.
|
/// Commit any unsaved code. `code_hash` will always return the hash of the `code_cache` after this.
|
||||||
pub fn commit_code(&mut self, db: &mut HashDB) {
|
pub fn commit_code(&mut self, db: &mut AccountDBMut) {
|
||||||
trace!("Commiting code of {:?} - {:?}, {:?}", self, self.code_hash.is_none(), self.code_cache.is_empty());
|
trace!("Commiting code of {:?} - {:?}, {:?}", self, self.code_hash.is_none(), self.code_cache.is_empty());
|
||||||
match (self.code_hash.is_none(), self.code_cache.is_empty()) {
|
match (self.code_hash.is_none(), self.code_cache.is_empty()) {
|
||||||
(true, true) => self.code_hash = Some(SHA3_EMPTY),
|
(true, true) => self.code_hash = Some(SHA3_EMPTY),
|
||||||
@ -233,10 +250,12 @@ mod tests {
|
|||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use account_db::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn storage_at() {
|
fn storage_at() {
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::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(U256::from(69u8));
|
||||||
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)));
|
||||||
@ -248,13 +267,14 @@ mod tests {
|
|||||||
|
|
||||||
let a = Account::from_rlp(&rlp);
|
let a = Account::from_rlp(&rlp);
|
||||||
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
assert_eq!(a.storage_root().unwrap().hex(), "c57e1afb758b07f8d2c8f13a3b6e44fa5ff94ab266facc5a4fd3f062426e50b2");
|
||||||
assert_eq!(a.storage_at(&db, &H256::from(&U256::from(0x00u64))), H256::from(&U256::from(0x1234u64)));
|
assert_eq!(a.storage_at(&db.immutable(), &H256::from(&U256::from(0x00u64))), H256::from(&U256::from(0x1234u64)));
|
||||||
assert_eq!(a.storage_at(&db, &H256::from(&U256::from(0x01u64))), H256::new());
|
assert_eq!(a.storage_at(&db.immutable(), &H256::from(&U256::from(0x01u64))), H256::new());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn note_code() {
|
fn note_code() {
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::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(U256::from(69u8));
|
||||||
@ -264,7 +284,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut a = Account::from_rlp(&rlp);
|
let mut a = Account::from_rlp(&rlp);
|
||||||
assert!(a.cache_code(&db));
|
assert!(a.cache_code(&db.immutable()));
|
||||||
|
|
||||||
let mut a = Account::from_rlp(&rlp);
|
let mut a = Account::from_rlp(&rlp);
|
||||||
assert_eq!(a.note_code(vec![0x55, 0x44, 0xffu8]), Ok(()));
|
assert_eq!(a.note_code(vec![0x55, 0x44, 0xffu8]), Ok(()));
|
||||||
@ -274,6 +294,7 @@ mod tests {
|
|||||||
fn commit_storage() {
|
fn commit_storage() {
|
||||||
let mut a = Account::new_contract(U256::from(69u8));
|
let mut a = Account::new_contract(U256::from(69u8));
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(x!(0), x!(0x1234));
|
a.set_storage(x!(0), x!(0x1234));
|
||||||
assert_eq!(a.storage_root(), None);
|
assert_eq!(a.storage_root(), None);
|
||||||
a.commit_storage(&mut db);
|
a.commit_storage(&mut db);
|
||||||
@ -284,6 +305,7 @@ mod tests {
|
|||||||
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(U256::from(69u8));
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(x!(0), x!(0x1234));
|
a.set_storage(x!(0), x!(0x1234));
|
||||||
a.commit_storage(&mut db);
|
a.commit_storage(&mut db);
|
||||||
a.set_storage(x!(1), x!(0x1234));
|
a.set_storage(x!(1), x!(0x1234));
|
||||||
@ -297,6 +319,7 @@ mod tests {
|
|||||||
fn commit_code() {
|
fn commit_code() {
|
||||||
let mut a = Account::new_contract(U256::from(69u8));
|
let mut a = Account::new_contract(U256::from(69u8));
|
||||||
let mut db = MemoryDB::new();
|
let mut db = MemoryDB::new();
|
||||||
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
||||||
assert_eq!(a.code_hash(), SHA3_EMPTY);
|
assert_eq!(a.code_hash(), SHA3_EMPTY);
|
||||||
a.commit_code(&mut db);
|
a.commit_code(&mut db);
|
||||||
|
120
ethcore/src/account_db.rs
Normal file
120
ethcore/src/account_db.rs
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
//! DB backend wrapper for Account trie
|
||||||
|
use util::*;
|
||||||
|
|
||||||
|
static NULL_RLP_STATIC: [u8; 1] = [0x80; 1];
|
||||||
|
|
||||||
|
// TODO: introduce HashDBMut?
|
||||||
|
/// DB backend wrapper for Account trie
|
||||||
|
/// Transforms trie node keys for the database
|
||||||
|
pub struct AccountDB<'db> {
|
||||||
|
db: &'db HashDB,
|
||||||
|
address: H256,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn combine_key<'a>(address: &'a H256, key: &'a H256) -> H256 {
|
||||||
|
let mut addr_hash = address.sha3();
|
||||||
|
// preserve 96 bits of original key for db lookup
|
||||||
|
addr_hash[0..12].clone_from_slice(&[0u8; 12]);
|
||||||
|
&addr_hash ^ key
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'db> AccountDB<'db> {
|
||||||
|
pub fn new(db: &'db HashDB, address: &Address) -> AccountDB<'db> {
|
||||||
|
AccountDB {
|
||||||
|
db: db,
|
||||||
|
address: x!(address.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'db> HashDB for AccountDB<'db>{
|
||||||
|
fn keys(&self) -> HashMap<H256, i32> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup(&self, key: &H256) -> Option<&[u8]> {
|
||||||
|
if key == &SHA3_NULL_RLP {
|
||||||
|
return Some(&NULL_RLP_STATIC);
|
||||||
|
}
|
||||||
|
self.db.lookup(&combine_key(&self.address, key))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exists(&self, key: &H256) -> bool {
|
||||||
|
if key == &SHA3_NULL_RLP {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
self.db.exists(&combine_key(&self.address, key))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert(&mut self, _value: &[u8]) -> H256 {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn emplace(&mut self, _key: H256, _value: Bytes) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn kill(&mut self, _key: &H256) {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// DB backend wrapper for Account trie
|
||||||
|
pub struct AccountDBMut<'db> {
|
||||||
|
db: &'db mut HashDB,
|
||||||
|
address: H256,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'db> AccountDBMut<'db> {
|
||||||
|
pub fn new(db: &'db mut HashDB, address: &Address) -> AccountDBMut<'db> {
|
||||||
|
AccountDBMut {
|
||||||
|
db: db,
|
||||||
|
address: x!(address.clone()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn immutable(&'db self) -> AccountDB<'db> {
|
||||||
|
AccountDB { db: self.db, address: self.address.clone() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'db> HashDB for AccountDBMut<'db>{
|
||||||
|
fn keys(&self) -> HashMap<H256, i32> {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lookup(&self, key: &H256) -> Option<&[u8]> {
|
||||||
|
if key == &SHA3_NULL_RLP {
|
||||||
|
return Some(&NULL_RLP_STATIC);
|
||||||
|
}
|
||||||
|
self.db.lookup(&combine_key(&self.address, key))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exists(&self, key: &H256) -> bool {
|
||||||
|
if key == &SHA3_NULL_RLP {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
self.db.exists(&combine_key(&self.address, key))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert(&mut self, value: &[u8]) -> H256 {
|
||||||
|
let k = value.sha3();
|
||||||
|
let ak = combine_key(&self.address, &k);
|
||||||
|
self.db.emplace(ak, value.to_vec());
|
||||||
|
k
|
||||||
|
}
|
||||||
|
|
||||||
|
fn emplace(&mut self, key: H256, value: Bytes) {
|
||||||
|
let key = combine_key(&self.address, &key);
|
||||||
|
self.db.emplace(key, value.to_vec())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn kill(&mut self, key: &H256) {
|
||||||
|
let key = combine_key(&self.address, key);
|
||||||
|
self.db.kill(&key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Diff between two accounts.
|
//! Diff between two accounts.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Evm input params.
|
//! Evm input params.
|
||||||
use util::hash::*;
|
use util::hash::*;
|
||||||
use util::uint::*;
|
use util::uint::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethcore basic typenames.
|
//! Ethcore basic typenames.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Blockchain block.
|
//! Blockchain block.
|
||||||
|
|
||||||
#![allow(ptr_arg)] // Because of &LastHashes -> &Vec<_>
|
#![allow(ptr_arg)] // Because of &LastHashes -> &Vec<_>
|
||||||
@ -14,7 +30,7 @@ pub struct Block {
|
|||||||
/// The header of this block.
|
/// The header of this block.
|
||||||
pub header: Header,
|
pub header: Header,
|
||||||
/// The transactions in this block.
|
/// The transactions in this block.
|
||||||
pub transactions: Vec<Transaction>,
|
pub transactions: Vec<SignedTransaction>,
|
||||||
/// The uncles of this block.
|
/// The uncles of this block.
|
||||||
pub uncles: Vec<Header>,
|
pub uncles: Vec<Header>,
|
||||||
}
|
}
|
||||||
@ -62,7 +78,7 @@ impl Decodable for Block {
|
|||||||
/// Internal type for a block's common elements.
|
/// Internal type for a block's common elements.
|
||||||
// TODO: rename to ExecutedBlock
|
// TODO: rename to ExecutedBlock
|
||||||
// TODO: use BareBlock
|
// TODO: use BareBlock
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug)]
|
||||||
pub struct ExecutedBlock {
|
pub struct ExecutedBlock {
|
||||||
base: Block,
|
base: Block,
|
||||||
|
|
||||||
@ -76,7 +92,7 @@ pub struct BlockRefMut<'a> {
|
|||||||
/// Block header.
|
/// Block header.
|
||||||
pub header: &'a Header,
|
pub header: &'a Header,
|
||||||
/// Block transactions.
|
/// Block transactions.
|
||||||
pub transactions: &'a Vec<Transaction>,
|
pub transactions: &'a Vec<SignedTransaction>,
|
||||||
/// Block uncles.
|
/// Block uncles.
|
||||||
pub uncles: &'a Vec<Header>,
|
pub uncles: &'a Vec<Header>,
|
||||||
/// Transaction receipts.
|
/// Transaction receipts.
|
||||||
@ -113,7 +129,7 @@ pub trait IsBlock {
|
|||||||
fn state(&self) -> &State { &self.block().state }
|
fn state(&self) -> &State { &self.block().state }
|
||||||
|
|
||||||
/// Get all information on transactions in this block.
|
/// Get all information on transactions in this block.
|
||||||
fn transactions(&self) -> &Vec<Transaction> { &self.block().base.transactions }
|
fn transactions(&self) -> &Vec<SignedTransaction> { &self.block().base.transactions }
|
||||||
|
|
||||||
/// Get all information on receipts in this block.
|
/// Get all information on receipts in this block.
|
||||||
fn receipts(&self) -> &Vec<Receipt> { &self.block().receipts }
|
fn receipts(&self) -> &Vec<Receipt> { &self.block().receipts }
|
||||||
@ -228,7 +244,7 @@ impl<'x, 'y> OpenBlock<'x, 'y> {
|
|||||||
/// Push a transaction into the block.
|
/// Push a transaction into the block.
|
||||||
///
|
///
|
||||||
/// If valid, it will be executed, and archived together with the receipt.
|
/// If valid, it will be executed, and archived together with the receipt.
|
||||||
pub fn push_transaction(&mut self, t: Transaction, h: Option<H256>) -> Result<&Receipt, Error> {
|
pub fn push_transaction(&mut self, t: SignedTransaction, h: Option<H256>) -> Result<&Receipt, Error> {
|
||||||
let env_info = self.env_info();
|
let env_info = self.env_info();
|
||||||
// info!("env_info says gas_used={}", env_info.gas_used);
|
// info!("env_info says gas_used={}", env_info.gas_used);
|
||||||
match self.block.state.apply(&env_info, self.engine, &t) {
|
match self.block.state.apply(&env_info, self.engine, &t) {
|
||||||
@ -316,11 +332,13 @@ impl IsBlock for SealedBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Enact the block given by block header, transactions and uncles
|
/// Enact the block given by block header, transactions and uncles
|
||||||
pub fn enact<'x, 'y>(header: &Header, transactions: &[Transaction], uncles: &[Header], engine: &'x Engine, db: JournalDB, parent: &Header, last_hashes: &'y LastHashes) -> Result<ClosedBlock<'x, 'y>, Error> {
|
pub fn enact<'x, 'y>(header: &Header, transactions: &[SignedTransaction], uncles: &[Header], engine: &'x Engine, db: JournalDB, parent: &Header, last_hashes: &'y LastHashes) -> Result<ClosedBlock<'x, 'y>, Error> {
|
||||||
{
|
{
|
||||||
|
if ::log::max_log_level() >= ::log::LogLevel::Trace {
|
||||||
let s = State::from_existing(db.clone(), parent.state_root().clone(), engine.account_start_nonce());
|
let s = State::from_existing(db.clone(), parent.state_root().clone(), engine.account_start_nonce());
|
||||||
trace!("enact(): root={}, author={}, author_balance={}\n", s.root(), header.author(), s.balance(&header.author()));
|
trace!("enact(): root={}, author={}, author_balance={}\n", s.root(), header.author(), s.balance(&header.author()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut b = OpenBlock::new(engine, db, parent, last_hashes, header.author().clone(), header.extra_data().clone());
|
let mut b = OpenBlock::new(engine, db, parent, last_hashes, header.author().clone(), header.extra_data().clone());
|
||||||
b.set_difficulty(*header.difficulty());
|
b.set_difficulty(*header.difficulty());
|
||||||
@ -363,10 +381,10 @@ mod tests {
|
|||||||
let engine = Spec::new_test().to_engine().unwrap();
|
let engine = Spec::new_test().to_engine().unwrap();
|
||||||
let genesis_header = engine.spec().genesis_header();
|
let genesis_header = engine.spec().genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let db = db_result.reference_mut();
|
let mut db = db_result.take();
|
||||||
engine.spec().ensure_db_good(db);
|
engine.spec().ensure_db_good(&mut db);
|
||||||
let last_hashes = vec![genesis_header.hash()];
|
let last_hashes = vec![genesis_header.hash()];
|
||||||
let b = OpenBlock::new(engine.deref(), db.clone(), &genesis_header, &last_hashes, Address::zero(), vec![]);
|
let b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]);
|
||||||
let b = b.close();
|
let b = b.close();
|
||||||
let _ = b.seal(vec![]);
|
let _ = b.seal(vec![]);
|
||||||
}
|
}
|
||||||
@ -378,16 +396,16 @@ mod tests {
|
|||||||
let genesis_header = engine.spec().genesis_header();
|
let genesis_header = engine.spec().genesis_header();
|
||||||
|
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let db = db_result.reference_mut();
|
let mut db = db_result.take();
|
||||||
engine.spec().ensure_db_good(db);
|
engine.spec().ensure_db_good(&mut db);
|
||||||
let b = OpenBlock::new(engine.deref(), db.clone(), &genesis_header, &vec![genesis_header.hash()], Address::zero(), vec![]).close().seal(vec![]).unwrap();
|
let b = OpenBlock::new(engine.deref(), db, &genesis_header, &vec![genesis_header.hash()], Address::zero(), vec![]).close().seal(vec![]).unwrap();
|
||||||
let orig_bytes = b.rlp_bytes();
|
let orig_bytes = b.rlp_bytes();
|
||||||
let orig_db = b.drain();
|
let orig_db = b.drain();
|
||||||
|
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let db = db_result.reference_mut();
|
let mut db = db_result.take();
|
||||||
engine.spec().ensure_db_good(db);
|
engine.spec().ensure_db_good(&mut db);
|
||||||
let e = enact_and_seal(&orig_bytes, engine.deref(), db.clone(), &genesis_header, &vec![genesis_header.hash()]).unwrap();
|
let e = enact_and_seal(&orig_bytes, engine.deref(), db, &genesis_header, &vec![genesis_header.hash()]).unwrap();
|
||||||
|
|
||||||
assert_eq!(e.rlp_bytes(), orig_bytes);
|
assert_eq!(e.rlp_bytes(), orig_bytes);
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! A queue of blocks. Sits between network or other I/O and the BlockChain.
|
//! A queue of blocks. Sits between network or other I/O and the BlockChain.
|
||||||
//! Sorts them ready for blockchain insertion.
|
//! Sorts them ready for blockchain insertion.
|
||||||
use std::thread::{JoinHandle, self};
|
use std::thread::{JoinHandle, self};
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Blockchain database.
|
//! Blockchain database.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
@ -93,7 +109,7 @@ pub trait BlockProvider {
|
|||||||
|
|
||||||
/// Get a list of transactions for a given block.
|
/// Get a list of transactions for a given block.
|
||||||
/// Returns None if block deos not exist.
|
/// Returns None if block deos not exist.
|
||||||
fn transactions(&self, hash: &H256) -> Option<Vec<Transaction>> {
|
fn transactions(&self, hash: &H256) -> Option<Vec<SignedTransaction>> {
|
||||||
self.block(hash).map(|bytes| BlockView::new(&bytes).transactions())
|
self.block(hash).map(|bytes| BlockView::new(&bytes).transactions())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use crypto::sha2::Sha256;
|
use crypto::sha2::Sha256;
|
||||||
use crypto::ripemd160::Ripemd160;
|
use crypto::ripemd160::Ripemd160;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Blockchain database client.
|
//! Blockchain database client.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
@ -139,10 +155,10 @@ impl ClientReport {
|
|||||||
pub struct Client {
|
pub struct Client {
|
||||||
chain: Arc<RwLock<BlockChain>>,
|
chain: Arc<RwLock<BlockChain>>,
|
||||||
engine: Arc<Box<Engine>>,
|
engine: Arc<Box<Engine>>,
|
||||||
state_db: JournalDB,
|
state_db: Arc<DB>,
|
||||||
|
state_journal: Mutex<JournalDB>,
|
||||||
block_queue: RwLock<BlockQueue>,
|
block_queue: RwLock<BlockQueue>,
|
||||||
report: RwLock<ClientReport>,
|
report: RwLock<ClientReport>,
|
||||||
uncommited_states: RwLock<HashMap<H256, JournalDB>>,
|
|
||||||
import_lock: Mutex<()>
|
import_lock: Mutex<()>
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,16 +196,16 @@ impl Client {
|
|||||||
|
|
||||||
let engine = Arc::new(try!(spec.to_engine()));
|
let engine = Arc::new(try!(spec.to_engine()));
|
||||||
let mut state_db = JournalDB::new_with_arc(db.clone());
|
let mut state_db = JournalDB::new_with_arc(db.clone());
|
||||||
if engine.spec().ensure_db_good(&mut state_db) {
|
if state_db.is_empty() && engine.spec().ensure_db_good(&mut state_db) {
|
||||||
state_db.commit(0, &engine.spec().genesis_header().hash(), None).expect("Error commiting genesis state to state DB");
|
state_db.commit(0, &engine.spec().genesis_header().hash(), None).expect("Error commiting genesis state to state DB");
|
||||||
}
|
}
|
||||||
Ok(Arc::new(Client {
|
Ok(Arc::new(Client {
|
||||||
chain: chain,
|
chain: chain,
|
||||||
engine: engine.clone(),
|
engine: engine.clone(),
|
||||||
state_db: state_db,
|
state_db: db.clone(),
|
||||||
|
state_journal: Mutex::new(JournalDB::new_with_arc(db)),
|
||||||
block_queue: RwLock::new(BlockQueue::new(engine, message_channel)),
|
block_queue: RwLock::new(BlockQueue::new(engine, message_channel)),
|
||||||
report: RwLock::new(Default::default()),
|
report: RwLock::new(Default::default()),
|
||||||
uncommited_states: RwLock::new(HashMap::new()),
|
|
||||||
import_lock: Mutex::new(()),
|
import_lock: Mutex::new(()),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -242,7 +258,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let db = self.state_db.clone();
|
let db = self.state_journal.lock().unwrap().clone();
|
||||||
let result = match enact_verified(&block, self.engine.deref().deref(), db, &parent, &last_hashes) {
|
let result = match enact_verified(&block, self.engine.deref().deref(), db, &parent, &last_hashes) {
|
||||||
Ok(b) => b,
|
Ok(b) => b,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -277,14 +293,9 @@ impl Client {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clear cached state overlay
|
|
||||||
pub fn clear_state(&self, hash: &H256) {
|
|
||||||
self.uncommited_states.write().unwrap().remove(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get a copy of the best block's state.
|
/// Get a copy of the best block's state.
|
||||||
pub fn state(&self) -> State {
|
pub fn state(&self) -> State {
|
||||||
State::from_existing(self.state_db.clone(), HeaderView::new(&self.best_block_header()).state_root(), self.engine.account_start_nonce())
|
State::from_existing(JournalDB::new_with_arc(self.state_db.clone()), HeaderView::new(&self.best_block_header()).state_root(), self.engine.account_start_nonce())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get info on the cache.
|
/// Get info on the cache.
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
pub use util::*;
|
pub use util::*;
|
||||||
pub use basic_types::*;
|
pub use basic_types::*;
|
||||||
pub use error::*;
|
pub use error::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use block::ExecutedBlock;
|
use block::ExecutedBlock;
|
||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
@ -56,9 +72,9 @@ pub trait Engine : Sync + Send {
|
|||||||
/// Additional verification for transactions in blocks.
|
/// Additional verification for transactions in blocks.
|
||||||
// TODO: Add flags for which bits of the transaction to check.
|
// TODO: Add flags for which bits of the transaction to check.
|
||||||
// TODO: consider including State in the params.
|
// TODO: consider including State in the params.
|
||||||
fn verify_transaction_basic(&self, _t: &Transaction, _header: &Header) -> Result<(), Error> { Ok(()) }
|
fn verify_transaction_basic(&self, _t: &SignedTransaction, _header: &Header) -> Result<(), Error> { Ok(()) }
|
||||||
/// Verify a particular transaction is valid.
|
/// Verify a particular transaction is valid.
|
||||||
fn verify_transaction(&self, _t: &Transaction, _header: &Header) -> Result<(), Error> { Ok(()) }
|
fn verify_transaction(&self, _t: &SignedTransaction, _header: &Header) -> Result<(), Error> { Ok(()) }
|
||||||
|
|
||||||
/// Don't forget to call Super::populateFromParent when subclassing & overriding.
|
/// Don't forget to call Super::populateFromParent when subclassing & overriding.
|
||||||
// TODO: consider including State in the params.
|
// TODO: consider including State in the params.
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! General error types for use in ethcore.
|
//! General error types for use in ethcore.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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 ethash;
|
extern crate ethash;
|
||||||
|
|
||||||
use self::ethash::{quick_get_difficulty, EthashManager, H256 as EH256};
|
use self::ethash::{quick_get_difficulty, EthashManager, H256 as EH256};
|
||||||
@ -154,14 +170,14 @@ impl Engine for Ethash {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_transaction_basic(&self, t: &Transaction, header: &Header) -> result::Result<(), Error> {
|
fn verify_transaction_basic(&self, t: &SignedTransaction, header: &Header) -> result::Result<(), Error> {
|
||||||
if header.number() >= self.u64_param("frontierCompatibilityModeLimit") {
|
if header.number() >= self.u64_param("frontierCompatibilityModeLimit") {
|
||||||
try!(t.check_low_s());
|
try!(t.check_low_s());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_transaction(&self, t: &Transaction, _header: &Header) -> Result<(), Error> {
|
fn verify_transaction(&self, t: &SignedTransaction, _header: &Header) -> Result<(), Error> {
|
||||||
t.sender().map(|_|()) // Perform EC recovery and cache sender
|
t.sender().map(|_|()) // Perform EC recovery and cache sender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,10 +248,10 @@ fn on_close_block() {
|
|||||||
let engine = new_morden().to_engine().unwrap();
|
let engine = new_morden().to_engine().unwrap();
|
||||||
let genesis_header = engine.spec().genesis_header();
|
let genesis_header = engine.spec().genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.reference_mut();
|
let mut db = db_result.take();
|
||||||
engine.spec().ensure_db_good(db);
|
engine.spec().ensure_db_good(&mut db);
|
||||||
let last_hashes = vec![genesis_header.hash()];
|
let last_hashes = vec![genesis_header.hash()];
|
||||||
let b = OpenBlock::new(engine.deref(), db.clone(), &genesis_header, &last_hashes, Address::zero(), vec![]);
|
let b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]);
|
||||||
let b = b.close();
|
let b = b.close();
|
||||||
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
assert_eq!(b.state().balance(&Address::zero()), U256::from_str("4563918244f40000").unwrap());
|
||||||
}
|
}
|
||||||
@ -246,10 +262,10 @@ fn on_close_block_with_uncle() {
|
|||||||
let engine = new_morden().to_engine().unwrap();
|
let engine = new_morden().to_engine().unwrap();
|
||||||
let genesis_header = engine.spec().genesis_header();
|
let genesis_header = engine.spec().genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.reference_mut();
|
let mut db = db_result.take();
|
||||||
engine.spec().ensure_db_good(db);
|
engine.spec().ensure_db_good(&mut db);
|
||||||
let last_hashes = vec![genesis_header.hash()];
|
let last_hashes = vec![genesis_header.hash()];
|
||||||
let mut b = OpenBlock::new(engine.deref(), db.clone(), &genesis_header, &last_hashes, Address::zero(), vec![]);
|
let mut b = OpenBlock::new(engine.deref(), db, &genesis_header, &last_hashes, Address::zero(), vec![]);
|
||||||
let mut uncle = Header::new();
|
let mut uncle = Header::new();
|
||||||
let uncle_author = address_from_hex("ef2d6d194084c2de36e0dabfce45d046b37d1106");
|
let uncle_author = address_from_hex("ef2d6d194084c2de36e0dabfce45d046b37d1106");
|
||||||
uncle.author = uncle_author.clone();
|
uncle.author = uncle_author.clone();
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethereum protocol module.
|
//! Ethereum protocol module.
|
||||||
//!
|
//!
|
||||||
//! Contains all Ethereum network specific stuff, such as denominations and
|
//! Contains all Ethereum network specific stuff, such as denominations and
|
||||||
@ -44,9 +60,9 @@ mod tests {
|
|||||||
let engine = new_morden().to_engine().unwrap();
|
let engine = new_morden().to_engine().unwrap();
|
||||||
let genesis_header = engine.spec().genesis_header();
|
let genesis_header = engine.spec().genesis_header();
|
||||||
let mut db_result = get_temp_journal_db();
|
let mut db_result = get_temp_journal_db();
|
||||||
let mut db = db_result.reference_mut();
|
let mut db = db_result.take();
|
||||||
engine.spec().ensure_db_good(db);
|
engine.spec().ensure_db_good(&mut db);
|
||||||
let s = State::from_existing(db.clone(), genesis_header.state_root.clone(), engine.account_start_nonce());
|
let s = State::from_existing(db, genesis_header.state_root.clone(), engine.account_start_nonce());
|
||||||
assert_eq!(s.balance(&address_from_hex("0000000000000000000000000000000000000001")), U256::from(1u64));
|
assert_eq!(s.balance(&address_from_hex("0000000000000000000000000000000000000001")), U256::from(1u64));
|
||||||
assert_eq!(s.balance(&address_from_hex("0000000000000000000000000000000000000002")), U256::from(1u64));
|
assert_eq!(s.balance(&address_from_hex("0000000000000000000000000000000000000002")), U256::from(1u64));
|
||||||
assert_eq!(s.balance(&address_from_hex("0000000000000000000000000000000000000003")), U256::from(1u64));
|
assert_eq!(s.balance(&address_from_hex("0000000000000000000000000000000000000003")), U256::from(1u64));
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Evm interface.
|
//! Evm interface.
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Interface for Evm externalities.
|
//! Interface for Evm externalities.
|
||||||
|
|
||||||
use common::Bytes;
|
use common::Bytes;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Evm factory.
|
//! Evm factory.
|
||||||
//!
|
//!
|
||||||
//! TODO: consider spliting it into two separate files.
|
//! TODO: consider spliting it into two separate files.
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! VM Instructions list and utility functions
|
//! VM Instructions list and utility functions
|
||||||
|
|
||||||
pub type Instruction = u8;
|
pub type Instruction = u8;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
///! Rust VM implementation
|
///! Rust VM implementation
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
@ -263,7 +279,7 @@ pub struct Interpreter;
|
|||||||
|
|
||||||
impl evm::Evm for Interpreter {
|
impl evm::Evm for Interpreter {
|
||||||
fn exec(&self, params: ActionParams, ext: &mut evm::Ext) -> evm::Result {
|
fn exec(&self, params: ActionParams, ext: &mut evm::Ext) -> evm::Result {
|
||||||
let code = ¶ms.code.clone().unwrap();
|
let code = ¶ms.code.as_ref().unwrap();
|
||||||
let valid_jump_destinations = self.find_jump_destinations(&code);
|
let valid_jump_destinations = self.find_jump_destinations(&code);
|
||||||
|
|
||||||
let mut current_gas = params.gas.clone();
|
let mut current_gas = params.gas.clone();
|
||||||
@ -728,15 +744,18 @@ impl Interpreter {
|
|||||||
let big_id = stack.pop_back();
|
let big_id = stack.pop_back();
|
||||||
let id = big_id.low_u64() as usize;
|
let id = big_id.low_u64() as usize;
|
||||||
let max = id.wrapping_add(32);
|
let max = id.wrapping_add(32);
|
||||||
let data = params.data.clone().unwrap_or_else(|| vec![]);
|
if let Some(data) = params.data.as_ref() {
|
||||||
let bound = cmp::min(data.len(), max);
|
let bound = cmp::min(data.len(), max);
|
||||||
if id < bound && big_id < U256::from(data.len()) {
|
if id < bound && big_id < U256::from(data.len()) {
|
||||||
let mut v = data[id..bound].to_vec();
|
let mut v = [0u8; 32];
|
||||||
v.resize(32, 0);
|
v[0..bound-id].clone_from_slice(&data[id..bound]);
|
||||||
stack.push(U256::from(&v[..]))
|
stack.push(U256::from(&v[..]))
|
||||||
} else {
|
} else {
|
||||||
stack.push(U256::zero())
|
stack.push(U256::zero())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
stack.push(U256::zero())
|
||||||
|
}
|
||||||
},
|
},
|
||||||
instructions::CALLDATASIZE => {
|
instructions::CALLDATASIZE => {
|
||||||
stack.push(U256::from(params.data.clone().map_or(0, |l| l.len())));
|
stack.push(U256::from(params.data.clone().map_or(0, |l| l.len())));
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Just in time compiler execution environment.
|
//! Just in time compiler execution environment.
|
||||||
use common::*;
|
use common::*;
|
||||||
use evmjit;
|
use evmjit;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethereum virtual machine.
|
//! Ethereum virtual machine.
|
||||||
|
|
||||||
pub mod ext;
|
pub mod ext;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Cost schedule and other parameterisations for the EVM.
|
//! Cost schedule and other parameterisations for the EVM.
|
||||||
|
|
||||||
/// Definition of the cost schedule and other parameterisations for the EVM.
|
/// Definition of the cost schedule and other parameterisations for the EVM.
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use evm;
|
use evm;
|
||||||
use evm::{Ext, Schedule, Factory, VMType, ContractCreateResult, MessageCallResult};
|
use evm::{Ext, Schedule, Factory, VMType, ContractCreateResult, MessageCallResult};
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Transaction Execution environment.
|
//! Transaction Execution environment.
|
||||||
use common::*;
|
use common::*;
|
||||||
use state::*;
|
use state::*;
|
||||||
@ -86,7 +102,7 @@ impl<'a> Executive<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// This funtion should be used to execute transaction.
|
/// This funtion should be used to execute transaction.
|
||||||
pub fn transact(&'a mut self, t: &Transaction) -> Result<Executed, Error> {
|
pub fn transact(&'a mut self, t: &SignedTransaction) -> Result<Executed, Error> {
|
||||||
let sender = try!(t.sender());
|
let sender = try!(t.sender());
|
||||||
let nonce = self.state.nonce(&sender);
|
let nonce = self.state.nonce(&sender);
|
||||||
|
|
||||||
@ -194,7 +210,7 @@ impl<'a> Executive<'a> {
|
|||||||
/// Returns either gas_left or `evm::Error`.
|
/// Returns either gas_left or `evm::Error`.
|
||||||
pub fn call(&mut self, params: ActionParams, substate: &mut Substate, mut output: BytesRef) -> evm::Result {
|
pub fn call(&mut self, params: ActionParams, substate: &mut Substate, mut output: BytesRef) -> evm::Result {
|
||||||
// backup used in case of running out of gas
|
// backup used in case of running out of gas
|
||||||
let backup = self.state.clone();
|
self.state.snapshot();
|
||||||
|
|
||||||
// at first, transfer value to destination
|
// at first, transfer value to destination
|
||||||
if let ActionValue::Transfer(val) = params.value {
|
if let ActionValue::Transfer(val) = params.value {
|
||||||
@ -212,11 +228,12 @@ impl<'a> Executive<'a> {
|
|||||||
match cost <= params.gas {
|
match cost <= params.gas {
|
||||||
true => {
|
true => {
|
||||||
self.engine.execute_builtin(¶ms.code_address, data, &mut output);
|
self.engine.execute_builtin(¶ms.code_address, data, &mut output);
|
||||||
|
self.state.clear_snapshot();
|
||||||
Ok(params.gas - cost)
|
Ok(params.gas - cost)
|
||||||
},
|
},
|
||||||
// just drain the whole gas
|
// just drain the whole gas
|
||||||
false => {
|
false => {
|
||||||
self.state.revert(backup);
|
self.state.revert_snapshot();
|
||||||
Err(evm::Error::OutOfGas)
|
Err(evm::Error::OutOfGas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -232,11 +249,12 @@ impl<'a> Executive<'a> {
|
|||||||
|
|
||||||
trace!("exec: sstore-clears={}\n", unconfirmed_substate.sstore_clears_count);
|
trace!("exec: sstore-clears={}\n", unconfirmed_substate.sstore_clears_count);
|
||||||
trace!("exec: substate={:?}; unconfirmed_substate={:?}\n", substate, unconfirmed_substate);
|
trace!("exec: substate={:?}; unconfirmed_substate={:?}\n", substate, unconfirmed_substate);
|
||||||
self.enact_result(&res, substate, unconfirmed_substate, backup);
|
self.enact_result(&res, substate, unconfirmed_substate);
|
||||||
trace!("exec: new substate={:?}\n", substate);
|
trace!("exec: new substate={:?}\n", substate);
|
||||||
res
|
res
|
||||||
} else {
|
} else {
|
||||||
// otherwise, nothing
|
// otherwise, nothing
|
||||||
|
self.state.clear_snapshot();
|
||||||
Ok(params.gas)
|
Ok(params.gas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +264,7 @@ impl<'a> Executive<'a> {
|
|||||||
/// Modifies the substate.
|
/// Modifies the substate.
|
||||||
pub fn create(&mut self, params: ActionParams, substate: &mut Substate) -> evm::Result {
|
pub fn create(&mut self, params: ActionParams, substate: &mut Substate) -> evm::Result {
|
||||||
// backup used in case of running out of gas
|
// backup used in case of running out of gas
|
||||||
let backup = self.state.clone();
|
self.state.snapshot();
|
||||||
|
|
||||||
// part of substate that may be reverted
|
// part of substate that may be reverted
|
||||||
let mut unconfirmed_substate = Substate::new();
|
let mut unconfirmed_substate = Substate::new();
|
||||||
@ -263,12 +281,12 @@ impl<'a> Executive<'a> {
|
|||||||
let res = {
|
let res = {
|
||||||
self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::InitContract)
|
self.exec_vm(params, &mut unconfirmed_substate, OutputPolicy::InitContract)
|
||||||
};
|
};
|
||||||
self.enact_result(&res, substate, unconfirmed_substate, backup);
|
self.enact_result(&res, substate, unconfirmed_substate);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finalizes the transaction (does refunds and suicides).
|
/// Finalizes the transaction (does refunds and suicides).
|
||||||
fn finalize(&mut self, t: &Transaction, substate: Substate, result: evm::Result) -> ExecutionResult {
|
fn finalize(&mut self, t: &SignedTransaction, substate: Substate, result: evm::Result) -> ExecutionResult {
|
||||||
let schedule = self.engine.schedule(self.info);
|
let schedule = self.engine.schedule(self.info);
|
||||||
|
|
||||||
// refunds from SSTORE nonzero -> zero
|
// refunds from SSTORE nonzero -> zero
|
||||||
@ -324,16 +342,19 @@ impl<'a> Executive<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enact_result(&mut self, result: &evm::Result, substate: &mut Substate, un_substate: Substate, backup: State) {
|
fn enact_result(&mut self, result: &evm::Result, substate: &mut Substate, un_substate: Substate) {
|
||||||
match *result {
|
match *result {
|
||||||
Err(evm::Error::OutOfGas)
|
Err(evm::Error::OutOfGas)
|
||||||
| Err(evm::Error::BadJumpDestination {..})
|
| Err(evm::Error::BadJumpDestination {..})
|
||||||
| Err(evm::Error::BadInstruction {.. })
|
| Err(evm::Error::BadInstruction {.. })
|
||||||
| Err(evm::Error::StackUnderflow {..})
|
| Err(evm::Error::StackUnderflow {..})
|
||||||
| Err(evm::Error::OutOfStack {..}) => {
|
| Err(evm::Error::OutOfStack {..}) => {
|
||||||
self.state.revert(backup);
|
self.state.revert_snapshot();
|
||||||
},
|
},
|
||||||
Ok(_) | Err(evm::Error::Internal) => substate.accrue(un_substate)
|
Ok(_) | Err(evm::Error::Internal) => {
|
||||||
|
self.state.clear_snapshot();
|
||||||
|
substate.accrue(un_substate)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -685,9 +706,15 @@ mod tests {
|
|||||||
// test is incorrect, mk
|
// test is incorrect, mk
|
||||||
evm_test_ignore!{test_transact_simple: test_transact_simple_jit, test_transact_simple_int}
|
evm_test_ignore!{test_transact_simple: test_transact_simple_jit, test_transact_simple_int}
|
||||||
fn test_transact_simple(factory: Factory) {
|
fn test_transact_simple(factory: Factory) {
|
||||||
let mut t = Transaction::new_create(U256::from(17), "3331600055".from_hex().unwrap(), U256::from(100_000), U256::zero(), U256::zero());
|
|
||||||
let keypair = KeyPair::create().unwrap();
|
let keypair = KeyPair::create().unwrap();
|
||||||
t.sign(&keypair.secret());
|
let t = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
value: U256::from(17),
|
||||||
|
data: "3331600055".from_hex().unwrap(),
|
||||||
|
gas: U256::from(100_000),
|
||||||
|
gas_price: U256::zero(),
|
||||||
|
nonce: U256::zero()
|
||||||
|
}.sign(&keypair.secret());
|
||||||
let sender = t.sender().unwrap();
|
let sender = t.sender().unwrap();
|
||||||
let contract = contract_address(&sender, &U256::zero());
|
let contract = contract_address(&sender, &U256::zero());
|
||||||
|
|
||||||
@ -717,8 +744,14 @@ mod tests {
|
|||||||
|
|
||||||
evm_test!{test_transact_invalid_sender: test_transact_invalid_sender_jit, test_transact_invalid_sender_int}
|
evm_test!{test_transact_invalid_sender: test_transact_invalid_sender_jit, test_transact_invalid_sender_int}
|
||||||
fn test_transact_invalid_sender(factory: Factory) {
|
fn test_transact_invalid_sender(factory: Factory) {
|
||||||
let t = Transaction::new_create(U256::from(17), "3331600055".from_hex().unwrap(), U256::from(100_000), U256::zero(), U256::zero());
|
let t = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
value: U256::from(17),
|
||||||
|
data: "3331600055".from_hex().unwrap(),
|
||||||
|
gas: U256::from(100_000),
|
||||||
|
gas_price: U256::zero(),
|
||||||
|
nonce: U256::zero()
|
||||||
|
}.fake_sign();
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
let mut state = state_result.reference_mut();
|
let mut state = state_result.reference_mut();
|
||||||
let mut info = EnvInfo::default();
|
let mut info = EnvInfo::default();
|
||||||
@ -738,9 +771,15 @@ mod tests {
|
|||||||
|
|
||||||
evm_test!{test_transact_invalid_nonce: test_transact_invalid_nonce_jit, test_transact_invalid_nonce_int}
|
evm_test!{test_transact_invalid_nonce: test_transact_invalid_nonce_jit, test_transact_invalid_nonce_int}
|
||||||
fn test_transact_invalid_nonce(factory: Factory) {
|
fn test_transact_invalid_nonce(factory: Factory) {
|
||||||
let mut t = Transaction::new_create(U256::from(17), "3331600055".from_hex().unwrap(), U256::from(100_000), U256::zero(), U256::one());
|
|
||||||
let keypair = KeyPair::create().unwrap();
|
let keypair = KeyPair::create().unwrap();
|
||||||
t.sign(&keypair.secret());
|
let t = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
value: U256::from(17),
|
||||||
|
data: "3331600055".from_hex().unwrap(),
|
||||||
|
gas: U256::from(100_000),
|
||||||
|
gas_price: U256::zero(),
|
||||||
|
nonce: U256::one()
|
||||||
|
}.sign(&keypair.secret());
|
||||||
let sender = t.sender().unwrap();
|
let sender = t.sender().unwrap();
|
||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
@ -764,9 +803,15 @@ mod tests {
|
|||||||
|
|
||||||
evm_test!{test_transact_gas_limit_reached: test_transact_gas_limit_reached_jit, test_transact_gas_limit_reached_int}
|
evm_test!{test_transact_gas_limit_reached: test_transact_gas_limit_reached_jit, test_transact_gas_limit_reached_int}
|
||||||
fn test_transact_gas_limit_reached(factory: Factory) {
|
fn test_transact_gas_limit_reached(factory: Factory) {
|
||||||
let mut t = Transaction::new_create(U256::from(17), "3331600055".from_hex().unwrap(), U256::from(80_001), U256::zero(), U256::zero());
|
|
||||||
let keypair = KeyPair::create().unwrap();
|
let keypair = KeyPair::create().unwrap();
|
||||||
t.sign(&keypair.secret());
|
let t = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
value: U256::from(17),
|
||||||
|
data: "3331600055".from_hex().unwrap(),
|
||||||
|
gas: U256::from(80_001),
|
||||||
|
gas_price: U256::zero(),
|
||||||
|
nonce: U256::zero()
|
||||||
|
}.sign(&keypair.secret());
|
||||||
let sender = t.sender().unwrap();
|
let sender = t.sender().unwrap();
|
||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
@ -791,9 +836,16 @@ mod tests {
|
|||||||
|
|
||||||
evm_test!{test_not_enough_cash: test_not_enough_cash_jit, test_not_enough_cash_int}
|
evm_test!{test_not_enough_cash: test_not_enough_cash_jit, test_not_enough_cash_int}
|
||||||
fn test_not_enough_cash(factory: Factory) {
|
fn test_not_enough_cash(factory: Factory) {
|
||||||
let mut t = Transaction::new_create(U256::from(18), "3331600055".from_hex().unwrap(), U256::from(100_000), U256::one(), U256::zero());
|
|
||||||
let keypair = KeyPair::create().unwrap();
|
let keypair = KeyPair::create().unwrap();
|
||||||
t.sign(&keypair.secret());
|
let t = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
value: U256::from(18),
|
||||||
|
data: "3331600055".from_hex().unwrap(),
|
||||||
|
gas: U256::from(100_000),
|
||||||
|
gas_price: U256::one(),
|
||||||
|
nonce: U256::zero()
|
||||||
|
}.sign(&keypair.secret());
|
||||||
let sender = t.sender().unwrap();
|
let sender = t.sender().unwrap();
|
||||||
|
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Transaction Execution environment.
|
//! Transaction Execution environment.
|
||||||
use common::*;
|
use common::*;
|
||||||
use state::*;
|
use state::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Blockchain DB extras.
|
//! Blockchain DB extras.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Block header.
|
//! Block header.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use client::{BlockChainClient,Client};
|
use client::{BlockChainClient,Client};
|
||||||
use pod_state::*;
|
use pod_state::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use client::{BlockChainClient,Client};
|
use client::{BlockChainClient,Client};
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use state::*;
|
use state::*;
|
||||||
use executive::*;
|
use executive::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use super::chain::json_chain_test;
|
use super::chain::json_chain_test;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use super::state::json_chain_test;
|
use super::state::json_chain_test;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod test_common;
|
mod test_common;
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
use pod_state::*;
|
use pod_state::*;
|
||||||
@ -33,7 +49,7 @@ pub fn json_chain_test(json_data: &[u8], era: ChainEra) -> Vec<String> {
|
|||||||
|
|
||||||
flush!(" - {}...", name);
|
flush!(" - {}...", name);
|
||||||
|
|
||||||
let t = Transaction::from_json(&test["transaction"]);
|
let t = SignedTransaction::from_json(&test["transaction"]);
|
||||||
let env = EnvInfo::from_json(&test["env"]);
|
let env = EnvInfo::from_json(&test["env"]);
|
||||||
let _out = Bytes::from_json(&test["out"]);
|
let _out = Bytes::from_json(&test["out"]);
|
||||||
let post_state_root = xjson!(&test["postStateRoot"]);
|
let post_state_root = xjson!(&test["postStateRoot"]);
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
pub use common::*;
|
pub use common::*;
|
||||||
|
|
||||||
macro_rules! test {
|
macro_rules! test {
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use super::test_common::*;
|
use super::test_common::*;
|
||||||
use evm;
|
use evm;
|
||||||
|
|
||||||
@ -6,7 +22,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
let mut failed = Vec::new();
|
let mut failed = Vec::new();
|
||||||
let old_schedule = evm::Schedule::new_frontier();
|
let old_schedule = evm::Schedule::new_frontier();
|
||||||
let new_schedule = evm::Schedule::new_homestead();
|
let new_schedule = evm::Schedule::new_homestead();
|
||||||
let ot = RefCell::new(Transaction::new());
|
let ot = RefCell::new(None);
|
||||||
for (name, test) in json.as_object().unwrap() {
|
for (name, test) in json.as_object().unwrap() {
|
||||||
let mut fail = false;
|
let mut fail = false;
|
||||||
let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.clone()); println!("Transaction: {:?}", ot.borrow()); fail = true };
|
let mut fail_unless = |cond: bool| if !cond && !fail { failed.push(name.clone()); println!("Transaction: {:?}", ot.borrow()); fail = true };
|
||||||
@ -15,7 +31,7 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
.and_then(|s| BlockNumber::from_str(s).ok())
|
.and_then(|s| BlockNumber::from_str(s).ok())
|
||||||
.unwrap_or(0) { x if x < 1_000_000 => &old_schedule, _ => &new_schedule };
|
.unwrap_or(0) { x if x < 1_000_000 => &old_schedule, _ => &new_schedule };
|
||||||
let rlp = Bytes::from_json(&test["rlp"]);
|
let rlp = Bytes::from_json(&test["rlp"]);
|
||||||
let res = UntrustedRlp::new(&rlp).as_val().map_err(From::from).and_then(|t: Transaction| t.validate(schedule, schedule.have_delegate_call));
|
let res = UntrustedRlp::new(&rlp).as_val().map_err(From::from).and_then(|t: SignedTransaction| t.validate(schedule, schedule.have_delegate_call));
|
||||||
fail_unless(test.find("transaction").is_none() == res.is_err());
|
fail_unless(test.find("transaction").is_none() == res.is_err());
|
||||||
if let (Some(&Json::Object(ref tx)), Some(&Json::String(ref expect_sender))) = (test.find("transaction"), test.find("sender")) {
|
if let (Some(&Json::Object(ref tx)), Some(&Json::String(ref expect_sender))) = (test.find("transaction"), test.find("sender")) {
|
||||||
let t = res.unwrap();
|
let t = res.unwrap();
|
||||||
@ -26,10 +42,10 @@ fn do_json_test(json_data: &[u8]) -> Vec<String> {
|
|||||||
fail_unless(t.nonce == xjson!(&tx["nonce"]));
|
fail_unless(t.nonce == xjson!(&tx["nonce"]));
|
||||||
fail_unless(t.value == xjson!(&tx["value"]));
|
fail_unless(t.value == xjson!(&tx["value"]));
|
||||||
if let Action::Call(ref to) = t.action {
|
if let Action::Call(ref to) = t.action {
|
||||||
*ot.borrow_mut() = t.clone();
|
*ot.borrow_mut() = Some(t.clone());
|
||||||
fail_unless(to == &xjson!(&tx["to"]));
|
fail_unless(to == &xjson!(&tx["to"]));
|
||||||
} else {
|
} else {
|
||||||
*ot.borrow_mut() = t.clone();
|
*ot.borrow_mut() = Some(t.clone());
|
||||||
fail_unless(Bytes::from_json(&tx["to"]).is_empty());
|
fail_unless(Bytes::from_json(&tx["to"]).is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![feature(cell_extras)]
|
#![feature(cell_extras)]
|
||||||
#![feature(augmented_assignments)]
|
#![feature(augmented_assignments)]
|
||||||
@ -83,6 +99,7 @@ pub mod header;
|
|||||||
pub mod service;
|
pub mod service;
|
||||||
pub mod spec;
|
pub mod spec;
|
||||||
pub mod views;
|
pub mod views;
|
||||||
|
pub mod receipt;
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
mod basic_types;
|
mod basic_types;
|
||||||
@ -96,9 +113,9 @@ mod state_diff;
|
|||||||
mod engine;
|
mod engine;
|
||||||
mod state;
|
mod state;
|
||||||
mod account;
|
mod account;
|
||||||
|
mod account_db;
|
||||||
mod action_params;
|
mod action_params;
|
||||||
mod transaction;
|
mod transaction;
|
||||||
mod receipt;
|
|
||||||
mod null_engine;
|
mod null_engine;
|
||||||
mod builtin;
|
mod builtin;
|
||||||
mod extras;
|
mod extras;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use basic_types::LogBloom;
|
use basic_types::LogBloom;
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use engine::Engine;
|
use engine::Engine;
|
||||||
use spec::Spec;
|
use spec::Spec;
|
||||||
use evm::Schedule;
|
use evm::Schedule;
|
||||||
|
@ -1,5 +1,22 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use account::*;
|
use account::*;
|
||||||
|
use account_db::*;
|
||||||
|
|
||||||
#[derive(Debug,Clone,PartialEq,Eq)]
|
#[derive(Debug,Clone,PartialEq,Eq)]
|
||||||
/// An account, expressed as Plain-Old-Data (hence the name).
|
/// An account, expressed as Plain-Old-Data (hence the name).
|
||||||
@ -44,7 +61,7 @@ impl PodAccount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Place additional data into given hash DB.
|
/// Place additional data into given hash DB.
|
||||||
pub fn insert_additional(&self, db: &mut HashDB) {
|
pub fn insert_additional(&self, db: &mut AccountDBMut) {
|
||||||
if !self.code.is_empty() {
|
if !self.code.is_empty() {
|
||||||
db.insert(&self.code);
|
db.insert(&self.code);
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use pod_account::*;
|
use pod_account::*;
|
||||||
|
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
//! Receipt
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use basic_types::LogBloom;
|
use basic_types::LogBloom;
|
||||||
use log_entry::LogEntry;
|
use log_entry::LogEntry;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Creates and registers client and network services.
|
//! Creates and registers client and network services.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
|
@ -1,9 +1,26 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Parameters for a block chain.
|
//! Parameters for a block chain.
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use engine::*;
|
use engine::*;
|
||||||
use pod_state::*;
|
use pod_state::*;
|
||||||
use null_engine::*;
|
use null_engine::*;
|
||||||
|
use account_db::*;
|
||||||
|
|
||||||
/// Convert JSON value to equivalent RLP representation.
|
/// Convert JSON value to equivalent RLP representation.
|
||||||
// TODO: handle container types.
|
// TODO: handle container types.
|
||||||
@ -262,8 +279,8 @@ impl Spec {
|
|||||||
t.insert(address.as_slice(), &account.rlp());
|
t.insert(address.as_slice(), &account.rlp());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (_, account) in self.genesis_state.get().iter() {
|
for (address, account) in self.genesis_state.get().iter() {
|
||||||
account.insert_additional(db);
|
account.insert_additional(&mut AccountDBMut::new(db, address));
|
||||||
}
|
}
|
||||||
assert!(db.contains(&self.state_root()));
|
assert!(db.contains(&self.state_root()));
|
||||||
true
|
true
|
||||||
|
@ -1,6 +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/>.
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use engine::Engine;
|
use engine::Engine;
|
||||||
use executive::Executive;
|
use executive::Executive;
|
||||||
|
use account_db::*;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature = "json-tests")]
|
#[cfg(feature = "json-tests")]
|
||||||
use pod_account::*;
|
use pod_account::*;
|
||||||
@ -13,12 +30,11 @@ use pod_state::PodState;
|
|||||||
pub type ApplyResult = Result<Receipt, Error>;
|
pub type ApplyResult = Result<Receipt, Error>;
|
||||||
|
|
||||||
/// Representation of the entire state of all accounts in the system.
|
/// Representation of the entire state of all accounts in the system.
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
db: JournalDB,
|
db: JournalDB,
|
||||||
root: H256,
|
root: H256,
|
||||||
cache: RefCell<HashMap<Address, Option<Account>>>,
|
cache: RefCell<HashMap<Address, Option<Account>>>,
|
||||||
|
snapshots: RefCell<Vec<HashMap<Address, Option<Option<Account>>>>>,
|
||||||
account_start_nonce: U256,
|
account_start_nonce: U256,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,6 +52,7 @@ impl State {
|
|||||||
db: db,
|
db: db,
|
||||||
root: root,
|
root: root,
|
||||||
cache: RefCell::new(HashMap::new()),
|
cache: RefCell::new(HashMap::new()),
|
||||||
|
snapshots: RefCell::new(Vec::new()),
|
||||||
account_start_nonce: account_start_nonce,
|
account_start_nonce: account_start_nonce,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,10 +68,63 @@ impl State {
|
|||||||
db: db,
|
db: db,
|
||||||
root: root,
|
root: root,
|
||||||
cache: RefCell::new(HashMap::new()),
|
cache: RefCell::new(HashMap::new()),
|
||||||
|
snapshots: RefCell::new(Vec::new()),
|
||||||
account_start_nonce: account_start_nonce,
|
account_start_nonce: account_start_nonce,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a recoverable snaphot of this state
|
||||||
|
pub fn snapshot(&mut self) {
|
||||||
|
self.snapshots.borrow_mut().push(HashMap::new());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Merge last snapshot with previous
|
||||||
|
pub fn clear_snapshot(&mut self) {
|
||||||
|
// merge with previous snapshot
|
||||||
|
let last = self.snapshots.borrow_mut().pop();
|
||||||
|
if let Some(mut snapshot) = last {
|
||||||
|
if let Some(ref mut prev) = self.snapshots.borrow_mut().last_mut() {
|
||||||
|
for (k, v) in snapshot.drain() {
|
||||||
|
prev.entry(k).or_insert(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Revert to snapshot
|
||||||
|
pub fn revert_snapshot(&mut self) {
|
||||||
|
if let Some(mut snapshot) = self.snapshots.borrow_mut().pop() {
|
||||||
|
for (k, v) in snapshot.drain() {
|
||||||
|
match v {
|
||||||
|
Some(v) => {
|
||||||
|
self.cache.borrow_mut().insert(k, v);
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
self.cache.borrow_mut().remove(&k);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert_cache(&self, address: &Address, account: Option<Account>) {
|
||||||
|
if let Some(ref mut snapshot) = self.snapshots.borrow_mut().last_mut() {
|
||||||
|
if !snapshot.contains_key(&address) {
|
||||||
|
snapshot.insert(address.clone(), self.cache.borrow_mut().insert(address.clone(), account));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.cache.borrow_mut().insert(address.clone(), account);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn note_cache(&self, address: &Address) {
|
||||||
|
if let Some(ref mut snapshot) = self.snapshots.borrow_mut().last_mut() {
|
||||||
|
if !snapshot.contains_key(&address) {
|
||||||
|
snapshot.insert(address.clone(), self.cache.borrow().get(address).cloned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Destroy the current object and return root and database.
|
/// Destroy the current object and return root and database.
|
||||||
pub fn drop(self) -> (H256, JournalDB) {
|
pub fn drop(self) -> (H256, JournalDB) {
|
||||||
(self.root, self.db)
|
(self.root, self.db)
|
||||||
@ -68,12 +138,12 @@ 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.cache.borrow_mut().insert(contract.clone(), Some(Account::new_contract(balance)));
|
self.insert_cache(&contract, Some(Account::new_contract(balance)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove an existing account.
|
/// Remove an existing account.
|
||||||
pub fn kill_account(&mut self, account: &Address) {
|
pub fn kill_account(&mut self, account: &Address) {
|
||||||
self.cache.borrow_mut().insert(account.clone(), None);
|
self.insert_cache(account, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine whether an account exists.
|
/// Determine whether an account exists.
|
||||||
@ -91,9 +161,9 @@ impl State {
|
|||||||
self.get(a, false).as_ref().map_or(U256::zero(), |account| account.nonce().clone())
|
self.get(a, false).as_ref().map_or(U256::zero(), |account| account.nonce().clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutate storage of account `a` so that it is `value` for `key`.
|
/// Mutate storage of account `address` so that it is `value` for `key`.
|
||||||
pub fn storage_at(&self, a: &Address, key: &H256) -> H256 {
|
pub fn storage_at(&self, address: &Address, key: &H256) -> H256 {
|
||||||
self.get(a, false).as_ref().map_or(H256::new(), |a|a.storage_at(&self.db, key))
|
self.get(address, false).as_ref().map_or(H256::new(), |a|a.storage_at(&AccountDB::new(&self.db, address), key))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mutate storage of account `a` so that it is `value` for `key`.
|
/// Mutate storage of account `a` so that it is `value` for `key`.
|
||||||
@ -139,7 +209,7 @@ impl State {
|
|||||||
|
|
||||||
/// Execute a given transaction.
|
/// Execute a given transaction.
|
||||||
/// This will change the state accordingly.
|
/// This will change the state accordingly.
|
||||||
pub fn apply(&mut self, env_info: &EnvInfo, engine: &Engine, t: &Transaction) -> ApplyResult {
|
pub fn apply(&mut self, env_info: &EnvInfo, engine: &Engine, t: &SignedTransaction) -> ApplyResult {
|
||||||
// let old = self.to_pod();
|
// let old = self.to_pod();
|
||||||
|
|
||||||
let e = try!(Executive::new(self, env_info, engine).transact(t));
|
let e = try!(Executive::new(self, env_info, engine).transact(t));
|
||||||
@ -152,22 +222,18 @@ impl State {
|
|||||||
Ok(receipt)
|
Ok(receipt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reverts uncommited changed.
|
|
||||||
pub fn revert(&mut self, backup: State) {
|
|
||||||
self.cache = backup.cache;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Commit accounts to SecTrieDBMut. This is similar to cpp-ethereum's dev::eth::commit.
|
/// Commit accounts to SecTrieDBMut. This is similar to cpp-ethereum's dev::eth::commit.
|
||||||
/// `accounts` is mutable because we may need to commit the code or storage and record that.
|
/// `accounts` is mutable because we may need to commit the code or storage and record that.
|
||||||
#[allow(match_ref_pats)]
|
#[allow(match_ref_pats)]
|
||||||
pub fn commit_into(db: &mut HashDB, root: &mut H256, accounts: &mut HashMap<Address, Option<Account>>) {
|
pub fn commit_into(db: &mut HashDB, root: &mut H256, accounts: &mut HashMap<Address, Option<Account>>) {
|
||||||
// first, commit the sub trees.
|
// first, commit the sub trees.
|
||||||
// TODO: is this necessary or can we dispense with the `ref mut a` for just `a`?
|
// TODO: is this necessary or can we dispense with the `ref mut a` for just `a`?
|
||||||
for (_, ref mut a) in accounts.iter_mut() {
|
for (address, ref mut a) in accounts.iter_mut() {
|
||||||
match a {
|
match a {
|
||||||
&mut&mut Some(ref mut account) => {
|
&mut&mut Some(ref mut account) => {
|
||||||
account.commit_storage(db);
|
let mut account_db = AccountDBMut::new(db, address);
|
||||||
account.commit_code(db);
|
account.commit_storage(&mut account_db);
|
||||||
|
account.commit_code(&mut account_db);
|
||||||
}
|
}
|
||||||
&mut&mut None => {}
|
&mut&mut None => {}
|
||||||
}
|
}
|
||||||
@ -186,6 +252,7 @@ impl State {
|
|||||||
|
|
||||||
/// Commits our cached account changes into the trie.
|
/// Commits our cached account changes into the trie.
|
||||||
pub fn commit(&mut self) {
|
pub fn commit(&mut self) {
|
||||||
|
assert!(self.snapshots.borrow().is_empty());
|
||||||
Self::commit_into(&mut self.db, &mut self.root, self.cache.borrow_mut().deref_mut());
|
Self::commit_into(&mut self.db, &mut self.root, self.cache.borrow_mut().deref_mut());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +260,7 @@ impl State {
|
|||||||
#[cfg(feature = "json-tests")]
|
#[cfg(feature = "json-tests")]
|
||||||
/// Populate the state from `accounts`.
|
/// Populate the state from `accounts`.
|
||||||
pub fn populate_from(&mut self, accounts: PodState) {
|
pub fn populate_from(&mut self, accounts: PodState) {
|
||||||
|
assert!(self.snapshots.borrow().is_empty());
|
||||||
for (add, acc) in accounts.drain().into_iter() {
|
for (add, acc) in accounts.drain().into_iter() {
|
||||||
self.cache.borrow_mut().insert(add, Some(Account::from_pod(acc)));
|
self.cache.borrow_mut().insert(add, Some(Account::from_pod(acc)));
|
||||||
}
|
}
|
||||||
@ -202,6 +270,7 @@ impl State {
|
|||||||
#[cfg(feature = "json-tests")]
|
#[cfg(feature = "json-tests")]
|
||||||
/// Populate a PodAccount map from this state.
|
/// Populate a PodAccount map from this state.
|
||||||
pub fn to_pod(&self) -> PodState {
|
pub fn to_pod(&self) -> PodState {
|
||||||
|
assert!(self.snapshots.borrow().is_empty());
|
||||||
// TODO: handle database rather than just the cache.
|
// TODO: handle database rather than just the cache.
|
||||||
PodState::from(self.cache.borrow().iter().fold(BTreeMap::new(), |mut m, (add, opt)| {
|
PodState::from(self.cache.borrow().iter().fold(BTreeMap::new(), |mut m, (add, opt)| {
|
||||||
if let Some(ref acc) = *opt {
|
if let Some(ref acc) = *opt {
|
||||||
@ -214,12 +283,13 @@ impl State {
|
|||||||
/// Pull account `a` in our cache from the trie DB and return it.
|
/// Pull account `a` in our cache from the trie DB and return it.
|
||||||
/// `require_code` requires that the code be cached, too.
|
/// `require_code` requires that the code be cached, too.
|
||||||
fn get(&self, a: &Address, require_code: bool) -> Ref<Option<Account>> {
|
fn get(&self, a: &Address, require_code: bool) -> Ref<Option<Account>> {
|
||||||
self.cache.borrow_mut().entry(a.clone()).or_insert_with(|| {
|
let have_key = self.cache.borrow().contains_key(a);
|
||||||
SecTrieDB::new(&self.db, &self.root).get(&a).map(|rlp| Account::from_rlp(rlp))
|
if !have_key {
|
||||||
});
|
self.insert_cache(a, SecTrieDB::new(&self.db, &self.root).get(&a).map(Account::from_rlp))
|
||||||
|
}
|
||||||
if require_code {
|
if require_code {
|
||||||
if let Some(ref mut account) = self.cache.borrow_mut().get_mut(a).unwrap().as_mut() {
|
if let Some(ref mut account) = self.cache.borrow_mut().get_mut(a).unwrap().as_mut() {
|
||||||
account.cache_code(&self.db);
|
account.cache_code(&AccountDB::new(&self.db, a));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ref::map(self.cache.borrow(), |m| m.get(a).unwrap())
|
Ref::map(self.cache.borrow(), |m| m.get(a).unwrap())
|
||||||
@ -233,8 +303,12 @@ impl State {
|
|||||||
/// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too.
|
/// Pull account `a` in our cache from the trie DB. `require_code` requires that the code be cached, too.
|
||||||
/// If it doesn't exist, make account equal the evaluation of `default`.
|
/// If it doesn't exist, make account equal the evaluation of `default`.
|
||||||
fn require_or_from<F: FnOnce() -> Account, G: FnOnce(&mut Account)>(&self, a: &Address, require_code: bool, default: F, not_default: G) -> RefMut<Account> {
|
fn require_or_from<F: FnOnce() -> Account, G: FnOnce(&mut Account)>(&self, a: &Address, require_code: bool, default: F, not_default: G) -> RefMut<Account> {
|
||||||
self.cache.borrow_mut().entry(a.clone()).or_insert_with(||
|
let have_key = self.cache.borrow().contains_key(a);
|
||||||
SecTrieDB::new(&self.db, &self.root).get(&a).map(|rlp| Account::from_rlp(rlp)));
|
if !have_key {
|
||||||
|
self.insert_cache(a, SecTrieDB::new(&self.db, &self.root).get(&a).map(Account::from_rlp))
|
||||||
|
} else {
|
||||||
|
self.note_cache(a);
|
||||||
|
}
|
||||||
let preexists = self.cache.borrow().get(a).unwrap().is_none();
|
let preexists = self.cache.borrow().get(a).unwrap().is_none();
|
||||||
if preexists {
|
if preexists {
|
||||||
self.cache.borrow_mut().insert(a.clone(), Some(default()));
|
self.cache.borrow_mut().insert(a.clone(), Some(default()));
|
||||||
@ -245,7 +319,7 @@ impl State {
|
|||||||
let b = self.cache.borrow_mut();
|
let b = self.cache.borrow_mut();
|
||||||
RefMut::map(b, |m| m.get_mut(a).unwrap().as_mut().map(|account| {
|
RefMut::map(b, |m| m.get_mut(a).unwrap().as_mut().map(|account| {
|
||||||
if require_code {
|
if require_code {
|
||||||
account.cache_code(&self.db);
|
account.cache_code(&AccountDB::new(&self.db, a));
|
||||||
}
|
}
|
||||||
account
|
account
|
||||||
}).unwrap())
|
}).unwrap())
|
||||||
@ -424,6 +498,38 @@ fn ensure_cached() {
|
|||||||
assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785");
|
assert_eq!(state.root().hex(), "0ce23f3c809de377b008a4a3ee94a0834aac8bec1f86e28ffe4fdb5a15b0c785");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn snapshot_basic() {
|
||||||
|
let mut state_result = get_temp_state();
|
||||||
|
let mut state = state_result.reference_mut();
|
||||||
|
let a = Address::zero();
|
||||||
|
state.snapshot();
|
||||||
|
state.add_balance(&a, &U256::from(69u64));
|
||||||
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
||||||
|
state.clear_snapshot();
|
||||||
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
||||||
|
state.snapshot();
|
||||||
|
state.add_balance(&a, &U256::from(1u64));
|
||||||
|
assert_eq!(state.balance(&a), U256::from(70u64));
|
||||||
|
state.revert_snapshot();
|
||||||
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn snapshot_nested() {
|
||||||
|
let mut state_result = get_temp_state();
|
||||||
|
let mut state = state_result.reference_mut();
|
||||||
|
let a = Address::zero();
|
||||||
|
state.snapshot();
|
||||||
|
state.snapshot();
|
||||||
|
state.add_balance(&a, &U256::from(69u64));
|
||||||
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
||||||
|
state.clear_snapshot();
|
||||||
|
assert_eq!(state.balance(&a), U256::from(69u64));
|
||||||
|
state.revert_snapshot();
|
||||||
|
assert_eq!(state.balance(&a), U256::from(0));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn create_empty() {
|
fn create_empty() {
|
||||||
let mut state_result = get_temp_state();
|
let mut state_result = get_temp_state();
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use pod_state::*;
|
use pod_state::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Execution environment substate.
|
//! Execution environment substate.
|
||||||
use common::*;
|
use common::*;
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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(feature = "json-tests")]
|
#[cfg(feature = "json-tests")]
|
||||||
use client::{BlockChainClient, Client};
|
use client::{BlockChainClient, Client};
|
||||||
use std::env;
|
use std::env;
|
||||||
@ -48,17 +64,21 @@ impl Drop for RandomTempPath {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub struct GuardedTempResult<T> {
|
pub struct GuardedTempResult<T> {
|
||||||
result: T,
|
result: Option<T>,
|
||||||
_temp: RandomTempPath
|
_temp: RandomTempPath
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> GuardedTempResult<T> {
|
impl<T> GuardedTempResult<T> {
|
||||||
pub fn reference(&self) -> &T {
|
pub fn reference(&self) -> &T {
|
||||||
&self.result
|
self.result.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reference_mut(&mut self) -> &mut T {
|
pub fn reference_mut(&mut self) -> &mut T {
|
||||||
&mut self.result
|
self.result.as_mut().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn take(&mut self) -> T {
|
||||||
|
self.result.take().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,12 +123,12 @@ fn create_unverifiable_block(order: u32, parent_hash: H256) -> Bytes {
|
|||||||
create_test_block(&create_unverifiable_block_header(order, parent_hash))
|
create_test_block(&create_unverifiable_block_header(order, parent_hash))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_test_block_with_data(header: &Header, transactions: &[&Transaction], uncles: &[Header]) -> Bytes {
|
pub fn create_test_block_with_data(header: &Header, transactions: &[&SignedTransaction], uncles: &[Header]) -> Bytes {
|
||||||
let mut rlp = RlpStream::new_list(3);
|
let mut rlp = RlpStream::new_list(3);
|
||||||
rlp.append(header);
|
rlp.append(header);
|
||||||
rlp.begin_list(transactions.len());
|
rlp.begin_list(transactions.len());
|
||||||
for t in transactions {
|
for t in transactions {
|
||||||
rlp.append_raw(&t.rlp_bytes_opt(Seal::With), 1);
|
rlp.append_raw(&encode::<SignedTransaction>(t).to_vec(), 1);
|
||||||
}
|
}
|
||||||
rlp.append(&uncles);
|
rlp.append(&uncles);
|
||||||
rlp.out()
|
rlp.out()
|
||||||
@ -150,7 +170,7 @@ pub fn generate_dummy_client(block_number: u32) -> GuardedTempResult<Arc<Client>
|
|||||||
|
|
||||||
GuardedTempResult::<Arc<Client>> {
|
GuardedTempResult::<Arc<Client>> {
|
||||||
_temp: dir,
|
_temp: dir,
|
||||||
result: client
|
result: Some(client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +188,7 @@ pub fn get_test_client_with_blocks(blocks: Vec<Bytes>) -> GuardedTempResult<Arc<
|
|||||||
|
|
||||||
GuardedTempResult::<Arc<Client>> {
|
GuardedTempResult::<Arc<Client>> {
|
||||||
_temp: dir,
|
_temp: dir,
|
||||||
result: client
|
result: Some(client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +201,7 @@ pub fn generate_dummy_blockchain(block_number: u32) -> GuardedTempResult<BlockCh
|
|||||||
|
|
||||||
GuardedTempResult::<BlockChain> {
|
GuardedTempResult::<BlockChain> {
|
||||||
_temp: temp,
|
_temp: temp,
|
||||||
result: bc
|
result: Some(bc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +214,7 @@ pub fn generate_dummy_blockchain_with_extra(block_number: u32) -> GuardedTempRes
|
|||||||
|
|
||||||
GuardedTempResult::<BlockChain> {
|
GuardedTempResult::<BlockChain> {
|
||||||
_temp: temp,
|
_temp: temp,
|
||||||
result: bc
|
result: Some(bc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +224,7 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
|
|||||||
|
|
||||||
GuardedTempResult::<BlockChain> {
|
GuardedTempResult::<BlockChain> {
|
||||||
_temp: temp,
|
_temp: temp,
|
||||||
result: bc
|
result: Some(bc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +234,7 @@ pub fn get_temp_journal_db() -> GuardedTempResult<JournalDB> {
|
|||||||
let journal_db = JournalDB::new(db);
|
let journal_db = JournalDB::new(db);
|
||||||
GuardedTempResult {
|
GuardedTempResult {
|
||||||
_temp: temp,
|
_temp: temp,
|
||||||
result: journal_db
|
result: Some(journal_db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +243,7 @@ pub fn get_temp_state() -> GuardedTempResult<State> {
|
|||||||
let journal_db = get_temp_journal_db_in(temp.as_path());
|
let journal_db = get_temp_journal_db_in(temp.as_path());
|
||||||
GuardedTempResult {
|
GuardedTempResult {
|
||||||
_temp: temp,
|
_temp: temp,
|
||||||
result: State::new(journal_db, U256::from(0u8))
|
result: Some(State::new(journal_db, U256::from(0u8)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1,17 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
|
@ -1,7 +1,22 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Transaction data structure.
|
//! Transaction data structure.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use basic_types::*;
|
|
||||||
use error::*;
|
use error::*;
|
||||||
use evm::Schedule;
|
use evm::Schedule;
|
||||||
|
|
||||||
@ -18,6 +33,16 @@ impl Default for Action {
|
|||||||
fn default() -> Action { Action::Create }
|
fn default() -> Action { Action::Create }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Decodable for Action {
|
||||||
|
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||||
|
let rlp = decoder.as_rlp();
|
||||||
|
match rlp.is_empty() {
|
||||||
|
true => Ok(Action::Create),
|
||||||
|
false => Ok(Action::Call(try!(rlp.as_val())))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A set of information describing an externally-originating message call
|
/// A set of information describing an externally-originating message call
|
||||||
/// or contract creation operation.
|
/// or contract creation operation.
|
||||||
#[derive(Default, Debug, Clone)]
|
#[derive(Default, Debug, Clone)]
|
||||||
@ -34,103 +59,27 @@ pub struct Transaction {
|
|||||||
pub value: U256,
|
pub value: U256,
|
||||||
/// Transaction data.
|
/// Transaction data.
|
||||||
pub data: Bytes,
|
pub data: Bytes,
|
||||||
|
|
||||||
// signature
|
|
||||||
/// The V field of the signature, either 27 or 28; helps describe the point on the curve.
|
|
||||||
pub v: u8,
|
|
||||||
/// The R field of the signature; helps describe the point on the curve.
|
|
||||||
pub r: U256,
|
|
||||||
/// The S field of the signature; helps describe the point on the curve.
|
|
||||||
pub s: U256,
|
|
||||||
|
|
||||||
hash: RefCell<Option<H256>>,
|
|
||||||
sender: RefCell<Option<Address>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transaction {
|
impl Transaction {
|
||||||
/// Create a new transaction.
|
/// Append object with a without signature into RLP stream
|
||||||
#[cfg(test)]
|
pub fn rlp_append_unsigned_transaction(&self, s: &mut RlpStream) {
|
||||||
#[cfg(feature = "json-tests")]
|
s.begin_list(6);
|
||||||
pub fn new() -> Self {
|
|
||||||
Transaction {
|
|
||||||
nonce: x!(0),
|
|
||||||
gas_price: x!(0),
|
|
||||||
gas: x!(0),
|
|
||||||
action: Action::Create,
|
|
||||||
value: x!(0),
|
|
||||||
data: vec![],
|
|
||||||
v: 0,
|
|
||||||
r: x!(0),
|
|
||||||
s: x!(0),
|
|
||||||
hash: RefCell::new(None),
|
|
||||||
sender: RefCell::new(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new message-call transaction.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn new_call(to: Address, value: U256, data: Bytes, gas: U256, gas_price: U256, nonce: U256) -> Transaction {
|
|
||||||
Transaction {
|
|
||||||
nonce: nonce,
|
|
||||||
gas_price: gas_price,
|
|
||||||
gas: gas,
|
|
||||||
action: Action::Call(to),
|
|
||||||
value: value,
|
|
||||||
data: data,
|
|
||||||
v: 0,
|
|
||||||
r: x!(0),
|
|
||||||
s: x!(0),
|
|
||||||
hash: RefCell::new(None),
|
|
||||||
sender: RefCell::new(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a new contract-creation transaction.
|
|
||||||
#[cfg(test)]
|
|
||||||
pub fn new_create(value: U256, data: Bytes, gas: U256, gas_price: U256, nonce: U256) -> Transaction {
|
|
||||||
Transaction {
|
|
||||||
nonce: nonce,
|
|
||||||
gas_price: gas_price,
|
|
||||||
gas: gas,
|
|
||||||
action: Action::Create,
|
|
||||||
value: value,
|
|
||||||
data: data,
|
|
||||||
v: 0,
|
|
||||||
r: x!(0),
|
|
||||||
s: x!(0),
|
|
||||||
hash: RefCell::new(None),
|
|
||||||
sender: RefCell::new(None),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Append object into RLP stream, optionally with or without the signature.
|
|
||||||
pub fn rlp_append_opt(&self, s: &mut RlpStream, with_seal: Seal) {
|
|
||||||
s.begin_list(6 + match with_seal { Seal::With => 3, _ => 0 });
|
|
||||||
s.append(&self.nonce);
|
s.append(&self.nonce);
|
||||||
s.append(&self.gas_price);
|
s.append(&self.gas_price);
|
||||||
s.append(&self.gas);
|
s.append(&self.gas);
|
||||||
match self.action {
|
match self.action {
|
||||||
Action::Create => s.append_empty_data(),
|
Action::Create => s.append_empty_data(),
|
||||||
Action::Call(ref to) => s.append(to),
|
Action::Call(ref to) => s.append(to)
|
||||||
};
|
};
|
||||||
s.append(&self.value);
|
s.append(&self.value);
|
||||||
s.append(&self.data);
|
s.append(&self.data);
|
||||||
if let Seal::With = with_seal {
|
|
||||||
s.append(&(self.v as u16)).append(&self.r).append(&self.s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the RLP serialisation of the object, optionally with or without the signature.
|
|
||||||
pub fn rlp_bytes_opt(&self, with_seal: Seal) -> Bytes {
|
|
||||||
let mut s = RlpStream::new();
|
|
||||||
self.rlp_append_opt(&mut s, with_seal);
|
|
||||||
s.out()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromJson for Transaction {
|
impl FromJson for SignedTransaction {
|
||||||
fn from_json(json: &Json) -> Transaction {
|
fn from_json(json: &Json) -> SignedTransaction {
|
||||||
let mut r = Transaction {
|
let t = Transaction {
|
||||||
nonce: xjson!(&json["nonce"]),
|
nonce: xjson!(&json["nonce"]),
|
||||||
gas_price: xjson!(&json["gasPrice"]),
|
gas_price: xjson!(&json["gasPrice"]),
|
||||||
gas: xjson!(&json["gasLimit"]),
|
gas: xjson!(&json["gasLimit"]),
|
||||||
@ -140,6 +89,11 @@ impl FromJson for Transaction {
|
|||||||
},
|
},
|
||||||
value: xjson!(&json["value"]),
|
value: xjson!(&json["value"]),
|
||||||
data: xjson!(&json["data"]),
|
data: xjson!(&json["data"]),
|
||||||
|
};
|
||||||
|
match json.find("secretKey") {
|
||||||
|
Some(&Json::String(ref secret_key)) => t.sign(&h256_from_hex(clean(secret_key))),
|
||||||
|
_ => SignedTransaction {
|
||||||
|
unsigned: t,
|
||||||
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) },
|
||||||
@ -147,20 +101,133 @@ impl FromJson for Transaction {
|
|||||||
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)) => RefCell::new(Some(address_from_hex(clean(sender)))),
|
||||||
_ => RefCell::new(None),
|
_ => RefCell::new(None),
|
||||||
},
|
|
||||||
};
|
|
||||||
if let Some(&Json::String(ref secret_key)) = json.find("secretKey") {
|
|
||||||
r.sign(&h256_from_hex(clean(secret_key)));
|
|
||||||
}
|
}
|
||||||
r
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
impl Encodable for Transaction {
|
|
||||||
fn rlp_append(&self, s: &mut RlpStream) { self.rlp_append_opt(s, Seal::With) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transaction {
|
impl Transaction {
|
||||||
|
/// The message hash of the transaction.
|
||||||
|
pub fn hash(&self) -> H256 {
|
||||||
|
let mut stream = RlpStream::new();
|
||||||
|
self.rlp_append_unsigned_transaction(&mut stream);
|
||||||
|
stream.out().sha3()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Signs the transaction as coming from `sender`.
|
||||||
|
pub fn sign(self, secret: &Secret) -> SignedTransaction {
|
||||||
|
let sig = ec::sign(secret, &self.hash());
|
||||||
|
let (r, s, v) = sig.unwrap().to_rsv();
|
||||||
|
SignedTransaction {
|
||||||
|
unsigned: self,
|
||||||
|
r: r,
|
||||||
|
s: s,
|
||||||
|
v: v + 27,
|
||||||
|
hash: RefCell::new(None),
|
||||||
|
sender: RefCell::new(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Useful for test incorrectly signed transactions.
|
||||||
|
#[cfg(test)]
|
||||||
|
pub fn fake_sign(self) -> SignedTransaction {
|
||||||
|
SignedTransaction {
|
||||||
|
unsigned: self,
|
||||||
|
r: U256::zero(),
|
||||||
|
s: U256::zero(),
|
||||||
|
v: 0,
|
||||||
|
hash: RefCell::new(None),
|
||||||
|
sender: RefCell::new(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the transaction cost in gas for the given params.
|
||||||
|
pub fn gas_required_for(is_create: bool, data: &[u8], schedule: &Schedule) -> u64 {
|
||||||
|
data.iter().fold(
|
||||||
|
(if is_create {schedule.tx_create_gas} else {schedule.tx_gas}) as u64,
|
||||||
|
|g, b| g + (match *b { 0 => schedule.tx_data_zero_gas, _ => schedule.tx_data_non_zero_gas }) as u64
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the transaction cost in gas for this transaction.
|
||||||
|
pub fn gas_required(&self, schedule: &Schedule) -> u64 {
|
||||||
|
Self::gas_required_for(match self.action{Action::Create=>true, Action::Call(_)=>false}, &self.data, schedule)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct SignedTransaction {
|
||||||
|
/// Plain Transaction.
|
||||||
|
unsigned: Transaction,
|
||||||
|
/// The V field of the signature, either 27 or 28; helps describe the point on the curve.
|
||||||
|
v: u8,
|
||||||
|
/// The R field of the signature; helps describe the point on the curve.
|
||||||
|
r: U256,
|
||||||
|
/// The S field of the signature; helps describe the point on the curve.
|
||||||
|
s: U256,
|
||||||
|
/// Cached hash.
|
||||||
|
hash: RefCell<Option<H256>>,
|
||||||
|
/// Cached sender.
|
||||||
|
sender: RefCell<Option<Address>>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for SignedTransaction {
|
||||||
|
type Target = Transaction;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.unsigned
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Decodable for SignedTransaction {
|
||||||
|
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||||
|
let d = decoder.as_rlp();
|
||||||
|
if d.item_count() != 9 {
|
||||||
|
return Err(DecoderError::RlpIncorrectListLen);
|
||||||
|
}
|
||||||
|
Ok(SignedTransaction {
|
||||||
|
unsigned: Transaction {
|
||||||
|
nonce: try!(d.val_at(0)),
|
||||||
|
gas_price: try!(d.val_at(1)),
|
||||||
|
gas: try!(d.val_at(2)),
|
||||||
|
action: try!(d.val_at(3)),
|
||||||
|
value: try!(d.val_at(4)),
|
||||||
|
data: try!(d.val_at(5)),
|
||||||
|
},
|
||||||
|
v: try!(d.val_at(6)),
|
||||||
|
r: try!(d.val_at(7)),
|
||||||
|
s: try!(d.val_at(8)),
|
||||||
|
hash: RefCell::new(None),
|
||||||
|
sender: RefCell::new(None),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encodable for SignedTransaction {
|
||||||
|
fn rlp_append(&self, s: &mut RlpStream) { self.rlp_append_sealed_transaction(s) }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SignedTransaction {
|
||||||
|
/// Append object with a signature into RLP stream
|
||||||
|
pub fn rlp_append_sealed_transaction(&self, s: &mut RlpStream) {
|
||||||
|
s.begin_list(9);
|
||||||
|
s.append(&self.nonce);
|
||||||
|
s.append(&self.gas_price);
|
||||||
|
s.append(&self.gas);
|
||||||
|
match self.action {
|
||||||
|
Action::Create => s.append_empty_data(),
|
||||||
|
Action::Call(ref to) => s.append(to)
|
||||||
|
};
|
||||||
|
s.append(&self.value);
|
||||||
|
s.append(&self.data);
|
||||||
|
s.append(&self.v);
|
||||||
|
s.append(&self.r);
|
||||||
|
s.append(&self.s);
|
||||||
|
}
|
||||||
|
|
||||||
/// 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 mut hash = self.hash.borrow_mut();
|
||||||
@ -179,48 +246,6 @@ impl Transaction {
|
|||||||
/// Construct a signature object from the sig.
|
/// Construct a signature object from the sig.
|
||||||
pub fn signature(&self) -> Signature { Signature::from_rsv(&From::from(&self.r), &From::from(&self.s), self.standard_v()) }
|
pub fn signature(&self) -> Signature { Signature::from_rsv(&From::from(&self.r), &From::from(&self.s), self.standard_v()) }
|
||||||
|
|
||||||
/// The message hash of the transaction.
|
|
||||||
pub fn message_hash(&self) -> H256 { self.rlp_bytes_opt(Seal::Without).sha3() }
|
|
||||||
|
|
||||||
/// Returns transaction sender.
|
|
||||||
pub fn sender(&self) -> Result<Address, Error> {
|
|
||||||
let mut sender = self.sender.borrow_mut();
|
|
||||||
match &mut *sender {
|
|
||||||
&mut Some(ref h) => Ok(h.clone()),
|
|
||||||
sender @ &mut None => {
|
|
||||||
*sender = Some(From::from(try!(ec::recover(&self.signature(), &self.message_hash())).sha3()));
|
|
||||||
Ok(sender.as_ref().unwrap().clone())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Signs the transaction as coming from `sender`.
|
|
||||||
pub fn sign(&mut self, secret: &Secret) {
|
|
||||||
// TODO: make always low.
|
|
||||||
let sig = ec::sign(secret, &self.message_hash());
|
|
||||||
let (r, s, v) = sig.unwrap().to_rsv();
|
|
||||||
self.r = r;
|
|
||||||
self.s = s;
|
|
||||||
self.v = v + 27;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Signs the transaction as coming from `sender`.
|
|
||||||
#[cfg(test)]
|
|
||||||
pub fn signed(self, secret: &Secret) -> Transaction { let mut r = self; r.sign(secret); r }
|
|
||||||
|
|
||||||
/// Get the transaction cost in gas for the given params.
|
|
||||||
pub fn gas_required_for(is_create: bool, data: &[u8], schedule: &Schedule) -> u64 {
|
|
||||||
data.iter().fold(
|
|
||||||
(if is_create {schedule.tx_create_gas} else {schedule.tx_gas}) as u64,
|
|
||||||
|g, b| g + (match *b { 0 => schedule.tx_data_zero_gas, _ => schedule.tx_data_non_zero_gas }) as u64
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get the transaction cost in gas for this transaction.
|
|
||||||
pub fn gas_required(&self, schedule: &Schedule) -> u64 {
|
|
||||||
Self::gas_required_for(match self.action{Action::Create=>true, Action::Call(_)=>false}, &self.data, schedule)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks whether the signature has a low 's' value.
|
/// Checks whether the signature has a low 's' value.
|
||||||
pub fn check_low_s(&self) -> Result<(), Error> {
|
pub fn check_low_s(&self) -> Result<(), Error> {
|
||||||
if !ec::is_low_s(&self.s) {
|
if !ec::is_low_s(&self.s) {
|
||||||
@ -230,11 +255,23 @@ impl Transaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns transaction sender.
|
||||||
|
pub fn sender(&self) -> Result<Address, Error> {
|
||||||
|
let mut sender = self.sender.borrow_mut();
|
||||||
|
match &mut *sender {
|
||||||
|
&mut Some(ref h) => Ok(h.clone()),
|
||||||
|
sender @ &mut None => {
|
||||||
|
*sender = Some(From::from(try!(ec::recover(&self.signature(), &self.unsigned.hash())).sha3()));
|
||||||
|
Ok(sender.as_ref().unwrap().clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Do basic validation, checking for valid signature and minimum gas,
|
/// Do basic validation, checking for valid signature and minimum gas,
|
||||||
// TODO: consider use in block validation.
|
// TODO: consider use in block validation.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature = "json-tests")]
|
#[cfg(feature = "json-tests")]
|
||||||
pub fn validate(self, schedule: &Schedule, require_low: bool) -> Result<Transaction, Error> {
|
pub fn validate(self, schedule: &Schedule, require_low: bool) -> Result<SignedTransaction, Error> {
|
||||||
if require_low && !ec::is_low_s(&self.s) {
|
if require_low && !ec::is_low_s(&self.s) {
|
||||||
return Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature)));
|
return Err(Error::Util(UtilError::Crypto(CryptoError::InvalidSignature)));
|
||||||
}
|
}
|
||||||
@ -247,42 +284,9 @@ impl Transaction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Decodable for Action {
|
|
||||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
|
||||||
let rlp = decoder.as_rlp();
|
|
||||||
if rlp.is_empty() {
|
|
||||||
Ok(Action::Create)
|
|
||||||
} else {
|
|
||||||
Ok(Action::Call(try!(rlp.as_val())))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Decodable for Transaction {
|
|
||||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
|
||||||
let d = decoder.as_rlp();
|
|
||||||
if d.item_count() != 9 {
|
|
||||||
return Err(DecoderError::RlpIncorrectListLen);
|
|
||||||
}
|
|
||||||
Ok(Transaction {
|
|
||||||
nonce: try!(d.val_at(0)),
|
|
||||||
gas_price: try!(d.val_at(1)),
|
|
||||||
gas: try!(d.val_at(2)),
|
|
||||||
action: try!(d.val_at(3)),
|
|
||||||
value: try!(d.val_at(4)),
|
|
||||||
data: try!(d.val_at(5)),
|
|
||||||
v: try!(d.val_at(6)),
|
|
||||||
r: try!(d.val_at(7)),
|
|
||||||
s: try!(d.val_at(8)),
|
|
||||||
hash: RefCell::new(None),
|
|
||||||
sender: RefCell::new(None),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sender_test() {
|
fn sender_test() {
|
||||||
let t: Transaction = decode(&FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap());
|
let t: SignedTransaction = decode(&FromHex::from_hex("f85f800182520894095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804").unwrap());
|
||||||
assert_eq!(t.data, b"");
|
assert_eq!(t.data, b"");
|
||||||
assert_eq!(t.gas, U256::from(0x5208u64));
|
assert_eq!(t.gas, U256::from(0x5208u64));
|
||||||
assert_eq!(t.gas_price, U256::from(0x01u64));
|
assert_eq!(t.gas_price, U256::from(0x01u64));
|
||||||
@ -297,6 +301,13 @@ fn sender_test() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn signing() {
|
fn signing() {
|
||||||
let key = KeyPair::create().unwrap();
|
let key = KeyPair::create().unwrap();
|
||||||
let t = Transaction::new_create(U256::from(42u64), b"Hello!".to_vec(), U256::from(3000u64), U256::from(50_000u64), U256::from(1u64)).signed(&key.secret());
|
let t = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
nonce: U256::from(42),
|
||||||
|
gas_price: U256::from(3000),
|
||||||
|
gas: U256::from(50_000),
|
||||||
|
value: U256::from(1),
|
||||||
|
data: b"Hello!".to_vec()
|
||||||
|
}.sign(&key.secret());
|
||||||
assert_eq!(Address::from(key.public().sha3()), t.sender().unwrap());
|
assert_eq!(Address::from(key.public().sha3()), t.sender().unwrap());
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
/// Block and transaction verification functions
|
/// Block and transaction verification functions
|
||||||
///
|
///
|
||||||
/// Block verification is done in 3 steps
|
/// Block verification is done in 3 steps
|
||||||
@ -14,7 +30,7 @@ pub struct PreVerifiedBlock {
|
|||||||
/// Populated block header
|
/// Populated block header
|
||||||
pub header: Header,
|
pub header: Header,
|
||||||
/// Populated block transactions
|
/// Populated block transactions
|
||||||
pub transactions: Vec<Transaction>,
|
pub transactions: Vec<SignedTransaction>,
|
||||||
/// Block bytes
|
/// Block bytes
|
||||||
pub bytes: Bytes,
|
pub bytes: Bytes,
|
||||||
}
|
}
|
||||||
@ -220,7 +236,6 @@ mod tests {
|
|||||||
use engine::*;
|
use engine::*;
|
||||||
use spec::*;
|
use spec::*;
|
||||||
use transaction::*;
|
use transaction::*;
|
||||||
use basic_types::*;
|
|
||||||
use tests::helpers::*;
|
use tests::helpers::*;
|
||||||
|
|
||||||
fn check_ok(result: Result<(), Error>) {
|
fn check_ok(result: Result<(), Error>) {
|
||||||
@ -309,8 +324,26 @@ mod tests {
|
|||||||
good.timestamp = 40;
|
good.timestamp = 40;
|
||||||
good.number = 10;
|
good.number = 10;
|
||||||
|
|
||||||
let tr1 = Transaction::new_create(x!(0), Bytes::new(), x!(30000), x!(40000), x!(1));
|
let keypair = KeyPair::create().unwrap();
|
||||||
let tr2 = Transaction::new_create(x!(0), Bytes::new(), x!(30000), x!(40000), x!(2));
|
|
||||||
|
let tr1 = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
value: U256::from(0),
|
||||||
|
data: Bytes::new(),
|
||||||
|
gas: U256::from(30_000),
|
||||||
|
gas_price: U256::from(40_000),
|
||||||
|
nonce: U256::one()
|
||||||
|
}.sign(&keypair.secret());
|
||||||
|
|
||||||
|
let tr2 = Transaction {
|
||||||
|
action: Action::Create,
|
||||||
|
value: U256::from(0),
|
||||||
|
data: Bytes::new(),
|
||||||
|
gas: U256::from(30_000),
|
||||||
|
gas_price: U256::from(40_000),
|
||||||
|
nonce: U256::from(2)
|
||||||
|
}.sign(&keypair.secret());
|
||||||
|
|
||||||
let good_transactions = [ &tr1, &tr2 ];
|
let good_transactions = [ &tr1, &tr2 ];
|
||||||
|
|
||||||
let diff_inc = U256::from(0x40);
|
let diff_inc = U256::from(0x40);
|
||||||
@ -346,7 +379,7 @@ mod tests {
|
|||||||
let mut uncles_rlp = RlpStream::new();
|
let mut uncles_rlp = RlpStream::new();
|
||||||
uncles_rlp.append(&good_uncles);
|
uncles_rlp.append(&good_uncles);
|
||||||
let good_uncles_hash = uncles_rlp.as_raw().sha3();
|
let good_uncles_hash = uncles_rlp.as_raw().sha3();
|
||||||
let good_transactions_root = ordered_trie_root(good_transactions.iter().map(|t| t.rlp_bytes_opt(Seal::With)).collect());
|
let good_transactions_root = ordered_trie_root(good_transactions.iter().map(|t| encode::<SignedTransaction>(t).to_vec()).collect());
|
||||||
|
|
||||||
let mut parent = good.clone();
|
let mut parent = good.clone();
|
||||||
parent.number = 9;
|
parent.number = 9;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Block oriented views onto rlp.
|
//! Block oriented views onto rlp.
|
||||||
use util::*;
|
use util::*;
|
||||||
use header::*;
|
use header::*;
|
||||||
@ -135,7 +151,7 @@ impl<'a> BlockView<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return List of transactions in given block.
|
/// Return List of transactions in given block.
|
||||||
pub fn transactions(&self) -> Vec<Transaction> {
|
pub fn transactions(&self) -> Vec<SignedTransaction> {
|
||||||
self.rlp.val_at(1)
|
self.rlp.val_at(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Bare rust wrapper around evmjit.
|
//! Bare rust wrapper around evmjit.
|
||||||
//!
|
//!
|
||||||
//! Requires latest version of Ethereum EVM JIT. https://github.com/debris/evmjit
|
//! Requires latest version of Ethereum EVM JIT. https://github.com/debris/evmjit
|
||||||
|
@ -385,7 +385,6 @@ function run_installer()
|
|||||||
find_gcc
|
find_gcc
|
||||||
|
|
||||||
find_apt
|
find_apt
|
||||||
find_docker
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function find_rocksdb()
|
function find_rocksdb()
|
||||||
@ -519,23 +518,6 @@ function run_installer()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function find_docker()
|
|
||||||
{
|
|
||||||
depCount=$((depCount+1))
|
|
||||||
DOCKER_PATH=`which docker 2>/dev/null`
|
|
||||||
|
|
||||||
if [[ -f $DOCKER_PATH ]]
|
|
||||||
then
|
|
||||||
depFound=$((depFound+1))
|
|
||||||
check "docker"
|
|
||||||
echo "$($DOCKER_PATH -v)"
|
|
||||||
isDocker=true
|
|
||||||
else
|
|
||||||
isDocker=false
|
|
||||||
uncheck "docker is missing"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function ubuntu1404_rocksdb_installer()
|
function ubuntu1404_rocksdb_installer()
|
||||||
{
|
{
|
||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
@ -644,15 +626,22 @@ function run_installer()
|
|||||||
git submodule init
|
git submodule init
|
||||||
git submodule update
|
git submodule update
|
||||||
|
|
||||||
info "Building & testing Parity..."
|
info "Building..."
|
||||||
cargo test --release -p ethcore-util
|
cargo build --release
|
||||||
|
cd ..
|
||||||
info "Running consensus tests..."
|
|
||||||
cargo test --release --features ethcore/json-tests -p ethcore
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
info "Parity source code is in $(pwd)/parity"
|
successHeading "Parity is built!"
|
||||||
info "Run a client with: ${b}cargo run --release${reset}"
|
info "Parity source code is in ${b}$(pwd)/parity${reset}. From there, you can:"
|
||||||
|
info "- Run a client & sync the chain with:"
|
||||||
|
info " ${b}cargo run --release${reset}"
|
||||||
|
info "- Run a JSONRPC-capable client (for use with netstats) with:"
|
||||||
|
info " ${b}cargo run --release -- -j --jsonrpc-url 127.0.0.1:8545${reset}"
|
||||||
|
info "- Run tests with:"
|
||||||
|
info " ${b}cargo test --release --features ethcore/json-tests -p ethcore${reset}"
|
||||||
|
info "- Install the client with:"
|
||||||
|
info " ${b}sudo cp parity/target/release/parity${reset}"
|
||||||
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_netstats()
|
function install_netstats()
|
||||||
|
16
license_header
Normal file
16
license_header
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethcore client application.
|
//! Ethcore client application.
|
||||||
|
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethcore rpc.
|
//! Ethcore rpc.
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![feature(custom_derive, custom_attribute, plugin)]
|
#![feature(custom_derive, custom_attribute, plugin)]
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Eth rpc implementation.
|
//! Eth rpc implementation.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethereum rpc interface implementation.
|
//! Ethereum rpc interface implementation.
|
||||||
mod web3;
|
mod web3;
|
||||||
mod eth;
|
mod eth;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Net rpc implementation.
|
//! Net rpc implementation.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Web3 rpc implementation.
|
//! Web3 rpc implementation.
|
||||||
use target_info::Target;
|
use target_info::Target;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethcore rpc v1.
|
//! Ethcore rpc v1.
|
||||||
//!
|
//!
|
||||||
//! Compliant with ethereum rpc.
|
//! Compliant with ethereum rpc.
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Eth rpc interface.
|
//! Eth rpc interface.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethereum rpc interfaces.
|
//! Ethereum rpc interfaces.
|
||||||
|
|
||||||
macro_rules! rpc_unimplemented {
|
macro_rules! rpc_unimplemented {
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Net rpc interface.
|
//! Net rpc interface.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Web3 rpc interface.
|
//! Web3 rpc interface.
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use jsonrpc_core::*;
|
use jsonrpc_core::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::hash::*;
|
use util::hash::*;
|
||||||
use util::uint::*;
|
use util::uint::*;
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
mod block;
|
mod block;
|
||||||
mod sync;
|
mod sync;
|
||||||
|
|
||||||
|
@ -5,5 +5,5 @@ fi
|
|||||||
|
|
||||||
cargo test --no-run || exit $?
|
cargo test --no-run || exit $?
|
||||||
mkdir -p target/coverage
|
mkdir -p target/coverage
|
||||||
kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1 --include-pattern sync/src --verify target/coverage target/debug/ethsync*
|
kcov --exclude-pattern ~/.multirust,rocksdb,secp256k1,sync/src/tests --include-pattern sync/src --verify target/coverage target/debug/ethsync*
|
||||||
xdg-open target/coverage/index.html
|
xdg-open target/coverage/index.html
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
///
|
///
|
||||||
/// BlockChain synchronization strategy.
|
/// BlockChain synchronization strategy.
|
||||||
/// Syncs to peers and keeps up to date.
|
/// Syncs to peers and keeps up to date.
|
||||||
@ -177,6 +193,7 @@ pub struct ChainSync {
|
|||||||
have_common_block: bool,
|
have_common_block: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RlpResponseResult = Result<Option<(PacketId, RlpStream)>, PacketDecodeError>;
|
||||||
|
|
||||||
impl ChainSync {
|
impl ChainSync {
|
||||||
/// Create a new instance of syncing strategy.
|
/// Create a new instance of syncing strategy.
|
||||||
@ -845,7 +862,7 @@ impl ChainSync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Respond to GetBlockHeaders request
|
/// Respond to GetBlockHeaders request
|
||||||
fn return_block_headers(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> {
|
fn return_block_headers(io: &SyncIo, r: &UntrustedRlp) -> RlpResponseResult {
|
||||||
// Packet layout:
|
// Packet layout:
|
||||||
// [ block: { P , B_32 }, maxHeaders: P, skip: P, reverse: P in { 0 , 1 } ]
|
// [ block: { P , B_32 }, maxHeaders: P, skip: P, reverse: P in { 0 , 1 } ]
|
||||||
let max_headers: usize = try!(r.val_at(1));
|
let max_headers: usize = try!(r.val_at(1));
|
||||||
@ -892,18 +909,16 @@ impl ChainSync {
|
|||||||
}
|
}
|
||||||
let mut rlp = RlpStream::new_list(count as usize);
|
let mut rlp = RlpStream::new_list(count as usize);
|
||||||
rlp.append_raw(&data, count as usize);
|
rlp.append_raw(&data, count as usize);
|
||||||
io.respond(BLOCK_HEADERS_PACKET, rlp.out()).unwrap_or_else(|e|
|
|
||||||
debug!(target: "sync", "Error sending headers: {:?}", e));
|
|
||||||
trace!(target: "sync", "-> GetBlockHeaders: returned {} entries", count);
|
trace!(target: "sync", "-> GetBlockHeaders: returned {} entries", count);
|
||||||
Ok(())
|
Ok(Some((BLOCK_HEADERS_PACKET, rlp)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Respond to GetBlockBodies request
|
/// Respond to GetBlockBodies request
|
||||||
fn return_block_bodies(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> {
|
fn return_block_bodies(io: &SyncIo, r: &UntrustedRlp) -> RlpResponseResult {
|
||||||
let mut count = r.item_count();
|
let mut count = r.item_count();
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
debug!(target: "sync", "Empty GetBlockBodies request, ignoring.");
|
debug!(target: "sync", "Empty GetBlockBodies request, ignoring.");
|
||||||
return Ok(());
|
return Ok(None);
|
||||||
}
|
}
|
||||||
trace!(target: "sync", "-> GetBlockBodies: {} entries", count);
|
trace!(target: "sync", "-> GetBlockBodies: {} entries", count);
|
||||||
count = min(count, MAX_BODIES_TO_SEND);
|
count = min(count, MAX_BODIES_TO_SEND);
|
||||||
@ -917,18 +932,16 @@ impl ChainSync {
|
|||||||
}
|
}
|
||||||
let mut rlp = RlpStream::new_list(added);
|
let mut rlp = RlpStream::new_list(added);
|
||||||
rlp.append_raw(&data, added);
|
rlp.append_raw(&data, added);
|
||||||
io.respond(BLOCK_BODIES_PACKET, rlp.out()).unwrap_or_else(|e|
|
|
||||||
debug!(target: "sync", "Error sending headers: {:?}", e));
|
|
||||||
trace!(target: "sync", "-> GetBlockBodies: returned {} entries", added);
|
trace!(target: "sync", "-> GetBlockBodies: returned {} entries", added);
|
||||||
Ok(())
|
Ok(Some((BLOCK_BODIES_PACKET, rlp)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Respond to GetNodeData request
|
/// Respond to GetNodeData request
|
||||||
fn return_node_data(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> {
|
fn return_node_data(io: &SyncIo, r: &UntrustedRlp) -> RlpResponseResult {
|
||||||
let mut count = r.item_count();
|
let mut count = r.item_count();
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
debug!(target: "sync", "Empty GetNodeData request, ignoring.");
|
debug!(target: "sync", "Empty GetNodeData request, ignoring.");
|
||||||
return Ok(());
|
return Ok(None);
|
||||||
}
|
}
|
||||||
count = min(count, MAX_NODE_DATA_TO_SEND);
|
count = min(count, MAX_NODE_DATA_TO_SEND);
|
||||||
let mut added = 0usize;
|
let mut added = 0usize;
|
||||||
@ -941,33 +954,44 @@ impl ChainSync {
|
|||||||
}
|
}
|
||||||
let mut rlp = RlpStream::new_list(added);
|
let mut rlp = RlpStream::new_list(added);
|
||||||
rlp.append_raw(&data, added);
|
rlp.append_raw(&data, added);
|
||||||
io.respond(NODE_DATA_PACKET, rlp.out()).unwrap_or_else(|e|
|
Ok(Some((NODE_DATA_PACKET, rlp)))
|
||||||
debug!(target: "sync", "Error sending headers: {:?}", e));
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Respond to GetReceipts request
|
fn return_receipts(io: &SyncIo, rlp: &UntrustedRlp) -> RlpResponseResult {
|
||||||
fn return_receipts(&self, io: &mut SyncIo, r: &UntrustedRlp) -> Result<(), PacketDecodeError> {
|
let mut count = rlp.item_count();
|
||||||
let mut count = r.item_count();
|
|
||||||
if count == 0 {
|
if count == 0 {
|
||||||
debug!(target: "sync", "Empty GetReceipts request, ignoring.");
|
debug!(target: "sync", "Empty GetReceipts request, ignoring.");
|
||||||
return Ok(());
|
return Ok(None);
|
||||||
}
|
}
|
||||||
count = min(count, MAX_RECEIPTS_TO_SEND);
|
count = min(count, MAX_RECEIPTS_TO_SEND);
|
||||||
let mut added = 0usize;
|
let mut added = 0usize;
|
||||||
let mut data = Bytes::new();
|
let mut data = Bytes::new();
|
||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
if let Some(mut hdr) = io.chain().block_receipts(&try!(r.val_at::<H256>(i))) {
|
if let Some(mut hdr) = io.chain().block_receipts(&try!(rlp.val_at::<H256>(i))) {
|
||||||
data.append(&mut hdr);
|
data.append(&mut hdr);
|
||||||
added += 1;
|
added += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut rlp = RlpStream::new_list(added);
|
let mut rlp_result = RlpStream::new_list(added);
|
||||||
rlp.append_raw(&data, added);
|
rlp_result.append_raw(&data, added);
|
||||||
io.respond(RECEIPTS_PACKET, rlp.out()).unwrap_or_else(|e|
|
Ok(Some((RECEIPTS_PACKET, rlp_result)))
|
||||||
debug!(target: "sync", "Error sending headers: {:?}", e));
|
}
|
||||||
|
|
||||||
|
fn return_rlp<FRlp, FError>(&self, io: &mut SyncIo, rlp: &UntrustedRlp, rlp_func: FRlp, error_func: FError) -> Result<(), PacketDecodeError>
|
||||||
|
where FRlp : Fn(&SyncIo, &UntrustedRlp) -> RlpResponseResult,
|
||||||
|
FError : FnOnce(UtilError) -> String
|
||||||
|
{
|
||||||
|
let response = rlp_func(io, rlp);
|
||||||
|
match response {
|
||||||
|
Err(e) => Err(e),
|
||||||
|
Ok(Some((packet_id, rlp_stream))) => {
|
||||||
|
io.respond(packet_id, rlp_stream.out()).unwrap_or_else(
|
||||||
|
|e| debug!(target: "sync", "{:?}", error_func(e)));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
_ => Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Dispatch incoming requests and responses
|
/// Dispatch incoming requests and responses
|
||||||
pub fn on_packet(&mut self, io: &mut SyncIo, peer: PeerId, packet_id: u8, data: &[u8]) {
|
pub fn on_packet(&mut self, io: &mut SyncIo, peer: PeerId, packet_id: u8, data: &[u8]) {
|
||||||
@ -975,14 +999,27 @@ impl ChainSync {
|
|||||||
let result = match packet_id {
|
let result = match packet_id {
|
||||||
STATUS_PACKET => self.on_peer_status(io, peer, &rlp),
|
STATUS_PACKET => self.on_peer_status(io, peer, &rlp),
|
||||||
TRANSACTIONS_PACKET => self.on_peer_transactions(io, peer, &rlp),
|
TRANSACTIONS_PACKET => self.on_peer_transactions(io, peer, &rlp),
|
||||||
GET_BLOCK_HEADERS_PACKET => self.return_block_headers(io, &rlp),
|
|
||||||
BLOCK_HEADERS_PACKET => self.on_peer_block_headers(io, peer, &rlp),
|
BLOCK_HEADERS_PACKET => self.on_peer_block_headers(io, peer, &rlp),
|
||||||
GET_BLOCK_BODIES_PACKET => self.return_block_bodies(io, &rlp),
|
|
||||||
BLOCK_BODIES_PACKET => self.on_peer_block_bodies(io, peer, &rlp),
|
BLOCK_BODIES_PACKET => self.on_peer_block_bodies(io, peer, &rlp),
|
||||||
NEW_BLOCK_PACKET => self.on_peer_new_block(io, peer, &rlp),
|
NEW_BLOCK_PACKET => self.on_peer_new_block(io, peer, &rlp),
|
||||||
NEW_BLOCK_HASHES_PACKET => self.on_peer_new_hashes(io, peer, &rlp),
|
NEW_BLOCK_HASHES_PACKET => self.on_peer_new_hashes(io, peer, &rlp),
|
||||||
GET_NODE_DATA_PACKET => self.return_node_data(io, &rlp),
|
|
||||||
GET_RECEIPTS_PACKET => self.return_receipts(io, &rlp),
|
GET_BLOCK_BODIES_PACKET => self.return_rlp(io, &rlp,
|
||||||
|
ChainSync::return_block_bodies,
|
||||||
|
|e| format!("Error sending block bodies: {:?}", e)),
|
||||||
|
|
||||||
|
GET_BLOCK_HEADERS_PACKET => self.return_rlp(io, &rlp,
|
||||||
|
ChainSync::return_block_headers,
|
||||||
|
|e| format!("Error sending block headers: {:?}", e)),
|
||||||
|
|
||||||
|
GET_RECEIPTS_PACKET => self.return_rlp(io, &rlp,
|
||||||
|
ChainSync::return_receipts,
|
||||||
|
|e| format!("Error sending receipts: {:?}", e)),
|
||||||
|
|
||||||
|
GET_NODE_DATA_PACKET => self.return_rlp(io, &rlp,
|
||||||
|
ChainSync::return_node_data,
|
||||||
|
|e| format!("Error sending nodes: {:?}", e)),
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
debug!(target: "sync", "Unknown packet {}", packet_id);
|
debug!(target: "sync", "Unknown packet {}", packet_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -1016,4 +1053,75 @@ impl ChainSync {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use tests::helpers::*;
|
||||||
|
use super::*;
|
||||||
|
use util::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn return_receipts_empty() {
|
||||||
|
let mut client = TestBlockChainClient::new();
|
||||||
|
let mut queue = VecDeque::new();
|
||||||
|
let io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
|
let result = ChainSync::return_receipts(&io, &UntrustedRlp::new(&[0xc0]));
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn return_receipts() {
|
||||||
|
let mut client = TestBlockChainClient::new();
|
||||||
|
let mut queue = VecDeque::new();
|
||||||
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
|
let mut receipt_list = RlpStream::new_list(4);
|
||||||
|
receipt_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555"));
|
||||||
|
receipt_list.append(&H256::from("ff00000000000000000000000000000000000000000000000000000000000000"));
|
||||||
|
receipt_list.append(&H256::from("fff0000000000000000000000000000000000000000000000000000000000000"));
|
||||||
|
receipt_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000"));
|
||||||
|
|
||||||
|
let receipts_request = receipt_list.out();
|
||||||
|
// it returns rlp ONLY for hashes started with "f"
|
||||||
|
let result = ChainSync::return_receipts(&io, &UntrustedRlp::new(&receipts_request.clone()));
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let rlp_result = result.unwrap();
|
||||||
|
assert!(rlp_result.is_some());
|
||||||
|
|
||||||
|
// the length of two rlp-encoded receipts
|
||||||
|
assert_eq!(597, rlp_result.unwrap().1.out().len());
|
||||||
|
|
||||||
|
let mut sync = ChainSync::new();
|
||||||
|
io.sender = Some(2usize);
|
||||||
|
sync.on_packet(&mut io, 1usize, super::GET_RECEIPTS_PACKET, &receipts_request);
|
||||||
|
assert_eq!(1, io.queue.len());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn return_nodes() {
|
||||||
|
let mut client = TestBlockChainClient::new();
|
||||||
|
let mut queue = VecDeque::new();
|
||||||
|
let mut io = TestIo::new(&mut client, &mut queue, None);
|
||||||
|
|
||||||
|
let mut node_list = RlpStream::new_list(3);
|
||||||
|
node_list.append(&H256::from("0000000000000000000000000000000000000000000000005555555555555555"));
|
||||||
|
node_list.append(&H256::from("ffffffffffffffffffffffffffffffffffffffffffffaaaaaaaaaaaaaaaaaaaa"));
|
||||||
|
node_list.append(&H256::from("aff0000000000000000000000000000000000000000000000000000000000000"));
|
||||||
|
|
||||||
|
let node_request = node_list.out();
|
||||||
|
// it returns rlp ONLY for hashes started with "f"
|
||||||
|
let result = ChainSync::return_node_data(&io, &UntrustedRlp::new(&node_request.clone()));
|
||||||
|
|
||||||
|
assert!(result.is_ok());
|
||||||
|
let rlp_result = result.unwrap();
|
||||||
|
assert!(rlp_result.is_some());
|
||||||
|
|
||||||
|
// the length of one rlp-encoded hashe
|
||||||
|
assert_eq!(34, rlp_result.unwrap().1.out().len());
|
||||||
|
|
||||||
|
let mut sync = ChainSync::new();
|
||||||
|
io.sender = Some(2usize);
|
||||||
|
sync.on_packet(&mut io, 1usize, super::GET_NODE_DATA_PACKET, &node_request);
|
||||||
|
assert_eq!(1, io.queue.len());
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use ethcore::client::BlockChainClient;
|
use ethcore::client::BlockChainClient;
|
||||||
use util::{NetworkContext, PeerId, PacketId,};
|
use util::{NetworkContext, PeerId, PacketId,};
|
||||||
use util::error::UtilError;
|
use util::error::UtilError;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
#![feature(plugin)]
|
#![feature(plugin)]
|
||||||
#![plugin(clippy)]
|
#![plugin(clippy)]
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
/// This module defines a trait for a collection of ranged values and an implementation
|
/// This module defines a trait for a collection of ranged values and an implementation
|
||||||
/// for this trait over sorted vector.
|
/// for this trait over sorted vector.
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use ethcore::client::{BlockChainClient};
|
use ethcore::client::{BlockChainClient};
|
||||||
use io::SyncIo;
|
use io::SyncIo;
|
||||||
@ -5,7 +21,7 @@ use chain::{SyncState};
|
|||||||
use super::helpers::*;
|
use super::helpers::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_two_peers() {
|
fn two_peers() {
|
||||||
::env_logger::init().ok();
|
::env_logger::init().ok();
|
||||||
let mut net = TestNet::new(3);
|
let mut net = TestNet::new(3);
|
||||||
net.peer_mut(1).chain.add_blocks(1000, false);
|
net.peer_mut(1).chain.add_blocks(1000, false);
|
||||||
@ -16,7 +32,7 @@ fn chain_two_peers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_status_after_sync() {
|
fn status_after_sync() {
|
||||||
::env_logger::init().ok();
|
::env_logger::init().ok();
|
||||||
let mut net = TestNet::new(3);
|
let mut net = TestNet::new(3);
|
||||||
net.peer_mut(1).chain.add_blocks(1000, false);
|
net.peer_mut(1).chain.add_blocks(1000, false);
|
||||||
@ -27,7 +43,7 @@ fn chain_status_after_sync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_takes_few_steps() {
|
fn takes_few_steps() {
|
||||||
let mut net = TestNet::new(3);
|
let mut net = TestNet::new(3);
|
||||||
net.peer_mut(1).chain.add_blocks(100, false);
|
net.peer_mut(1).chain.add_blocks(100, false);
|
||||||
net.peer_mut(2).chain.add_blocks(100, false);
|
net.peer_mut(2).chain.add_blocks(100, false);
|
||||||
@ -36,7 +52,7 @@ fn chain_takes_few_steps() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_empty_blocks() {
|
fn empty_blocks() {
|
||||||
::env_logger::init().ok();
|
::env_logger::init().ok();
|
||||||
let mut net = TestNet::new(3);
|
let mut net = TestNet::new(3);
|
||||||
for n in 0..200 {
|
for n in 0..200 {
|
||||||
@ -49,7 +65,7 @@ fn chain_empty_blocks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_forked() {
|
fn forked() {
|
||||||
::env_logger::init().ok();
|
::env_logger::init().ok();
|
||||||
let mut net = TestNet::new(3);
|
let mut net = TestNet::new(3);
|
||||||
net.peer_mut(0).chain.add_blocks(300, false);
|
net.peer_mut(0).chain.add_blocks(300, false);
|
||||||
@ -69,7 +85,7 @@ fn chain_forked() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_restart() {
|
fn restart() {
|
||||||
let mut net = TestNet::new(3);
|
let mut net = TestNet::new(3);
|
||||||
net.peer_mut(1).chain.add_blocks(1000, false);
|
net.peer_mut(1).chain.add_blocks(1000, false);
|
||||||
net.peer_mut(2).chain.add_blocks(1000, false);
|
net.peer_mut(2).chain.add_blocks(1000, false);
|
||||||
@ -85,7 +101,7 @@ fn chain_restart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn chain_status_empty() {
|
fn status_empty() {
|
||||||
let net = TestNet::new(2);
|
let net = TestNet::new(2);
|
||||||
assert_eq!(net.peer(0).sync.status().state, SyncState::NotSynced);
|
assert_eq!(net.peer(0).sync.status().state, SyncState::NotSynced);
|
||||||
}
|
}
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use util::*;
|
use util::*;
|
||||||
use ethcore::client::{BlockChainClient, BlockStatus, TreeRoute, BlockChainInfo};
|
use ethcore::client::{BlockChainClient, BlockStatus, TreeRoute, BlockChainInfo};
|
||||||
use ethcore::block_queue::BlockQueueInfo;
|
use ethcore::block_queue::BlockQueueInfo;
|
||||||
@ -5,6 +21,7 @@ use ethcore::header::{Header as BlockHeader, BlockNumber};
|
|||||||
use ethcore::error::*;
|
use ethcore::error::*;
|
||||||
use io::SyncIo;
|
use io::SyncIo;
|
||||||
use chain::{ChainSync};
|
use chain::{ChainSync};
|
||||||
|
use ethcore::receipt::Receipt;
|
||||||
|
|
||||||
pub struct TestBlockChainClient {
|
pub struct TestBlockChainClient {
|
||||||
pub blocks: RwLock<HashMap<H256, Bytes>>,
|
pub blocks: RwLock<HashMap<H256, Bytes>>,
|
||||||
@ -15,7 +32,7 @@ pub struct TestBlockChainClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TestBlockChainClient {
|
impl TestBlockChainClient {
|
||||||
fn new() -> TestBlockChainClient {
|
pub fn new() -> TestBlockChainClient {
|
||||||
|
|
||||||
let mut client = TestBlockChainClient {
|
let mut client = TestBlockChainClient {
|
||||||
blocks: RwLock::new(HashMap::new()),
|
blocks: RwLock::new(HashMap::new()),
|
||||||
@ -116,11 +133,28 @@ impl BlockChainClient for TestBlockChainClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state_data(&self, _h: &H256) -> Option<Bytes> {
|
// TODO: returns just hashes instead of node state rlp(?)
|
||||||
|
fn state_data(&self, hash: &H256) -> Option<Bytes> {
|
||||||
|
// starts with 'f' ?
|
||||||
|
if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") {
|
||||||
|
let mut rlp = RlpStream::new();
|
||||||
|
rlp.append(&hash.clone());
|
||||||
|
return Some(rlp.out());
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn block_receipts(&self, _h: &H256) -> Option<Bytes> {
|
fn block_receipts(&self, hash: &H256) -> Option<Bytes> {
|
||||||
|
// starts with 'f' ?
|
||||||
|
if *hash > H256::from("f000000000000000000000000000000000000000000000000000000000000000") {
|
||||||
|
let receipt = Receipt::new(
|
||||||
|
H256::zero(),
|
||||||
|
U256::zero(),
|
||||||
|
vec![]);
|
||||||
|
let mut rlp = RlpStream::new();
|
||||||
|
rlp.append(&receipt);
|
||||||
|
return Some(rlp.out());
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +230,7 @@ pub struct TestIo<'p> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'p> TestIo<'p> {
|
impl<'p> TestIo<'p> {
|
||||||
fn new(chain: &'p mut TestBlockChainClient, queue: &'p mut VecDeque<TestPacket>, sender: Option<PeerId>) -> TestIo<'p> {
|
pub fn new(chain: &'p mut TestBlockChainClient, queue: &'p mut VecDeque<TestPacket>, sender: Option<PeerId>) -> TestIo<'p> {
|
||||||
TestIo {
|
TestIo {
|
||||||
chain: chain,
|
chain: chain,
|
||||||
queue: queue,
|
queue: queue,
|
||||||
|
@ -1,2 +1,18 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
mod chain;
|
mod chain;
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! benchmarking for rlp
|
//! benchmarking for rlp
|
||||||
//! should be started with:
|
//! should be started with:
|
||||||
//! ```bash
|
//! ```bash
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
#![feature(test)]
|
#![feature(test)]
|
||||||
|
|
||||||
extern crate test;
|
extern crate test;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate glob;
|
extern crate glob;
|
||||||
|
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! json rlp tests
|
//! json rlp tests
|
||||||
use rustc_serialize::*;
|
use rustc_serialize::*;
|
||||||
use super::{JsonTest, JsonLoader};
|
use super::{JsonTest, JsonLoader};
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! json trie tests
|
//! json trie tests
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use rustc_serialize::*;
|
use rustc_serialize::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
use rustc_serialize::hex::FromHex;
|
use rustc_serialize::hex::FromHex;
|
||||||
|
|
||||||
pub fn hex_or_string(s: &str) -> Vec<u8> {
|
pub fn hex_or_string(s: &str) -> Vec<u8> {
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
// build.rs
|
// build.rs
|
||||||
|
|
||||||
// Bring in a dependency on an externally maintained `gcc` package which manages
|
// Bring in a dependency on an externally maintained `gcc` package which manages
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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 {
|
extern {
|
||||||
pub fn sha3_256(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
|
pub fn sha3_256(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
|
||||||
pub fn sha3_512(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
|
pub fn sha3_512(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Unified interfaces for bytes operations on basic types
|
//! Unified interfaces for bytes operations on basic types
|
||||||
//!
|
//!
|
||||||
//! # Examples
|
//! # Examples
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Multilevel blockchain bloom filter.
|
//! Multilevel blockchain bloom filter.
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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 common types and macros global reexport.
|
//! Utils common types and macros global reexport.
|
||||||
|
|
||||||
pub use standard::*;
|
pub use standard::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Ethcore crypto.
|
//! Ethcore crypto.
|
||||||
|
|
||||||
use hash::*;
|
use hash::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! General error types for use in ethcore.
|
//! General error types for use in ethcore.
|
||||||
|
|
||||||
use rustc_serialize::hex::FromHexError;
|
use rustc_serialize::hex::FromHexError;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! Coversion from json.
|
//! Coversion from json.
|
||||||
|
|
||||||
use standard::*;
|
use standard::*;
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
//! General hash types, a fixed-size raw-data type used as the output of hash functions.
|
//! General hash types, a fixed-size raw-data type used as the output of hash functions.
|
||||||
|
|
||||||
use standard::*;
|
use standard::*;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user