serde is no longer util dependency (#1534)

* removed old json-tests

* simplify folds in triehash.rs

* removed unused json_aid

* removed unused squeeze.rs

* json branching tests for trie

* removing todos from util

* separated UsingQueue and Table

* further cleanup, removing unused code

* serde serialization of hash moved to rpc module

* uint wrapper for rpc in progress

* serialization of uint moved to rpc module

* updated eth-secp256k1

* updated igd, serde is no longer dependency of util

* loading trie consensus tests

* renamed aliases in rpc imports
This commit is contained in:
Marek Kotewicz 2016-07-06 11:23:29 +02:00 committed by Gav Wood
parent cb1808d53d
commit bcb63bce12
55 changed files with 854 additions and 717 deletions

92
Cargo.lock generated
View File

@ -70,7 +70,6 @@ dependencies = [
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -149,15 +148,6 @@ dependencies = [
"unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "cookie"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "cookie" name = "cookie"
version = "0.2.4" version = "0.2.4"
@ -225,15 +215,13 @@ dependencies = [
[[package]] [[package]]
name = "eth-secp256k1" name = "eth-secp256k1"
version = "0.5.4" version = "0.5.4"
source = "git+https://github.com/ethcore/rust-secp256k1#b6fdd43bbcf6d46adb72a92dd1632a0fc834cbf5" source = "git+https://github.com/ethcore/rust-secp256k1#a9a0b1be1f39560ca86e8fc8e55e205a753ff25c"
dependencies = [ dependencies = [
"arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -388,7 +376,7 @@ dependencies = [
"eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)", "eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)",
"ethcore-devtools 1.3.0", "ethcore-devtools 1.3.0",
"heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"igd 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "igd 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.4.13 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
@ -400,12 +388,13 @@ dependencies = [
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
"sha3 0.1.0", "sha3 0.1.0",
"slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"table 0.1.0",
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"using_queue 0.1.0",
"vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
@ -505,26 +494,6 @@ name = "httparse"
version = "1.1.2" version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "hyper"
version = "0.6.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cookie 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)",
"httparse 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"language-tags 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"mime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
"traitobject 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 0.2.38 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "hyper" name = "hyper"
version = "0.8.1" version = "0.8.1"
@ -578,10 +547,10 @@ dependencies = [
[[package]] [[package]]
name = "igd" name = "igd"
version = "0.4.2" version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"hyper 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)",
"xml-rs 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "xml-rs 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
@ -638,11 +607,6 @@ dependencies = [
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "language-tags"
version = "0.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "language-tags" name = "language-tags"
version = "0.2.2" version = "0.2.2"
@ -676,15 +640,6 @@ dependencies = [
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "mime"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "mime" name = "mime"
version = "0.2.0" version = "0.2.0"
@ -1145,14 +1100,6 @@ dependencies = [
"nom 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "nom 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "serde"
version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "serde" name = "serde"
version = "0.7.9" version = "0.7.9"
@ -1244,6 +1191,10 @@ dependencies = [
"unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "table"
version = "0.1.0"
[[package]] [[package]]
name = "target_info" name = "target_info"
version = "0.1.0" version = "0.1.0"
@ -1350,16 +1301,6 @@ name = "unicode-xid"
version = "0.0.3" version = "0.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "url"
version = "0.2.38"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "url" name = "url"
version = "0.5.9" version = "0.5.9"
@ -1381,20 +1322,15 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "using_queue"
version = "0.1.0"
[[package]] [[package]]
name = "utf8-ranges" name = "utf8-ranges"
version = "0.1.3" version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "uuid"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "uuid" name = "uuid"
version = "0.2.1" version = "0.2.1"

View File

@ -127,7 +127,7 @@ impl Account {
SecTrieDBMut would not set it to an invalid state root. Therefore the root is valid and DB creation \ SecTrieDBMut would not set it to an invalid state root. Therefore the root is valid and DB creation \
using it will not fail."); using it will not fail.");
(Filth::Clean, H256::from(db.get(key.bytes()).map_or(U256::zero(), |v| -> U256 {decode(v)}))) (Filth::Clean, H256::from(db.get(key).map_or(U256::zero(), |v| -> U256 {decode(v)})))
}).1.clone() }).1.clone()
} }

View File

@ -92,10 +92,10 @@ impl PartialEq for Header {
impl Default for Header { impl Default for Header {
fn default() -> Self { fn default() -> Self {
Header { Header {
parent_hash: ZERO_H256.clone(), parent_hash: H256::default(),
timestamp: 0, timestamp: 0,
number: 0, number: 0,
author: ZERO_ADDRESS.clone(), author: Address::default(),
transactions_root: SHA3_NULL_RLP, transactions_root: SHA3_NULL_RLP,
uncles_hash: SHA3_EMPTY_LIST_RLP, uncles_hash: SHA3_EMPTY_LIST_RLP,
@ -104,10 +104,10 @@ impl Default for Header {
state_root: SHA3_NULL_RLP, state_root: SHA3_NULL_RLP,
receipts_root: SHA3_NULL_RLP, receipts_root: SHA3_NULL_RLP,
log_bloom: ZERO_LOGBLOOM.clone(), log_bloom: ZERO_LOGBLOOM.clone(),
gas_used: ZERO_U256, gas_used: U256::default(),
gas_limit: ZERO_U256, gas_limit: U256::default(),
difficulty: ZERO_U256, difficulty: U256::default(),
seal: vec![], seal: vec![],
hash: RefCell::new(None), hash: RefCell::new(None),
bare_hash: RefCell::new(None), bare_hash: RefCell::new(None),

View File

@ -19,6 +19,7 @@ use std::sync::atomic::AtomicBool;
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
use util::*; use util::*;
use util::using_queue::{UsingQueue, GetAction};
use util::Colour::White; use util::Colour::White;
use account_provider::AccountProvider; use account_provider::AccountProvider;
use views::{BlockView, HeaderView}; use views::{BlockView, HeaderView};

View File

@ -87,7 +87,7 @@ use std::cmp;
use std::collections::{HashMap, BTreeSet}; use std::collections::{HashMap, BTreeSet};
use util::numbers::{Uint, U256}; use util::numbers::{Uint, U256};
use util::hash::{Address, H256}; use util::hash::{Address, H256};
use util::table::*; use util::table::Table;
use transaction::*; use transaction::*;
use error::{Error, TransactionError}; use error::{Error, TransactionError};
use client::TransactionImportResult; use client::TransactionImportResult;

View File

@ -16,8 +16,10 @@
mod poll_manager; mod poll_manager;
mod poll_filter; mod poll_filter;
mod requests;
mod signing_queue; mod signing_queue;
pub use self::poll_manager::PollManager; pub use self::poll_manager::PollManager;
pub use self::poll_filter::PollFilter; pub use self::poll_filter::PollFilter;
pub use self::signing_queue::{ConfirmationsQueue, SigningQueue}; pub use self::requests::{TransactionRequest, TransactionConfirmation, CallRequest};
pub use self::signing_queue::{ConfirmationsQueue, SigningQueue, QueueEvent};

View File

@ -0,0 +1,64 @@
// 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::{Address, U256};
/// Transaction request coming from RPC
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash)]
pub struct TransactionRequest {
/// Sender
pub from: Address,
/// Recipient
pub to: Option<Address>,
/// Gas Price
pub gas_price: Option<U256>,
/// Gas
pub gas: Option<U256>,
/// Value of transaction in wei
pub value: Option<U256>,
/// Additional data sent with transaction
pub data: Option<Vec<u8>>,
/// Transaction's nonce
pub nonce: Option<U256>,
}
/// Transaction confirmation waiting in a queue
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash)]
pub struct TransactionConfirmation {
/// Id of this confirmation
pub id: U256,
/// TransactionRequest
pub transaction: TransactionRequest,
}
/// Call request
#[derive(Debug, Default, PartialEq)]
pub struct CallRequest {
/// From
pub from: Option<Address>,
/// To
pub to: Option<Address>,
/// Gas Price
pub gas_price: Option<U256>,
/// Gas
pub gas: Option<U256>,
/// Value
pub value: Option<U256>,
/// Data
pub data: Option<Vec<u8>>,
/// Nonce
pub nonce: Option<U256>,
}

View File

@ -18,9 +18,9 @@ use std::thread;
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
use std::sync::{mpsc, Mutex, RwLock, Arc}; use std::sync::{mpsc, Mutex, RwLock, Arc};
use std::collections::HashMap; use std::collections::HashMap;
use v1::types::{TransactionRequest, TransactionConfirmation};
use util::U256;
use jsonrpc_core; use jsonrpc_core;
use util::U256;
use v1::helpers::{TransactionRequest, TransactionConfirmation};
/// Result that can be returned from JSON RPC. /// Result that can be returned from JSON RPC.
pub type RpcResult = Result<jsonrpc_core::Value, jsonrpc_core::Error>; pub type RpcResult = Result<jsonrpc_core::Value, jsonrpc_core::Error>;
@ -301,10 +301,9 @@ mod test {
use std::time::Duration; use std::time::Duration;
use std::thread; use std::thread;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use util::hash::Address; use util::{Address, U256, H256};
use util::numbers::{U256, H256}; use v1::helpers::{SigningQueue, ConfirmationsQueue, QueueEvent, TransactionRequest};
use v1::types::TransactionRequest; use v1::types::H256 as NH256;
use super::*;
use jsonrpc_core::to_value; use jsonrpc_core::to_value;
fn request() -> TransactionRequest { fn request() -> TransactionRequest {
@ -337,10 +336,10 @@ mod test {
// Just wait for the other thread to start // Just wait for the other thread to start
thread::sleep(Duration::from_millis(100)); thread::sleep(Duration::from_millis(100));
} }
queue.request_confirmed(id, to_value(&H256::from(1))); queue.request_confirmed(id, to_value(&NH256::from(H256::from(1))));
// then // then
assert_eq!(handle.join().expect("Thread should finish nicely"), to_value(&H256::from(1))); assert_eq!(handle.join().expect("Thread should finish nicely"), to_value(&NH256::from(H256::from(1))));
} }
#[test] #[test]

View File

@ -38,7 +38,8 @@ use ethcore::log_entry::LogEntry;
use ethcore::filter::Filter as EthcoreFilter; use ethcore::filter::Filter as EthcoreFilter;
use self::ethash::SeedHashCompute; use self::ethash::SeedHashCompute;
use v1::traits::Eth; use v1::traits::Eth;
use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, OptionalValue, Index, Filter, Log, Receipt}; use v1::types::{Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, Index, Filter, Log, Receipt, H64 as RpcH64, H256 as RpcH256, H160 as RpcH160, U256 as RpcU256};
use v1::helpers::CallRequest as CRequest;
use v1::impls::{default_gas_price, dispatch_transaction, error_codes}; use v1::impls::{default_gas_price, dispatch_transaction, error_codes};
use serde; use serde;
use ethcore::header::Header as BlockHeader; use ethcore::header::Header as BlockHeader;
@ -86,28 +87,28 @@ impl<C, S, M, EM> EthClient<C, S, M, EM> where
let block_view = BlockView::new(&bytes); let block_view = BlockView::new(&bytes);
let view = block_view.header_view(); let view = block_view.header_view();
let block = Block { let block = Block {
hash: OptionalValue::Value(view.sha3()), hash: Some(view.sha3().into()),
parent_hash: view.parent_hash(), parent_hash: view.parent_hash().into(),
uncles_hash: view.uncles_hash(), uncles_hash: view.uncles_hash().into(),
author: view.author(), author: view.author().into(),
miner: view.author(), miner: view.author().into(),
state_root: view.state_root(), state_root: view.state_root().into(),
transactions_root: view.transactions_root(), transactions_root: view.transactions_root().into(),
receipts_root: view.receipts_root(), receipts_root: view.receipts_root().into(),
number: OptionalValue::Value(U256::from(view.number())), number: Some(view.number().into()),
gas_used: view.gas_used(), gas_used: view.gas_used().into(),
gas_limit: view.gas_limit(), gas_limit: view.gas_limit().into(),
logs_bloom: view.log_bloom(), logs_bloom: view.log_bloom().into(),
timestamp: U256::from(view.timestamp()), timestamp: view.timestamp().into(),
difficulty: view.difficulty(), difficulty: view.difficulty().into(),
total_difficulty: total_difficulty, total_difficulty: total_difficulty.into(),
seal_fields: view.seal().into_iter().map(|f| decode(&f)).map(Bytes::new).collect(), seal_fields: view.seal().into_iter().map(|f| decode(&f)).map(Bytes::new).collect(),
uncles: block_view.uncle_hashes(), uncles: block_view.uncle_hashes().into_iter().map(Into::into).collect(),
transactions: { transactions: {
if include_txs { if include_txs {
BlockTransactions::Full(block_view.localized_transactions().into_iter().map(From::from).collect()) BlockTransactions::Full(block_view.localized_transactions().into_iter().map(Into::into).collect())
} else { } else {
BlockTransactions::Hashes(block_view.transaction_hashes()) BlockTransactions::Hashes(block_view.transaction_hashes().into_iter().map(Into::into).collect())
} }
}, },
extra_data: Bytes::new(view.extra_data()) extra_data: Bytes::new(view.extra_data())
@ -127,7 +128,6 @@ impl<C, S, M, EM> EthClient<C, S, M, EM> where
fn uncle(&self, id: UncleID) -> Result<Value, Error> { fn uncle(&self, id: UncleID) -> Result<Value, Error> {
let client = take_weak!(self.client); let client = take_weak!(self.client);
let uncle: BlockHeader = match client.uncle(id) { let uncle: BlockHeader = match client.uncle(id) {
Some(rlp) => decode(&rlp), Some(rlp) => decode(&rlp),
None => { return Ok(Value::Null); } None => { return Ok(Value::Null); }
@ -138,22 +138,22 @@ impl<C, S, M, EM> EthClient<C, S, M, EM> where
}; };
let block = Block { let block = Block {
hash: OptionalValue::Value(uncle.hash()), hash: Some(uncle.hash().into()),
parent_hash: uncle.parent_hash, parent_hash: uncle.parent_hash.into(),
uncles_hash: uncle.uncles_hash, uncles_hash: uncle.uncles_hash.into(),
author: uncle.author, author: uncle.author.into(),
miner: uncle.author, miner: uncle.author.into(),
state_root: uncle.state_root, state_root: uncle.state_root.into(),
transactions_root: uncle.transactions_root, transactions_root: uncle.transactions_root.into(),
number: OptionalValue::Value(U256::from(uncle.number)), number: Some(uncle.number.into()),
gas_used: uncle.gas_used, gas_used: uncle.gas_used.into(),
gas_limit: uncle.gas_limit, gas_limit: uncle.gas_limit.into(),
logs_bloom: uncle.log_bloom, logs_bloom: uncle.log_bloom.into(),
timestamp: U256::from(uncle.timestamp), timestamp: uncle.timestamp.into(),
difficulty: uncle.difficulty, difficulty: uncle.difficulty.into(),
total_difficulty: uncle.difficulty + parent_difficulty, total_difficulty: (uncle.difficulty + parent_difficulty).into(),
receipts_root: uncle.receipts_root, receipts_root: uncle.receipts_root.into(),
extra_data: Bytes::new(uncle.extra_data), extra_data: uncle.extra_data.into(),
seal_fields: uncle.seal.into_iter().map(|f| decode(&f)).map(Bytes::new).collect(), seal_fields: uncle.seal.into_iter().map(|f| decode(&f)).map(Bytes::new).collect(),
uncles: vec![], uncles: vec![],
transactions: BlockTransactions::Hashes(vec![]), transactions: BlockTransactions::Hashes(vec![]),
@ -161,7 +161,7 @@ impl<C, S, M, EM> EthClient<C, S, M, EM> where
to_value(&block) to_value(&block)
} }
fn sign_call(&self, request: CallRequest) -> Result<SignedTransaction, Error> { fn sign_call(&self, request: CRequest) -> Result<SignedTransaction, Error> {
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner)); let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
let from = request.from.unwrap_or(Address::zero()); let from = request.from.unwrap_or(Address::zero());
Ok(EthTransaction { Ok(EthTransaction {
@ -186,7 +186,7 @@ pub fn pending_logs<M>(miner: &M, filter: &EthcoreFilter) -> Vec<Log> where M: M
.filter(|pair| filter.matches(&pair.1)) .filter(|pair| filter.matches(&pair.1))
.map(|pair| { .map(|pair| {
let mut log = Log::from(pair.1); let mut log = Log::from(pair.1);
log.transaction_hash = Some(pair.0); log.transaction_hash = Some(pair.0.into());
log log
}) })
.collect(); .collect();
@ -277,15 +277,17 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
SyncState::Idle => SyncStatus::None, SyncState::Idle => SyncStatus::None,
SyncState::Waiting | SyncState::Blocks | SyncState::NewBlocks | SyncState::ChainHead => { SyncState::Waiting | SyncState::Blocks | SyncState::NewBlocks | SyncState::ChainHead => {
let current_block = U256::from(take_weak!(self.client).chain_info().best_block_number); let current_block = U256::from(take_weak!(self.client).chain_info().best_block_number);
let highest_block = U256::from(status.highest_block_number.unwrap_or(status.start_block_number));
let info = SyncInfo { if highest_block > current_block + U256::from(6) {
starting_block: U256::from(status.start_block_number), let info = SyncInfo {
current_block: current_block, starting_block: status.start_block_number.into(),
highest_block: U256::from(status.highest_block_number.unwrap_or(status.start_block_number)) current_block: current_block.into(),
}; highest_block: highest_block.into(),
match info.highest_block > info.current_block + U256::from(6) { };
true => SyncStatus::Info(info), SyncStatus::Info(info)
false => SyncStatus::None, } else {
SyncStatus::None
} }
} }
}; };
@ -298,7 +300,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn author(&self, params: Params) -> Result<Value, Error> { fn author(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
match params { match params {
Params::None => to_value(&take_weak!(self.miner).author()), Params::None => to_value(&RpcH160::from(take_weak!(self.miner).author())),
_ => Err(Error::invalid_params()), _ => Err(Error::invalid_params()),
} }
} }
@ -314,7 +316,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn hashrate(&self, params: Params) -> Result<Value, Error> { fn hashrate(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
match params { match params {
Params::None => to_value(&self.external_miner.hashrate()), Params::None => to_value(&RpcU256::from(self.external_miner.hashrate())),
_ => Err(Error::invalid_params()) _ => Err(Error::invalid_params())
} }
} }
@ -324,7 +326,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
match params { match params {
Params::None => { Params::None => {
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner)); let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
to_value(&default_gas_price(&*client, &*miner)) to_value(&RpcU256::from(default_gas_price(&*client, &*miner)))
} }
_ => Err(Error::invalid_params()) _ => Err(Error::invalid_params())
} }
@ -333,13 +335,13 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn accounts(&self, _: Params) -> Result<Value, Error> { fn accounts(&self, _: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
let store = take_weak!(self.accounts); let store = take_weak!(self.accounts);
to_value(&store.accounts()) to_value(&store.accounts().into_iter().map(Into::into).collect::<Vec<RpcH160>>())
} }
fn block_number(&self, params: Params) -> Result<Value, Error> { fn block_number(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
match params { match params {
Params::None => to_value(&U256::from(take_weak!(self.client).chain_info().best_block_number)), Params::None => to_value(&RpcU256::from(take_weak!(self.client).chain_info().best_block_number)),
_ => Err(Error::invalid_params()) _ => Err(Error::invalid_params())
} }
} }
@ -347,39 +349,50 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn balance(&self, params: Params) -> Result<Value, Error> { fn balance(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params_default_second(params) from_params_default_second(params)
.and_then(|(address, block_number,)| match block_number { .and_then(|(address, block_number,)| {
BlockNumber::Pending => to_value(&take_weak!(self.miner).balance(take_weak!(self.client).deref(), &address)), let address: Address = RpcH160::into(address);
id => to_value(&try!(take_weak!(self.client).balance(&address, id.into()).ok_or_else(make_unsupported_err))), match block_number {
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).balance(take_weak!(self.client).deref(), &address))),
id => to_value(&RpcU256::from(try!(take_weak!(self.client).balance(&address, id.into()).ok_or_else(make_unsupported_err)))),
}
}) })
} }
fn storage_at(&self, params: Params) -> Result<Value, Error> { fn storage_at(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params_default_third::<Address, U256>(params) from_params_default_third::<RpcH160, RpcU256>(params)
.and_then(|(address, position, block_number,)| match block_number { .and_then(|(address, position, block_number,)| {
BlockNumber::Pending => to_value(&U256::from(take_weak!(self.miner).storage_at(&*take_weak!(self.client), &address, &H256::from(position)))), let address: Address = RpcH160::into(address);
id => match take_weak!(self.client).storage_at(&address, &H256::from(position), id.into()) { let position: U256 = RpcU256::into(position);
Some(s) => to_value(&U256::from(s)), match block_number {
None => Err(make_unsupported_err()), // None is only returned on unsupported requests. BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).storage_at(&*take_weak!(self.client), &address, &H256::from(position)))),
id => match take_weak!(self.client).storage_at(&address, &H256::from(position), id.into()) {
Some(s) => to_value(&RpcU256::from(s)),
None => Err(make_unsupported_err()), // None is only returned on unsupported requests.
}
} }
}) })
} }
fn transaction_count(&self, params: Params) -> Result<Value, Error> { fn transaction_count(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params_default_second(params) from_params_default_second(params)
.and_then(|(address, block_number,)| match block_number { .and_then(|(address, block_number,)| {
BlockNumber::Pending => to_value(&take_weak!(self.miner).nonce(take_weak!(self.client).deref(), &address)), let address: Address = RpcH160::into(address);
id => to_value(&take_weak!(self.client).nonce(&address, id.into())), match block_number {
BlockNumber::Pending => to_value(&RpcU256::from(take_weak!(self.miner).nonce(take_weak!(self.client).deref(), &address))),
id => to_value(&take_weak!(self.client).nonce(&address, id.into()).map(RpcU256::from)),
}
}) })
} }
fn block_transaction_count_by_hash(&self, params: Params) -> Result<Value, Error> { fn block_transaction_count_by_hash(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H256,)>(params) from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| // match .and_then(|(hash,)| // match
take_weak!(self.client).block(BlockID::Hash(hash)) take_weak!(self.client).block(BlockID::Hash(hash.into()))
.map_or(Ok(Value::Null), |bytes| to_value(&U256::from(BlockView::new(&bytes).transactions_count())))) .map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).transactions_count()))))
} }
fn block_transaction_count_by_number(&self, params: Params) -> Result<Value, Error> { fn block_transaction_count_by_number(&self, params: Params) -> Result<Value, Error> {
@ -387,45 +400,48 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
from_params::<(BlockNumber,)>(params) from_params::<(BlockNumber,)>(params)
.and_then(|(block_number,)| match block_number { .and_then(|(block_number,)| match block_number {
BlockNumber::Pending => to_value( BlockNumber::Pending => to_value(
&U256::from(take_weak!(self.miner).status().transactions_in_pending_block) &RpcU256::from(take_weak!(self.miner).status().transactions_in_pending_block)
), ),
_ => take_weak!(self.client).block(block_number.into()) _ => take_weak!(self.client).block(block_number.into())
.map_or(Ok(Value::Null), |bytes| to_value(&U256::from(BlockView::new(&bytes).transactions_count()))) .map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).transactions_count())))
}) })
} }
fn block_uncles_count_by_hash(&self, params: Params) -> Result<Value, Error> { fn block_uncles_count_by_hash(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H256,)>(params) from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| .and_then(|(hash,)|
take_weak!(self.client).block(BlockID::Hash(hash)) take_weak!(self.client).block(BlockID::Hash(hash.into()))
.map_or(Ok(Value::Null), |bytes| to_value(&U256::from(BlockView::new(&bytes).uncles_count())))) .map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).uncles_count()))))
} }
fn block_uncles_count_by_number(&self, params: Params) -> Result<Value, Error> { fn block_uncles_count_by_number(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(BlockNumber,)>(params) from_params::<(BlockNumber,)>(params)
.and_then(|(block_number,)| match block_number { .and_then(|(block_number,)| match block_number {
BlockNumber::Pending => to_value(&U256::from(0)), BlockNumber::Pending => to_value(&RpcU256::from(0)),
_ => take_weak!(self.client).block(block_number.into()) _ => take_weak!(self.client).block(block_number.into())
.map_or(Ok(Value::Null), |bytes| to_value(&U256::from(BlockView::new(&bytes).uncles_count()))) .map_or(Ok(Value::Null), |bytes| to_value(&RpcU256::from(BlockView::new(&bytes).uncles_count())))
}) })
} }
fn code_at(&self, params: Params) -> Result<Value, Error> { fn code_at(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params_default_second(params) from_params_default_second(params)
.and_then(|(address, block_number,)| match block_number { .and_then(|(address, block_number,)| {
BlockNumber::Pending => to_value(&take_weak!(self.miner).code(take_weak!(self.client).deref(), &address).map_or_else(Bytes::default, Bytes::new)), let address: Address = RpcH160::into(address);
BlockNumber::Latest => to_value(&take_weak!(self.client).code(&address).map_or_else(Bytes::default, Bytes::new)), match block_number {
_ => Err(Error::invalid_params()), BlockNumber::Pending => to_value(&take_weak!(self.miner).code(take_weak!(self.client).deref(), &address).map_or_else(Bytes::default, Bytes::new)),
BlockNumber::Latest => to_value(&take_weak!(self.client).code(&address).map_or_else(Bytes::default, Bytes::new)),
_ => Err(Error::invalid_params()),
}
}) })
} }
fn block_by_hash(&self, params: Params) -> Result<Value, Error> { fn block_by_hash(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H256, bool)>(params) from_params::<(RpcH256, bool)>(params)
.and_then(|(hash, include_txs)| self.block(BlockID::Hash(hash), include_txs)) .and_then(|(hash, include_txs)| self.block(BlockID::Hash(hash.into()), include_txs))
} }
fn block_by_number(&self, params: Params) -> Result<Value, Error> { fn block_by_number(&self, params: Params) -> Result<Value, Error> {
@ -436,9 +452,10 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn transaction_by_hash(&self, params: Params) -> Result<Value, Error> { fn transaction_by_hash(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H256,)>(params) from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| { .and_then(|(hash,)| {
let miner = take_weak!(self.miner); let miner = take_weak!(self.miner);
let hash: H256 = hash.into();
match miner.transaction(&hash) { match miner.transaction(&hash) {
Some(pending_tx) => to_value(&Transaction::from(pending_tx)), Some(pending_tx) => to_value(&Transaction::from(pending_tx)),
None => self.transaction(TransactionID::Hash(hash)) None => self.transaction(TransactionID::Hash(hash))
@ -448,8 +465,8 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn transaction_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> { fn transaction_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H256, Index)>(params) from_params::<(RpcH256, Index)>(params)
.and_then(|(hash, index)| self.transaction(TransactionID::Location(BlockID::Hash(hash), index.value()))) .and_then(|(hash, index)| self.transaction(TransactionID::Location(BlockID::Hash(hash.into()), index.value())))
} }
fn transaction_by_block_number_and_index(&self, params: Params) -> Result<Value, Error> { fn transaction_by_block_number_and_index(&self, params: Params) -> Result<Value, Error> {
@ -460,9 +477,10 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn transaction_receipt(&self, params: Params) -> Result<Value, Error> { fn transaction_receipt(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H256,)>(params) from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| { .and_then(|(hash,)| {
let miner = take_weak!(self.miner); let miner = take_weak!(self.miner);
let hash: H256 = hash.into();
match miner.pending_receipts().get(&hash) { match miner.pending_receipts().get(&hash) {
Some(receipt) if self.allow_pending_receipt_query => to_value(&Receipt::from(receipt.clone())), Some(receipt) if self.allow_pending_receipt_query => to_value(&Receipt::from(receipt.clone())),
_ => { _ => {
@ -476,8 +494,8 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn uncle_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> { fn uncle_by_block_hash_and_index(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H256, Index)>(params) from_params::<(RpcH256, Index)>(params)
.and_then(|(hash, index)| self.uncle(UncleID { block: BlockID::Hash(hash), position: index.value() })) .and_then(|(hash, index)| self.uncle(UncleID { block: BlockID::Hash(hash.into()), position: index.value() }))
} }
fn uncle_by_block_number_and_index(&self, params: Params) -> Result<Value, Error> { fn uncle_by_block_number_and_index(&self, params: Params) -> Result<Value, Error> {
@ -543,8 +561,9 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
miner.map_sealing_work(client.deref(), |b| { miner.map_sealing_work(client.deref(), |b| {
let pow_hash = b.hash(); let pow_hash = b.hash();
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty()); let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
let seed_hash = &self.seed_compute.lock().unwrap().get_seedhash(b.block().header().number()); let seed_hash = self.seed_compute.lock().unwrap().get_seedhash(b.block().header().number());
to_value(&(pow_hash, H256::from_slice(&seed_hash[..]), target, &U256::from(b.block().header().number()))) let block_number = RpcU256::from(b.block().header().number());
to_value(&(RpcH256::from(pow_hash), RpcH256::from(seed_hash), RpcH256::from(target), block_number))
}).unwrap_or(Err(Error::internal_error())) // no work found. }).unwrap_or(Err(Error::internal_error())) // no work found.
}, },
_ => Err(Error::invalid_params()) _ => Err(Error::invalid_params())
@ -553,7 +572,10 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn submit_work(&self, params: Params) -> Result<Value, Error> { fn submit_work(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(H64, H256, H256)>(params).and_then(|(nonce, pow_hash, mix_hash)| { from_params::<(RpcH64, RpcH256, RpcH256)>(params).and_then(|(nonce, pow_hash, mix_hash)| {
let nonce: H64 = nonce.into();
let pow_hash: H256 = pow_hash.into();
let mix_hash: H256 = mix_hash.into();
trace!(target: "miner", "submit_work: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash); trace!(target: "miner", "submit_work: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash);
let miner = take_weak!(self.miner); let miner = take_weak!(self.miner);
let client = take_weak!(self.client); let client = take_weak!(self.client);
@ -565,8 +587,8 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
fn submit_hashrate(&self, params: Params) -> Result<Value, Error> { fn submit_hashrate(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(U256, H256)>(params).and_then(|(rate, id)| { from_params::<(RpcU256, RpcH256)>(params).and_then(|(rate, id)| {
self.external_miner.submit_hashrate(rate, id); self.external_miner.submit_hashrate(rate.into(), id.into());
to_value(&true) to_value(&true)
}) })
} }
@ -578,7 +600,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
let raw_transaction = raw_transaction.to_vec(); let raw_transaction = raw_transaction.to_vec();
match UntrustedRlp::new(&raw_transaction).as_val() { match UntrustedRlp::new(&raw_transaction).as_val() {
Ok(signed_transaction) => dispatch_transaction(&*take_weak!(self.client), &*take_weak!(self.miner), signed_transaction), Ok(signed_transaction) => dispatch_transaction(&*take_weak!(self.client), &*take_weak!(self.miner), signed_transaction),
Err(_) => to_value(&H256::zero()), Err(_) => to_value(&RpcH256::from(H256::from(0))),
} }
}) })
} }
@ -588,6 +610,7 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
trace!(target: "jsonrpc", "call: {:?}", params); trace!(target: "jsonrpc", "call: {:?}", params);
from_params_default_second(params) from_params_default_second(params)
.and_then(|(request, block_number,)| { .and_then(|(request, block_number,)| {
let request = CallRequest::into(request);
let signed = try!(self.sign_call(request)); let signed = try!(self.sign_call(request));
let r = match block_number { let r = match block_number {
BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()), BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()),
@ -602,13 +625,14 @@ impl<C, S, M, EM> Eth for EthClient<C, S, M, EM> where
try!(self.active()); try!(self.active());
from_params_default_second(params) from_params_default_second(params)
.and_then(|(request, block_number,)| { .and_then(|(request, block_number,)| {
let request = CallRequest::into(request);
let signed = try!(self.sign_call(request)); let signed = try!(self.sign_call(request));
let r = match block_number { let r = match block_number {
BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()), BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()),
BlockNumber::Latest => take_weak!(self.client).call(&signed, Default::default()), BlockNumber::Latest => take_weak!(self.client).call(&signed, Default::default()),
_ => return Err(Error::invalid_params()), _ => return Err(Error::invalid_params()),
}; };
to_value(&r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0))) to_value(&RpcU256::from(r.map(|res| res.gas_used + res.refunded).unwrap_or(From::from(0))))
}) })
} }

View File

@ -25,7 +25,7 @@ use ethcore::miner::MinerService;
use ethcore::filter::Filter as EthcoreFilter; use ethcore::filter::Filter as EthcoreFilter;
use ethcore::client::{BlockChainClient, BlockID}; use ethcore::client::{BlockChainClient, BlockID};
use v1::traits::EthFilter; use v1::traits::EthFilter;
use v1::types::{BlockNumber, Index, Filter, Log}; use v1::types::{BlockNumber, Index, Filter, Log, H256 as RpcH256, U256 as RpcU256};
use v1::helpers::{PollFilter, PollManager}; use v1::helpers::{PollFilter, PollManager};
use v1::impls::eth::pending_logs; use v1::impls::eth::pending_logs;
@ -71,7 +71,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
let mut polls = self.polls.lock().unwrap(); let mut polls = self.polls.lock().unwrap();
let block_number = take_weak!(self.client).chain_info().best_block_number; let block_number = take_weak!(self.client).chain_info().best_block_number;
let id = polls.create_poll(PollFilter::Logs(block_number, Default::default(), filter)); let id = polls.create_poll(PollFilter::Logs(block_number, Default::default(), filter));
to_value(&U256::from(id)) to_value(&RpcU256::from(id))
}) })
} }
@ -81,7 +81,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
Params::None => { Params::None => {
let mut polls = self.polls.lock().unwrap(); let mut polls = self.polls.lock().unwrap();
let id = polls.create_poll(PollFilter::Block(take_weak!(self.client).chain_info().best_block_number)); let id = polls.create_poll(PollFilter::Block(take_weak!(self.client).chain_info().best_block_number));
to_value(&U256::from(id)) to_value(&RpcU256::from(id))
}, },
_ => Err(Error::invalid_params()) _ => Err(Error::invalid_params())
} }
@ -95,7 +95,7 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
let pending_transactions = take_weak!(self.miner).pending_transactions_hashes(); let pending_transactions = take_weak!(self.miner).pending_transactions_hashes();
let id = polls.create_poll(PollFilter::PendingTransaction(pending_transactions)); let id = polls.create_poll(PollFilter::PendingTransaction(pending_transactions));
to_value(&U256::from(id)) to_value(&RpcU256::from(id))
}, },
_ => Err(Error::invalid_params()) _ => Err(Error::invalid_params())
} }
@ -116,7 +116,8 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
let hashes = (*block_number..current_number).into_iter() let hashes = (*block_number..current_number).into_iter()
.map(BlockID::Number) .map(BlockID::Number)
.filter_map(|id| client.block_hash(id)) .filter_map(|id| client.block_hash(id))
.collect::<Vec<H256>>(); .map(Into::into)
.collect::<Vec<RpcH256>>();
*block_number = current_number; *block_number = current_number;
@ -135,7 +136,8 @@ impl<C, M> EthFilter for EthFilterClient<C, M> where
.iter() .iter()
.filter(|hash| !previous_hashes_set.contains(hash)) .filter(|hash| !previous_hashes_set.contains(hash))
.cloned() .cloned()
.collect::<Vec<H256>>() .map(Into::into)
.collect::<Vec<RpcH256>>()
}; };
// save all hashes of pending transactions // save all hashes of pending transactions

