From 29dc10c446573173c40afd4d48fd64562e211a33 Mon Sep 17 00:00:00 2001 From: Karim Agha Date: Fri, 12 Mar 2021 14:55:49 +0100 Subject: [PATCH] Updating ethcore and ethjson crates to Rust Edition 2018 (#316) * Migrating use crate::Type imports to Rust 2018 edition * import name fixes * fmt * removing diff leftover * catching up with latest developments on dev * fmt * removing another diff leftover --- Cargo.lock | 24 ++++++ bin/oe/account.rs | 8 +- bin/oe/account_utils.rs | 8 +- bin/oe/blockchain.rs | 20 +++-- bin/oe/configuration.rs | 85 ++++++++++--------- bin/oe/helpers.rs | 16 ++-- bin/oe/informant.rs | 8 +- bin/oe/lib.rs | 8 +- bin/oe/modules.rs | 8 +- bin/oe/params.rs | 14 +-- bin/oe/presale.rs | 8 +- bin/oe/rpc.rs | 8 +- bin/oe/rpc_apis.rs | 8 +- bin/oe/run.rs | 45 +++++----- bin/oe/secretstore.rs | 3 +- bin/oe/signer.rs | 4 +- bin/oe/snapshot.rs | 17 ++-- crates/ethcore/types/Cargo.toml | 9 +- crates/ethcore/types/src/account_diff.rs | 4 +- crates/ethcore/types/src/block.rs | 8 +- crates/ethcore/types/src/blockchain_info.rs | 3 +- crates/ethcore/types/src/encoded.rs | 15 ++-- crates/ethcore/types/src/filter.rs | 7 +- crates/ethcore/types/src/header.rs | 12 +-- crates/ethcore/types/src/ids.rs | 2 +- crates/ethcore/types/src/lib.rs | 13 +-- crates/ethcore/types/src/log_entry.rs | 4 +- crates/ethcore/types/src/receipt.rs | 8 +- crates/ethcore/types/src/security_level.rs | 2 +- crates/ethcore/types/src/snapshot_manifest.rs | 2 +- crates/ethcore/types/src/state_diff.rs | 2 +- crates/ethcore/types/src/trace_filter.rs | 2 +- crates/ethcore/types/src/transaction/error.rs | 1 + .../types/src/transaction/transaction.rs | 31 +++---- crates/ethcore/types/src/views/block.rs | 13 +-- crates/ethcore/types/src/views/body.rs | 17 ++-- crates/ethcore/types/src/views/header.rs | 4 +- .../types/src/views/typed_transaction.rs | 10 ++- crates/ethjson/Cargo.toml | 6 +- crates/ethjson/src/blockchain/account.rs | 5 +- crates/ethjson/src/blockchain/block.rs | 8 +- crates/ethjson/src/blockchain/blockchain.rs | 12 +-- crates/ethjson/src/blockchain/header.rs | 10 ++- crates/ethjson/src/blockchain/test.rs | 2 +- crates/ethjson/src/blockchain/transaction.rs | 7 +- crates/ethjson/src/bytes.rs | 2 +- crates/ethjson/src/hash.rs | 2 +- crates/ethjson/src/lib.rs | 6 +- crates/ethjson/src/local_tests/mod.rs | 2 +- crates/ethjson/src/maybe.rs | 3 +- crates/ethjson/src/spec/account.rs | 8 +- crates/ethjson/src/spec/authority_round.rs | 12 +-- crates/ethjson/src/spec/basic_authority.rs | 10 ++- crates/ethjson/src/spec/builtin.rs | 2 +- crates/ethjson/src/spec/engine.rs | 2 +- crates/ethjson/src/spec/ethash.rs | 16 ++-- crates/ethjson/src/spec/genesis.rs | 20 +++-- crates/ethjson/src/spec/null_engine.rs | 4 +- crates/ethjson/src/spec/params.rs | 11 +-- crates/ethjson/src/spec/seal.rs | 14 +-- crates/ethjson/src/spec/spec.rs | 4 +- crates/ethjson/src/spec/state.rs | 8 +- crates/ethjson/src/spec/validator_set.rs | 7 +- crates/ethjson/src/state/log.rs | 19 ++++- crates/ethjson/src/state/mod.rs | 3 +- crates/ethjson/src/state/state.rs | 10 ++- crates/ethjson/src/state/test.rs | 22 +++-- crates/ethjson/src/state/transaction.rs | 12 +-- crates/ethjson/src/test/mod.rs | 3 +- crates/ethjson/src/transaction/test.rs | 2 +- crates/ethjson/src/transaction/transaction.rs | 39 +++++++-- crates/ethjson/src/transaction/txtest.rs | 10 ++- crates/ethjson/src/trie/input.rs | 4 +- crates/ethjson/src/trie/test.rs | 2 +- crates/ethjson/src/trie/trie.rs | 3 +- crates/ethjson/src/uint.rs | 2 +- crates/ethjson/src/vm/call.rs | 11 +-- crates/ethjson/src/vm/env.rs | 5 +- crates/ethjson/src/vm/test.rs | 2 +- crates/ethjson/src/vm/transaction.rs | 6 +- crates/ethjson/src/vm/vm.rs | 14 +-- 81 files changed, 467 insertions(+), 346 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 97cb5d193..4baf2a786 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,11 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + [[package]] name = "aes" version = "0.3.2" @@ -438,6 +444,9 @@ name = "common-types" version = "0.1.0" dependencies = [ "ethereum-types", + "ethkey", + "hex", + "inflate", "keccak-hash", "parity-bytes", "parity-crypto", @@ -1804,6 +1813,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + [[package]] name = "hex-literal" version = "0.2.1" @@ -2056,6 +2071,15 @@ dependencies = [ "autocfg 0.1.7", ] +[[package]] +name = "inflate" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cdb29978cc5797bd8dcc8e5bf7de604891df2a8dc576973d71a281e916db2ff" +dependencies = [ + "adler32", +] + [[package]] name = "interleaved-ordered" version = "0.1.1" diff --git a/bin/oe/account.rs b/bin/oe/account.rs index 430dd2a19..0bd87cdbd 100644 --- a/bin/oe/account.rs +++ b/bin/oe/account.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use params::SpecType; +use crate::params::SpecType; use std::num::NonZeroU32; #[derive(Debug, PartialEq)] @@ -53,9 +53,11 @@ pub fn execute(_cmd: AccountCmd) -> Result { #[cfg(feature = "accounts")] mod command { use super::*; - use accounts::{AccountProvider, AccountProviderSettings}; + use crate::{ + accounts::{AccountProvider, AccountProviderSettings}, + helpers::{password_from_file, password_prompt}, + }; use ethstore::{accounts_dir::RootDiskDirectory, import_account, import_accounts, EthStore}; - use helpers::{password_from_file, password_prompt}; use std::path::PathBuf; pub fn execute(cmd: AccountCmd) -> Result { diff --git a/bin/oe/account_utils.rs b/bin/oe/account_utils.rs index 902e557cc..405aa917c 100644 --- a/bin/oe/account_utils.rs +++ b/bin/oe/account_utils.rs @@ -21,7 +21,7 @@ use dir::Directories; use ethereum_types::{Address, H160}; use ethkey::Password; -use params::{AccountsConfig, SpecType}; +use crate::params::{AccountsConfig, SpecType}; #[cfg(not(feature = "accounts"))] mod accounts { @@ -71,10 +71,10 @@ mod accounts { #[cfg(feature = "accounts")] mod accounts { use super::*; + use crate::upgrade::upgrade_key_location; use std::str::FromStr; - use upgrade::upgrade_key_location; - pub use accounts::AccountProvider; + pub use crate::accounts::AccountProvider; /// Pops along with error messages when a password is missing or invalid. const VERIFY_PASSWORD_HINT: &str = "Make sure valid password is present in files passed using `--password` or in the configuration file."; @@ -87,7 +87,7 @@ mod accounts { cfg: AccountsConfig, passwords: &[Password], ) -> Result { - use accounts::AccountProviderSettings; + use crate::accounts::AccountProviderSettings; use ethstore::{accounts_dir::RootDiskDirectory, EthStore}; let path = dirs.keys_path(data_dir); diff --git a/bin/oe/blockchain.rs b/bin/oe/blockchain.rs index f101aa869..d7f585758 100644 --- a/bin/oe/blockchain.rs +++ b/bin/oe/blockchain.rs @@ -16,10 +16,18 @@ use std::{fs, io, sync::Arc, time::Instant}; +use crate::{ + bytes::ToPretty, + cache::CacheConfig, + db, + hash::{keccak, KECCAK_NULL_RLP}, + helpers::{execute_upgrades, to_client_config}, + informant::{FullNodeInformantData, Informant, MillisecondDuration}, + params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch}, + types::data_format::DataFormat, + user_defaults::UserDefaults, +}; use ansi_term::Colour; -use bytes::ToPretty; -use cache::CacheConfig; -use db; use dir::Directories; use ethcore::{ client::{ @@ -31,12 +39,6 @@ use ethcore::{ }; use ethcore_service::ClientService; use ethereum_types::{Address, H256, U256}; -use hash::{keccak, KECCAK_NULL_RLP}; -use helpers::{execute_upgrades, to_client_config}; -use informant::{FullNodeInformantData, Informant, MillisecondDuration}; -use params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch}; -use types::data_format::DataFormat; -use user_defaults::UserDefaults; #[derive(Debug, PartialEq)] pub enum BlockchainCmd { diff --git a/bin/oe/configuration.rs b/bin/oe/configuration.rs index 84c83bca8..1e3743c5c 100644 --- a/bin/oe/configuration.rs +++ b/bin/oe/configuration.rs @@ -14,9 +14,16 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + bytes::Bytes, + cli::{Args, ArgsError}, + hash::keccak, + metrics::MetricsConfiguration, + miner::pool, + sync::{self, validate_node_url, NetworkConfiguration}, +}; use ansi_term::Colour; -use bytes::Bytes; -use cli::{Args, ArgsError}; + use crypto::publickey::{Public, Secret}; use ethcore::{ client::VMType, @@ -25,9 +32,7 @@ use ethcore::{ verification::queue::VerifierSettings, }; use ethereum_types::{Address, H256, U256}; -use hash::keccak; -use metrics::MetricsConfiguration; -use miner::pool; + use num_cpus; use parity_version::{version, version_data}; use std::{ @@ -40,35 +45,37 @@ use std::{ path::PathBuf, time::Duration, }; -use sync::{self, validate_node_url, NetworkConfiguration}; -use account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount}; -use blockchain::{ - BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain, KillBlockchain, ResetBlockchain, +use crate::{ + account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount}, + blockchain::{ + BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain, KillBlockchain, + ResetBlockchain, + }, + cache::CacheConfig, + helpers::{ + parity_ipc_path, to_address, to_addresses, to_block_id, to_bootnodes, to_duration, to_mode, + to_pending_set, to_price, to_queue_penalization, to_queue_strategy, to_u256, + }, + network::IpFilter, + params::{AccountsConfig, GasPricerConfig, MinerExtras, ResealPolicy, SpecType}, + presale::ImportWallet, + rpc::{HttpConfiguration, IpcConfiguration, WsConfiguration}, + run::RunCmd, + secretstore::{ + Configuration as SecretStoreConfiguration, ContractAddress as SecretStoreContractAddress, + NodeSecretKey, + }, + snapshot::{self, SnapshotCommand}, + types::data_format::DataFormat, }; -use cache::CacheConfig; use dir::{ self, default_data_path, default_local_path, helpers::{replace_home, replace_home_and_local}, Directories, }; use ethcore_logger::Config as LogConfig; -use helpers::{ - parity_ipc_path, to_address, to_addresses, to_block_id, to_bootnodes, to_duration, to_mode, - to_pending_set, to_price, to_queue_penalization, to_queue_strategy, to_u256, -}; -use network::IpFilter; -use params::{AccountsConfig, GasPricerConfig, MinerExtras, ResealPolicy, SpecType}; use parity_rpc::NetworkSettings; -use presale::ImportWallet; -use rpc::{HttpConfiguration, IpcConfiguration, WsConfiguration}; -use run::RunCmd; -use secretstore::{ - Configuration as SecretStoreConfiguration, ContractAddress as SecretStoreContractAddress, - NodeSecretKey, -}; -use snapshot::{self, SnapshotCommand}; -use types::data_format::DataFormat; const DEFAULT_MAX_PEERS: u16 = 50; const DEFAULT_MIN_PEERS: u16 = 25; @@ -166,7 +173,7 @@ impl Configuration { let cmd = if self.args.flag_version { Cmd::Version } else if self.args.cmd_signer { - let authfile = ::signer::codes_path(&ws_conf.signer_path); + let authfile = crate::signer::codes_path(&ws_conf.signer_path); if self.args.cmd_signer_new_token { Cmd::SignerToken(ws_conf, logger_config.clone()) @@ -1243,23 +1250,25 @@ fn into_secretstore_service_contract_address( mod tests { use std::{fs::File, io::Write, str::FromStr}; - use account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount}; - use blockchain::{BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain}; - use cli::Args; + use crate::{ + account::{AccountCmd, ImportAccounts, ListAccounts, NewAccount}, + blockchain::{BlockchainCmd, ExportBlockchain, ExportState, ImportBlockchain}, + cli::Args, + helpers::default_network_config, + miner::pool::PrioritizationStrategy, + params::SpecType, + presale::ImportWallet, + rpc::WsConfiguration, + rpc_apis::ApiSet, + run::RunCmd, + types::{data_format::DataFormat, ids::BlockId}, + }; use dir::Directories; use ethcore::{client::VMType, miner::MinerOptions}; - use helpers::default_network_config; - use miner::pool::PrioritizationStrategy; - use params::SpecType; use parity_rpc::NetworkSettings; - use presale::ImportWallet; - use rpc::WsConfiguration; - use rpc_apis::ApiSet; - use run::RunCmd; use tempdir::TempDir; - use types::{data_format::DataFormat, ids::BlockId}; - use network::{AllowIP, IpFilter}; + use crate::network::{AllowIP, IpFilter}; extern crate ipnetwork; use self::ipnetwork::IpNetwork; diff --git a/bin/oe/helpers.rs b/bin/oe/helpers.rs index e9cdf93df..688ba25e4 100644 --- a/bin/oe/helpers.rs +++ b/bin/oe/helpers.rs @@ -14,8 +14,13 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -use cache::CacheConfig; -use db::migrate; +use crate::{ + cache::CacheConfig, + db::migrate, + miner::pool::PrioritizationStrategy, + sync::{self, validate_node_url}, + upgrade::{upgrade, upgrade_data_paths}, +}; use dir::{helpers::replace_home, DatabaseDirectories}; use ethcore::{ client::{BlockId, ClientConfig, DatabaseCompactionProfile, Mode, VMType, VerifierType}, @@ -24,7 +29,6 @@ use ethcore::{ use ethereum_types::{Address, U256}; use ethkey::Password; use journaldb::Algorithm; -use miner::pool::PrioritizationStrategy; use std::{ collections::HashSet, fs::File, @@ -32,8 +36,6 @@ use std::{ io::{BufRead, BufReader, Write}, time::Duration, }; -use sync::{self, validate_node_url}; -use upgrade::{upgrade, upgrade_data_paths}; pub fn to_duration(s: &str) -> Result { to_seconds(s).map(Duration::from_secs) @@ -223,9 +225,9 @@ pub fn to_bootnodes(bootnodes: &Option) -> Result, String> { } #[cfg(test)] -pub fn default_network_config() -> ::sync::NetworkConfiguration { +pub fn default_network_config() -> crate::sync::NetworkConfiguration { use super::network::IpFilter; - use sync::NetworkConfiguration; + use crate::sync::NetworkConfiguration; NetworkConfiguration { config_path: Some(replace_home(&::dir::default_data_path(), "$BASE/network")), net_config_path: None, diff --git a/bin/oe/informant.rs b/bin/oe/informant.rs index 45d8eb354..ae205f6fc 100644 --- a/bin/oe/informant.rs +++ b/bin/oe/informant.rs @@ -29,6 +29,11 @@ use std::{ time::{Duration, Instant}, }; +use crate::{ + io::{IoContext, IoHandler, TimerToken}, + sync::{ManageNetwork, SyncProvider}, + types::BlockNumber, +}; use atty; use ethcore::{ client::{ @@ -37,12 +42,9 @@ use ethcore::{ }, snapshot::{service::Service as SnapshotService, RestorationStatus, SnapshotService as SS}, }; -use io::{IoContext, IoHandler, TimerToken}; use number_prefix::{binary_prefix, Prefixed, Standalone}; use parity_rpc::{informant::RpcStats, is_major_importing_or_waiting}; use parking_lot::{Mutex, RwLock}; -use sync::{ManageNetwork, SyncProvider}; -use types::BlockNumber; /// Format byte counts to standard denominations. pub fn format_bytes(b: usize) -> String { diff --git a/bin/oe/lib.rs b/bin/oe/lib.rs index ed9a7166e..4c7a596b1 100644 --- a/bin/oe/lib.rs +++ b/bin/oe/lib.rs @@ -114,9 +114,11 @@ mod user_defaults; use std::{fs::File, io::BufReader, sync::Arc}; -use cli::Args; -use configuration::{Cmd, Execute}; -use hash::keccak_buffer; +use crate::{ + cli::Args, + configuration::{Cmd, Execute}, + hash::keccak_buffer, +}; #[cfg(feature = "memory_profiling")] use std::alloc::System; diff --git a/bin/oe/modules.rs b/bin/oe/modules.rs index 5cf6971d6..8e8063521 100644 --- a/bin/oe/modules.rs +++ b/bin/oe/modules.rs @@ -16,14 +16,16 @@ use std::sync::{mpsc, Arc}; +use crate::{ + sync::{self, ConnectionFilter, NetworkConfiguration, Params, SyncConfig}, + types::BlockNumber, +}; use ethcore::{client::BlockChainClient, snapshot::SnapshotService}; use std::collections::BTreeSet; -use sync::{self, ConnectionFilter, NetworkConfiguration, Params, SyncConfig}; -use types::BlockNumber; +pub use crate::sync::{EthSync, ManageNetwork, SyncProvider}; pub use ethcore::client::ChainNotify; use ethcore_logger::Config as LogConfig; -pub use sync::{EthSync, ManageNetwork, SyncProvider}; pub type SyncModules = ( Arc, diff --git a/bin/oe/params.rs b/bin/oe/params.rs index b1be1cafb..af2747ab1 100644 --- a/bin/oe/params.rs +++ b/bin/oe/params.rs @@ -16,6 +16,13 @@ use std::{collections::HashSet, fmt, fs, num::NonZeroU32, str, time::Duration}; +use crate::{ + miner::{ + gas_price_calibrator::{GasPriceCalibrator, GasPriceCalibratorOptions}, + gas_pricer::GasPricer, + }, + user_defaults::UserDefaults, +}; use ethcore::{ client::Mode, ethereum, @@ -24,13 +31,8 @@ use ethcore::{ use ethereum_types::{Address, U256}; use fetch::Client as FetchClient; use journaldb::Algorithm; -use miner::{ - gas_price_calibrator::{GasPriceCalibrator, GasPriceCalibratorOptions}, - gas_pricer::GasPricer, -}; use parity_runtime::Executor; use parity_version::version_data; -use user_defaults::UserDefaults; use crate::configuration; @@ -374,8 +376,8 @@ pub fn mode_switch_to_bool( #[cfg(test)] mod tests { use super::{tracing_switch_to_bool, Pruning, ResealPolicy, SpecType, Switch}; + use crate::user_defaults::UserDefaults; use journaldb::Algorithm; - use user_defaults::UserDefaults; #[test] fn test_spec_type_parsing() { diff --git a/bin/oe/presale.rs b/bin/oe/presale.rs index 5a5fecf0c..c44c9fd1c 100644 --- a/bin/oe/presale.rs +++ b/bin/oe/presale.rs @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . +use crate::{ + helpers::{password_from_file, password_prompt}, + params::SpecType, +}; use crypto::publickey; + use ethkey::Password; use ethstore::PresaleWallet; -use helpers::{password_from_file, password_prompt}; -use params::SpecType; use std::num::NonZeroU32; #[derive(Debug, PartialEq)] @@ -45,6 +48,7 @@ pub fn execute(cmd: ImportWallet) -> Result { } #[cfg(feature = "accounts")] + pub fn import_account(cmd: &ImportWallet, kp: publickey::KeyPair, password: Password) { use accounts::{AccountProvider, AccountProviderSettings}; use ethstore::{accounts_dir::RootDiskDirectory, EthStore}; diff --git a/bin/oe/rpc.rs b/bin/oe/rpc.rs index 4cd639ba6..3d90b812e 100644 --- a/bin/oe/rpc.rs +++ b/bin/oe/rpc.rs @@ -16,8 +16,11 @@ use std::{collections::HashSet, io, path::PathBuf, sync::Arc}; +use crate::{ + helpers::parity_ipc_path, + rpc_apis::{self, ApiSet}, +}; use dir::{default_data_path, helpers::replace_home}; -use helpers::parity_ipc_path; use jsonrpc_core::MetaIoHandler; use parity_rpc::{ self as rpc, @@ -25,7 +28,6 @@ use parity_rpc::{ DomainsValidation, Metadata, }; use parity_runtime::Executor; -use rpc_apis::{self, ApiSet}; pub use parity_rpc::{HttpServer, IpcServer, RequestMiddleware}; //pub use parity_rpc::ws::Server as WsServer; @@ -182,7 +184,7 @@ pub fn new_ws( let signer_path; let path = match conf.support_token_api { true => { - signer_path = ::signer::codes_path(&conf.signer_path); + signer_path = crate::signer::codes_path(&conf.signer_path); Some(signer_path.as_path()) } false => None, diff --git a/bin/oe/rpc_apis.rs b/bin/oe/rpc_apis.rs index 0acb88646..50db479cb 100644 --- a/bin/oe/rpc_apis.rs +++ b/bin/oe/rpc_apis.rs @@ -23,12 +23,15 @@ use std::{ pub use parity_rpc::signer::SignerService; -use account_utils::{self, AccountProvider}; +use crate::{ + account_utils::{self, AccountProvider}, + miner::external::ExternalMiner, + sync::{ManageNetwork, SyncProvider}, +}; use ethcore::{client::Client, miner::Miner, snapshot::SnapshotService}; use ethcore_logger::RotatingLogger; use fetch::Client as FetchClient; use jsonrpc_core::{self as core, MetaIoHandler}; -use miner::external::ExternalMiner; use parity_rpc::{ dispatch::FullDispatcher, informant::{ActivityNotifier, ClientNotifier}, @@ -36,7 +39,6 @@ use parity_rpc::{ }; use parity_runtime::Executor; use parking_lot::Mutex; -use sync::{ManageNetwork, SyncProvider}; #[derive(Debug, PartialEq, Clone, Eq, Hash)] pub enum Api { diff --git a/bin/oe/run.rs b/bin/oe/run.rs index 91d274a67..503524c8b 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -22,10 +22,24 @@ use std::{ time::{Duration, Instant}, }; -use account_utils; +use crate::{ + account_utils, + cache::CacheConfig, + db, + helpers::{execute_upgrades, passwords_from_files, to_client_config}, + informant::{FullNodeInformantData, Informant}, + metrics::{start_prometheus_metrics, MetricsConfiguration}, + miner::{external::ExternalMiner, work_notify::WorkPoster}, + modules, + params::{ + fatdb_switch_to_bool, mode_switch_to_bool, tracing_switch_to_bool, AccountsConfig, + GasPricerConfig, MinerExtras, Pruning, SpecType, Switch, + }, + rpc, rpc_apis, secretstore, signer, + sync::{self, SyncConfig}, + user_defaults::UserDefaults, +}; use ansi_term::Colour; -use cache::CacheConfig; -use db; use dir::{DatabaseDirectories, Directories}; use ethcore::{ client::{BlockChainClient, BlockInfo, Client, DatabaseCompactionProfile, Mode, VMType}, @@ -36,30 +50,15 @@ use ethcore::{ use ethcore_logger::{Config as LogConfig, RotatingLogger}; use ethcore_service::ClientService; use ethereum_types::{H256, U64}; -use helpers::{execute_upgrades, passwords_from_files, to_client_config}; -use informant::{FullNodeInformantData, Informant}; use journaldb::Algorithm; use jsonrpc_core; -use metrics::{start_prometheus_metrics, MetricsConfiguration}; -use miner::{external::ExternalMiner, work_notify::WorkPoster}; -use modules; use node_filter::NodeFilter; -use params::{ - fatdb_switch_to_bool, mode_switch_to_bool, tracing_switch_to_bool, AccountsConfig, - GasPricerConfig, MinerExtras, Pruning, SpecType, Switch, -}; use parity_rpc::{ informant, is_major_importing, FutureOutput, FutureResponse, FutureResult, Metadata, NetworkSettings, Origin, PubSubSession, }; use parity_runtime::Runtime; use parity_version::version; -use rpc; -use rpc_apis; -use secretstore; -use signer; -use sync::{self, SyncConfig}; -use user_defaults::UserDefaults; // How often we attempt to take a snapshot: only snapshot on blocknumbers that are multiples of this. const SNAPSHOT_PERIOD: u64 = 20000; @@ -120,8 +119,8 @@ struct FullNodeInfo { miner: Option>, // TODO: only TXQ needed, just use that after decoupling. } -impl ::local_store::NodeInfo for FullNodeInfo { - fn pending_transactions(&self) -> Vec<::types::transaction::PendingTransaction> { +impl crate::local_store::NodeInfo for FullNodeInfo { + fn pending_transactions(&self) -> Vec { let miner = match self.miner.as_ref() { Some(m) => m, None => return Vec::new(), @@ -131,7 +130,7 @@ impl ::local_store::NodeInfo for FullNodeInfo { .local_transactions() .values() .filter_map(|status| match *status { - ::miner::pool::local_transactions::Status::Pending(ref tx) => { + crate::miner::pool::local_transactions::Status::Pending(ref tx) => { Some(tx.pending().clone()) } _ => None, @@ -387,7 +386,7 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result) -> Result. -use account_utils::AccountProvider; +use crate::{account_utils::AccountProvider, sync::SyncProvider}; use crypto::publickey::{Public, Secret}; use dir::{default_data_path, helpers::replace_home}; use ethcore::{client::Client, miner::Miner}; @@ -22,7 +22,6 @@ use ethereum_types::Address; use ethkey::Password; use parity_runtime::Executor; use std::{collections::BTreeMap, sync::Arc}; -use sync::SyncProvider; /// This node secret key. #[derive(Debug, PartialEq, Clone)] diff --git a/bin/oe/signer.rs b/bin/oe/signer.rs index 7dd00f728..ff30c11f2 100644 --- a/bin/oe/signer.rs +++ b/bin/oe/signer.rs @@ -19,12 +19,10 @@ use std::{ path::{Path, PathBuf}, }; +use crate::{path::restrict_permissions_owner, rpc, rpc_apis}; use ansi_term::Colour::White; use ethcore_logger::Config as LogConfig; use parity_rpc; -use path::restrict_permissions_owner; -use rpc; -use rpc_apis; pub const CODES_FILENAME: &'static str = "authcodes"; diff --git a/bin/oe/snapshot.rs b/bin/oe/snapshot.rs index 1cd4bbf99..3ed7f0f24 100644 --- a/bin/oe/snapshot.rs +++ b/bin/oe/snapshot.rs @@ -22,6 +22,7 @@ use std::{ time::Duration, }; +use crate::{hash::keccak, types::ids::BlockId}; use ethcore::{ client::{DatabaseCompactionProfile, Mode, VMType}, miner::Miner, @@ -32,15 +33,15 @@ use ethcore::{ }, }; use ethcore_service::ClientService; -use hash::keccak; -use types::ids::BlockId; -use cache::CacheConfig; -use db; +use crate::{ + cache::CacheConfig, + db, + helpers::{execute_upgrades, to_client_config}, + params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch}, + user_defaults::UserDefaults, +}; use dir::Directories; -use helpers::{execute_upgrades, to_client_config}; -use params::{fatdb_switch_to_bool, tracing_switch_to_bool, Pruning, SpecType, Switch}; -use user_defaults::UserDefaults; /// Kinds of snapshot commands. #[derive(Debug, PartialEq, Clone, Copy)] @@ -303,7 +304,7 @@ impl SnapshotCommand { let cur_size = p.size(); if cur_size != last_size { last_size = cur_size; - let bytes = ::informant::format_bytes(cur_size as usize); + let bytes = crate::informant::format_bytes(cur_size as usize); info!( "Snapshot: {} accounts {} blocks {}", p.accounts(), diff --git a/crates/ethcore/types/Cargo.toml b/crates/ethcore/types/Cargo.toml index 86c0d48ea..e0c059a3e 100644 --- a/crates/ethcore/types/Cargo.toml +++ b/crates/ethcore/types/Cargo.toml @@ -2,9 +2,14 @@ description = "Parity Ethereum Common Types" name = "common-types" version = "0.1.0" -authors = ["Parity Technologies "] +edition = "2018" +authors = [ + "Gnosis Ltd ", + "Parity Technologies ", +] [dependencies] +ethkey = { path = "../../accounts/ethkey" } ethereum-types = "0.9.2" keccak-hash = "0.5.0" parity-bytes = "0.1" @@ -16,6 +21,8 @@ unexpected = { path = "../../util/unexpected" } serde = "1.0" serde_json = "1.0" serde_repr = "0.1" +hex = "0.4.3" +inflate = "0.4.5" [dev-dependencies] rustc-hex = "1.0" diff --git a/crates/ethcore/types/src/account_diff.rs b/crates/ethcore/types/src/account_diff.rs index 7ea690df1..92a12902e 100644 --- a/crates/ethcore/types/src/account_diff.rs +++ b/crates/ethcore/types/src/account_diff.rs @@ -16,7 +16,7 @@ //! Diff between two accounts. -use bytes::Bytes; +use crate::bytes::Bytes; use ethereum_types::{H256, U256}; use std::{cmp::*, collections::BTreeMap, fmt}; @@ -141,7 +141,7 @@ fn interpreted_hash(u: &H256) -> String { impl fmt::Display for AccountDiff { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use bytes::ToPretty; + use crate::bytes::ToPretty; match self.nonce { Diff::Born(ref x) => write!(f, " non {}", x)?, diff --git a/crates/ethcore/types/src/block.rs b/crates/ethcore/types/src/block.rs index 221d4d64e..d0c1cc3e8 100644 --- a/crates/ethcore/types/src/block.rs +++ b/crates/ethcore/types/src/block.rs @@ -31,11 +31,13 @@ //! `ExecutedBlock` is an underlaying data structure used by all structs above to store block //! related info. -use bytes::Bytes; +use crate::bytes::Bytes; -use header::Header; +use crate::{ + header::Header, + transaction::{TypedTransaction, UnverifiedTransaction}, +}; use rlp::{Decodable, DecoderError, Rlp, RlpStream}; -use transaction::{TypedTransaction, UnverifiedTransaction}; /// A block, encoded as it is on the block chain. #[derive(Default, Debug, Clone, PartialEq)] diff --git a/crates/ethcore/types/src/blockchain_info.rs b/crates/ethcore/types/src/blockchain_info.rs index b04a8640d..008fb5a55 100644 --- a/crates/ethcore/types/src/blockchain_info.rs +++ b/crates/ethcore/types/src/blockchain_info.rs @@ -18,9 +18,8 @@ use std::fmt; +use crate::{security_level::SecurityLevel, BlockNumber}; use ethereum_types::{H256, U256}; -use security_level::SecurityLevel; -use BlockNumber; /// Information about the blockchain gathered together. #[derive(Clone, Debug)] diff --git a/crates/ethcore/types/src/encoded.rs b/crates/ethcore/types/src/encoded.rs index f55074022..7bad7945e 100644 --- a/crates/ethcore/types/src/encoded.rs +++ b/crates/ethcore/types/src/encoded.rs @@ -23,15 +23,18 @@ //! When the entirety of the object is needed, it's better to upgrade it to a fully //! decoded object where parts like the hash can be saved. -use block::Block as FullBlock; +use crate::{ + block::Block as FullBlock, + hash::keccak, + header::Header as FullHeader, + transaction::UnverifiedTransaction, + views::{self, BlockView, BodyView, HeaderView}, + BlockNumber, +}; + use ethereum_types::{Address, Bloom, H256, U256}; -use hash::keccak; -use header::Header as FullHeader; use parity_util_mem::MallocSizeOf; use rlp::{self, Rlp, RlpStream}; -use transaction::UnverifiedTransaction; -use views::{self, BlockView, BodyView, HeaderView}; -use BlockNumber; /// Owning header view. #[derive(Debug, Clone, PartialEq, Eq, MallocSizeOf)] diff --git a/crates/ethcore/types/src/filter.rs b/crates/ethcore/types/src/filter.rs index 822c2f7de..5415b447f 100644 --- a/crates/ethcore/types/src/filter.rs +++ b/crates/ethcore/types/src/filter.rs @@ -16,9 +16,8 @@ //! Blockchain filter +use crate::{ids::BlockId, log_entry::LogEntry}; use ethereum_types::{Address, Bloom, BloomInput, H256}; -use ids::BlockId; -use log_entry::LogEntry; /// Blockchain Filter. #[derive(Debug, PartialEq)] @@ -119,10 +118,8 @@ impl Filter { #[cfg(test)] mod tests { + use crate::{filter::Filter, ids::BlockId, log_entry::LogEntry}; use ethereum_types::{Bloom, H160, H256}; - use filter::Filter; - use ids::BlockId; - use log_entry::LogEntry; use std::str::FromStr; #[test] diff --git a/crates/ethcore/types/src/header.rs b/crates/ethcore/types/src/header.rs index 88c68e835..a5f9b988e 100644 --- a/crates/ethcore/types/src/header.rs +++ b/crates/ethcore/types/src/header.rs @@ -16,12 +16,14 @@ //! Block header. -use bytes::Bytes; +use crate::{ + bytes::Bytes, + hash::{keccak, KECCAK_EMPTY_LIST_RLP, KECCAK_NULL_RLP}, + BlockNumber, +}; use ethereum_types::{Address, Bloom, H256, U256}; -use hash::{keccak, KECCAK_EMPTY_LIST_RLP, KECCAK_NULL_RLP}; use parity_util_mem::MallocSizeOf; use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; -use BlockNumber; /// Semantic boolean for when a seal/signature is included. #[derive(Debug, Clone, Copy)] @@ -307,8 +309,8 @@ impl Header { } /// Encode the header, getting a type-safe wrapper around the RLP. - pub fn encoded(&self) -> ::encoded::Header { - ::encoded::Header::new(self.rlp(Seal::With)) + pub fn encoded(&self) -> crate::encoded::Header { + crate::encoded::Header::new(self.rlp(Seal::With)) } /// Get the RLP representation of this Header. diff --git a/crates/ethcore/types/src/ids.rs b/crates/ethcore/types/src/ids.rs index c117ed3c1..7be363d1d 100644 --- a/crates/ethcore/types/src/ids.rs +++ b/crates/ethcore/types/src/ids.rs @@ -16,8 +16,8 @@ //! Unique identifiers. +use crate::BlockNumber; use ethereum_types::H256; -use BlockNumber; /// Uniquely identifies block. #[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)] diff --git a/crates/ethcore/types/src/lib.rs b/crates/ethcore/types/src/lib.rs index 2eafc66ee..73e934284 100644 --- a/crates/ethcore/types/src/lib.rs +++ b/crates/ethcore/types/src/lib.rs @@ -34,20 +34,15 @@ #![allow(missing_docs)] #![warn(unused_extern_crates)] -extern crate ethereum_types; -extern crate keccak_hash as hash; -extern crate parity_bytes as bytes; -extern crate parity_crypto as crypto; -extern crate parity_util_mem; -extern crate rlp; -extern crate serde_repr; -extern crate unexpected; +pub use keccak_hash as hash; +pub use parity_bytes as bytes; +pub use parity_crypto as crypto; #[macro_use] extern crate rlp_derive; #[cfg(test)] -extern crate rustc_hex; +pub use rustc_hex; #[macro_use] pub mod views; diff --git a/crates/ethcore/types/src/log_entry.rs b/crates/ethcore/types/src/log_entry.rs index 8c72df15b..f607ce8b3 100644 --- a/crates/ethcore/types/src/log_entry.rs +++ b/crates/ethcore/types/src/log_entry.rs @@ -16,13 +16,11 @@ //! Log entry type definition. -use bytes::Bytes; +use crate::{bytes::Bytes, BlockNumber}; use ethereum_types::{Address, Bloom, BloomInput, H256}; use parity_util_mem::MallocSizeOf; use std::ops::Deref; -use BlockNumber; - /// A record of execution for a `LOG` operation. #[derive(Default, Debug, Clone, PartialEq, Eq, RlpEncodable, RlpDecodable, MallocSizeOf)] pub struct LogEntry { diff --git a/crates/ethcore/types/src/receipt.rs b/crates/ethcore/types/src/receipt.rs index 2026081a8..1ae47bc16 100644 --- a/crates/ethcore/types/src/receipt.rs +++ b/crates/ethcore/types/src/receipt.rs @@ -22,8 +22,10 @@ use parity_util_mem::MallocSizeOf; use rlp::{DecoderError, Rlp, RlpStream}; use std::ops::{Deref, DerefMut}; -use log_entry::{LocalizedLogEntry, LogEntry}; -use BlockNumber; +use crate::{ + log_entry::{LocalizedLogEntry, LogEntry}, + BlockNumber, +}; /// Transaction outcome store in the receipt. #[derive(Debug, Clone, PartialEq, Eq, MallocSizeOf)] @@ -296,8 +298,8 @@ pub struct LocalizedReceipt { #[cfg(test)] mod tests { use super::{LegacyReceipt, TransactionOutcome, TypedReceipt, TypedTxId}; + use crate::log_entry::LogEntry; use ethereum_types::{H160, H256}; - use log_entry::LogEntry; use std::str::FromStr; #[test] diff --git a/crates/ethcore/types/src/security_level.rs b/crates/ethcore/types/src/security_level.rs index 10439ff02..c49bbe40c 100644 --- a/crates/ethcore/types/src/security_level.rs +++ b/crates/ethcore/types/src/security_level.rs @@ -16,7 +16,7 @@ //! Indication of how secure the chain is. -use BlockNumber; +use crate::BlockNumber; /// Indication of how secure the chain is. #[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)] diff --git a/crates/ethcore/types/src/snapshot_manifest.rs b/crates/ethcore/types/src/snapshot_manifest.rs index 461e2a5bb..e5220e0eb 100644 --- a/crates/ethcore/types/src/snapshot_manifest.rs +++ b/crates/ethcore/types/src/snapshot_manifest.rs @@ -16,7 +16,7 @@ //! Snapshot manifest type definition -use bytes::Bytes; +use crate::bytes::Bytes; use ethereum_types::H256; use rlp::{DecoderError, Rlp, RlpStream}; diff --git a/crates/ethcore/types/src/state_diff.rs b/crates/ethcore/types/src/state_diff.rs index 439133c83..0045796c6 100644 --- a/crates/ethcore/types/src/state_diff.rs +++ b/crates/ethcore/types/src/state_diff.rs @@ -16,7 +16,7 @@ //! State diff module. -use account_diff::*; +use crate::account_diff::*; use ethereum_types::Address; use std::{collections::BTreeMap, fmt, ops::*}; diff --git a/crates/ethcore/types/src/trace_filter.rs b/crates/ethcore/types/src/trace_filter.rs index 5404bad95..66104acb4 100644 --- a/crates/ethcore/types/src/trace_filter.rs +++ b/crates/ethcore/types/src/trace_filter.rs @@ -16,8 +16,8 @@ //! Trace filter related types +use crate::ids::BlockId; use ethereum_types::Address; -use ids::BlockId; use std::ops::Range; /// Easy to use trace filter. diff --git a/crates/ethcore/types/src/transaction/error.rs b/crates/ethcore/types/src/transaction/error.rs index aa927c55e..d3351cad8 100644 --- a/crates/ethcore/types/src/transaction/error.rs +++ b/crates/ethcore/types/src/transaction/error.rs @@ -16,6 +16,7 @@ use std::{error, fmt}; +use crate::crypto; use ethereum_types::U256; use rlp; use unexpected::OutOfBounds; diff --git a/crates/ethcore/types/src/transaction/transaction.rs b/crates/ethcore/types/src/transaction/transaction.rs index 55a10506d..892b00ea0 100644 --- a/crates/ethcore/types/src/transaction/transaction.rs +++ b/crates/ethcore/types/src/transaction/transaction.rs @@ -16,10 +16,14 @@ //! Transaction data structure. -use crypto::publickey::{self, public_to_address, recover, Public, Secret, Signature}; +use crate::{ + crypto::publickey::{self, public_to_address, recover, Public, Secret, Signature}, + hash::keccak, + transaction::error, +}; use ethereum_types::{Address, BigEndianHash, H160, H256, U256}; -use hash::keccak; use parity_util_mem::MallocSizeOf; + use rlp::{self, DecoderError, Rlp, RlpStream}; use std::ops::Deref; @@ -28,8 +32,6 @@ pub type AccessList = Vec; use super::TypedTxId; -use transaction::error; - type Bytes = Vec; type BlockNumber = u64; @@ -134,7 +136,7 @@ pub struct Transaction { pub gas: U256, /// Action, can be either call or contract create. pub action: Action, - /// Transfered value. + /// Transfered value.s pub value: U256, /// Transaction data. pub data: Bytes, @@ -430,7 +432,6 @@ impl TypedTransaction { /// Legacy EIP-86 compatible empty signature. /// This method is used in json tests as well as /// signature verification tests. - #[cfg(any(test, feature = "test-helpers"))] pub fn null_sign(self, chain_id: u64) -> SignedTransaction { SignedTransaction { transaction: UnverifiedTransaction { @@ -566,11 +567,11 @@ impl TypedTransaction { pub struct SignatureComponents { /// The V field of the signature; the LS bit described which half of the curve our point falls /// in. It can be 0 or 1. - standard_v: u8, + pub standard_v: u8, /// The R field of the signature; helps describe the point on the curve. - r: U256, + pub r: U256, /// The S field of the signature; helps describe the point on the curve. - s: U256, + pub s: U256, } impl SignatureComponents { @@ -594,13 +595,13 @@ impl SignatureComponents { #[derive(Debug, Clone, Eq, PartialEq, MallocSizeOf)] pub struct UnverifiedTransaction { /// Plain Transaction. - unsigned: TypedTransaction, + pub unsigned: TypedTransaction, /// Transaction signature - signature: SignatureComponents, + pub signature: SignatureComponents, /// chain_id recover from signature in legacy transaction. For TypedTransaction it is probably separate field. - chain_id: Option, + pub chain_id: Option, /// Hash of the transaction - hash: H256, + pub hash: H256, } impl Deref for UnverifiedTransaction { @@ -628,7 +629,7 @@ impl UnverifiedTransaction { } /// Used to compute hash of created transactions. - fn compute_hash(mut self) -> UnverifiedTransaction { + pub fn compute_hash(mut self) -> UnverifiedTransaction { let hash = keccak(&*self.encode()); self.hash = hash; self @@ -874,8 +875,8 @@ impl From for PendingTransaction { #[cfg(test)] mod tests { use super::*; + use crate::hash::keccak; use ethereum_types::{H160, U256}; - use hash::keccak; use std::str::FromStr; #[test] diff --git a/crates/ethcore/types/src/views/block.rs b/crates/ethcore/types/src/views/block.rs index 1d7fbf345..06edfe9ea 100644 --- a/crates/ethcore/types/src/views/block.rs +++ b/crates/ethcore/types/src/views/block.rs @@ -17,12 +17,15 @@ //! View onto block rlp. use super::ViewRlp; -use bytes::Bytes; +use crate::{ + bytes::Bytes, + hash::keccak, + header::Header, + transaction::{LocalizedTransaction, TypedTransaction, UnverifiedTransaction}, + views::{HeaderView, TypedTransactionView}, +}; + use ethereum_types::H256; -use hash::keccak; -use header::Header; -use transaction::{LocalizedTransaction, TypedTransaction, UnverifiedTransaction}; -use views::{HeaderView, TypedTransactionView}; /// View onto block rlp. pub struct BlockView<'a> { diff --git a/crates/ethcore/types/src/views/body.rs b/crates/ethcore/types/src/views/body.rs index 3bdf7f274..218e79185 100644 --- a/crates/ethcore/types/src/views/body.rs +++ b/crates/ethcore/types/src/views/body.rs @@ -17,13 +17,15 @@ //! View onto block body rlp. use super::ViewRlp; -use bytes::Bytes; +use crate::{ + bytes::Bytes, + hash::keccak, + header::Header, + transaction::{LocalizedTransaction, TypedTransaction, UnverifiedTransaction}, + views::{HeaderView, TypedTransactionView}, + BlockNumber, +}; use ethereum_types::H256; -use hash::keccak; -use header::Header; -use transaction::{LocalizedTransaction, TypedTransaction, UnverifiedTransaction}; -use views::{HeaderView, TypedTransactionView}; -use BlockNumber; /// View onto block rlp. pub struct BodyView<'a> { @@ -184,10 +186,9 @@ impl<'a> BodyView<'a> { #[cfg(test)] mod tests { use super::BodyView; - use bytes::Bytes; + use crate::{bytes::Bytes, views::BlockView}; use rlp::RlpStream; use rustc_hex::FromHex; - use views::BlockView; fn block_to_body(block: &[u8]) -> Bytes { let mut body = RlpStream::new_list(2); diff --git a/crates/ethcore/types/src/views/header.rs b/crates/ethcore/types/src/views/header.rs index a5ecd8e2e..db33b2eb6 100644 --- a/crates/ethcore/types/src/views/header.rs +++ b/crates/ethcore/types/src/views/header.rs @@ -17,11 +17,9 @@ //! View onto block header rlp use super::ViewRlp; -use bytes::Bytes; +use crate::{bytes::Bytes, hash::keccak, BlockNumber}; use ethereum_types::{Address, Bloom, H256, U256}; -use hash::keccak; use rlp::{self}; -use BlockNumber; /// View onto block header rlp. pub struct HeaderView<'a> { diff --git a/crates/ethcore/types/src/views/typed_transaction.rs b/crates/ethcore/types/src/views/typed_transaction.rs index e9a9da115..39b670c65 100644 --- a/crates/ethcore/types/src/views/typed_transaction.rs +++ b/crates/ethcore/types/src/views/typed_transaction.rs @@ -16,12 +16,14 @@ //! View onto transaction rlp -use crate::transaction::{signature, TypedTxId}; +use crate::{ + bytes::Bytes, + hash::keccak, + transaction::{signature, TypedTxId}, + views::ViewRlp, +}; -use super::ViewRlp; -use bytes::Bytes; use ethereum_types::{H256, U256}; -use hash::keccak; use rlp::Rlp; /// View onto transaction rlp. Assumption is this is part of block. diff --git a/crates/ethjson/Cargo.toml b/crates/ethjson/Cargo.toml index 819db5dbf..436bfef02 100644 --- a/crates/ethjson/Cargo.toml +++ b/crates/ethjson/Cargo.toml @@ -2,7 +2,11 @@ description = "Parity Ethereum JSON Deserialization" name = "ethjson" version = "0.1.0" -authors = ["Parity Technologies "] +edition = "2018" +authors = [ + "Gnosis Ltd ", + "Parity Technologies " + ] [dependencies] common-types = { path = "../ethcore/types", features = ["test-helpers"] } diff --git a/crates/ethjson/src/blockchain/account.rs b/crates/ethjson/src/blockchain/account.rs index fc39b074e..678db5d10 100644 --- a/crates/ethjson/src/blockchain/account.rs +++ b/crates/ethjson/src/blockchain/account.rs @@ -16,9 +16,8 @@ //! Blockchain test account deserializer. -use bytes::Bytes; +use crate::{bytes::Bytes, uint::Uint}; use std::collections::BTreeMap; -use uint::Uint; /// Blockchain test account deserializer. #[derive(Debug, PartialEq, Deserialize, Clone)] @@ -35,7 +34,7 @@ pub struct Account { #[cfg(test)] mod tests { - use blockchain::account::Account; + use crate::blockchain::account::Account; use serde_json; #[test] diff --git a/crates/ethjson/src/blockchain/block.rs b/crates/ethjson/src/blockchain/block.rs index 045a42f33..2c6fa3839 100644 --- a/crates/ethjson/src/blockchain/block.rs +++ b/crates/ethjson/src/blockchain/block.rs @@ -16,8 +16,10 @@ //! Blockchain test block deserializer. -use blockchain::{header::Header, transaction::Transaction}; -use bytes::Bytes; +use crate::{ + blockchain::{header::Header, transaction::Transaction}, + bytes::Bytes, +}; /// Blockchain test block deserializer. #[derive(Debug, PartialEq, Deserialize)] @@ -39,7 +41,7 @@ impl Block { #[cfg(test)] mod tests { - use blockchain::block::Block; + use crate::blockchain::block::Block; use serde_json; #[test] diff --git a/crates/ethjson/src/blockchain/blockchain.rs b/crates/ethjson/src/blockchain/blockchain.rs index 7e1406f0a..3f7e5b061 100644 --- a/crates/ethjson/src/blockchain/blockchain.rs +++ b/crates/ethjson/src/blockchain/blockchain.rs @@ -16,10 +16,12 @@ //! Blockchain deserialization. -use blockchain::{block::Block, header::Header, state::State}; -use bytes::Bytes; -use hash::H256; -use spec::{Ethereum, ForkSpec, Genesis, Seal}; +use crate::{ + blockchain::{block::Block, header::Header, state::State}, + bytes::Bytes, + hash::H256, + spec::{Ethereum, ForkSpec, Genesis, Seal}, +}; /// Json Block test possible engine kind. #[derive(Debug, PartialEq, Deserialize)] @@ -93,7 +95,7 @@ impl BlockChain { #[cfg(test)] mod tests { - use blockchain::blockchain::BlockChain; + use crate::blockchain::blockchain::BlockChain; use serde_json; #[test] diff --git a/crates/ethjson/src/blockchain/header.rs b/crates/ethjson/src/blockchain/header.rs index 8fcb25caa..f03cb7dcf 100644 --- a/crates/ethjson/src/blockchain/header.rs +++ b/crates/ethjson/src/blockchain/header.rs @@ -16,9 +16,11 @@ //! Blockchain test header deserializer. -use bytes::Bytes; -use hash::{Address, Bloom, H256, H64}; -use uint::Uint; +use crate::{ + bytes::Bytes, + hash::{Address, Bloom, H256, H64}, + uint::Uint, +}; /// Blockchain test header deserializer. #[derive(Debug, PartialEq, Deserialize)] @@ -64,7 +66,7 @@ pub struct Header { #[cfg(test)] mod tests { - use blockchain::header::Header; + use crate::blockchain::header::Header; use serde_json; #[test] diff --git a/crates/ethjson/src/blockchain/test.rs b/crates/ethjson/src/blockchain/test.rs index 01ace8eb6..3eb8bed76 100644 --- a/crates/ethjson/src/blockchain/test.rs +++ b/crates/ethjson/src/blockchain/test.rs @@ -16,7 +16,7 @@ //! Blockchain test deserializer. -use blockchain::blockchain::BlockChain; +use crate::blockchain::blockchain::BlockChain; use serde_json::{self, Error}; use std::{collections::BTreeMap, io::Read}; diff --git a/crates/ethjson/src/blockchain/transaction.rs b/crates/ethjson/src/blockchain/transaction.rs index 277e52001..dc470a29d 100644 --- a/crates/ethjson/src/blockchain/transaction.rs +++ b/crates/ethjson/src/blockchain/transaction.rs @@ -16,9 +16,8 @@ //! Blockchain test transaction deserialization. -use bytes::Bytes; +use crate::{bytes::Bytes, uint::Uint}; use ethereum_types::{H160, H256}; -use uint::Uint; /// Blockchain test transaction deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -39,11 +38,11 @@ pub struct Transaction { pub hash: Option, } -pub type AccessList = Vec; - #[derive(Debug, PartialEq, Deserialize, Clone)] #[serde(rename_all = "camelCase")] pub struct AccessListItem { pub address: H160, pub storage_keys: Vec, } + +pub type AccessList = Vec; diff --git a/crates/ethjson/src/bytes.rs b/crates/ethjson/src/bytes.rs index bc9804f5d..8fd7852ac 100644 --- a/crates/ethjson/src/bytes.rs +++ b/crates/ethjson/src/bytes.rs @@ -102,7 +102,7 @@ impl<'a> Visitor<'a> for BytesVisitor { #[cfg(test)] mod test { - use bytes::Bytes; + use crate::bytes::Bytes; use serde_json; #[test] diff --git a/crates/ethjson/src/hash.rs b/crates/ethjson/src/hash.rs index c0b7d834b..bc59c966b 100644 --- a/crates/ethjson/src/hash.rs +++ b/crates/ethjson/src/hash.rs @@ -112,8 +112,8 @@ impl_hash!(Bloom, Hash2048); #[cfg(test)] mod test { + use crate::hash::H256; use ethereum_types; - use hash::H256; use serde_json; use std::str::FromStr; diff --git a/crates/ethjson/src/lib.rs b/crates/ethjson/src/lib.rs index 910175dfb..851b1dbab 100644 --- a/crates/ethjson/src/lib.rs +++ b/crates/ethjson/src/lib.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with OpenEthereum. If not, see . -extern crate common_types as types; -extern crate ethereum_types; -extern crate parity_crypto as crypto; +pub use common_types as types; +pub use parity_crypto as crypto; + extern crate rustc_hex; extern crate serde; extern crate serde_json; diff --git a/crates/ethjson/src/local_tests/mod.rs b/crates/ethjson/src/local_tests/mod.rs index f051528fb..d7b490d75 100644 --- a/crates/ethjson/src/local_tests/mod.rs +++ b/crates/ethjson/src/local_tests/mod.rs @@ -1,4 +1,4 @@ -use blockchain::block::Block; +use crate::blockchain::block::Block; use serde_json::{self, Error}; use std::{collections::BTreeMap, io::Read}; diff --git a/crates/ethjson/src/maybe.rs b/crates/ethjson/src/maybe.rs index 4d72a6735..da1116942 100644 --- a/crates/ethjson/src/maybe.rs +++ b/crates/ethjson/src/maybe.rs @@ -94,9 +94,8 @@ impl Into> for MaybeEmpty { #[cfg(test)] mod tests { + use crate::{hash::H256, maybe::MaybeEmpty}; use ethereum_types; - use hash::H256; - use maybe::MaybeEmpty; use serde_json; use std::str::FromStr; diff --git a/crates/ethjson/src/spec/account.rs b/crates/ethjson/src/spec/account.rs index 0f920db4c..f2aef63d7 100644 --- a/crates/ethjson/src/spec/account.rs +++ b/crates/ethjson/src/spec/account.rs @@ -18,9 +18,7 @@ use std::collections::BTreeMap; -use bytes::Bytes; -use spec::builtin::BuiltinCompat; -use uint::Uint; +use crate::{bytes::Bytes, spec::builtin::BuiltinCompat, uint::Uint}; /// Spec account. #[derive(Clone, Debug, PartialEq, Deserialize)] @@ -53,12 +51,10 @@ impl Account { #[cfg(test)] mod tests { - use bytes::Bytes; + use crate::{bytes::Bytes, spec::account::Account, uint::Uint}; use ethereum_types::U256; use serde_json; - use spec::account::Account; use std::collections::BTreeMap; - use uint::Uint; #[test] fn account_balance_missing_not_empty() { diff --git a/crates/ethjson/src/spec/authority_round.rs b/crates/ethjson/src/spec/authority_round.rs index 45132d7b7..f84e933a9 100644 --- a/crates/ethjson/src/spec/authority_round.rs +++ b/crates/ethjson/src/spec/authority_round.rs @@ -17,9 +17,7 @@ //! Authority params deserialization. use super::{BlockReward, ValidatorSet}; -use bytes::Bytes; -use hash::Address; -use uint::Uint; +use crate::{bytes::Bytes, hash::Address, uint::Uint}; /// Authority params deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -73,12 +71,14 @@ mod tests { use std::collections::BTreeMap; use super::BlockReward; + use crate::{ + hash::Address, + spec::{authority_round::AuthorityRound, validator_set::ValidatorSet}, + uint::Uint, + }; use ethereum_types::{H160, U256}; - use hash::Address; use serde_json; - use spec::{authority_round::AuthorityRound, validator_set::ValidatorSet}; use std::str::FromStr; - use uint::Uint; #[test] fn authority_round_deserialization() { diff --git a/crates/ethjson/src/spec/basic_authority.rs b/crates/ethjson/src/spec/basic_authority.rs index d744407a5..e42e5164f 100644 --- a/crates/ethjson/src/spec/basic_authority.rs +++ b/crates/ethjson/src/spec/basic_authority.rs @@ -17,7 +17,7 @@ //! Authority params deserialization. use super::ValidatorSet; -use uint::Uint; +use crate::uint::Uint; /// Authority params deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -40,12 +40,14 @@ pub struct BasicAuthority { #[cfg(test)] mod tests { + use crate::{ + hash::Address, + spec::{basic_authority::BasicAuthority, validator_set::ValidatorSet}, + uint::Uint, + }; use ethereum_types::{H160, U256}; - use hash::Address; use serde_json; - use spec::{basic_authority::BasicAuthority, validator_set::ValidatorSet}; use std::str::FromStr; - use uint::Uint; #[test] fn basic_authority_deserialization() { diff --git a/crates/ethjson/src/spec/builtin.rs b/crates/ethjson/src/spec/builtin.rs index 5c0adb45e..a4c7455b2 100644 --- a/crates/ethjson/src/spec/builtin.rs +++ b/crates/ethjson/src/spec/builtin.rs @@ -16,8 +16,8 @@ //! Spec builtin deserialization. +use crate::uint::Uint; use std::collections::BTreeMap; -use uint::Uint; /// Linear pricing. #[derive(Debug, PartialEq, Deserialize, Clone)] diff --git a/crates/ethjson/src/spec/engine.rs b/crates/ethjson/src/spec/engine.rs index 2a6e9faf6..f85f1dc87 100644 --- a/crates/ethjson/src/spec/engine.rs +++ b/crates/ethjson/src/spec/engine.rs @@ -40,8 +40,8 @@ pub enum Engine { #[cfg(test)] mod tests { + use crate::spec::Engine; use serde_json; - use spec::Engine; #[test] fn engine_deserialization() { diff --git a/crates/ethjson/src/spec/ethash.rs b/crates/ethjson/src/spec/ethash.rs index b7e8c0907..df20119a5 100644 --- a/crates/ethjson/src/spec/ethash.rs +++ b/crates/ethjson/src/spec/ethash.rs @@ -16,10 +16,12 @@ //! Ethash params deserialization. -use bytes::Bytes; -use hash::Address; +use crate::{ + bytes::Bytes, + hash::Address, + uint::{self, Uint}, +}; use std::collections::BTreeMap; -use uint::{self, Uint}; /// Deserializable doppelganger of block rewards for EthashParams #[derive(Clone, Debug, PartialEq, Deserialize)] @@ -105,12 +107,14 @@ pub struct Ethash { #[cfg(test)] mod tests { + use crate::{ + hash::Address, + spec::ethash::{BlockReward, Ethash, EthashParams}, + uint::Uint, + }; use ethereum_types::{H160, U256}; - use hash::Address; use serde_json; - use spec::ethash::{BlockReward, Ethash, EthashParams}; use std::str::FromStr; - use uint::Uint; #[test] fn ethash_deserialization() { diff --git a/crates/ethjson/src/spec/genesis.rs b/crates/ethjson/src/spec/genesis.rs index 38445f123..0bbc95431 100644 --- a/crates/ethjson/src/spec/genesis.rs +++ b/crates/ethjson/src/spec/genesis.rs @@ -16,10 +16,12 @@ //! Spec genesis deserialization. -use bytes::Bytes; -use hash::{Address, H256}; -use spec::Seal; -use uint::{self, Uint}; +use crate::{ + bytes::Bytes, + hash::{Address, H256}, + spec::Seal, + uint::{self, Uint}, +}; /// Spec genesis. #[derive(Debug, PartialEq, Deserialize)] @@ -53,13 +55,15 @@ pub struct Genesis { #[cfg(test)] mod tests { - use bytes::Bytes; + use crate::{ + bytes::Bytes, + hash::{Address, H256, H64}, + spec::{genesis::Genesis, Ethereum, Seal}, + uint::Uint, + }; use ethereum_types::{H160, H256 as Eth256, H64 as Eth64, U256}; - use hash::{Address, H256, H64}; use serde_json; - use spec::{genesis::Genesis, Ethereum, Seal}; use std::str::FromStr; - use uint::Uint; #[test] fn genesis_deserialization() { diff --git a/crates/ethjson/src/spec/null_engine.rs b/crates/ethjson/src/spec/null_engine.rs index 6c978b479..caa0bc47f 100644 --- a/crates/ethjson/src/spec/null_engine.rs +++ b/crates/ethjson/src/spec/null_engine.rs @@ -16,7 +16,7 @@ //! Null engine params deserialization. -use uint::Uint; +use crate::uint::Uint; /// Authority params deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -40,9 +40,9 @@ pub struct NullEngine { #[cfg(test)] mod tests { use super::*; + use crate::uint::Uint; use ethereum_types::U256; use serde_json; - use uint::Uint; #[test] fn null_engine_deserialization() { diff --git a/crates/ethjson/src/spec/params.rs b/crates/ethjson/src/spec/params.rs index 15c1747d4..7933208fe 100644 --- a/crates/ethjson/src/spec/params.rs +++ b/crates/ethjson/src/spec/params.rs @@ -16,9 +16,11 @@ //! Spec params deserialization. -use bytes::Bytes; -use hash::{Address, H256}; -use uint::{self, Uint}; +use crate::{ + bytes::Bytes, + hash::{Address, H256}, + uint::{self, Uint}, +}; /// Spec params. #[derive(Debug, PartialEq, Deserialize)] @@ -146,10 +148,9 @@ pub struct Params { #[cfg(test)] mod tests { + use crate::{spec::params::Params, uint::Uint}; use ethereum_types::U256; use serde_json; - use spec::params::Params; - use uint::Uint; #[test] fn params_deserialization() { diff --git a/crates/ethjson/src/spec/seal.rs b/crates/ethjson/src/spec/seal.rs index a53a1f07d..aebdca41a 100644 --- a/crates/ethjson/src/spec/seal.rs +++ b/crates/ethjson/src/spec/seal.rs @@ -16,9 +16,7 @@ //! Spec seal deserialization. -use bytes::Bytes; -use hash::*; -use uint::Uint; +use crate::{bytes::Bytes, hash::*, uint::Uint}; /// Ethereum seal. #[derive(Debug, PartialEq, Deserialize)] @@ -70,13 +68,15 @@ pub enum Seal { #[cfg(test)] mod tests { - use bytes::Bytes; + use crate::{ + bytes::Bytes, + hash::*, + spec::{AuthorityRoundSeal, Ethereum, Seal, TendermintSeal}, + uint::Uint, + }; use ethereum_types::{H256 as Eth256, H520 as Eth520, H64 as Eth64, U256}; - use hash::*; use serde_json; - use spec::{AuthorityRoundSeal, Ethereum, Seal, TendermintSeal}; use std::str::FromStr; - use uint::Uint; #[test] fn seal_deserialization() { diff --git a/crates/ethjson/src/spec/spec.rs b/crates/ethjson/src/spec/spec.rs index e5e23be77..9db235ac6 100644 --- a/crates/ethjson/src/spec/spec.rs +++ b/crates/ethjson/src/spec/spec.rs @@ -16,8 +16,8 @@ //! Spec deserialization. +use crate::spec::{Engine, Genesis, Params, State}; use serde_json::{self, Error}; -use spec::{Engine, Genesis, Params, State}; use std::io::Read; /// Fork spec definition @@ -73,8 +73,8 @@ impl Spec { #[cfg(test)] mod tests { + use crate::spec::spec::Spec; use serde_json; - use spec::spec::Spec; #[test] fn should_error_on_unknown_fields() { diff --git a/crates/ethjson/src/spec/state.rs b/crates/ethjson/src/spec/state.rs index 0bf295589..c38c32cbf 100644 --- a/crates/ethjson/src/spec/state.rs +++ b/crates/ethjson/src/spec/state.rs @@ -16,9 +16,11 @@ //! Blockchain test state deserializer. -use bytes::Bytes; -use hash::Address; -use spec::{Account, Builtin}; +use crate::{ + bytes::Bytes, + hash::Address, + spec::{Account, Builtin}, +}; use std::collections::BTreeMap; /// Blockchain test state deserializer. diff --git a/crates/ethjson/src/spec/validator_set.rs b/crates/ethjson/src/spec/validator_set.rs index e41905082..a54466551 100644 --- a/crates/ethjson/src/spec/validator_set.rs +++ b/crates/ethjson/src/spec/validator_set.rs @@ -16,9 +16,8 @@ //! Validator set deserialization. -use hash::Address; +use crate::{hash::Address, uint::Uint}; use std::collections::BTreeMap; -use uint::Uint; /// Different ways of specifying validators. #[derive(Debug, PartialEq, Deserialize)] @@ -37,12 +36,10 @@ pub enum ValidatorSet { #[cfg(test)] mod tests { + use crate::{hash::Address, spec::validator_set::ValidatorSet, uint::Uint}; use ethereum_types::{H160, U256}; - use hash::Address; use serde_json; - use spec::validator_set::ValidatorSet; use std::str::FromStr; - use uint::Uint; #[test] fn validator_set_deserialization() { diff --git a/crates/ethjson/src/state/log.rs b/crates/ethjson/src/state/log.rs index bd753d4c9..89e0f18e1 100644 --- a/crates/ethjson/src/state/log.rs +++ b/crates/ethjson/src/state/log.rs @@ -15,8 +15,11 @@ // along with OpenEthereum. If not, see . //! State test log deserialization. -use bytes::Bytes; -use hash::{Address, Bloom, H256}; +use crate::{ + bytes::Bytes, + hash::{Address, Bloom, H256}, +}; +use common_types::log_entry::LogEntry; /// State test log deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -33,8 +36,8 @@ pub struct Log { #[cfg(test)] mod tests { + use super::Log; use serde_json; - use state::Log; #[test] fn log_deserialization() { @@ -50,3 +53,13 @@ mod tests { // TODO: validate all fields } } + +impl From for LogEntry { + fn from(l: Log) -> Self { + LogEntry { + address: l.address.into(), + topics: l.topics.into_iter().map(Into::into).collect(), + data: l.data.into(), + } + } +} diff --git a/crates/ethjson/src/state/mod.rs b/crates/ethjson/src/state/mod.rs index 865e3373e..5060a58e6 100644 --- a/crates/ethjson/src/state/mod.rs +++ b/crates/ethjson/src/state/mod.rs @@ -22,5 +22,4 @@ pub mod test; pub mod transaction; pub use self::{log::Log, state::State, test::Test, transaction::Transaction}; -pub use blockchain::State as AccountState; -pub use vm::Env; +pub use crate::{blockchain::State as AccountState, vm::Env}; diff --git a/crates/ethjson/src/state/state.rs b/crates/ethjson/src/state/state.rs index fc18e5440..f53a7ea66 100644 --- a/crates/ethjson/src/state/state.rs +++ b/crates/ethjson/src/state/state.rs @@ -16,9 +16,11 @@ //! State test deserialization. -use bytes::Bytes; -use hash::H256; -use state::{AccountState, Env, Log, Transaction}; +use crate::{ + bytes::Bytes, + hash::H256, + state::{AccountState, Env, Log, Transaction}, +}; /// State test deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -45,8 +47,8 @@ pub struct State { #[cfg(test)] mod tests { + use super::State; use serde_json; - use state::State; #[test] fn state_deserialization() { diff --git a/crates/ethjson/src/state/test.rs b/crates/ethjson/src/state/test.rs index cc76fa101..5ee43e40b 100644 --- a/crates/ethjson/src/state/test.rs +++ b/crates/ethjson/src/state/test.rs @@ -16,16 +16,22 @@ //! General test deserialization. -use bytes::Bytes; -use crypto::publickey::Secret; -use hash::{Address, H256}; -use maybe::MaybeEmpty; +use crate::{ + bytes::Bytes, + crypto::publickey::Secret, + hash::{Address, H256}, + maybe::MaybeEmpty, + spec::ForkSpec, + state::{AccountState, Env}, + uint::Uint, +}; + +use common_types::transaction::{ + AccessListTx, Action, SignedTransaction, Transaction, TypedTransaction, +}; + use serde_json::{self, Error}; -use spec::ForkSpec; -use state::{AccountState, Env}; use std::{collections::BTreeMap, io::Read}; -use types::transaction::{AccessListTx, Action, SignedTransaction, Transaction, TypedTransaction}; -use uint::Uint; use crate::blockchain::transaction::AccessList; diff --git a/crates/ethjson/src/state/transaction.rs b/crates/ethjson/src/state/transaction.rs index b770a30a4..ffb291471 100644 --- a/crates/ethjson/src/state/transaction.rs +++ b/crates/ethjson/src/state/transaction.rs @@ -16,10 +16,12 @@ //! State test transaction deserialization. -use bytes::Bytes; -use hash::{Address, H256}; -use maybe::MaybeEmpty; -use uint::Uint; +use crate::{ + bytes::Bytes, + hash::{Address, H256}, + maybe::MaybeEmpty, + uint::Uint, +}; /// State test transaction deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -44,8 +46,8 @@ pub struct Transaction { #[cfg(test)] mod tests { + use super::Transaction; use serde_json; - use state::Transaction; #[test] fn transaction_deserialization() { diff --git a/crates/ethjson/src/test/mod.rs b/crates/ethjson/src/test/mod.rs index e4d69a27e..b64cd4763 100644 --- a/crates/ethjson/src/test/mod.rs +++ b/crates/ethjson/src/test/mod.rs @@ -16,10 +16,9 @@ //! Additional test structures deserialization. -use hash::H256; +use crate::{hash::H256, uint::Uint}; use serde_json::{self, Error}; use std::{collections::BTreeMap, io::Read, path::PathBuf}; -use uint::Uint; /// Blockchain test header deserializer. #[derive(Debug, PartialEq, Deserialize)] diff --git a/crates/ethjson/src/transaction/test.rs b/crates/ethjson/src/transaction/test.rs index 2fd4a1c7d..4712a75e8 100644 --- a/crates/ethjson/src/transaction/test.rs +++ b/crates/ethjson/src/transaction/test.rs @@ -16,9 +16,9 @@ //! TransactionTest test deserializer. +use crate::transaction::TransactionTest; use serde_json::{self, Error}; use std::{collections::BTreeMap, io::Read}; -use transaction::TransactionTest; /// TransactionTest test deserializer. #[derive(Debug, Deserialize)] diff --git a/crates/ethjson/src/transaction/transaction.rs b/crates/ethjson/src/transaction/transaction.rs index 5186918aa..9d33b0716 100644 --- a/crates/ethjson/src/transaction/transaction.rs +++ b/crates/ethjson/src/transaction/transaction.rs @@ -16,10 +16,12 @@ //! Transaction test transaction deserialization. -use bytes::Bytes; -use hash::Address; -use maybe::MaybeEmpty; -use uint::Uint; +use crate::{bytes::Bytes, hash::Address, maybe::MaybeEmpty, uint::Uint}; +use common_types::transaction::{ + signature, Action, SignatureComponents, Transaction as CoreTransaction, TypedTransaction, + UnverifiedTransaction, +}; +use ethereum_types::H256; /// Transaction test transaction deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -45,10 +47,37 @@ pub struct Transaction { pub v: Uint, } +impl From for UnverifiedTransaction { + fn from(t: Transaction) -> Self { + let to: Option
= t.to.into(); + UnverifiedTransaction { + unsigned: TypedTransaction::Legacy(CoreTransaction { + nonce: t.nonce.into(), + gas_price: t.gas_price.into(), + gas: t.gas_limit.into(), + action: match to { + Some(to) => Action::Call(to.into()), + None => Action::Create, + }, + value: t.value.into(), + data: t.data.into(), + }), + chain_id: signature::extract_chain_id_from_legacy_v(t.v.into()), + signature: SignatureComponents { + r: t.r.into(), + s: t.s.into(), + standard_v: signature::extract_standard_v(t.v.into()), + }, + hash: H256::zero(), + } + .compute_hash() + } +} + #[cfg(test)] mod tests { + use super::Transaction; use serde_json; - use transaction::Transaction; #[test] fn transaction_deserialization() { diff --git a/crates/ethjson/src/transaction/txtest.rs b/crates/ethjson/src/transaction/txtest.rs index e466374f6..be73a0649 100644 --- a/crates/ethjson/src/transaction/txtest.rs +++ b/crates/ethjson/src/transaction/txtest.rs @@ -16,9 +16,11 @@ //! Transaction test deserialization. -use bytes::Bytes; -use hash::{Address, H256}; -use spec::ForkSpec; +use crate::{ + bytes::Bytes, + hash::{Address, H256}, + spec::ForkSpec, +}; use std::collections::BTreeMap; /// Transaction test deserialization. @@ -42,8 +44,8 @@ pub struct PostState { #[cfg(test)] mod tests { + use super::TransactionTest; use serde_json; - use transaction::TransactionTest; #[test] fn transaction_deserialization() { diff --git a/crates/ethjson/src/trie/input.rs b/crates/ethjson/src/trie/input.rs index 0bdbc82db..80f9060ab 100644 --- a/crates/ethjson/src/trie/input.rs +++ b/crates/ethjson/src/trie/input.rs @@ -16,7 +16,7 @@ //! Trie test input deserialization. -use bytes::Bytes; +use crate::bytes::Bytes; use serde::{ de::{Error as ErrorTrait, MapAccess, SeqAccess, Visitor}, Deserialize, Deserializer, @@ -135,7 +135,7 @@ impl<'a> Visitor<'a> for InputVisitor { #[cfg(test)] mod tests { use super::Input; - use bytes::Bytes; + use crate::bytes::Bytes; use serde_json; use std::collections::BTreeMap; diff --git a/crates/ethjson/src/trie/test.rs b/crates/ethjson/src/trie/test.rs index eb2bcea95..1a5148571 100644 --- a/crates/ethjson/src/trie/test.rs +++ b/crates/ethjson/src/trie/test.rs @@ -16,9 +16,9 @@ //! TransactionTest test deserializer. +use crate::trie::Trie; use serde_json::{self, Error}; use std::{collections::BTreeMap, io::Read}; -use trie::Trie; /// TransactionTest test deserializer. #[derive(Debug, PartialEq, Deserialize)] diff --git a/crates/ethjson/src/trie/trie.rs b/crates/ethjson/src/trie/trie.rs index ec8f9466d..94e1c3809 100644 --- a/crates/ethjson/src/trie/trie.rs +++ b/crates/ethjson/src/trie/trie.rs @@ -16,8 +16,7 @@ //! Trie test deserialization. -use hash::H256; -use trie::Input; +use crate::{hash::H256, trie::Input}; /// Trie test deserialization. #[derive(Debug, Deserialize, PartialEq)] diff --git a/crates/ethjson/src/uint.rs b/crates/ethjson/src/uint.rs index fdcf4931a..8fd6b3723 100644 --- a/crates/ethjson/src/uint.rs +++ b/crates/ethjson/src/uint.rs @@ -148,9 +148,9 @@ where #[cfg(test)] mod test { + use crate::uint::Uint; use ethereum_types::U256; use serde_json; - use uint::Uint; #[test] fn uint_deserialization() { diff --git a/crates/ethjson/src/vm/call.rs b/crates/ethjson/src/vm/call.rs index 7dbb46a1a..14a1815ae 100644 --- a/crates/ethjson/src/vm/call.rs +++ b/crates/ethjson/src/vm/call.rs @@ -16,10 +16,7 @@ //! Vm call deserialization. -use bytes::Bytes; -use hash::Address; -use maybe::MaybeEmpty; -use uint::Uint; +use crate::{bytes::Bytes, hash::Address, maybe::MaybeEmpty, uint::Uint}; /// Vm call deserialization. #[derive(Debug, PartialEq, Deserialize)] @@ -37,13 +34,11 @@ pub struct Call { #[cfg(test)] mod tests { + use crate::{hash::Address, maybe::MaybeEmpty, uint::Uint, vm::Call}; use ethereum_types::{H160 as Hash160, U256}; - use hash::Address; - use maybe::MaybeEmpty; + use serde_json; use std::str::FromStr; - use uint::Uint; - use vm::Call; #[test] fn call_deserialization_empty_dest() { diff --git a/crates/ethjson/src/vm/env.rs b/crates/ethjson/src/vm/env.rs index 09bcda0d6..ad4caa682 100644 --- a/crates/ethjson/src/vm/env.rs +++ b/crates/ethjson/src/vm/env.rs @@ -15,8 +15,7 @@ // along with OpenEthereum. If not, see . //! Vm environment. -use hash::Address; -use uint::Uint; +use crate::{hash::Address, uint::Uint}; /// Vm environment. #[derive(Debug, PartialEq, Deserialize)] @@ -40,8 +39,8 @@ pub struct Env { #[cfg(test)] mod tests { + use super::Env; use serde_json; - use vm::Env; #[test] fn env_deserialization() { diff --git a/crates/ethjson/src/vm/test.rs b/crates/ethjson/src/vm/test.rs index 7e40d8f22..96459e929 100644 --- a/crates/ethjson/src/vm/test.rs +++ b/crates/ethjson/src/vm/test.rs @@ -16,9 +16,9 @@ //! Vm test deserializer. +use crate::vm::Vm; use serde_json::{self, Error}; use std::{collections::BTreeMap, io::Read}; -use vm::Vm; /// Vm test deserializer. #[derive(Debug, PartialEq, Deserialize)] diff --git a/crates/ethjson/src/vm/transaction.rs b/crates/ethjson/src/vm/transaction.rs index 87e79965b..f1f128b16 100644 --- a/crates/ethjson/src/vm/transaction.rs +++ b/crates/ethjson/src/vm/transaction.rs @@ -15,9 +15,7 @@ // along with OpenEthereum. If not, see . //! Executed transaction. -use bytes::Bytes; -use hash::Address; -use uint::Uint; +use crate::{bytes::Bytes, hash::Address, uint::Uint}; /// Executed transaction. #[derive(Debug, PartialEq, Deserialize)] @@ -44,8 +42,8 @@ pub struct Transaction { #[cfg(test)] mod tests { + use super::Transaction; use serde_json; - use vm::Transaction; #[test] fn transaction_deserialization() { diff --git a/crates/ethjson/src/vm/vm.rs b/crates/ethjson/src/vm/vm.rs index 0945449e7..bfffdd9a2 100644 --- a/crates/ethjson/src/vm/vm.rs +++ b/crates/ethjson/src/vm/vm.rs @@ -16,11 +16,13 @@ //! Vm execution env. -use blockchain::State; -use bytes::Bytes; -use hash::H256; -use uint::Uint; -use vm::{Call, Env, Transaction}; +use crate::{ + blockchain::State, + bytes::Bytes, + hash::H256, + uint::Uint, + vm::{Call, Env, Transaction}, +}; /// Represents vm execution environment before and after execution of transaction. #[derive(Debug, PartialEq, Deserialize)] @@ -58,8 +60,8 @@ impl Vm { #[cfg(test)] mod tests { + use super::Vm; use serde_json; - use vm::Vm; #[test] fn vm_deserialization() {