cli overhaul (#1600)
* cli commands * cleanup parity/signer * cleanup parity/signer * remove redundant import of signer crate from main.rs * cli cleanup in progress * cli cleanup in progress * moved few commonly used functions to separate methods with tests * cleaning up blockchain import in progress * cleaning up blockchain import in progress2 * cleaning up blockchain import in progress3 * tests for database compaction profile parsing * cleaning up blockchain import in progress4 * cleaning up blockchain import in progress5 * blockchain import * export blockchain in progress * cleanup execute_export * Configuration::to_duration cleaned up * removed unused code, tests for to_duration * cleanup Configuration::mode function * parsing some of the cli params in params.rs * rpc and signer are no longer optional * move importing extern crates to main.rs file * swipe dies from rpc module * swipe dies from dapps * finding deprecated * several tests and fixes for parity * parity cleanup in progress * cleanup price parsing * parity cleanup in progress * swiped all dies * parity cleanup in progress * replace usages of from_str with parse() in parity/params.rs * removed few more from_str * split parity/params.rs into params and helpers * removed wildcard import from configuration.rs * cleanup directories/path creation * cleaning up run cmd * moved LoggerConfig * defaults for cli params * fixed indention in raise_fd_limit * tests for rpc_apis * tests for default ipc and rpc settings * ipc socket * cleanup in progress * account service * cleanup miner config * BlockChain commands use Directiores structure now * client_config * network settings and dapps configuration * removing warnings * default logger config * fixed client_path * overhaul * fixing export && import * default export DataFormat * import and export also upgrade db * fixed export && import * polishing pr * polishing pr * fixed custom bootnodes * fixed daemonize on windows * fixed setting up enable network * finished pr * fixed compiling on windows * Fixed warning; windows build * Better cache management * Fixed tests on windows * Fixed test * Restored pruning method names * --cache alias * Fixed more tests * Ensure default options actually listed as valid [ci:skip]
This commit is contained in:
@@ -67,7 +67,7 @@ pub trait FixedHash: Sized + BytesConvertable + Populatable + FromStr + Default
|
||||
|
||||
/// Return `s` without the `0x` at the beginning of it, if any.
|
||||
pub fn clean_0x(s: &str) -> &str {
|
||||
if s.len() >= 2 && &s[0..2] == "0x" {
|
||||
if s.starts_with("0x") {
|
||||
&s[2..]
|
||||
} else {
|
||||
s
|
||||
@@ -429,13 +429,13 @@ macro_rules! impl_hash {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a str> for $from {
|
||||
fn from(s: &'a str) -> $from {
|
||||
use std::str::FromStr;
|
||||
impl From<&'static str> for $from {
|
||||
fn from(s: &'static str) -> $from {
|
||||
let s = clean_0x(s);
|
||||
if s.len() % 2 == 1 {
|
||||
$from::from_str(&("0".to_owned() + &(clean_0x(s).to_owned()))[..]).unwrap_or_else(|_| $from::new())
|
||||
$from::from_str(&("0".to_owned() + s)).unwrap()
|
||||
} else {
|
||||
$from::from_str(clean_0x(s)).unwrap_or_else(|_| $from::new())
|
||||
$from::from_str(s).unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -613,8 +613,6 @@ mod tests {
|
||||
assert_eq!(H64::from(0x1234567890abcdef), H64::from("0x1234567890abcdef"));
|
||||
assert_eq!(H64::from(0x1234567890abcdef), H64::from("1234567890abcdef"));
|
||||
assert_eq!(H64::from(0x234567890abcdef), H64::from("0x234567890abcdef"));
|
||||
// too short.
|
||||
assert_eq!(H64::from(0), H64::from("0x34567890abcdef"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -30,7 +30,7 @@ mod refcounteddb;
|
||||
pub use self::traits::JournalDB;
|
||||
|
||||
/// A journal database algorithm.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||
pub enum Algorithm {
|
||||
/// Keep all keys forever.
|
||||
Archive,
|
||||
@@ -60,14 +60,48 @@ impl Default for Algorithm {
|
||||
fn default() -> Algorithm { Algorithm::OverlayRecent }
|
||||
}
|
||||
|
||||
impl FromStr for Algorithm {
|
||||
type Err = String;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"archive" => Ok(Algorithm::Archive),
|
||||
"light" => Ok(Algorithm::EarlyMerge),
|
||||
"fast" => Ok(Algorithm::OverlayRecent),
|
||||
"basic" => Ok(Algorithm::RefCounted),
|
||||
e => Err(format!("Invalid algorithm: {}", e)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Algorithm {
|
||||
/// Returns static str describing journal database algorithm.
|
||||
pub fn as_str(&self) -> &'static str {
|
||||
match *self {
|
||||
Algorithm::Archive => "archive",
|
||||
Algorithm::EarlyMerge => "light",
|
||||
Algorithm::OverlayRecent => "fast",
|
||||
Algorithm::RefCounted => "basic",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if pruning strategy is stable
|
||||
pub fn is_stable(&self) -> bool {
|
||||
match *self {
|
||||
Algorithm::Archive | Algorithm::OverlayRecent => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns all algorithm types.
|
||||
pub fn all_types() -> Vec<Algorithm> {
|
||||
vec![Algorithm::Archive, Algorithm::EarlyMerge, Algorithm::OverlayRecent, Algorithm::RefCounted]
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Algorithm {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", match self {
|
||||
&Algorithm::Archive => "archive",
|
||||
&Algorithm::EarlyMerge => "earlymerge",
|
||||
&Algorithm::OverlayRecent => "overlayrecent",
|
||||
&Algorithm::RefCounted => "refcounted",
|
||||
})
|
||||
write!(f, "{}", self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,3 +119,60 @@ pub fn new(path: &str, algorithm: Algorithm, config: DatabaseConfig) -> Box<Jour
|
||||
const DB_PREFIX_LEN : usize = 12;
|
||||
const LATEST_ERA_KEY : [u8; DB_PREFIX_LEN] = [ b'l', b'a', b's', b't', 0, 0, 0, 0, 0, 0, 0, 0 ];
|
||||
const VERSION_KEY : [u8; DB_PREFIX_LEN] = [ b'j', b'v', b'e', b'r', 0, 0, 0, 0, 0, 0, 0, 0 ];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Algorithm;
|
||||
|
||||
#[test]
|
||||
fn test_journal_algorithm_parsing() {
|
||||
assert_eq!(Algorithm::Archive, "archive".parse().unwrap());
|
||||
assert_eq!(Algorithm::EarlyMerge, "light".parse().unwrap());
|
||||
assert_eq!(Algorithm::OverlayRecent, "fast".parse().unwrap());
|
||||
assert_eq!(Algorithm::RefCounted, "basic".parse().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_journal_algorithm_printing() {
|
||||
assert_eq!(Algorithm::Archive.to_string(), "archive".to_owned());
|
||||
assert_eq!(Algorithm::EarlyMerge.to_string(), "light".to_owned());
|
||||
assert_eq!(Algorithm::OverlayRecent.to_string(), "fast".to_owned());
|
||||
assert_eq!(Algorithm::RefCounted.to_string(), "basic".to_owned());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_journal_algorithm_is_stable() {
|
||||
assert!(Algorithm::Archive.is_stable());
|
||||
assert!(Algorithm::OverlayRecent.is_stable());
|
||||
assert!(!Algorithm::EarlyMerge.is_stable());
|
||||
assert!(!Algorithm::RefCounted.is_stable());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_journal_algorithm_default() {
|
||||
assert_eq!(Algorithm::default(), Algorithm::OverlayRecent);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_journal_algorithm_all_types() {
|
||||
// compiling should fail if some cases are not covered
|
||||
let mut archive = 0;
|
||||
let mut earlymerge = 0;
|
||||
let mut overlayrecent = 0;
|
||||
let mut refcounted = 0;
|
||||
|
||||
for a in &Algorithm::all_types() {
|
||||
match *a {
|
||||
Algorithm::Archive => archive += 1,
|
||||
Algorithm::EarlyMerge => earlymerge += 1,
|
||||
Algorithm::OverlayRecent => overlayrecent += 1,
|
||||
Algorithm::RefCounted => refcounted += 1,
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(archive, 1);
|
||||
assert_eq!(earlymerge, 1);
|
||||
assert_eq!(overlayrecent, 1);
|
||||
assert_eq!(refcounted, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ const MAX_HANDSHAKES: usize = 80;
|
||||
const MAX_HANDSHAKES_PER_ROUND: usize = 32;
|
||||
const MAINTENANCE_TIMEOUT: u64 = 1000;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
/// Network service configuration
|
||||
pub struct NetworkConfiguration {
|
||||
/// Directory path to store network configuration. None means nothing will be saved
|
||||
|
||||
@@ -16,17 +16,12 @@
|
||||
|
||||
// Based on original work by David Levy https://raw.githubusercontent.com/dlevy47/rust-interfaces
|
||||
|
||||
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||
use std::io;
|
||||
use igd::{PortMappingProtocol, search_gateway_from_timeout};
|
||||
use std::time::Duration;
|
||||
use network::node_table::{NodeEndpoint};
|
||||
|
||||
pub enum IpAddr{
|
||||
V4(Ipv4Addr),
|
||||
V6(Ipv6Addr),
|
||||
}
|
||||
|
||||
/// Socket address extension for rustc beta. To be replaces with now unstable API
|
||||
pub trait SocketAddrExt {
|
||||
/// Returns true for the special 'unspecified' address 0.0.0.0.
|
||||
@@ -66,8 +61,7 @@ mod getinterfaces {
|
||||
use std::{mem, io, ptr};
|
||||
use libc::{AF_INET, AF_INET6};
|
||||
use libc::{getifaddrs, freeifaddrs, ifaddrs, sockaddr, sockaddr_in, sockaddr_in6};
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
use super::IpAddr;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr, IpAddr};
|
||||
|
||||
fn convert_sockaddr (sa: *mut sockaddr) -> Option<IpAddr> {
|
||||
if sa == ptr::null_mut() { return None; }
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
//! Structure to hold network settings configured from CLI
|
||||
|
||||
/// Networking & RPC settings
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct NetworkSettings {
|
||||
/// Node name
|
||||
pub name: String,
|
||||
@@ -34,3 +34,16 @@ pub struct NetworkSettings {
|
||||
pub rpc_port: u16,
|
||||
}
|
||||
|
||||
impl Default for NetworkSettings {
|
||||
fn default() -> Self {
|
||||
NetworkSettings {
|
||||
name: "".into(),
|
||||
chain: "homestead".into(),
|
||||
max_peers: 25,
|
||||
network_port: 30303,
|
||||
rpc_enabled: true,
|
||||
rpc_interface: "local".into(),
|
||||
rpc_port: 8545
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ impl fmt::Display for TrieError {
|
||||
}
|
||||
|
||||
/// Trie types
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub enum TrieSpec {
|
||||
/// Generic trie.
|
||||
Generic,
|
||||
|
||||
Reference in New Issue
Block a user