View File

@ -20,17 +20,17 @@ use std::sync::{Arc, Weak};
use jsonrpc_core::*; use jsonrpc_core::*;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use ethcore::client::MiningBlockChainClient; use ethcore::client::MiningBlockChainClient;
use util::numbers::*; use util::{U256, Address, H256};
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;
use v1::helpers::{SigningQueue, ConfirmationsQueue}; use v1::helpers::{SigningQueue, ConfirmationsQueue, TransactionRequest as TRequest};
use v1::traits::EthSigning; use v1::traits::EthSigning;
use v1::types::{TransactionRequest, Bytes}; use v1::types::{TransactionRequest, H160 as RpcH160, H256 as RpcH256, H520 as RpcH520};
use v1::impls::{default_gas_price, sign_and_dispatch}; use v1::impls::{default_gas_price, sign_and_dispatch};
fn fill_optional_fields<C, M>(request: &mut TransactionRequest, client: &C, miner: &M) fn fill_optional_fields<C, M>(request: &mut TRequest, client: &C, miner: &M)
where C: MiningBlockChainClient, M: MinerService { where C: MiningBlockChainClient, M: MinerService {
if request.value.is_none() { if request.value.is_none() {
request.value = Some(U256::zero()); request.value = Some(U256::from(0));
} }
if request.gas.is_none() { if request.gas.is_none() {
request.gas = Some(miner.sensible_gas_limit()); request.gas = Some(miner.sensible_gas_limit());
@ -39,7 +39,7 @@ fn fill_optional_fields<C, M>(request: &mut TransactionRequest, client: &C, mine
request.gas_price = Some(default_gas_price(client, miner)); request.gas_price = Some(default_gas_price(client, miner));
} }
if request.data.is_none() { if request.data.is_none() {
request.data = Some(Bytes::new(Vec::new())); request.data = Some(Vec::new());
} }
} }
@ -83,7 +83,8 @@ impl<C, M> EthSigning for EthSigningQueueClient<C, M>
fn send_transaction(&self, params: Params) -> Result<Value, Error> { fn send_transaction(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(TransactionRequest, )>(params) from_params::<(TransactionRequest, )>(params)
.and_then(|(mut request, )| { .and_then(|(request, )| {
let mut request: TRequest = request.into();
let accounts = take_weak!(self.accounts); let accounts = take_weak!(self.accounts);
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner)); let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
@ -91,7 +92,7 @@ impl<C, M> EthSigning for EthSigningQueueClient<C, M>
let sender = request.from; let sender = request.from;
return match sign_and_dispatch(&*client, &*miner, request, &*accounts, sender) { return match sign_and_dispatch(&*client, &*miner, request, &*accounts, sender) {
Ok(hash) => to_value(&hash), Ok(hash) => to_value(&hash),
_ => to_value(&H256::zero()), _ => to_value(&RpcH256::default()),
} }
} }
@ -99,7 +100,7 @@ impl<C, M> EthSigning for EthSigningQueueClient<C, M>
fill_optional_fields(&mut request, &*client, &*miner); fill_optional_fields(&mut request, &*client, &*miner);
let id = queue.add_request(request); let id = queue.add_request(request);
let result = id.wait_with_timeout(); let result = id.wait_with_timeout();
result.unwrap_or_else(|| to_value(&H256::new())) result.unwrap_or_else(|| to_value(&RpcH256::default()))
}) })
} }
} }
@ -140,8 +141,10 @@ impl<C, M> EthSigning for EthSigningUnsafeClient<C, M> where
fn sign(&self, params: Params) -> Result<Value, Error> { fn sign(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(Address, H256)>(params).and_then(|(addr, msg)| { from_params::<(RpcH160, RpcH256)>(params).and_then(|(address, msg)| {
to_value(&take_weak!(self.accounts).sign(addr, msg).unwrap_or(H520::zero())) let address: Address = address.into();
let msg: H256 = msg.into();
to_value(&take_weak!(self.accounts).sign(address, msg).ok().map_or_else(RpcH520::default, Into::into))
}) })
} }
@ -149,10 +152,11 @@ impl<C, M> EthSigning for EthSigningUnsafeClient<C, M> where
try!(self.active()); try!(self.active());
from_params::<(TransactionRequest, )>(params) from_params::<(TransactionRequest, )>(params)
.and_then(|(request, )| { .and_then(|(request, )| {
let request: TRequest = request.into();
let sender = request.from; let sender = request.from;
match sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), request, &*take_weak!(self.accounts), sender) { match sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), request, &*take_weak!(self.accounts), sender) {
Ok(hash) => to_value(&hash), Ok(hash) => to_value(&hash),
_ => to_value(&H256::zero()), _ => to_value(&RpcH256::default()),
} }
}) })
} }

