From a30ee88236e3e69642ba9ac0a9546132dafbefc3 Mon Sep 17 00:00:00 2001 From: Quentin Le Sceller Date: Thu, 14 Jun 2018 08:16:14 -0400 Subject: [PATCH] Cleanup imports (#1161) Reorganize imports --- api/src/handlers.rs | 10 ++++------ api/src/rest.rs | 2 +- chain/src/chain.rs | 6 +++--- chain/src/pipe.rs | 2 +- chain/src/store.rs | 4 ++-- chain/src/types.rs | 7 +++---- chain/tests/data_file_integrity.rs | 9 +++------ chain/tests/mine_simple_chain.rs | 10 +++------- chain/tests/store_indices.rs | 7 ++----- chain/tests/test_coinbase_maturity.rs | 16 +++++----------- chain/tests/test_txhashset_raw_txs.rs | 5 ++--- config/src/config.rs | 8 ++++---- core/fuzz/src/main.rs | 11 +++++------ core/src/core/block.rs | 17 ++++++----------- core/src/core/committed.rs | 2 +- core/src/core/id.rs | 5 ++--- core/src/core/mod.rs | 2 +- core/src/core/pmmr.rs | 3 +-- core/src/core/transaction.rs | 15 +++++---------- core/src/global.rs | 17 +++++++---------- core/src/ser.rs | 8 +++----- core/tests/block.rs | 8 +++----- core/tests/consensus.rs | 10 ++++++---- p2p/src/conn.rs | 8 +++----- p2p/src/handshake.rs | 6 +++--- p2p/src/msg.rs | 7 +++---- p2p/src/peer.rs | 6 +++--- p2p/src/peers.rs | 3 ++- p2p/src/protocol.rs | 10 +++++----- p2p/src/serv.rs | 5 ++--- p2p/src/types.rs | 3 +-- p2p/tests/peer_handshake.rs | 5 ++--- pool/src/pool.rs | 2 +- pool/src/transaction_pool.rs | 5 ++--- pool/src/types.rs | 3 +-- pool/tests/block_building.rs | 3 +-- pool/tests/block_reconciliation.rs | 8 +++----- pool/tests/coinbase_maturity.rs | 6 ++---- pool/tests/transaction_pool.rs | 12 ++++-------- servers/src/common/adapters.rs | 6 ++---- servers/src/common/types.rs | 3 +-- servers/src/grin/dandelion_monitor.rs | 6 ++---- servers/src/grin/seed.rs | 3 +-- servers/src/grin/server.rs | 14 ++++++-------- servers/src/grin/sync.rs | 4 ++-- servers/src/mining/mine_block.rs | 15 +++++---------- servers/src/mining/stratumserver.rs | 12 ++++-------- servers/src/mining/test_miner.rs | 11 ++++------- servers/tests/api.rs | 5 ++--- servers/tests/framework/mod.rs | 4 +--- servers/tests/simulnet.rs | 6 ++---- servers/tests/stratum.rs | 10 ++++------ src/bin/tui/menu.rs | 9 +++++---- src/bin/tui/mining.rs | 13 +++++++------ src/bin/tui/peers.rs | 10 +++++----- src/bin/tui/status.rs | 10 +++++----- src/bin/tui/table.rs | 10 ++++++---- src/bin/tui/types.rs | 2 +- src/bin/tui/ui.rs | 16 ++++++++-------- src/bin/tui/version.rs | 12 ++++++------ store/src/pmmr.rs | 5 ++--- store/src/types.rs | 3 +-- store/tests/pmmr.rs | 2 +- wallet/src/client.rs | 3 +-- wallet/src/display.rs | 7 +++---- wallet/src/file_wallet.rs | 17 ++++++++--------- wallet/src/libtx/error.rs | 3 +-- wallet/src/libtx/slate.rs | 2 +- wallet/src/libwallet/api.rs | 7 +++---- wallet/src/libwallet/controller.rs | 6 ++---- wallet/src/libwallet/error.rs | 7 +++++-- wallet/src/libwallet/internal/restore.rs | 3 +-- wallet/src/libwallet/internal/selection.rs | 2 +- wallet/src/libwallet/internal/updater.rs | 11 +++++------ wallet/src/libwallet/types.rs | 1 - wallet/tests/common/mod.rs | 7 ++++--- wallet/tests/transaction.rs | 2 +- 77 files changed, 230 insertions(+), 315 deletions(-) diff --git a/api/src/handlers.rs b/api/src/handlers.rs index 4e72f9a81..ed55386df 100644 --- a/api/src/handlers.rs +++ b/api/src/handlers.rs @@ -17,9 +17,8 @@ use std::sync::{Arc, RwLock, Weak}; use std::thread; use failure::{Fail, ResultExt}; -use iron::Handler; -use iron::prelude::*; -use iron::status; +use iron::prelude::{IronError, IronResult, Plugin, Request, Response}; +use iron::{status, Handler}; use serde::Serialize; use serde_json; use urlencoded::UrlEncodedQuery; @@ -32,11 +31,10 @@ use p2p; use p2p::types::ReasonForBan; use pool; use regex::Regex; -use rest::*; +use rest::{ApiServer, Error, ErrorKind}; use types::*; -use util; -use util::LOGGER; use util::secp::pedersen::Commitment; +use util::{self, LOGGER}; // All handlers use `Weak` references instead of `Arc` to avoid cycles that // can never be destroyed. These 2 functions are simple helpers to reduce the diff --git a/api/src/rest.rs b/api/src/rest.rs index dfb265432..9d1f4d80e 100644 --- a/api/src/rest.rs +++ b/api/src/rest.rs @@ -25,7 +25,7 @@ use std::string::ToString; use failure::{Backtrace, Context, Fail}; use iron::middleware::Handler; -use iron::prelude::*; +use iron::prelude::Iron; use iron::Listening; use mount::Mount; use router::Router; diff --git a/chain/src/chain.rs b/chain/src/chain.rs index fa54f93f7..b44783fef 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -20,19 +20,19 @@ use std::fs::File; use std::sync::{Arc, Mutex, RwLock}; use std::time::{Duration, Instant}; -use core::core::Committed; use core::core::hash::{Hash, Hashed}; use core::core::pmmr::MerkleProof; use core::core::target::Difficulty; +use core::core::Committed; use core::core::{Block, BlockHeader, Output, OutputIdentifier, Transaction, TxKernel}; use core::global; use grin_store::Error::NotFoundErr; use pipe; use store; use txhashset; -use types::*; -use util::LOGGER; +use types::{BlockMarker, BlockSums, ChainAdapter, ChainStore, Error, Options, Tip}; use util::secp::pedersen::{Commitment, RangeProof}; +use util::LOGGER; /// Orphan pool size is limited by MAX_ORPHAN_SIZE pub const MAX_ORPHAN_SIZE: usize = 200; diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs index 1c5b579c3..13c4cfcac 100644 --- a/chain/src/pipe.rs +++ b/chain/src/pipe.rs @@ -26,7 +26,7 @@ use core::global; use grin_store; use store; use txhashset; -use types::*; +use types::{BlockSums, ChainStore, Error, Options, Tip}; use util::LOGGER; /// Contextual information required to process a new block and either reject or diff --git a/chain/src/store.rs b/chain/src/store.rs index bc87b311c..19943d184 100644 --- a/chain/src/store.rs +++ b/chain/src/store.rs @@ -24,8 +24,8 @@ use core::consensus::TargetError; use core::core::hash::{Hash, Hashed}; use core::core::target::Difficulty; use core::core::{Block, BlockHeader}; -use grin_store::{self, option_to_not_found, to_key, Error, u64_to_key}; -use types::*; +use grin_store::{self, option_to_not_found, to_key, u64_to_key, Error}; +use types::{BlockMarker, BlockSums, ChainStore, Tip}; const STORE_SUBPATH: &'static str = "chain"; diff --git a/chain/src/types.rs b/chain/src/types.rs index 95e274719..198a94e9b 100644 --- a/chain/src/types.rs +++ b/chain/src/types.rs @@ -26,7 +26,6 @@ use core::core::target::Difficulty; use core::core::{block, transaction, Block, BlockHeader}; use core::ser::{self, Readable, Reader, Writeable, Writer}; use grin_store as store; -use grin_store; use keychain; bitflags! { @@ -93,7 +92,7 @@ pub enum Error { /// We've been provided a bad txhashset InvalidTxHashSet(String), /// Internal issue when trying to save or load data from store - StoreErr(grin_store::Error, String), + StoreErr(store::Error, String), /// Internal issue when trying to save or load data from append only files FileReadErr(String), /// Error serializing or deserializing a type @@ -128,8 +127,8 @@ impl fmt::Display for Error { } } -impl From for Error { - fn from(e: grin_store::Error) -> Error { +impl From for Error { + fn from(e: store::Error) -> Error { Error::StoreErr(e, "wrapped".to_owned()) } } diff --git a/chain/tests/data_file_integrity.rs b/chain/tests/data_file_integrity.rs index cdf8c1893..5a5ab485a 100644 --- a/chain/tests/data_file_integrity.rs +++ b/chain/tests/data_file_integrity.rs @@ -24,19 +24,16 @@ extern crate time; use std::fs; use std::sync::Arc; +use chain::types::{NoopAdapter, Tip}; use chain::Chain; -use chain::types::*; use core::core::target::Difficulty; use core::core::{Block, BlockHeader, Transaction}; -use core::global; -use core::global::ChainTypes; +use core::global::{self, ChainTypes}; +use core::pow; use core::{consensus, genesis}; - use keychain::{ExtKeychain, Keychain}; use wallet::libtx; -use core::pow; - fn clean_output_dir(dir_name: &str) { let _ = fs::remove_dir_all(dir_name); } diff --git a/chain/tests/mine_simple_chain.rs b/chain/tests/mine_simple_chain.rs index 191b03a89..7529674df 100644 --- a/chain/tests/mine_simple_chain.rs +++ b/chain/tests/mine_simple_chain.rs @@ -24,19 +24,15 @@ extern crate time; use std::fs; use std::sync::Arc; +use chain::types::NoopAdapter; use chain::Chain; -use chain::types::*; -use core::consensus; use core::core::hash::Hashed; use core::core::target::Difficulty; use core::core::{Block, BlockHeader, OutputFeatures, OutputIdentifier, Transaction}; -use core::global; use core::global::ChainTypes; -use wallet::libtx::{self, build}; - +use core::{consensus, global, pow}; use keychain::{ExtKeychain, Keychain}; - -use core::pow; +use wallet::libtx::{self, build}; fn clean_output_dir(dir_name: &str) { let _ = fs::remove_dir_all(dir_name); diff --git a/chain/tests/store_indices.rs b/chain/tests/store_indices.rs index a3a5ba947..bd89b2bdb 100644 --- a/chain/tests/store_indices.rs +++ b/chain/tests/store_indices.rs @@ -22,15 +22,12 @@ extern crate rand; use std::fs; use chain::{ChainStore, Tip}; -use core::core::Block; -use core::core::BlockHeader; use core::core::hash::Hashed; use core::core::target::Difficulty; -use core::global; -use core::global::ChainTypes; +use core::core::{Block, BlockHeader}; +use core::global::{self, ChainTypes}; use core::pow; use keychain::{ExtKeychain, Keychain}; - use wallet::libtx; fn clean_output_dir(dir_name: &str) { diff --git a/chain/tests/test_coinbase_maturity.rs b/chain/tests/test_coinbase_maturity.rs index 8d14abc5a..11880809e 100644 --- a/chain/tests/test_coinbase_maturity.rs +++ b/chain/tests/test_coinbase_maturity.rs @@ -23,19 +23,13 @@ extern crate time; use std::fs; use std::sync::Arc; -use chain::types::*; -use core::consensus; -use core::core::OutputIdentifier; +use chain::types::{Error, NoopAdapter}; use core::core::target::Difficulty; -use core::core::transaction; -use core::global; -use core::global::ChainTypes; -use wallet::libtx::build; - +use core::core::{transaction, OutputIdentifier}; +use core::global::{self, ChainTypes}; +use core::{consensus, pow}; use keychain::{ExtKeychain, Keychain}; -use wallet::libtx; - -use core::pow; +use wallet::libtx::{self, build}; fn clean_output_dir(dir_name: &str) { let _ = fs::remove_dir_all(dir_name); diff --git a/chain/tests/test_txhashset_raw_txs.rs b/chain/tests/test_txhashset_raw_txs.rs index 3ceddd6aa..73a7b210d 100644 --- a/chain/tests/test_txhashset_raw_txs.rs +++ b/chain/tests/test_txhashset_raw_txs.rs @@ -20,11 +20,10 @@ extern crate grin_wallet as wallet; use std::fs; use std::sync::Arc; -use chain::ChainStore; use chain::store::ChainKVStore; -use chain::txhashset; -use chain::txhashset::TxHashSet; +use chain::txhashset::{self, TxHashSet}; use chain::types::Tip; +use chain::ChainStore; use core::core::pmmr::MerkleProof; use core::core::target::Difficulty; use core::core::{Block, BlockHeader}; diff --git a/config/src/config.rs b/config/src/config.rs index 404d79a8b..d49855659 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -15,14 +15,14 @@ //! Configuration file management use std::env; +use std::fs::File; use std::io::Read; use std::path::PathBuf; -use std::fs::File; - use toml; + use servers::{ServerConfig, StratumServerConfig}; -use util::LoggingConfig; use types::{ConfigError, ConfigMembers, GlobalConfig}; +use util::LoggingConfig; use wallet::WalletConfig; /// The default file name to use when trying to derive @@ -108,7 +108,7 @@ impl GlobalConfig { let config_file = return_value.config_file_path.clone().unwrap(); if !config_file.exists() { return Err(ConfigError::FileNotFoundError(String::from( - config_file.to_str().unwrap() + config_file.to_str().unwrap(), ))); } diff --git a/core/fuzz/src/main.rs b/core/fuzz/src/main.rs index e36974275..e41aed8df 100644 --- a/core/fuzz/src/main.rs +++ b/core/fuzz/src/main.rs @@ -1,14 +1,13 @@ extern crate grin_core; extern crate grin_keychain; -use std::path::Path; -use std::fs::{self, File}; -use grin_core::ser; -use grin_core::core::{Block, BlockHeader, CompactBlock, Transaction}; -use grin_core::core::target::Difficulty; - use grin_core::core::build::{input, output, transaction_with_offset, with_fee}; +use grin_core::core::target::Difficulty; +use grin_core::core::{Block, BlockHeader, CompactBlock, Transaction}; +use grin_core::ser; use grin_keychain::keychain::Keychain; +use std::fs::{self, File}; +use std::path::Path; fn main() { generate("transaction_read", &tx()).unwrap(); diff --git a/core/src/core/block.rs b/core/src/core/block.rs index b794e509e..ff1eaa31b 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -19,22 +19,17 @@ use std::collections::HashSet; use std::iter::FromIterator; use time; -use consensus; -use consensus::{exceeds_weight, reward, VerifySortOrder, REWARD}; -use core::committed; -use core::committed::Committed; +use consensus::{self, exceeds_weight, reward, VerifySortOrder, REWARD}; +use core::committed::{self, Committed}; use core::hash::{Hash, HashWriter, Hashed, ZERO_HASH}; use core::id::ShortIdentifiable; use core::target::Difficulty; -use core::transaction; -use core::{Commitment, Input, KernelFeatures, Output, OutputFeatures, Proof, ShortId, Transaction, - TxKernel}; +use core::{transaction, Commitment, Input, KernelFeatures, Output, OutputFeatures, Proof, ShortId, + Transaction, TxKernel}; use global; -use keychain; -use keychain::BlindingFactor; +use keychain::{self, BlindingFactor}; use ser::{self, read_and_verify_sorted, Readable, Reader, Writeable, WriteableSorted, Writer}; -use util::LOGGER; -use util::{secp, static_secp_instance}; +use util::{secp, static_secp_instance, LOGGER}; /// Errors thrown by Block validation #[derive(Debug, Clone, PartialEq)] diff --git a/core/src/core/committed.rs b/core/src/core/committed.rs index 7f8d7b8a3..d861108c5 100644 --- a/core/src/core/committed.rs +++ b/core/src/core/committed.rs @@ -17,7 +17,7 @@ use keychain; use keychain::BlindingFactor; -use util::secp::pedersen::*; +use util::secp::pedersen::Commitment; use util::{secp, secp_static, static_secp_instance}; /// Errors from summing and verifying kernel excesses via committed trait. diff --git a/core/src/core/id.rs b/core/src/core/id.rs index 854c538c3..21c0a8f77 100644 --- a/core/src/core/id.rs +++ b/core/src/core/id.rs @@ -14,15 +14,14 @@ //! short ids for compact blocks -use std::cmp::Ordering; use std::cmp::min; +use std::cmp::Ordering; use byteorder::{ByteOrder, LittleEndian}; use siphasher::sip::SipHasher24; use core::hash::{Hash, Hashed}; -use ser; -use ser::{Readable, Reader, Writeable, Writer}; +use ser::{self, Readable, Reader, Writeable, Writer}; use util; /// The size of a short id used to identify inputs|outputs|kernels (6 bytes) diff --git a/core/src/core/mod.rs b/core/src/core/mod.rs index 02adb2a87..eb42534cb 100644 --- a/core/src/core/mod.rs +++ b/core/src/core/mod.rs @@ -27,7 +27,7 @@ use rand::{thread_rng, Rng}; use std::num::ParseFloatError; use std::{fmt, iter}; -use util::secp::pedersen::*; +use util::secp::pedersen::Commitment; pub use self::block::*; pub use self::committed::Committed; diff --git a/core/src/core/pmmr.rs b/core/src/core/pmmr.rs index 7f1441204..72ea526af 100644 --- a/core/src/core/pmmr.rs +++ b/core/src/core/pmmr.rs @@ -40,8 +40,7 @@ use ser::{self, PMMRIndexHashable, PMMRable, Readable, Reader, Writeable, Writer use std::clone::Clone; use std::marker; -use util; -use util::LOGGER; +use util::{self, LOGGER}; /// Storage backend for the MMR, just needs to be indexed by order of insertion. /// The PMMR itself does not need the Backend to be accurate on the existence diff --git a/core/src/core/transaction.rs b/core/src/core/transaction.rs index 04d204d88..8c4ab34d5 100644 --- a/core/src/core/transaction.rs +++ b/core/src/core/transaction.rs @@ -14,8 +14,8 @@ //! Transactions -use std::cmp::Ordering; use std::cmp::max; +use std::cmp::Ordering; use std::collections::HashSet; use std::io::Cursor; use std::{error, fmt}; @@ -24,16 +24,11 @@ use util::secp::pedersen::{Commitment, ProofMessage, RangeProof}; use util::secp::{self, Message, Signature}; use util::{kernel_sig_msg, static_secp_instance}; -use consensus; -use consensus::VerifySortOrder; -use core::BlockHeader; -use core::Committed; -use core::committed; -use core::global; +use consensus::{self, VerifySortOrder}; use core::hash::{Hash, Hashed, ZERO_HASH}; use core::pmmr::MerkleProof; -use keychain; -use keychain::BlindingFactor; +use core::{committed, global, BlockHeader, Committed}; +use keychain::{self, BlindingFactor}; use ser::{self, read_and_verify_sorted, ser_vec, PMMRable, Readable, Reader, Writeable, WriteableSorted, Writer}; use util; @@ -505,7 +500,7 @@ pub fn aggregate(transactions: Vec) -> Result { let mut kernel_offsets: Vec = vec![]; for mut transaction in transactions { - // we will summ these later to give a single aggregate offset + // we will sum these later to give a single aggregate offset kernel_offsets.push(transaction.offset); inputs.append(&mut transaction.inputs); diff --git a/core/src/global.rs b/core/src/global.rs index e1c720d57..ef6814ff9 100644 --- a/core/src/global.rs +++ b/core/src/global.rs @@ -16,19 +16,15 @@ //! having to pass them all over the place, but aren't consensus values. //! should be used sparingly. +use consensus::TargetError; +use consensus::{BLOCK_TIME_SEC, COINBASE_MATURITY, CUT_THROUGH_HORIZON, DEFAULT_SIZESHIFT, + DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, MEDIAN_TIME_WINDOW, PROOFSIZE}; +use core::target::Difficulty; /// An enum collecting sets of parameters used throughout the /// code wherever mining is needed. This should allow for /// different sets of parameters for different purposes, /// e.g. CI, User testing, production values - use std::sync::RwLock; -use consensus::PROOFSIZE; -use consensus::DEFAULT_SIZESHIFT; -use consensus::COINBASE_MATURITY; -use consensus::{BLOCK_TIME_SEC, CUT_THROUGH_HORIZON, DIFFICULTY_ADJUST_WINDOW, INITIAL_DIFFICULTY, - MEDIAN_TIME_WINDOW}; -use core::target::Difficulty; -use consensus::TargetError; /// Define these here, as they should be developer-set, not really tweakable /// by users @@ -193,8 +189,9 @@ pub fn get_genesis_nonce() -> u64 { } } -/// Converts an iterator of block difficulty data to more a more mangeable vector and pads -/// if needed (which will) only be needed for the first few blocks after genesis +/// Converts an iterator of block difficulty data to more a more mangeable +/// vector and pads if needed (which will) only be needed for the first few +/// blocks after genesis pub fn difficulty_data_to_vector(cursor: T) -> Vec> where diff --git a/core/src/ser.rs b/core/src/ser.rs index f246c3107..1372a7fb5 100644 --- a/core/src/ser.rs +++ b/core/src/ser.rs @@ -20,17 +20,15 @@ //! `serialize` or `deserialize` functions on them as appropriate. use byteorder::{BigEndian, ByteOrder, ReadBytesExt}; -use consensus; -use consensus::VerifySortOrder; +use consensus::{self, VerifySortOrder}; use core::hash::{Hash, Hashed}; use keychain::{BlindingFactor, Identifier, IDENTIFIER_SIZE}; use std::io::{self, Read, Write}; use std::{cmp, error, fmt, mem}; -use util::secp::Signature; use util::secp::constants::{AGG_SIGNATURE_SIZE, MAX_PROOF_SIZE, PEDERSEN_COMMITMENT_SIZE, SECRET_KEY_SIZE}; -use util::secp::pedersen::Commitment; -use util::secp::pedersen::RangeProof; +use util::secp::pedersen::{Commitment, RangeProof}; +use util::secp::Signature; /// Possible errors deriving from serializing or deserializing. #[derive(Debug)] diff --git a/core/tests/block.rs b/core/tests/block.rs index 423ab30af..79184cc6e 100644 --- a/core/tests/block.rs +++ b/core/tests/block.rs @@ -21,18 +21,16 @@ pub mod common; use common::{new_block, tx1i2o, tx2i1o, txspend1i1o}; use grin_core::consensus::{BLOCK_OUTPUT_WEIGHT, MAX_BLOCK_WEIGHT}; -use grin_core::core::Committed; use grin_core::core::block::Error; use grin_core::core::hash::Hashed; use grin_core::core::id::{ShortId, ShortIdentifiable}; +use grin_core::core::Committed; use grin_core::core::{Block, BlockHeader, CompactBlock, KernelFeatures, OutputFeatures}; -use grin_core::global; -use grin_core::ser; +use grin_core::{global, ser}; use keychain::{ExtKeychain, Keychain}; use std::time::Instant; -use wallet::libtx::build::{self, input, output, with_fee}; - use util::{secp, secp_static}; +use wallet::libtx::build::{self, input, output, with_fee}; // Too slow for now #[test] // TODO: make this fast enough or add similar but faster test? diff --git a/core/tests/consensus.rs b/core/tests/consensus.rs index 922768472..91fad2ca3 100644 --- a/core/tests/consensus.rs +++ b/core/tests/consensus.rs @@ -16,9 +16,10 @@ extern crate grin_core as core; extern crate time; +use core::consensus::{next_difficulty, valid_header_version, TargetError, + DIFFICULTY_ADJUST_WINDOW, MEDIAN_TIME_WINDOW}; use core::core::target::Difficulty; use core::global; -use core::consensus::*; // Builds an iterator for next difficulty calculation with the provided // constant time interval, difficulty and total length. @@ -49,9 +50,10 @@ fn create_chain_sim(diff: u64) -> Vec> { time::get_time().sec, Difficulty::from_num(diff) ); - vec![ - Ok((time::get_time().sec as u64, Difficulty::from_num(diff))), - ] + vec![Ok(( + time::get_time().sec as u64, + Difficulty::from_num(diff), + ))] } // Adds another 'block' to the iterator, so to speak, with difficulty calculated diff --git a/p2p/src/conn.rs b/p2p/src/conn.rs index 73c44838d..ec0163ffb 100644 --- a/p2p/src/conn.rs +++ b/p2p/src/conn.rs @@ -20,17 +20,15 @@ //! forces us to go through some additional gymnastic to loop over the async //! stream and make sure we get the right number of bytes out. -use std::cmp; use std::fs::File; use std::io::{self, Read, Write}; use std::net::TcpStream; use std::sync::{mpsc, Arc, Mutex}; -use std::thread; -use std::time; +use std::{cmp, thread, time}; use core::ser; -use msg::*; -use types::*; +use msg::{read_body, read_exact, read_header, write_all, write_to_buf, MsgHeader, Type}; +use types::Error; use util::LOGGER; /// A trait to be implemented in order to receive messages from the diff --git a/p2p/src/handshake.rs b/p2p/src/handshake.rs index 4cc365dfe..e69a248cf 100644 --- a/p2p/src/handshake.rs +++ b/p2p/src/handshake.rs @@ -16,14 +16,14 @@ use std::collections::VecDeque; use std::net::{SocketAddr, TcpStream}; use std::sync::{Arc, RwLock}; -use rand::Rng; use rand::os::OsRng; +use rand::Rng; use core::core::hash::Hash; use core::core::target::Difficulty; -use msg::*; +use msg::{read_message, write_message, Hand, Shake, SockAddr, Type, PROTOCOL_VERSION, USER_AGENT}; use peer::Peer; -use types::*; +use types::{Capabilities, Direction, Error, P2PConfig, PeerInfo}; use util::LOGGER; const NONCES_CAP: usize = 100; diff --git a/p2p/src/msg.rs b/p2p/src/msg.rs index e07a7daf6..ec945c5cc 100644 --- a/p2p/src/msg.rs +++ b/p2p/src/msg.rs @@ -17,16 +17,15 @@ use num::FromPrimitive; use std::io::{self, Read, Write}; use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, TcpStream}; -use std::thread; -use std::time; +use std::{thread, time}; use core::consensus::{MAX_MSG_LEN, MAX_TX_INPUTS, MAX_TX_KERNELS, MAX_TX_OUTPUTS}; -use core::core::BlockHeader; use core::core::hash::Hash; use core::core::target::Difficulty; +use core::core::BlockHeader; use core::ser::{self, Readable, Reader, Writeable, Writer}; -use types::*; +use types::{Capabilities, Error, ReasonForBan, MAX_BLOCK_HEADERS, MAX_LOCATORS, MAX_PEER_ADDRS}; use util::LOGGER; /// Current latest version of the protocol diff --git a/p2p/src/peer.rs b/p2p/src/peer.rs index 825ee7752..6bdab1755 100644 --- a/p2p/src/peer.rs +++ b/p2p/src/peer.rs @@ -21,10 +21,10 @@ use core::core; use core::core::hash::{Hash, Hashed}; use core::core::target::Difficulty; use handshake::Handshake; -use msg; -use msg::*; +use msg::{self, BanReason, GetPeerAddrs, Locator, Ping, TxHashSetRequest}; use protocol::Protocol; -use types::*; +use types::{Capabilities, ChainAdapter, Error, NetAdapter, P2PConfig, PeerInfo, ReasonForBan, + TxHashSetRead}; use util::LOGGER; const MAX_TRACK_SIZE: usize = 30; diff --git a/p2p/src/peers.rs b/p2p/src/peers.rs index 58723c0b6..77001fcd1 100644 --- a/p2p/src/peers.rs +++ b/p2p/src/peers.rs @@ -27,7 +27,8 @@ use util::LOGGER; use peer::Peer; use store::{PeerData, PeerStore, State}; -use types::*; +use types::{Capabilities, ChainAdapter, Direction, Error, NetAdapter, P2PConfig, ReasonForBan, + TxHashSetRead, MAX_PEER_ADDRS}; pub struct Peers { pub adapter: Arc, diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index 8a8ff9d80..8bbf1a55f 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -17,13 +17,13 @@ use std::fs::File; use std::net::SocketAddr; use std::sync::Arc; -use conn::*; +use conn::{Message, MessageHandler, Response}; use core::core; use core::core::hash::{Hash, Hashed}; -use msg::*; -use rand; -use rand::Rng; -use types::*; +use msg::{BanReason, GetPeerAddrs, Headers, Locator, PeerAddrs, Ping, Pong, SockAddr, + TxHashSetArchive, TxHashSetRequest, Type}; +use rand::{self, Rng}; +use types::{Error, NetAdapter}; use util::LOGGER; pub struct Protocol { diff --git a/p2p/src/serv.rs b/p2p/src/serv.rs index a7b2dbb56..bcfe0f840 100644 --- a/p2p/src/serv.rs +++ b/p2p/src/serv.rs @@ -13,12 +13,11 @@ // limitations under the License. use std::fs::File; -use std::io; use std::net::{Shutdown, SocketAddr, TcpListener, TcpStream}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, RwLock}; -use std::thread; use std::time::Duration; +use std::{io, thread}; use core::core; use core::core::hash::Hash; @@ -27,7 +26,7 @@ use handshake::Handshake; use peer::Peer; use peers::Peers; use store::PeerStore; -use types::*; +use types::{Capabilities, ChainAdapter, Error, NetAdapter, P2PConfig, TxHashSetRead}; use util::LOGGER; /// P2P server implementation, handling bootstrapping to find and connect to diff --git a/p2p/src/types.rs b/p2p/src/types.rs index 8119c9454..41e99196d 100644 --- a/p2p/src/types.rs +++ b/p2p/src/types.rs @@ -18,10 +18,9 @@ use std::io; use std::net::{IpAddr, SocketAddr}; use std::sync::mpsc; -use core::core; use core::core::hash::Hash; use core::core::target::Difficulty; -use core::ser; +use core::{core, ser}; use grin_store; /// Maximum number of block headers a peer should ever send diff --git a/p2p/tests/peer_handshake.rs b/p2p/tests/peer_handshake.rs index 45353b901..521190f00 100644 --- a/p2p/tests/peer_handshake.rs +++ b/p2p/tests/peer_handshake.rs @@ -17,10 +17,9 @@ extern crate grin_p2p as p2p; extern crate grin_util as util; use std::net::{SocketAddr, TcpListener, TcpStream}; -use std::sync::Arc; use std::sync::atomic::AtomicBool; -use std::thread; -use std::time; +use std::sync::Arc; +use std::{thread, time}; use core::core::hash::Hash; use core::core::target::Difficulty; diff --git a/pool/src/pool.rs b/pool/src/pool.rs index 5f974f043..277607e7e 100644 --- a/pool/src/pool.rs +++ b/pool/src/pool.rs @@ -22,7 +22,7 @@ use core::core::hash::Hashed; use core::core::id::ShortIdentifiable; use core::core::transaction; use core::core::{Block, CompactBlock, Transaction, TxKernel}; -use types::*; +use types::{BlockChain, PoolEntry, PoolEntryState, PoolError}; use util::LOGGER; pub struct Pool { diff --git a/pool/src/transaction_pool.rs b/pool/src/transaction_pool.rs index edf212e69..55fb25af7 100644 --- a/pool/src/transaction_pool.rs +++ b/pool/src/transaction_pool.rs @@ -21,10 +21,9 @@ use std::sync::Arc; use time; use core::core::hash::Hashed; -use core::core::transaction; -use core::core::{Block, CompactBlock, Transaction}; +use core::core::{transaction, Block, CompactBlock, Transaction}; use pool::Pool; -use types::*; +use types::{BlockChain, PoolAdapter, PoolConfig, PoolEntry, PoolEntryState, PoolError, TxSource}; use util::LOGGER; /// Transaction pool implementation. diff --git a/pool/src/types.rs b/pool/src/types.rs index 864ef590d..709c5c9ac 100644 --- a/pool/src/types.rs +++ b/pool/src/types.rs @@ -19,8 +19,7 @@ use std::{error, fmt}; use time::Timespec; use core::consensus; -use core::core::transaction; -use core::core::transaction::Transaction; +use core::core::transaction::{self, Transaction}; /// Dandelion relay timer const DANDELION_RELAY_SECS: u64 = 600; diff --git a/pool/tests/block_building.rs b/pool/tests/block_building.rs index ece57cff5..8520095eb 100644 --- a/pool/tests/block_building.rs +++ b/pool/tests/block_building.rs @@ -29,9 +29,8 @@ use std::sync::{Arc, RwLock}; use core::core::{Block, BlockHeader}; -use chain::ChainStore; -use chain::txhashset; use chain::types::Tip; +use chain::{txhashset, ChainStore}; use core::core::target::Difficulty; use keychain::{ExtKeychain, Keychain}; diff --git a/pool/tests/block_reconciliation.rs b/pool/tests/block_reconciliation.rs index d4cdb12d8..425d61ae1 100644 --- a/pool/tests/block_reconciliation.rs +++ b/pool/tests/block_reconciliation.rs @@ -29,16 +29,14 @@ use std::sync::{Arc, RwLock}; use core::core::{Block, BlockHeader}; -use chain::ChainStore; -use chain::txhashset; use chain::types::Tip; +use chain::{txhashset, ChainStore}; +use common::{clean_output_dir, test_setup, test_source, test_transaction, + test_transaction_spending_coinbase, ChainAdapter}; use core::core::target::Difficulty; - use keychain::{ExtKeychain, Keychain}; use wallet::libtx; -use common::*; - #[test] fn test_transaction_pool_block_reconciliation() { let keychain: ExtKeychain = Keychain::from_random_seed().unwrap(); diff --git a/pool/tests/coinbase_maturity.rs b/pool/tests/coinbase_maturity.rs index 3c57481ea..2beb4349a 100644 --- a/pool/tests/coinbase_maturity.rs +++ b/pool/tests/coinbase_maturity.rs @@ -27,13 +27,11 @@ pub mod common; use std::sync::{Arc, RwLock}; +use common::{test_source, test_transaction}; use core::core::Transaction; - use keychain::{ExtKeychain, Keychain}; +use pool::types::{BlockChain, NoopAdapter, PoolConfig, PoolError}; use pool::TransactionPool; -use pool::types::*; - -use common::*; pub fn test_setup( chain: &Arc, diff --git a/pool/tests/transaction_pool.rs b/pool/tests/transaction_pool.rs index d28b577d0..cfb9e09fe 100644 --- a/pool/tests/transaction_pool.rs +++ b/pool/tests/transaction_pool.rs @@ -27,19 +27,15 @@ pub mod common; use std::sync::{Arc, RwLock}; -use core::core::{Block, BlockHeader}; - -use chain::ChainStore; -use chain::txhashset; use chain::types::Tip; +use chain::{txhashset, ChainStore}; +use common::{clean_output_dir, test_setup, test_source, test_transaction, + test_transaction_spending_coinbase, ChainAdapter}; use core::core::target::Difficulty; -use core::core::transaction; - +use core::core::{transaction, Block, BlockHeader}; use keychain::{ExtKeychain, Keychain}; use wallet::libtx; -use common::*; - /// Test we can add some txs to the pool (both stempool and txpool). #[test] fn test_the_transaction_pool() { diff --git a/servers/src/common/adapters.rs b/servers/src/common/adapters.rs index 459395f93..0e789e49e 100644 --- a/servers/src/common/adapters.rs +++ b/servers/src/common/adapters.rs @@ -15,8 +15,7 @@ //! Adapters connecting new block, new transaction, and accepted transaction //! events to consumers of those events. -use rand; -use rand::Rng; +use rand::{self, Rng}; use std::fs::File; use std::net::SocketAddr; use std::ops::Deref; @@ -35,8 +34,7 @@ use core::core::transaction::Transaction; use p2p; use pool; use store; -use util::LOGGER; -use util::OneTime; +use util::{OneTime, LOGGER}; // All adapters use `Weak` references instead of `Arc` to avoid cycles that // can never be destroyed. These 2 functions are simple helpers to reduce the diff --git a/servers/src/common/types.rs b/servers/src/common/types.rs index 881e7808b..cd901bac1 100644 --- a/servers/src/common/types.rs +++ b/servers/src/common/types.rs @@ -18,9 +18,8 @@ use std::convert::From; use api; use chain; -use core::core; use core::global::ChainTypes; -use core::pow; +use core::{core, pow}; use p2p; use pool; use store; diff --git a/servers/src/grin/dandelion_monitor.rs b/servers/src/grin/dandelion_monitor.rs index 4e5259cf7..a531d09c2 100644 --- a/servers/src/grin/dandelion_monitor.rs +++ b/servers/src/grin/dandelion_monitor.rs @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use rand; -use rand::Rng; +use rand::{self, Rng}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, RwLock}; use std::thread; @@ -22,8 +21,7 @@ use time::now_utc; use core::core::hash::Hashed; use core::core::transaction; -use pool::DandelionConfig; -use pool::{BlockChain, PoolEntryState, PoolError, TransactionPool, TxSource}; +use pool::{BlockChain, DandelionConfig, PoolEntryState, PoolError, TransactionPool, TxSource}; use util::LOGGER; /// A process to monitor transactions in the stempool. diff --git a/servers/src/grin/seed.rs b/servers/src/grin/seed.rs index d30af8389..41fbfa969 100644 --- a/servers/src/grin/seed.rs +++ b/servers/src/grin/seed.rs @@ -17,8 +17,7 @@ //! use std::io::Read; -use std::net::SocketAddr; -use std::net::ToSocketAddrs; +use std::net::{SocketAddr, ToSocketAddrs}; use std::str; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{mpsc, Arc}; diff --git a/servers/src/grin/server.rs b/servers/src/grin/server.rs index bac7d512c..697caf462 100644 --- a/servers/src/grin/server.rs +++ b/servers/src/grin/server.rs @@ -19,20 +19,18 @@ use std::net::SocketAddr; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, RwLock}; -use std::thread; -use std::time; +use std::{thread, time}; use api; use chain; -use common::adapters::*; -use common::stats::*; -use common::types::*; +use common::adapters::{ChainToPoolAndNetAdapter, NetToChainAdapter, PoolToChainAdapter, + PoolToNetAdapter}; +use common::stats::{DiffBlock, DiffStats, PeerStats, ServerStateInfo, ServerStats}; +use common::types::{Error, Seeding, ServerConfig, StratumServerConfig}; use core::core::hash::Hashed; use core::core::target::Difficulty; use core::{consensus, genesis, global, pow}; -use grin::dandelion_monitor; -use grin::seed; -use grin::sync; +use grin::{dandelion_monitor, seed, sync}; use mining::stratumserver; use mining::test_miner::Miner; use p2p; diff --git a/servers/src/grin/sync.rs b/servers/src/grin/sync.rs index 890f7f3ae..ab8021d71 100644 --- a/servers/src/grin/sync.rs +++ b/servers/src/grin/sync.rs @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::Arc; use std::time::Duration; use std::{cmp, thread}; use time; @@ -457,7 +457,7 @@ mod test { assert_eq!( get_locator_heights(10000), vec![ - 10000, 9998, 9994, 9986, 9970, 9938, 9874, 9746, 9490, 8978, 7954, 5906, 1810, 0 + 10000, 9998, 9994, 9986, 9970, 9938, 9874, 9746, 9490, 8978, 7954, 5906, 1810, 0, ] ); } diff --git a/servers/src/mining/mine_block.rs b/servers/src/mining/mine_block.rs index cd9d4cded..4f7440fa5 100644 --- a/servers/src/mining/mine_block.rs +++ b/servers/src/mining/mine_block.rs @@ -22,21 +22,16 @@ use std::thread; use std::time::Duration; use time; -use chain; -use chain::types::BlockSums; +use chain::{self, types::BlockSums}; use common::adapters::PoolToChainAdapter; use common::types::Error; -use core::consensus; -use core::core; use core::core::hash::Hashed; -use core::ser; -use core::ser::AsFixedBytes; +use core::ser::{self, AsFixedBytes}; +use core::{consensus, core}; use keychain::{ExtKeychain, Identifier, Keychain}; use pool; -use util; -use util::LOGGER; -use wallet; -use wallet::BlockFees; +use util::{self, LOGGER}; +use wallet::{self, BlockFees}; /// Serializer that outputs the pre-pow part of the header, /// including the nonce (last 8 bytes) that can be sent off diff --git a/servers/src/mining/stratumserver.rs b/servers/src/mining/stratumserver.rs index dc9e16b64..f5e4f91bf 100644 --- a/servers/src/mining/stratumserver.rs +++ b/servers/src/mining/stratumserver.rs @@ -15,25 +15,21 @@ //! Mining Stratum Server use bufstream::BufStream; use serde_json; -use std::cmp; use std::error::Error; -use std::io::BufRead; -use std::io::{ErrorKind, Write}; +use std::io::{BufRead, ErrorKind, Write}; use std::net::{TcpListener, TcpStream}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex, RwLock}; -use std::thread; -use std::time::Duration; -use std::time::SystemTime; +use std::time::{Duration, SystemTime}; +use std::{cmp, thread}; use time; use chain; use common::adapters::PoolToChainAdapter; use common::stats::{StratumStats, WorkerStats}; use common::types::StratumServerConfig; -use core::consensus; use core::core::{Block, BlockHeader}; -use core::pow; +use core::{consensus, pow}; use keychain; use mining::mine_block; use pool; diff --git a/servers/src/mining/test_miner.rs b/servers/src/mining/test_miner.rs index f32ef8f7d..ff5ca28e8 100644 --- a/servers/src/mining/test_miner.rs +++ b/servers/src/mining/test_miner.rs @@ -21,19 +21,16 @@ use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, RwLock}; use time; +use chain; use common::adapters::PoolToChainAdapter; use common::types::StratumServerConfig; -use core::consensus; -use core::core::Proof; use core::core::hash::{Hash, Hashed}; -use core::core::{Block, BlockHeader}; +use core::core::{Block, BlockHeader, Proof}; use core::pow::cuckoo; -use util::LOGGER; - -use chain; -use core::global; +use core::{consensus, global}; use mining::mine_block; use pool; +use util::LOGGER; // Max number of transactions this miner will assemble in a block const MAX_TX: u32 = 5000; diff --git a/servers/tests/api.rs b/servers/tests/api.rs index fbdf5bdb5..21ebbd776 100644 --- a/servers/tests/api.rs +++ b/servers/tests/api.rs @@ -26,11 +26,10 @@ extern crate grin_wallet as wallet; mod framework; -use std::{thread, time}; use std::sync::{Arc, Mutex}; +use std::{thread, time}; -use core::global; -use core::global::ChainTypes; +use core::global::{self, ChainTypes}; use framework::{LocalServerContainer, LocalServerContainerConfig}; use util::{init_test_logger, LOGGER}; diff --git a/servers/tests/framework/mod.rs b/servers/tests/framework/mod.rs index 8dc35c2ed..254bd0c1f 100644 --- a/servers/tests/framework/mod.rs +++ b/servers/tests/framework/mod.rs @@ -24,10 +24,8 @@ extern crate grin_wallet as wallet; extern crate blake2_rfc as blake2; use std::default::Default; -use std::fs; use std::sync::{Arc, Mutex}; -use std::thread; -use std::time; +use std::{fs, thread, time}; use wallet::{FileWallet, WalletConfig}; diff --git a/servers/tests/simulnet.rs b/servers/tests/simulnet.rs index 6b9aea26f..a856aa358 100644 --- a/servers/tests/simulnet.rs +++ b/servers/tests/simulnet.rs @@ -23,11 +23,9 @@ extern crate grin_wallet as wallet; mod framework; use std::default::Default; -use std::thread; -use std::time; +use std::{thread, time}; -use core::global; -use core::global::ChainTypes; +use core::global::{self, ChainTypes}; use framework::{config, stratum_config, LocalServerContainerConfig, LocalServerContainerPool, LocalServerContainerPoolConfig}; diff --git a/servers/tests/stratum.rs b/servers/tests/stratum.rs index 98e033305..0b9b4b98d 100644 --- a/servers/tests/stratum.rs +++ b/servers/tests/stratum.rs @@ -25,16 +25,14 @@ extern crate serde_json; mod framework; -use std::io::prelude::*; -use std::net::TcpStream; use bufstream::BufStream; use serde_json::Value; +use std::io::prelude::{BufRead, Write}; +use std::net::TcpStream; -use std::thread; -use std::time; +use std::{thread, time}; -use core::global; -use core::global::ChainTypes; +use core::global::{self, ChainTypes}; use framework::{config, stratum_config}; diff --git a/src/bin/tui/menu.rs b/src/bin/tui/menu.rs index 084f325db..7d6ad4322 100644 --- a/src/bin/tui/menu.rs +++ b/src/bin/tui/menu.rs @@ -14,15 +14,16 @@ //! Main Menu definition -use cursive::Cursive; -use cursive::view::View; use cursive::align::HAlign; +use cursive::direction::Orientation; use cursive::event::{EventResult, Key}; use cursive::view::Identifiable; +use cursive::view::View; use cursive::views::{BoxView, LinearLayout, OnEventView, SelectView, StackView, TextView, ViewRef}; -use cursive::direction::Orientation; +use cursive::Cursive; -use tui::constants::*; +use tui::constants::{MAIN_MENU, ROOT_STACK, SUBMENU_MINING_BUTTON, VIEW_BASIC_STATUS, VIEW_MINING, + VIEW_PEER_SYNC, VIEW_VERSION}; pub fn create() -> Box { let mut main_menu = SelectView::new().h_align(HAlign::Left).with_id(MAIN_MENU); diff --git a/src/bin/tui/mining.rs b/src/bin/tui/mining.rs index 7ab18fed7..48958b095 100644 --- a/src/bin/tui/mining.rs +++ b/src/bin/tui/mining.rs @@ -16,18 +16,19 @@ use std::cmp::Ordering; -use cursive::Cursive; +use cursive::direction::Orientation; use cursive::event::Key; +use cursive::traits::{Boxable, Identifiable}; use cursive::view::View; use cursive::views::{BoxView, Button, Dialog, LinearLayout, OnEventView, Panel, StackView, TextView}; -use cursive::direction::Orientation; -use cursive::traits::*; +use cursive::Cursive; use std::time; -use tui::chrono::prelude::*; +use tui::chrono::prelude::{DateTime, NaiveDateTime, Utc}; -use tui::constants::*; -use tui::types::*; +use tui::constants::{MAIN_MENU, SUBMENU_MINING_BUTTON, TABLE_MINING_DIFF_STATUS, + TABLE_MINING_STATUS, VIEW_MINING}; +use tui::types::TUIStatusListener; use servers::{DiffBlock, ServerStats, WorkerStats}; use tui::table::{TableView, TableViewItem}; diff --git a/src/bin/tui/peers.rs b/src/bin/tui/peers.rs index 2b59d5ce0..40a2f11d1 100644 --- a/src/bin/tui/peers.rs +++ b/src/bin/tui/peers.rs @@ -18,15 +18,15 @@ use std::cmp::Ordering; use servers::{PeerStats, ServerStats}; -use cursive::Cursive; +use cursive::direction::Orientation; +use cursive::traits::{Boxable, Identifiable}; use cursive::view::View; use cursive::views::{BoxView, Dialog, LinearLayout, TextView}; -use cursive::direction::Orientation; -use cursive::traits::*; +use cursive::Cursive; +use tui::constants::{TABLE_PEER_STATUS, VIEW_PEER_SYNC}; use tui::table::{TableView, TableViewItem}; -use tui::constants::*; -use tui::types::*; +use tui::types::TUIStatusListener; #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum PeerColumn { diff --git a/src/bin/tui/status.rs b/src/bin/tui/status.rs index 66f56ccdb..95bc04ccc 100644 --- a/src/bin/tui/status.rs +++ b/src/bin/tui/status.rs @@ -14,14 +14,14 @@ //! Basic status view definition -use cursive::Cursive; +use cursive::direction::Orientation; +use cursive::traits::Identifiable; use cursive::view::View; use cursive::views::{BoxView, LinearLayout, TextView}; -use cursive::direction::Orientation; -use cursive::traits::*; +use cursive::Cursive; -use tui::constants::*; -use tui::types::*; +use tui::constants::VIEW_BASIC_STATUS; +use tui::types::TUIStatusListener; use servers::ServerStats; diff --git a/src/bin/tui/table.rs b/src/bin/tui/table.rs index 91e953d8c..9377ce2a8 100644 --- a/src/bin/tui/table.rs +++ b/src/bin/tui/table.rs @@ -41,8 +41,10 @@ //! Adapted from https://github.com/behnam/rust-cursive-table-view //! A basic table view implementation for [cursive](https://crates.io/crates/cursive). -#![deny(missing_docs, missing_copy_implementations, trivial_casts, trivial_numeric_casts, - unsafe_code, unused_import_braces, unused_qualifications)] +#![deny( + missing_docs, missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, + unused_import_braces, unused_qualifications +)] // Crate Dependencies --------------------------------------------------------- extern crate cursive; @@ -54,14 +56,14 @@ use std::hash::Hash; use std::rc::Rc; // External Dependencies ------------------------------------------------------ -use cursive::With; use cursive::align::HAlign; use cursive::direction::Direction; use cursive::event::{Callback, Event, EventResult, Key}; use cursive::theme::ColorStyle; -use cursive::theme::PaletteColor::*; +use cursive::theme::PaletteColor::{Highlight, HighlightInactive, Primary}; use cursive::vec::Vec2; use cursive::view::{ScrollBase, View}; +use cursive::With; use cursive::{Cursive, Printer}; /// A trait for displaying and sorting items inside a diff --git a/src/bin/tui/types.rs b/src/bin/tui/types.rs index f899b4dd6..24ec4001a 100644 --- a/src/bin/tui/types.rs +++ b/src/bin/tui/types.rs @@ -14,8 +14,8 @@ //! Types specific to the UI module -use cursive::Cursive; use cursive::view::View; +use cursive::Cursive; use servers::ServerStats; /// Main message struct to communicate between the UI and diff --git a/src/bin/tui/ui.rs b/src/bin/tui/ui.rs index 310748563..83ce83d22 100644 --- a/src/bin/tui/ui.rs +++ b/src/bin/tui/ui.rs @@ -18,21 +18,21 @@ use std::sync::{mpsc, Arc}; use time; -use cursive::Cursive; +use cursive::direction::Orientation; +use cursive::theme::BaseColor::{Black, Blue, Cyan, White}; +use cursive::theme::Color::Dark; +use cursive::theme::PaletteColor::{Background, Highlight, HighlightInactive, Primary, Shadow, View}; use cursive::theme::{BaseColor, BorderStyle, Color, Theme}; -use cursive::theme::PaletteColor::*; -use cursive::theme::Color::*; -use cursive::theme::BaseColor::*; +use cursive::traits::Identifiable; use cursive::utils::markup::StyledString; use cursive::views::{LinearLayout, Panel, StackView, TextView, ViewBox}; -use cursive::direction::Orientation; -use cursive::traits::*; +use cursive::Cursive; use servers::Server; +use tui::constants::ROOT_STACK; +use tui::types::{TUIStatusListener, UIMessage}; use tui::{menu, mining, peers, status, version}; -use tui::types::*; -use tui::constants::*; use built_info; diff --git a/src/bin/tui/version.rs b/src/bin/tui/version.rs index ceccca1ef..e8f63d4f3 100644 --- a/src/bin/tui/version.rs +++ b/src/bin/tui/version.rs @@ -14,17 +14,17 @@ //! Version and build info -use cursive::Cursive; +use cursive::direction::Orientation; +use cursive::traits::Identifiable; use cursive::view::View; use cursive::views::{BoxView, LinearLayout, TextView}; -use cursive::direction::Orientation; -use cursive::traits::*; +use cursive::Cursive; -use tui::constants::*; -use tui::types::*; +use tui::constants::VIEW_VERSION; +use tui::types::TUIStatusListener; -use servers::ServerStats; use info_strings; +use servers::ServerStats; pub struct TUIVersionView; diff --git a/store/src/pmmr.rs b/store/src/pmmr.rs index baf37e646..4b5ed83bc 100644 --- a/store/src/pmmr.rs +++ b/store/src/pmmr.rs @@ -19,9 +19,8 @@ use std::marker; use core::core::hash::Hash; use core::core::pmmr::{self, family, Backend}; -use core::ser; -use core::ser::PMMRable; -use types::*; +use core::ser::{self, PMMRable}; +use types::{prune_noop, read_ordered_vec, write_vec, AppendOnlyFile, RemoveLog}; use util::LOGGER; const PMMR_HASH_FILE: &'static str = "pmmr_hash.bin"; diff --git a/store/src/types.rs b/store/src/types.rs index a688bace2..39ccdf905 100644 --- a/store/src/types.rs +++ b/store/src/types.rs @@ -16,8 +16,7 @@ use memmap; use std::cmp; use std::fs::{self, File, OpenOptions}; -use std::io::Read; -use std::io::{self, BufRead, BufReader, BufWriter, ErrorKind, Write}; +use std::io::{self, BufRead, BufReader, BufWriter, ErrorKind, Read, Write}; use std::os::unix::io::AsRawFd; use std::path::Path; diff --git a/store/tests/pmmr.rs b/store/tests/pmmr.rs index c3b0ebe27..fc1a05f72 100644 --- a/store/tests/pmmr.rs +++ b/store/tests/pmmr.rs @@ -20,7 +20,7 @@ extern crate time; use std::fs; use core::core::pmmr::{Backend, PMMR}; -use core::ser::*; +use core::ser::{Error, PMMRIndexHashable, PMMRable, Readable, Reader, Writeable, Writer}; use store::types::prune_noop; #[test] diff --git a/wallet/src/client.rs b/wallet/src/client.rs index 8386f75f6..baa091779 100644 --- a/wallet/src/client.rs +++ b/wallet/src/client.rs @@ -21,9 +21,8 @@ use std::collections::HashMap; use std::io; use futures::{Future, Stream}; -use hyper; use hyper::header::ContentType; -use hyper::{Method, Request}; +use hyper::{self, Method, Request}; use serde_json; use tokio_core::reactor; diff --git a/wallet/src/display.rs b/wallet/src/display.rs index d07ce4718..369956ce1 100644 --- a/wallet/src/display.rs +++ b/wallet/src/display.rs @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use core::core; -use core::core::amount_to_hr_string; -use libwallet::Error; +use core::core::{self, amount_to_hr_string}; use libwallet::types::{OutputData, WalletInfo}; +use libwallet::Error; use prettytable; -use std::io::prelude::*; +use std::io::prelude::Write; use term; /// Display outputs in a pretty way diff --git a/wallet/src/file_wallet.rs b/wallet/src/file_wallet.rs index 8f2ec5144..cfdf0022f 100644 --- a/wallet/src/file_wallet.rs +++ b/wallet/src/file_wallet.rs @@ -18,27 +18,26 @@ use std::cmp::min; use std::collections::HashMap; use std::fs::{self, File}; use std::io::{Read, Write}; -use std::path::MAIN_SEPARATOR; -use std::path::Path; +use std::path::{Path, MAIN_SEPARATOR}; use serde_json; use tokio_core::reactor; -use tokio_retry::Retry; use tokio_retry::strategy::FibonacciBackoff; +use tokio_retry::Retry; use failure::ResultExt; use keychain::{self, Keychain}; -use util; -use util::LOGGER; use util::secp::pedersen; +use util::{self, LOGGER}; use error::{Error, ErrorKind}; use client; use libtx::slate::Slate; use libwallet; -use libwallet::types::*; +use libwallet::types::{BlockFees, BlockIdentifier, CbData, MerkleProofWrapper, OutputData, + TxWrapper, WalletBackend, WalletClient}; const DAT_FILE: &'static str = "wallet.dat"; const BCK_FILE: &'static str = "wallet.bck"; @@ -189,7 +188,7 @@ impl WalletBackend for FileWallet where K: Keychain, { - /// Initialise with whatever stored credentials we have + /// Initialize with whatever stored credentials we have fn open_with_credentials(&mut self) -> Result<(), libwallet::Error> { let wallet_seed = WalletSeed::from_file(&self.config) .context(libwallet::ErrorKind::CallbackImpl("Error opening wallet"))?; @@ -361,7 +360,7 @@ where // The limit exists because by default, we always select as many inputs as // possible in a transaction, to reduce both the Output set and the fees. // But that only makes sense up to a point, hence the limit to avoid being too - // greedy. But if max_outputs(500) is actually not enought to cover the whole + // greedy. But if max_outputs(500) is actually not enough to cover the whole // amount, the wallet should allow going over it to satisfy what the user // wants to send. So the wallet considers max_outputs more of a soft limit. if eligible.len() > max_outputs { @@ -436,7 +435,7 @@ impl WalletClient for FileWallet { } } - /// Posts a tranaction to a grin node + /// Posts a transaction to a grin node fn post_tx(&self, dest: &str, tx: &TxWrapper, fluff: bool) -> Result<(), libwallet::Error> { let res = client::post_tx(dest, tx, fluff).context(libwallet::ErrorKind::Node)?; Ok(res) diff --git a/wallet/src/libtx/error.rs b/wallet/src/libtx/error.rs index 4951da460..0bd73f422 100644 --- a/wallet/src/libtx/error.rs +++ b/wallet/src/libtx/error.rs @@ -16,8 +16,7 @@ use failure::{Backtrace, Context, Fail}; use std::fmt::{self, Display}; -use core::core::committed; -use core::core::transaction; +use core::core::{committed, transaction}; use keychain; use util::secp; diff --git a/wallet/src/libtx/slate.rs b/wallet/src/libtx/slate.rs index df4ccc591..b6bf23451 100644 --- a/wallet/src/libtx/slate.rs +++ b/wallet/src/libtx/slate.rs @@ -23,8 +23,8 @@ use keychain::{BlindSum, BlindingFactor, Keychain}; use libtx::error::{Error, ErrorKind}; use libtx::{aggsig, build, tx_fee}; -use util::secp::Signature; use util::secp::key::{PublicKey, SecretKey}; +use util::secp::Signature; use util::{secp, LOGGER}; /// Public data for each participant in the slate diff --git a/wallet/src/libwallet/api.rs b/wallet/src/libwallet/api.rs index 22c523328..9867ffc6d 100644 --- a/wallet/src/libwallet/api.rs +++ b/wallet/src/libwallet/api.rs @@ -19,14 +19,13 @@ use std::marker::PhantomData; +use core::ser; +use keychain::Keychain; use libtx::slate::Slate; -use libwallet::Error; use libwallet::internal::{tx, updater}; use libwallet::types::{BlockFees, CbData, OutputData, TxWrapper, WalletBackend, WalletClient, WalletInfo}; - -use core::ser; -use keychain::Keychain; +use libwallet::Error; use util::{self, LOGGER}; /// Wrapper around internal API functions, containing a reference to diff --git a/wallet/src/libwallet/controller.rs b/wallet/src/libwallet/controller.rs index de3905aec..c5e6b89cd 100644 --- a/wallet/src/libwallet/controller.rs +++ b/wallet/src/libwallet/controller.rs @@ -20,10 +20,8 @@ use std::marker::PhantomData; use std::sync::{Arc, Mutex}; use bodyparser; -use iron::Handler; -use iron::Headers; -use iron::prelude::*; -use iron::status; +use iron::prelude::{IronError, IronResult, Plugin, Request, Response}; +use iron::{status, Handler, Headers}; use serde::Serialize; use serde_json; use urlencoded::UrlEncodedQuery; diff --git a/wallet/src/libwallet/error.rs b/wallet/src/libwallet/error.rs index 95cfa7862..61aeeae55 100644 --- a/wallet/src/libwallet/error.rs +++ b/wallet/src/libwallet/error.rs @@ -48,8 +48,11 @@ pub enum ErrorKind { }, /// Fee Exceeds amount - #[fail(display = "Fee exceeds amount: sender amount {}, recipient fee {}", sender_amount, - recipient_fee)] + #[fail( + display = "Fee exceeds amount: sender amount {}, recipient fee {}", + sender_amount, + recipient_fee + )] FeeExceedsAmount { /// sender amount sender_amount: u64, diff --git a/wallet/src/libwallet/internal/restore.rs b/wallet/src/libwallet/internal/restore.rs index 01814b56c..68da479d4 100644 --- a/wallet/src/libwallet/internal/restore.rs +++ b/wallet/src/libwallet/internal/restore.rs @@ -23,9 +23,8 @@ use failure::{Fail, ResultExt}; use keychain::{Identifier, Keychain}; use libtx::proof; use libwallet::types::*; -use util; -use util::LOGGER; use util::secp::pedersen; +use util::{self, LOGGER}; fn get_merkle_proof_for_commit(node_addr: &str, commit: &str) -> Result { let url = format!("{}/v1/txhashset/merkleproof?id={}", node_addr, commit); diff --git a/wallet/src/libwallet/internal/selection.rs b/wallet/src/libwallet/internal/selection.rs index 5adbfa9d9..0e7b7b1b2 100644 --- a/wallet/src/libwallet/internal/selection.rs +++ b/wallet/src/libwallet/internal/selection.rs @@ -15,7 +15,7 @@ //! Selection of inputs for building transactions use keychain::{Identifier, Keychain}; -use libtx::{build, tx_fee, slate::Slate}; +use libtx::{build, slate::Slate, tx_fee}; use libwallet::error::{Error, ErrorKind}; use libwallet::internal::{keys, sigcontext}; use libwallet::types::*; diff --git a/wallet/src/libwallet/internal/updater.rs b/wallet/src/libwallet/internal/updater.rs index b8862b3cb..7d679faf1 100644 --- a/wallet/src/libwallet/internal/updater.rs +++ b/wallet/src/libwallet/internal/updater.rs @@ -16,21 +16,20 @@ //! the wallet storage and update them. use failure::ResultExt; -use std::collections::HashMap; use std::collections::hash_map::Entry; +use std::collections::HashMap; use core::consensus::reward; use core::core::{Output, TxKernel}; -use core::global; -use core::ser; +use core::{global, ser}; use keychain::{Identifier, Keychain}; use libtx::reward; use libwallet::error::{Error, ErrorKind}; use libwallet::internal::keys; -use libwallet::types::*; -use util; -use util::LOGGER; +use libwallet::types::{BlockFees, CbData, OutputData, OutputStatus, WalletBackend, WalletClient, + WalletInfo}; use util::secp::pedersen; +use util::{self, LOGGER}; /// Retrieve all of the outputs (doesn't attempt to update from node) pub fn retrieve_outputs(wallet: &mut T, show_spent: bool) -> Result, Error> diff --git a/wallet/src/libwallet/types.rs b/wallet/src/libwallet/types.rs index 95eafa43c..2cc6efa07 100644 --- a/wallet/src/libwallet/types.rs +++ b/wallet/src/libwallet/types.rs @@ -24,7 +24,6 @@ use failure::ResultExt; use core::core::hash::Hash; use core::core::pmmr::MerkleProof; - use keychain::{Identifier, Keychain}; use libtx::slate::Slate; diff --git a/wallet/tests/common/mod.rs b/wallet/tests/common/mod.rs index 07fcddbbb..476a2291e 100644 --- a/wallet/tests/common/mod.rs +++ b/wallet/tests/common/mod.rs @@ -13,8 +13,8 @@ // limitations under the License. //! Common functions to facilitate wallet, walletlib and transaction testing -use std::collections::HashMap; use std::collections::hash_map::Entry; +use std::collections::HashMap; extern crate grin_api as api; extern crate grin_chain as chain; @@ -28,9 +28,10 @@ use core::core::hash::Hashed; use core::core::{Output, OutputFeatures, OutputIdentifier, Transaction, TxKernel}; use core::{consensus, global, pow}; use keychain::ExtKeychain; -use wallet::file_wallet::*; +use wallet::file_wallet::{FileWallet, WalletConfig}; use wallet::libwallet::internal::updater; -use wallet::libwallet::types::*; +use wallet::libwallet::types::{BlockFees, BlockIdentifier, MerkleProofWrapper, OutputStatus, + WalletBackend}; use wallet::libwallet::{Error, ErrorKind}; use util; diff --git a/wallet/tests/transaction.rs b/wallet/tests/transaction.rs index 82b239ea3..597dff487 100644 --- a/wallet/tests/transaction.rs +++ b/wallet/tests/transaction.rs @@ -29,8 +29,8 @@ mod common; use std::fs; use std::sync::Arc; +use chain::types::NoopAdapter; use chain::Chain; -use chain::types::*; use core::global::ChainTypes; use core::{global, pow}; use util::LOGGER;