diff --git a/Cargo.lock b/Cargo.lock
index 703935bff..a17bc4413 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -70,7 +70,6 @@ dependencies = [
"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_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]]
@@ -149,15 +148,6 @@ dependencies = [
"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]]
name = "cookie"
version = "0.2.4"
@@ -225,15 +215,13 @@ dependencies = [
[[package]]
name = "eth-secp256k1"
version = "0.5.4"
-source = "git+https://github.com/ethcore/rust-secp256k1#b6fdd43bbcf6d46adb72a92dd1632a0fc834cbf5"
+source = "git+https://github.com/ethcore/rust-secp256k1#a9a0b1be1f39560ca86e8fc8e55e205a753ff25c"
dependencies = [
"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)",
"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)",
"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]]
@@ -388,7 +376,7 @@ dependencies = [
"eth-secp256k1 0.5.4 (git+https://github.com/ethcore/rust-secp256k1)",
"ethcore-devtools 1.3.0",
"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)",
"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)",
@@ -400,12 +388,13 @@ dependencies = [
"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_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",
"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)",
"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)",
+ "using_queue 0.1.0",
"vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -505,26 +494,6 @@ name = "httparse"
version = "1.1.2"
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]]
name = "hyper"
version = "0.8.1"
@@ -578,10 +547,10 @@ dependencies = [
[[package]]
name = "igd"
-version = "0.4.2"
+version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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)",
"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)",
@@ -638,11 +607,6 @@ dependencies = [
"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]]
name = "language-tags"
version = "0.2.2"
@@ -676,15 +640,6 @@ dependencies = [
"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]]
name = "mime"
version = "0.2.0"
@@ -1145,14 +1100,6 @@ dependencies = [
"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]]
name = "serde"
version = "0.7.9"
@@ -1244,6 +1191,10 @@ dependencies = [
"unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "table"
+version = "0.1.0"
+
[[package]]
name = "target_info"
version = "0.1.0"
@@ -1350,16 +1301,6 @@ name = "unicode-xid"
version = "0.0.3"
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]]
name = "url"
version = "0.5.9"
@@ -1381,20 +1322,15 @@ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "using_queue"
+version = "0.1.0"
+
[[package]]
name = "utf8-ranges"
version = "0.1.3"
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]]
name = "uuid"
version = "0.2.1"
diff --git a/ethcore/src/account.rs b/ethcore/src/account.rs
index 2db4ffcc0..5119b2e33 100644
--- a/ethcore/src/account.rs
+++ b/ethcore/src/account.rs
@@ -127,7 +127,7 @@ impl Account {
SecTrieDBMut would not set it to an invalid state root. Therefore the root is valid and DB creation \
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()
}
diff --git a/ethcore/src/header.rs b/ethcore/src/header.rs
index 0941c9ca6..77ec4813b 100644
--- a/ethcore/src/header.rs
+++ b/ethcore/src/header.rs
@@ -92,10 +92,10 @@ impl PartialEq for Header {
impl Default for Header {
fn default() -> Self {
Header {
- parent_hash: ZERO_H256.clone(),
+ parent_hash: H256::default(),
timestamp: 0,
number: 0,
- author: ZERO_ADDRESS.clone(),
+ author: Address::default(),
transactions_root: SHA3_NULL_RLP,
uncles_hash: SHA3_EMPTY_LIST_RLP,
@@ -104,10 +104,10 @@ impl Default for Header {
state_root: SHA3_NULL_RLP,
receipts_root: SHA3_NULL_RLP,
log_bloom: ZERO_LOGBLOOM.clone(),
- gas_used: ZERO_U256,
- gas_limit: ZERO_U256,
+ gas_used: U256::default(),
+ gas_limit: U256::default(),
- difficulty: ZERO_U256,
+ difficulty: U256::default(),
seal: vec![],
hash: RefCell::new(None),
bare_hash: RefCell::new(None),
diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs
index dac25addf..3e5d3d445 100644
--- a/ethcore/src/miner/miner.rs
+++ b/ethcore/src/miner/miner.rs
@@ -19,6 +19,7 @@ use std::sync::atomic::AtomicBool;
use std::time::{Instant, Duration};
use util::*;
+use util::using_queue::{UsingQueue, GetAction};
use util::Colour::White;
use account_provider::AccountProvider;
use views::{BlockView, HeaderView};
diff --git a/ethcore/src/miner/transaction_queue.rs b/ethcore/src/miner/transaction_queue.rs
index 1fbc8774f..bdce9f504 100644
--- a/ethcore/src/miner/transaction_queue.rs
+++ b/ethcore/src/miner/transaction_queue.rs
@@ -87,7 +87,7 @@ use std::cmp;
use std::collections::{HashMap, BTreeSet};
use util::numbers::{Uint, U256};
use util::hash::{Address, H256};
-use util::table::*;
+use util::table::Table;
use transaction::*;
use error::{Error, TransactionError};
use client::TransactionImportResult;
diff --git a/rpc/src/v1/helpers/mod.rs b/rpc/src/v1/helpers/mod.rs
index 2acf98bf2..3df96b00e 100644
--- a/rpc/src/v1/helpers/mod.rs
+++ b/rpc/src/v1/helpers/mod.rs
@@ -16,8 +16,10 @@
mod poll_manager;
mod poll_filter;
+mod requests;
mod signing_queue;
pub use self::poll_manager::PollManager;
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};
diff --git a/rpc/src/v1/helpers/requests.rs b/rpc/src/v1/helpers/requests.rs
new file mode 100644
index 000000000..d162774d9
--- /dev/null
+++ b/rpc/src/v1/helpers/requests.rs
@@ -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 .
+
+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
,
+ /// Gas Price
+ pub gas_price: Option,
+ /// Gas
+ pub gas: Option,
+ /// Value of transaction in wei
+ pub value: Option,
+ /// Additional data sent with transaction
+ pub data: Option>,
+ /// Transaction's nonce
+ pub nonce: Option,
+}
+
+/// 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,
+ /// To
+ pub to: Option,
+ /// Gas Price
+ pub gas_price: Option,
+ /// Gas
+ pub gas: Option,
+ /// Value
+ pub value: Option,
+ /// Data
+ pub data: Option>,
+ /// Nonce
+ pub nonce: Option,
+}
diff --git a/rpc/src/v1/helpers/signing_queue.rs b/rpc/src/v1/helpers/signing_queue.rs
index 3d7f9e35b..756718000 100644
--- a/rpc/src/v1/helpers/signing_queue.rs
+++ b/rpc/src/v1/helpers/signing_queue.rs
@@ -18,9 +18,9 @@ use std::thread;
use std::time::{Instant, Duration};
use std::sync::{mpsc, Mutex, RwLock, Arc};
use std::collections::HashMap;
-use v1::types::{TransactionRequest, TransactionConfirmation};
-use util::U256;
use jsonrpc_core;
+use util::U256;
+use v1::helpers::{TransactionRequest, TransactionConfirmation};
/// Result that can be returned from JSON RPC.
pub type RpcResult = Result;
@@ -301,10 +301,9 @@ mod test {
use std::time::Duration;
use std::thread;
use std::sync::{Arc, Mutex};
- use util::hash::Address;
- use util::numbers::{U256, H256};
- use v1::types::TransactionRequest;
- use super::*;
+ use util::{Address, U256, H256};
+ use v1::helpers::{SigningQueue, ConfirmationsQueue, QueueEvent, TransactionRequest};
+ use v1::types::H256 as NH256;
use jsonrpc_core::to_value;
fn request() -> TransactionRequest {
@@ -337,10 +336,10 @@ mod test {
// Just wait for the other thread to start
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
- 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]
diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs
index 4ccefc0bf..13f54feea 100644
--- a/rpc/src/v1/impls/eth.rs
+++ b/rpc/src/v1/impls/eth.rs
@@ -38,7 +38,8 @@ use ethcore::log_entry::LogEntry;
use ethcore::filter::Filter as EthcoreFilter;
use self::ethash::SeedHashCompute;
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 serde;
use ethcore::header::Header as BlockHeader;
@@ -86,28 +87,28 @@ impl EthClient where
let block_view = BlockView::new(&bytes);
let view = block_view.header_view();
let block = Block {
- hash: OptionalValue::Value(view.sha3()),
- parent_hash: view.parent_hash(),
- uncles_hash: view.uncles_hash(),
- author: view.author(),
- miner: view.author(),
- state_root: view.state_root(),
- transactions_root: view.transactions_root(),
- receipts_root: view.receipts_root(),
- number: OptionalValue::Value(U256::from(view.number())),
- gas_used: view.gas_used(),
- gas_limit: view.gas_limit(),
- logs_bloom: view.log_bloom(),
- timestamp: U256::from(view.timestamp()),
- difficulty: view.difficulty(),
- total_difficulty: total_difficulty,
+ hash: Some(view.sha3().into()),
+ parent_hash: view.parent_hash().into(),
+ uncles_hash: view.uncles_hash().into(),
+ author: view.author().into(),
+ miner: view.author().into(),
+ state_root: view.state_root().into(),
+ transactions_root: view.transactions_root().into(),
+ receipts_root: view.receipts_root().into(),
+ number: Some(view.number().into()),
+ gas_used: view.gas_used().into(),
+ gas_limit: view.gas_limit().into(),
+ logs_bloom: view.log_bloom().into(),
+ timestamp: view.timestamp().into(),
+ difficulty: view.difficulty().into(),
+ total_difficulty: total_difficulty.into(),
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: {
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 {
- 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())
@@ -127,7 +128,6 @@ impl EthClient where
fn uncle(&self, id: UncleID) -> Result {
let client = take_weak!(self.client);
-
let uncle: BlockHeader = match client.uncle(id) {
Some(rlp) => decode(&rlp),
None => { return Ok(Value::Null); }
@@ -138,22 +138,22 @@ impl EthClient where
};
let block = Block {
- hash: OptionalValue::Value(uncle.hash()),
- parent_hash: uncle.parent_hash,
- uncles_hash: uncle.uncles_hash,
- author: uncle.author,
- miner: uncle.author,
- state_root: uncle.state_root,
- transactions_root: uncle.transactions_root,
- number: OptionalValue::Value(U256::from(uncle.number)),
- gas_used: uncle.gas_used,
- gas_limit: uncle.gas_limit,
- logs_bloom: uncle.log_bloom,
- timestamp: U256::from(uncle.timestamp),
- difficulty: uncle.difficulty,
- total_difficulty: uncle.difficulty + parent_difficulty,
- receipts_root: uncle.receipts_root,
- extra_data: Bytes::new(uncle.extra_data),
+ hash: Some(uncle.hash().into()),
+ parent_hash: uncle.parent_hash.into(),
+ uncles_hash: uncle.uncles_hash.into(),
+ author: uncle.author.into(),
+ miner: uncle.author.into(),
+ state_root: uncle.state_root.into(),
+ transactions_root: uncle.transactions_root.into(),
+ number: Some(uncle.number.into()),
+ gas_used: uncle.gas_used.into(),
+ gas_limit: uncle.gas_limit.into(),
+ logs_bloom: uncle.log_bloom.into(),
+ timestamp: uncle.timestamp.into(),
+ difficulty: uncle.difficulty.into(),
+ total_difficulty: (uncle.difficulty + parent_difficulty).into(),
+ receipts_root: uncle.receipts_root.into(),
+ extra_data: uncle.extra_data.into(),
seal_fields: uncle.seal.into_iter().map(|f| decode(&f)).map(Bytes::new).collect(),
uncles: vec![],
transactions: BlockTransactions::Hashes(vec![]),
@@ -161,7 +161,7 @@ impl EthClient where
to_value(&block)
}
- fn sign_call(&self, request: CallRequest) -> Result {
+ fn sign_call(&self, request: CRequest) -> Result {
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
let from = request.from.unwrap_or(Address::zero());
Ok(EthTransaction {
@@ -186,7 +186,7 @@ pub fn pending_logs(miner: &M, filter: &EthcoreFilter) -> Vec where M: M
.filter(|pair| filter.matches(&pair.1))
.map(|pair| {
let mut log = Log::from(pair.1);
- log.transaction_hash = Some(pair.0);
+ log.transaction_hash = Some(pair.0.into());
log
})
.collect();
@@ -277,15 +277,17 @@ impl Eth for EthClient where
SyncState::Idle => SyncStatus::None,
SyncState::Waiting | SyncState::Blocks | SyncState::NewBlocks | SyncState::ChainHead => {
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 {
- starting_block: U256::from(status.start_block_number),
- current_block: current_block,
- highest_block: U256::from(status.highest_block_number.unwrap_or(status.start_block_number))
- };
- match info.highest_block > info.current_block + U256::from(6) {
- true => SyncStatus::Info(info),
- false => SyncStatus::None,
+ if highest_block > current_block + U256::from(6) {
+ let info = SyncInfo {
+ starting_block: status.start_block_number.into(),
+ current_block: current_block.into(),
+ highest_block: highest_block.into(),
+ };
+ SyncStatus::Info(info)
+ } else {
+ SyncStatus::None
}
}
};
@@ -298,7 +300,7 @@ impl Eth for EthClient where
fn author(&self, params: Params) -> Result {
try!(self.active());
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()),
}
}
@@ -314,7 +316,7 @@ impl Eth for EthClient where
fn hashrate(&self, params: Params) -> Result {
try!(self.active());
match params {
- Params::None => to_value(&self.external_miner.hashrate()),
+ Params::None => to_value(&RpcU256::from(self.external_miner.hashrate())),
_ => Err(Error::invalid_params())
}
}
@@ -324,7 +326,7 @@ impl Eth for EthClient where
match params {
Params::None => {
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())
}
@@ -333,13 +335,13 @@ impl Eth for EthClient where
fn accounts(&self, _: Params) -> Result {
try!(self.active());
let store = take_weak!(self.accounts);
- to_value(&store.accounts())
+ to_value(&store.accounts().into_iter().map(Into::into).collect::>())
}
fn block_number(&self, params: Params) -> Result {
try!(self.active());
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())
}
}
@@ -347,39 +349,50 @@ impl Eth for EthClient where
fn balance(&self, params: Params) -> Result {
try!(self.active());
from_params_default_second(params)
- .and_then(|(address, block_number,)| match block_number {
- BlockNumber::Pending => to_value(&take_weak!(self.miner).balance(take_weak!(self.client).deref(), &address)),
- id => to_value(&try!(take_weak!(self.client).balance(&address, id.into()).ok_or_else(make_unsupported_err))),
+ .and_then(|(address, block_number,)| {
+ let address: Address = RpcH160::into(address);
+ 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 {
try!(self.active());
- from_params_default_third::(params)
- .and_then(|(address, position, block_number,)| match block_number {
- BlockNumber::Pending => to_value(&U256::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(&U256::from(s)),
- None => Err(make_unsupported_err()), // None is only returned on unsupported requests.
+ from_params_default_third::(params)
+ .and_then(|(address, position, block_number,)| {
+ let address: Address = RpcH160::into(address);
+ let position: U256 = RpcU256::into(position);
+ match block_number {
+ 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 {
try!(self.active());
from_params_default_second(params)
- .and_then(|(address, block_number,)| match block_number {
- BlockNumber::Pending => to_value(&take_weak!(self.miner).nonce(take_weak!(self.client).deref(), &address)),
- id => to_value(&take_weak!(self.client).nonce(&address, id.into())),
+ .and_then(|(address, block_number,)| {
+ let address: Address = RpcH160::into(address);
+ 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 {
try!(self.active());
- from_params::<(H256,)>(params)
+ from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| // match
- take_weak!(self.client).block(BlockID::Hash(hash))
- .map_or(Ok(Value::Null), |bytes| to_value(&U256::from(BlockView::new(&bytes).transactions_count()))))
+ take_weak!(self.client).block(BlockID::Hash(hash.into()))
+ .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 {
@@ -387,45 +400,48 @@ impl Eth for EthClient where
from_params::<(BlockNumber,)>(params)
.and_then(|(block_number,)| match block_number {
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())
- .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 {
try!(self.active());
- from_params::<(H256,)>(params)
+ from_params::<(RpcH256,)>(params)
.and_then(|(hash,)|
- take_weak!(self.client).block(BlockID::Hash(hash))
- .map_or(Ok(Value::Null), |bytes| to_value(&U256::from(BlockView::new(&bytes).uncles_count()))))
+ take_weak!(self.client).block(BlockID::Hash(hash.into()))
+ .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 {
try!(self.active());
from_params::<(BlockNumber,)>(params)
.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())
- .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 {
try!(self.active());
from_params_default_second(params)
- .and_then(|(address, block_number,)| match block_number {
- 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()),
+ .and_then(|(address, block_number,)| {
+ let address: Address = RpcH160::into(address);
+ match block_number {
+ 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 {
try!(self.active());
- from_params::<(H256, bool)>(params)
- .and_then(|(hash, include_txs)| self.block(BlockID::Hash(hash), include_txs))
+ from_params::<(RpcH256, bool)>(params)
+ .and_then(|(hash, include_txs)| self.block(BlockID::Hash(hash.into()), include_txs))
}
fn block_by_number(&self, params: Params) -> Result {
@@ -436,9 +452,10 @@ impl Eth for EthClient where
fn transaction_by_hash(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(H256,)>(params)
+ from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| {
let miner = take_weak!(self.miner);
+ let hash: H256 = hash.into();
match miner.transaction(&hash) {
Some(pending_tx) => to_value(&Transaction::from(pending_tx)),
None => self.transaction(TransactionID::Hash(hash))
@@ -448,8 +465,8 @@ impl Eth for EthClient where
fn transaction_by_block_hash_and_index(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(H256, Index)>(params)
- .and_then(|(hash, index)| self.transaction(TransactionID::Location(BlockID::Hash(hash), index.value())))
+ from_params::<(RpcH256, Index)>(params)
+ .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 {
@@ -460,9 +477,10 @@ impl Eth for EthClient where
fn transaction_receipt(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(H256,)>(params)
+ from_params::<(RpcH256,)>(params)
.and_then(|(hash,)| {
let miner = take_weak!(self.miner);
+ let hash: H256 = hash.into();
match miner.pending_receipts().get(&hash) {
Some(receipt) if self.allow_pending_receipt_query => to_value(&Receipt::from(receipt.clone())),
_ => {
@@ -476,8 +494,8 @@ impl Eth for EthClient where
fn uncle_by_block_hash_and_index(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(H256, Index)>(params)
- .and_then(|(hash, index)| self.uncle(UncleID { block: BlockID::Hash(hash), position: index.value() }))
+ from_params::<(RpcH256, Index)>(params)
+ .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 {
@@ -543,8 +561,9 @@ impl Eth for EthClient where
miner.map_sealing_work(client.deref(), |b| {
let pow_hash = b.hash();
let target = Ethash::difficulty_to_boundary(b.block().header().difficulty());
- 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 seed_hash = self.seed_compute.lock().unwrap().get_seedhash(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.
},
_ => Err(Error::invalid_params())
@@ -553,7 +572,10 @@ impl Eth for EthClient where
fn submit_work(&self, params: Params) -> Result {
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);
let miner = take_weak!(self.miner);
let client = take_weak!(self.client);
@@ -565,8 +587,8 @@ impl Eth for EthClient where
fn submit_hashrate(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(U256, H256)>(params).and_then(|(rate, id)| {
- self.external_miner.submit_hashrate(rate, id);
+ from_params::<(RpcU256, RpcH256)>(params).and_then(|(rate, id)| {
+ self.external_miner.submit_hashrate(rate.into(), id.into());
to_value(&true)
})
}
@@ -578,7 +600,7 @@ impl Eth for EthClient where
let raw_transaction = raw_transaction.to_vec();
match UntrustedRlp::new(&raw_transaction).as_val() {
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 Eth for EthClient where
trace!(target: "jsonrpc", "call: {:?}", params);
from_params_default_second(params)
.and_then(|(request, block_number,)| {
+ let request = CallRequest::into(request);
let signed = try!(self.sign_call(request));
let r = match block_number {
BlockNumber::Pending => take_weak!(self.miner).call(take_weak!(self.client).deref(), &signed, Default::default()),
@@ -602,13 +625,14 @@ impl Eth for EthClient where
try!(self.active());
from_params_default_second(params)
.and_then(|(request, block_number,)| {
+ let request = CallRequest::into(request);
let signed = try!(self.sign_call(request));
let r = match block_number {
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()),
_ => 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))))
})
}
diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs
index 40ced7187..cf2006788 100644
--- a/rpc/src/v1/impls/eth_filter.rs
+++ b/rpc/src/v1/impls/eth_filter.rs
@@ -25,7 +25,7 @@ use ethcore::miner::MinerService;
use ethcore::filter::Filter as EthcoreFilter;
use ethcore::client::{BlockChainClient, BlockID};
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::impls::eth::pending_logs;
@@ -71,7 +71,7 @@ impl EthFilter for EthFilterClient where
let mut polls = self.polls.lock().unwrap();
let block_number = take_weak!(self.client).chain_info().best_block_number;
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 EthFilter for EthFilterClient where
Params::None => {
let mut polls = self.polls.lock().unwrap();
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())
}
@@ -95,7 +95,7 @@ impl EthFilter for EthFilterClient where
let pending_transactions = take_weak!(self.miner).pending_transactions_hashes();
let id = polls.create_poll(PollFilter::PendingTransaction(pending_transactions));
- to_value(&U256::from(id))
+ to_value(&RpcU256::from(id))
},
_ => Err(Error::invalid_params())
}
@@ -116,7 +116,8 @@ impl EthFilter for EthFilterClient where
let hashes = (*block_number..current_number).into_iter()
.map(BlockID::Number)
.filter_map(|id| client.block_hash(id))
- .collect::>();
+ .map(Into::into)
+ .collect::>();
*block_number = current_number;
@@ -135,7 +136,8 @@ impl EthFilter for EthFilterClient where
.iter()
.filter(|hash| !previous_hashes_set.contains(hash))
.cloned()
- .collect::>()
+ .map(Into::into)
+ .collect::>()
};
// save all hashes of pending transactions
diff --git a/rpc/src/v1/impls/eth_signing.rs b/rpc/src/v1/impls/eth_signing.rs
index 6dd01bdf1..4ba076358 100644
--- a/rpc/src/v1/impls/eth_signing.rs
+++ b/rpc/src/v1/impls/eth_signing.rs
@@ -20,17 +20,17 @@ use std::sync::{Arc, Weak};
use jsonrpc_core::*;
use ethcore::miner::MinerService;
use ethcore::client::MiningBlockChainClient;
-use util::numbers::*;
+use util::{U256, Address, H256};
use ethcore::account_provider::AccountProvider;
-use v1::helpers::{SigningQueue, ConfirmationsQueue};
+use v1::helpers::{SigningQueue, ConfirmationsQueue, TransactionRequest as TRequest};
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};
-fn fill_optional_fields(request: &mut TransactionRequest, client: &C, miner: &M)
+fn fill_optional_fields(request: &mut TRequest, client: &C, miner: &M)
where C: MiningBlockChainClient, M: MinerService {
if request.value.is_none() {
- request.value = Some(U256::zero());
+ request.value = Some(U256::from(0));
}
if request.gas.is_none() {
request.gas = Some(miner.sensible_gas_limit());
@@ -39,7 +39,7 @@ fn fill_optional_fields(request: &mut TransactionRequest, client: &C, mine
request.gas_price = Some(default_gas_price(client, miner));
}
if request.data.is_none() {
- request.data = Some(Bytes::new(Vec::new()));
+ request.data = Some(Vec::new());
}
}
@@ -83,7 +83,8 @@ impl EthSigning for EthSigningQueueClient
fn send_transaction(&self, params: Params) -> Result {
try!(self.active());
from_params::<(TransactionRequest, )>(params)
- .and_then(|(mut request, )| {
+ .and_then(|(request, )| {
+ let mut request: TRequest = request.into();
let accounts = take_weak!(self.accounts);
let (client, miner) = (take_weak!(self.client), take_weak!(self.miner));
@@ -91,7 +92,7 @@ impl EthSigning for EthSigningQueueClient
let sender = request.from;
return match sign_and_dispatch(&*client, &*miner, request, &*accounts, sender) {
Ok(hash) => to_value(&hash),
- _ => to_value(&H256::zero()),
+ _ => to_value(&RpcH256::default()),
}
}
@@ -99,7 +100,7 @@ impl EthSigning for EthSigningQueueClient
fill_optional_fields(&mut request, &*client, &*miner);
let id = queue.add_request(request);
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 EthSigning for EthSigningUnsafeClient where
fn sign(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(Address, H256)>(params).and_then(|(addr, msg)| {
- to_value(&take_weak!(self.accounts).sign(addr, msg).unwrap_or(H520::zero()))
+ from_params::<(RpcH160, RpcH256)>(params).and_then(|(address, msg)| {
+ 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 EthSigning for EthSigningUnsafeClient where
try!(self.active());
from_params::<(TransactionRequest, )>(params)
.and_then(|(request, )| {
+ let request: TRequest = request.into();
let sender = request.from;
match sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), request, &*take_weak!(self.accounts), sender) {
Ok(hash) => to_value(&hash),
- _ => to_value(&H256::zero()),
+ _ => to_value(&RpcH256::default()),
}
})
}
diff --git a/rpc/src/v1/impls/ethcore.rs b/rpc/src/v1/impls/ethcore.rs
index fe2313c30..b62e21b0c 100644
--- a/rpc/src/v1/impls/ethcore.rs
+++ b/rpc/src/v1/impls/ethcore.rs
@@ -25,7 +25,7 @@ use ethcore::client::{MiningBlockChainClient};
use jsonrpc_core::*;
use ethcore::miner::MinerService;
use v1::traits::Ethcore;
-use v1::types::{Bytes};
+use v1::types::{Bytes, U256};
use v1::helpers::{SigningQueue, ConfirmationsQueue};
use v1::impls::error_codes;
@@ -69,7 +69,7 @@ impl Ethcore for EthcoreClient where M: MinerService + 'static, C: M
fn min_gas_price(&self, _: Params) -> Result {
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 {
@@ -79,12 +79,12 @@ impl Ethcore for EthcoreClient where M: MinerService + 'static, C: M
fn gas_floor_target(&self, _: Params) -> Result {
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 {
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 {
@@ -140,8 +140,8 @@ impl Ethcore for EthcoreClient where M: MinerService + 'static, C: M
match params {
Params::None => match take_weak!(self.client).gas_price_statistics(100, 8) {
Ok(stats) => to_value(&stats
- .iter()
- .map(|x| to_value(&x).expect("x must be U256; qed"))
+ .into_iter()
+ .map(|x| to_value(&U256::from(x)).expect("x must be U256; qed"))
.collect::>()),
_ => Err(Error::internal_error()),
},
diff --git a/rpc/src/v1/impls/ethcore_set.rs b/rpc/src/v1/impls/ethcore_set.rs
index 1a41509f7..1b8dd474e 100644
--- a/rpc/src/v1/impls/ethcore_set.rs
+++ b/rpc/src/v1/impls/ethcore_set.rs
@@ -15,15 +15,14 @@
// along with Parity. If not, see .
/// Ethcore-specific rpc interface for operations altering the settings.
-use util::{U256, Address};
-use util::network::{NetworkService, NonReservedPeerMode};
use std::sync::{Arc, Weak};
use jsonrpc_core::*;
use ethcore::miner::MinerService;
use ethcore::client::MiningBlockChainClient;
use ethcore::service::SyncMessage;
+use util::network::{NetworkService, NonReservedPeerMode};
use v1::traits::EthcoreSet;
-use v1::types::Bytes;
+use v1::types::{Bytes, H160, U256};
/// Ethcore-specific rpc interface for operations altering the settings.
pub struct EthcoreSetClient where
@@ -61,7 +60,7 @@ impl EthcoreSet for EthcoreSetClient where
fn set_min_gas_price(&self, params: Params) -> Result {
try!(self.active());
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)
})
}
@@ -69,7 +68,7 @@ impl EthcoreSet for EthcoreSetClient where
fn set_gas_floor_target(&self, params: Params) -> Result {
try!(self.active());
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)
})
}
@@ -77,7 +76,7 @@ impl EthcoreSet for EthcoreSetClient where
fn set_gas_ceil_target(&self, params: Params) -> Result {
try!(self.active());
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)
})
}
@@ -92,8 +91,8 @@ impl EthcoreSet for EthcoreSetClient where
fn set_author(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(Address,)>(params).and_then(|(author,)| {
- take_weak!(self.miner).set_author(author);
+ from_params::<(H160,)>(params).and_then(|(author,)| {
+ take_weak!(self.miner).set_author(author.into());
to_value(&true)
})
}
diff --git a/rpc/src/v1/impls/mod.rs b/rpc/src/v1/impls/mod.rs
index 1a6b1c398..d64619527 100644
--- a/rpc/src/v1/impls/mod.rs
+++ b/rpc/src/v1/impls/mod.rs
@@ -53,7 +53,8 @@ pub use self::ethcore_set::EthcoreSetClient;
pub use self::traces::TracesClient;
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::miner::{AccountDetails, MinerService};
use ethcore::client::MiningBlockChainClient;
@@ -77,7 +78,7 @@ mod error_codes {
fn dispatch_transaction(client: &C, miner: &M, signed_transaction: SignedTransaction) -> Result
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| {
AccountDetails {
diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs
index 94636ae99..d6286afb9 100644
--- a/rpc/src/v1/impls/personal.rs
+++ b/rpc/src/v1/impls/personal.rs
@@ -18,10 +18,11 @@
use std::sync::{Arc, Weak};
use jsonrpc_core::*;
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::helpers::{TransactionRequest as TRequest};
use ethcore::account_provider::AccountProvider;
-use util::numbers::*;
+use util::Address;
use ethcore::client::MiningBlockChainClient;
use ethcore::miner::MinerService;
@@ -63,7 +64,7 @@ impl Personal for PersonalClient where C: MiningBl
fn accounts(&self, _: Params) -> Result {
try!(self.active());
let store = take_weak!(self.accounts);
- to_value(&store.accounts())
+ to_value(&store.accounts().into_iter().map(Into::into).collect::>())
}
fn new_account(&self, params: Params) -> Result {
@@ -72,7 +73,7 @@ impl Personal for PersonalClient where C: MiningBl
|(pass, )| {
let store = take_weak!(self.accounts);
match store.new_account(&pass) {
- Ok(address) => to_value(&address),
+ Ok(address) => to_value(&RpcH160::from(address)),
Err(_) => Err(Error::internal_error())
}
}
@@ -81,8 +82,9 @@ impl Personal for PersonalClient where C: MiningBl
fn unlock_account(&self, params: Params) -> Result {
try!(self.active());
- from_params::<(Address, String, u64)>(params).and_then(
+ from_params::<(RpcH160, String, u64)>(params).and_then(
|(account, account_pass, _)|{
+ let account: Address = account.into();
let store = take_weak!(self.accounts);
match store.unlock_account_temporarily(account, account_pass) {
Ok(_) => Ok(Value::Bool(true)),
@@ -95,12 +97,13 @@ impl Personal for PersonalClient where C: MiningBl
try!(self.active());
from_params::<(TransactionRequest, String)>(params)
.and_then(|(request, password)| {
+ let request: TRequest = request.into();
let sender = request.from;
let accounts = take_weak!(self.accounts);
match unlock_sign_and_dispatch(&*take_weak!(self.client), &*take_weak!(self.miner), request, &*accounts, sender, password) {
- Ok(hash) => to_value(&hash),
- _ => to_value(&H256::zero()),
+ Ok(hash) => Ok(hash),
+ _ => to_value(&RpcH256::default()),
}
})
}
diff --git a/rpc/src/v1/impls/personal_signer.rs b/rpc/src/v1/impls/personal_signer.rs
index 97749657e..a31a3820f 100644
--- a/rpc/src/v1/impls/personal_signer.rs
+++ b/rpc/src/v1/impls/personal_signer.rs
@@ -18,14 +18,13 @@
use std::sync::{Arc, Weak};
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 util::numbers::*;
use ethcore::client::MiningBlockChainClient;
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.
pub struct SignerClient where C: MiningBlockChainClient, M: MinerService {
@@ -59,13 +58,14 @@ impl PersonalSigner for SignerClient where C: Mini
fn transactions_to_confirm(&self, _params: Params) -> Result {
try!(self.active());
let queue = take_weak!(self.queue);
- to_value(&queue.requests())
+ to_value(&queue.requests().into_iter().map(From::from).collect::>())
}
fn confirm_transaction(&self, params: Params) -> Result {
try!(self.active());
from_params::<(U256, TransactionModification, String)>(params).and_then(
|(id, modification, pass)| {
+ let id = id.into();
let accounts = take_weak!(self.accounts);
let queue = take_weak!(self.queue);
let client = take_weak!(self.client);
@@ -74,7 +74,7 @@ impl PersonalSigner for SignerClient where C: Mini
let mut request = confirmation.transaction;
// apply modification
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;
@@ -99,7 +99,7 @@ impl PersonalSigner for SignerClient where C: Mini
from_params::<(U256, )>(params).and_then(
|(id, )| {
let queue = take_weak!(self.queue);
- let res = queue.request_rejected(id);
+ let res = queue.request_rejected(id.into());
to_value(&res.is_some())
}
)
diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs
index 45daa2500..71176df27 100644
--- a/rpc/src/v1/impls/traces.rs
+++ b/rpc/src/v1/impls/traces.rs
@@ -19,12 +19,13 @@
use std::sync::{Weak, Arc};
use jsonrpc_core::*;
use std::collections::BTreeMap;
-use util::H256;
+//use util::H256;
use ethcore::client::{BlockChainClient, CallAnalytics, TransactionID, TraceId};
use ethcore::miner::MinerService;
use ethcore::transaction::{Transaction as EthTransaction, SignedTransaction, Action};
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.
pub struct TracesClient where C: BlockChainClient, M: MinerService {
@@ -42,7 +43,7 @@ impl TracesClient where C: BlockChainClient, M: MinerService {
}
// TODO: share with eth.rs
- fn sign_call(&self, request: CallRequest) -> Result {
+ fn sign_call(&self, request: CRequest) -> Result {
let client = take_weak!(self.client);
let miner = take_weak!(self.miner);
let from = request.from.unwrap_or(0.into());
@@ -91,7 +92,7 @@ impl Traces for TracesClient where C: BlockChainClient + 'static, M:
from_params::<(H256,)>(params)
.and_then(|(transaction_hash,)| {
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());
to_value(&traces)
})
@@ -103,7 +104,7 @@ impl Traces for TracesClient where C: BlockChainClient + 'static, M:
.and_then(|(transaction_hash, address)| {
let client = take_weak!(self.client);
let id = TraceId {
- transaction: TransactionID::Hash(transaction_hash),
+ transaction: TransactionID::Hash(transaction_hash.into()),
address: address.into_iter().map(|i| i.value()).collect()
};
let trace = client.trace(id);
@@ -117,6 +118,7 @@ impl Traces for TracesClient where C: BlockChainClient + 'static, M:
trace!(target: "jsonrpc", "call: {:?}", params);
from_params(params)
.and_then(|(request, flags)| {
+ let request = CallRequest::into(request);
let flags: Vec = flags;
let analytics = CallAnalytics {
transaction_tracing: flags.contains(&("trace".to_owned())),
diff --git a/rpc/src/v1/impls/web3.rs b/rpc/src/v1/impls/web3.rs
index 87343a18a..3f993f21c 100644
--- a/rpc/src/v1/impls/web3.rs
+++ b/rpc/src/v1/impls/web3.rs
@@ -18,7 +18,7 @@
use jsonrpc_core::*;
use util::version;
use v1::traits::Web3;
-use v1::types::Bytes;
+use v1::types::{H256, Bytes};
use util::sha3::Hashable;
/// Web3 rpc implementation.
@@ -40,9 +40,9 @@ impl Web3 for Web3Client {
fn sha3(&self, params: Params) -> Result {
from_params::<(Bytes,)>(params).and_then(
|(data,)| {
- let Bytes(ref v) = data;
- let sha3 = v.sha3();
- to_value(&sha3)
+ let Bytes(ref vec) = data;
+ let sha3 = vec.sha3();
+ to_value(&H256::from(sha3))
}
)
}
diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs
index 2965a62d2..739c91b17 100644
--- a/rpc/src/v1/tests/eth.rs
+++ b/rpc/src/v1/tests/eth.rs
@@ -34,6 +34,7 @@ use util::{U256, H256, Uint};
use jsonrpc_core::IoHandler;
use ethjson::blockchain::BlockChain;
+use v1::types::U256 as NU256;
use v1::traits::eth::{Eth, EthSigning};
use v1::impls::{EthClient, EthSigningUnsafeClient};
use v1::tests::helpers::{TestSyncProvider, Config};
@@ -330,7 +331,7 @@ fn verify_transaction_counts(name: String, chain: BlockChain) {
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByNumber",
"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#"
}"#;
diff --git a/rpc/src/v1/tests/mocked/personal_signer.rs b/rpc/src/v1/tests/mocked/personal_signer.rs
index 6fa734cec..b2ef694a1 100644
--- a/rpc/src/v1/tests/mocked/personal_signer.rs
+++ b/rpc/src/v1/tests/mocked/personal_signer.rs
@@ -23,9 +23,7 @@ use ethcore::client::TestBlockChainClient;
use ethcore::transaction::{Transaction, Action};
use v1::{SignerClient, PersonalSigner};
use v1::tests::helpers::TestMinerService;
-use v1::helpers::{SigningQueue, ConfirmationsQueue};
-use v1::types::TransactionRequest;
-
+use v1::helpers::{SigningQueue, ConfirmationsQueue, TransactionRequest};
struct PersonalSignerTester {
queue: Arc,
diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs
index b86723357..63f596d4a 100644
--- a/rpc/src/v1/types/block.rs
+++ b/rpc/src/v1/types/block.rs
@@ -15,8 +15,7 @@
// along with Parity. If not, see .
use serde::{Serialize, Serializer};
-use util::numbers::*;
-use v1::types::{Bytes, Transaction, OptionalValue};
+use v1::types::{Bytes, Transaction, H160, H256, H2048, U256};
/// Block Transactions
#[derive(Debug)]
@@ -41,7 +40,7 @@ impl Serialize for BlockTransactions {
#[derive(Debug, Serialize)]
pub struct Block {
/// Hash of the block
- pub hash: OptionalValue,
+ pub hash: Option,
/// Hash of the parent
#[serde(rename="parentHash")]
pub parent_hash: H256,
@@ -49,10 +48,10 @@ pub struct Block {
#[serde(rename="sha3Uncles")]
pub uncles_hash: H256,
/// Authors address
- pub author: Address,
+ pub author: H160,
// TODO: get rid of this one
/// ?
- pub miner: Address,
+ pub miner: H160,
/// State root hash
#[serde(rename="stateRoot")]
pub state_root: H256,
@@ -63,7 +62,7 @@ pub struct Block {
#[serde(rename="receiptsRoot")]
pub receipts_root: H256,
/// Block number
- pub number: OptionalValue,
+ pub number: Option,
/// Gas Used
#[serde(rename="gasUsed")]
pub gas_used: U256,
@@ -95,9 +94,8 @@ pub struct Block {
#[cfg(test)]
mod tests {
use serde_json;
- use util::numbers::*;
- use v1::types::{Transaction, Bytes, OptionalValue};
- use super::*;
+ use v1::types::{Transaction, H160, H256, H2048, Bytes, U256};
+ use super::{Block, BlockTransactions};
#[test]
fn test_serialize_block_transactions() {
@@ -105,7 +103,7 @@ mod tests {
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}]"#);
- let t = BlockTransactions::Hashes(vec![H256::default()]);
+ let t = BlockTransactions::Hashes(vec![H256::default().into()]);
let serialized = serde_json::to_string(&t).unwrap();
assert_eq!(serialized, r#"["0x0000000000000000000000000000000000000000000000000000000000000000"]"#);
}
@@ -113,15 +111,15 @@ mod tests {
#[test]
fn test_serialize_block() {
let block = Block {
- hash: OptionalValue::Value(H256::default()),
+ hash: Some(H256::default()),
parent_hash: H256::default(),
uncles_hash: H256::default(),
- author: Address::default(),
- miner: Address::default(),
+ author: H160::default(),
+ miner: H160::default(),
state_root: H256::default(),
transactions_root: H256::default(),
receipts_root: H256::default(),
- number: OptionalValue::Value(U256::default()),
+ number: Some(U256::default()),
gas_used: U256::default(),
gas_limit: U256::default(),
extra_data: Bytes::default(),
@@ -131,7 +129,7 @@ mod tests {
total_difficulty: U256::default(),
seal_fields: vec![Bytes::default(), Bytes::default()],
uncles: vec![],
- transactions: BlockTransactions::Hashes(vec![])
+ transactions: BlockTransactions::Hashes(vec![].into())
};
let serialized = serde_json::to_string(&block).unwrap();
diff --git a/rpc/src/v1/types/bytes.rs b/rpc/src/v1/types/bytes.rs
index 1bf5deb75..09c899057 100644
--- a/rpc/src/v1/types/bytes.rs
+++ b/rpc/src/v1/types/bytes.rs
@@ -42,6 +42,12 @@ impl From> for Bytes {
}
}
+impl Into> for Bytes {
+ fn into(self) -> Vec {
+ self.0
+ }
+}
+
impl Serialize for Bytes {
fn serialize(&self, serializer: &mut S) -> Result<(), S::Error>
where S: Serializer {
diff --git a/rpc/src/v1/types/call_request.rs b/rpc/src/v1/types/call_request.rs
index 50ebbd1f0..38721e2f8 100644
--- a/rpc/src/v1/types/call_request.rs
+++ b/rpc/src/v1/types/call_request.rs
@@ -14,17 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see .
-use util::hash::Address;
-use util::numbers::U256;
-use v1::types::Bytes;
+use v1::helpers::CallRequest as Request;
+use v1::types::{Bytes, H160, U256};
/// Call request
#[derive(Debug, Default, PartialEq, Deserialize)]
pub struct CallRequest {
/// From
- pub from: Option,
+ pub from: Option,
/// To
- pub to: Option,
+ pub to: Option,
/// Gas Price
#[serde(rename="gasPrice")]
pub gas_price: Option,
@@ -38,18 +37,30 @@ pub struct CallRequest {
pub nonce: Option,
}
+impl Into 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)]
mod tests {
use std::str::FromStr;
use rustc_serialize::hex::FromHex;
use serde_json;
- use util::numbers::{U256};
- use util::hash::Address;
- use v1::types::Bytes;
- use super::*;
+ use v1::types::{U256, H160};
+ use super::CallRequest;
#[test]
- fn transaction_request_deserialize() {
+ fn call_request_deserialize() {
let s = r#"{
"from":"0x0000000000000000000000000000000000000001",
"to":"0x0000000000000000000000000000000000000002",
@@ -62,18 +73,18 @@ mod tests {
let deserialized: CallRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, CallRequest {
- from: Some(Address::from(1)),
- to: Some(Address::from(2)),
+ from: Some(H160::from(1)),
+ to: Some(H160::from(2)),
gas_price: Some(U256::from(1)),
gas: Some(U256::from(2)),
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)),
});
}
#[test]
- fn transaction_request_deserialize2() {
+ fn call_request_deserialize2() {
let s = r#"{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
@@ -85,23 +96,23 @@ mod tests {
let deserialized: CallRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, CallRequest {
- from: Some(Address::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap()),
- to: Some(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
+ from: Some(H160::from_str("b60e8dd61c5d32be8058bb8eb970870f07233155").unwrap()),
+ to: Some(H160::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()),
gas_price: Some(U256::from_str("9184e72a000").unwrap()),
gas: Some(U256::from_str("76c0").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
});
}
#[test]
- fn transaction_request_deserialize_empty() {
+ fn call_request_deserialize_empty() {
let s = r#"{"from":"0x0000000000000000000000000000000000000001"}"#;
let deserialized: CallRequest = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, CallRequest {
- from: Some(Address::from(1)),
+ from: Some(H160::from(1)),
to: None,
gas_price: None,
gas: None,
diff --git a/rpc/src/v1/types/filter.rs b/rpc/src/v1/types/filter.rs
index 77a3f0500..a34bb9ae9 100644
--- a/rpc/src/v1/types/filter.rs
+++ b/rpc/src/v1/types/filter.rs
@@ -17,10 +17,9 @@
use serde::{Deserialize, Deserializer, Error};
use serde_json::value;
use jsonrpc_core::Value;
-use util::numbers::*;
-use v1::types::BlockNumber;
use ethcore::filter::Filter as EthFilter;
use ethcore::client::BlockID;
+use v1::types::{BlockNumber, H160, H256};
/// Variadic value
#[derive(Debug, PartialEq, Clone)]
@@ -49,7 +48,7 @@ impl Deserialize for VariadicValue where T: Deserialize {
}
/// Filter Address
-pub type FilterAddress = VariadicValue;
+pub type FilterAddress = VariadicValue;
/// Topic
pub type Topic = VariadicValue;
@@ -76,14 +75,14 @@ impl Into for Filter {
to_block: self.to_block.map_or_else(|| BlockID::Latest, Into::into),
address: self.address.and_then(|address| match address {
VariadicValue::Null => None,
- VariadicValue::Single(a) => Some(vec![a]),
- VariadicValue::Multiple(a) => Some(a)
+ VariadicValue::Single(a) => Some(vec![a.into()]),
+ VariadicValue::Multiple(a) => Some(a.into_iter().map(Into::into).collect())
}),
topics: {
let mut iter = self.topics.map_or_else(Vec::new, |topics| topics.into_iter().take(4).map(|topic| match topic {
VariadicValue::Null => None,
- VariadicValue::Single(t) => Some(vec![t]),
- VariadicValue::Multiple(t) => Some(t)
+ VariadicValue::Single(t) => Some(vec![t.into()]),
+ VariadicValue::Multiple(t) => Some(t.into_iter().map(Into::into).collect())
}).filter_map(|m| m).collect()).into_iter();
[iter.next(), iter.next(), iter.next(), iter.next()]
}
@@ -104,11 +103,11 @@ mod tests {
let s = r#"["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null, ["0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"]]"#;
let deserialized: Vec = serde_json::from_str(s).unwrap();
assert_eq!(deserialized, vec![
- VariadicValue::Single(H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap()),
+ VariadicValue::Single(H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap().into()),
VariadicValue::Null,
VariadicValue::Multiple(vec![
- H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap(),
- H256::from_str("0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc").unwrap()
+ H256::from_str("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b").unwrap().into(),
+ H256::from_str("0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc").unwrap().into(),
])
]);
}
diff --git a/rpc/src/v1/types/hash.rs b/rpc/src/v1/types/hash.rs
new file mode 100644
index 000000000..f0606ed51
--- /dev/null
+++ b/rpc/src/v1/types/hash.rs
@@ -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 .
+
+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 From for $name where $other: From {
+ 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 {
+ $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 {
+ 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(&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(&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(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(&mut self, value: &str) -> Result 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(&mut self, value: String) -> Result 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);
diff --git a/rpc/src/v1/types/log.rs b/rpc/src/v1/types/log.rs
index 72a482d1b..9d9261d94 100644
--- a/rpc/src/v1/types/log.rs
+++ b/rpc/src/v1/types/log.rs
@@ -14,15 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see .
-use util::numbers::*;
use ethcore::log_entry::{LocalizedLogEntry, LogEntry};
-use v1::types::Bytes;
+use v1::types::{Bytes, H160, H256, U256};
/// Log
#[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)]
pub struct Log {
- /// Address
- pub address: Address,
+ /// H160
+ pub address: H160,
/// Topics
pub topics: Vec,
/// Data
@@ -50,14 +49,14 @@ pub struct Log {
impl From for Log {
fn from(e: LocalizedLogEntry) -> Log {
Log {
- address: e.entry.address,
- topics: e.entry.topics,
- data: Bytes::new(e.entry.data),
- block_hash: Some(e.block_hash),
- block_number: Some(From::from(e.block_number)),
- transaction_hash: Some(e.transaction_hash),
- transaction_index: Some(From::from(e.transaction_index)),
- log_index: Some(From::from(e.log_index)),
+ address: e.entry.address.into(),
+ topics: e.entry.topics.into_iter().map(Into::into).collect(),
+ data: e.entry.data.into(),
+ block_hash: Some(e.block_hash.into()),
+ block_number: Some(e.block_number.into()),
+ transaction_hash: Some(e.transaction_hash.into()),
+ transaction_index: Some(e.transaction_index.into()),
+ log_index: Some(e.log_index.into()),
log_type: "mined".to_owned(),
}
}
@@ -66,9 +65,9 @@ impl From for Log {
impl From for Log {
fn from(e: LogEntry) -> Log {
Log {
- address: e.address,
- topics: e.topics,
- data: Bytes::new(e.data),
+ address: e.address.into(),
+ topics: e.topics.into_iter().map(Into::into).collect(),
+ data: e.data.into(),
block_hash: None,
block_number: None,
transaction_hash: None,
@@ -83,25 +82,24 @@ impl From for Log {
mod tests {
use serde_json;
use std::str::FromStr;
- use util::numbers::*;
- use v1::types::{Bytes, Log};
+ use v1::types::{Log, H160, H256, U256};
#[test]
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 log = Log {
- address: Address::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(),
+ address: H160::from_str("33990122638b9132ca29c723bdf037f1a891a70c").unwrap(),
topics: vec![
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_number: Some(U256::from(0x4510c)),
- transaction_hash: Some(H256::new()),
- transaction_index: Some(U256::zero()),
- log_index: Some(U256::one()),
+ transaction_hash: Some(H256::default()),
+ transaction_index: Some(U256::default()),
+ log_index: Some(U256::from(1)),
log_type: "mined".to_owned(),
};
diff --git a/rpc/src/v1/types/mod.rs.in b/rpc/src/v1/types/mod.rs.in
index 3f07bfb31..ecbe6d9a0 100644
--- a/rpc/src/v1/types/mod.rs.in
+++ b/rpc/src/v1/types/mod.rs.in
@@ -18,9 +18,9 @@ mod bytes;
mod block;
mod block_number;
mod filter;
+mod hash;
mod index;
mod log;
-mod optionals;
mod sync;
mod transaction;
mod transaction_request;
@@ -28,14 +28,15 @@ mod call_request;
mod receipt;
mod trace;
mod trace_filter;
+mod uint;
pub use self::bytes::Bytes;
pub use self::block::{Block, BlockTransactions};
pub use self::block_number::BlockNumber;
pub use self::filter::Filter;
+pub use self::hash::{H64, H160, H256, H520, H2048};
pub use self::index::Index;
pub use self::log::Log;
-pub use self::optionals::OptionalValue;
pub use self::sync::{SyncStatus, SyncInfo};
pub use self::transaction::Transaction;
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::trace::{Trace, LocalizedTrace, StateDiff, VMTrace};
pub use self::trace_filter::TraceFilter;
+pub use self::uint::U256;
diff --git a/rpc/src/v1/types/optionals.rs b/rpc/src/v1/types/optionals.rs
deleted file mode 100644
index 5f62dc4a0..000000000
--- a/rpc/src/v1/types/optionals.rs
+++ /dev/null
@@ -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 .
-
-use serde::{Serialize, Serializer, Deserialize, Deserializer};
-use serde_json::Value;
-
-/// Optional value
-#[derive(Debug)]
-pub enum OptionalValue where T: Serialize {
- /// Some
- Value(T),
- /// None
- Null
-}
-
-impl Default for OptionalValue where T: Serialize + Deserialize {
- fn default() -> Self {
- OptionalValue::Null
- }
-}
-
-impl Into