From acc0545917ae18f431b6c6176a143871b101f765 Mon Sep 17 00:00:00 2001 From: niklasad1 Date: Fri, 18 Jan 2019 22:50:23 +0100 Subject: [PATCH 01/13] fix(rpc-types): remove uint and hash wrappers --- Cargo.lock | 3 + cli-signer/Cargo.toml | 1 + cli-signer/rpc-client/Cargo.toml | 1 + cli-signer/rpc-client/src/lib.rs | 1 + cli-signer/rpc-client/src/signer_client.rs | 3 +- cli-signer/src/lib.rs | 4 +- rpc/Cargo.toml | 1 + rpc/src/lib.rs | 1 + .../helpers/external_signer/signing_queue.rs | 15 +- rpc/src/v1/helpers/secretstore.rs | 3 +- rpc/src/v1/helpers/signature.rs | 12 +- rpc/src/v1/helpers/subscribers.rs | 2 +- rpc/src/v1/helpers/work.rs | 9 +- rpc/src/v1/impls/eth.rs | 77 ++++---- rpc/src/v1/impls/eth_filter.rs | 12 +- rpc/src/v1/impls/light/eth.rs | 71 ++++---- rpc/src/v1/impls/light/parity.rs | 5 +- rpc/src/v1/impls/light/parity_set.rs | 5 +- rpc/src/v1/impls/light/trace.rs | 4 +- rpc/src/v1/impls/parity.rs | 7 +- rpc/src/v1/impls/parity_accounts.rs | 61 +++---- rpc/src/v1/impls/parity_set.rs | 4 +- rpc/src/v1/impls/personal.rs | 36 ++-- rpc/src/v1/impls/private.rs | 4 +- rpc/src/v1/impls/secretstore.rs | 5 +- rpc/src/v1/impls/signer.rs | 3 +- rpc/src/v1/impls/signing.rs | 23 +-- rpc/src/v1/impls/signing_unsafe.rs | 21 +-- rpc/src/v1/impls/traces.rs | 4 +- rpc/src/v1/impls/web3.rs | 3 +- rpc/src/v1/tests/eth.rs | 5 +- rpc/src/v1/tests/mocked/personal.rs | 4 +- rpc/src/v1/tests/mocked/secretstore.rs | 3 +- rpc/src/v1/tests/mocked/signer.rs | 4 +- rpc/src/v1/traits/eth.rs | 3 +- rpc/src/v1/traits/eth_signing.rs | 3 +- rpc/src/v1/traits/parity.rs | 3 +- rpc/src/v1/traits/parity_accounts.rs | 3 +- rpc/src/v1/traits/parity_set.rs | 3 +- rpc/src/v1/traits/parity_signing.rs | 3 +- rpc/src/v1/traits/personal.rs | 4 +- rpc/src/v1/traits/private.rs | 3 +- rpc/src/v1/traits/secretstore.rs | 5 +- rpc/src/v1/traits/signer.rs | 4 +- rpc/src/v1/traits/traces.rs | 4 +- rpc/src/v1/traits/web3.rs | 3 +- rpc/src/v1/types/account_info.rs | 4 +- rpc/src/v1/types/block.rs | 8 +- rpc/src/v1/types/call_request.rs | 5 +- rpc/src/v1/types/confirmations.rs | 6 +- rpc/src/v1/types/consensus_status.rs | 2 +- rpc/src/v1/types/derivation.rs | 3 +- rpc/src/v1/types/eip191.rs | 4 +- rpc/src/v1/types/filter.rs | 3 +- rpc/src/v1/types/hash.rs | 165 ------------------ rpc/src/v1/types/histogram.rs | 2 +- rpc/src/v1/types/log.rs | 6 +- rpc/src/v1/types/mod.rs | 5 +- rpc/src/v1/types/private_receipt.rs | 3 +- rpc/src/v1/types/provenance.rs | 2 +- rpc/src/v1/types/pubsub.rs | 3 +- rpc/src/v1/types/receipt.rs | 4 +- rpc/src/v1/types/secretstore.rs | 5 +- rpc/src/v1/types/sync.rs | 3 +- rpc/src/v1/types/trace.rs | 8 +- rpc/src/v1/types/trace_filter.rs | 3 +- rpc/src/v1/types/transaction.rs | 3 +- rpc/src/v1/types/transaction_request.rs | 6 +- rpc/src/v1/types/work.rs | 2 +- 69 files changed, 283 insertions(+), 430 deletions(-) delete mode 100644 rpc/src/v1/types/hash.rs diff --git a/Cargo.lock b/Cargo.lock index f67f3b610c4..7e80bf393ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,6 +261,7 @@ dependencies = [ name = "cli-signer" version = "1.4.0" dependencies = [ + "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc 1.12.0", "parity-rpc-client 1.4.0", @@ -2641,6 +2642,7 @@ dependencies = [ "common-types 0.1.0", "eip-712 0.1.0", "ethash 1.12.0", + "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-accounts 0.1.0", "ethcore-io 1.12.0", @@ -2699,6 +2701,7 @@ dependencies = [ name = "parity-rpc-client" version = "1.4.0" dependencies = [ + "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-ws-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/cli-signer/Cargo.toml b/cli-signer/Cargo.toml index f4fa86d9450..11dd06107e2 100644 --- a/cli-signer/Cargo.toml +++ b/cli-signer/Cargo.toml @@ -7,6 +7,7 @@ name = "cli-signer" version = "1.4.0" [dependencies] +ethereum-types = "0.4" futures = "0.1" rpassword = "1.0" parity-rpc = { path = "../rpc" } diff --git a/cli-signer/rpc-client/Cargo.toml b/cli-signer/rpc-client/Cargo.toml index e7eb354618a..53ec983391e 100644 --- a/cli-signer/rpc-client/Cargo.toml +++ b/cli-signer/rpc-client/Cargo.toml @@ -7,6 +7,7 @@ name = "parity-rpc-client" version = "1.4.0" [dependencies] +ethereum-types = "0.4" futures = "0.1" log = "0.4" serde = "1.0" diff --git a/cli-signer/rpc-client/src/lib.rs b/cli-signer/rpc-client/src/lib.rs index df7936eaeed..d0e087e59d9 100644 --- a/cli-signer/rpc-client/src/lib.rs +++ b/cli-signer/rpc-client/src/lib.rs @@ -17,6 +17,7 @@ pub mod client; pub mod signer_client; +extern crate ethereum_types; extern crate futures; extern crate jsonrpc_core; extern crate jsonrpc_ws_server as ws; diff --git a/cli-signer/rpc-client/src/signer_client.rs b/cli-signer/rpc-client/src/signer_client.rs index 339f43b6e33..997841936d1 100644 --- a/cli-signer/rpc-client/src/signer_client.rs +++ b/cli-signer/rpc-client/src/signer_client.rs @@ -15,7 +15,8 @@ // along with Parity Ethereum. If not, see . use client::{Rpc, RpcError}; -use rpc::signer::{ConfirmationRequest, TransactionModification, U256, TransactionCondition}; +use ethereum_types::U256; +use rpc::signer::{ConfirmationRequest, TransactionModification, TransactionCondition}; use serde; use serde_json::{Value as JsonValue, to_value}; use std::path::PathBuf; diff --git a/cli-signer/src/lib.rs b/cli-signer/src/lib.rs index f09d4403aa3..3ef6e70549b 100644 --- a/cli-signer/src/lib.rs +++ b/cli-signer/src/lib.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . +extern crate ethereum_types; extern crate futures; extern crate rpassword; extern crate parity_rpc as rpc; extern crate parity_rpc_client as client; -use rpc::signer::{U256, ConfirmationRequest}; +use ethereum_types::U256; +use rpc::signer::ConfirmationRequest; use client::signer_client::SignerRpc; use std::io::{Write, BufRead, BufReader, stdout, stdin}; use std::path::PathBuf; diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index c6c59dc15a4..2d4629dbfb2 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -45,6 +45,7 @@ ethcore-miner = { path = "../miner" } ethcore-network = { path = "../util/network" } ethcore-private-tx = { path = "../ethcore/private-tx" } ethcore-sync = { path = "../ethcore/sync" } +ethbloom = "0.5" ethereum-types = "0.4" fastmap = { path = "../util/fastmap" } parity-bytes = "0.1" diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 4a90fbe6939..d946364220f 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -48,6 +48,7 @@ extern crate ethcore; extern crate fastmap; extern crate parity_bytes as bytes; extern crate parity_crypto as crypto; +extern crate ethbloom; extern crate ethcore_io as io; extern crate ethcore_light as light; extern crate ethcore_logger; diff --git a/rpc/src/v1/helpers/external_signer/signing_queue.rs b/rpc/src/v1/helpers/external_signer/signing_queue.rs index 76405005295..abc5058ac8b 100644 --- a/rpc/src/v1/helpers/external_signer/signing_queue.rs +++ b/rpc/src/v1/helpers/external_signer/signing_queue.rs @@ -15,7 +15,8 @@ // along with Parity Ethereum. If not, see . use std::collections::BTreeMap; -use ethereum_types::U256; + +use ethereum_types::{H160, U256, Address}; use parking_lot::{Mutex, RwLock}; use super::oneshot; use v1::helpers::errors; @@ -27,6 +28,18 @@ use jsonrpc_core::Error; /// Result that can be returned from JSON RPC. pub type ConfirmationResult = Result; +/// Type of default account +pub enum DefaultAccount { + /// Default account is known + Provided(Address), +} + +impl From for DefaultAccount { + fn from(address: H160) -> Self { + DefaultAccount::Provided(address.into()) + } +} + /// Possible events happening in the queue that can be listened to. #[derive(Debug, PartialEq, Clone)] pub enum QueueEvent { diff --git a/rpc/src/v1/helpers/secretstore.rs b/rpc/src/v1/helpers/secretstore.rs index d8a60d592c3..6e1cbca45de 100644 --- a/rpc/src/v1/helpers/secretstore.rs +++ b/rpc/src/v1/helpers/secretstore.rs @@ -16,12 +16,13 @@ use std::collections::BTreeSet; use rand::{Rng, OsRng}; +use ethereum_types::{H256, H512}; use ethkey::{self, Public, Secret, Random, Generator, math}; use crypto; use bytes::Bytes; use jsonrpc_core::Error; use v1::helpers::errors; -use v1::types::{H256, H512, EncryptedDocumentKey}; +use v1::types::EncryptedDocumentKey; use tiny_keccak::Keccak; /// Initialization vector length. diff --git a/rpc/src/v1/helpers/signature.rs b/rpc/src/v1/helpers/signature.rs index b2bea2588f8..651320f0235 100644 --- a/rpc/src/v1/helpers/signature.rs +++ b/rpc/src/v1/helpers/signature.rs @@ -15,8 +15,9 @@ // along with Parity Ethereum. If not, see . use ethkey::{recover, public_to_address, Signature}; +use ethereum_types::H256; use jsonrpc_core::Result; -use v1::types::{Bytes, RecoveredAccount, H256, U64}; +use v1::types::{Bytes, RecoveredAccount}; use v1::helpers::errors; use v1::helpers::dispatch::eth_data_hash; use hash::keccak; @@ -27,7 +28,7 @@ pub fn verify_signature( message: Bytes, r: H256, s: H256, - v: U64, + v: u64, chain_id: Option ) -> Result { let hash = if is_prefixed { @@ -35,7 +36,6 @@ pub fn verify_signature( } else { keccak(message.0) }; - let v: u64 = v.into(); let is_valid_for_current_chain = match (chain_id, v) { (None, v) if v == 0 || v == 1 => true, (Some(chain_id), v) if v >= 35 => (v - 35) / 2 == chain_id, @@ -54,7 +54,7 @@ pub fn verify_signature( mod tests { use super::*; use ethkey::Generator; - use v1::types::H160; + use ethereum_types::{H160, U64}; pub fn add_chain_replay_protection(v: u64, chain_id: Option) -> u64 { v + if let Some(n) = chain_id { 35 + n * 2 } else { 0 } @@ -68,7 +68,7 @@ mod tests { } /// mocked signer - fn sign(should_prefix: bool, data: Vec, signing_chain_id: Option) -> (H160, [u8; 32], [u8; 32], U64) { + fn sign(should_prefix: bool, data: Vec, signing_chain_id: Option) -> (H160, [u8; 32], [u8; 32], u64) { let hash = if should_prefix { eth_data_hash(data) } else { keccak(data) }; let account = ethkey::Random.generate().unwrap(); let address = account.address(); @@ -81,7 +81,7 @@ mod tests { s_buf.copy_from_slice(s); (r_buf, s_buf) }; - (address.into(), r_buf, s_buf, v.into()) + (address.into(), r_buf, s_buf, v) } fn run_test(test_case: TestCase) { diff --git a/rpc/src/v1/helpers/subscribers.rs b/rpc/src/v1/helpers/subscribers.rs index 5b48b67a22e..0fce8892cfc 100644 --- a/rpc/src/v1/helpers/subscribers.rs +++ b/rpc/src/v1/helpers/subscribers.rs @@ -19,8 +19,8 @@ use std::{ops, str}; use std::collections::HashMap; use jsonrpc_pubsub::{typed::{Subscriber, Sink}, SubscriptionId}; +use ethereum_types::H64; use rand::{Rng, StdRng}; -use v1::types::H64; #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct Id(H64); diff --git a/rpc/src/v1/helpers/work.rs b/rpc/src/v1/helpers/work.rs index 0a90d446ee8..c4278db172b 100644 --- a/rpc/src/v1/helpers/work.rs +++ b/rpc/src/v1/helpers/work.rs @@ -20,17 +20,16 @@ use std::sync::Arc; use rlp; use ethcore::miner::{BlockChainClient, MinerService}; -use ethereum_types::{H64 as EthcoreH64, H256 as EthcoreH256}; +use ethereum_types::{H64, H256}; use jsonrpc_core::Error; -use v1::types::{H64, H256}; use v1::helpers::errors; // Submit a POW work and return the block's hash pub fn submit_work_detail(client: &Arc, miner: &Arc, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result { // TODO [ToDr] Should disallow submissions in case of PoA? - let nonce: EthcoreH64 = nonce.into(); - let pow_hash: EthcoreH256 = pow_hash.into(); - let mix_hash: EthcoreH256 = mix_hash.into(); + let nonce: H64 = nonce.into(); + let pow_hash: H256 = pow_hash.into(); + let mix_hash: H256 = mix_hash.into(); trace!(target: "miner", "submit_work_detail: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash); let seal = vec![rlp::encode(&mix_hash), rlp::encode(&nonce)]; let import = miner.submit_seal(pow_hash, seal) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 8d47b9b7b5a..1089415ea51 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -21,7 +21,7 @@ use std::time::{Instant, Duration, SystemTime, UNIX_EPOCH}; use std::sync::Arc; use rlp::Rlp; -use ethereum_types::{U256, H256, H160, Address}; +use ethereum_types::{Address, H64, H160, H256, U64, U256}; use parking_lot::Mutex; use ethash::{self, SeedHashCompute}; @@ -47,8 +47,7 @@ use v1::traits::Eth; use v1::types::{ RichBlock, Block, BlockTransactions, BlockNumber, Bytes, SyncStatus, SyncInfo, Transaction, CallRequest, Index, Filter, Log, Receipt, Work, EthAccount, StorageProof, - H64 as RpcH64, H256 as RpcH256, H160 as RpcH160, U256 as RpcU256, block_number_to_id, - U64 as RpcU64, + block_number_to_id }; use v1::metadata::Metadata; @@ -530,7 +529,7 @@ impl Eth for EthClient< } } - fn author(&self) -> Result { + fn author(&self) -> Result { let miner = self.miner.authoring_params().author; if miner == 0.into() { (self.accounts)() @@ -539,7 +538,7 @@ impl Eth for EthClient< .map(From::from) .ok_or_else(|| errors::account("No accounts were found", "")) } else { - Ok(RpcH160::from(miner)) + Ok(H160::from(miner)) } } @@ -547,30 +546,30 @@ impl Eth for EthClient< Ok(self.miner.is_currently_sealing()) } - fn chain_id(&self) -> Result> { - Ok(self.client.signing_chain_id().map(RpcU64::from)) + fn chain_id(&self) -> Result> { + Ok(self.client.signing_chain_id().map(U64::from)) } - fn hashrate(&self) -> Result { - Ok(RpcU256::from(self.external_miner.hashrate())) + fn hashrate(&self) -> Result { + Ok(U256::from(self.external_miner.hashrate())) } - fn gas_price(&self) -> Result { - Ok(RpcU256::from(default_gas_price(&*self.client, &*self.miner, self.options.gas_price_percentile))) + fn gas_price(&self) -> Result { + Ok(U256::from(default_gas_price(&*self.client, &*self.miner, self.options.gas_price_percentile))) } - fn accounts(&self) -> Result> { + fn accounts(&self) -> Result> { self.deprecation_notice.print("eth_accounts", deprecated::msgs::ACCOUNTS); let accounts = (self.accounts)(); Ok(accounts.into_iter().map(Into::into).collect()) } - fn block_number(&self) -> Result { - Ok(RpcU256::from(self.client.chain_info().best_block_number)) + fn block_number(&self) -> Result { + Ok(U256::from(self.client.chain_info().best_block_number)) } - fn balance(&self, address: RpcH160, num: Option) -> BoxFuture { + fn balance(&self, address: H160, num: Trailing) -> BoxFuture { let address = address.into(); let num = num.unwrap_or_default(); @@ -584,7 +583,7 @@ impl Eth for EthClient< Box::new(future::done(res)) } - fn proof(&self, address: RpcH160, values: Vec, num: Option) -> BoxFuture { + fn proof(&self, address: H160, values: Vec, num: Trailing) -> BoxFuture { try_bf!(errors::require_experimental(self.options.allow_experimental_rpcs, "1186")); let a: H160 = address.clone().into(); @@ -603,7 +602,7 @@ impl Eth for EthClient< try_bf!(check_known(&*self.client, num.clone())); let res = match self.client.prove_account(key1, id) { - Some((proof,account)) => Ok(EthAccount { + Some((proof, account)) => Ok(EthAccount { address: address, balance: account.balance.into(), nonce: account.nonce.into(), @@ -626,10 +625,9 @@ impl Eth for EthClient< Box::new(future::done(res)) } - - fn storage_at(&self, address: RpcH160, pos: RpcU256, num: Option) -> BoxFuture { - let address: Address = RpcH160::into(address); - let position: U256 = RpcU256::into(pos); + fn storage_at(&self, address: H160, pos: U256, num: Trailing) -> BoxFuture { + let address: Address = H160::into(address); + let position: U256 = U256::into(pos); let num = num.unwrap_or_default(); @@ -641,9 +639,8 @@ impl Eth for EthClient< Box::new(future::done(res)) } - - fn transaction_count(&self, address: RpcH160, num: Option) -> BoxFuture { - let address: Address = RpcH160::into(address); + fn transaction_count(&self, address: H160, num: Trailing) -> BoxFuture { + let address: Address = H160::into(address); let res = match num.unwrap_or_default() { BlockNumber::Pending if self.options.pending_nonce_from_queue => { @@ -676,7 +673,7 @@ impl Eth for EthClient< Box::new(future::done(res)) } - fn block_transaction_count_by_hash(&self, hash: RpcH256) -> BoxFuture> { + fn block_transaction_count_by_hash(&self, hash: H256) -> BoxFuture> { let trx_count = self.client.block(BlockId::Hash(hash.into())) .map(|block| block.transactions_count().into()); let result = Ok(trx_count) @@ -684,7 +681,7 @@ impl Eth for EthClient< Box::new(future::done(result)) } - fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture> { + fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture> { Box::new(future::done(match num { BlockNumber::Pending => Ok(Some(self.miner.pending_transaction_hashes(&*self.client).len().into())), @@ -701,7 +698,7 @@ impl Eth for EthClient< })) } - fn block_uncles_count_by_hash(&self, hash: RpcH256) -> BoxFuture> { + fn block_uncles_count_by_hash(&self, hash: H256) -> BoxFuture> { let uncle_count = self.client.block(BlockId::Hash(hash.into())) .map(|block| block.uncles_count().into()); let result = Ok(uncle_count) @@ -709,7 +706,7 @@ impl Eth for EthClient< Box::new(future::done(result)) } - fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture> { + fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture> { Box::new(future::done(match num { BlockNumber::Pending => Ok(Some(0.into())), _ => { @@ -725,8 +722,8 @@ impl Eth for EthClient< })) } - fn code_at(&self, address: RpcH160, num: Option) -> BoxFuture { - let address: Address = RpcH160::into(address); + fn code_at(&self, address: H160, num: Trailing) -> BoxFuture { + let address: Address = H160::into(address); let num = num.unwrap_or_default(); try_bf!(check_known(&*self.client, num.clone())); @@ -739,7 +736,7 @@ impl Eth for EthClient< Box::new(future::done(res)) } - fn block_by_hash(&self, hash: RpcH256, include_txs: bool) -> BoxFuture> { + fn block_by_hash(&self, hash: H256, include_txs: bool) -> BoxFuture> { let result = self.rich_block(BlockId::Hash(hash.into()).into(), include_txs) .and_then(errors::check_block_gap(&*self.client, self.options.allow_missing_blocks)); Box::new(future::done(result)) @@ -751,7 +748,7 @@ impl Eth for EthClient< Box::new(future::done(result)) } - fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture> { + fn transaction_by_hash(&self, hash: H256) -> BoxFuture> { let hash: H256 = hash.into(); let tx = try_bf!(self.transaction(PendingTransactionId::Hash(hash))).or_else(|| { self.miner.transaction(&hash) @@ -762,7 +759,7 @@ impl Eth for EthClient< Box::new(future::done(result)) } - fn transaction_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> BoxFuture> { + fn transaction_by_block_hash_and_index(&self, hash: H256, index: Index) -> BoxFuture> { let id = PendingTransactionId::Location(PendingOrBlock::Block(BlockId::Hash(hash.into())), index.value()); let result = self.transaction(id).and_then( errors::check_block_gap(&*self.client, self.options.allow_missing_blocks)); @@ -783,7 +780,7 @@ impl Eth for EthClient< Box::new(future::done(result)) } - fn transaction_receipt(&self, hash: RpcH256) -> BoxFuture> { + fn transaction_receipt(&self, hash: H256) -> BoxFuture> { let hash: H256 = hash.into(); if self.options.allow_pending_receipt_query { @@ -799,7 +796,7 @@ impl Eth for EthClient< Box::new(future::done(result)) } - fn uncle_by_block_hash_and_index(&self, hash: RpcH256, index: Index) -> BoxFuture> { + fn uncle_by_block_hash_and_index(&self, hash: H256, index: Index) -> BoxFuture> { let result = self.uncle(PendingUncleId { id: PendingOrBlock::Block(BlockId::Hash(hash.into())), position: index.value() @@ -889,19 +886,19 @@ impl Eth for EthClient< } } - fn submit_work(&self, nonce: RpcH64, pow_hash: RpcH256, mix_hash: RpcH256) -> Result { + fn submit_work(&self, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result { match helpers::submit_work_detail(&self.client, &self.miner, nonce, pow_hash, mix_hash) { Ok(_) => Ok(true), Err(_) => Ok(false), } } - fn submit_hashrate(&self, rate: RpcU256, id: RpcH256) -> Result { + fn submit_hashrate(&self, rate: U256, id: H256) -> Result { self.external_miner.submit_hashrate(rate.into(), id.into()); Ok(true) } - fn send_raw_transaction(&self, raw: Bytes) -> Result { + fn send_raw_transaction(&self, raw: Bytes) -> Result { Rlp::new(&raw.into_vec()).as_val() .map_err(errors::rlp) .and_then(|tx| SignedTransaction::new(tx).map_err(errors::transaction)) @@ -916,7 +913,7 @@ impl Eth for EthClient< .map(Into::into) } - fn submit_transaction(&self, raw: Bytes) -> Result { + fn submit_transaction(&self, raw: Bytes) -> Result { self.send_raw_transaction(raw) } @@ -960,7 +957,7 @@ impl Eth for EthClient< )) } - fn estimate_gas(&self, request: CallRequest, num: Option) -> BoxFuture { + fn estimate_gas(&self, request: CallRequest, num: Trailing) -> BoxFuture { let request = CallRequest::into(request); let signed = try_bf!(fake_sign::sign_call(request)); let num = num.unwrap_or_default(); diff --git a/rpc/src/v1/impls/eth_filter.rs b/rpc/src/v1/impls/eth_filter.rs index 20a0d274000..f8d4d290221 100644 --- a/rpc/src/v1/impls/eth_filter.rs +++ b/rpc/src/v1/impls/eth_filter.rs @@ -21,7 +21,7 @@ use std::collections::{BTreeSet, VecDeque}; use ethcore::client::{BlockChainClient, BlockId}; use ethcore::miner::{self, MinerService}; -use ethereum_types::H256; +use ethereum_types::{H256, U256}; use parking_lot::Mutex; use types::filter::Filter as EthcoreFilter; @@ -29,7 +29,7 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_core::futures::{future, Future}; use jsonrpc_core::futures::future::Either; use v1::traits::EthFilter; -use v1::types::{BlockNumber, Index, Filter, FilterChanges, Log, H256 as RpcH256, U256 as RpcU256}; +use v1::types::{BlockNumber, Index, Filter, FilterChanges, Log}; use v1::helpers::{errors, SyncPollFilter, PollFilter, PollManager, limit_logs}; use v1::impls::eth::pending_logs; @@ -137,7 +137,7 @@ impl Filterable for EthFilterClient where } impl EthFilter for T { - fn new_filter(&self, filter: Filter) -> Result { + fn new_filter(&self, filter: Filter) -> Result { let mut polls = self.polls().lock(); let block_number = self.best_block_number(); let include_pending = filter.to_block == Some(BlockNumber::Pending); @@ -150,7 +150,7 @@ impl EthFilter for T { Ok(id.into()) } - fn new_block_filter(&self) -> Result { + fn new_block_filter(&self) -> Result { let mut polls = self.polls().lock(); // +1, since we don't want to include the current block let id = polls.create_poll(SyncPollFilter::new(PollFilter::Block { @@ -160,7 +160,7 @@ impl EthFilter for T { Ok(id.into()) } - fn new_pending_transaction_filter(&self) -> Result { + fn new_pending_transaction_filter(&self) -> Result { let mut polls = self.polls().lock(); let pending_transactions = self.pending_transaction_hashes(); let id = polls.create_poll(SyncPollFilter::new(PollFilter::PendingTransaction(pending_transactions))); @@ -191,7 +191,7 @@ impl EthFilter for T { match self.block_hash(block_number) { Some(hash) => { *last_block_number = n; - hashes.push(RpcH256::from(hash)); + hashes.push(H256::from(hash)); // Only keep the most recent history if recent_reported_hashes.len() >= PollFilter::MAX_BLOCK_HISTORY_SIZE { recent_reported_hashes.pop_back(); diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index e13f5621945..61fa39dd69e 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -28,7 +28,7 @@ use light::client::LightChainClient; use light::{cht, TransactionQueue}; use light::on_demand::{request, OnDemand}; -use ethereum_types::{U256, Address}; +use ethereum_types::{H64, H160, H256, U64, U256}; use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; use parking_lot::{RwLock, Mutex}; use rlp::Rlp; @@ -44,11 +44,8 @@ use v1::helpers::deprecated::{self, DeprecationNotice}; use v1::helpers::light_fetch::{self, LightFetch}; use v1::traits::Eth; use v1::types::{ - RichBlock, Block, BlockTransactions, BlockNumber, LightBlockNumber, Bytes, - SyncStatus as RpcSyncStatus, SyncInfo as RpcSyncInfo, - Transaction, CallRequest, Index, Filter, Log, Receipt, Work, EthAccount, - H64 as RpcH64, H256 as RpcH256, H160 as RpcH160, U256 as RpcU256, - U64 as RpcU64, + RichBlock, Block, BlockTransactions, BlockNumber, LightBlockNumber, Bytes, SyncStatus, SyncInfo, + Transaction, CallRequest, Index, Filter, Log, Receipt, Work, EthAccount }; use v1::metadata::Metadata; @@ -251,34 +248,32 @@ where } } - fn author(&self) -> Result { + fn author(&self) -> Result { (self.accounts)() .first() .cloned() - .map(From::from) - .ok_or_else(|| errors::account("No accounts were found", "")) } fn is_mining(&self) -> Result { Ok(false) } - fn chain_id(&self) -> Result> { - Ok(self.client.signing_chain_id().map(RpcU64::from)) + fn chain_id(&self) -> Result> { + Ok(self.client.signing_chain_id().map(U64::from)) } - fn hashrate(&self) -> Result { + fn hashrate(&self) -> Result { Ok(Default::default()) } - fn gas_price(&self) -> Result { + fn gas_price(&self) -> Result { Ok(self.cache.lock().gas_price_corpus() .and_then(|c| c.percentile(self.gas_price_percentile).cloned()) - .map(RpcU256::from) + .map(U256::from) .unwrap_or_else(Default::default)) } - fn accounts(&self) -> Result> { + fn accounts(&self) -> Result> { self.deprecation_notice.print("eth_accounts", deprecated::msgs::ACCOUNTS); Ok((self.accounts)() @@ -287,20 +282,20 @@ where .collect()) } - fn block_number(&self) -> Result { + fn block_number(&self) -> Result { Ok(self.client.chain_info().best_block_number.into()) } - fn balance(&self, address: RpcH160, num: Option) -> BoxFuture { + fn balance(&self, address: H160, num: Trailing) -> BoxFuture { Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id()) .map(|acc| acc.map_or(0.into(), |a| a.balance).into())) } - fn storage_at(&self, _address: RpcH160, _key: RpcU256, _num: Option) -> BoxFuture { + fn storage_at(&self, _address: H160, _key: U256, _num: Trailing) -> BoxFuture { Box::new(future::err(errors::unimplemented(None))) } - fn block_by_hash(&self, hash: RpcH256, include_txs: bool) -> BoxFuture> { + fn block_by_hash(&self, hash: H256, include_txs: bool) -> BoxFuture> { Box::new(self.rich_block(BlockId::Hash(hash.into()), include_txs).map(Some)) } @@ -308,12 +303,12 @@ where Box::new(self.rich_block(num.to_block_id(), include_txs).map(Some)) } - fn transaction_count(&self, address: RpcH160, num: Option) -> BoxFuture { + fn transaction_count(&self, address: H160, num: Trailing) -> BoxFuture { Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id()) .map(|acc| acc.map_or(0.into(), |a| a.nonce).into())) } - fn block_transaction_count_by_hash(&self, hash: RpcH256) -> BoxFuture> { + fn block_transaction_count_by_hash(&self, hash: H256) -> BoxFuture> { let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone()); Box::new(self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| { @@ -329,7 +324,7 @@ where })) } - fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture> { + fn block_transaction_count_by_number(&self, num: BlockNumber) -> BoxFuture> { let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone()); Box::new(self.fetcher().header(num.to_block_id()).and_then(move |hdr| { @@ -345,7 +340,7 @@ where })) } - fn block_uncles_count_by_hash(&self, hash: RpcH256) -> BoxFuture> { + fn block_uncles_count_by_hash(&self, hash: H256) -> BoxFuture> { let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone()); Box::new(self.fetcher().header(BlockId::Hash(hash.into())).and_then(move |hdr| { @@ -361,7 +356,7 @@ where })) } - fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture> { + fn block_uncles_count_by_number(&self, num: BlockNumber) -> BoxFuture> { let (sync, on_demand) = (self.sync.clone(), self.on_demand.clone()); Box::new(self.fetcher().header(num.to_block_id()).and_then(move |hdr| { @@ -377,11 +372,11 @@ where })) } - fn code_at(&self, address: RpcH160, num: Option) -> BoxFuture { + fn code_at(&self, address: H160, num: Trailing) -> BoxFuture { Box::new(self.fetcher().code(address.into(), num.unwrap_or_default().to_block_id()).map(Into::into)) } - fn send_raw_transaction(&self, raw: Bytes) -> Result { + fn send_raw_transaction(&self, raw: Bytes) -> Result { let best_header = self.client.best_block_header().decode().map_err(errors::decode)?; Rlp::new(&raw.into_vec()).as_val() @@ -400,7 +395,7 @@ where .map(Into::into) } - fn submit_transaction(&self, raw: Bytes) -> Result { + fn submit_transaction(&self, raw: Bytes) -> Result { self.send_raw_transaction(raw) } @@ -413,7 +408,7 @@ where })) } - fn estimate_gas(&self, req: CallRequest, num: Option) -> BoxFuture { + fn estimate_gas(&self, req: CallRequest, num: Trailing) -> BoxFuture { // TODO: binary chop for more accurate estimates. Box::new(self.fetcher().proved_read_only_execution(req, num).and_then(|res| { match res { @@ -423,7 +418,7 @@ where })) } - fn transaction_by_hash(&self, hash: RpcH256) -> BoxFuture> { + fn transaction_by_hash(&self, hash: H256) -> BoxFuture> { let hash = hash.into(); { @@ -438,7 +433,7 @@ where Box::new(self.fetcher().transaction_by_hash(hash).map(|x| x.map(|(tx, _)| tx))) } - fn transaction_by_block_hash_and_index(&self, hash: RpcH256, idx: Index) -> BoxFuture> { + fn transaction_by_block_hash_and_index(&self, hash: H256, idx: Index) -> BoxFuture> { Box::new(self.fetcher().block(BlockId::Hash(hash.into())).map(move |block| { light_fetch::extract_transaction_at_index(block, idx.value()) })) @@ -450,9 +445,9 @@ where })) } - fn transaction_receipt(&self, hash: RpcH256) -> BoxFuture> { + fn transaction_receipt(&self, hash: H256) -> BoxFuture> { let fetcher = self.fetcher(); - Box::new(fetcher.transaction_by_hash(hash.clone().into()).and_then(move |tx| { + Box::new(fetcher.transaction_by_hash(hash.into()).and_then(move |tx| { // the block hash included in the transaction object here has // already been checked for canonicality and whether it contains // the transaction. @@ -480,7 +475,7 @@ where })) } - fn uncle_by_block_hash_and_index(&self, hash: RpcH256, idx: Index) -> BoxFuture> { + fn uncle_by_block_hash_and_index(&self, hash: H256, idx: Index) -> BoxFuture> { let client = self.client.clone(); Box::new(self.fetcher().block(BlockId::Hash(hash.into())).map(move |block| { extract_uncle_at_index(block, idx, client) @@ -494,7 +489,7 @@ where })) } - fn proof(&self, _address: RpcH160, _values:Vec, _num: Option) -> BoxFuture { + fn proof(&self, _address: H160, _values:Vec, _num: Trailing) -> BoxFuture { Box::new(future::err(errors::unimplemented(None))) } @@ -528,11 +523,11 @@ where Err(errors::light_unimplemented(None)) } - fn submit_work(&self, _nonce: RpcH64, _pow_hash: RpcH256, _mix_hash: RpcH256) -> Result { + fn submit_work(&self, _nonce: H64, _pow_hash: H256, _mix_hash: H256) -> Result { Err(errors::light_unimplemented(None)) } - fn submit_hashrate(&self, _rate: RpcU256, _id: RpcH256) -> Result { + fn submit_hashrate(&self, _rate: U256, _id: H256) -> Result { Err(errors::light_unimplemented(None)) } } @@ -545,11 +540,11 @@ where { fn best_block_number(&self) -> u64 { self.client.chain_info().best_block_number } - fn block_hash(&self, id: BlockId) -> Option<::ethereum_types::H256> { + fn block_hash(&self, id: BlockId) -> Option { self.client.block_hash(id) } - fn pending_transaction_hashes(&self) -> BTreeSet<::ethereum_types::H256> { + fn pending_transaction_hashes(&self) -> BTreeSet { BTreeSet::new() } diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index f744095cbaf..47d6cb01d21 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -24,6 +24,7 @@ use crypto::DEFAULT_MAC; use ethkey::{crypto::ecies, Brain, Generator}; use ethstore::random_phrase; use sync::{LightSyncInfo, LightSyncProvider, LightNetworkDispatcher, ManageNetwork}; +use ethereum_types::{H64, H160, H256, H512, U256}; use ethcore_logger::RotatingLogger; use jsonrpc_core::{Result, BoxFuture}; @@ -35,7 +36,7 @@ use v1::helpers::light_fetch::{LightFetch, light_all_transactions}; use v1::metadata::Metadata; use v1::traits::Parity; use v1::types::{ - Bytes, U256, U64, H64, H160, H256, H512, CallRequest, + Bytes, CallRequest, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, LightBlockNumber, ChainStatus, Receipt, @@ -395,7 +396,7 @@ where Box::new(self.fetcher().logs_no_tx_hash(filter)) as BoxFuture<_> } - fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: U64) -> Result { + fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: u64) -> Result { verify_signature(is_prefixed, message, r, s, v, self.light_dispatch.client.signing_chain_id()) } } diff --git a/rpc/src/v1/impls/light/parity_set.rs b/rpc/src/v1/impls/light/parity_set.rs index c7bd7da17a4..080e9402a1b 100644 --- a/rpc/src/v1/impls/light/parity_set.rs +++ b/rpc/src/v1/impls/light/parity_set.rs @@ -20,15 +20,16 @@ use std::io; use std::sync::Arc; -use sync::ManageNetwork; +use ethereum_types::{H160, H256, U256}; use fetch::{self, Fetch}; use hash::keccak_buffer; +use sync::ManageNetwork; use jsonrpc_core::{Result, BoxFuture}; use jsonrpc_core::futures::Future; use v1::helpers::errors; use v1::traits::ParitySet; -use v1::types::{Bytes, H160, H256, U256, ReleaseInfo, Transaction}; +use v1::types::{Bytes, ReleaseInfo, Transaction}; /// Parity-specific rpc interface for operations altering the settings. pub struct ParitySetClient { diff --git a/rpc/src/v1/impls/light/trace.rs b/rpc/src/v1/impls/light/trace.rs index 42f62e0c4f7..a560f980e78 100644 --- a/rpc/src/v1/impls/light/trace.rs +++ b/rpc/src/v1/impls/light/trace.rs @@ -16,11 +16,13 @@ //! Traces api implementation. +use ethereum_types::H256; use jsonrpc_core::Result; use v1::Metadata; use v1::traits::Traces; use v1::helpers::errors; -use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, TraceResultsWithTransactionHash, TraceOptions, H256}; +use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, + TraceResultsWithTransactionHash, TraceOptions}; /// Traces api implementation. // TODO: all calling APIs should be possible w. proved remote TX execution. diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 648b410694f..9f64c3973af 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -19,6 +19,9 @@ use std::sync::Arc; use std::str::FromStr; use std::collections::BTreeMap; +use ethereum_types::{Address, H64, H160, H256, H512, U256}; +use version::version_data; + use crypto::DEFAULT_MAC; use ethcore::client::{BlockChainClient, StateClient, Call}; use ethcore::miner::{self, MinerService}; @@ -41,7 +44,7 @@ use v1::helpers::external_signer::{SigningQueue, SignerService}; use v1::metadata::Metadata; use v1::traits::Parity; use v1::types::{ - Bytes, U256, H64, U64, H160, H256, H512, CallRequest, + Bytes, CallRequest, Peers, Transaction, RpcSettings, Histogram, TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, @@ -470,7 +473,7 @@ impl Parity for ParityClient where base_logs(&*self.client, &*self.miner, filter.into()) } - fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: U64) -> Result { + fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: u64) -> Result { verify_signature(is_prefixed, message, r, s, v, self.client.signing_chain_id()) } } diff --git a/rpc/src/v1/impls/parity_accounts.rs b/rpc/src/v1/impls/parity_accounts.rs index 55f23dded75..0924981d40d 100644 --- a/rpc/src/v1/impls/parity_accounts.rs +++ b/rpc/src/v1/impls/parity_accounts.rs @@ -20,8 +20,8 @@ use std::collections::{ btree_map::{BTreeMap, Entry}, HashSet, }; -use ethereum_types::Address; +use ethereum_types::{Address, H160, H256, H520}; use ethkey::{Brain, Generator, Secret}; use ethstore::KeyFile; use accounts::AccountProvider; @@ -29,10 +29,7 @@ use jsonrpc_core::Result; use v1::helpers::deprecated::{self, DeprecationNotice}; use v1::helpers::errors; use v1::traits::{ParityAccounts, ParityAccountsInfo}; -use v1::types::{ - H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, Derive, DeriveHierarchical, DeriveHash, - ExtAccountInfo, AccountInfo, HwAccountInfo, -}; +use v1::types::{Derive, DeriveHierarchical, DeriveHash,ExtAccountInfo, AccountInfo, HwAccountInfo}; use ethkey::Password; /// Account management (personal) rpc implementation. @@ -105,9 +102,7 @@ impl ParityAccountsInfo for ParityAccountsClient { } impl ParityAccounts for ParityAccountsClient { - fn all_accounts_info(&self) -> Result> { - self.deprecation_notice("parity_allAccountsInfo"); - + fn all_accounts_info(&self) -> Result> { let info = self.accounts.accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?; let other = self.accounts.addresses_info(); @@ -120,7 +115,7 @@ impl ParityAccounts for ParityAccountsClient { uuid: v.uuid.map(|uuid| uuid.to_string()) })); - let mut accounts: BTreeMap = BTreeMap::new(); + let mut accounts: BTreeMap = BTreeMap::new(); for (address, account) in account_iter { match accounts.entry(address) { @@ -138,27 +133,24 @@ impl ParityAccounts for ParityAccountsClient { Ok(accounts) } - fn new_account_from_phrase(&self, phrase: String, pass: Password) -> Result { + fn new_account_from_phrase(&self, phrase: String, pass: Password) -> Result { self.deprecation_notice("parity_newAccountFromPhrase"); - let brain = Brain::new(phrase).generate().unwrap(); self.accounts.insert_account(brain.secret().clone(), &pass) .map(Into::into) .map_err(|e| errors::account("Could not create account.", e)) } - fn new_account_from_wallet(&self, json: String, pass: Password) -> Result { + fn new_account_from_wallet(&self, json: String, pass: Password) -> Result { self.deprecation_notice("parity_newAccountFromWallet"); - self.accounts.import_presale(json.as_bytes(), &pass) .or_else(|_| self.accounts.import_wallet(json.as_bytes(), &pass, true)) .map(Into::into) .map_err(|e| errors::account("Could not create account.", e)) } - fn new_account_from_secret(&self, secret: RpcH256, pass: Password) -> Result { + fn new_account_from_secret(&self, secret: H256, pass: Password) -> Result { self.deprecation_notice("parity_newAccountFromSecret"); - let secret = Secret::from_unsafe_slice(&secret.0) .map_err(|e| errors::account("Could not create account.", e))?; self.accounts.insert_account(secret, &pass) @@ -166,9 +158,8 @@ impl ParityAccounts for ParityAccountsClient { .map_err(|e| errors::account("Could not create account.", e)) } - fn test_password(&self, account: RpcH160, password: Password) -> Result { + fn test_password(&self, account: H160, password: Password) -> Result { self.deprecation_notice("parity_testPassword"); - let account: Address = account.into(); self.accounts @@ -176,9 +167,8 @@ impl ParityAccounts for ParityAccountsClient { .map_err(|e| errors::account("Could not fetch account info.", e)) } - fn change_password(&self, account: RpcH160, password: Password, new_password: Password) -> Result { + fn change_password(&self, account: H160, password: Password, new_password: Password) -> Result { self.deprecation_notice("parity_changePassword"); - let account: Address = account.into(); self.accounts .change_password(&account, password, new_password) @@ -186,9 +176,8 @@ impl ParityAccounts for ParityAccountsClient { .map_err(|e| errors::account("Could not fetch account info.", e)) } - fn kill_account(&self, account: RpcH160, password: Password) -> Result { + fn kill_account(&self, account: H160, password: Password) -> Result { self.deprecation_notice("parity_killAccount"); - let account: Address = account.into(); self.accounts .kill_account(&account, &password) @@ -196,18 +185,16 @@ impl ParityAccounts for ParityAccountsClient { .map_err(|e| errors::account("Could not delete account.", e)) } - fn remove_address(&self, addr: RpcH160) -> Result { + fn remove_address(&self, addr: H160) -> Result { self.deprecation_notice("parity_removeAddresss"); - let addr: Address = addr.into(); self.accounts.remove_address(addr); Ok(true) } - fn set_account_name(&self, addr: RpcH160, name: String) -> Result { + fn set_account_name(&self, addr: H160, name: String) -> Result { self.deprecation_notice("parity_setAccountName"); - let addr: Address = addr.into(); self.accounts.set_account_name(addr.clone(), name.clone()) @@ -215,9 +202,8 @@ impl ParityAccounts for ParityAccountsClient { Ok(true) } - fn set_account_meta(&self, addr: RpcH160, meta: String) -> Result { + fn set_account_meta(&self, addr: H160, meta: String) -> Result { self.deprecation_notice("parity_setAccountMeta"); - let addr: Address = addr.into(); self.accounts.set_account_meta(addr.clone(), meta.clone()) @@ -225,18 +211,16 @@ impl ParityAccounts for ParityAccountsClient { Ok(true) } - fn import_geth_accounts(&self, addresses: Vec) -> Result> { + fn import_geth_accounts(&self, addresses: Vec) -> Result> { self.deprecation_notice("parity_importGethAccounts"); - self.accounts .import_geth_accounts(into_vec(addresses), false) .map(into_vec) .map_err(|e| errors::account("Couldn't import Geth accounts", e)) } - fn geth_accounts(&self) -> Result> { + fn geth_accounts(&self) -> Result> { self.deprecation_notice("parity_listGethAccounts"); - Ok(into_vec(self.accounts.list_geth_accounts(false))) } @@ -292,9 +276,8 @@ impl ParityAccounts for ParityAccountsClient { .map(|_| true) } - fn change_vault(&self, address: RpcH160, new_vault: String) -> Result { + fn change_vault(&self, address: H160, new_vault: String) -> Result { self.deprecation_notice("parity_changeVault"); - self.accounts .change_vault(address.into(), &new_vault) .map_err(|e| errors::account("Could not change vault.", e)) @@ -318,9 +301,8 @@ impl ParityAccounts for ParityAccountsClient { .map(|_| true) } - fn derive_key_index(&self, addr: RpcH160, password: Password, derivation: DeriveHierarchical, save_as_account: bool) -> Result { + fn derive_key_index(&self, addr: H160, password: Password, derivation: DeriveHierarchical, save_as_account: bool) -> Result { self.deprecation_notice("parity_deriveAddressIndex"); - let addr: Address = addr.into(); self.accounts .derive_account( @@ -333,9 +315,8 @@ impl ParityAccounts for ParityAccountsClient { .map_err(|e| errors::account("Could not derive account.", e)) } - fn derive_key_hash(&self, addr: RpcH160, password: Password, derivation: DeriveHash, save_as_account: bool) -> Result { + fn derive_key_hash(&self, addr: H160, password: Password, derivation: DeriveHash, save_as_account: bool) -> Result { self.deprecation_notice("parity_deriveAddressHash"); - let addr: Address = addr.into(); self.accounts .derive_account( @@ -348,9 +329,8 @@ impl ParityAccounts for ParityAccountsClient { .map_err(|e| errors::account("Could not derive account.", e)) } - fn export_account(&self, addr: RpcH160, password: Password) -> Result { + fn export_account(&self, addr: H160, password: Password) -> Result { self.deprecation_notice("parity_exportAccount"); - let addr = addr.into(); self.accounts .export_account( @@ -361,9 +341,8 @@ impl ParityAccounts for ParityAccountsClient { .map_err(|e| errors::account("Could not export account.", e)) } - fn sign_message(&self, addr: RpcH160, password: Password, message: RpcH256) -> Result { + fn sign_message(&self, addr: H160, password: Password, message: H256) -> Result { self.deprecation_notice("parity_signMessage"); - self.accounts .sign( addr.into(), diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index 3e0d2697452..e6bd81db363 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -21,7 +21,7 @@ use std::time::Duration; use ethcore::client::{BlockChainClient, Mode}; use ethcore::miner::{self, MinerService}; -use ethereum_types::H256 as EthH256; +use ethereum_types::{H160, H256, U256}; use ethkey; use fetch::{self, Fetch}; use hash::keccak_buffer; @@ -32,7 +32,7 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_core::futures::Future; use v1::helpers::errors; use v1::traits::ParitySet; -use v1::types::{Bytes, H160, H256, U256, ReleaseInfo, Transaction}; +use v1::types::{Bytes, ReleaseInfo, Transaction}; #[cfg(any(test, feature = "accounts"))] pub mod accounts { diff --git a/rpc/src/v1/impls/personal.rs b/rpc/src/v1/impls/personal.rs index 92886cbe315..b6af1f81e5a 100644 --- a/rpc/src/v1/impls/personal.rs +++ b/rpc/src/v1/impls/personal.rs @@ -21,7 +21,7 @@ use std::time::Duration; use accounts::AccountProvider; use bytes::Bytes; use eip_712::{EIP712, hash_structured_data}; -use ethereum_types::{H520, U128, Address}; +use ethereum_types::{H160, H256, H520, U128, Address}; use ethkey::{public_to_address, recover, Signature}; use types::transaction::{PendingTransaction, SignedTransaction}; @@ -34,7 +34,6 @@ use v1::helpers::{errors, eip191}; use v1::metadata::Metadata; use v1::traits::Personal; use v1::types::{ - H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, U128 as RpcU128, Bytes as RpcBytes, ConfirmationPayload as RpcConfirmationPayload, ConfirmationResponse as RpcConfirmationResponse, @@ -108,24 +107,21 @@ impl PersonalClient { impl Personal for PersonalClient { type Metadata = Metadata; - fn accounts(&self) -> Result> { + fn accounts(&self) -> Result> { self.deprecation_notice.print("personal_accounts", deprecated::msgs::ACCOUNTS); - let accounts = self.accounts.accounts().map_err(|e| errors::account("Could not fetch accounts.", e))?; - Ok(accounts.into_iter().map(Into::into).collect::>()) + Ok(accounts.into_iter().map(Into::into).collect::>()) } - fn new_account(&self, pass: String) -> Result { + fn new_account(&self, pass: String) -> Result { self.deprecation_notice.print("personal_newAccount", deprecated::msgs::ACCOUNTS); - self.accounts.new_account(&pass.into()) .map(Into::into) .map_err(|e| errors::account("Could not create account.", e)) } - fn unlock_account(&self, account: RpcH160, account_pass: String, duration: Option) -> Result { + fn unlock_account(&self, account: H160, account_pass: String, duration: Option) -> Result { self.deprecation_notice.print("personal_unlockAccount", deprecated::msgs::ACCOUNTS); - let account: Address = account.into(); let store = self.accounts.clone(); let duration = match duration { @@ -157,9 +153,8 @@ impl Personal for PersonalClient { } } - fn sign(&self, data: RpcBytes, account: RpcH160, password: String) -> BoxFuture { + fn sign(&self, data: RpcBytes, account: H160, password: String) -> BoxFuture { self.deprecation_notice.print("personal_sign", deprecated::msgs::ACCOUNTS); - let dispatcher = self.dispatcher.clone(); let accounts = Arc::new(dispatch::Signer::new(self.accounts.clone())) as _; @@ -177,9 +172,8 @@ impl Personal for PersonalClient { })) } - fn sign_191(&self, version: EIP191Version, data: Value, account: RpcH160, password: String) -> BoxFuture { + fn sign_191(&self, version: EIP191Version, data: Value, account: H160, password: String) -> BoxFuture { self.deprecation_notice.print("personal_sign191", deprecated::msgs::ACCOUNTS); - try_bf!(errors::require_experimental(self.allow_experimental_rpcs, "191")); let data = try_bf!(eip191::hash_message(version, data)); @@ -201,9 +195,8 @@ impl Personal for PersonalClient { ) } - fn sign_typed_data(&self, typed_data: EIP712, account: RpcH160, password: String) -> BoxFuture { + fn sign_typed_data(&self, typed_data: EIP712, account: H160, password: String) -> BoxFuture { self.deprecation_notice.print("personal_signTypedData", deprecated::msgs::ACCOUNTS); - try_bf!(errors::require_experimental(self.allow_experimental_rpcs, "712")); let data = match hash_structured_data(typed_data) { @@ -228,7 +221,7 @@ impl Personal for PersonalClient { ) } - fn ec_recover(&self, data: RpcBytes, signature: RpcH520) -> BoxFuture { + fn ec_recover(&self, data: RpcBytes, signature: H520) -> BoxFuture { let signature: H520 = signature.into(); let signature = Signature::from_electrum(&signature); let data: Bytes = data.into(); @@ -253,28 +246,25 @@ impl Personal for PersonalClient { .map(move |pending_tx| dispatcher.enrich(pending_tx.transaction))) } - fn send_transaction(&self, meta: Metadata, request: TransactionRequest, password: String) -> BoxFuture { + fn send_transaction(&self, meta: Metadata, request: TransactionRequest, password: String) -> BoxFuture { self.deprecation_notice.print("personal_sendTransaction", deprecated::msgs::ACCOUNTS); - let condition = request.condition.clone().map(Into::into); let dispatcher = self.dispatcher.clone(); Box::new( - self.do_sign_transaction(meta, request, password, move |signed: WithToken| { + self.do_sign_transaction(meta, request, password, move |signed: WithToken| { dispatcher.dispatch_transaction( PendingTransaction::new( signed.into_value(), condition ) ) - }).and_then(|hash| { - Ok(RpcH256::from(hash)) }) ) } - fn sign_and_send_transaction(&self, meta: Metadata, request: TransactionRequest, password: String) -> BoxFuture { + fn sign_and_send_transaction(&self, meta: Metadata, request: TransactionRequest, password: String) -> BoxFuture { self.deprecation_notice.print("personal_signAndSendTransaction", Some("use personal_sendTransaction instead.")); - + warn!("Using deprecated personal_signAndSendTransaction, use personal_sendTransaction instead."); self.send_transaction(meta, request, password) } } diff --git a/rpc/src/v1/impls/private.rs b/rpc/src/v1/impls/private.rs index e9c8c239cde..f1cf991240b 100644 --- a/rpc/src/v1/impls/private.rs +++ b/rpc/src/v1/impls/private.rs @@ -21,11 +21,11 @@ use std::sync::Arc; use rlp::Rlp; use ethcore_private_tx::Provider as PrivateTransactionManager; -use ethereum_types::Address; +use ethereum_types::{Address, H160, H256, U256}; use types::transaction::SignedTransaction; use jsonrpc_core::{Error}; -use v1::types::{Bytes, PrivateTransactionReceipt, H160, H256, TransactionRequest, U256, +use v1::types::{Bytes, PrivateTransactionReceipt, TransactionRequest, BlockNumber, PrivateTransactionReceiptAndTransaction, CallRequest, block_number_to_id}; use v1::traits::Private; use v1::metadata::Metadata; diff --git a/rpc/src/v1/impls/secretstore.rs b/rpc/src/v1/impls/secretstore.rs index 8eb1c3d1124..b6526b85d5f 100644 --- a/rpc/src/v1/impls/secretstore.rs +++ b/rpc/src/v1/impls/secretstore.rs @@ -19,16 +19,17 @@ use std::collections::BTreeSet; use std::sync::Arc; +use accounts::AccountProvider; use crypto::DEFAULT_MAC; +use ethereum_types::{H160, H256, H512}; use ethkey::Secret; -use accounts::AccountProvider; use jsonrpc_core::Result; use v1::helpers::errors; use v1::helpers::secretstore::{generate_document_key, encrypt_document, decrypt_document, decrypt_document_with_shadow, ordered_servers_keccak}; use v1::traits::SecretStore; -use v1::types::{H160, H256, H512, Bytes, EncryptedDocumentKey}; +use v1::types::{Bytes, EncryptedDocumentKey}; use ethkey::Password; /// Parity implementation. diff --git a/rpc/src/v1/impls/signer.rs b/rpc/src/v1/impls/signer.rs index 152a16d4b38..c4f4d357668 100644 --- a/rpc/src/v1/impls/signer.rs +++ b/rpc/src/v1/impls/signer.rs @@ -18,6 +18,7 @@ use std::sync::Arc; +use ethereum_types::U256; use ethkey; use parity_runtime::Executor; use parking_lot::Mutex; @@ -34,7 +35,7 @@ use v1::helpers::{errors, ConfirmationPayload, FilledTransactionRequest, Subscri use v1::helpers::external_signer::{SigningQueue, SignerService}; use v1::metadata::Metadata; use v1::traits::Signer; -use v1::types::{TransactionModification, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken, U256, Bytes}; +use v1::types::{TransactionModification, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken, Bytes}; /// Transactions confirmation (personal) rpc implementation. pub struct SignerClient { diff --git a/rpc/src/v1/impls/signing.rs b/rpc/src/v1/impls/signing.rs index 96d4059aa26..12f8909563c 100644 --- a/rpc/src/v1/impls/signing.rs +++ b/rpc/src/v1/impls/signing.rs @@ -18,9 +18,10 @@ use std::sync::Arc; use transient_hashmap::TransientHashMap; -use ethereum_types::U256; use parking_lot::Mutex; +use ethereum_types::{H160, H256, H520, U256}; + use jsonrpc_core::{BoxFuture, Result, Error}; use jsonrpc_core::futures::{future, Future, Poll, Async}; use jsonrpc_core::futures::future::Either; @@ -36,7 +37,7 @@ use v1::helpers::external_signer::{ use v1::metadata::Metadata; use v1::traits::{EthSigning, ParitySigning}; use v1::types::{ - H160 as RpcH160, H256 as RpcH256, U256 as RpcU256, Bytes as RpcBytes, H520 as RpcH520, + Bytes as RpcBytes, Either as RpcEither, RichRawTransaction as RpcRichRawTransaction, TransactionRequest as RpcTransactionRequest, @@ -142,9 +143,8 @@ impl ParitySigning for SigningQueueClient { Box::new(self.dispatcher.fill_optional_fields(transaction.into(), default_account, true).map(Into::into)) } - fn post_sign(&self, meta: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture> { + fn post_sign(&self, meta: Metadata, address: H160, data: RpcBytes) -> BoxFuture> { self.deprecation_notice.print("parity_postSign", deprecated::msgs::ACCOUNTS); - let executor = self.executor.clone(); let confirmations = self.confirmations.clone(); @@ -160,9 +160,8 @@ impl ParitySigning for SigningQueueClient { })) } - fn post_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture> { + fn post_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture> { self.deprecation_notice.print("parity_postTransaction", deprecated::msgs::ACCOUNTS); - let executor = self.executor.clone(); let confirmations = self.confirmations.clone(); @@ -176,9 +175,8 @@ impl ParitySigning for SigningQueueClient { })) } - fn check_request(&self, id: RpcU256) -> Result> { + fn check_request(&self, id: U256) -> Result> { self.deprecation_notice.print("parity_checkRequest", deprecated::msgs::ACCOUNTS); - let id: U256 = id.into(); match self.confirmations.lock().get(&id) { None => Err(errors::request_not_found()), // Request info has been dropped, or even never been there @@ -187,9 +185,8 @@ impl ParitySigning for SigningQueueClient { } } - fn decrypt_message(&self, meta: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture { + fn decrypt_message(&self, meta: Metadata, address: H160, data: RpcBytes) -> BoxFuture { self.deprecation_notice.print("parity_decryptMessage", deprecated::msgs::ACCOUNTS); - let res = self.dispatch( RpcConfirmationPayload::Decrypt((address.clone(), data).into()), meta.origin, @@ -208,9 +205,8 @@ impl ParitySigning for SigningQueueClient { impl EthSigning for SigningQueueClient { type Metadata = Metadata; - fn sign(&self, meta: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture { + fn sign(&self, meta: Metadata, address: H160, data: RpcBytes) -> BoxFuture { self.deprecation_notice.print("eth_sign", deprecated::msgs::ACCOUNTS); - let res = self.dispatch( RpcConfirmationPayload::EthSignMessage((address.clone(), data).into()), meta.origin, @@ -224,9 +220,8 @@ impl EthSigning for SigningQueueClient { })) } - fn send_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture { + fn send_transaction(&self, meta: Metadata, request: RpcTransactionRequest) -> BoxFuture { self.deprecation_notice.print("eth_sendTransaction", deprecated::msgs::ACCOUNTS); - let res = self.dispatch( RpcConfirmationPayload::SendTransaction(request), meta.origin, diff --git a/rpc/src/v1/impls/signing_unsafe.rs b/rpc/src/v1/impls/signing_unsafe.rs index 59b8d5e9dce..72a3a6fbf18 100644 --- a/rpc/src/v1/impls/signing_unsafe.rs +++ b/rpc/src/v1/impls/signing_unsafe.rs @@ -18,8 +18,7 @@ use std::sync::Arc; -use ethereum_types::Address; - +use ethereum_types::{Address, H160, H256, H520, U256}; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_core::futures::{future, Future}; use v1::helpers::{errors}; @@ -28,8 +27,7 @@ use v1::helpers::dispatch::{self, Dispatcher}; use v1::metadata::Metadata; use v1::traits::{EthSigning, ParitySigning}; use v1::types::{ - U256 as RpcU256, - H160 as RpcH160, H256 as RpcH256, H520 as RpcH520, Bytes as RpcBytes, + Bytes as RpcBytes, Either as RpcEither, RichRawTransaction as RpcRichRawTransaction, TransactionRequest as RpcTransactionRequest, @@ -70,9 +68,8 @@ impl EthSigning for SigningUnsafeClient { type Metadata = Metadata; - fn sign(&self, _: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture { + fn sign(&self, _: Metadata, address: H160, data: RpcBytes) -> BoxFuture { self.deprecation_notice.print("eth_sign", deprecated::msgs::ACCOUNTS); - Box::new(self.handle(RpcConfirmationPayload::EthSignMessage((address.clone(), data).into()), address.into()) .then(|res| match res { Ok(RpcConfirmationResponse::Signature(signature)) => Ok(signature), @@ -81,9 +78,8 @@ impl EthSigning for SigningUnsafeClient })) } - fn send_transaction(&self, _meta: Metadata, request: RpcTransactionRequest) -> BoxFuture { + fn send_transaction(&self, _meta: Metadata, request: RpcTransactionRequest) -> BoxFuture { self.deprecation_notice.print("eth_sendTransaction", deprecated::msgs::ACCOUNTS); - Box::new(self.handle(RpcConfirmationPayload::SendTransaction(request), self.accounts.default_account()) .then(|res| match res { Ok(RpcConfirmationResponse::SendTransaction(hash)) => Ok(hash), @@ -113,9 +109,8 @@ impl ParitySigning for SigningUnsafeClient { Box::new(self.dispatcher.fill_optional_fields(transaction.into(), default_account, true).map(Into::into)) } - fn decrypt_message(&self, _: Metadata, address: RpcH160, data: RpcBytes) -> BoxFuture { + fn decrypt_message(&self, _: Metadata, address: H160, data: RpcBytes) -> BoxFuture { self.deprecation_notice.print("parity_decryptMessage", deprecated::msgs::ACCOUNTS); - Box::new(self.handle(RpcConfirmationPayload::Decrypt((address.clone(), data).into()), address.into()) .then(|res| match res { Ok(RpcConfirmationResponse::Decrypt(data)) => Ok(data), @@ -124,17 +119,17 @@ impl ParitySigning for SigningUnsafeClient { })) } - fn post_sign(&self, _: Metadata, _: RpcH160, _: RpcBytes) -> BoxFuture> { + fn post_sign(&self, _: Metadata, _: H160, _: RpcBytes) -> BoxFuture> { // We don't support this in non-signer mode. Box::new(future::err(errors::signer_disabled())) } - fn post_transaction(&self, _: Metadata, _: RpcTransactionRequest) -> BoxFuture> { + fn post_transaction(&self, _: Metadata, _: RpcTransactionRequest) -> BoxFuture> { // We don't support this in non-signer mode. Box::new(future::err(errors::signer_disabled())) } - fn check_request(&self, _: RpcU256) -> Result> { + fn check_request(&self, _: U256) -> Result> { // We don't support this in non-signer mode. Err(errors::signer_disabled()) } diff --git a/rpc/src/v1/impls/traces.rs b/rpc/src/v1/impls/traces.rs index f2a5c83d4ea..d7428aad27b 100644 --- a/rpc/src/v1/impls/traces.rs +++ b/rpc/src/v1/impls/traces.rs @@ -19,6 +19,7 @@ use std::sync::Arc; use ethcore::client::{BlockChainClient, CallAnalytics, TransactionId, TraceId, StateClient, StateInfo, Call, BlockId}; +use ethereum_types::H256; use rlp::Rlp; use types::transaction::SignedTransaction; @@ -26,7 +27,8 @@ use jsonrpc_core::Result; use v1::Metadata; use v1::traits::Traces; use v1::helpers::{errors, fake_sign}; -use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, TraceResultsWithTransactionHash, TraceOptions, H256, block_number_to_id}; +use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, + TraceResultsWithTransactionHash, TraceOptions, block_number_to_id}; fn to_call_analytics(flags: TraceOptions) -> CallAnalytics { CallAnalytics { diff --git a/rpc/src/v1/impls/web3.rs b/rpc/src/v1/impls/web3.rs index 3dfe2a6653c..e7bf9dd49fe 100644 --- a/rpc/src/v1/impls/web3.rs +++ b/rpc/src/v1/impls/web3.rs @@ -15,11 +15,12 @@ // along with Parity Ethereum. If not, see . //! Web3 rpc implementation. +use ethereum_types::H256; use hash::keccak; use jsonrpc_core::Result; use version::version; use v1::traits::Web3; -use v1::types::{H256, Bytes}; +use v1::types::Bytes; /// Web3 rpc implementation. pub struct Web3Client; diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 56398add1ec..68710ae5591 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -26,7 +26,7 @@ use ethcore::spec::{Genesis, Spec}; use ethcore::test_helpers; use ethcore::verification::VerifierType; use ethcore::verification::queue::kind::blocks::Unverified; -use ethereum_types::{H256, Address}; +use ethereum_types::{Address, H256, U256}; use ethjson::blockchain::BlockChain; use ethjson::spec::ForkSpec; use io::IoChannel; @@ -42,7 +42,6 @@ use v1::impls::{EthClient, EthClientOptions, SigningUnsafeClient}; use v1::metadata::Metadata; use v1::tests::helpers::{TestSnapshotService, TestSyncProvider, Config}; use v1::traits::{Eth, EthSigning}; -use v1::types::U256 as NU256; fn account_provider() -> Arc { Arc::new(AccountProvider::transient_provider()) @@ -459,7 +458,7 @@ fn verify_transaction_counts(name: String, chain: BlockChain) { "jsonrpc": "2.0", "method": "eth_getBlockTransactionCountByNumber", "params": [ - "#.to_owned() + &::serde_json::to_string(&NU256::from(num)).unwrap() + r#" + "#.to_owned() + &::serde_json::to_string(&U256::from(num)).unwrap() + r#" ], "id": "# + format!("{}", *id).as_ref() + r#" }"#; diff --git a/rpc/src/v1/tests/mocked/personal.rs b/rpc/src/v1/tests/mocked/personal.rs index 771abe24ef4..0da6f46068b 100644 --- a/rpc/src/v1/tests/mocked/personal.rs +++ b/rpc/src/v1/tests/mocked/personal.rs @@ -18,8 +18,8 @@ use std::sync::Arc; use std::str::FromStr; use bytes::ToPretty; -use ethereum_types::{U256, Address}; use accounts::AccountProvider; +use ethereum_types::{Address, H520, U256}; use ethcore::client::TestBlockChainClient; use jsonrpc_core::IoHandler; use parking_lot::Mutex; @@ -31,7 +31,7 @@ use v1::{PersonalClient, Personal, Metadata}; use v1::helpers::{nonce, eip191}; use v1::helpers::dispatch::{eth_data_hash, FullDispatcher}; use v1::tests::helpers::TestMinerService; -use v1::types::{EIP191Version, PresignedTransaction, H520}; +use v1::types::{EIP191Version, PresignedTransaction}; use rustc_hex::ToHex; use serde_json::to_value; use ethkey::Secret; diff --git a/rpc/src/v1/tests/mocked/secretstore.rs b/rpc/src/v1/tests/mocked/secretstore.rs index fa3cba58fd1..96e20d0028b 100644 --- a/rpc/src/v1/tests/mocked/secretstore.rs +++ b/rpc/src/v1/tests/mocked/secretstore.rs @@ -18,6 +18,7 @@ use std::sync::Arc; use crypto::DEFAULT_MAC; use accounts::AccountProvider; +use ethereum_types::H256; use ethkey::{KeyPair, Signature, verify_public}; use serde_json; @@ -26,7 +27,7 @@ use v1::metadata::Metadata; use v1::SecretStoreClient; use v1::traits::secretstore::SecretStore; use v1::helpers::secretstore::ordered_servers_keccak; -use v1::types::{H256, EncryptedDocumentKey}; +use v1::types::EncryptedDocumentKey; struct Dependencies { pub accounts: Arc, diff --git a/rpc/src/v1/tests/mocked/signer.rs b/rpc/src/v1/tests/mocked/signer.rs index dea1f1fb7fd..492eee81855 100644 --- a/rpc/src/v1/tests/mocked/signer.rs +++ b/rpc/src/v1/tests/mocked/signer.rs @@ -16,7 +16,7 @@ use std::sync::Arc; use std::str::FromStr; -use ethereum_types::{U256, Address}; +use ethereum_types::{H520, U256, Address}; use bytes::ToPretty; use accounts::AccountProvider; @@ -31,7 +31,7 @@ use jsonrpc_core::IoHandler; use v1::{SignerClient, Signer, Origin}; use v1::metadata::Metadata; use v1::tests::helpers::TestMinerService; -use v1::types::{Bytes as RpcBytes, H520}; +use v1::types::Bytes as RpcBytes; use v1::helpers::{nonce, FilledTransactionRequest, ConfirmationPayload}; use v1::helpers::external_signer::{SigningQueue, SignerService}; use v1::helpers::dispatch::{self, FullDispatcher, eth_data_hash}; diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index 0f0dc48a592..52a7588ae42 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -17,10 +17,11 @@ //! Eth rpc interface. use jsonrpc_core::{Result, BoxFuture}; use jsonrpc_derive::rpc; +use jsonrpc_macros::Trailing; +use ethereum_types::{H64, H160, H256, U64, U256}; use v1::types::{RichBlock, BlockNumber, Bytes, CallRequest, Filter, FilterChanges, Index, EthAccount}; use v1::types::{Log, Receipt, SyncStatus, Transaction, Work}; -use v1::types::{H64, H160, H256, U256, U64}; /// Eth rpc interface. #[rpc] diff --git a/rpc/src/v1/traits/eth_signing.rs b/rpc/src/v1/traits/eth_signing.rs index c272a42e40e..72e13ddabe6 100644 --- a/rpc/src/v1/traits/eth_signing.rs +++ b/rpc/src/v1/traits/eth_signing.rs @@ -19,7 +19,8 @@ use jsonrpc_core::BoxFuture; use jsonrpc_derive::rpc; -use v1::types::{Bytes, H160, H256, H520, TransactionRequest, RichRawTransaction}; +use ethereum_types::{H160, H256, H520}; +use v1::types::{Bytes, TransactionRequest, RichRawTransaction}; /// Signing methods implementation relying on unlocked accounts. #[rpc] diff --git a/rpc/src/v1/traits/parity.rs b/rpc/src/v1/traits/parity.rs index 4303af3d6f3..e3821355eee 100644 --- a/rpc/src/v1/traits/parity.rs +++ b/rpc/src/v1/traits/parity.rs @@ -18,10 +18,11 @@ use std::collections::BTreeMap; +use ethereum_types::{H64, H160, H256, H512, U64, U256}; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; use v1::types::{ - H160, H256, H512, U256, U64, H64, Bytes, CallRequest, + Bytes, CallRequest, Peers, Transaction, RpcSettings, Histogram, RecoveredAccount, TransactionStats, LocalTransactionStatus, BlockNumber, ConsensusCapability, VersionInfo, diff --git a/rpc/src/v1/traits/parity_accounts.rs b/rpc/src/v1/traits/parity_accounts.rs index b17e4b8dfc7..eaffac78850 100644 --- a/rpc/src/v1/traits/parity_accounts.rs +++ b/rpc/src/v1/traits/parity_accounts.rs @@ -19,9 +19,10 @@ use std::collections::BTreeMap; use jsonrpc_core::Result; use jsonrpc_derive::rpc; +use ethereum_types::{H160, H256, H520}; use ethkey::Password; use ethstore::KeyFile; -use v1::types::{H160, H256, H520, DeriveHash, DeriveHierarchical, ExtAccountInfo}; +use v1::types::{DeriveHash, DeriveHierarchical, ExtAccountInfo}; use v1::types::{AccountInfo, HwAccountInfo}; /// Parity-specific read-only accounts rpc interface. diff --git a/rpc/src/v1/traits/parity_set.rs b/rpc/src/v1/traits/parity_set.rs index b2628f364c7..c7c23387900 100644 --- a/rpc/src/v1/traits/parity_set.rs +++ b/rpc/src/v1/traits/parity_set.rs @@ -16,10 +16,11 @@ //! Parity-specific rpc interface for operations altering the settings. +use ethereum_types::{H160, H256, U256}; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use v1::types::{Bytes, H160, H256, U256, ReleaseInfo, Transaction}; +use v1::types::{Bytes, ReleaseInfo, Transaction}; /// Parity-specific rpc interface for operations altering the account-related settings. #[rpc] diff --git a/rpc/src/v1/traits/parity_signing.rs b/rpc/src/v1/traits/parity_signing.rs index 26495831a74..acd9e8cd686 100644 --- a/rpc/src/v1/traits/parity_signing.rs +++ b/rpc/src/v1/traits/parity_signing.rs @@ -18,7 +18,8 @@ use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use v1::types::{U256, H160, Bytes, ConfirmationResponse, TransactionRequest, Either}; +use ethereum_types::{H160, U256}; +use v1::types::{Bytes, ConfirmationResponse, TransactionRequest, Either}; /// Signing methods implementation. #[rpc] diff --git a/rpc/src/v1/traits/personal.rs b/rpc/src/v1/traits/personal.rs index 25412f6646b..e3632731fa5 100644 --- a/rpc/src/v1/traits/personal.rs +++ b/rpc/src/v1/traits/personal.rs @@ -16,10 +16,11 @@ //! Personal rpc interface. use eip_712::EIP712; +use ethereum_types::{H160, H256, H520, U128}; use jsonrpc_core::types::Value; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_derive::rpc; -use v1::types::{Bytes, U128, H160, H256, H520, TransactionRequest, RichRawTransaction as RpcRichRawTransaction, EIP191Version}; +use v1::types::{Bytes, TransactionRequest, RichRawTransaction as RpcRichRawTransaction, EIP191Version}; /// Personal rpc interface. Safe (read-only) functions. #[rpc] @@ -70,5 +71,4 @@ pub trait Personal { /// @deprecated alias for `personal_sendTransaction`. #[rpc(meta, name = "personal_signAndSendTransaction")] fn sign_and_send_transaction(&self, Self::Metadata, TransactionRequest, String) -> BoxFuture; - } diff --git a/rpc/src/v1/traits/private.rs b/rpc/src/v1/traits/private.rs index b7b871df04f..732e3914bda 100644 --- a/rpc/src/v1/traits/private.rs +++ b/rpc/src/v1/traits/private.rs @@ -16,10 +16,11 @@ //! SecretStore-specific rpc interface. +use ethereum_types::{H160, H256, U256}; use jsonrpc_core::Error; use jsonrpc_derive::rpc; -use v1::types::{Bytes, PrivateTransactionReceipt, H160, H256, U256, BlockNumber, +use v1::types::{Bytes, PrivateTransactionReceipt, BlockNumber, PrivateTransactionReceiptAndTransaction, CallRequest}; /// Private transaction management RPC interface. diff --git a/rpc/src/v1/traits/secretstore.rs b/rpc/src/v1/traits/secretstore.rs index 8ff1c0e99e6..6883753b4fa 100644 --- a/rpc/src/v1/traits/secretstore.rs +++ b/rpc/src/v1/traits/secretstore.rs @@ -17,11 +17,12 @@ //! SecretStore-specific rpc interface. use std::collections::BTreeSet; + use jsonrpc_core::Result; use jsonrpc_derive::rpc; +use ethereum_types::{H160, H256, H512}; use ethkey::Password; - -use v1::types::{H160, H256, H512, Bytes, EncryptedDocumentKey}; +use v1::types::{Bytes, EncryptedDocumentKey}; /// Parity-specific rpc interface. #[rpc] diff --git a/rpc/src/v1/traits/signer.rs b/rpc/src/v1/traits/signer.rs index 675808a9807..b5653eba635 100644 --- a/rpc/src/v1/traits/signer.rs +++ b/rpc/src/v1/traits/signer.rs @@ -15,11 +15,13 @@ // along with Parity Ethereum. If not, see . //! Parity Signer-related rpc interface. + +use ethereum_types::U256; use jsonrpc_core::{BoxFuture, Result}; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; use jsonrpc_derive::rpc; -use v1::types::{U256, Bytes, TransactionModification, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken}; +use v1::types::{Bytes, TransactionModification, ConfirmationRequest, ConfirmationResponse, ConfirmationResponseWithToken}; /// Signer extension for confirmations rpc interface. #[rpc] diff --git a/rpc/src/v1/traits/traces.rs b/rpc/src/v1/traits/traces.rs index 3ac4964bd58..5308ed4c6c3 100644 --- a/rpc/src/v1/traits/traces.rs +++ b/rpc/src/v1/traits/traces.rs @@ -16,9 +16,11 @@ //! Traces specific rpc interface. +use ethereum_types::H256; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, TraceResultsWithTransactionHash, H256, TraceOptions}; +use v1::types::{TraceFilter, LocalizedTrace, BlockNumber, Index, CallRequest, Bytes, TraceResults, + TraceResultsWithTransactionHash, TraceOptions}; /// Traces specific rpc interface. #[rpc] diff --git a/rpc/src/v1/traits/web3.rs b/rpc/src/v1/traits/web3.rs index 69d74756eaa..dd464ee1c22 100644 --- a/rpc/src/v1/traits/web3.rs +++ b/rpc/src/v1/traits/web3.rs @@ -15,10 +15,11 @@ // along with Parity Ethereum. If not, see . //! Web3 rpc interface. +use ethereum_types::H256; use jsonrpc_core::Result; use jsonrpc_derive::rpc; -use v1::types::{H256, Bytes}; +use v1::types::Bytes; /// Web3 rpc interface. #[rpc] diff --git a/rpc/src/v1/types/account_info.rs b/rpc/src/v1/types/account_info.rs index a35537b0296..6d7585f87fc 100644 --- a/rpc/src/v1/types/account_info.rs +++ b/rpc/src/v1/types/account_info.rs @@ -16,8 +16,8 @@ //! Return types for RPC calls -use ethereum_types::{Public, Address}; -use v1::types::{H160, H256, U256, Bytes}; +use ethereum_types::{Public, Address, H160, H256, U256}; +use v1::types::Bytes; /// Account information. #[derive(Debug, Default, Clone, PartialEq, Serialize)] diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index b3a6018f674..258acad8ef3 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -17,11 +17,13 @@ use std::ops::Deref; use std::collections::BTreeMap; +use ethbloom::Bloom as H2048; +use ethereum_types::{H160, H256, U256}; use serde::ser::Error; use serde::{Serialize, Serializer}; use types::encoded::Header as EthHeader; -use v1::types::{Bytes, Transaction, H160, H256, H2048, U256}; +use v1::types::{Bytes, Transaction}; /// Block Transactions #[derive(Debug)] @@ -205,8 +207,10 @@ impl Serialize for Rich { #[cfg(test)] mod tests { use std::collections::BTreeMap; + use ethbloom::Bloom as H2048; + use ethereum_types::{H64, H160, H256, U256}; use serde_json; - use v1::types::{Transaction, H64, H160, H256, H2048, Bytes, U256}; + use v1::types::{Transaction, Bytes}; use super::{Block, RichBlock, BlockTransactions, Header, RichHeader}; #[test] diff --git a/rpc/src/v1/types/call_request.rs b/rpc/src/v1/types/call_request.rs index c2657315093..d75e4b1a2d7 100644 --- a/rpc/src/v1/types/call_request.rs +++ b/rpc/src/v1/types/call_request.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . +use ethereum_types::{H160, U256}; use v1::helpers::CallRequest as Request; -use v1::types::{Bytes, H160, U256}; +use v1::types::Bytes; /// Call request #[derive(Debug, Default, PartialEq, Deserialize)] @@ -57,7 +58,7 @@ mod tests { use std::str::FromStr; use rustc_hex::FromHex; use serde_json; - use v1::types::{U256, H160}; + use ethereum_types::{U256, H160}; use super::CallRequest; #[test] diff --git a/rpc/src/v1/types/confirmations.rs b/rpc/src/v1/types/confirmations.rs index 2a62e2cfae5..1534fbcea19 100644 --- a/rpc/src/v1/types/confirmations.rs +++ b/rpc/src/v1/types/confirmations.rs @@ -21,7 +21,8 @@ use serde::{Serialize, Serializer}; use ansi_term::Colour; use bytes::ToPretty; -use v1::types::{U256, TransactionRequest, RichRawTransaction, H160, H256, H520, Bytes, TransactionCondition, Origin}; +use ethereum_types::{H160, H256, H520, U256}; +use v1::types::{TransactionRequest, RichRawTransaction, Bytes, TransactionCondition, Origin}; use v1::helpers; use ethkey::Password; @@ -281,8 +282,9 @@ impl Serialize for Either where #[cfg(test)] mod tests { use std::str::FromStr; + use ethereum_types::{H256, U256}; use serde_json; - use v1::types::{U256, H256, TransactionCondition}; + use v1::types::TransactionCondition; use v1::helpers; use super::*; diff --git a/rpc/src/v1/types/consensus_status.rs b/rpc/src/v1/types/consensus_status.rs index 15047ed0518..a5a5c9de8b3 100644 --- a/rpc/src/v1/types/consensus_status.rs +++ b/rpc/src/v1/types/consensus_status.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . +use ethereum_types::{H160, H256}; use semver; -use v1::types::{H160, H256}; use updater::{self, CapState}; /// Capability info diff --git a/rpc/src/v1/types/derivation.rs b/rpc/src/v1/types/derivation.rs index 4c2f6651214..1f2764d9ff2 100644 --- a/rpc/src/v1/types/derivation.rs +++ b/rpc/src/v1/types/derivation.rs @@ -18,10 +18,9 @@ use std::fmt; use serde::{Deserialize, Deserializer}; use serde::de::{Error, Visitor}; +use ethereum_types::H256; use ethstore; -use super::hash::H256; - /// Type of derivation pub enum DerivationType { /// Soft - allow proof of parent diff --git a/rpc/src/v1/types/eip191.rs b/rpc/src/v1/types/eip191.rs index 16b8536bf89..fe3aab4c51a 100644 --- a/rpc/src/v1/types/eip191.rs +++ b/rpc/src/v1/types/eip191.rs @@ -15,9 +15,11 @@ // along with Parity Ethereum. If not, see . //! EIP-191 specific types + +use ethereum_types::H160; use serde::{Deserialize, Deserializer}; use serde::de; -use v1::types::{H160, Bytes}; +use v1::types::Bytes; /// EIP-191 version specifier #[derive(Debug)] diff --git a/rpc/src/v1/types/filter.rs b/rpc/src/v1/types/filter.rs index dfcf78acf42..c6708da5765 100644 --- a/rpc/src/v1/types/filter.rs +++ b/rpc/src/v1/types/filter.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . +use ethereum_types::{H160, H256}; use jsonrpc_core::{Error as RpcError}; use serde::de::{Error, DeserializeOwned}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; @@ -21,7 +22,7 @@ use serde_json::{Value, from_value}; use types::filter::Filter as EthFilter; use types::ids::BlockId; -use v1::types::{BlockNumber, H160, H256, Log}; +use v1::types::{BlockNumber, Log}; use v1::helpers::errors::invalid_params; /// Variadic value diff --git a/rpc/src/v1/types/hash.rs b/rpc/src/v1/types/hash.rs deleted file mode 100644 index 6cdaccf43b8..00000000000 --- a/rpc/src/v1/types/hash.rs +++ /dev/null @@ -1,165 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . - -use std::fmt; -use std::str::FromStr; -use std::cmp::Ordering; -use std::hash::{Hash, Hasher}; -use serde; -use rustc_hex::{ToHex, FromHex}; -use ethereum_types::{H64 as Eth64, H160 as Eth160, H256 as Eth256, H520 as Eth520, H512 as Eth512, Bloom as Eth2048}; - -macro_rules! impl_hash { - ($name: ident, $other: ident, $size: expr) => { - /// Hash serialization - pub struct $name(pub [u8; $size]); - - impl Eq for $name { } - - impl Default for $name { - fn default() -> Self { - $name([0; $size]) - } - } - - impl fmt::Debug for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0.to_hex()) - } - } - - impl fmt::Display for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let hex = self.0.to_hex(); - write!(f, "{}..{}", &hex[0..2], &hex[$size-2..$size]) - } - } - - 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: S) -> Result - where S: serde::Serializer { - let mut hex = "0x".to_owned(); - hex.push_str(&self.0.to_hex()); - serializer.serialize_str(&hex) - } - } - - impl<'a> serde::Deserialize<'a> for $name { - fn deserialize(deserializer: D) -> Result<$name, D::Error> where D: serde::Deserializer<'a> { - struct HashVisitor; - - impl<'b> serde::de::Visitor<'b> for HashVisitor { - type Value = $name; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "a 0x-prefixed, padded, hex-encoded hash with length {}", $size * 2) - } - - fn visit_str(self, value: &str) -> Result where E: serde::de::Error { - - if value.len() < 2 || !value.starts_with("0x") { - return Err(E::custom("expected a hex-encoded hash with 0x prefix")); - } - if value.len() != 2 + $size * 2 { - return Err(E::invalid_length(value.len() - 2, &self)); - } - - match value[2..].from_hex() { - Ok(ref v) => { - let mut result = [0u8; $size]; - result.copy_from_slice(v); - Ok($name(result)) - }, - Err(e) => Err(E::custom(format!("invalid hex value: {:?}", e))), - } - } - - fn visit_string(self, value: String) -> Result where E: serde::de::Error { - self.visit_str(value.as_ref()) - } - } - - deserializer.deserialize_any(HashVisitor) - } - } - } -} - -impl_hash!(H64, Eth64, 8); -impl_hash!(H160, Eth160, 20); -impl_hash!(H256, Eth256, 32); -impl_hash!(H512, Eth512, 64); -impl_hash!(H520, Eth520, 65); -impl_hash!(H2048, Eth2048, 256); diff --git a/rpc/src/v1/types/histogram.rs b/rpc/src/v1/types/histogram.rs index 5b7ab1bb68f..d7f14c514e6 100644 --- a/rpc/src/v1/types/histogram.rs +++ b/rpc/src/v1/types/histogram.rs @@ -16,7 +16,7 @@ //! Gas prices histogram. -use v1::types::U256; +use ethereum_types::U256; /// Values of RPC settings. #[derive(Serialize, Deserialize)] diff --git a/rpc/src/v1/types/log.rs b/rpc/src/v1/types/log.rs index dd8f3d31cca..3dcc8fb2988 100644 --- a/rpc/src/v1/types/log.rs +++ b/rpc/src/v1/types/log.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . +use ethereum_types::{H160, H256, U256}; use types::log_entry::{LocalizedLogEntry, LogEntry}; -use v1::types::{Bytes, H160, H256, U256}; +use v1::types::Bytes; /// Log #[derive(Debug, Serialize, PartialEq, Eq, Hash, Clone)] @@ -87,7 +88,8 @@ impl From for Log { mod tests { use serde_json; use std::str::FromStr; - use v1::types::{Log, H160, H256, U256}; + use v1::types::Log; + use ethereum_types::{H160, H256, U256}; #[test] fn log_serialization() { diff --git a/rpc/src/v1/types/mod.rs b/rpc/src/v1/types/mod.rs index 9859bc909dc..45fb2467e18 100644 --- a/rpc/src/v1/types/mod.rs +++ b/rpc/src/v1/types/mod.rs @@ -25,7 +25,6 @@ mod confirmations; mod consensus_status; mod derivation; mod filter; -mod hash; mod histogram; mod index; mod log; @@ -40,7 +39,7 @@ mod trace_filter; mod transaction; mod transaction_request; mod transaction_condition; -mod uint; +// mod uint; mod work; mod private_receipt; mod eip191; @@ -60,7 +59,6 @@ pub use self::confirmations::{ pub use self::consensus_status::*; pub use self::derivation::{DeriveHash, DeriveHierarchical, Derive}; pub use self::filter::{Filter, FilterChanges}; -pub use self::hash::{H64, H160, H256, H512, H520, H2048}; pub use self::histogram::Histogram; pub use self::index::Index; pub use self::log::Log; @@ -78,7 +76,6 @@ pub use self::trace_filter::TraceFilter; pub use self::transaction::{Transaction, RichRawTransaction, LocalTransactionStatus}; pub use self::transaction_request::TransactionRequest; pub use self::transaction_condition::TransactionCondition; -pub use self::uint::{U128, U256, U64}; pub use self::work::Work; pub use self::private_receipt::{PrivateTransactionReceipt, PrivateTransactionReceiptAndTransaction}; diff --git a/rpc/src/v1/types/private_receipt.rs b/rpc/src/v1/types/private_receipt.rs index e6170314f7a..fd0eae067fb 100644 --- a/rpc/src/v1/types/private_receipt.rs +++ b/rpc/src/v1/types/private_receipt.rs @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use v1::types::{H160, H256, TransactionRequest}; use ethcore_private_tx::{Receipt as EthPrivateReceipt}; +use ethereum_types::{H160, H256}; +use v1::types::TransactionRequest; /// Receipt #[derive(Debug, Serialize)] diff --git a/rpc/src/v1/types/provenance.rs b/rpc/src/v1/types/provenance.rs index 2d9301b49ef..dcdd2408fe8 100644 --- a/rpc/src/v1/types/provenance.rs +++ b/rpc/src/v1/types/provenance.rs @@ -17,7 +17,7 @@ //! Request Provenance use std::fmt; -use v1::types::H256; +use ethereum_types::H256; /// RPC request origin #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] diff --git a/rpc/src/v1/types/pubsub.rs b/rpc/src/v1/types/pubsub.rs index 179ee0e5c35..c526a2b372e 100644 --- a/rpc/src/v1/types/pubsub.rs +++ b/rpc/src/v1/types/pubsub.rs @@ -16,10 +16,11 @@ //! Pub-Sub types. +use ethereum_types::H256; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::de::Error; use serde_json::{Value, from_value}; -use v1::types::{RichHeader, Filter, Log, H256}; +use v1::types::{RichHeader, Filter, Log}; /// Subscription result. #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index f57c988ffea..98e9f34e0b3 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use v1::types::{Log, H160, H256, H2048, U256, U64}; +use ethereum_types::{H160, H256, U64, U256}; +use ethbloom::Bloom as H2048; +use v1::types::Log; use types::receipt::{Receipt as EthReceipt, RichReceipt, LocalizedReceipt, TransactionOutcome}; /// Receipt diff --git a/rpc/src/v1/types/secretstore.rs b/rpc/src/v1/types/secretstore.rs index 0de3aaac673..ef76ec5b464 100644 --- a/rpc/src/v1/types/secretstore.rs +++ b/rpc/src/v1/types/secretstore.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use v1::types::{Bytes, H512}; +use ethereum_types::H512; +use v1::types::Bytes; /// Encrypted document key. #[derive(Default, Debug, Serialize, PartialEq)] @@ -22,7 +23,7 @@ use v1::types::{Bytes, H512}; pub struct EncryptedDocumentKey { /// Common encryption point. Pass this to Secret Store 'Document key storing session' pub common_point: H512, - /// Ecnrypted point. Pass this to Secret Store 'Document key storing session'. + /// Encrypted point. Pass this to Secret Store 'Document key storing session'. pub encrypted_point: H512, /// Document key itself, encrypted with passed account public. Pass this to 'secretstore_encrypt'. pub encrypted_key: Bytes, diff --git a/rpc/src/v1/types/sync.rs b/rpc/src/v1/types/sync.rs index e51c853ad91..10094742c0a 100644 --- a/rpc/src/v1/types/sync.rs +++ b/rpc/src/v1/types/sync.rs @@ -16,9 +16,10 @@ use network::client_version::ClientVersion; use std::collections::BTreeMap; + +use ethereum_types::{U256, H512}; use sync::{self, PeerInfo as SyncPeerInfo, TransactionStats as SyncTransactionStats}; use serde::{Serialize, Serializer}; -use v1::types::{U256, H512}; /// Sync info #[derive(Default, Debug, Serialize, PartialEq)] diff --git a/rpc/src/v1/types/trace.rs b/rpc/src/v1/types/trace.rs index 209523d3f86..715ffe62c58 100644 --- a/rpc/src/v1/types/trace.rs +++ b/rpc/src/v1/types/trace.rs @@ -19,14 +19,14 @@ use std::collections::BTreeMap; use ethcore::client::Executed; use ethcore::trace as et; use ethcore::trace::{FlatTrace, LocalizedTrace as EthLocalizedTrace, trace, TraceError}; -use ethereum_types::H256 as EthH256; +use ethereum_types::{H160, H256, U256}; use serde::ser::SerializeStruct; use serde::{Serialize, Serializer}; use types::account_diff; use types::state_diff; use vm; -use v1::types::{Bytes, H160, H256, U256}; +use v1::types::Bytes; #[derive(Debug, Serialize)] /// A diff of some chunk of memory. @@ -639,8 +639,8 @@ pub struct TraceResultsWithTransactionHash { pub transaction_hash: H256, } -impl From<(EthH256, Executed)> for TraceResultsWithTransactionHash { - fn from(t: (EthH256, Executed)) -> Self { +impl From<(H256, Executed)> for TraceResultsWithTransactionHash { + fn from(t: (H256, Executed)) -> Self { TraceResultsWithTransactionHash { output: t.1.output.into(), trace: t.1.trace.into_iter().map(Into::into).collect(), diff --git a/rpc/src/v1/types/trace_filter.rs b/rpc/src/v1/types/trace_filter.rs index d5ef60f47b4..a455c3d1cc2 100644 --- a/rpc/src/v1/types/trace_filter.rs +++ b/rpc/src/v1/types/trace_filter.rs @@ -18,7 +18,8 @@ use ethcore::client::BlockId; use ethcore::client; -use v1::types::{BlockNumber, H160}; +use ethereum_types::H160; +use v1::types::BlockNumber; /// Trace filter #[derive(Debug, PartialEq, Deserialize)] diff --git a/rpc/src/v1/types/transaction.rs b/rpc/src/v1/types/transaction.rs index dc7d6b5a152..72b591a89f7 100644 --- a/rpc/src/v1/types/transaction.rs +++ b/rpc/src/v1/types/transaction.rs @@ -19,9 +19,10 @@ use std::sync::Arc; use serde::{Serialize, Serializer}; use serde::ser::SerializeStruct; use ethcore::{contract_address, CreateContractAddress}; +use ethereum_types::{H160, H256, H512, U64, U256}; use miner; use types::transaction::{LocalizedTransaction, Action, PendingTransaction, SignedTransaction}; -use v1::types::{Bytes, H160, H256, U256, H512, U64, TransactionCondition}; +use v1::types::{Bytes, TransactionCondition}; /// Transaction #[derive(Debug, Default, Clone, PartialEq, Serialize)] diff --git a/rpc/src/v1/types/transaction_request.rs b/rpc/src/v1/types/transaction_request.rs index e7a2126b405..a4698cafa76 100644 --- a/rpc/src/v1/types/transaction_request.rs +++ b/rpc/src/v1/types/transaction_request.rs @@ -16,7 +16,8 @@ //! `TransactionRequest` type -use v1::types::{Bytes, H160, U256, TransactionCondition}; +use ethereum_types::{H160, U256}; +use v1::types::{Bytes, TransactionCondition}; use v1::helpers; use ansi_term::Colour; @@ -137,7 +138,8 @@ mod tests { use std::str::FromStr; use rustc_hex::FromHex; use serde_json; - use v1::types::{U256, H160, TransactionCondition}; + use v1::types::TransactionCondition; + use ethereum_types::{H160, U256}; use super::*; #[test] diff --git a/rpc/src/v1/types/work.rs b/rpc/src/v1/types/work.rs index b7c312162bd..ed6c7c8e917 100644 --- a/rpc/src/v1/types/work.rs +++ b/rpc/src/v1/types/work.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use super::{H256, U256}; +use ethereum_types::{H256, U256}; use serde::{Serialize, Serializer}; From e766a406e3bfb0e301e1d10fefb192f724c28768 Mon Sep 17 00:00:00 2001 From: niklasad1 Date: Sat, 19 Jan 2019 21:47:43 +0100 Subject: [PATCH 02/13] fix(tests) --- rpc/src/v1/helpers/dispatch.rs | 876 ++++++++++++++++++++++++++++ rpc/src/v1/helpers/subscribers.rs | 3 +- rpc/src/v1/tests/mocked/parity.rs | 2 +- rpc/src/v1/tests/mocked/personal.rs | 4 +- rpc/src/v1/tests/mocked/signer.rs | 2 +- rpc/src/v1/types/block.rs | 12 +- rpc/src/v1/types/mod.rs | 1 - 7 files changed, 888 insertions(+), 12 deletions(-) create mode 100644 rpc/src/v1/helpers/dispatch.rs diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs new file mode 100644 index 00000000000..93bfe92e326 --- /dev/null +++ b/rpc/src/v1/helpers/dispatch.rs @@ -0,0 +1,876 @@ +// Copyright 2015-2019 Parity Technologies (UK) Ltd. +// This file is part of Parity Ethereum. + +// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . + +//! Utilities and helpers for transaction dispatch. + +use std::fmt::Debug; +use std::ops::Deref; +use std::sync::Arc; + +use light::cache::Cache as LightDataCache; +use light::client::LightChainClient; +use light::on_demand::{request, OnDemand}; +use light::TransactionQueue as LightTransactionQueue; +use hash::keccak; +use ethereum_types::{H256, H520, Address, U256}; +use bytes::Bytes; +use parking_lot::{Mutex, RwLock}; +use stats::Corpus; + +use crypto::DEFAULT_MAC; +use ethcore::account_provider::AccountProvider; +use ethcore::client::BlockChainClient; +use ethcore::miner::{self, MinerService}; +use ethkey::{Password, Signature}; +use sync::LightSync; +use types::transaction::{Action, SignedTransaction, PendingTransaction, Transaction, Error as TransactionError}; +use types::basic_account::BasicAccount; +use types::ids::BlockId; + +use jsonrpc_core::{BoxFuture, Result, Error}; +use jsonrpc_core::futures::{future, Future, Poll, Async, IntoFuture}; +use jsonrpc_core::futures::future::Either; +use v1::helpers::{errors, nonce, TransactionRequest, FilledTransactionRequest, ConfirmationPayload}; +use v1::types::{ + Bytes as RpcBytes, + RichRawTransaction as RpcRichRawTransaction, + ConfirmationPayload as RpcConfirmationPayload, + ConfirmationResponse, + EthSignRequest as RpcEthSignRequest, + EIP191SignRequest as RpcSignRequest, + DecryptRequest as RpcDecryptRequest, +}; +use rlp; + +pub use self::nonce::Reservations; + +/// Has the capability to dispatch, sign, and decrypt. +/// +/// Requires a clone implementation, with the implication that it be cheap; +/// usually just bumping a reference count or two. +pub trait Dispatcher: Send + Sync + Clone { + // TODO: when ATC exist, use zero-cost + // type Out: IntoFuture + + /// Fill optional fields of a transaction request, fetching gas price but not nonce. + fn fill_optional_fields(&self, request: TransactionRequest, default_sender: Address, force_nonce: bool) + -> BoxFuture; + + /// Sign the given transaction request, fetching appropriate nonce and executing the PostSign action + fn sign

( + &self, + accounts: Arc, + filled: FilledTransactionRequest, + password: SignWith, + post_sign: P + ) -> BoxFuture + where + P: PostSign + 'static, + ::Future: Send; + + /// Converts a `SignedTransaction` into `RichRawTransaction` + fn enrich(&self, signed: SignedTransaction) -> RpcRichRawTransaction; + + /// "Dispatch" a local transaction. + fn dispatch_transaction(&self, signed_transaction: PendingTransaction) + -> Result; +} + +/// A dispatcher which uses references to a client and miner in order to sign +/// requests locally. +#[derive(Debug)] +pub struct FullDispatcher { + client: Arc, + miner: Arc, + nonces: Arc>, + gas_price_percentile: usize, +} + +impl FullDispatcher { + /// Create a `FullDispatcher` from Arc references to a client and miner. + pub fn new( + client: Arc, + miner: Arc, + nonces: Arc>, + gas_price_percentile: usize, + ) -> Self { + FullDispatcher { + client, + miner, + nonces, + gas_price_percentile, + } + } +} + +impl Clone for FullDispatcher { + fn clone(&self) -> Self { + FullDispatcher { + client: self.client.clone(), + miner: self.miner.clone(), + nonces: self.nonces.clone(), + gas_price_percentile: self.gas_price_percentile, + } + } +} + +impl FullDispatcher { + fn state_nonce(&self, from: &Address) -> U256 { + self.miner.next_nonce(&*self.client, from) + } + + /// Imports transaction to the miner's queue. + pub fn dispatch_transaction(client: &C, miner: &M, signed_transaction: PendingTransaction, trusted: bool) -> Result { + let hash = signed_transaction.transaction.hash(); + + // use `import_claimed_local_transaction` so we can decide (based on config flags) if we want to treat + // it as local or not. Nodes with public RPC interfaces will want these transactions to be treated like + // external transactions. + miner.import_claimed_local_transaction(client, signed_transaction, trusted) + .map_err(errors::transaction) + .map(|_| hash) + } +} + +impl Dispatcher for FullDispatcher { + fn fill_optional_fields(&self, request: TransactionRequest, default_sender: Address, force_nonce: bool) + -> BoxFuture + { + let request = request; + let from = request.from.unwrap_or(default_sender); + let nonce = if force_nonce { + request.nonce.or_else(|| Some(self.state_nonce(&from))) + } else { + request.nonce + }; + + Box::new(future::ok(FilledTransactionRequest { + from, + used_default_from: request.from.is_none(), + to: request.to, + nonce, + gas_price: request.gas_price.unwrap_or_else(|| { + default_gas_price(&*self.client, &*self.miner, self.gas_price_percentile) + }), + gas: request.gas.unwrap_or_else(|| self.miner.sensible_gas_limit()), + value: request.value.unwrap_or_else(|| 0.into()), + data: request.data.unwrap_or_else(Vec::new), + condition: request.condition, + })) + } + + fn sign

( + &self, + accounts: Arc, + filled: FilledTransactionRequest, + password: SignWith, + post_sign: P + ) -> BoxFuture + where + P: PostSign + 'static, + ::Future: Send + { + let chain_id = self.client.signing_chain_id(); + + if let Some(nonce) = filled.nonce { + let future = sign_transaction(&*accounts, filled, chain_id, nonce, password) + .into_future() + .and_then(move |signed| post_sign.execute(signed)); + Box::new(future) + } else { + let state = self.state_nonce(&filled.from); + let reserved = self.nonces.lock().reserve(filled.from, state); + + Box::new(ProspectiveSigner::new(accounts, filled, chain_id, reserved, password, post_sign)) + } + } + + fn enrich(&self, signed_transaction: SignedTransaction) -> RpcRichRawTransaction { + RpcRichRawTransaction::from_signed(signed_transaction) + } + + fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result { + Self::dispatch_transaction(&*self.client, &*self.miner, signed_transaction, true) + } +} + +/// Get a recent gas price corpus. +// TODO: this could be `impl Trait`. +pub fn fetch_gas_price_corpus( + sync: Arc, + client: Arc, + on_demand: Arc, + cache: Arc>, +) -> BoxFuture> { + const GAS_PRICE_SAMPLE_SIZE: usize = 100; + + if let Some(cached) = { cache.lock().gas_price_corpus() } { + return Box::new(future::ok(cached)) + } + + let cache = cache.clone(); + let eventual_corpus = sync.with_context(|ctx| { + // get some recent headers with gas used, + // and request each of the blocks from the network. + let block_requests = client.ancestry_iter(BlockId::Latest) + .filter(|hdr| hdr.gas_used() != U256::default()) + .take(GAS_PRICE_SAMPLE_SIZE) + .map(|hdr| request::Body(hdr.into())) + .collect::>(); + + // when the blocks come in, collect gas prices into a vector + on_demand.request(ctx, block_requests) + .expect("no back-references; therefore all back-references are valid; qed") + .map(|bodies| { + bodies.into_iter().fold(Vec::new(), |mut v, block| { + for t in block.transaction_views().iter() { + v.push(t.gas_price()) + } + v + }) + }) + .map(move |prices| { + // produce a corpus from the vector and cache it. + // It's later used to get a percentile for default gas price. + let corpus: ::stats::Corpus<_> = prices.into(); + cache.lock().set_gas_price_corpus(corpus.clone()); + corpus + }) + }); + + match eventual_corpus { + Some(corp) => Box::new(corp.map_err(|_| errors::no_light_peers())), + None => Box::new(future::err(errors::network_disabled())), + } +} + +/// Returns a eth_sign-compatible hash of data to sign. +/// The data is prepended with special message to prevent +/// malicious DApps from using the function to sign forged transactions. +pub fn eth_data_hash(mut data: Bytes) -> H256 { + let mut message_data = + format!("\x19Ethereum Signed Message:\n{}", data.len()) + .into_bytes(); + message_data.append(&mut data); + keccak(message_data) +} + +/// Dispatcher for light clients -- fetches default gas price, next nonce, etc. from network. +#[derive(Clone)] +pub struct LightDispatcher { + /// Sync service. + pub sync: Arc, + /// Header chain client. + pub client: Arc, + /// On-demand request service. + pub on_demand: Arc, + /// Data cache. + pub cache: Arc>, + /// Transaction queue. + pub transaction_queue: Arc>, + /// Nonce reservations + pub nonces: Arc>, + /// Gas Price percentile value used as default gas price. + pub gas_price_percentile: usize, +} + +impl LightDispatcher { + /// Create a new `LightDispatcher` from its requisite parts. + /// + /// For correct operation, the OnDemand service is assumed to be registered as a network handler, + pub fn new( + sync: Arc, + client: Arc, + on_demand: Arc, + cache: Arc>, + transaction_queue: Arc>, + nonces: Arc>, + gas_price_percentile: usize, + ) -> Self { + LightDispatcher { + sync, + client, + on_demand, + cache, + transaction_queue, + nonces, + gas_price_percentile, + } + } + + /// Get a recent gas price corpus. + // TODO: this could be `impl Trait`. + pub fn gas_price_corpus(&self) -> BoxFuture> { + fetch_gas_price_corpus( + self.sync.clone(), + self.client.clone(), + self.on_demand.clone(), + self.cache.clone(), + ) + } + + /// Get an account's state + fn account(&self, addr: Address) -> BoxFuture> { + let best_header = self.client.best_block_header(); + let account_future = self.sync.with_context(|ctx| self.on_demand.request(ctx, request::Account { + header: best_header.into(), + address: addr, + }).expect("no back-references; therefore all back-references valid; qed")); + + match account_future { + Some(response) => Box::new(response.map_err(|_| errors::no_light_peers())), + None => Box::new(future::err(errors::network_disabled())), + } + } + + /// Get an account's next nonce. + pub fn next_nonce(&self, addr: Address) -> BoxFuture { + let account_start_nonce = self.client.engine().account_start_nonce(self.client.best_block_header().number()); + Box::new(self.account(addr) + .and_then(move |maybe_account| { + future::ok(maybe_account.map_or(account_start_nonce, |account| account.nonce)) + }) + ) + } +} + +impl Dispatcher for LightDispatcher { + // Ignore the `force_nonce` flag in order to always query the network when fetching the nonce and + // the account state. If the nonce is specified in the transaction use that nonce instead but do the + // network request anyway to the account state (balance) + fn fill_optional_fields(&self, request: TransactionRequest, default_sender: Address, _force_nonce: bool) + -> BoxFuture + { + const DEFAULT_GAS_PRICE: U256 = U256([0, 0, 0, 21_000_000]); + + let gas_limit = self.client.best_block_header().gas_limit(); + let request_gas_price = request.gas_price.clone(); + let from = request.from.unwrap_or(default_sender); + + let with_gas_price = move |gas_price| { + let request = request; + FilledTransactionRequest { + from: from.clone(), + used_default_from: request.from.is_none(), + to: request.to, + nonce: request.nonce, + gas_price: gas_price, + gas: request.gas.unwrap_or_else(|| gas_limit / 3), + value: request.value.unwrap_or_else(|| 0.into()), + data: request.data.unwrap_or_else(Vec::new), + condition: request.condition, + } + }; + + // fast path for known gas price. + let gas_price_percentile = self.gas_price_percentile; + let gas_price = match request_gas_price { + Some(gas_price) => Either::A(future::ok(with_gas_price(gas_price))), + None => Either::B(fetch_gas_price_corpus( + self.sync.clone(), + self.client.clone(), + self.on_demand.clone(), + self.cache.clone() + ).and_then(move |corp| match corp.percentile(gas_price_percentile) { + Some(percentile) => Ok(*percentile), + None => Ok(DEFAULT_GAS_PRICE), // fall back to default on error. + }).map(with_gas_price)) + }; + + let future_account = self.account(from); + + Box::new(gas_price.and_then(move |mut filled| { + future_account + .and_then(move |maybe_account| { + let cost = filled.value.saturating_add(filled.gas.saturating_mul(filled.gas_price)); + match maybe_account { + Some(ref account) if cost > account.balance => { + Err(errors::transaction(TransactionError::InsufficientBalance { + balance: account.balance, + cost, + })) + } + Some(account) => { + if filled.nonce.is_none() { + filled.nonce = Some(account.nonce); + } + Ok(filled) + } + None => Err(errors::account("Account not found", "")), + } + }) + })) + } + + fn sign

( + &self, + accounts: Arc, + filled: FilledTransactionRequest, + password: SignWith, + post_sign: P + ) -> BoxFuture + where + P: PostSign + 'static, + ::Future: Send + { + let chain_id = self.client.signing_chain_id(); + let nonce = filled.nonce.expect("nonce is always provided; qed"); + + let future = sign_transaction(&*accounts, filled, chain_id, nonce, password) + .into_future() + .and_then(move |signed| post_sign.execute(signed)); + Box::new(future) + } + + fn enrich(&self, signed_transaction: SignedTransaction) -> RpcRichRawTransaction { + RpcRichRawTransaction::from_signed(signed_transaction) + } + + fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result { + let hash = signed_transaction.transaction.hash(); + + self.transaction_queue.write().import(signed_transaction) + .map_err(errors::transaction) + .map(|_| hash) + } +} + +fn sign_transaction( + accounts: &AccountProvider, + filled: FilledTransactionRequest, + chain_id: Option, + nonce: U256, + password: SignWith, +) -> Result> { + let t = Transaction { + nonce: nonce, + action: filled.to.map_or(Action::Create, Action::Call), + gas: filled.gas, + gas_price: filled.gas_price, + value: filled.value, + data: filled.data, + }; + + if accounts.is_hardware_address(&filled.from) { + return hardware_signature(accounts, filled.from, t, chain_id).map(WithToken::No) + } + + let hash = t.hash(chain_id); + let signature = signature(accounts, filled.from, hash, password)?; + + Ok(signature.map(|sig| { + SignedTransaction::new(t.with_signature(sig, chain_id)) + .expect("Transaction was signed by AccountsProvider; it never produces invalid signatures; qed") + })) +} + +#[derive(Debug, Clone, Copy)] +enum ProspectiveSignerState { + TryProspectiveSign, + WaitForPostSign, + WaitForNonce, +} + +struct ProspectiveSigner { + accounts: Arc, + filled: FilledTransactionRequest, + chain_id: Option, + reserved: nonce::Reserved, + password: SignWith, + state: ProspectiveSignerState, + prospective: Option>, + ready: Option, + post_sign: Option

, + post_sign_future: Option<::Future> +} + +/// action to execute after signing +/// e.g importing a transaction into the chain +pub trait PostSign: Send { + /// item that this PostSign returns + type Item: Send; + /// incase you need to perform async PostSign actions + type Out: IntoFuture + Send; + /// perform an action with the signed transaction + fn execute(self, signer: WithToken) -> Self::Out; +} + +impl PostSign for () { + type Item = WithToken; + type Out = Result; + fn execute(self, signed: WithToken) -> Self::Out { + Ok(signed) + } +} + +impl PostSign for F + where F: FnOnce(WithToken) -> Result +{ + type Item = T; + type Out = Result; + fn execute(self, signed: WithToken) -> Self::Out { + (self)(signed) + } +} + +impl ProspectiveSigner

{ + pub fn new( + accounts: Arc, + filled: FilledTransactionRequest, + chain_id: Option, + reserved: nonce::Reserved, + password: SignWith, + post_sign: P + ) -> Self { + // If the account is permanently unlocked we can try to sign + // using prospective nonce. This should speed up sending + // multiple subsequent transactions in multi-threaded RPC environment. + let is_unlocked_permanently = accounts.is_unlocked_permanently(&filled.from); + let has_password = password.is_password(); + + ProspectiveSigner { + accounts, + filled, + chain_id, + reserved, + password, + state: if is_unlocked_permanently || has_password { + ProspectiveSignerState::TryProspectiveSign + } else { + ProspectiveSignerState::WaitForNonce + }, + prospective: None, + ready: None, + post_sign: Some(post_sign), + post_sign_future: None + } + } + + fn sign(&self, nonce: &U256) -> Result> { + sign_transaction( + &*self.accounts, + self.filled.clone(), + self.chain_id, + *nonce, + self.password.clone() + ) + } + + fn poll_reserved(&mut self) -> Poll { + self.reserved.poll().map_err(|_| errors::internal("Nonce reservation failure", "")) + } +} + +impl Future for ProspectiveSigner

{ + type Item = P::Item; + type Error = Error; + + fn poll(&mut self) -> Poll { + use self::ProspectiveSignerState::*; + + loop { + match self.state { + TryProspectiveSign => { + // Try to poll reserved, it might be ready. + match self.poll_reserved()? { + Async::NotReady => { + self.state = WaitForNonce; + self.prospective = Some(self.sign(self.reserved.prospective_value())?); + }, + Async::Ready(nonce) => { + self.state = WaitForPostSign; + self.post_sign_future = Some(self.post_sign.take() + .expect("post_sign is set on creation; qed") + .execute(self.sign(nonce.value())?) + .into_future()); + self.ready = Some(nonce); + }, + } + }, + WaitForNonce => { + let nonce = try_ready!(self.poll_reserved()); + let prospective = match (self.prospective.take(), nonce.matches_prospective()) { + (Some(prospective), true) => prospective, + _ => self.sign(nonce.value())?, + }; + self.ready = Some(nonce); + self.state = WaitForPostSign; + self.post_sign_future = Some(self.post_sign.take() + .expect("post_sign is set on creation; qed") + .execute(prospective) + .into_future()); + }, + WaitForPostSign => { + if let Some(mut fut) = self.post_sign_future.as_mut() { + match fut.poll()? { + Async::Ready(item) => { + let nonce = self.ready + .take() + .expect("nonce is set before state transitions to WaitForPostSign; qed"); + nonce.mark_used(); + return Ok(Async::Ready(item)) + }, + Async::NotReady => { + return Ok(Async::NotReady) + } + } + } else { + panic!("Poll after ready."); + } + } + } + } + } +} + +/// Single-use account token. +pub type AccountToken = Password; + +/// Values used to unlock accounts for signing. +#[derive(Clone, PartialEq)] +pub enum SignWith { + /// Nothing -- implies the account is already unlocked. + Nothing, + /// Unlock with password. + Password(Password), + /// Unlock with single-use token. + Token(AccountToken), +} + +impl SignWith { + fn is_password(&self) -> bool { + if let SignWith::Password(_) = *self { + true + } else { + false + } + } +} + +/// A value, potentially accompanied by a signing token. +pub enum WithToken { + /// No token. + No(T), + /// With token. + Yes(T, AccountToken), +} + +impl Deref for WithToken { + type Target = T; + + fn deref(&self) -> &Self::Target { + match *self { + WithToken::No(ref v) => v, + WithToken::Yes(ref v, _) => v, + } + } +} + +impl WithToken { + /// Map the value with the given closure, preserving the token. + pub fn map(self, f: F) -> WithToken where + S: Debug, + F: FnOnce(T) -> S, + { + match self { + WithToken::No(v) => WithToken::No(f(v)), + WithToken::Yes(v, token) => WithToken::Yes(f(v), token), + } + } + + /// Convert into inner value, ignoring possible token. + pub fn into_value(self) -> T { + match self { + WithToken::No(v) => v, + WithToken::Yes(v, _) => v, + } + } + + /// Convert the `WithToken` into a tuple. + pub fn into_tuple(self) -> (T, Option) { + match self { + WithToken::No(v) => (v, None), + WithToken::Yes(v, token) => (v, Some(token)) + } + } +} + +impl From<(T, AccountToken)> for WithToken { + fn from(tuple: (T, AccountToken)) -> Self { + WithToken::Yes(tuple.0, tuple.1) + } +} + +impl From<(T, Option)> for WithToken { + fn from(tuple: (T, Option)) -> Self { + match tuple.1 { + Some(token) => WithToken::Yes(tuple.0, token), + None => WithToken::No(tuple.0), + } + } +} + +/// Execute a confirmation payload. +pub fn execute( + dispatcher: D, + accounts: Arc, + payload: ConfirmationPayload, + pass: SignWith +) -> BoxFuture> { + match payload { + ConfirmationPayload::SendTransaction(request) => { + let condition = request.condition.clone().map(Into::into); + let cloned_dispatcher = dispatcher.clone(); + let post_sign = move |with_token_signed: WithToken| { + let (signed, token) = with_token_signed.into_tuple(); + let signed_transaction = PendingTransaction::new(signed, condition); + cloned_dispatcher.dispatch_transaction(signed_transaction) + .map(|hash| (hash, token)) + }; + let future = dispatcher.sign(accounts, request, pass, post_sign) + .map(|(hash, token)| { + WithToken::from((ConfirmationResponse::SendTransaction(hash.into()), token)) + }); + Box::new(future) + }, + ConfirmationPayload::SignTransaction(request) => { + Box::new(dispatcher.sign(accounts, request, pass, ()) + .map(move |result| result + .map(move |tx| dispatcher.enrich(tx)) + .map(ConfirmationResponse::SignTransaction) + )) + }, + ConfirmationPayload::EthSignMessage(address, data) => { + if accounts.is_hardware_address(&address) { + let signature = accounts.sign_message_with_hardware(&address, &data) + .map(|s| H520(s.into_electrum())) + .map(ConfirmationResponse::Signature) + .map(WithToken::No) + .map_err(|e| errors::account("Error signing message with hardware_wallet", e)); + + return Box::new(future::done(signature)); + } + let hash = eth_data_hash(data); + let res = signature(&accounts, address, hash, pass) + .map(|result| result + .map(|rsv| H520(rsv.into_electrum())) + .map(ConfirmationResponse::Signature) + ); + Box::new(future::done(res)) + }, + ConfirmationPayload::SignMessage(address, data) => { + if accounts.is_hardware_address(&address) { + return Box::new(future::err(errors::account("Error signing message with hardware_wallet", + "Message signing is unsupported"))); + } + let res = signature(&accounts, address, data, pass) + .map(|result| result + .map(|rsv| H520(rsv.into_electrum())) + // .map(RpcH520::from) + .map(ConfirmationResponse::Signature) + ); + Box::new(future::done(res)) + }, + ConfirmationPayload::Decrypt(address, data) => { + if accounts.is_hardware_address(&address) { + return Box::new(future::err(errors::unsupported("Decrypting via hardware wallets is not supported.", None))); + } + let res = decrypt(&accounts, address, data, pass) + .map(|result| result + .map(RpcBytes) + .map(ConfirmationResponse::Decrypt) + ); + Box::new(future::done(res)) + }, + } +} + +fn signature(accounts: &AccountProvider, address: Address, hash: H256, password: SignWith) -> Result> { + match password.clone() { + SignWith::Nothing => accounts.sign(address, None, hash).map(WithToken::No), + SignWith::Password(pass) => accounts.sign(address, Some(pass), hash).map(WithToken::No), + SignWith::Token(token) => accounts.sign_with_token(address, token, hash).map(Into::into), + }.map_err(|e| match password { + SignWith::Nothing => errors::signing(e), + _ => errors::password(e), + }) +} + +// obtain a hardware signature from the given account. +fn hardware_signature(accounts: &AccountProvider, address: Address, t: Transaction, chain_id: Option) + -> Result +{ + debug_assert!(accounts.is_hardware_address(&address)); + + let mut stream = rlp::RlpStream::new(); + t.rlp_append_unsigned_transaction(&mut stream, chain_id); + let signature = accounts.sign_transaction_with_hardware(&address, &t, chain_id, &stream.as_raw()) + .map_err(|e| { + debug!(target: "miner", "Error signing transaction with hardware wallet: {}", e); + errors::account("Error signing transaction with hardware wallet", e) + })?; + + SignedTransaction::new(t.with_signature(signature, chain_id)) + .map_err(|e| { + debug!(target: "miner", "Hardware wallet has produced invalid signature: {}", e); + errors::account("Invalid signature generated", e) + }) +} + +fn decrypt(accounts: &AccountProvider, address: Address, msg: Bytes, password: SignWith) -> Result> { + match password.clone() { + SignWith::Nothing => accounts.decrypt(address, None, &DEFAULT_MAC, &msg).map(WithToken::No), + SignWith::Password(pass) => accounts.decrypt(address, Some(pass), &DEFAULT_MAC, &msg).map(WithToken::No), + SignWith::Token(token) => accounts.decrypt_with_token(address, token, &DEFAULT_MAC, &msg).map(Into::into), + }.map_err(|e| match password { + SignWith::Nothing => errors::signing(e), + _ => errors::password(e), + }) +} + +/// Extract the default gas price from a client and miner. +pub fn default_gas_price(client: &C, miner: &M, percentile: usize) -> U256 where + C: BlockChainClient, + M: MinerService, +{ + client.gas_price_corpus(100).percentile(percentile).cloned().unwrap_or_else(|| miner.sensible_gas_price()) +} + +/// Convert RPC confirmation payload to signer confirmation payload. +/// May need to resolve in the future to fetch things like gas price. +pub fn from_rpc(payload: RpcConfirmationPayload, default_account: Address, dispatcher: &D) -> BoxFuture + where D: Dispatcher +{ + match payload { + RpcConfirmationPayload::SendTransaction(request) => { + Box::new(dispatcher.fill_optional_fields(request.into(), default_account, false) + .map(ConfirmationPayload::SendTransaction)) + }, + RpcConfirmationPayload::SignTransaction(request) => { + Box::new(dispatcher.fill_optional_fields(request.into(), default_account, false) + .map(ConfirmationPayload::SignTransaction)) + }, + RpcConfirmationPayload::Decrypt(RpcDecryptRequest { address, msg }) => { + Box::new(future::ok(ConfirmationPayload::Decrypt(address.into(), msg.into()))) + }, + RpcConfirmationPayload::EthSignMessage(RpcEthSignRequest { address, data }) => { + Box::new(future::ok(ConfirmationPayload::EthSignMessage(address.into(), data.into()))) + }, + RpcConfirmationPayload::EIP191SignMessage(RpcSignRequest { address, data }) => { + Box::new(future::ok(ConfirmationPayload::SignMessage(address.into(), data.into()))) + }, + } +} diff --git a/rpc/src/v1/helpers/subscribers.rs b/rpc/src/v1/helpers/subscribers.rs index 0fce8892cfc..59e15ecc0f9 100644 --- a/rpc/src/v1/helpers/subscribers.rs +++ b/rpc/src/v1/helpers/subscribers.rs @@ -22,6 +22,7 @@ use jsonrpc_pubsub::{typed::{Subscriber, Sink}, SubscriptionId}; use ethereum_types::H64; use rand::{Rng, StdRng}; +// FIXME: This type is needless use `serde_json::to_string` instead #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct Id(H64); impl str::FromStr for Id { @@ -37,7 +38,7 @@ impl str::FromStr for Id { } impl Id { pub fn as_string(&self) -> String { - format!("0x{:?}", self.0) + format!("{:?}", self.0) } } diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index 6608589f557..d8b4779faf9 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -574,7 +574,7 @@ fn rpc_parity_verify_signature() { "0xe552acf4caabe9661893fd48c7b5e68af20bf007193442f8ca05ce836699d75e", "0x2089e84151c3cdc45255c07557b349f5bf2ed3e68f6098723eaa90a0f8b2b3e5", "0x5f70e8df7bd0c4417afb5f5a39d82e15d03adeff8796725d8b14889ed1d1aa8a", - "0x1" + 1 ], "id": 0 }"#; diff --git a/rpc/src/v1/tests/mocked/personal.rs b/rpc/src/v1/tests/mocked/personal.rs index 0da6f46068b..a2d6b87ce26 100644 --- a/rpc/src/v1/tests/mocked/personal.rs +++ b/rpc/src/v1/tests/mocked/personal.rs @@ -156,7 +156,7 @@ fn sign() { let hash = eth_data_hash(data); let signature = H520(tester.accounts.sign(address, Some("password123".into()), hash).unwrap().into_electrum()); - let signature = format!("0x{:?}", signature); + let signature = format!("{:?}", signature); let response = r#"{"jsonrpc":"2.0","result":""#.to_owned() + &signature + r#"","id":1}"#; @@ -264,7 +264,7 @@ fn ec_recover() { let hash = eth_data_hash(data.clone()); let signature = H520(tester.accounts.sign(address, Some("password123".into()), hash).unwrap().into_electrum()); - let signature = format!("0x{:?}", signature); + let signature = format!("{:?}", signature); let request = r#"{ "jsonrpc": "2.0", diff --git a/rpc/src/v1/tests/mocked/signer.rs b/rpc/src/v1/tests/mocked/signer.rs index 492eee81855..e22c5b8d249 100644 --- a/rpc/src/v1/tests/mocked/signer.rs +++ b/rpc/src/v1/tests/mocked/signer.rs @@ -495,7 +495,7 @@ fn should_confirm_data_sign_with_signature() { let data_hash = eth_data_hash(vec![1, 2, 3, 4].into()); let signature = H520(tester.accounts.sign(address, Some("test".into()), data_hash).unwrap().into_electrum()); - let signature = format!("0x{:?}", signature); + let signature = format!("{:?}", signature); // when let request = r#"{ diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index 258acad8ef3..86078ee61bf 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -252,8 +252,8 @@ mod tests { let rich_block = RichBlock { inner: block, extra_info: map![ - "mixHash".into() => format!("0x{:?}", H256::default()), - "nonce".into() => format!("0x{:?}", H64::default()) + "mixHash".into() => format!("{:?}", H256::default()), + "nonce".into() => format!("{:?}", H64::default()) ], }; let serialized_rich_block = serde_json::to_string(&rich_block).unwrap(); @@ -290,8 +290,8 @@ mod tests { let rich_block = RichBlock { inner: block, extra_info: map![ - "mixHash".into() => format!("0x{:?}", H256::default()), - "nonce".into() => format!("0x{:?}", H64::default()) + "mixHash".into() => format!("{:?}", H256::default()), + "nonce".into() => format!("{:?}", H64::default()) ], }; let serialized_rich_block = serde_json::to_string(&rich_block).unwrap(); @@ -325,8 +325,8 @@ mod tests { let rich_header = RichHeader { inner: header, extra_info: map![ - "mixHash".into() => format!("0x{:?}", H256::default()), - "nonce".into() => format!("0x{:?}", H64::default()) + "mixHash".into() => format!("{:?}", H256::default()), + "nonce".into() => format!("{:?}", H64::default()) ], }; let serialized_rich_header = serde_json::to_string(&rich_header).unwrap(); diff --git a/rpc/src/v1/types/mod.rs b/rpc/src/v1/types/mod.rs index 45fb2467e18..d340d8c42ff 100644 --- a/rpc/src/v1/types/mod.rs +++ b/rpc/src/v1/types/mod.rs @@ -39,7 +39,6 @@ mod trace_filter; mod transaction; mod transaction_request; mod transaction_condition; -// mod uint; mod work; mod private_receipt; mod eip191; From 3ce514418517c2a562197be04c01ad8ef6b0986d Mon Sep 17 00:00:00 2001 From: niklasad1 Date: Sat, 19 Jan 2019 23:10:14 +0100 Subject: [PATCH 03/13] fix(cleanup) --- rpc/src/v1/helpers/dispatch.rs | 1 - rpc/src/v1/helpers/subscribers.rs | 2 +- rpc/src/v1/helpers/work.rs | 3 --- rpc/src/v1/impls/eth.rs | 16 +++++----------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs index 93bfe92e326..92360ec66dc 100644 --- a/rpc/src/v1/helpers/dispatch.rs +++ b/rpc/src/v1/helpers/dispatch.rs @@ -779,7 +779,6 @@ pub fn execute( let res = signature(&accounts, address, data, pass) .map(|result| result .map(|rsv| H520(rsv.into_electrum())) - // .map(RpcH520::from) .map(ConfirmationResponse::Signature) ); Box::new(future::done(res)) diff --git a/rpc/src/v1/helpers/subscribers.rs b/rpc/src/v1/helpers/subscribers.rs index 59e15ecc0f9..69af21f7381 100644 --- a/rpc/src/v1/helpers/subscribers.rs +++ b/rpc/src/v1/helpers/subscribers.rs @@ -22,7 +22,6 @@ use jsonrpc_pubsub::{typed::{Subscriber, Sink}, SubscriptionId}; use ethereum_types::H64; use rand::{Rng, StdRng}; -// FIXME: This type is needless use `serde_json::to_string` instead #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct Id(H64); impl str::FromStr for Id { @@ -37,6 +36,7 @@ impl str::FromStr for Id { } } impl Id { + // FIXME: [niklasad1] replace `format` with `serde_json::to_string_pretty` pub fn as_string(&self) -> String { format!("{:?}", self.0) } diff --git a/rpc/src/v1/helpers/work.rs b/rpc/src/v1/helpers/work.rs index c4278db172b..661b4cab8b8 100644 --- a/rpc/src/v1/helpers/work.rs +++ b/rpc/src/v1/helpers/work.rs @@ -27,9 +27,6 @@ use v1::helpers::errors; // Submit a POW work and return the block's hash pub fn submit_work_detail(client: &Arc, miner: &Arc, nonce: H64, pow_hash: H256, mix_hash: H256) -> Result { // TODO [ToDr] Should disallow submissions in case of PoA? - let nonce: H64 = nonce.into(); - let pow_hash: H256 = pow_hash.into(); - let mix_hash: H256 = mix_hash.into(); trace!(target: "miner", "submit_work_detail: Decoded: nonce={}, pow_hash={}, mix_hash={}", nonce, pow_hash, mix_hash); let seal = vec![rlp::encode(&mix_hash), rlp::encode(&nonce)]; let import = miner.submit_seal(pow_hash, seal) diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 1089415ea51..0da007cadf1 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -570,8 +570,6 @@ impl Eth for EthClient< } fn balance(&self, address: H160, num: Trailing) -> BoxFuture { - let address = address.into(); - let num = num.unwrap_or_default(); try_bf!(check_known(&*self.client, num.clone())); @@ -586,8 +584,7 @@ impl Eth for EthClient< fn proof(&self, address: H160, values: Vec, num: Trailing) -> BoxFuture { try_bf!(errors::require_experimental(self.options.allow_experimental_rpcs, "1186")); - let a: H160 = address.clone().into(); - let key1 = keccak(a); + let key1 = keccak(address); let num = num.unwrap_or_default(); let id = match num { @@ -625,10 +622,9 @@ impl Eth for EthClient< Box::new(future::done(res)) } - fn storage_at(&self, address: H160, pos: U256, num: Trailing) -> BoxFuture { - let address: Address = H160::into(address); - let position: U256 = U256::into(pos); + fn storage_at(&self, address: H160, pos: U256, num: Trailing) -> BoxFuture { + let address: Address = address.into(); let num = num.unwrap_or_default(); try_bf!(check_known(&*self.client, num.clone())); @@ -639,8 +635,9 @@ impl Eth for EthClient< Box::new(future::done(res)) } + fn transaction_count(&self, address: H160, num: Trailing) -> BoxFuture { - let address: Address = H160::into(address); + let address: Address = address.into(); let res = match num.unwrap_or_default() { BlockNumber::Pending if self.options.pending_nonce_from_queue => { @@ -749,7 +746,6 @@ impl Eth for EthClient< } fn transaction_by_hash(&self, hash: H256) -> BoxFuture> { - let hash: H256 = hash.into(); let tx = try_bf!(self.transaction(PendingTransactionId::Hash(hash))).or_else(|| { self.miner.transaction(&hash) .map(|t| Transaction::from_pending(t.pending().clone())) @@ -781,8 +777,6 @@ impl Eth for EthClient< } fn transaction_receipt(&self, hash: H256) -> BoxFuture> { - let hash: H256 = hash.into(); - if self.options.allow_pending_receipt_query { let best_block = self.client.chain_info().best_block_number; if let Some(receipt) = self.miner.pending_receipt(best_block, &hash) { From 0529056d3f7c76953443868c05632e7edcd3ed7d Mon Sep 17 00:00:00 2001 From: niklasad1 Date: Mon, 21 Jan 2019 09:59:03 +0100 Subject: [PATCH 04/13] grumbles(rpc-api): revert `verify_signature` * revert change of `U64` -> `u64` --- rpc/src/v1/helpers/signature.rs | 9 +++++---- rpc/src/v1/impls/light/parity.rs | 4 ++-- rpc/src/v1/impls/parity.rs | 4 ++-- rpc/src/v1/tests/mocked/parity.rs | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/rpc/src/v1/helpers/signature.rs b/rpc/src/v1/helpers/signature.rs index 651320f0235..32827ea1e11 100644 --- a/rpc/src/v1/helpers/signature.rs +++ b/rpc/src/v1/helpers/signature.rs @@ -15,7 +15,7 @@ // along with Parity Ethereum. If not, see . use ethkey::{recover, public_to_address, Signature}; -use ethereum_types::H256; +use ethereum_types::{H256, U64}; use jsonrpc_core::Result; use v1::types::{Bytes, RecoveredAccount}; use v1::helpers::errors; @@ -28,7 +28,7 @@ pub fn verify_signature( message: Bytes, r: H256, s: H256, - v: u64, + v: U64, chain_id: Option ) -> Result { let hash = if is_prefixed { @@ -36,6 +36,7 @@ pub fn verify_signature( } else { keccak(message.0) }; + let v = v.as_u64(); let is_valid_for_current_chain = match (chain_id, v) { (None, v) if v == 0 || v == 1 => true, (Some(chain_id), v) if v >= 35 => (v - 35) / 2 == chain_id, @@ -68,7 +69,7 @@ mod tests { } /// mocked signer - fn sign(should_prefix: bool, data: Vec, signing_chain_id: Option) -> (H160, [u8; 32], [u8; 32], u64) { + fn sign(should_prefix: bool, data: Vec, signing_chain_id: Option) -> (H160, [u8; 32], [u8; 32], U64) { let hash = if should_prefix { eth_data_hash(data) } else { keccak(data) }; let account = ethkey::Random.generate().unwrap(); let address = account.address(); @@ -81,7 +82,7 @@ mod tests { s_buf.copy_from_slice(s); (r_buf, s_buf) }; - (address.into(), r_buf, s_buf, v) + (address.into(), r_buf, s_buf, v.into()) } fn run_test(test_case: TestCase) { diff --git a/rpc/src/v1/impls/light/parity.rs b/rpc/src/v1/impls/light/parity.rs index 47d6cb01d21..da7425e1f4c 100644 --- a/rpc/src/v1/impls/light/parity.rs +++ b/rpc/src/v1/impls/light/parity.rs @@ -24,7 +24,7 @@ use crypto::DEFAULT_MAC; use ethkey::{crypto::ecies, Brain, Generator}; use ethstore::random_phrase; use sync::{LightSyncInfo, LightSyncProvider, LightNetworkDispatcher, ManageNetwork}; -use ethereum_types::{H64, H160, H256, H512, U256}; +use ethereum_types::{H64, H160, H256, H512, U64, U256}; use ethcore_logger::RotatingLogger; use jsonrpc_core::{Result, BoxFuture}; @@ -396,7 +396,7 @@ where Box::new(self.fetcher().logs_no_tx_hash(filter)) as BoxFuture<_> } - fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: u64) -> Result { + fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: U64) -> Result { verify_signature(is_prefixed, message, r, s, v, self.light_dispatch.client.signing_chain_id()) } } diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index 9f64c3973af..eb2408fcbe6 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -19,7 +19,7 @@ use std::sync::Arc; use std::str::FromStr; use std::collections::BTreeMap; -use ethereum_types::{Address, H64, H160, H256, H512, U256}; +use ethereum_types::{Address, H64, H160, H256, H512, U64, U256}; use version::version_data; use crypto::DEFAULT_MAC; @@ -473,7 +473,7 @@ impl Parity for ParityClient where base_logs(&*self.client, &*self.miner, filter.into()) } - fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: u64) -> Result { + fn verify_signature(&self, is_prefixed: bool, message: Bytes, r: H256, s: H256, v: U64) -> Result { verify_signature(is_prefixed, message, r, s, v, self.client.signing_chain_id()) } } diff --git a/rpc/src/v1/tests/mocked/parity.rs b/rpc/src/v1/tests/mocked/parity.rs index d8b4779faf9..6608589f557 100644 --- a/rpc/src/v1/tests/mocked/parity.rs +++ b/rpc/src/v1/tests/mocked/parity.rs @@ -574,7 +574,7 @@ fn rpc_parity_verify_signature() { "0xe552acf4caabe9661893fd48c7b5e68af20bf007193442f8ca05ce836699d75e", "0x2089e84151c3cdc45255c07557b349f5bf2ed3e68f6098723eaa90a0f8b2b3e5", "0x5f70e8df7bd0c4417afb5f5a39d82e15d03adeff8796725d8b14889ed1d1aa8a", - 1 + "0x1" ], "id": 0 }"#; From 390070b4d9e335d814062e2f05e1539704a4a96d Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Fri, 8 Feb 2019 15:32:28 +0100 Subject: [PATCH 05/13] fix(cleanup after bad merge) --- rpc/src/v1/helpers/dispatch.rs | 875 ---------------------- rpc/src/v1/helpers/dispatch/mod.rs | 4 +- rpc/src/v1/impls/eth.rs | 12 +- rpc/src/v1/impls/light/eth.rs | 16 +- rpc/src/v1/impls/parity.rs | 5 +- rpc/src/v1/impls/parity_accounts.rs | 10 +- rpc/src/v1/impls/parity_set.rs | 1 - rpc/src/v1/mod.rs | 2 +- rpc/src/v1/tests/mocked/signing_unsafe.rs | 2 +- rpc/src/v1/traits/eth.rs | 1 - 10 files changed, 24 insertions(+), 904 deletions(-) delete mode 100644 rpc/src/v1/helpers/dispatch.rs diff --git a/rpc/src/v1/helpers/dispatch.rs b/rpc/src/v1/helpers/dispatch.rs deleted file mode 100644 index 92360ec66dc..00000000000 --- a/rpc/src/v1/helpers/dispatch.rs +++ /dev/null @@ -1,875 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . - -//! Utilities and helpers for transaction dispatch. - -use std::fmt::Debug; -use std::ops::Deref; -use std::sync::Arc; - -use light::cache::Cache as LightDataCache; -use light::client::LightChainClient; -use light::on_demand::{request, OnDemand}; -use light::TransactionQueue as LightTransactionQueue; -use hash::keccak; -use ethereum_types::{H256, H520, Address, U256}; -use bytes::Bytes; -use parking_lot::{Mutex, RwLock}; -use stats::Corpus; - -use crypto::DEFAULT_MAC; -use ethcore::account_provider::AccountProvider; -use ethcore::client::BlockChainClient; -use ethcore::miner::{self, MinerService}; -use ethkey::{Password, Signature}; -use sync::LightSync; -use types::transaction::{Action, SignedTransaction, PendingTransaction, Transaction, Error as TransactionError}; -use types::basic_account::BasicAccount; -use types::ids::BlockId; - -use jsonrpc_core::{BoxFuture, Result, Error}; -use jsonrpc_core::futures::{future, Future, Poll, Async, IntoFuture}; -use jsonrpc_core::futures::future::Either; -use v1::helpers::{errors, nonce, TransactionRequest, FilledTransactionRequest, ConfirmationPayload}; -use v1::types::{ - Bytes as RpcBytes, - RichRawTransaction as RpcRichRawTransaction, - ConfirmationPayload as RpcConfirmationPayload, - ConfirmationResponse, - EthSignRequest as RpcEthSignRequest, - EIP191SignRequest as RpcSignRequest, - DecryptRequest as RpcDecryptRequest, -}; -use rlp; - -pub use self::nonce::Reservations; - -/// Has the capability to dispatch, sign, and decrypt. -/// -/// Requires a clone implementation, with the implication that it be cheap; -/// usually just bumping a reference count or two. -pub trait Dispatcher: Send + Sync + Clone { - // TODO: when ATC exist, use zero-cost - // type Out: IntoFuture - - /// Fill optional fields of a transaction request, fetching gas price but not nonce. - fn fill_optional_fields(&self, request: TransactionRequest, default_sender: Address, force_nonce: bool) - -> BoxFuture; - - /// Sign the given transaction request, fetching appropriate nonce and executing the PostSign action - fn sign

( - &self, - accounts: Arc, - filled: FilledTransactionRequest, - password: SignWith, - post_sign: P - ) -> BoxFuture - where - P: PostSign + 'static, - ::Future: Send; - - /// Converts a `SignedTransaction` into `RichRawTransaction` - fn enrich(&self, signed: SignedTransaction) -> RpcRichRawTransaction; - - /// "Dispatch" a local transaction. - fn dispatch_transaction(&self, signed_transaction: PendingTransaction) - -> Result; -} - -/// A dispatcher which uses references to a client and miner in order to sign -/// requests locally. -#[derive(Debug)] -pub struct FullDispatcher { - client: Arc, - miner: Arc, - nonces: Arc>, - gas_price_percentile: usize, -} - -impl FullDispatcher { - /// Create a `FullDispatcher` from Arc references to a client and miner. - pub fn new( - client: Arc, - miner: Arc, - nonces: Arc>, - gas_price_percentile: usize, - ) -> Self { - FullDispatcher { - client, - miner, - nonces, - gas_price_percentile, - } - } -} - -impl Clone for FullDispatcher { - fn clone(&self) -> Self { - FullDispatcher { - client: self.client.clone(), - miner: self.miner.clone(), - nonces: self.nonces.clone(), - gas_price_percentile: self.gas_price_percentile, - } - } -} - -impl FullDispatcher { - fn state_nonce(&self, from: &Address) -> U256 { - self.miner.next_nonce(&*self.client, from) - } - - /// Imports transaction to the miner's queue. - pub fn dispatch_transaction(client: &C, miner: &M, signed_transaction: PendingTransaction, trusted: bool) -> Result { - let hash = signed_transaction.transaction.hash(); - - // use `import_claimed_local_transaction` so we can decide (based on config flags) if we want to treat - // it as local or not. Nodes with public RPC interfaces will want these transactions to be treated like - // external transactions. - miner.import_claimed_local_transaction(client, signed_transaction, trusted) - .map_err(errors::transaction) - .map(|_| hash) - } -} - -impl Dispatcher for FullDispatcher { - fn fill_optional_fields(&self, request: TransactionRequest, default_sender: Address, force_nonce: bool) - -> BoxFuture - { - let request = request; - let from = request.from.unwrap_or(default_sender); - let nonce = if force_nonce { - request.nonce.or_else(|| Some(self.state_nonce(&from))) - } else { - request.nonce - }; - - Box::new(future::ok(FilledTransactionRequest { - from, - used_default_from: request.from.is_none(), - to: request.to, - nonce, - gas_price: request.gas_price.unwrap_or_else(|| { - default_gas_price(&*self.client, &*self.miner, self.gas_price_percentile) - }), - gas: request.gas.unwrap_or_else(|| self.miner.sensible_gas_limit()), - value: request.value.unwrap_or_else(|| 0.into()), - data: request.data.unwrap_or_else(Vec::new), - condition: request.condition, - })) - } - - fn sign

( - &self, - accounts: Arc, - filled: FilledTransactionRequest, - password: SignWith, - post_sign: P - ) -> BoxFuture - where - P: PostSign + 'static, - ::Future: Send - { - let chain_id = self.client.signing_chain_id(); - - if let Some(nonce) = filled.nonce { - let future = sign_transaction(&*accounts, filled, chain_id, nonce, password) - .into_future() - .and_then(move |signed| post_sign.execute(signed)); - Box::new(future) - } else { - let state = self.state_nonce(&filled.from); - let reserved = self.nonces.lock().reserve(filled.from, state); - - Box::new(ProspectiveSigner::new(accounts, filled, chain_id, reserved, password, post_sign)) - } - } - - fn enrich(&self, signed_transaction: SignedTransaction) -> RpcRichRawTransaction { - RpcRichRawTransaction::from_signed(signed_transaction) - } - - fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result { - Self::dispatch_transaction(&*self.client, &*self.miner, signed_transaction, true) - } -} - -/// Get a recent gas price corpus. -// TODO: this could be `impl Trait`. -pub fn fetch_gas_price_corpus( - sync: Arc, - client: Arc, - on_demand: Arc, - cache: Arc>, -) -> BoxFuture> { - const GAS_PRICE_SAMPLE_SIZE: usize = 100; - - if let Some(cached) = { cache.lock().gas_price_corpus() } { - return Box::new(future::ok(cached)) - } - - let cache = cache.clone(); - let eventual_corpus = sync.with_context(|ctx| { - // get some recent headers with gas used, - // and request each of the blocks from the network. - let block_requests = client.ancestry_iter(BlockId::Latest) - .filter(|hdr| hdr.gas_used() != U256::default()) - .take(GAS_PRICE_SAMPLE_SIZE) - .map(|hdr| request::Body(hdr.into())) - .collect::>(); - - // when the blocks come in, collect gas prices into a vector - on_demand.request(ctx, block_requests) - .expect("no back-references; therefore all back-references are valid; qed") - .map(|bodies| { - bodies.into_iter().fold(Vec::new(), |mut v, block| { - for t in block.transaction_views().iter() { - v.push(t.gas_price()) - } - v - }) - }) - .map(move |prices| { - // produce a corpus from the vector and cache it. - // It's later used to get a percentile for default gas price. - let corpus: ::stats::Corpus<_> = prices.into(); - cache.lock().set_gas_price_corpus(corpus.clone()); - corpus - }) - }); - - match eventual_corpus { - Some(corp) => Box::new(corp.map_err(|_| errors::no_light_peers())), - None => Box::new(future::err(errors::network_disabled())), - } -} - -/// Returns a eth_sign-compatible hash of data to sign. -/// The data is prepended with special message to prevent -/// malicious DApps from using the function to sign forged transactions. -pub fn eth_data_hash(mut data: Bytes) -> H256 { - let mut message_data = - format!("\x19Ethereum Signed Message:\n{}", data.len()) - .into_bytes(); - message_data.append(&mut data); - keccak(message_data) -} - -/// Dispatcher for light clients -- fetches default gas price, next nonce, etc. from network. -#[derive(Clone)] -pub struct LightDispatcher { - /// Sync service. - pub sync: Arc, - /// Header chain client. - pub client: Arc, - /// On-demand request service. - pub on_demand: Arc, - /// Data cache. - pub cache: Arc>, - /// Transaction queue. - pub transaction_queue: Arc>, - /// Nonce reservations - pub nonces: Arc>, - /// Gas Price percentile value used as default gas price. - pub gas_price_percentile: usize, -} - -impl LightDispatcher { - /// Create a new `LightDispatcher` from its requisite parts. - /// - /// For correct operation, the OnDemand service is assumed to be registered as a network handler, - pub fn new( - sync: Arc, - client: Arc, - on_demand: Arc, - cache: Arc>, - transaction_queue: Arc>, - nonces: Arc>, - gas_price_percentile: usize, - ) -> Self { - LightDispatcher { - sync, - client, - on_demand, - cache, - transaction_queue, - nonces, - gas_price_percentile, - } - } - - /// Get a recent gas price corpus. - // TODO: this could be `impl Trait`. - pub fn gas_price_corpus(&self) -> BoxFuture> { - fetch_gas_price_corpus( - self.sync.clone(), - self.client.clone(), - self.on_demand.clone(), - self.cache.clone(), - ) - } - - /// Get an account's state - fn account(&self, addr: Address) -> BoxFuture> { - let best_header = self.client.best_block_header(); - let account_future = self.sync.with_context(|ctx| self.on_demand.request(ctx, request::Account { - header: best_header.into(), - address: addr, - }).expect("no back-references; therefore all back-references valid; qed")); - - match account_future { - Some(response) => Box::new(response.map_err(|_| errors::no_light_peers())), - None => Box::new(future::err(errors::network_disabled())), - } - } - - /// Get an account's next nonce. - pub fn next_nonce(&self, addr: Address) -> BoxFuture { - let account_start_nonce = self.client.engine().account_start_nonce(self.client.best_block_header().number()); - Box::new(self.account(addr) - .and_then(move |maybe_account| { - future::ok(maybe_account.map_or(account_start_nonce, |account| account.nonce)) - }) - ) - } -} - -impl Dispatcher for LightDispatcher { - // Ignore the `force_nonce` flag in order to always query the network when fetching the nonce and - // the account state. If the nonce is specified in the transaction use that nonce instead but do the - // network request anyway to the account state (balance) - fn fill_optional_fields(&self, request: TransactionRequest, default_sender: Address, _force_nonce: bool) - -> BoxFuture - { - const DEFAULT_GAS_PRICE: U256 = U256([0, 0, 0, 21_000_000]); - - let gas_limit = self.client.best_block_header().gas_limit(); - let request_gas_price = request.gas_price.clone(); - let from = request.from.unwrap_or(default_sender); - - let with_gas_price = move |gas_price| { - let request = request; - FilledTransactionRequest { - from: from.clone(), - used_default_from: request.from.is_none(), - to: request.to, - nonce: request.nonce, - gas_price: gas_price, - gas: request.gas.unwrap_or_else(|| gas_limit / 3), - value: request.value.unwrap_or_else(|| 0.into()), - data: request.data.unwrap_or_else(Vec::new), - condition: request.condition, - } - }; - - // fast path for known gas price. - let gas_price_percentile = self.gas_price_percentile; - let gas_price = match request_gas_price { - Some(gas_price) => Either::A(future::ok(with_gas_price(gas_price))), - None => Either::B(fetch_gas_price_corpus( - self.sync.clone(), - self.client.clone(), - self.on_demand.clone(), - self.cache.clone() - ).and_then(move |corp| match corp.percentile(gas_price_percentile) { - Some(percentile) => Ok(*percentile), - None => Ok(DEFAULT_GAS_PRICE), // fall back to default on error. - }).map(with_gas_price)) - }; - - let future_account = self.account(from); - - Box::new(gas_price.and_then(move |mut filled| { - future_account - .and_then(move |maybe_account| { - let cost = filled.value.saturating_add(filled.gas.saturating_mul(filled.gas_price)); - match maybe_account { - Some(ref account) if cost > account.balance => { - Err(errors::transaction(TransactionError::InsufficientBalance { - balance: account.balance, - cost, - })) - } - Some(account) => { - if filled.nonce.is_none() { - filled.nonce = Some(account.nonce); - } - Ok(filled) - } - None => Err(errors::account("Account not found", "")), - } - }) - })) - } - - fn sign

( - &self, - accounts: Arc, - filled: FilledTransactionRequest, - password: SignWith, - post_sign: P - ) -> BoxFuture - where - P: PostSign + 'static, - ::Future: Send - { - let chain_id = self.client.signing_chain_id(); - let nonce = filled.nonce.expect("nonce is always provided; qed"); - - let future = sign_transaction(&*accounts, filled, chain_id, nonce, password) - .into_future() - .and_then(move |signed| post_sign.execute(signed)); - Box::new(future) - } - - fn enrich(&self, signed_transaction: SignedTransaction) -> RpcRichRawTransaction { - RpcRichRawTransaction::from_signed(signed_transaction) - } - - fn dispatch_transaction(&self, signed_transaction: PendingTransaction) -> Result { - let hash = signed_transaction.transaction.hash(); - - self.transaction_queue.write().import(signed_transaction) - .map_err(errors::transaction) - .map(|_| hash) - } -} - -fn sign_transaction( - accounts: &AccountProvider, - filled: FilledTransactionRequest, - chain_id: Option, - nonce: U256, - password: SignWith, -) -> Result> { - let t = Transaction { - nonce: nonce, - action: filled.to.map_or(Action::Create, Action::Call), - gas: filled.gas, - gas_price: filled.gas_price, - value: filled.value, - data: filled.data, - }; - - if accounts.is_hardware_address(&filled.from) { - return hardware_signature(accounts, filled.from, t, chain_id).map(WithToken::No) - } - - let hash = t.hash(chain_id); - let signature = signature(accounts, filled.from, hash, password)?; - - Ok(signature.map(|sig| { - SignedTransaction::new(t.with_signature(sig, chain_id)) - .expect("Transaction was signed by AccountsProvider; it never produces invalid signatures; qed") - })) -} - -#[derive(Debug, Clone, Copy)] -enum ProspectiveSignerState { - TryProspectiveSign, - WaitForPostSign, - WaitForNonce, -} - -struct ProspectiveSigner { - accounts: Arc, - filled: FilledTransactionRequest, - chain_id: Option, - reserved: nonce::Reserved, - password: SignWith, - state: ProspectiveSignerState, - prospective: Option>, - ready: Option, - post_sign: Option

, - post_sign_future: Option<::Future> -} - -/// action to execute after signing -/// e.g importing a transaction into the chain -pub trait PostSign: Send { - /// item that this PostSign returns - type Item: Send; - /// incase you need to perform async PostSign actions - type Out: IntoFuture + Send; - /// perform an action with the signed transaction - fn execute(self, signer: WithToken) -> Self::Out; -} - -impl PostSign for () { - type Item = WithToken; - type Out = Result; - fn execute(self, signed: WithToken) -> Self::Out { - Ok(signed) - } -} - -impl PostSign for F - where F: FnOnce(WithToken) -> Result -{ - type Item = T; - type Out = Result; - fn execute(self, signed: WithToken) -> Self::Out { - (self)(signed) - } -} - -impl ProspectiveSigner

{ - pub fn new( - accounts: Arc, - filled: FilledTransactionRequest, - chain_id: Option, - reserved: nonce::Reserved, - password: SignWith, - post_sign: P - ) -> Self { - // If the account is permanently unlocked we can try to sign - // using prospective nonce. This should speed up sending - // multiple subsequent transactions in multi-threaded RPC environment. - let is_unlocked_permanently = accounts.is_unlocked_permanently(&filled.from); - let has_password = password.is_password(); - - ProspectiveSigner { - accounts, - filled, - chain_id, - reserved, - password, - state: if is_unlocked_permanently || has_password { - ProspectiveSignerState::TryProspectiveSign - } else { - ProspectiveSignerState::WaitForNonce - }, - prospective: None, - ready: None, - post_sign: Some(post_sign), - post_sign_future: None - } - } - - fn sign(&self, nonce: &U256) -> Result> { - sign_transaction( - &*self.accounts, - self.filled.clone(), - self.chain_id, - *nonce, - self.password.clone() - ) - } - - fn poll_reserved(&mut self) -> Poll { - self.reserved.poll().map_err(|_| errors::internal("Nonce reservation failure", "")) - } -} - -impl Future for ProspectiveSigner

{ - type Item = P::Item; - type Error = Error; - - fn poll(&mut self) -> Poll { - use self::ProspectiveSignerState::*; - - loop { - match self.state { - TryProspectiveSign => { - // Try to poll reserved, it might be ready. - match self.poll_reserved()? { - Async::NotReady => { - self.state = WaitForNonce; - self.prospective = Some(self.sign(self.reserved.prospective_value())?); - }, - Async::Ready(nonce) => { - self.state = WaitForPostSign; - self.post_sign_future = Some(self.post_sign.take() - .expect("post_sign is set on creation; qed") - .execute(self.sign(nonce.value())?) - .into_future()); - self.ready = Some(nonce); - }, - } - }, - WaitForNonce => { - let nonce = try_ready!(self.poll_reserved()); - let prospective = match (self.prospective.take(), nonce.matches_prospective()) { - (Some(prospective), true) => prospective, - _ => self.sign(nonce.value())?, - }; - self.ready = Some(nonce); - self.state = WaitForPostSign; - self.post_sign_future = Some(self.post_sign.take() - .expect("post_sign is set on creation; qed") - .execute(prospective) - .into_future()); - }, - WaitForPostSign => { - if let Some(mut fut) = self.post_sign_future.as_mut() { - match fut.poll()? { - Async::Ready(item) => { - let nonce = self.ready - .take() - .expect("nonce is set before state transitions to WaitForPostSign; qed"); - nonce.mark_used(); - return Ok(Async::Ready(item)) - }, - Async::NotReady => { - return Ok(Async::NotReady) - } - } - } else { - panic!("Poll after ready."); - } - } - } - } - } -} - -/// Single-use account token. -pub type AccountToken = Password; - -/// Values used to unlock accounts for signing. -#[derive(Clone, PartialEq)] -pub enum SignWith { - /// Nothing -- implies the account is already unlocked. - Nothing, - /// Unlock with password. - Password(Password), - /// Unlock with single-use token. - Token(AccountToken), -} - -impl SignWith { - fn is_password(&self) -> bool { - if let SignWith::Password(_) = *self { - true - } else { - false - } - } -} - -/// A value, potentially accompanied by a signing token. -pub enum WithToken { - /// No token. - No(T), - /// With token. - Yes(T, AccountToken), -} - -impl Deref for WithToken { - type Target = T; - - fn deref(&self) -> &Self::Target { - match *self { - WithToken::No(ref v) => v, - WithToken::Yes(ref v, _) => v, - } - } -} - -impl WithToken { - /// Map the value with the given closure, preserving the token. - pub fn map(self, f: F) -> WithToken where - S: Debug, - F: FnOnce(T) -> S, - { - match self { - WithToken::No(v) => WithToken::No(f(v)), - WithToken::Yes(v, token) => WithToken::Yes(f(v), token), - } - } - - /// Convert into inner value, ignoring possible token. - pub fn into_value(self) -> T { - match self { - WithToken::No(v) => v, - WithToken::Yes(v, _) => v, - } - } - - /// Convert the `WithToken` into a tuple. - pub fn into_tuple(self) -> (T, Option) { - match self { - WithToken::No(v) => (v, None), - WithToken::Yes(v, token) => (v, Some(token)) - } - } -} - -impl From<(T, AccountToken)> for WithToken { - fn from(tuple: (T, AccountToken)) -> Self { - WithToken::Yes(tuple.0, tuple.1) - } -} - -impl From<(T, Option)> for WithToken { - fn from(tuple: (T, Option)) -> Self { - match tuple.1 { - Some(token) => WithToken::Yes(tuple.0, token), - None => WithToken::No(tuple.0), - } - } -} - -/// Execute a confirmation payload. -pub fn execute( - dispatcher: D, - accounts: Arc, - payload: ConfirmationPayload, - pass: SignWith -) -> BoxFuture> { - match payload { - ConfirmationPayload::SendTransaction(request) => { - let condition = request.condition.clone().map(Into::into); - let cloned_dispatcher = dispatcher.clone(); - let post_sign = move |with_token_signed: WithToken| { - let (signed, token) = with_token_signed.into_tuple(); - let signed_transaction = PendingTransaction::new(signed, condition); - cloned_dispatcher.dispatch_transaction(signed_transaction) - .map(|hash| (hash, token)) - }; - let future = dispatcher.sign(accounts, request, pass, post_sign) - .map(|(hash, token)| { - WithToken::from((ConfirmationResponse::SendTransaction(hash.into()), token)) - }); - Box::new(future) - }, - ConfirmationPayload::SignTransaction(request) => { - Box::new(dispatcher.sign(accounts, request, pass, ()) - .map(move |result| result - .map(move |tx| dispatcher.enrich(tx)) - .map(ConfirmationResponse::SignTransaction) - )) - }, - ConfirmationPayload::EthSignMessage(address, data) => { - if accounts.is_hardware_address(&address) { - let signature = accounts.sign_message_with_hardware(&address, &data) - .map(|s| H520(s.into_electrum())) - .map(ConfirmationResponse::Signature) - .map(WithToken::No) - .map_err(|e| errors::account("Error signing message with hardware_wallet", e)); - - return Box::new(future::done(signature)); - } - let hash = eth_data_hash(data); - let res = signature(&accounts, address, hash, pass) - .map(|result| result - .map(|rsv| H520(rsv.into_electrum())) - .map(ConfirmationResponse::Signature) - ); - Box::new(future::done(res)) - }, - ConfirmationPayload::SignMessage(address, data) => { - if accounts.is_hardware_address(&address) { - return Box::new(future::err(errors::account("Error signing message with hardware_wallet", - "Message signing is unsupported"))); - } - let res = signature(&accounts, address, data, pass) - .map(|result| result - .map(|rsv| H520(rsv.into_electrum())) - .map(ConfirmationResponse::Signature) - ); - Box::new(future::done(res)) - }, - ConfirmationPayload::Decrypt(address, data) => { - if accounts.is_hardware_address(&address) { - return Box::new(future::err(errors::unsupported("Decrypting via hardware wallets is not supported.", None))); - } - let res = decrypt(&accounts, address, data, pass) - .map(|result| result - .map(RpcBytes) - .map(ConfirmationResponse::Decrypt) - ); - Box::new(future::done(res)) - }, - } -} - -fn signature(accounts: &AccountProvider, address: Address, hash: H256, password: SignWith) -> Result> { - match password.clone() { - SignWith::Nothing => accounts.sign(address, None, hash).map(WithToken::No), - SignWith::Password(pass) => accounts.sign(address, Some(pass), hash).map(WithToken::No), - SignWith::Token(token) => accounts.sign_with_token(address, token, hash).map(Into::into), - }.map_err(|e| match password { - SignWith::Nothing => errors::signing(e), - _ => errors::password(e), - }) -} - -// obtain a hardware signature from the given account. -fn hardware_signature(accounts: &AccountProvider, address: Address, t: Transaction, chain_id: Option) - -> Result -{ - debug_assert!(accounts.is_hardware_address(&address)); - - let mut stream = rlp::RlpStream::new(); - t.rlp_append_unsigned_transaction(&mut stream, chain_id); - let signature = accounts.sign_transaction_with_hardware(&address, &t, chain_id, &stream.as_raw()) - .map_err(|e| { - debug!(target: "miner", "Error signing transaction with hardware wallet: {}", e); - errors::account("Error signing transaction with hardware wallet", e) - })?; - - SignedTransaction::new(t.with_signature(signature, chain_id)) - .map_err(|e| { - debug!(target: "miner", "Hardware wallet has produced invalid signature: {}", e); - errors::account("Invalid signature generated", e) - }) -} - -fn decrypt(accounts: &AccountProvider, address: Address, msg: Bytes, password: SignWith) -> Result> { - match password.clone() { - SignWith::Nothing => accounts.decrypt(address, None, &DEFAULT_MAC, &msg).map(WithToken::No), - SignWith::Password(pass) => accounts.decrypt(address, Some(pass), &DEFAULT_MAC, &msg).map(WithToken::No), - SignWith::Token(token) => accounts.decrypt_with_token(address, token, &DEFAULT_MAC, &msg).map(Into::into), - }.map_err(|e| match password { - SignWith::Nothing => errors::signing(e), - _ => errors::password(e), - }) -} - -/// Extract the default gas price from a client and miner. -pub fn default_gas_price(client: &C, miner: &M, percentile: usize) -> U256 where - C: BlockChainClient, - M: MinerService, -{ - client.gas_price_corpus(100).percentile(percentile).cloned().unwrap_or_else(|| miner.sensible_gas_price()) -} - -/// Convert RPC confirmation payload to signer confirmation payload. -/// May need to resolve in the future to fetch things like gas price. -pub fn from_rpc(payload: RpcConfirmationPayload, default_account: Address, dispatcher: &D) -> BoxFuture - where D: Dispatcher -{ - match payload { - RpcConfirmationPayload::SendTransaction(request) => { - Box::new(dispatcher.fill_optional_fields(request.into(), default_account, false) - .map(ConfirmationPayload::SendTransaction)) - }, - RpcConfirmationPayload::SignTransaction(request) => { - Box::new(dispatcher.fill_optional_fields(request.into(), default_account, false) - .map(ConfirmationPayload::SignTransaction)) - }, - RpcConfirmationPayload::Decrypt(RpcDecryptRequest { address, msg }) => { - Box::new(future::ok(ConfirmationPayload::Decrypt(address.into(), msg.into()))) - }, - RpcConfirmationPayload::EthSignMessage(RpcEthSignRequest { address, data }) => { - Box::new(future::ok(ConfirmationPayload::EthSignMessage(address.into(), data.into()))) - }, - RpcConfirmationPayload::EIP191SignMessage(RpcSignRequest { address, data }) => { - Box::new(future::ok(ConfirmationPayload::SignMessage(address.into(), data.into()))) - }, - } -} diff --git a/rpc/src/v1/helpers/dispatch/mod.rs b/rpc/src/v1/helpers/dispatch/mod.rs index d23619f4178..8877209723d 100644 --- a/rpc/src/v1/helpers/dispatch/mod.rs +++ b/rpc/src/v1/helpers/dispatch/mod.rs @@ -86,7 +86,7 @@ use jsonrpc_core::{BoxFuture, Result, Error}; use jsonrpc_core::futures::{future, Future, IntoFuture}; use v1::helpers::{TransactionRequest, FilledTransactionRequest, ConfirmationPayload}; use v1::types::{ - H520 as RpcH520, Bytes as RpcBytes, + Bytes as RpcBytes, RichRawTransaction as RpcRichRawTransaction, ConfirmationPayload as RpcConfirmationPayload, ConfirmationResponse, @@ -309,7 +309,6 @@ pub fn execute( let res = signer.sign_message(address, pass, SignMessage::Data(data)) .map(|result| result .map(|s| H520(s.into_electrum())) - .map(RpcH520::from) .map(ConfirmationResponse::Signature) ); @@ -319,7 +318,6 @@ pub fn execute( let res = signer.sign_message(address, pass, SignMessage::Hash(data)) .map(|result| result .map(|rsv| H520(rsv.into_electrum())) - .map(RpcH520::from) .map(ConfirmationResponse::Signature) ); diff --git a/rpc/src/v1/impls/eth.rs b/rpc/src/v1/impls/eth.rs index 0da007cadf1..31b8be10c29 100644 --- a/rpc/src/v1/impls/eth.rs +++ b/rpc/src/v1/impls/eth.rs @@ -569,7 +569,7 @@ impl Eth for EthClient< Ok(U256::from(self.client.chain_info().best_block_number)) } - fn balance(&self, address: H160, num: Trailing) -> BoxFuture { + fn balance(&self, address: H160, num: Option) -> BoxFuture { let num = num.unwrap_or_default(); try_bf!(check_known(&*self.client, num.clone())); @@ -581,7 +581,7 @@ impl Eth for EthClient< Box::new(future::done(res)) } - fn proof(&self, address: H160, values: Vec, num: Trailing) -> BoxFuture { + fn proof(&self, address: H160, values: Vec, num: Option) -> BoxFuture { try_bf!(errors::require_experimental(self.options.allow_experimental_rpcs, "1186")); let key1 = keccak(address); @@ -623,7 +623,7 @@ impl Eth for EthClient< Box::new(future::done(res)) } - fn storage_at(&self, address: H160, pos: U256, num: Trailing) -> BoxFuture { + fn storage_at(&self, address: H160, position: U256, num: Option) -> BoxFuture { let address: Address = address.into(); let num = num.unwrap_or_default(); @@ -636,7 +636,7 @@ impl Eth for EthClient< Box::new(future::done(res)) } - fn transaction_count(&self, address: H160, num: Trailing) -> BoxFuture { + fn transaction_count(&self, address: H160, num: Option) -> BoxFuture { let address: Address = address.into(); let res = match num.unwrap_or_default() { @@ -719,7 +719,7 @@ impl Eth for EthClient< })) } - fn code_at(&self, address: H160, num: Trailing) -> BoxFuture { + fn code_at(&self, address: H160, num: Option) -> BoxFuture { let address: Address = H160::into(address); let num = num.unwrap_or_default(); @@ -951,7 +951,7 @@ impl Eth for EthClient< )) } - fn estimate_gas(&self, request: CallRequest, num: Trailing) -> BoxFuture { + fn estimate_gas(&self, request: CallRequest, num: Option) -> BoxFuture { let request = CallRequest::into(request); let signed = try_bf!(fake_sign::sign_call(request)); let num = num.unwrap_or_default(); diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index 61fa39dd69e..1e847eef2c0 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -28,7 +28,7 @@ use light::client::LightChainClient; use light::{cht, TransactionQueue}; use light::on_demand::{request, OnDemand}; -use ethereum_types::{H64, H160, H256, U64, U256}; +use ethereum_types::{Address, H64, H160, H256, U64, U256}; use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP}; use parking_lot::{RwLock, Mutex}; use rlp::Rlp; @@ -252,6 +252,8 @@ where (self.accounts)() .first() .cloned() + .map(From::from) + .ok_or_else(|| errors::account("No accounts were found", "")) } fn is_mining(&self) -> Result { @@ -286,12 +288,12 @@ where Ok(self.client.chain_info().best_block_number.into()) } - fn balance(&self, address: H160, num: Trailing) -> BoxFuture { + fn balance(&self, address: H160, num: Option) -> BoxFuture { Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id()) .map(|acc| acc.map_or(0.into(), |a| a.balance).into())) } - fn storage_at(&self, _address: H160, _key: U256, _num: Trailing) -> BoxFuture { + fn storage_at(&self, _address: H160, _key: U256, _num: Option) -> BoxFuture { Box::new(future::err(errors::unimplemented(None))) } @@ -303,7 +305,7 @@ where Box::new(self.rich_block(num.to_block_id(), include_txs).map(Some)) } - fn transaction_count(&self, address: H160, num: Trailing) -> BoxFuture { + fn transaction_count(&self, address: H160, num: Option) -> BoxFuture { Box::new(self.fetcher().account(address.into(), num.unwrap_or_default().to_block_id()) .map(|acc| acc.map_or(0.into(), |a| a.nonce).into())) } @@ -372,7 +374,7 @@ where })) } - fn code_at(&self, address: H160, num: Trailing) -> BoxFuture { + fn code_at(&self, address: H160, num: Option) -> BoxFuture { Box::new(self.fetcher().code(address.into(), num.unwrap_or_default().to_block_id()).map(Into::into)) } @@ -408,7 +410,7 @@ where })) } - fn estimate_gas(&self, req: CallRequest, num: Trailing) -> BoxFuture { + fn estimate_gas(&self, req: CallRequest, num: Option) -> BoxFuture { // TODO: binary chop for more accurate estimates. Box::new(self.fetcher().proved_read_only_execution(req, num).and_then(|res| { match res { @@ -489,7 +491,7 @@ where })) } - fn proof(&self, _address: H160, _values:Vec, _num: Trailing) -> BoxFuture { + fn proof(&self, _address: H160, _values:Vec, _num: Option) -> BoxFuture { Box::new(future::err(errors::unimplemented(None))) } diff --git a/rpc/src/v1/impls/parity.rs b/rpc/src/v1/impls/parity.rs index eb2408fcbe6..d985f33f625 100644 --- a/rpc/src/v1/impls/parity.rs +++ b/rpc/src/v1/impls/parity.rs @@ -19,16 +19,13 @@ use std::sync::Arc; use std::str::FromStr; use std::collections::BTreeMap; -use ethereum_types::{Address, H64, H160, H256, H512, U64, U256}; -use version::version_data; - use crypto::DEFAULT_MAC; +use ethereum_types::{Address, H64, H160, H256, H512, U64, U256}; use ethcore::client::{BlockChainClient, StateClient, Call}; use ethcore::miner::{self, MinerService}; use ethcore::snapshot::{SnapshotService, RestorationStatus}; use ethcore::state::StateInfo; use ethcore_logger::RotatingLogger; -use ethereum_types::Address; use ethkey::{crypto::ecies, Brain, Generator}; use ethstore::random_phrase; use jsonrpc_core::futures::future; diff --git a/rpc/src/v1/impls/parity_accounts.rs b/rpc/src/v1/impls/parity_accounts.rs index 0924981d40d..e52f8b7ac0d 100644 --- a/rpc/src/v1/impls/parity_accounts.rs +++ b/rpc/src/v1/impls/parity_accounts.rs @@ -55,7 +55,7 @@ impl ParityAccountsClient { } impl ParityAccountsInfo for ParityAccountsClient { - fn accounts_info(&self) -> Result> { + fn accounts_info(&self) -> Result> { self.deprecation_notice("parity_accountsInfo"); let dapp_accounts = self.accounts.accounts() @@ -69,18 +69,18 @@ impl ParityAccountsInfo for ParityAccountsClient { .into_iter() .chain(other.into_iter()) .filter(|&(ref a, _)| dapp_accounts.contains(a)) - .map(|(a, v)| (RpcH160::from(a), AccountInfo { name: v.name })) + .map(|(a, v)| (H160::from(a), AccountInfo { name: v.name })) .collect() ) } - fn hardware_accounts_info(&self) -> Result> { + fn hardware_accounts_info(&self) -> Result> { self.deprecation_notice("parity_hardwareAccountsInfo"); let info = self.accounts.hardware_accounts_info().map_err(|e| errors::account("Could not fetch account info.", e))?; Ok(info .into_iter() - .map(|(a, v)| (RpcH160::from(a), HwAccountInfo { name: v.name, manufacturer: v.meta })) + .map(|(a, v)| (H160::from(a), HwAccountInfo { name: v.name, manufacturer: v.meta })) .collect() ) } @@ -91,7 +91,7 @@ impl ParityAccountsInfo for ParityAccountsClient { self.accounts.locked_hardware_accounts().map_err(|e| errors::account("Error communicating with hardware wallet.", e)) } - fn default_account(&self) -> Result { + fn default_account(&self) -> Result { self.deprecation_notice("parity_defaultAccount"); Ok(self.accounts.default_account() diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index e6bd81db363..a50138eb19d 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -160,7 +160,6 @@ impl ParitySet for ParitySetClient where } fn set_engine_signer_secret(&self, secret: H256) -> Result { - let secret: EthH256 = secret.into(); let keypair = ethkey::KeyPair::from_secret(secret.into()).map_err(|e| errors::account("Invalid secret", e))?; self.miner.set_author(miner::Author::Sealer(ethcore::engines::signer::from_keypair(keypair))); Ok(true) diff --git a/rpc/src/v1/mod.rs b/rpc/src/v1/mod.rs index 67b25bffbf5..8b8afacdb1c 100644 --- a/rpc/src/v1/mod.rs +++ b/rpc/src/v1/mod.rs @@ -53,5 +53,5 @@ pub mod signer { #[cfg(any(test, feature = "accounts"))] pub use super::helpers::engine_signer::EngineSigner; pub use super::helpers::external_signer::{SignerService, ConfirmationsQueue}; - pub use super::types::{ConfirmationRequest, TransactionModification, U256, TransactionCondition}; + pub use super::types::{ConfirmationRequest, TransactionModification, TransactionCondition}; } diff --git a/rpc/src/v1/tests/mocked/signing_unsafe.rs b/rpc/src/v1/tests/mocked/signing_unsafe.rs index 7e82038571d..a91a85ea1fb 100644 --- a/rpc/src/v1/tests/mocked/signing_unsafe.rs +++ b/rpc/src/v1/tests/mocked/signing_unsafe.rs @@ -210,7 +210,7 @@ fn rpc_eth_send_transaction_with_bad_to() { "id": 1 }"#; - let response = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params: expected a hex-encoded hash with 0x prefix."},"id":1}"#; + let response = r#"{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid params: prefix is missing."},"id":1}"#; assert_eq!(tester.io.handle_request_sync(&request), Some(response.into())); } diff --git a/rpc/src/v1/traits/eth.rs b/rpc/src/v1/traits/eth.rs index 52a7588ae42..14f8fb69e11 100644 --- a/rpc/src/v1/traits/eth.rs +++ b/rpc/src/v1/traits/eth.rs @@ -17,7 +17,6 @@ //! Eth rpc interface. use jsonrpc_core::{Result, BoxFuture}; use jsonrpc_derive::rpc; -use jsonrpc_macros::Trailing; use ethereum_types::{H64, H160, H256, U64, U256}; use v1::types::{RichBlock, BlockNumber, Bytes, CallRequest, Filter, FilterChanges, Index, EthAccount}; From 6801c5e622924e7861b2628200fdb14aa94f93ad Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 12 Feb 2019 14:11:04 +0100 Subject: [PATCH 06/13] chore(bump ethereum-types) --- Cargo.lock | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7e80bf393ab..0f25c09c8e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,7 +261,7 @@ dependencies = [ name = "cli-signer" version = "1.4.0" dependencies = [ - "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc 1.12.0", "parity-rpc-client 1.4.0", @@ -821,7 +821,11 @@ name = "ethcore-call-contract" version = "0.1.0" dependencies = [ "common-types 0.1.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -830,7 +834,11 @@ name = "ethcore-db" version = "0.1.0" dependencies = [ "common-types 0.1.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -867,7 +875,11 @@ dependencies = [ "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethcore-network 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -926,7 +938,11 @@ dependencies = [ "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.12.0", "ethcore-call-contract 0.1.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -952,7 +968,11 @@ dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-io 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -976,7 +996,11 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-io 1.12.0", "ethcore-network 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "igd 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1016,7 +1040,11 @@ dependencies = [ "ethcore-call-contract 0.1.0", "ethcore-io 1.12.0", "ethcore-miner 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "ethkey 0.3.0", "fetch 0.1.0", @@ -1055,7 +1083,11 @@ dependencies = [ "ethcore-accounts 0.1.0", "ethcore-call-contract 0.1.0", "ethcore-sync 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1092,7 +1124,11 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1105,7 +1141,11 @@ name = "ethcore-stratum" version = "1.12.0" dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-tcp-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1128,7 +1168,11 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-network-devp2p 1.12.0", "ethcore-private-tx 1.0.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "ethstore 0.2.1", "fastmap 0.1.0", @@ -1151,7 +1195,11 @@ dependencies = [ [[package]] name = "ethereum-types" +<<<<<<< HEAD version = "0.4.2" +======= +version = "0.4.1" +>>>>>>> chore(bump ethereum-types) source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1174,7 +1222,11 @@ dependencies = [ name = "ethjson" version = "0.1.0" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1188,7 +1240,11 @@ dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "memzero 0.1.0", @@ -1222,7 +1278,11 @@ name = "ethstore" version = "0.2.1" dependencies = [ "dir 0.1.2", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1266,7 +1326,11 @@ version = "0.1.0" dependencies = [ "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1286,7 +1350,11 @@ dependencies = [ "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "evm 0.1.0", "panic_hook 0.1.0", @@ -1343,7 +1411,11 @@ dependencies = [ name = "fake-hardware-wallet" version = "0.0.1" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", ] @@ -1356,7 +1428,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "fastmap" version = "0.1.0" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1529,7 +1605,11 @@ dependencies = [ name = "hardware-wallet" version = "1.12.0" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "hidapi 0.3.1 (git+https://github.com/paritytech/hidapi-rs)", "libusb 0.3.0 (git+https://github.com/paritytech/libusb-rs)", @@ -1809,7 +1889,11 @@ name = "journaldb" version = "0.2.0" dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "fastmap 0.1.0", "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", @@ -1930,7 +2014,11 @@ name = "keccak-hash" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2306,7 +2394,11 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-network 1.12.0", "ethcore-network-devp2p 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2497,7 +2589,11 @@ dependencies = [ "ethcore-secretstore 1.0.0", "ethcore-service 0.1.0", "ethcore-sync 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "ethstore 0.2.1", "fake-fetch 0.0.1", @@ -2553,7 +2649,11 @@ dependencies = [ "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "fake-fetch 0.0.1", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2575,7 +2675,11 @@ version = "1.12.0" dependencies = [ "cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2604,7 +2708,11 @@ dependencies = [ name = "parity-machine" version = "0.1.0" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) ] [[package]] @@ -2652,7 +2760,11 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "ethkey 0.3.0", "ethstore 0.2.1", @@ -2701,7 +2813,7 @@ dependencies = [ name = "parity-rpc-client" version = "1.4.0" dependencies = [ - "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-ws-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2768,7 +2880,11 @@ dependencies = [ "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-sync 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2811,7 +2927,11 @@ dependencies = [ "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-network 1.12.0", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2909,7 +3029,11 @@ name = "patricia-trie-ethereum" version = "0.1.0" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3082,7 +3206,11 @@ version = "0.1.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3344,7 +3472,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3354,7 +3486,11 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4086,7 +4222,11 @@ name = "trie-standardmap" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4105,7 +4245,11 @@ dependencies = [ name = "triehash-ethereum" version = "0.2.0" dependencies = [ +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "keccak-hasher 0.1.1", "triehash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4278,7 +4422,11 @@ name = "vm" version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4329,7 +4477,11 @@ version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", +<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +======= + "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", +>>>>>>> chore(bump ethereum-types) "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4531,8 +4683,13 @@ dependencies = [ "checksum ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "795e25fd868e12a59ca235dbe1f6cc8f1eba8f67d6a39438b29535e0126e0c27" "checksum ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "66a587250c8190be9d6ae28d67b8957ed97cb9eee2e272173a20593ab054a075" "checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" +<<<<<<< HEAD "checksum ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e742184dc63a01c8ea0637369f8faa27c40f537949908a237f95c05e68d2c96" "checksum ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1873d77b32bc1891a79dad925f2acbc318ee942b38b9110f9dbc5fbeffcea350" +======= +"checksum ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5ef1b8b23cb62440bad25bfb5d0f5ba97f18ebabd9b777ef0ef5d37c72cca3c0" +"checksum ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ac59a21a9ce98e188f3dace9eb67a6c4a3c67ec7fbc7218cb827852679dc002" +>>>>>>> chore(bump ethereum-types) "checksum failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3bf1642583ea2f1fa38a1e8546613a7488816941b33e5f0fccceac61879118" "checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" "checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" From 2a1c854d1b4b7ef9c828801ce30e6a7beef1a2ee Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 12 Feb 2019 14:15:22 +0100 Subject: [PATCH 07/13] fix(bad merge) --- rpc/src/v1/impls/light/eth.rs | 4 +- rpc/src/v1/types/uint.rs | 172 ---------------------------------- 2 files changed, 2 insertions(+), 174 deletions(-) delete mode 100644 rpc/src/v1/types/uint.rs diff --git a/rpc/src/v1/impls/light/eth.rs b/rpc/src/v1/impls/light/eth.rs index 1e847eef2c0..909d4c24439 100644 --- a/rpc/src/v1/impls/light/eth.rs +++ b/rpc/src/v1/impls/light/eth.rs @@ -44,8 +44,8 @@ use v1::helpers::deprecated::{self, DeprecationNotice}; use v1::helpers::light_fetch::{self, LightFetch}; use v1::traits::Eth; use v1::types::{ - RichBlock, Block, BlockTransactions, BlockNumber, LightBlockNumber, Bytes, SyncStatus, SyncInfo, - Transaction, CallRequest, Index, Filter, Log, Receipt, Work, EthAccount + RichBlock, Block, BlockTransactions, BlockNumber, LightBlockNumber, Bytes, SyncStatus as RpcSyncStatus, + SyncInfo as RpcSyncInfo, Transaction, CallRequest, Index, Filter, Log, Receipt, Work, EthAccount }; use v1::metadata::Metadata; diff --git a/rpc/src/v1/types/uint.rs b/rpc/src/v1/types/uint.rs deleted file mode 100644 index 3c5801c07ce..00000000000 --- a/rpc/src/v1/types/uint.rs +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright 2015-2019 Parity Technologies (UK) Ltd. -// This file is part of Parity Ethereum. - -// Parity Ethereum 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 Ethereum 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 Ethereum. If not, see . - -use std::str::FromStr; -use std::fmt; -use serde; -use ethereum_types::{U256 as EthU256, U128 as EthU128}; - -macro_rules! impl_uint { - ($name: ident, $other: ident, $size: expr) => { - /// Uint serialization. - #[derive(Debug, Default, Clone, Copy, PartialEq, Hash)] - pub struct $name($other); - - impl Eq for $name { } - - impl From for $name where $other: From { - 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 { - $other::from_str(s).map($name) - } - } - - impl Into<$other> for $name { - fn into(self) -> $other { - self.0 - } - } - - impl fmt::Display for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.0) - } - } - - impl fmt::LowerHex for $name { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::LowerHex::fmt(&self.0, f) - } - } - - impl<'a> serde::Deserialize<'a> for $name { - fn deserialize(deserializer: D) -> Result<$name, D::Error> - where D: serde::Deserializer<'a> { - struct UintVisitor; - - impl<'b> serde::de::Visitor<'b> for UintVisitor { - type Value = $name; - - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!(formatter, "a 0x-prefixed, hex-encoded number of length {}", $size*16) - } - - fn visit_str(self, value: &str) -> Result where E: serde::de::Error { - if value.len() < 2 || !value.starts_with("0x") { - return Err(E::custom("expected a hex-encoded numbers with 0x prefix")) - } - - // 0x + len - if value.len() > 2 + $size * 16 { - return Err(E::invalid_length(value.len() - 2, &self)); - } - - $other::from_str(&value[2..]).map($name).map_err(|e| E::custom(&format!("invalid hex value: {:?}", e))) - } - - fn visit_string(self, value: String) -> Result where E: serde::de::Error { - self.visit_str(&value) - } - } - - deserializer.deserialize_any(UintVisitor) - } - } - - } -} - -impl_uint!(U128, EthU128, 2); -impl_uint!(U256, EthU256, 4); -impl_uint!(U64, u64, 1); - -impl serde::Serialize for U128 { - fn serialize(&self, serializer: S) -> Result where S: serde::Serializer { - serializer.serialize_str(&format!("{:#x}", self)) - } -} - -impl serde::Serialize for U256 { - fn serialize(&self, serializer: S) -> Result where S: serde::Serializer { - serializer.serialize_str(&format!("{:#x}", self)) - } -} - -impl serde::Serialize for U64 { - fn serialize(&self, serializer: S) -> Result where S: serde::Serializer { - serializer.serialize_str(&format!("{:#x}", self)) - } -} - -#[cfg(test)] -mod tests { - use super::U256; - use serde_json; - - type Res = Result; - - #[test] - fn should_serialize_u256() { - let serialized1 = serde_json::to_string(&U256(0.into())).unwrap(); - let serialized2 = serde_json::to_string(&U256(1.into())).unwrap(); - let serialized3 = serde_json::to_string(&U256(16.into())).unwrap(); - let serialized4 = serde_json::to_string(&U256(256.into())).unwrap(); - - assert_eq!(serialized1, r#""0x0""#); - assert_eq!(serialized2, r#""0x1""#); - assert_eq!(serialized3, r#""0x10""#); - assert_eq!(serialized4, r#""0x100""#); - } - - #[test] - fn should_fail_to_deserialize_decimals() { - let deserialized0: Res = serde_json::from_str(r#""∀∂""#); - let deserialized1: Res = serde_json::from_str(r#""""#); - let deserialized2: Res = serde_json::from_str(r#""0""#); - let deserialized3: Res = serde_json::from_str(r#""10""#); - let deserialized4: Res = serde_json::from_str(r#""1000000""#); - let deserialized5: Res = serde_json::from_str(r#""1000000000000000000""#); - - assert!(deserialized0.is_err()); - assert!(deserialized1.is_err()); - assert!(deserialized2.is_err()); - assert!(deserialized3.is_err()); - assert!(deserialized4.is_err()); - assert!(deserialized5.is_err()); - } - - #[test] - fn should_deserialize_u256() { - let deserialized1: U256 = serde_json::from_str(r#""0x""#).unwrap(); - let deserialized2: U256 = serde_json::from_str(r#""0x0""#).unwrap(); - let deserialized3: U256 = serde_json::from_str(r#""0x1""#).unwrap(); - let deserialized4: U256 = serde_json::from_str(r#""0x01""#).unwrap(); - let deserialized5: U256 = serde_json::from_str(r#""0x100""#).unwrap(); - - assert_eq!(deserialized1, U256(0.into())); - assert_eq!(deserialized2, U256(0.into())); - assert_eq!(deserialized3, U256(1.into())); - assert_eq!(deserialized4, U256(1.into())); - assert_eq!(deserialized5, U256(256.into())); - } -} From f2ddacbb705b05bafd31b1c02c72d217b83e482c Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Tue, 12 Feb 2019 17:50:28 +0100 Subject: [PATCH 08/13] feat(tests ethereum-types): add tests --- rpc/Cargo.toml | 2 +- rpc/src/v1/types/eth_types.rs | 62 +++++++++++++++++++++++++++++++++++ rpc/src/v1/types/mod.rs | 3 ++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 rpc/src/v1/types/eth_types.rs diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index 2d4629dbfb2..f4c31f9c306 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -46,7 +46,7 @@ ethcore-network = { path = "../util/network" } ethcore-private-tx = { path = "../ethcore/private-tx" } ethcore-sync = { path = "../ethcore/sync" } ethbloom = "0.5" -ethereum-types = "0.4" +ethereum-types = "0.4.1" fastmap = { path = "../util/fastmap" } parity-bytes = "0.1" parity-crypto = "0.3.0" diff --git a/rpc/src/v1/types/eth_types.rs b/rpc/src/v1/types/eth_types.rs new file mode 100644 index 00000000000..9269e261f90 --- /dev/null +++ b/rpc/src/v1/types/eth_types.rs @@ -0,0 +1,62 @@ +use ethereum_types::{H256, U256}; +use serde_json; + +type Res = Result; + +#[test] +fn should_serialize_u256() { + let serialized1 = serde_json::to_string(&U256::from(0)).unwrap(); + let serialized2 = serde_json::to_string(&U256::from(1)).unwrap(); + let serialized3 = serde_json::to_string(&U256::from(16)).unwrap(); + let serialized4 = serde_json::to_string(&U256::from(256)).unwrap(); + + assert_eq!(serialized1, r#""0x0""#); + assert_eq!(serialized2, r#""0x1""#); + assert_eq!(serialized3, r#""0x10""#); + assert_eq!(serialized4, r#""0x100""#); +} + +#[test] +fn should_serialize_h256() { + let serialized1 = serde_json::to_string(&H256::from(0)).unwrap(); + let serialized2 = serde_json::to_string(&H256::from(1)).unwrap(); + let serialized3 = serde_json::to_string(&H256::from(16)).unwrap(); + let serialized4 = serde_json::to_string(&H256::from(256)).unwrap(); + + assert_eq!(serialized1, r#""0x0000000000000000000000000000000000000000000000000000000000000000""#); + assert_eq!(serialized2, r#""0x0000000000000000000000000000000000000000000000000000000000000001""#); + assert_eq!(serialized3, r#""0x0000000000000000000000000000000000000000000000000000000000000010""#); + assert_eq!(serialized4, r#""0x0000000000000000000000000000000000000000000000000000000000000100""#); +} + +#[test] +fn should_fail_to_deserialize_decimals() { + let deserialized0: Res = serde_json::from_str(r#""∀∂""#); + let deserialized1: Res = serde_json::from_str(r#""""#); + let deserialized2: Res = serde_json::from_str(r#""0""#); + let deserialized3: Res = serde_json::from_str(r#""10""#); + let deserialized4: Res = serde_json::from_str(r#""1000000""#); + let deserialized5: Res = serde_json::from_str(r#""1000000000000000000""#); + let deserialized6: Res = serde_json::from_str(r#""0x""#); + + assert!(deserialized0.is_err()); + assert!(deserialized1.is_err()); + assert!(deserialized2.is_err()); + assert!(deserialized3.is_err()); + assert!(deserialized4.is_err()); + assert!(deserialized5.is_err()); + assert!(deserialized6.is_err(), "Quantities should represent zero as 0x0"); +} + +#[test] +fn should_deserialize_u256() { + let deserialized1: U256 = serde_json::from_str(r#""0x0""#).unwrap(); + let deserialized2: U256 = serde_json::from_str(r#""0x1""#).unwrap(); + let deserialized3: U256 = serde_json::from_str(r#""0x01""#).unwrap(); + let deserialized4: U256 = serde_json::from_str(r#""0x100""#).unwrap(); + + assert_eq!(deserialized1, 0.into()); + assert_eq!(deserialized2, 1.into()); + assert_eq!(deserialized3, 1.into()); + assert_eq!(deserialized4, 256.into()); +} diff --git a/rpc/src/v1/types/mod.rs b/rpc/src/v1/types/mod.rs index d340d8c42ff..a41f49fab18 100644 --- a/rpc/src/v1/types/mod.rs +++ b/rpc/src/v1/types/mod.rs @@ -16,6 +16,9 @@ //! RPC types +#[cfg(test)] +mod eth_types; + mod account_info; mod block; mod block_number; From 6aa654f0a17d5ac176b424e9ddd21bc4d40507e2 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 13 Feb 2019 10:41:32 +0100 Subject: [PATCH 09/13] chore(update `ethereum-types` to 0.4.2) --- Cargo.lock | 161 +---------------------------------------------------- 1 file changed, 2 insertions(+), 159 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0f25c09c8e7..46de847a348 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -261,7 +261,7 @@ dependencies = [ name = "cli-signer" version = "1.4.0" dependencies = [ - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "parity-rpc 1.12.0", "parity-rpc-client 1.4.0", @@ -821,11 +821,7 @@ name = "ethcore-call-contract" version = "0.1.0" dependencies = [ "common-types 0.1.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -834,11 +830,7 @@ name = "ethcore-db" version = "0.1.0" dependencies = [ "common-types 0.1.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -875,11 +867,7 @@ dependencies = [ "ethcore-db 0.1.0", "ethcore-io 1.12.0", "ethcore-network 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "fastmap 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -938,11 +926,7 @@ dependencies = [ "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethash 1.12.0", "ethcore-call-contract 0.1.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -968,11 +952,7 @@ dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-io 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -996,11 +976,7 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-io 1.12.0", "ethcore-network 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "igd 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1040,11 +1016,7 @@ dependencies = [ "ethcore-call-contract 0.1.0", "ethcore-io 1.12.0", "ethcore-miner 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "ethkey 0.3.0", "fetch 0.1.0", @@ -1083,11 +1055,7 @@ dependencies = [ "ethcore-accounts 0.1.0", "ethcore-call-contract 0.1.0", "ethcore-sync 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1124,11 +1092,7 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb-rocksdb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1141,11 +1105,7 @@ name = "ethcore-stratum" version = "1.12.0" dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-tcp-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1168,11 +1128,7 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-network-devp2p 1.12.0", "ethcore-private-tx 1.0.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "ethstore 0.2.1", "fastmap 0.1.0", @@ -1195,11 +1151,7 @@ dependencies = [ [[package]] name = "ethereum-types" -<<<<<<< HEAD version = "0.4.2" -======= -version = "0.4.1" ->>>>>>> chore(bump ethereum-types) source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1222,11 +1174,7 @@ dependencies = [ name = "ethjson" version = "0.1.0" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1240,11 +1188,7 @@ dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "edit-distance 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "memzero 0.1.0", @@ -1278,11 +1222,7 @@ name = "ethstore" version = "0.2.1" dependencies = [ "dir 0.1.2", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1326,11 +1266,7 @@ version = "0.1.0" dependencies = [ "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1350,11 +1286,7 @@ dependencies = [ "docopt 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "evm 0.1.0", "panic_hook 0.1.0", @@ -1411,11 +1343,7 @@ dependencies = [ name = "fake-hardware-wallet" version = "0.0.1" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", ] @@ -1428,11 +1356,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "fastmap" version = "0.1.0" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1605,11 +1529,7 @@ dependencies = [ name = "hardware-wallet" version = "1.12.0" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "hidapi 0.3.1 (git+https://github.com/paritytech/hidapi-rs)", "libusb 0.3.0 (git+https://github.com/paritytech/libusb-rs)", @@ -1889,11 +1809,7 @@ name = "journaldb" version = "0.2.0" dependencies = [ "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "fastmap 0.1.0", "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)", @@ -2014,11 +1930,7 @@ name = "keccak-hash" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2394,11 +2306,7 @@ dependencies = [ "ethcore-io 1.12.0", "ethcore-network 1.12.0", "ethcore-network-devp2p 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2589,11 +2497,7 @@ dependencies = [ "ethcore-secretstore 1.0.0", "ethcore-service 0.1.0", "ethcore-sync 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "ethstore 0.2.1", "fake-fetch 0.0.1", @@ -2649,11 +2553,7 @@ dependencies = [ "ethabi 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "fake-fetch 0.0.1", "fetch 0.1.0", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2675,11 +2575,7 @@ version = "1.12.0" dependencies = [ "cid 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2708,11 +2604,7 @@ dependencies = [ name = "parity-machine" version = "0.1.0" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) ] [[package]] @@ -2760,11 +2652,7 @@ dependencies = [ "ethcore-network 1.12.0", "ethcore-private-tx 1.0.0", "ethcore-sync 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "ethkey 0.3.0", "ethstore 0.2.1", @@ -2813,7 +2701,7 @@ dependencies = [ name = "parity-rpc-client" version = "1.4.0" dependencies = [ - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-ws-server 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2880,11 +2768,7 @@ dependencies = [ "ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-sync 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2927,11 +2811,7 @@ dependencies = [ "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore-network 1.12.0", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethkey 0.3.0", "hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3029,11 +2909,7 @@ name = "patricia-trie-ethereum" version = "0.1.0" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "journaldb 0.2.0", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3206,11 +3082,7 @@ version = "0.1.0" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3472,11 +3344,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3486,11 +3354,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4222,11 +4086,7 @@ name = "trie-standardmap" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4245,11 +4105,7 @@ dependencies = [ name = "triehash-ethereum" version = "0.2.0" dependencies = [ -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "keccak-hasher 0.1.1", "triehash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4422,11 +4278,7 @@ name = "vm" version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "ethjson 0.1.0", "keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4477,11 +4329,7 @@ version = "0.1.0" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", -<<<<<<< HEAD "ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -======= - "ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ->>>>>>> chore(bump ethereum-types) "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4683,13 +4531,8 @@ dependencies = [ "checksum ethabi-contract 6.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "795e25fd868e12a59ca235dbe1f6cc8f1eba8f67d6a39438b29535e0126e0c27" "checksum ethabi-derive 6.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "66a587250c8190be9d6ae28d67b8957ed97cb9eee2e272173a20593ab054a075" "checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" -<<<<<<< HEAD "checksum ethereum-types 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e742184dc63a01c8ea0637369f8faa27c40f537949908a237f95c05e68d2c96" "checksum ethereum-types-serialize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1873d77b32bc1891a79dad925f2acbc318ee942b38b9110f9dbc5fbeffcea350" -======= -"checksum ethereum-types 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5ef1b8b23cb62440bad25bfb5d0f5ba97f18ebabd9b777ef0ef5d37c72cca3c0" -"checksum ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ac59a21a9ce98e188f3dace9eb67a6c4a3c67ec7fbc7218cb827852679dc002" ->>>>>>> chore(bump ethereum-types) "checksum failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad3bf1642583ea2f1fa38a1e8546613a7488816941b33e5f0fccceac61879118" "checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" "checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" From 5b30381ca8bed48dcb7f8327473a49280eaac52e Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 13 Feb 2019 11:31:01 +0100 Subject: [PATCH 10/13] feat(tests for h256) --- rpc/src/v1/types/eth_types.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/rpc/src/v1/types/eth_types.rs b/rpc/src/v1/types/eth_types.rs index 9269e261f90..606e7592489 100644 --- a/rpc/src/v1/types/eth_types.rs +++ b/rpc/src/v1/types/eth_types.rs @@ -48,6 +48,17 @@ fn should_fail_to_deserialize_decimals() { assert!(deserialized6.is_err(), "Quantities should represent zero as 0x0"); } +#[test] +fn should_fail_to_deserialize_bad_hex_strings() { + let deserialized1: Result = serde_json::from_str(r#""0""#); + let deserialized2: Result = serde_json::from_str(r#""0x""#); + let deserialized3: Result = serde_json::from_str(r#""0x∀∂0000000000000000000000000000000000000000000000000000000000""#); + + assert!(deserialized1.is_err(), "hex string should start with 0x"); + assert!(deserialized2.is_err(), "0x-prefixed hex string of length 64"); + assert!(deserialized3.is_err(), "hex string should only contain hex chars"); +} + #[test] fn should_deserialize_u256() { let deserialized1: U256 = serde_json::from_str(r#""0x0""#).unwrap(); @@ -60,3 +71,14 @@ fn should_deserialize_u256() { assert_eq!(deserialized3, 1.into()); assert_eq!(deserialized4, 256.into()); } + +#[test] +fn should_deserialize_h256() { + let deserialized1: H256 = serde_json::from_str(r#""0x0000000000000000000000000000000000000000000000000000000000000000""#).unwrap(); + let deserialized2: H256 = serde_json::from_str(r#""0x0000000000000000000000000000000000000000000000000000000000000001""#).unwrap(); + let deserialized3: H256 = serde_json::from_str(r#""0x0000000000000000000000000000000000000000000000000000000000000100""#).unwrap(); + + assert_eq!(deserialized1, 0.into()); + assert_eq!(deserialized2, 1.into()); + assert_eq!(deserialized3, 256.into()); +} From 6b7d773a53937e0e3a2bffa0ee10e5ac45cca2cc Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 13 Feb 2019 11:38:04 +0100 Subject: [PATCH 11/13] chore(rpc): remove `ethbloom` import Use re-export from `ethereum-types` instead --- Cargo.lock | 1 - rpc/Cargo.toml | 3 +-- rpc/src/lib.rs | 1 - rpc/src/v1/types/block.rs | 7 ++----- rpc/src/v1/types/receipt.rs | 3 +-- 5 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46de847a348..71061696dee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2642,7 +2642,6 @@ dependencies = [ "common-types 0.1.0", "eip-712 0.1.0", "ethash 1.12.0", - "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethcore 1.12.0", "ethcore-accounts 0.1.0", "ethcore-io 1.12.0", diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index f4c31f9c306..c6c59dc15a4 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -45,8 +45,7 @@ ethcore-miner = { path = "../miner" } ethcore-network = { path = "../util/network" } ethcore-private-tx = { path = "../ethcore/private-tx" } ethcore-sync = { path = "../ethcore/sync" } -ethbloom = "0.5" -ethereum-types = "0.4.1" +ethereum-types = "0.4" fastmap = { path = "../util/fastmap" } parity-bytes = "0.1" parity-crypto = "0.3.0" diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index d946364220f..4a90fbe6939 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -48,7 +48,6 @@ extern crate ethcore; extern crate fastmap; extern crate parity_bytes as bytes; extern crate parity_crypto as crypto; -extern crate ethbloom; extern crate ethcore_io as io; extern crate ethcore_light as light; extern crate ethcore_logger; diff --git a/rpc/src/v1/types/block.rs b/rpc/src/v1/types/block.rs index 86078ee61bf..6e23647a0ec 100644 --- a/rpc/src/v1/types/block.rs +++ b/rpc/src/v1/types/block.rs @@ -17,12 +17,10 @@ use std::ops::Deref; use std::collections::BTreeMap; -use ethbloom::Bloom as H2048; -use ethereum_types::{H160, H256, U256}; +use ethereum_types::{H160, H256, U256, Bloom as H2048}; use serde::ser::Error; use serde::{Serialize, Serializer}; use types::encoded::Header as EthHeader; - use v1::types::{Bytes, Transaction}; /// Block Transactions @@ -207,8 +205,7 @@ impl Serialize for Rich { #[cfg(test)] mod tests { use std::collections::BTreeMap; - use ethbloom::Bloom as H2048; - use ethereum_types::{H64, H160, H256, U256}; + use ethereum_types::{H64, H160, H256, U256, Bloom as H2048}; use serde_json; use v1::types::{Transaction, Bytes}; use super::{Block, RichBlock, BlockTransactions, Header, RichHeader}; diff --git a/rpc/src/v1/types/receipt.rs b/rpc/src/v1/types/receipt.rs index 98e9f34e0b3..f440c8f4864 100644 --- a/rpc/src/v1/types/receipt.rs +++ b/rpc/src/v1/types/receipt.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity Ethereum. If not, see . -use ethereum_types::{H160, H256, U64, U256}; -use ethbloom::Bloom as H2048; +use ethereum_types::{H160, H256, U64, U256, Bloom as H2048}; use v1::types::Log; use types::receipt::{Receipt as EthReceipt, RichReceipt, LocalizedReceipt, TransactionOutcome}; From 8db4d7bbdacf614f8bff366f90d505bc4669c0b0 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Wed, 13 Feb 2019 12:24:29 +0100 Subject: [PATCH 12/13] fix(bad merge): remove `DefaultAccount` type --- .../v1/helpers/external_signer/signing_queue.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/rpc/src/v1/helpers/external_signer/signing_queue.rs b/rpc/src/v1/helpers/external_signer/signing_queue.rs index abc5058ac8b..9bbc778ece1 100644 --- a/rpc/src/v1/helpers/external_signer/signing_queue.rs +++ b/rpc/src/v1/helpers/external_signer/signing_queue.rs @@ -16,7 +16,7 @@ use std::collections::BTreeMap; -use ethereum_types::{H160, U256, Address}; +use ethereum_types::U256; use parking_lot::{Mutex, RwLock}; use super::oneshot; use v1::helpers::errors; @@ -28,18 +28,6 @@ use jsonrpc_core::Error; /// Result that can be returned from JSON RPC. pub type ConfirmationResult = Result; -/// Type of default account -pub enum DefaultAccount { - /// Default account is known - Provided(Address), -} - -impl From for DefaultAccount { - fn from(address: H160) -> Self { - DefaultAccount::Provided(address.into()) - } -} - /// Possible events happening in the queue that can be listened to. #[derive(Debug, PartialEq, Clone)] pub enum QueueEvent { From 3ff03c823612eaffc5d446cd1a002472ac8f6dee Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Sun, 24 Feb 2019 23:02:46 +0100 Subject: [PATCH 13/13] doc(add TODO with issue link) --- rpc/src/v1/helpers/subscribers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/src/v1/helpers/subscribers.rs b/rpc/src/v1/helpers/subscribers.rs index 69af21f7381..9483d8e3216 100644 --- a/rpc/src/v1/helpers/subscribers.rs +++ b/rpc/src/v1/helpers/subscribers.rs @@ -36,7 +36,7 @@ impl str::FromStr for Id { } } impl Id { - // FIXME: [niklasad1] replace `format` with `serde_json::to_string_pretty` + // TODO: replace `format!` see [#10412](https://github.com/paritytech/parity-ethereum/issues/10412) pub fn as_string(&self) -> String { format!("{:?}", self.0) }