View File

@ -25,7 +25,7 @@ use ethcore::client::{MiningBlockChainClient};
use jsonrpc_core::*; use jsonrpc_core::*;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use v1::traits::Ethcore; use v1::traits::Ethcore;
use v1::types::{Bytes}; use v1::types::{Bytes, U256};
use v1::helpers::{SigningQueue, ConfirmationsQueue}; use v1::helpers::{SigningQueue, ConfirmationsQueue};
use v1::impls::error_codes; use v1::impls::error_codes;
@ -69,7 +69,7 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
fn min_gas_price(&self, _: Params) -> Result<Value, Error> { fn min_gas_price(&self, _: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
to_value(&take_weak!(self.miner).minimal_gas_price()) to_value(&U256::from(take_weak!(self.miner).minimal_gas_price()))
} }
fn extra_data(&self, _: Params) -> Result<Value, Error> { fn extra_data(&self, _: Params) -> Result<Value, Error> {
@ -79,12 +79,12 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
fn gas_floor_target(&self, _: Params) -> Result<Value, Error> { fn gas_floor_target(&self, _: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
to_value(&take_weak!(self.miner).gas_floor_target()) to_value(&U256::from(take_weak!(self.miner).gas_floor_target()))
} }
fn gas_ceil_target(&self, _: Params) -> Result<Value, Error> { fn gas_ceil_target(&self, _: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
to_value(&take_weak!(self.miner).gas_ceil_target()) to_value(&U256::from(take_weak!(self.miner).gas_ceil_target()))
} }
fn dev_logs(&self, _params: Params) -> Result<Value, Error> { fn dev_logs(&self, _params: Params) -> Result<Value, Error> {
@ -140,8 +140,8 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where M: MinerService + 'static, C: M
match params { match params {
Params::None => match take_weak!(self.client).gas_price_statistics(100, 8) { Params::None => match take_weak!(self.client).gas_price_statistics(100, 8) {
Ok(stats) => to_value(&stats Ok(stats) => to_value(&stats
.iter() .into_iter()
.map(|x| to_value(&x).expect("x must be U256; qed")) .map(|x| to_value(&U256::from(x)).expect("x must be U256; qed"))
.collect::<Vec<_>>()), .collect::<Vec<_>>()),
_ => Err(Error::internal_error()), _ => Err(Error::internal_error()),
}, },

View File

@ -15,15 +15,14 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
/// Ethcore-specific rpc interface for operations altering the settings. /// Ethcore-specific rpc interface for operations altering the settings.
use util::{U256, Address};
use util::network::{NetworkService, NonReservedPeerMode};
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use jsonrpc_core::*; use jsonrpc_core::*;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use ethcore::client::MiningBlockChainClient; use ethcore::client::MiningBlockChainClient;
use ethcore::service::SyncMessage; use ethcore::service::SyncMessage;
use util::network::{NetworkService, NonReservedPeerMode};
use v1::traits::EthcoreSet; use v1::traits::EthcoreSet;
use v1::types::Bytes; use v1::types::{Bytes, H160, U256};
/// Ethcore-specific rpc interface for operations altering the settings. /// Ethcore-specific rpc interface for operations altering the settings.
pub struct EthcoreSetClient<C, M> where pub struct EthcoreSetClient<C, M> where
@ -61,7 +60,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
fn set_min_gas_price(&self, params: Params) -> Result<Value, Error> { fn set_min_gas_price(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(U256,)>(params).and_then(|(gas_price,)| { from_params::<(U256,)>(params).and_then(|(gas_price,)| {
take_weak!(self.miner).set_minimal_gas_price(gas_price); take_weak!(self.miner).set_minimal_gas_price(gas_price.into());
to_value(&true) to_value(&true)
}) })
} }
@ -69,7 +68,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
fn set_gas_floor_target(&self, params: Params) -> Result<Value, Error> { fn set_gas_floor_target(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(U256,)>(params).and_then(|(target,)| { from_params::<(U256,)>(params).and_then(|(target,)| {
take_weak!(self.miner).set_gas_floor_target(target); take_weak!(self.miner).set_gas_floor_target(target.into());
to_value(&true) to_value(&true)
}) })
} }
@ -77,7 +76,7 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
fn set_gas_ceil_target(&self, params: Params) -> Result<Value, Error> { fn set_gas_ceil_target(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(U256,)>(params).and_then(|(target,)| { from_params::<(U256,)>(params).and_then(|(target,)| {
take_weak!(self.miner).set_gas_ceil_target(target); take_weak!(self.miner).set_gas_ceil_target(target.into());
to_value(&true) to_value(&true)
}) })
} }
@ -92,8 +91,8 @@ impl<C, M> EthcoreSet for EthcoreSetClient<C, M> where
fn set_author(&self, params: Params) -> Result<Value, Error> { fn set_author(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(Address,)>(params).and_then(|(author,)| { from_params::<(H160,)>(params).and_then(|(author,)| {
take_weak!(self.miner).set_author(author); take_weak!(self.miner).set_author(author.into());
to_value(&true) to_value(&true)
}) })
} }

View File

@ -53,7 +53,8 @@ pub use self::ethcore_set::EthcoreSetClient;
pub use self::traces::TracesClient; pub use self::traces::TracesClient;
pub use self::rpc::RpcClient; pub use self::rpc::RpcClient;
use v1::types::TransactionRequest; use v1::helpers::TransactionRequest;
use v1::types::H256 as NH256;
use ethcore::error::Error as EthcoreError; use ethcore::error::Error as EthcoreError;
use ethcore::miner::{AccountDetails, MinerService}; use ethcore::miner::{AccountDetails, MinerService};
use ethcore::client::MiningBlockChainClient; use ethcore::client::MiningBlockChainClient;
@ -77,7 +78,7 @@ mod error_codes {
fn dispatch_transaction<C, M>(client: &C, miner: &M, signed_transaction: SignedTransaction) -> Result<Value, Error> fn dispatch_transaction<C, M>(client: &C, miner: &M, signed_transaction: SignedTransaction) -> Result<Value, Error>
where C: MiningBlockChainClient, M: MinerService { where C: MiningBlockChainClient, M: MinerService {
let hash = signed_transaction.hash(); let hash = NH256::from(signed_transaction.hash());
let import = miner.import_own_transaction(client, signed_transaction, |a: &Address| { let import = miner.import_own_transaction(client, signed_transaction, |a: &Address| {
AccountDetails { AccountDetails {

View File

@ -18,10 +18,11 @@
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use jsonrpc_core::*; use jsonrpc_core::*;
use v1::traits::Personal; use v1::traits::Personal;
use v1::types::TransactionRequest; use v1::types::{H160 as RpcH160, H256 as RpcH256, TransactionRequest};
use v1::impls::unlock_sign_and_dispatch; use v1::impls::unlock_sign_and_dispatch;
use v1::helpers::{TransactionRequest as TRequest};
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;
use util::numbers::*; use util::Address;
use ethcore::client::MiningBlockChainClient; use ethcore::client::MiningBlockChainClient;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
@ -63,7 +64,7 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
fn accounts(&self, _: Params) -> Result<Value, Error> { fn accounts(&self, _: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
let store = take_weak!(self.accounts); let store = take_weak!(self.accounts);
to_value(&store.accounts()) to_value(&store.accounts().into_iter().map(Into::into).collect::<Vec<RpcH160>>())
} }
fn new_account(&self, params: Params) -> Result<Value, Error> { fn new_account(&self, params: Params) -> Result<Value, Error> {
@ -72,7 +73,7 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
|(pass, )| { |(pass, )| {
let store = take_weak!(self.accounts); let store = take_weak!(self.accounts);
match store.new_account(&pass) { match store.new_account(&pass) {
Ok(address) => to_value(&address), Ok(address) => to_value(&RpcH160::from(address)),
Err(_) => Err(Error::internal_error()) Err(_) => Err(Error::internal_error())
} }
} }
@ -81,8 +82,9 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
fn unlock_account(&self, params: Params) -> Result<Value, Error> { fn unlock_account(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(Address, String, u64)>(params).and_then( from_params::<(RpcH160, String, u64)>(params).and_then(
|(account, account_pass, _)|{ |(account, account_pass, _)|{
let account: Address = account.into();
let store = take_weak!(self.accounts); let store = take_weak!(self.accounts);
match store.unlock_account_temporarily(account, account_pass) { match store.unlock_account_temporarily(account, account_pass) {
Ok(_) => Ok(Value::Bool(true)), Ok(_) => Ok(Value::Bool(true)),
@ -95,12 +97,13 @@ impl<C: 'static, M: 'static> Personal for PersonalClient<C, M> where C: MiningBl
try!(self.active()); try!(self.active());
from_params::<(TransactionRequest, String)>(params) from_params::<(TransactionRequest, String)>(params)
.and_then(|(request, password)| { .and_then(|(request, password)| {
let request: TRequest = request.into();
let sender = request.from; let sender = request.from;
let accounts = take_weak!(self.accounts); let accounts = take_weak!(self.accounts);
match unlock_sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), request, &*accounts, sender, password) { match unlock_sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), request, &*accounts, sender, password) {
Ok(hash) => to_value(&hash), Ok(hash) => Ok(hash),
_ => to_value(&H256::zero()), _ => to_value(&RpcH256::default()),
} }
}) })
} }

View File

@ -18,14 +18,13 @@
use std::sync::{Arc, Weak}; use std::sync::{Arc, Weak};
use jsonrpc_core::*; use jsonrpc_core::*;
use v1::traits::PersonalSigner;
use v1::types::TransactionModification;
use v1::impls::unlock_sign_and_dispatch;
use v1::helpers::{SigningQueue, ConfirmationsQueue};
use ethcore::account_provider::AccountProvider; use ethcore::account_provider::AccountProvider;
use util::numbers::*;
use ethcore::client::MiningBlockChainClient; use ethcore::client::MiningBlockChainClient;
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use v1::traits::PersonalSigner;
use v1::types::{TransactionModification, TransactionConfirmation, U256};
use v1::impls::unlock_sign_and_dispatch;
use v1::helpers::{SigningQueue, ConfirmationsQueue};
/// Transactions confirmation (personal) rpc implementation. /// Transactions confirmation (personal) rpc implementation.
pub struct SignerClient<C, M> where C: MiningBlockChainClient, M: MinerService { pub struct SignerClient<C, M> where C: MiningBlockChainClient, M: MinerService {
@ -59,13 +58,14 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
fn transactions_to_confirm(&self, _params: Params) -> Result<Value, Error> { fn transactions_to_confirm(&self, _params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
let queue = take_weak!(self.queue); let queue = take_weak!(self.queue);
to_value(&queue.requests()) to_value(&queue.requests().into_iter().map(From::from).collect::<Vec<TransactionConfirmation>>())
} }
fn confirm_transaction(&self, params: Params) -> Result<Value, Error> { fn confirm_transaction(&self, params: Params) -> Result<Value, Error> {
try!(self.active()); try!(self.active());
from_params::<(U256, TransactionModification, String)>(params).and_then( from_params::<(U256, TransactionModification, String)>(params).and_then(
|(id, modification, pass)| { |(id, modification, pass)| {
let id = id.into();
let accounts = take_weak!(self.accounts); let accounts = take_weak!(self.accounts);
let queue = take_weak!(self.queue); let queue = take_weak!(self.queue);
let client = take_weak!(self.client); let client = take_weak!(self.client);
@ -74,7 +74,7 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
let mut request = confirmation.transaction; let mut request = confirmation.transaction;
// apply modification // apply modification
if let Some(gas_price) = modification.gas_price { if let Some(gas_price) = modification.gas_price {
request.gas_price = Some(gas_price); request.gas_price = Some(gas_price.into());
} }
let sender = request.from; let sender = request.from;
@ -99,7 +99,7 @@ impl<C: 'static, M: 'static> PersonalSigner for SignerClient<C, M> where C: Mini
from_params::<(U256, )>(params).and_then( from_params::<(U256, )>(params).and_then(
|(id, )| { |(id, )| {
let queue = take_weak!(self.queue); let queue = take_weak!(self.queue);
let res = queue.request_rejected(id); let res = queue.request_rejected(id.into());
to_value(&res.is_some()) to_value(&res.is_some())
} }
) )

View File

@ -19,12 +19,13 @@
use std::sync::{Weak, Arc}; use std::sync::{Weak, Arc};
use jsonrpc_core::*; use jsonrpc_core::*;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use util::H256; //use util::H256;
use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId}; use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId};
use ethcore::miner::MinerService; use ethcore::miner::MinerService;
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action}; use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
use v1::traits::Traces; use v1::traits::Traces;
use v1::types::{TraceFilter, LocalizedTrace, Trace, BlockNumber, Index, CallRequest, Bytes, StateDiff, VMTrace}; use v1::helpers::CallRequest as CRequest;
use v1::types::{TraceFilter, LocalizedTrace, Trace, BlockNumber, Index, CallRequest, Bytes, StateDiff, VMTrace, H256};
/// Traces api implementation. /// Traces api implementation.
pub struct TracesClient<C, M> where C: BlockChainClient, M: MinerService { pub struct TracesClient<C, M> where C: BlockChainClient, M: MinerService {
@ -42,7 +43,7 @@ impl<C, M> TracesClient<C, M> where C: BlockChainClient, M: MinerService {
} }
// TODO: share with eth.rs // TODO: share with eth.rs
fn sign_call(&self, request: CallRequest) -> Result<SignedTransaction, Error> { fn sign_call(&self, request: CRequest) -> Result<SignedTransaction, Error> {
let client = take_weak!(self.client); let client = take_weak!(self.client);
let miner = take_weak!(self.miner); let miner = take_weak!(self.miner);
let from = request.from.unwrap_or(0.into()); let from = request.from.unwrap_or(0.into());
@ -91,7 +92,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
from_params::<(H256,)>(params) from_params::<(H256,)>(params)
.and_then(|(transaction_hash,)| { .and_then(|(transaction_hash,)| {
let client = take_weak!(self.client); let client = take_weak!(self.client);
let traces = client.transaction_traces(TransactionID::Hash(transaction_hash)); let traces = client.transaction_traces(TransactionID::Hash(transaction_hash.into()));
let traces = traces.map_or_else(Vec::new, |traces| traces.into_iter().map(LocalizedTrace::from).collect()); let traces = traces.map_or_else(Vec::new, |traces| traces.into_iter().map(LocalizedTrace::from).collect());
to_value(&traces) to_value(&traces)
}) })
@ -103,7 +104,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
.and_then(|(transaction_hash, address)| { .and_then(|(transaction_hash, address)| {
let client = take_weak!(self.client); let client = take_weak!(self.client);
let id = TraceId { let id = TraceId {
transaction: TransactionID::Hash(transaction_hash), transaction: TransactionID::Hash(transaction_hash.into()),
address: address.into_iter().map(|i| i.value()).collect() address: address.into_iter().map(|i| i.value()).collect()
}; };
let trace = client.trace(id); let trace = client.trace(id);
@ -117,6 +118,7 @@ impl<C, M> Traces for TracesClient<C, M> where C: BlockChainClient + 'static, M:
trace!(target: "jsonrpc", "call: {:?}", params); trace!(target: "jsonrpc", "call: {:?}", params);
from_params(params) from_params(params)
.and_then(|(request, flags)| { .and_then(|(request, flags)| {
let request = CallRequest::into(request);
let flags: Vec<String> = flags; let flags: Vec<String> = flags;
let analytics = CallAnalytics { let analytics = CallAnalytics {
transaction_tracing: flags.contains(&("trace".to_owned())), transaction_tracing: flags.contains(&("trace".to_owned())),

View File

@ -18,7 +18,7 @@
use jsonrpc_core::*; use jsonrpc_core::*;
use util::version; use util::version;
use v1::traits::Web3; use v1::traits::Web3;
use v1::types::Bytes; use v1::types::{H256, Bytes};
use util::sha3::Hashable; use util::sha3::Hashable;
/// Web3 rpc implementation. /// Web3 rpc implementation.
@ -40,9 +40,9 @@ impl Web3 for Web3Client {
fn sha3(&self, params: Params) -> Result<Value, Error> { fn sha3(&self, params: Params) -> Result<Value, Error> {
from_params::<(Bytes,)>(params).and_then( from_params::<(Bytes,)>(params).and_then(
|(data,)| { |(data,)| {
let Bytes(ref v) = data; let Bytes(ref vec) = data;
let sha3 = v.sha3(); let sha3 = vec.sha3();
to_value(&sha3) to_value(&H256::from(sha3))
} }
) )
} }

View File

@ -34,6 +34,7 @@ use util::{U256, H256, Uint};
use jsonrpc_core::IoHandler; use jsonrpc_core::IoHandler;
use ethjson::blockchain::BlockChain; use ethjson::blockchain::BlockChain;
use v1::types::U256 as NU256;
use v1::traits::eth::{Eth, EthSigning}; use v1::traits::eth::{Eth, EthSigning};
use v1::impls::{EthClient, EthSigningUnsafeClient}; use v1::impls::{EthClient, EthSigningUnsafeClient};
use v1::tests::helpers::{TestSyncProvider, Config}; use v1::tests::helpers::{TestSyncProvider, Config};
@ -330,7 +331,7 @@ fn verify_transaction_counts(name: String, chain: BlockChain) {
"jsonrpc": "2.0", "jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByNumber", "method": "eth_getBlockTransactionCountByNumber",
"params": [ "params": [
"#.to_owned() + &::serde_json::to_string(&U256::from(num)).unwrap() + r#" "#.to_owned() + &::serde_json::to_string(&NU256::from(num)).unwrap() + r#"
], ],
"id": "# + format!("{}", *id).as_ref() + r#" "id": "# + format!("{}", *id).as_ref() + r#"
}"#; }"#;

View File

@ -23,9 +23,7 @@ use ethcore::client::TestBlockChainClient;
use ethcore::transaction::{Transaction, Action}; use ethcore::transaction::{Transaction, Action};
use v1::{SignerClient, PersonalSigner}; use v1::{SignerClient, PersonalSigner};
use v1::tests::helpers::TestMinerService; use v1::tests::helpers::TestMinerService;
use v1::helpers::{SigningQueue, ConfirmationsQueue}; use v1::helpers::{SigningQueue, ConfirmationsQueue, TransactionRequest};
use v1::types::TransactionRequest;
struct PersonalSignerTester { struct PersonalSignerTester {
queue: Arc<ConfirmationsQueue>, queue: Arc<ConfirmationsQueue>,

View File

@ -15,8 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use serde::{Serialize, Serializer}; use serde::{Serialize, Serializer};
use util::numbers::*; use v1::types::{Bytes, Transaction, H160, H256, H2048, U256};
use v1::types::{Bytes, Transaction, OptionalValue};
/// Block Transactions /// Block Transactions
#[derive(Debug)] #[derive(Debug)]
@ -41,7 +40,7 @@ impl Serialize for BlockTransactions {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct Block { pub struct Block {
/// Hash of the block /// Hash of the block
pub hash: OptionalValue<H256>, pub hash: Option<H256>,
/// Hash of the parent /// Hash of the parent
#[serde(rename="parentHash")] #[serde(rename="parentHash")]
pub parent_hash: H256, pub parent_hash: H256,
@ -49,10 +48,10 @@ pub struct Block {
#[serde(rename="sha3Uncles")] #[serde(rename="sha3Uncles")]
pub uncles_hash: H256, pub uncles_hash: H256,
/// Authors address /// Authors address
pub author: Address, pub author: H160,
// TODO: get rid of this one // TODO: get rid of this one
/// ? /// ?
pub miner: Address, pub miner: H160,
/// State root hash /// State root hash
#[serde(rename="stateRoot")] #[serde(rename="stateRoot")]
pub state_root: H256, pub state_root: H256,
@ -63,7 +62,7 @@ pub struct Block {
#[serde(rename="receiptsRoot")] #[serde(rename="receiptsRoot")]
pub receipts_root: H256, pub receipts_root: H256,
/// Block number /// Block number
pub number: OptionalValue<U256>, pub number: Option<U256>,
/// Gas Used /// Gas Used
#[serde(rename="gasUsed")] #[serde(rename="gasUsed")]
pub gas_used: U256, pub gas_used: U256,
@ -95,9 +94,8 @@ pub struct Block {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json; use serde_json;
use util::numbers::*; use v1::types::{Transaction, H160, H256, H2048, Bytes, U256};
use v1::types::{Transaction, Bytes, OptionalValue}; use super::{Block, BlockTransactions};
use super::*;
#[test] #[test]
fn test_serialize_block_transactions() { fn test_serialize_block_transactions() {
@ -105,7 +103,7 @@ mod tests {
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x00","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x00","gasPrice":"0x00","gas":"0x00","input":"0x","creates":null}]"#); assert_eq!(serialized, r#"[{"hash":"0x0000000000000000000000000000000000000000000000000000000000000000","nonce":"0x00","blockHash":null,"blockNumber":null,"transactionIndex":null,"from":"0x0000000000000000000000000000000000000000","to":null,"value":"0x00","gasPrice":"0x00","gas":"0x00","input":"0x","creates":null}]"#);
let t = BlockTransactions::Hashes(vec![H256::default()]); let t = BlockTransactions::Hashes(vec![H256::default().into()]);
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"["0x0000000000000000000000000000000000000000000000000000000000000000"]"#); assert_eq!(serialized, r#"["0x0000000000000000000000000000000000000000000000000000000000000000"]"#);
} }
@ -113,15 +111,15 @@ mod tests {
#[test] #[test]
fn test_serialize_block() { fn test_serialize_block() {
let block = Block { let block = Block {
hash: OptionalValue::Value(H256::default()), hash: Some(H256::default()),
parent_hash: H256::default(), parent_hash: H256::default(),
uncles_hash: H256::default(), uncles_hash: H256::default(),
author: Address::default(), author: H160::default(),
miner: Address::default(), miner: H160::default(),
state_root: H256::default(), state_root: H256::default(),
transactions_root: H256::default(), transactions_root: H256::default(),
receipts_root: H256::default(), receipts_root: H256::default(),
number: OptionalValue::Value(U256::default()), number: Some(U256::default()),
gas_used: U256::default(), gas_used: U256::default(),
gas_limit: U256::default(), gas_limit: U256::default(),
extra_data: Bytes::default(), extra_data: Bytes::default(),
@ -131,7 +129,7 @@ mod tests {
total_difficulty: U256::default(), total_difficulty: U256::default(),
seal_fields: vec![Bytes::default(), Bytes::default()], seal_fields: vec![Bytes::default(), Bytes::default()],
uncles: vec![], uncles: vec![],
transactions: BlockTransactions::Hashes(vec![]) transactions: BlockTransactions::Hashes(vec![].into())
}; };
let serialized = serde_json::to_string(&block).unwrap(); let serialized = serde_json::to_string(&block).unwrap();

View File

@ -42,6 +42,12 @@ impl From<Vec<u8>> for Bytes {
} }
} }
impl Into<Vec<u8>> for Bytes {
fn into(self) -> Vec<u8> {
self.0
}
}
impl Serialize for Bytes { impl Serialize for Bytes {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer { where S: Serializer {

View File

@ -14,17 +14,16 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::hash::Address; use v1::helpers::CallRequest as Request;
use util::numbers::U256; use v1::types::{Bytes, H160, U256};
use v1::types::Bytes;
/// Call request /// Call request
#[derive(Debug, Default, PartialEq, Deserialize)] #[derive(Debug, Default, PartialEq, Deserialize)]
pub struct CallRequest { pub struct CallRequest {
/// From /// From
pub from: Option<Address>, pub from: Option<H160>,
/// To /// To
pub to: Option<Address>, pub to: Option<H160>,
/// Gas Price /// Gas Price
#[serde(rename="gasPrice")] #[serde(rename="gasPrice")]
pub gas_price: Option<U256>, pub gas_price: Option<U256>,
@ -38,18 +37,30 @@ pub struct CallRequest {
pub nonce: Option<U256>, pub nonce: Option<U256>,
} }
impl Into<Request> for CallRequest {
fn into(self) -> Request {
Request {
from: self.from.map(Into::into),
to: self.to.map(Into::into),
gas_price: self.gas_price.map(Into::into),
gas: self.gas.map(Into::into),
value: self.value.map(Into::into),
data: self.data.map(Into::into),
nonce: self.nonce.map(Into::into),
}
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::str::FromStr; use std::str::FromStr;
use rustc_serialize::hex::FromHex; use rustc_serialize::hex::FromHex;
use serde_json; use serde_json;
use util::numbers::{U256}; use v1::types::{U256, H160};
use util::hash::Address; use super::CallRequest;
use v1::types::Bytes;
use super::*;
#[test] #[test]
fn transaction_request_deserialize() { fn call_request_deserialize() {
let s = r#"{ let s = r#"{
"from":"0x0000000000000000000000000000000000000001", "from":"0x0000000000000000000000000000000000000001",
"to":"0x0000000000000000000000000000000000000002", "to":"0x0000000000000000000000000000000000000002",
@ -62,18 +73,18 @@ mod tests {
let deserialized: CallRequest = serde_json::from_str(s).unwrap(); let deserialized: CallRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, CallRequest { assert_eq!(deserialized, CallRequest {
from: Some(Address::from(1)), from: Some(H160::from(1)),
to: Some(Address::from(2)), to: Some(H160::from(2)),
gas_price: Some(U256::from(1)), gas_price: Some(U256::from(1)),
gas: Some(U256::from(2)), gas: Some(U256::from(2)),
value: Some(U256::from(3)), value: Some(U256::from(3)),
data: Some(Bytes::new(vec![0x12, 0x34, 0x56])), data: Some(vec![0x12, 0x34, 0x56].into()),
nonce: Some(U256::from(4)), nonce: Some(U256::from(4)),
}); });
} }
#[test] #[test]
fn transaction_request_deserialize2() { fn call_request_deserialize2() {
let s = r#"{ let s = r#"{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155", "from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567", "to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
@ -85,23 +96,23 @@ mod tests {
let deserialized: CallRequest = serde_json::from_str(s).unwrap(); let deserialized: CallRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, CallRequest { assert_eq!(deserialized, CallRequest {
from: Some(Address::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap()), from: Some(H160::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap()),
to: Some(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()), to: Some(H160::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
gas_price: Some(U256::from_str("9184e72a000").unwrap()), gas_price: Some(U256::from_str("9184e72a000").unwrap()),
gas: Some(U256::from_str("76c0").unwrap()), gas: Some(U256::from_str("76c0").unwrap()),
value: Some(U256::from_str("9184e72a").unwrap()), value: Some(U256::from_str("9184e72a").unwrap()),
data: Some(Bytes::new("d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675".from_hex().unwrap())), data: Some("d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675".from_hex().unwrap().into()),
nonce: None nonce: None
}); });
} }
#[test] #[test]
fn transaction_request_deserialize_empty() { fn call_request_deserialize_empty() {
let s = r#"{"from":"0x0000000000000000000000000000000000000001"}"#; let s = r#"{"from":"0x0000000000000000000000000000000000000001"}"#;
let deserialized: CallRequest = serde_json::from_str(s).unwrap(); let deserialized: CallRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, CallRequest { assert_eq!(deserialized, CallRequest {
from: Some(Address::from(1)), from: Some(H160::from(1)),
to: None, to: None,
gas_price: None, gas_price: None,
gas: None, gas: None,

View File

@ -17,10 +17,9 @@
use serde::{Deserialize, Deserializer, Error}; use serde::{Deserialize, Deserializer, Error};
use serde_json::value; use serde_json::value;
use jsonrpc_core::Value; use jsonrpc_core::Value;
use util::numbers::*;
use v1::types::BlockNumber;
use ethcore::filter::Filter as EthFilter; use ethcore::filter::Filter as EthFilter;
use ethcore::client::BlockID; use ethcore::client::BlockID;
use v1::types::{BlockNumber, H160, H256};
/// Variadic value /// Variadic value
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
@ -49,7 +48,7 @@ impl<T> Deserialize for VariadicValue<T> where T: Deserialize {
} }
/// Filter Address /// Filter Address
pub type FilterAddress = VariadicValue<Address>; pub type FilterAddress = VariadicValue<H160>;
/// Topic /// Topic
pub type Topic = VariadicValue<H256>; pub type Topic = VariadicValue<H256>;
@ -76,14 +75,14 @@ impl Into<EthFilter> for Filter {
to_block: self.to_block.map_or_else(|| BlockID::Latest, Into::into), to_block: self.to_block.map_or_else(|| BlockID::Latest, Into::into),
address: self.address.and_then(|address| match address { address: self.address.and_then(|address| match address {
VariadicValue::Null => None, VariadicValue::Null => None,
VariadicValue::Single(a) => Some(vec![a]), VariadicValue::Single(a) => Some(vec![a.into()]),
VariadicValue::Multiple(a) => Some(a) VariadicValue::Multiple(a) => Some(a.into_iter().map(Into::into).collect())
}), }),
topics: { topics: {
let mut iter = self.topics.map_or_else(Vec::new, |topics| topics.into_iter().take(4).map(|topic| match topic { let mut iter = self.topics.map_or_else(Vec::new, |topics| topics.into_iter().take(4).map(|topic| match topic {
VariadicValue::Null => None, VariadicValue::Null => None,
VariadicValue::Single(t) => Some(vec![t]), VariadicValue::Single(t) => Some(vec![t.into()]),
VariadicValue::Multiple(t) => Some(t) VariadicValue::Multiple(t) => Some(t.into_iter().map(Into::into).collect())
}).filter_map(|m| m).collect()).into_iter(); }).filter_map(|m| m).collect()).into_iter();
[iter.next(), iter.next(), iter.next(), iter.next()] [iter.next(), iter.next(), iter.next(), iter.next()]
} }
@ -104,11 +103,11 @@ mod tests {
let s = r#"["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null, ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]]"#; let s = r#"["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null, ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]]"#;
let deserialized: Vec<Topic> = serde_json::from_str(s).unwrap(); let deserialized: Vec<Topic> = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, vec![ assert_eq!(deserialized, vec![
VariadicValue::Single(H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap()), VariadicValue::Single(H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap().into()),
VariadicValue::Null, VariadicValue::Null,
VariadicValue::Multiple(vec![ VariadicValue::Multiple(vec![
H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(), H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap().into(),
H256::from_str("0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc").unwrap() H256::from_str("0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc").unwrap().into(),
]) ])
]); ]);
} }

145
rpc/src/v1/types/hash.rs Normal file
View File

@ -0,0 +1,145 @@
// 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 std::fmt;
use std::str::FromStr;
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use serde;
use rustc_serialize::hex::{ToHex, FromHex};
use util::{H64 as Eth64, H256 as EthH256, H520 as EthH520, H2048 as Eth2048, Address};
macro_rules! impl_hash {
($name: ident, $other: ident, $size: expr) => {
/// Hash serialization
#[derive(Eq)]
pub struct $name([u8; $size]);
impl Default for $name {
fn default() -> Self {
$name([0; $size])
}
}
impl fmt::Debug for $name {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "{}", self.0.to_hex())
}
}
impl<T> From<T> for $name where $other: From<T> {
fn from(o: T) -> Self {
$name($other::from(o).0)
}
}
impl FromStr for $name {
type Err = <$other as FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
$other::from_str(s).map(|x| $name(x.0))
}
}
impl Into<$other> for $name {
fn into(self) -> $other {
$other(self.0)
}
}
impl PartialEq for $name {
fn eq(&self, other: &Self) -> bool {
let self_ref: &[u8] = &self.0;
let other_ref: &[u8] = &other.0;
self_ref == other_ref
}
}
impl PartialOrd for $name {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let self_ref: &[u8] = &self.0;
let other_ref: &[u8] = &other.0;
self_ref.partial_cmp(other_ref)
}
}
impl Ord for $name {
fn cmp(&self, other: &Self) -> Ordering {
let self_ref: &[u8] = &self.0;
let other_ref: &[u8] = &other.0;
self_ref.cmp(other_ref)
}
}
impl Hash for $name {
fn hash<H>(&self, state: &mut H) where H: Hasher {
let self_ref: &[u8] = &self.0;
Hash::hash(self_ref, state)
}
}
impl Clone for $name {
fn clone(&self) -> Self {
let mut r = [0; $size];
r.copy_from_slice(&self.0);
$name(r)
}
}
impl serde::Serialize for $name {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: serde::Serializer {
let mut hex = "0x".to_owned();
hex.push_str(&self.0.to_hex());
serializer.serialize_str(&hex)
}
}
impl serde::Deserialize for $name {
fn deserialize<D>(deserializer: &mut D) -> Result<$name, D::Error> where D: serde::Deserializer {
struct HashVisitor;
impl serde::de::Visitor for HashVisitor {
type Value = $name;
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
match value[2..].from_hex() {
Ok(ref v) if v.len() == $size => {
let mut result = [0u8; $size];
result.copy_from_slice(v);
Ok($name(result))
},
Ok(_) => Err(serde::Error::custom("Invalid length.")),
_ => Err(serde::Error::custom("Invalid hex value."))
}
}
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: serde::Error {
self.visit_str(value.as_ref())
}
}
deserializer.deserialize(HashVisitor)
}
}
}
}
impl_hash!(H64, Eth64, 8);
impl_hash!(H160, Address, 20);
impl_hash!(H256, EthH256, 32);
impl_hash!(H520, EthH520, 65);
impl_hash!(H2048, Eth2048, 256);

View File

@ -14,15 +14,14 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::numbers::*;
use ethcore::log_entry::{LocalizedLogEntry, LogEntry}; use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
use v1::types::Bytes; use v1::types::{Bytes, H160, H256, U256};
/// Log /// Log
#[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)] #[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)]
pub struct Log { pub struct Log {
/// Address /// H160
pub address: Address, pub address: H160,
/// Topics /// Topics
pub topics: Vec<H256>, pub topics: Vec<H256>,
/// Data /// Data
@ -50,14 +49,14 @@ pub struct Log {
impl From<LocalizedLogEntry> for Log { impl From<LocalizedLogEntry> for Log {
fn from(e: LocalizedLogEntry) -> Log { fn from(e: LocalizedLogEntry) -> Log {
Log { Log {
address: e.entry.address, address: e.entry.address.into(),
topics: e.entry.topics, topics: e.entry.topics.into_iter().map(Into::into).collect(),
data: Bytes::new(e.entry.data), data: e.entry.data.into(),
block_hash: Some(e.block_hash), block_hash: Some(e.block_hash.into()),
block_number: Some(From::from(e.block_number)), block_number: Some(e.block_number.into()),
transaction_hash: Some(e.transaction_hash), transaction_hash: Some(e.transaction_hash.into()),
transaction_index: Some(From::from(e.transaction_index)), transaction_index: Some(e.transaction_index.into()),
log_index: Some(From::from(e.log_index)), log_index: Some(e.log_index.into()),
log_type: "mined".to_owned(), log_type: "mined".to_owned(),
} }
} }
@ -66,9 +65,9 @@ impl From<LocalizedLogEntry> for Log {
impl From<LogEntry> for Log { impl From<LogEntry> for Log {
fn from(e: LogEntry) -> Log { fn from(e: LogEntry) -> Log {
Log { Log {
address: e.address, address: e.address.into(),
topics: e.topics, topics: e.topics.into_iter().map(Into::into).collect(),
data: Bytes::new(e.data), data: e.data.into(),
block_hash: None, block_hash: None,
block_number: None, block_number: None,
transaction_hash: None, transaction_hash: None,
@ -83,25 +82,24 @@ impl From<LogEntry> for Log {
mod tests { mod tests {
use serde_json; use serde_json;
use std::str::FromStr; use std::str::FromStr;
use util::numbers::*; use v1::types::{Log, H160, H256, U256};
use v1::types::{Bytes, Log};
#[test] #[test]
fn log_serialization() { fn log_serialization() {
let s = r#"{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","logIndex":"0x01","type":"mined"}"#; let s = r#"{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","logIndex":"0x01","type":"mined"}"#;
let log = Log { let log = Log {
address: Address::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(), address: H160::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(),
topics: vec![ topics: vec![
H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(), H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(),
H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap() H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap(),
], ],
data: Bytes::new(vec![]), data: vec![].into(),
block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()), block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()),
block_number: Some(U256::from(0x4510c)), block_number: Some(U256::from(0x4510c)),
transaction_hash: Some(H256::new()), transaction_hash: Some(H256::default()),
transaction_index: Some(U256::zero()), transaction_index: Some(U256::default()),
log_index: Some(U256::one()), log_index: Some(U256::from(1)),
log_type: "mined".to_owned(), log_type: "mined".to_owned(),
}; };

View File

@ -18,9 +18,9 @@ mod bytes;
mod block; mod block;
mod block_number; mod block_number;
mod filter; mod filter;
mod hash;
mod index; mod index;
mod log; mod log;
mod optionals;
mod sync; mod sync;
mod transaction; mod transaction;
mod transaction_request; mod transaction_request;
@ -28,14 +28,15 @@ mod call_request;
mod receipt; mod receipt;
mod trace; mod trace;
mod trace_filter; mod trace_filter;
mod uint;
pub use self::bytes::Bytes; pub use self::bytes::Bytes;
pub use self::block::{Block, BlockTransactions}; pub use self::block::{Block, BlockTransactions};
pub use self::block_number::BlockNumber; pub use self::block_number::BlockNumber;
pub use self::filter::Filter; pub use self::filter::Filter;
pub use self::hash::{H64, H160, H256, H520, H2048};
pub use self::index::Index; pub use self::index::Index;
pub use self::log::Log; pub use self::log::Log;
pub use self::optionals::OptionalValue;
pub use self::sync::{SyncStatus, SyncInfo}; pub use self::sync::{SyncStatus, SyncInfo};
pub use self::transaction::Transaction; pub use self::transaction::Transaction;
pub use self::transaction_request::{TransactionRequest, TransactionConfirmation, TransactionModification}; pub use self::transaction_request::{TransactionRequest, TransactionConfirmation, TransactionModification};
@ -43,3 +44,4 @@ pub use self::call_request::CallRequest;
pub use self::receipt::Receipt; pub use self::receipt::Receipt;
pub use self::trace::{Trace, LocalizedTrace, StateDiff, VMTrace}; pub use self::trace::{Trace, LocalizedTrace, StateDiff, VMTrace};
pub use self::trace_filter::TraceFilter; pub use self::trace_filter::TraceFilter;
pub use self::uint::U256;

View File

@ -1,81 +0,0 @@
// 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 serde::{Serialize, Serializer, Deserialize, Deserializer};
use serde_json::Value;
/// Optional value
#[derive(Debug)]
pub enum OptionalValue<T> where T: Serialize {
/// Some
Value(T),
/// None
Null
}
impl<T> Default for OptionalValue<T> where T: Serialize + Deserialize {
fn default() -> Self {
OptionalValue::Null
}
}
impl<T> Into<Option<T>> for OptionalValue<T> where T: Serialize + Deserialize {
fn into(self) -> Option<T> {
match self {
OptionalValue::Null => None,
OptionalValue::Value(t) => Some(t),
}
}
}
impl<T> Serialize for OptionalValue<T> where T: Serialize + Deserialize {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer {
match *self {
OptionalValue::Value(ref value) => value.serialize(serializer),
OptionalValue::Null => Value::Null.serialize(serializer)
}
}
}
impl<T> Deserialize for OptionalValue<T> where T: Serialize + Deserialize {
fn deserialize<D>(deserializer: &mut D) -> Result<OptionalValue<T>, D::Error>
where D: Deserializer {
let deser_result: Result<T, D::Error> = Deserialize::deserialize(deserializer);
match deser_result {
Ok(t) => Ok(OptionalValue::Value(t)),
Err(_) => Ok(OptionalValue::Null),
}
}
}
#[cfg(test)]
mod tests {
use serde_json;
use util::hash::*;
use super::*;
#[test]
fn test_serialize_optional_value() {
let v: OptionalValue<H256> = OptionalValue::Null;
let serialized = serde_json::to_string(&v).unwrap();
assert_eq!(serialized, r#"null"#);
let v = OptionalValue::Value(H256::default());
let serialized = serde_json::to_string(&v).unwrap();
assert_eq!(serialized, r#""0x0000000000000000000000000000000000000000000000000000000000000000""#);
}
}

View File

@ -14,9 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::numbers::U256; use v1::types::{Log, H160, H256, U256};
use util::hash::{Address, H256};
use v1::types::Log;
use ethcore::receipt::{Receipt as EthReceipt, LocalizedReceipt}; use ethcore::receipt::{Receipt as EthReceipt, LocalizedReceipt};
/// Receipt /// Receipt
@ -42,7 +40,7 @@ pub struct Receipt {
pub gas_used: U256, pub gas_used: U256,
/// Contract address /// Contract address
#[serde(rename="contractAddress")] #[serde(rename="contractAddress")]
pub contract_address: Option<Address>, pub contract_address: Option<H160>,
/// Logs /// Logs
pub logs: Vec<Log>, pub logs: Vec<Log>,
} }
@ -50,14 +48,14 @@ pub struct Receipt {
impl From<LocalizedReceipt> for Receipt { impl From<LocalizedReceipt> for Receipt {
fn from(r: LocalizedReceipt) -> Self { fn from(r: LocalizedReceipt) -> Self {
Receipt { Receipt {
transaction_hash: Some(r.transaction_hash), transaction_hash: Some(r.transaction_hash.into()),
transaction_index: Some(U256::from(r.transaction_index)), transaction_index: Some(r.transaction_index.into()),
block_hash: Some(r.block_hash), block_hash: Some(r.block_hash.into()),
block_number: Some(U256::from(r.block_number)), block_number: Some(r.block_number.into()),
cumulative_gas_used: r.cumulative_gas_used, cumulative_gas_used: r.cumulative_gas_used.into(),
gas_used: r.gas_used, gas_used: r.gas_used.into(),
contract_address: r.contract_address, contract_address: r.contract_address.map(Into::into),
logs: r.logs.into_iter().map(From::from).collect(), logs: r.logs.into_iter().map(Into::into).collect(),
} }
} }
} }
@ -69,10 +67,10 @@ impl From<EthReceipt> for Receipt {
transaction_index: None, transaction_index: None,
block_hash: None, block_hash: None,
block_number: None, block_number: None,
cumulative_gas_used: r.gas_used, cumulative_gas_used: r.gas_used.into(),
gas_used: r.gas_used, gas_used: r.gas_used.into(),
contract_address: None, contract_address: None,
logs: r.logs.into_iter().map(From::from).collect(), logs: r.logs.into_iter().map(Into::into).collect(),
} }
} }
} }
@ -81,33 +79,32 @@ impl From<EthReceipt> for Receipt {
mod tests { mod tests {
use serde_json; use serde_json;
use std::str::FromStr; use std::str::FromStr;
use util::numbers::*; use v1::types::{Log, Receipt, U256, H256, H160};
use v1::types::{Bytes, Log, Receipt};
#[test] #[test]
fn receipt_serialization() { fn receipt_serialization() {
let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","logIndex":"0x01","type":"mined"}]}"#; let s = r#"{"transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","cumulativeGasUsed":"0x20","gasUsed":"0x10","contractAddress":null,"logs":[{"address":"0x33990122638b9132ca29c723bdf037f1a891a70c","topics":["0xa6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc","0x4861736852656700000000000000000000000000000000000000000000000000"],"data":"0x","blockHash":"0xed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5","blockNumber":"0x04510c","transactionHash":"0x0000000000000000000000000000000000000000000000000000000000000000","transactionIndex":"0x00","logIndex":"0x01","type":"mined"}]}"#;
let receipt = Receipt { let receipt = Receipt {
transaction_hash: Some(H256::zero()), transaction_hash: Some(H256::from(0)),
transaction_index: Some(U256::zero()), transaction_index: Some(U256::from(0)),
block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()), block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()),
block_number: Some(U256::from(0x4510c)), block_number: Some(U256::from(0x4510c)),
cumulative_gas_used: U256::from(0x20), cumulative_gas_used: U256::from(0x20),
gas_used: U256::from(0x10), gas_used: U256::from(0x10),
contract_address: None, contract_address: None,
logs: vec![Log { logs: vec![Log {
address: Address::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(), address: H160::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(),
topics: vec![ topics: vec![
H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(), H256::from_str("a6697e974e6a320f454390be03f74955e8978f1a6971ea6730542e37b66179bc").unwrap(),
H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap() H256::from_str("4861736852656700000000000000000000000000000000000000000000000000").unwrap(),
], ],
data: Bytes::new(vec![]), data: vec![].into(),
block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()), block_hash: Some(H256::from_str("ed76641c68a1c641aee09a94b3b471f4dc0316efe5ac19cf488e2674cf8d05b5").unwrap()),
block_number: Some(U256::from(0x4510c)), block_number: Some(U256::from(0x4510c)),
transaction_hash: Some(H256::new()), transaction_hash: Some(H256::default()),
transaction_index: Some(U256::zero()), transaction_index: Some(U256::default()),
log_index: Some(U256::one()), log_index: Some(U256::from(1)),
log_type: "mined".to_owned(), log_type: "mined".to_owned(),
}] }]
}; };

View File

@ -15,7 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use serde::{Serialize, Serializer}; use serde::{Serialize, Serializer};
use util::numbers::*; use v1::types::U256;
/// Sync info /// Sync info
#[derive(Default, Debug, Serialize, PartialEq)] #[derive(Default, Debug, Serialize, PartialEq)]
@ -53,7 +53,7 @@ impl Serialize for SyncStatus {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use serde_json; use serde_json;
use super::*; use super::{SyncInfo, SyncStatus};
#[test] #[test]
fn test_serialize_sync_info() { fn test_serialize_sync_info() {

View File

@ -15,14 +15,14 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use std::collections::BTreeMap; use std::collections::BTreeMap;
use util::{Address, U256, H256, Uint};
use serde::{Serialize, Serializer}; use serde::{Serialize, Serializer};
use ethcore::trace::trace; use ethcore::trace::trace;
use ethcore::trace::{Trace as EthTrace, LocalizedTrace as EthLocalizedTrace}; use ethcore::trace::{Trace as EthTrace, LocalizedTrace as EthLocalizedTrace};
use ethcore::trace as et; use ethcore::trace as et;
use ethcore::state_diff; use ethcore::state_diff;
use ethcore::account_diff; use ethcore::account_diff;
use v1::types::Bytes; use util::Uint;
use v1::types::{Bytes, H160, H256, U256};
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
/// A diff of some chunk of memory. /// A diff of some chunk of memory.
@ -54,8 +54,8 @@ pub struct StorageDiff {
impl From<et::StorageDiff> for StorageDiff { impl From<et::StorageDiff> for StorageDiff {
fn from(c: et::StorageDiff) -> Self { fn from(c: et::StorageDiff) -> Self {
StorageDiff { StorageDiff {
key: c.location, key: c.location.into(),
val: c.value, val: c.value.into(),
} }
} }
} }
@ -80,9 +80,9 @@ impl From<et::VMExecutedOperation> for VMExecutedOperation {
fn from(c: et::VMExecutedOperation) -> Self { fn from(c: et::VMExecutedOperation) -> Self {
VMExecutedOperation { VMExecutedOperation {
used: c.gas_used.low_u64(), used: c.gas_used.low_u64(),
push: c.stack_push, push: c.stack_push.into_iter().map(Into::into).collect(),
mem: c.mem_diff.map(From::from), mem: c.mem_diff.map(Into::into),
store: c.store_diff.map(From::from), store: c.store_diff.map(Into::into),
} }
} }
} }
@ -105,8 +105,8 @@ impl From<(et::VMOperation, Option<et::VMTrace>)> for VMOperation {
VMOperation { VMOperation {
pc: c.0.pc, pc: c.0.pc,
cost: c.0.gas_cost.low_u64(), cost: c.0.gas_cost.low_u64(),
ex: c.0.executed.map(From::from), ex: c.0.executed.map(Into::into),
sub: c.1.map(From::from), sub: c.1.map(Into::into),
} }
} }
} }
@ -188,13 +188,13 @@ impl From<account_diff::AccountDiff> for AccountDiff {
balance: c.balance.into(), balance: c.balance.into(),
nonce: c.nonce.into(), nonce: c.nonce.into(),
code: c.code.into(), code: c.code.into(),
storage: c.storage.into_iter().map(|(k, v)| (k, v.into())).collect(), storage: c.storage.into_iter().map(|(k, v)| (k.into(), v.into())).collect(),
} }
} }
} }
/// Serde-friendly `StateDiff` shadow. /// Serde-friendly `StateDiff` shadow.
pub struct StateDiff(BTreeMap<Address, AccountDiff>); pub struct StateDiff(BTreeMap<H160, AccountDiff>);
impl Serialize for StateDiff { impl Serialize for StateDiff {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
@ -205,7 +205,7 @@ impl Serialize for StateDiff {
impl From<state_diff::StateDiff> for StateDiff { impl From<state_diff::StateDiff> for StateDiff {
fn from(c: state_diff::StateDiff) -> Self { fn from(c: state_diff::StateDiff) -> Self {
StateDiff(c.0.into_iter().map(|(k, v)| (k, v.into())).collect()) StateDiff(c.0.into_iter().map(|(k, v)| (k.into(), v.into())).collect())
} }
} }
@ -213,7 +213,7 @@ impl From<state_diff::StateDiff> for StateDiff {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct Create { pub struct Create {
/// Sender /// Sender
from: Address, from: H160,
/// Value /// Value
value: U256, value: U256,
/// Gas /// Gas
@ -225,9 +225,9 @@ pub struct Create {
impl From<trace::Create> for Create { impl From<trace::Create> for Create {
fn from(c: trace::Create) -> Self { fn from(c: trace::Create) -> Self {
Create { Create {
from: c.from, from: c.from.into(),
value: c.value, value: c.value.into(),
gas: c.gas, gas: c.gas.into(),
init: Bytes::new(c.init), init: Bytes::new(c.init),
} }
} }
@ -237,9 +237,9 @@ impl From<trace::Create> for Create {
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct Call { pub struct Call {
/// Sender /// Sender
from: Address, from: H160,
/// Recipient /// Recipient
to: Address, to: H160,
/// Transfered Value /// Transfered Value
value: U256, value: U256,
/// Gas /// Gas
@ -251,11 +251,11 @@ pub struct Call {
impl From<trace::Call> for Call { impl From<trace::Call> for Call {
fn from(c: trace::Call) -> Self { fn from(c: trace::Call) -> Self {
Call { Call {
from: c.from, from: c.from.into(),
to: c.to, to: c.to.into(),
value: c.value, value: c.value.into(),
gas: c.gas, gas: c.gas.into(),
input: Bytes::new(c.input), input: c.input.into(),
} }
} }
} }
@ -293,8 +293,8 @@ pub struct CallResult {
impl From<trace::CallResult> for CallResult { impl From<trace::CallResult> for CallResult {
fn from(c: trace::CallResult) -> Self { fn from(c: trace::CallResult) -> Self {
CallResult { CallResult {
gas_used: c.gas_used, gas_used: c.gas_used.into(),
output: Bytes::new(c.output), output: c.output.into(),
} }
} }
} }
@ -308,15 +308,15 @@ pub struct CreateResult {
/// Code /// Code
code: Bytes, code: Bytes,
/// Assigned address /// Assigned address
address: Address, address: H160,
} }
impl From<trace::CreateResult> for CreateResult { impl From<trace::CreateResult> for CreateResult {
fn from(c: trace::CreateResult) -> Self { fn from(c: trace::CreateResult) -> Self {
CreateResult { CreateResult {
gas_used: c.gas_used, gas_used: c.gas_used.into(),
code: Bytes::new(c.code), code: c.code.into(),
address: c.address, address: c.address.into(),
} }
} }
} }
@ -357,7 +357,7 @@ pub struct LocalizedTrace {
/// Result /// Result
result: Res, result: Res,
/// Trace address /// Trace address
#[serde(rename="traceAddress")] #[serde(rename="traceH160")]
trace_address: Vec<U256>, trace_address: Vec<U256>,
/// Subtraces /// Subtraces
subtraces: U256, subtraces: U256,
@ -378,14 +378,14 @@ pub struct LocalizedTrace {
impl From<EthLocalizedTrace> for LocalizedTrace { impl From<EthLocalizedTrace> for LocalizedTrace {
fn from(t: EthLocalizedTrace) -> Self { fn from(t: EthLocalizedTrace) -> Self {
LocalizedTrace { LocalizedTrace {
action: From::from(t.action), action: t.action.into(),
result: From::from(t.result), result: t.result.into(),
trace_address: t.trace_address.into_iter().map(From::from).collect(), trace_address: t.trace_address.into_iter().map(Into::into).collect(),
subtraces: From::from(t.subtraces), subtraces: t.subtraces.into(),
transaction_position: From::from(t.transaction_number), transaction_position: t.transaction_number.into(),
transaction_hash: t.transaction_hash, transaction_hash: t.transaction_hash.into(),
block_number: From::from(t.block_number), block_number: t.block_number.into(),
block_hash: t.block_hash, block_hash: t.block_hash.into(),
} }
} }
} }
@ -409,7 +409,7 @@ impl From<EthTrace> for Trace {
depth: t.depth.into(), depth: t.depth.into(),
action: t.action.into(), action: t.action.into(),
result: t.result.into(), result: t.result.into(),
subtraces: t.subs.into_iter().map(From::from).collect(), subtraces: t.subs.into_iter().map(Into::into).collect(),
} }
} }
} }
@ -418,23 +418,22 @@ impl From<EthTrace> for Trace {
mod tests { mod tests {
use serde_json; use serde_json;
use std::collections::BTreeMap; use std::collections::BTreeMap;
use util::{U256, H256, Address}; use v1::types::{Bytes, U256, H256, H160};
use v1::types::Bytes;
use super::*; use super::*;
#[test] #[test]
fn test_trace_serialize() { fn test_trace_serialize() {
let t = LocalizedTrace { let t = LocalizedTrace {
action: Action::Call(Call { action: Action::Call(Call {
from: Address::from(4), from: H160::from(4),
to: Address::from(5), to: H160::from(5),
value: U256::from(6), value: U256::from(6),
gas: U256::from(7), gas: U256::from(7),
input: Bytes::new(vec![0x12, 0x34]), input: Bytes::new(vec![0x12, 0x34]),
}), }),
result: Res::Call(CallResult { result: Res::Call(CallResult {
gas_used: U256::from(8), gas_used: U256::from(8),
output: Bytes::new(vec![0x56, 0x78]), output: vec![0x56, 0x78].into(),
}), }),
trace_address: vec![U256::from(10)], trace_address: vec![U256::from(10)],
subtraces: U256::from(1), subtraces: U256::from(1),
@ -444,7 +443,7 @@ mod tests {
block_hash: H256::from(14), block_hash: H256::from(14),
}; };
let serialized = serde_json::to_string(&t).unwrap(); let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"{"action":{"call":{"from":"0x0000000000000000000000000000000000000004","to":"0x0000000000000000000000000000000000000005","value":"0x06","gas":"0x07","input":"0x1234"}},"result":{"call":{"gasUsed":"0x08","output":"0x5678"}},"traceAddress":["0x0a"],"subtraces":"0x01","transactionPosition":"0x0b","transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":"0x0d","blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#); assert_eq!(serialized, r#"{"action":{"call":{"from":"0x0000000000000000000000000000000000000004","to":"0x0000000000000000000000000000000000000005","value":"0x06","gas":"0x07","input":"0x1234"}},"result":{"call":{"gasUsed":"0x08","output":"0x5678"}},"traceH160":["0x0a"],"subtraces":"0x01","transactionPosition":"0x0b","transactionHash":"0x000000000000000000000000000000000000000000000000000000000000000c","blockNumber":"0x0d","blockHash":"0x000000000000000000000000000000000000000000000000000000000000000e"}"#);
} }
#[test] #[test]
@ -515,16 +514,16 @@ mod tests {
#[test] #[test]
fn test_action_serialize() { fn test_action_serialize() {
let actions = vec![Action::Call(Call { let actions = vec![Action::Call(Call {
from: Address::from(1), from: H160::from(1),
to: Address::from(2), to: H160::from(2),
value: U256::from(3), value: U256::from(3),
gas: U256::from(4), gas: U256::from(4),
input: Bytes::new(vec![0x12, 0x34]), input: vec![0x12, 0x34].into(),
}), Action::Create(Create { }), Action::Create(Create {
from: Address::from(5), from: H160::from(5),
value: U256::from(6), value: U256::from(6),
gas: U256::from(7), gas: U256::from(7),
init: Bytes::new(vec![0x56, 0x78]), init: vec![0x56, 0x78].into(),
})]; })];
let serialized = serde_json::to_string(&actions).unwrap(); let serialized = serde_json::to_string(&actions).unwrap();
@ -536,12 +535,12 @@ mod tests {
let results = vec![ let results = vec![
Res::Call(CallResult { Res::Call(CallResult {
gas_used: U256::from(1), gas_used: U256::from(1),
output: Bytes::new(vec![0x12, 0x34]), output: vec![0x12, 0x34].into(),
}), }),
Res::Create(CreateResult { Res::Create(CreateResult {
gas_used: U256::from(2), gas_used: U256::from(2),
code: Bytes::new(vec![0x45, 0x56]), code: vec![0x45, 0x56].into(),
address: Address::from(3), address: H160::from(3),
}), }),
Res::FailedCall, Res::FailedCall,
Res::FailedCreate, Res::FailedCreate,

View File

@ -16,10 +16,9 @@
//! Trace filter deserialization. //! Trace filter deserialization.
use util::Address;
use ethcore::client::BlockID; use ethcore::client::BlockID;
use ethcore::client; use ethcore::client;
use super::BlockNumber; use v1::types::{BlockNumber, H160};
/// Trace filter /// Trace filter
#[derive(Debug, PartialEq, Deserialize)] #[derive(Debug, PartialEq, Deserialize)]
@ -32,10 +31,10 @@ pub struct TraceFilter {
pub to_block: Option<BlockNumber>, pub to_block: Option<BlockNumber>,
/// From address /// From address
#[serde(rename="fromAddress")] #[serde(rename="fromAddress")]
pub from_address: Option<Vec<Address>>, pub from_address: Option<Vec<H160>>,
/// To address /// To address
#[serde(rename="toAddress")] #[serde(rename="toAddress")]
pub to_address: Option<Vec<Address>>, pub to_address: Option<Vec<H160>>,
} }
impl Into<client::TraceFilter> for TraceFilter { impl Into<client::TraceFilter> for TraceFilter {
@ -44,8 +43,8 @@ impl Into<client::TraceFilter> for TraceFilter {
let end = self.to_block.map_or(BlockID::Latest, Into::into); let end = self.to_block.map_or(BlockID::Latest, Into::into);
client::TraceFilter { client::TraceFilter {
range: start..end, range: start..end,
from_address: self.from_address.unwrap_or_else(Vec::new), from_address: self.from_address.map_or_else(Vec::new, |x| x.into_iter().map(Into::into).collect()),
to_address: self.to_address.unwrap_or_else(Vec::new), to_address: self.to_address.map_or_else(Vec::new, |x| x.into_iter().map(Into::into).collect()),
} }
} }
} }
@ -80,8 +79,8 @@ mod tests {
assert_eq!(deserialized, TraceFilter { assert_eq!(deserialized, TraceFilter {
from_block: Some(BlockNumber::Latest), from_block: Some(BlockNumber::Latest),
to_block: Some(BlockNumber::Latest), to_block: Some(BlockNumber::Latest),
from_address: Some(vec![Address::from(3)]), from_address: Some(vec![Address::from(3).into()]),
to_address: Some(vec![Address::from(5)]), to_address: Some(vec![Address::from(5).into()]),
}); });
} }
} }

View File

@ -14,10 +14,9 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
use util::numbers::*;
use ethcore::contract_address; use ethcore::contract_address;
use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction}; use ethcore::transaction::{LocalizedTransaction, Action, SignedTransaction};
use v1::types::{Bytes, OptionalValue}; use v1::types::{Bytes, H160, H256, U256};
/// Transaction /// Transaction
#[derive(Debug, Default, Serialize)] #[derive(Debug, Default, Serialize)]
@ -28,17 +27,17 @@ pub struct Transaction {
pub nonce: U256, pub nonce: U256,
/// Block hash /// Block hash
#[serde(rename="blockHash")] #[serde(rename="blockHash")]
pub block_hash: OptionalValue<H256>, pub block_hash: Option<H256>,
/// Block number /// Block number
#[serde(rename="blockNumber")] #[serde(rename="blockNumber")]
pub block_number: OptionalValue<U256>, pub block_number: Option<U256>,
/// Transaction Index /// Transaction Index
#[serde(rename="transactionIndex")] #[serde(rename="transactionIndex")]
pub transaction_index: OptionalValue<U256>, pub transaction_index: Option<U256>,
/// Sender /// Sender
pub from: Address, pub from: H160,
/// Recipient /// Recipient
pub to: OptionalValue<Address>, pub to: Option<H160>,
/// Transfered value /// Transfered value
pub value: U256, pub value: U256,
/// Gas Price /// Gas Price
@ -49,29 +48,29 @@ pub struct Transaction {
/// Data /// Data
pub input: Bytes, pub input: Bytes,
/// Creates contract /// Creates contract
pub creates: OptionalValue<Address>, pub creates: Option<H160>,
} }
impl From<LocalizedTransaction> for Transaction { impl From<LocalizedTransaction> for Transaction {
fn from(t: LocalizedTransaction) -> Transaction { fn from(t: LocalizedTransaction) -> Transaction {
Transaction { Transaction {
hash: t.hash(), hash: t.hash().into(),
nonce: t.nonce, nonce: t.nonce.into(),
block_hash: OptionalValue::Value(t.block_hash.clone()), block_hash: Some(t.block_hash.clone().into()),
block_number: OptionalValue::Value(U256::from(t.block_number)), block_number: Some(t.block_number.into()),
transaction_index: OptionalValue::Value(U256::from(t.transaction_index)), transaction_index: Some(t.transaction_index.into()),
from: t.sender().unwrap(), from: t.sender().unwrap().into(),
to: match t.action { to: match t.action {
Action::Create => OptionalValue::Null, Action::Create => None,
Action::Call(ref address) => OptionalValue::Value(address.clone()) Action::Call(ref address) => Some(address.clone().into())
}, },
value: t.value, value: t.value.into(),
gas_price: t.gas_price, gas_price: t.gas_price.into(),
gas: t.gas, gas: t.gas.into(),
input: Bytes::new(t.data.clone()), input: Bytes::new(t.data.clone()),
creates: match t.action { creates: match t.action {
Action::Create => OptionalValue::Value(contract_address(&t.sender().unwrap(), &t.nonce)), Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()),
Action::Call(_) => OptionalValue::Null, Action::Call(_) => None,
}, },
} }
} }
@ -80,23 +79,23 @@ impl From<LocalizedTransaction> for Transaction {
impl From<SignedTransaction> for Transaction { impl From<SignedTransaction> for Transaction {
fn from(t: SignedTransaction) -> Transaction { fn from(t: SignedTransaction) -> Transaction {
Transaction { Transaction {
hash: t.hash(), hash: t.hash().into(),
nonce: t.nonce, nonce: t.nonce.into(),
block_hash: OptionalValue::Null, block_hash: None,
block_number: OptionalValue::Null, block_number: None,
transaction_index: OptionalValue::Null, transaction_index: None,
from: t.sender().unwrap(), from: t.sender().unwrap().into(),
to: match t.action { to: match t.action {
Action::Create => OptionalValue::Null, Action::Create => None,
Action::Call(ref address) => OptionalValue::Value(address.clone()) Action::Call(ref address) => Some(address.clone().into())
}, },
value: t.value, value: t.value.into(),
gas_price: t.gas_price, gas_price: t.gas_price.into(),
gas: t.gas, gas: t.gas.into(),
input: Bytes::new(t.data.clone()), input: Bytes::new(t.data.clone()),
creates: match t.action { creates: match t.action {
Action::Create => OptionalValue::Value(contract_address(&t.sender().unwrap(), &t.nonce)), Action::Create => Some(contract_address(&t.sender().unwrap(), &t.nonce).into()),
Action::Call(_) => OptionalValue::Null, Action::Call(_) => None,
}, },
} }
} }
@ -104,7 +103,7 @@ impl From<SignedTransaction> for Transaction {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::Transaction;
use serde_json; use serde_json;
#[test] #[test]

View File

@ -16,17 +16,16 @@
//! `TransactionRequest` type //! `TransactionRequest` type
use util::hash::Address; use v1::types::{Bytes, H160, U256};
use util::numbers::U256; use v1::helpers::{TransactionRequest as Request, TransactionConfirmation as Confirmation};
use v1::types::bytes::Bytes;
/// Transaction request coming from RPC /// Transaction request coming from RPC
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)] #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct TransactionRequest { pub struct TransactionRequest {
/// Sender /// Sender
pub from: Address, pub from: H160,
/// Recipient /// Recipient
pub to: Option<Address>, pub to: Option<H160>,
/// Gas Price /// Gas Price
#[serde(rename="gasPrice")] #[serde(rename="gasPrice")]
pub gas_price: Option<U256>, pub gas_price: Option<U256>,
@ -40,6 +39,34 @@ pub struct TransactionRequest {
pub nonce: Option<U256>, pub nonce: Option<U256>,
} }
impl From<Request> for TransactionRequest {
fn from(r: Request) -> Self {
TransactionRequest {
from: r.from.into(),
to: r.to.map(Into::into),
gas_price: r.gas_price.map(Into::into),
gas: r.gas.map(Into::into),
value: r.value.map(Into::into),
data: r.data.map(Into::into),
nonce: r.nonce.map(Into::into),
}
}
}
impl Into<Request> for TransactionRequest {
fn into(self) -> Request {
Request {
from: self.from.into(),
to: self.to.map(Into::into),
gas_price: self.gas_price.map(Into::into),
gas: self.gas.map(Into::into),
value: self.value.map(Into::into),
data: self.data.map(Into::into),
nonce: self.nonce.map(Into::into),
}
}
}
/// Transaction confirmation waiting in a queue /// Transaction confirmation waiting in a queue
#[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize)] #[derive(Debug, Clone, Default, Eq, PartialEq, Hash, Serialize)]
pub struct TransactionConfirmation { pub struct TransactionConfirmation {
@ -49,6 +76,15 @@ pub struct TransactionConfirmation {
pub transaction: TransactionRequest, pub transaction: TransactionRequest,
} }
impl From<Confirmation> for TransactionConfirmation {
fn from(c: Confirmation) -> Self {
TransactionConfirmation {
id: c.id.into(),
transaction: c.transaction.into(),
}
}
}
/// Possible modifications to the confirmed transaction sent by `SignerUI` /// Possible modifications to the confirmed transaction sent by `SignerUI`
#[derive(Debug, PartialEq, Deserialize)] #[derive(Debug, PartialEq, Deserialize)]
pub struct TransactionModification { pub struct TransactionModification {
@ -63,9 +99,7 @@ mod tests {
use std::str::FromStr; use std::str::FromStr;
use rustc_serialize::hex::FromHex; use rustc_serialize::hex::FromHex;
use serde_json; use serde_json;
use util::numbers::{U256}; use v1::types::{U256, H160};
use util::hash::Address;
use v1::types::bytes::Bytes;
use super::*; use super::*;
#[test] #[test]
@ -82,12 +116,12 @@ mod tests {
let deserialized: TransactionRequest = serde_json::from_str(s).unwrap(); let deserialized: TransactionRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, TransactionRequest { assert_eq!(deserialized, TransactionRequest {
from: Address::from(1), from: H160::from(1),
to: Some(Address::from(2)), to: Some(H160::from(2)),
gas_price: Some(U256::from(1)), gas_price: Some(U256::from(1)),
gas: Some(U256::from(2)), gas: Some(U256::from(2)),
value: Some(U256::from(3)), value: Some(U256::from(3)),
data: Some(Bytes::new(vec![0x12, 0x34, 0x56])), data: Some(vec![0x12, 0x34, 0x56].into()),
nonce: Some(U256::from(4)), nonce: Some(U256::from(4)),
}); });
} }
@ -105,12 +139,12 @@ mod tests {
let deserialized: TransactionRequest = serde_json::from_str(s).unwrap(); let deserialized: TransactionRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, TransactionRequest { assert_eq!(deserialized, TransactionRequest {
from: Address::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap(), from: H160::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap(),
to: Some(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()), to: Some(H160::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
gas_price: Some(U256::from_str("9184e72a000").unwrap()), gas_price: Some(U256::from_str("9184e72a000").unwrap()),
gas: Some(U256::from_str("76c0").unwrap()), gas: Some(U256::from_str("76c0").unwrap()),
value: Some(U256::from_str("9184e72a").unwrap()), value: Some(U256::from_str("9184e72a").unwrap()),
data: Some(Bytes::new("d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675".from_hex().unwrap())), data: Some("d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675".from_hex().unwrap().into()),
nonce: None nonce: None
}); });
} }
@ -121,7 +155,7 @@ mod tests {
let deserialized: TransactionRequest = serde_json::from_str(s).unwrap(); let deserialized: TransactionRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, TransactionRequest { assert_eq!(deserialized, TransactionRequest {
from: Address::from(1), from: H160::from(1).into(),
to: None, to: None,
gas_price: None, gas_price: None,
gas: None, gas: None,
@ -144,12 +178,12 @@ mod tests {
let deserialized: TransactionRequest = serde_json::from_str(s).unwrap(); let deserialized: TransactionRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, TransactionRequest { assert_eq!(deserialized, TransactionRequest {
from: Address::from_str("b5f7502a2807cb23615c7456055e1d65b2508625").unwrap(), from: H160::from_str("b5f7502a2807cb23615c7456055e1d65b2508625").unwrap(),
to: Some(Address::from_str("895d32f2db7d01ebb50053f9e48aacf26584fe40").unwrap()), to: Some(H160::from_str("895d32f2db7d01ebb50053f9e48aacf26584fe40").unwrap()),
gas_price: Some(U256::from_str("0ba43b7400").unwrap()), gas_price: Some(U256::from_str("0ba43b7400").unwrap()),
gas: Some(U256::from_str("2fd618").unwrap()), gas: Some(U256::from_str("2fd618").unwrap()),
value: None, value: None,
data: Some(Bytes::new(vec![0x85, 0x95, 0xba, 0xb1])), data: Some(vec![0x85, 0x95, 0xba, 0xb1].into()),
nonce: None, nonce: None,
}); });
} }

89
rpc/src/v1/types/uint.rs Normal file
View File

@ -0,0 +1,89 @@
// 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 std::cmp;
use std::str::FromStr;
use rustc_serialize::hex::ToHex;
use serde;
use util::{U256 as EthU256, Uint};
macro_rules! impl_uint {
($name: ident, $other: ident, $size: expr) => {
/// Uint serialization.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct $name($other);
impl<T> From<T> for $name where $other: From<T> {
fn from(o: T) -> Self {
$name($other::from(o))
}
}
impl FromStr for $name {
type Err = <$other as FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
$other::from_str(s).map($name)
}
}
impl Into<$other> for $name {
fn into(self) -> $other {
self.0
}
}
impl serde::Serialize for $name {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error> where S: serde::Serializer {
let mut hex = "0x".to_owned();
let mut bytes = [0u8; 8 * $size];
self.0.to_raw_bytes(&mut bytes);
let len = cmp::max((self.0.bits() + 7) / 8, 1);
hex.push_str(&bytes[bytes.len() - len..].to_hex());
serializer.serialize_str(&hex)
}
}
impl serde::Deserialize for $name {
fn deserialize<D>(deserializer: &mut D) -> Result<$name, D::Error>
where D: serde::Deserializer {
struct UintVisitor;
impl serde::de::Visitor for UintVisitor {
type Value = $name;
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
// 0x + len
if value.len() > 2 + $size * 16 || value.len() < 2 {
return Err(serde::Error::custom("Invalid length."));
}
$other::from_str(&value[2..]).map($name).map_err(|_| serde::Error::custom("Invalid hex value."))
}
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: serde::Error {
self.visit_str(&value)
}
}
deserializer.deserialize(UintVisitor)
}
}
}
}
impl_uint!(U256, EthU256, 4);

View File

@ -71,8 +71,7 @@ extern crate heapsize;
use std::ops::*; use std::ops::*;
use std::sync::*; use std::sync::*;
use util::network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId}; use util::network::{NetworkProtocolHandler, NetworkService, NetworkContext, PeerId};
use util::TimerToken; use util::{TimerToken, U256};
use util::{U256, ONE_U256};
use ethcore::client::Client; use ethcore::client::Client;
use ethcore::service::{SyncMessage, NetSyncMessage}; use ethcore::service::{SyncMessage, NetSyncMessage};
use io::NetSyncIo; use io::NetSyncIo;
@ -99,7 +98,7 @@ impl Default for SyncConfig {
fn default() -> SyncConfig { fn default() -> SyncConfig {
SyncConfig { SyncConfig {
max_download_ahead_blocks: 20000, max_download_ahead_blocks: 20000,
network_id: ONE_U256, network_id: U256::from(1),
} }
} }
} }

View File

@ -27,15 +27,16 @@ itertools = "0.4"
crossbeam = "0.2" crossbeam = "0.2"
slab = "0.2" slab = "0.2"
sha3 = { path = "sha3" } sha3 = { path = "sha3" }
serde = "0.7.0"
clippy = { version = "0.0.78", optional = true} clippy = { version = "0.0.78", optional = true}
igd = "0.4.2" igd = "0.5.0"
ethcore-devtools = { path = "../devtools" } ethcore-devtools = { path = "../devtools" }
libc = "0.2.7" libc = "0.2.7"
vergen = "0.1" vergen = "0.1"
target_info = "0.1" target_info = "0.1"
bigint = { path = "bigint" } bigint = { path = "bigint" }
chrono = "0.2" chrono = "0.2"
using_queue = { path = "using_queue" }
table = { path = "table" }
ansi_term = "0.7" ansi_term = "0.7"
[features] [features]

View File

@ -12,7 +12,6 @@ rustc_version = "0.1"
[dependencies] [dependencies]
rustc-serialize = "0.3" rustc-serialize = "0.3"
serde = "0.7.0"
heapsize = "0.3" heapsize = "0.3"
[features] [features]

View File

@ -17,7 +17,6 @@
#![cfg_attr(asm_available, feature(asm))] #![cfg_attr(asm_available, feature(asm))]
extern crate rustc_serialize; extern crate rustc_serialize;
extern crate serde;
#[macro_use] extern crate heapsize; #[macro_use] extern crate heapsize;
pub mod uint; pub mod uint;

View File

@ -39,7 +39,6 @@
#[cfg(all(asm_available, target_arch="x86_64"))] #[cfg(all(asm_available, target_arch="x86_64"))]
use std::mem; use std::mem;
use std::fmt; use std::fmt;
use std::cmp;
use std::str::{FromStr}; use std::str::{FromStr};
use std::convert::From; use std::convert::From;
@ -47,14 +46,15 @@ use std::hash::Hash;
use std::ops::*; use std::ops::*;
use std::cmp::*; use std::cmp::*;
use serde; use rustc_serialize::hex::{FromHex, FromHexError};
use rustc_serialize::hex::{FromHex, FromHexError, ToHex};
/// Conversion from decimal string error /// Conversion from decimal string error
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum FromDecStrErr { pub enum FromDecStrErr {
/// Char not from range 0-9
InvalidCharacter,
/// Value does not fit into type /// Value does not fit into type
InvalidLength InvalidLength,
} }
macro_rules! impl_map_from { macro_rules! impl_map_from {
@ -562,8 +562,11 @@ macro_rules! construct_uint {
impl Uint for $name { impl Uint for $name {
/// TODO: optimize, throw appropriate err
fn from_dec_str(value: &str) -> Result<Self, FromDecStrErr> { fn from_dec_str(value: &str) -> Result<Self, FromDecStrErr> {
if value.bytes().any(|b| b < 48 && b > 57) {
return Err(FromDecStrErr::InvalidCharacter)
}
let mut res = Self::default(); let mut res = Self::default();
for b in value.bytes().map(|b| b - 48) { for b in value.bytes().map(|b| b - 48) {
let (r, overflow) = res.overflowing_mul_u32(10); let (r, overflow) = res.overflowing_mul_u32(10);
@ -649,7 +652,7 @@ macro_rules! construct_uint {
fn exp10(n: usize) -> Self { fn exp10(n: usize) -> Self {
match n { match n {
0 => Self::from(1u64), 0 => Self::from(1u64),
_ => Self::exp10(n - 1) * Self::from(10u64) _ => Self::exp10(n - 1).mul_u32(10)
} }
} }
@ -757,16 +760,16 @@ macro_rules! construct_uint {
} }
impl $name { impl $name {
#[allow(dead_code)] // not used when multiplied with inline assembly
/// Multiplication by u32 /// Multiplication by u32
#[allow(dead_code)] // not used when multiplied with inline assembly
fn mul_u32(self, other: u32) -> Self { fn mul_u32(self, other: u32) -> Self {
let (ret, overflow) = self.overflowing_mul_u32(other); let (ret, overflow) = self.overflowing_mul_u32(other);
panic_on_overflow!(overflow); panic_on_overflow!(overflow);
ret ret
} }
#[allow(dead_code)] // not used when multiplied with inline assembly
/// Overflowing multiplication by u32 /// Overflowing multiplication by u32
#[allow(dead_code)] // not used when multiplied with inline assembly
fn overflowing_mul_u32(self, other: u32) -> (Self, bool) { fn overflowing_mul_u32(self, other: u32) -> (Self, bool) {
let $name(ref arr) = self; let $name(ref arr) = self;
let mut ret = [0u64; $n_words]; let mut ret = [0u64; $n_words];
@ -789,44 +792,6 @@ macro_rules! construct_uint {
} }
} }
impl serde::Serialize for $name {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: serde::Serializer {
let mut hex = "0x".to_owned();
let mut bytes = [0u8; 8 * $n_words];
self.to_raw_bytes(&mut bytes);
let len = cmp::max((self.bits() + 7) / 8, 1);
hex.push_str(bytes[bytes.len() - len..].to_hex().as_ref());
serializer.serialize_str(hex.as_ref())
}
}
impl serde::Deserialize for $name {
fn deserialize<D>(deserializer: &mut D) -> Result<$name, D::Error>
where D: serde::Deserializer {
struct UintVisitor;
impl serde::de::Visitor for UintVisitor {
type Value = $name;
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
// 0x + len
if value.len() > 2 + $n_words * 16 || value.len() < 2 {
return Err(serde::Error::custom("Invalid length."));
}
$name::from_str(&value[2..]).map_err(|_| serde::Error::custom("Invalid hex value."))
}
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: serde::Error {
self.visit_str(value.as_ref())
}
}
deserializer.deserialize(UintVisitor)
}
}
impl From<u64> for $name { impl From<u64> for $name {
fn from(value: u64) -> $name { fn from(value: u64) -> $name {
let mut ret = [0; $n_words]; let mut ret = [0; $n_words];
@ -959,8 +924,6 @@ macro_rules! construct_uint {
} }
} }
// TODO: optimise and traitify.
impl BitAnd<$name> for $name { impl BitAnd<$name> for $name {
type Output = $name; type Output = $name;
@ -1434,12 +1397,6 @@ impl From<U256> for u32 {
} }
} }
/// Constant value of `U256::zero()` that can be used for a reference saving an additional instance creation.
pub const ZERO_U256: U256 = U256([0x00u64; 4]);
/// Constant value of `U256::one()` that can be used for a reference saving an additional instance creation.
pub const ONE_U256: U256 = U256([0x01u64, 0x00u64, 0x00u64, 0x00u64]);
known_heap_size!(0, U128, U256); known_heap_size!(0, U128, U256);
#[cfg(test)] #[cfg(test)]
@ -1582,7 +1539,13 @@ mod tests {
assert_eq!(U256::from(105u8) / U256::from(5u8), U256::from(21u8)); assert_eq!(U256::from(105u8) / U256::from(5u8), U256::from(21u8));
let div = mult / U256::from(300u16); let div = mult / U256::from(300u16);
assert_eq!(div, U256([0x9F30411021524112u64, 0x0001BD5B7DDFBD5A, 0, 0])); assert_eq!(div, U256([0x9F30411021524112u64, 0x0001BD5B7DDFBD5A, 0, 0]));
//// TODO: bit inversion
let a = U256::from_str("ff000000000000000000000000000000000000000000000000000000000000d1").unwrap();
let b = U256::from_str("00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e").unwrap();
println!("{:x}", a);
println!("{:x}", b);
assert_eq!(!a, b);
assert_eq!(a, !b);
} }
#[test] #[test]

View File

@ -24,7 +24,7 @@
//! use util::bytes::BytesConvertable; //! use util::bytes::BytesConvertable;
//! //!
//! let arr = [0; 5]; //! let arr = [0; 5];
//! let slice: &[u8] = arr.bytes(); //! let slice: &[u8] = arr.as_slice();
//! } //! }
//! //!
//! fn main() { //! fn main() {
@ -120,12 +120,12 @@ impl<'a> ToPretty for &'a [u8] {
impl<'a> ToPretty for &'a Bytes { impl<'a> ToPretty for &'a Bytes {
fn pretty(&self) -> PrettySlice { fn pretty(&self) -> PrettySlice {
PrettySlice(self.bytes()) PrettySlice(self.as_slice())
} }
} }
impl ToPretty for Bytes { impl ToPretty for Bytes {
fn pretty(&self) -> PrettySlice { fn pretty(&self) -> PrettySlice {
PrettySlice(self.bytes()) PrettySlice(self.as_slice())
} }
} }
@ -162,23 +162,19 @@ pub type Bytes = Vec<u8>;
/// Slice of bytes to underlying memory /// Slice of bytes to underlying memory
pub trait BytesConvertable { pub trait BytesConvertable {
// TODO: rename to as_slice
/// Get the underlying byte-wise representation of the value. /// Get the underlying byte-wise representation of the value.
/// Deprecated - use `as_slice` instead. fn as_slice(&self) -> &[u8];
fn bytes(&self) -> &[u8];
/// Get the underlying byte-wise representation of the value.
fn as_slice(&self) -> &[u8] { self.bytes() }
/// Get a copy of the underlying byte-wise representation. /// Get a copy of the underlying byte-wise representation.
fn to_bytes(&self) -> Bytes { self.as_slice().to_vec() } fn to_bytes(&self) -> Bytes { self.as_slice().to_vec() }
} }
impl<T> BytesConvertable for T where T: AsRef<[u8]> { impl<T> BytesConvertable for T where T: AsRef<[u8]> {
fn bytes(&self) -> &[u8] { self.as_ref() } fn as_slice(&self) -> &[u8] { self.as_ref() }
} }
#[test] #[test]
fn bytes_convertable() { fn bytes_convertable() {
assert_eq!(vec![0x12u8, 0x34].bytes(), &[0x12u8, 0x34]); assert_eq!(vec![0x12u8, 0x34].as_slice(), &[0x12u8, 0x34]);
assert!([0u8; 0].as_slice().is_empty()); assert!([0u8; 0].as_slice().is_empty());
} }

View File

@ -16,16 +16,18 @@
//! 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 rustc_serialize::hex::FromHex;
use std::{ops, fmt, cmp};
use std::cmp::*;
use std::ops::*;
use std::hash::{Hash, Hasher};
use std::str::FromStr;
use math::log2; use math::log2;
use error::UtilError; use error::UtilError;
use rand::Rng; use rand::Rng;
use rand::os::OsRng; use rand::os::OsRng;
use bytes::{BytesConvertable,Populatable}; use bytes::{BytesConvertable,Populatable};
use from_json::*;
use bigint::uint::{Uint, U256}; use bigint::uint::{Uint, U256};
use rustc_serialize::hex::ToHex;
use serde;
/// Trait for a fixed-size byte array to be used as the output of hash functions. /// Trait for a fixed-size byte array to be used as the output of hash functions.
/// ///
@ -228,55 +230,6 @@ macro_rules! impl_hash {
} }
} }
impl serde::Serialize for $from {
fn serialize<S>(&self, serializer: &mut S) -> Result<(), S::Error>
where S: serde::Serializer {
let mut hex = "0x".to_owned();
hex.push_str(self.to_hex().as_ref());
serializer.serialize_str(hex.as_ref())
}
}
impl serde::Deserialize for $from {
fn deserialize<D>(deserializer: &mut D) -> Result<$from, D::Error>
where D: serde::Deserializer {
struct HashVisitor;
impl serde::de::Visitor for HashVisitor {
type Value = $from;
fn visit_str<E>(&mut self, value: &str) -> Result<Self::Value, E> where E: serde::Error {
// 0x + len
if value.len() != 2 + $size * 2 {
return Err(serde::Error::custom("Invalid length."));
}
value[2..].from_hex().map(|ref v| $from::from_slice(v)).map_err(|_| serde::Error::custom("Invalid hex value."))
}
fn visit_string<E>(&mut self, value: String) -> Result<Self::Value, E> where E: serde::Error {
self.visit_str(value.as_ref())
}
}
deserializer.deserialize(HashVisitor)
}
}
impl FromJson for $from {
fn from_json(json: &Json) -> Self {
match *json {
Json::String(ref s) => {
match s.len() % 2 {
0 => FromStr::from_str(clean_0x(s)).unwrap(),
_ => FromStr::from_str(&("0".to_owned() + &(clean_0x(s).to_owned()))[..]).unwrap()
}
},
_ => Default::default(),
}
}
}
impl fmt::Debug for $from { impl fmt::Debug for $from {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for i in &self.0[..] { for i in &self.0[..] {
@ -285,6 +238,7 @@ macro_rules! impl_hash {
Ok(()) Ok(())
} }
} }
impl fmt::Display for $from { impl fmt::Display for $from {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
for i in &self.0[0..2] { for i in &self.0[0..2] {
@ -506,13 +460,13 @@ impl<'a> From<&'a U256> for H256 {
impl From<H256> for U256 { impl From<H256> for U256 {
fn from(value: H256) -> U256 { fn from(value: H256) -> U256 {
U256::from(value.bytes()) U256::from(value.as_slice())
} }
} }
impl<'a> From<&'a H256> for U256 { impl<'a> From<&'a H256> for U256 {
fn from(value: &'a H256) -> U256 { fn from(value: &'a H256) -> U256 {
U256::from(value.bytes()) U256::from(value.as_slice())
} }
} }
@ -532,17 +486,6 @@ impl From<H256> for H64 {
} }
} }
/*
impl<'a> From<&'a H256> for Address {
fn from(value: &'a H256) -> Address {
let mut ret = Address::new();
ret.0.copy_from_slice(&value[12..32]);
ret
}
}
}
*/
impl From<Address> for H256 { impl From<Address> for H256 {
fn from(value: Address) -> H256 { fn from(value: Address) -> H256 {
let mut ret = H256::new(); let mut ret = H256::new();
@ -596,11 +539,6 @@ impl_hash!(H520, 65);
impl_hash!(H1024, 128); impl_hash!(H1024, 128);
impl_hash!(H2048, 256); impl_hash!(H2048, 256);
/// Constant address for point 0. Often used as a default.
pub static ZERO_ADDRESS: Address = Address([0x00; 20]);
/// Constant 256-bit datum for 0. Often used as a default.
pub static ZERO_H256: H256 = H256([0x00; 32]);
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use hash::*; use hash::*;

View File

@ -79,7 +79,7 @@ impl ArchiveDB {
} }
fn payload(&self, key: &H256) -> Option<Bytes> { fn payload(&self, key: &H256) -> Option<Bytes> {
self.backing.get(&key.bytes()).expect("Low-level database error. Some issue with your hard disk?").map(|v| v.to_vec()) self.backing.get(key).expect("Low-level database error. Some issue with your hard disk?").map(|v| v.to_vec())
} }
} }
@ -177,7 +177,7 @@ impl JournalDB for ArchiveDB {
let (key, (value, rc)) = i; let (key, (value, rc)) = i;
if rc > 0 { if rc > 0 {
assert!(rc == 1); assert!(rc == 1);
batch.put(&key.bytes(), &value).expect("Low-level database error. Some issue with your hard disk?"); batch.put(&key, &value).expect("Low-level database error. Some issue with your hard disk?");
inserts += 1; inserts += 1;
} }
if rc < 0 { if rc < 0 {
@ -202,7 +202,7 @@ impl JournalDB for ArchiveDB {
fn latest_era(&self) -> Option<u64> { self.latest_era } fn latest_era(&self) -> Option<u64> { self.latest_era }
fn state(&self, id: &H256) -> Option<Bytes> { fn state(&self, id: &H256) -> Option<Bytes> {
self.backing.get_by_prefix(&id.bytes()[0..12]).and_then(|b| Some(b.to_vec())) self.backing.get_by_prefix(&id[0..12]).and_then(|b| Some(b.to_vec()))
} }
fn is_pruned(&self) -> bool { false } fn is_pruned(&self) -> bool { false }

View File

@ -106,7 +106,7 @@ impl EarlyMergeDB {
} }
fn morph_key(key: &H256, index: u8) -> Bytes { fn morph_key(key: &H256, index: u8) -> Bytes {
let mut ret = key.bytes().to_owned(); let mut ret = key.to_bytes();
ret.push(index); ret.push(index);
ret ret
} }
@ -130,7 +130,7 @@ impl EarlyMergeDB {
} }
// this is the first entry for this node in the journal. // this is the first entry for this node in the journal.
if backing.get(&h.bytes()).expect("Low-level database error. Some issue with your hard disk?").is_some() { if backing.get(h).expect("Low-level database error. Some issue with your hard disk?").is_some() {
// already in the backing DB. start counting, and remember it was already in. // already in the backing DB. start counting, and remember it was already in.
Self::set_already_in(batch, &h); Self::set_already_in(batch, &h);
refs.insert(h.clone(), RefInfo{queue_refs: 1, in_archive: true}); refs.insert(h.clone(), RefInfo{queue_refs: 1, in_archive: true});
@ -143,7 +143,7 @@ impl EarlyMergeDB {
// Gets removed when a key leaves the journal, so should never be set when we're placing a new key. // Gets removed when a key leaves the journal, so should never be set when we're placing a new key.
//Self::reset_already_in(&h); //Self::reset_already_in(&h);
assert!(!Self::is_already_in(backing, &h)); assert!(!Self::is_already_in(backing, &h));
batch.put(&h.bytes(), d).expect("Low-level database error. Some issue with your hard disk?"); batch.put(h, d).expect("Low-level database error. Some issue with your hard disk?");
refs.insert(h.clone(), RefInfo{queue_refs: 1, in_archive: false}); refs.insert(h.clone(), RefInfo{queue_refs: 1, in_archive: false});
if trace { if trace {
trace!(target: "jdb.fine", " insert({}): New to queue, not in DB: Inserting into queue and DB", h); trace!(target: "jdb.fine", " insert({}): New to queue, not in DB: Inserting into queue and DB", h);
@ -204,7 +204,7 @@ impl EarlyMergeDB {
} }
Some(RefInfo{queue_refs: 1, in_archive: false}) => { Some(RefInfo{queue_refs: 1, in_archive: false}) => {
refs.remove(h); refs.remove(h);
batch.delete(&h.bytes()).expect("Low-level database error. Some issue with your hard disk?"); batch.delete(h).expect("Low-level database error. Some issue with your hard disk?");
if trace { if trace {
trace!(target: "jdb.fine", " remove({}): Not in archive, only 1 ref in queue: Removing from queue and DB", h); trace!(target: "jdb.fine", " remove({}): Not in archive, only 1 ref in queue: Removing from queue and DB", h);
} }
@ -212,7 +212,7 @@ impl EarlyMergeDB {
None => { None => {
// Gets removed when moving from 1 to 0 additional refs. Should never be here at 0 additional refs. // Gets removed when moving from 1 to 0 additional refs. Should never be here at 0 additional refs.
//assert!(!Self::is_already_in(db, &h)); //assert!(!Self::is_already_in(db, &h));
batch.delete(&h.bytes()).expect("Low-level database error. Some issue with your hard disk?"); batch.delete(h).expect("Low-level database error. Some issue with your hard disk?");
if trace { if trace {
trace!(target: "jdb.fine", " remove({}): Not in queue - MUST BE IN ARCHIVE: Removing from DB", h); trace!(target: "jdb.fine", " remove({}): Not in queue - MUST BE IN ARCHIVE: Removing from DB", h);
} }
@ -237,7 +237,7 @@ impl EarlyMergeDB {
} }
fn payload(&self, key: &H256) -> Option<Bytes> { fn payload(&self, key: &H256) -> Option<Bytes> {
self.backing.get(&key.bytes()).expect("Low-level database error. Some issue with your hard disk?").map(|v| v.to_vec()) self.backing.get(key).expect("Low-level database error. Some issue with your hard disk?").map(|v| v.to_vec())
} }
fn read_refs(db: &Database) -> (Option<u64>, HashMap<H256, RefInfo>) { fn read_refs(db: &Database) -> (Option<u64>, HashMap<H256, RefInfo>) {

View File

@ -141,7 +141,7 @@ impl OverlayRecentDB {
} }
fn payload(&self, key: &H256) -> Option<Bytes> { fn payload(&self, key: &H256) -> Option<Bytes> {
self.backing.get(&key.bytes()).expect("Low-level database error. Some issue with your hard disk?").map(|v| v.to_vec()) self.backing.get(key).expect("Low-level database error. Some issue with your hard disk?").map(|v| v.to_vec())
} }
fn read_overlay(db: &Database) -> JournalOverlay { fn read_overlay(db: &Database) -> JournalOverlay {

View File

@ -108,7 +108,6 @@ extern crate secp256k1;
extern crate arrayvec; extern crate arrayvec;
extern crate elastic_array; extern crate elastic_array;
extern crate crossbeam; extern crate crossbeam;
extern crate serde;
#[macro_use] #[macro_use]
extern crate log as rlog; extern crate log as rlog;
extern crate igd; extern crate igd;
@ -117,6 +116,8 @@ extern crate libc;
extern crate target_info; extern crate target_info;
extern crate bigint; extern crate bigint;
extern crate chrono; extern crate chrono;
pub extern crate using_queue;
pub extern crate table;
extern crate ansi_term; extern crate ansi_term;
pub mod standard; pub mod standard;
@ -130,7 +131,6 @@ pub mod hash;
pub mod bytes; pub mod bytes;
pub mod rlp; pub mod rlp;
pub mod misc; pub mod misc;
pub mod using_queue;
pub mod vector; pub mod vector;
pub mod sha3; pub mod sha3;
pub mod hashdb; pub mod hashdb;
@ -151,14 +151,12 @@ pub mod io;
pub mod network; pub mod network;
pub mod log; pub mod log;
pub mod panics; pub mod panics;
pub mod table;
pub mod network_settings; pub mod network_settings;
pub mod path; pub mod path;
mod timer; mod timer;
pub use common::*; pub use common::*;
pub use misc::*; pub use misc::*;
pub use using_queue::*;
pub use rlp::*; pub use rlp::*;
pub use hashdb::*; pub use hashdb::*;
pub use memorydb::*; pub use memorydb::*;

View File

@ -198,14 +198,14 @@ impl HashDB for MemoryDB {
let key = value.sha3(); let key = value.sha3();
if match self.data.get_mut(&key) { if match self.data.get_mut(&key) {
Some(&mut (ref mut old_value, ref mut rc @ -0x80000000i32 ... 0)) => { Some(&mut (ref mut old_value, ref mut rc @ -0x80000000i32 ... 0)) => {
*old_value = From::from(value.bytes()); *old_value = From::from(value);
*rc += 1; *rc += 1;
false false
}, },
Some(&mut (_, ref mut x)) => { *x += 1; false } , Some(&mut (_, ref mut x)) => { *x += 1; false } ,
None => true, None => true,
}{ // ... None falls through into... }{ // ... None falls through into...
self.data.insert(key.clone(), (From::from(value.bytes()), 1)); self.data.insert(key.clone(), (From::from(value), 1));
} }
key key
} }
@ -262,8 +262,8 @@ fn memorydb_denote() {
for _ in 0..1000 { for _ in 0..1000 {
let r = H256::random(); let r = H256::random();
let k = r.sha3(); let k = r.sha3();
let &(ref v, ref rc) = m.denote(&k, r.bytes().to_vec()); let &(ref v, ref rc) = m.denote(&k, r.to_bytes());
assert_eq!(v, &r.bytes()); assert_eq!(v.as_slice(), r.as_slice());
assert_eq!(*rc, 0); assert_eq!(*rc, 0);
} }

View File

@ -172,10 +172,10 @@ impl OverlayDB {
/// Get the refs and value of the given key. /// Get the refs and value of the given key.
fn payload(&self, key: &H256) -> Option<(Bytes, u32)> { fn payload(&self, key: &H256) -> Option<(Bytes, u32)> {
self.backing.get(&key.bytes()) self.backing.get(key)
.expect("Low-level database error. Some issue with your hard disk?") .expect("Low-level database error. Some issue with your hard disk?")
.map(|d| { .map(|d| {
let r = Rlp::new(d.deref()); let r = Rlp::new(&d);
(r.at(1).as_val(), r.at(0).as_val()) (r.at(1).as_val(), r.at(0).as_val())
}) })
} }
@ -186,10 +186,10 @@ impl OverlayDB {
let mut s = RlpStream::new_list(2); let mut s = RlpStream::new_list(2);
s.append(&payload.1); s.append(&payload.1);
s.append(&payload.0); s.append(&payload.0);
batch.put(&key.bytes(), s.as_raw()).expect("Low-level database error. Some issue with your hard disk?"); batch.put(key, s.as_raw()).expect("Low-level database error. Some issue with your hard disk?");
false false
} else { } else {
batch.delete(&key.bytes()).expect("Low-level database error. Some issue with your hard disk?"); batch.delete(key).expect("Low-level database error. Some issue with your hard disk?");
true true
} }
} }
@ -200,10 +200,10 @@ impl OverlayDB {
let mut s = RlpStream::new_list(2); let mut s = RlpStream::new_list(2);
s.append(&payload.1); s.append(&payload.1);
s.append(&payload.0); s.append(&payload.0);
self.backing.put(&key.bytes(), s.as_raw()).expect("Low-level database error. Some issue with your hard disk?"); self.backing.put(key, s.as_raw()).expect("Low-level database error. Some issue with your hard disk?");
false false
} else { } else {
self.backing.delete(&key.bytes()).expect("Low-level database error. Some issue with your hard disk?"); self.backing.delete(key).expect("Low-level database error. Some issue with your hard disk?");
true true
} }
} }

View File

@ -148,9 +148,9 @@ impl_uint_to_bytes!(U128);
impl <T>ToBytes for T where T: FixedHash { impl <T>ToBytes for T where T: FixedHash {
fn to_bytes<V: VecLike<u8>>(&self, out: &mut V) { fn to_bytes<V: VecLike<u8>>(&self, out: &mut V) {
out.vec_extend(self.bytes()); out.vec_extend(self.as_slice());
} }
fn to_bytes_len(&self) -> usize { self.bytes().len() } fn to_bytes_len(&self) -> usize { self.as_slice().len() }
} }
/// Error returned when `FromBytes` conversation goes wrong /// Error returned when `FromBytes` conversation goes wrong

View File

@ -58,7 +58,7 @@ impl<T> Hashable for T where T: BytesConvertable {
} }
fn sha3_into(&self, dest: &mut [u8]) { fn sha3_into(&self, dest: &mut [u8]) {
unsafe { unsafe {
let input: &[u8] = self.bytes(); let input: &[u8] = self.as_slice();
sha3_256(dest.as_mut_ptr(), dest.len(), input.as_ptr(), input.len()); sha3_256(dest.as_mut_ptr(), dest.len(), input.as_ptr(), input.len());
} }
} }

View File

@ -64,16 +64,16 @@ impl StandardMap {
fn random_bytes(min_count: usize, journal_count: usize, seed: &mut H256) -> Vec<u8> { fn random_bytes(min_count: usize, journal_count: usize, seed: &mut H256) -> Vec<u8> {
assert!(min_count + journal_count <= 32); assert!(min_count + journal_count <= 32);
*seed = seed.sha3(); *seed = seed.sha3();
let r = min_count + (seed.bytes()[31] as usize % (journal_count + 1)); let r = min_count + (seed[31] as usize % (journal_count + 1));
seed.bytes()[0..r].to_vec() seed[0..r].to_vec()
} }
/// Get a random value. Equal chance of being 1 byte as of 32. `seed` is mutated pseudoramdonly and used. /// Get a random value. Equal chance of being 1 byte as of 32. `seed` is mutated pseudoramdonly and used.
fn random_value(seed: &mut H256) -> Bytes { fn random_value(seed: &mut H256) -> Bytes {
*seed = seed.sha3(); *seed = seed.sha3();
match seed.bytes()[0] % 2 { match seed[0] % 2 {
1 => vec![seed.bytes()[31];1], 1 => vec![seed[31];1],
_ => seed.bytes().to_vec(), _ => seed.to_vec(),
} }
} }
@ -82,10 +82,10 @@ impl StandardMap {
fn random_word(alphabet: &[u8], min_count: usize, journal_count: usize, seed: &mut H256) -> Vec<u8> { fn random_word(alphabet: &[u8], min_count: usize, journal_count: usize, seed: &mut H256) -> Vec<u8> {
assert!(min_count + journal_count <= 32); assert!(min_count + journal_count <= 32);
*seed = seed.sha3(); *seed = seed.sha3();
let r = min_count + (seed.bytes()[31] as usize % (journal_count + 1)); let r = min_count + (seed[31] as usize % (journal_count + 1));
let mut ret: Vec<u8> = Vec::with_capacity(r); let mut ret: Vec<u8> = Vec::with_capacity(r);
for i in 0..r { for i in 0..r {
ret.push(alphabet[seed.bytes()[i] as usize % alphabet.len()]); ret.push(alphabet[seed[i] as usize % alphabet.len()]);
} }
ret ret
} }

6
util/table/Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[package]
name = "table"
version = "0.1.0"
authors = ["debris <marek.kotewicz@gmail.com>"]
[dependencies]

View File

@ -0,0 +1,6 @@
[package]
name = "using_queue"
version = "0.1.0"
authors = ["debris <marek.kotewicz@gmail.com>"]
[dependencies]

View File

@ -13,6 +13,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Queue-like datastructure including notion of usage. //! Queue-like datastructure including notion of usage.
/// Special queue-like datastructure that includes the notion of /// Special queue-like datastructure that includes the notion of