2017-01-25 18:51:41 +01:00
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
2016-04-21 16:45:04 +02:00
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
2016-06-29 16:26:19 +02:00
use std ::time ::Duration ;
2017-03-02 20:04:17 +01:00
use std ::io ::{ Read , Write , stderr } ;
2016-07-25 16:09:47 +02:00
use std ::net ::SocketAddr ;
2017-01-06 16:05:58 +01:00
use std ::path ::{ Path , PathBuf } ;
2017-04-08 11:26:16 +02:00
use std ::collections ::BTreeMap ;
2016-07-29 17:30:02 +02:00
use std ::cmp ::max ;
2016-09-11 11:52:12 +02:00
use cli ::{ Args , ArgsError } ;
2017-05-24 12:31:33 +02:00
use util ::{ Hashable , H256 , U256 , Bytes , version_data , Address } ;
2017-03-02 20:04:17 +01:00
use util ::journaldb ::Algorithm ;
2017-03-22 06:23:40 +01:00
use util ::Colour ;
2016-10-24 18:25:27 +02:00
use ethsync ::{ NetworkConfiguration , is_valid_node_url , AllowIP } ;
2017-04-08 11:26:16 +02:00
use ethcore ::ethstore ::ethkey ::{ Secret , Public } ;
2016-12-11 02:02:40 +01:00
use ethcore ::client ::{ VMType } ;
2017-01-25 11:03:36 +01:00
use ethcore ::miner ::{ MinerOptions , Banning , StratumOptions } ;
2016-12-02 18:21:54 +01:00
use ethcore ::verification ::queue ::VerifierSettings ;
2016-07-25 16:09:47 +02:00
2017-05-24 12:24:07 +02:00
use rpc ::{ IpcConfiguration , HttpConfiguration , WsConfiguration , UiConfiguration } ;
2017-04-06 19:38:33 +02:00
use rpc_apis ::ApiSet ;
2017-04-13 16:32:07 +02:00
use parity_rpc ::NetworkSettings ;
2016-07-25 16:09:47 +02:00
use cache ::CacheConfig ;
2017-07-10 12:57:40 +02:00
use helpers ::{ to_duration , to_mode , to_block_id , to_u256 , to_pending_set , to_price , replace_home , replace_home_and_local ,
2016-10-15 14:46:33 +02:00
geth_ipc_path , parity_ipc_path , to_bootnodes , to_addresses , to_address , to_gas_limit , to_queue_strategy } ;
2017-03-02 20:04:17 +01:00
use params ::{ SpecType , ResealPolicy , AccountsConfig , GasPricerConfig , MinerExtras , Pruning , Switch } ;
2016-07-25 16:09:47 +02:00
use ethcore_logger ::Config as LogConfig ;
2017-01-18 18:45:30 +01:00
use dir ::{ self , Directories , default_hypervisor_path , default_local_path , default_data_path } ;
2016-07-25 16:09:47 +02:00
use dapps ::Configuration as DappsConfiguration ;
2017-02-16 14:41:33 +01:00
use ipfs ::Configuration as IpfsConfiguration ;
2017-02-20 16:13:21 +01:00
use secretstore ::Configuration as SecretStoreConfiguration ;
2016-12-15 18:51:59 +01:00
use updater ::{ UpdatePolicy , UpdateFilter , ReleaseTrack } ;
2016-07-25 16:09:47 +02:00
use run ::RunCmd ;
2016-12-12 17:19:41 +01:00
use blockchain ::{ BlockchainCmd , ImportBlockchain , ExportBlockchain , KillBlockchain , ExportState , DataFormat } ;
2016-07-25 16:09:47 +02:00
use presale ::ImportWallet ;
2016-12-12 16:51:07 +01:00
use account ::{ AccountCmd , NewAccount , ListAccounts , ImportAccounts , ImportFromGethAccounts } ;
2016-08-05 17:00:46 +02:00
use snapshot ::{ self , SnapshotCommand } ;
2016-07-25 16:09:47 +02:00
#[ derive(Debug, PartialEq) ]
pub enum Cmd {
Run ( RunCmd ) ,
Version ,
Account ( AccountCmd ) ,
ImportPresaleWallet ( ImportWallet ) ,
Blockchain ( BlockchainCmd ) ,
2017-05-24 12:24:07 +02:00
SignerToken ( WsConfiguration , UiConfiguration ) ,
2016-09-20 12:19:07 +02:00
SignerSign {
id : Option < usize > ,
pwfile : Option < PathBuf > ,
port : u16 ,
authfile : PathBuf ,
} ,
SignerList {
port : u16 ,
authfile : PathBuf
} ,
SignerReject {
2016-09-30 15:30:17 +02:00
id : Option < usize > ,
2016-09-20 12:19:07 +02:00
port : u16 ,
authfile : PathBuf
} ,
2016-08-05 17:00:46 +02:00
Snapshot ( SnapshotCommand ) ,
2016-09-23 15:28:09 +02:00
Hash ( Option < String > ) ,
2016-04-21 16:45:04 +02:00
}
2016-11-02 19:42:21 +01:00
pub struct Execute {
pub logger : LogConfig ,
pub cmd : Cmd ,
}
2016-07-25 16:09:47 +02:00
#[ derive(Debug, PartialEq) ]
pub struct Configuration {
pub args : Args ,
2017-03-13 12:10:53 +01:00
pub spec_name_override : Option < String > ,
2016-05-13 17:32:32 +02:00
}
2016-04-21 16:45:04 +02:00
impl Configuration {
2017-03-13 12:10:53 +01:00
pub fn parse < S : AsRef < str > > ( command : & [ S ] , spec_name_override : Option < String > ) -> Result < Self , ArgsError > {
2016-12-27 12:53:56 +01:00
let args = Args ::parse ( command ) ? ;
2016-07-25 16:09:47 +02:00
let config = Configuration {
args : args ,
2017-03-13 12:10:53 +01:00
spec_name_override : spec_name_override ,
2016-07-25 16:09:47 +02:00
} ;
Ok ( config )
}
2016-11-02 19:42:21 +01:00
pub fn into_command ( self ) -> Result < Execute , String > {
2016-07-25 16:09:47 +02:00
let dirs = self . directories ( ) ;
2016-12-27 12:53:56 +01:00
let pruning = self . args . flag_pruning . parse ( ) ? ;
2016-10-14 14:44:56 +02:00
let pruning_history = self . args . flag_pruning_history ;
2016-12-27 12:53:56 +01:00
let vm_type = self . vm_type ( ) ? ;
2017-03-13 12:10:53 +01:00
let spec = self . chain ( ) . parse ( ) ? ;
let mode = match self . args . flag_mode . as_ref ( ) {
" last " = > None ,
mode = > Some ( to_mode ( & mode , self . args . flag_mode_timeout , self . args . flag_mode_alarm ) ? ) ,
} ;
2016-12-27 12:53:56 +01:00
let update_policy = self . update_policy ( ) ? ;
2016-07-25 16:09:47 +02:00
let logger_config = self . logger_config ( ) ;
2017-04-13 16:32:07 +02:00
let ws_conf = self . ws_config ( ) ? ;
2016-12-27 12:53:56 +01:00
let http_conf = self . http_config ( ) ? ;
let ipc_conf = self . ipc_config ( ) ? ;
let net_conf = self . net_config ( ) ? ;
2017-05-24 12:24:07 +02:00
let ui_conf = self . ui_config ( ) ;
2016-11-03 22:22:25 +01:00
let network_id = self . network_id ( ) ;
2016-07-25 16:09:47 +02:00
let cache_config = self . cache_config ( ) ;
2016-12-27 12:53:56 +01:00
let tracing = self . args . flag_tracing . parse ( ) ? ;
let fat_db = self . args . flag_fat_db . parse ( ) ? ;
let compaction = self . args . flag_db_compaction . parse ( ) ? ;
2016-07-29 15:36:00 +02:00
let wal = ! self . args . flag_fast_and_loose ;
2017-03-02 20:04:17 +01:00
match self . args . flag_warp {
// Logging is not initialized yet, so we print directly to stderr
Some ( true ) if fat_db = = Switch ::On = > writeln! ( & mut stderr ( ) , " Warning: Warp Sync is disabled because Fat DB is turned on " ) . expect ( " Error writing to stderr " ) ,
Some ( true ) if tracing = = Switch ::On = > writeln! ( & mut stderr ( ) , " Warning: Warp Sync is disabled because tracing is turned on " ) . expect ( " Error writing to stderr " ) ,
Some ( true ) if pruning = = Pruning ::Specific ( Algorithm ::Archive ) = > writeln! ( & mut stderr ( ) , " Warning: Warp Sync is disabled because pruning mode is set to archive " ) . expect ( " Error writing to stderr " ) ,
_ = > { } ,
} ;
2017-03-29 17:07:58 +02:00
let public_node = self . args . flag_public_node ;
2017-03-02 20:04:17 +01:00
let warp_sync = ! self . args . flag_no_warp & & fat_db ! = Switch ::On & & tracing ! = Switch ::On & & pruning ! = Pruning ::Specific ( Algorithm ::Archive ) ;
2016-07-25 16:09:47 +02:00
let geth_compatibility = self . args . flag_geth ;
2017-04-03 10:27:37 +02:00
let mut dapps_conf = self . dapps_config ( ) ;
2017-02-16 14:41:33 +01:00
let ipfs_conf = self . ipfs_config ( ) ;
2017-04-08 11:26:16 +02:00
let secretstore_conf = self . secretstore_config ( ) ? ;
2016-12-27 12:53:56 +01:00
let format = self . format ( ) ? ;
2016-07-25 16:09:47 +02:00
2017-07-11 12:22:19 +02:00
if self . args . flag_jsonrpc_server_threads . is_some ( ) & & dapps_conf . enabled {
2017-04-03 10:27:37 +02:00
dapps_conf . enabled = false ;
writeln! ( & mut stderr ( ) , " Warning: Disabling Dapps server because fast RPC server was enabled. " ) . expect ( " Error writing to stderr. " )
}
2016-07-25 16:09:47 +02:00
let cmd = if self . args . flag_version {
Cmd ::Version
2016-09-20 12:19:07 +02:00
} else if self . args . cmd_signer {
2017-05-24 12:24:07 +02:00
let authfile = ::signer ::codes_path ( & ws_conf . signer_path ) ;
2016-09-20 12:19:07 +02:00
if self . args . cmd_new_token {
2017-05-24 12:24:07 +02:00
Cmd ::SignerToken ( ws_conf , ui_conf )
2016-09-20 12:19:07 +02:00
} else if self . args . cmd_sign {
2016-09-30 15:30:17 +02:00
let pwfile = self . args . flag_password . get ( 0 ) . map ( | pwfile | {
PathBuf ::from ( pwfile )
} ) ;
2016-09-20 12:19:07 +02:00
Cmd ::SignerSign {
id : self . args . arg_id ,
pwfile : pwfile ,
2017-05-24 12:24:07 +02:00
port : ws_conf . port ,
2016-09-20 12:19:07 +02:00
authfile : authfile ,
}
} else if self . args . cmd_reject {
Cmd ::SignerReject {
2016-09-30 15:30:17 +02:00
id : self . args . arg_id ,
2017-05-24 12:24:07 +02:00
port : ws_conf . port ,
2016-09-20 12:19:07 +02:00
authfile : authfile ,
}
} else if self . args . cmd_list {
Cmd ::SignerList {
2017-05-24 12:24:07 +02:00
port : ws_conf . port ,
2016-09-20 12:19:07 +02:00
authfile : authfile ,
}
} else {
unreachable! ( ) ;
}
2016-09-23 15:28:09 +02:00
} else if self . args . cmd_tools & & self . args . cmd_hash {
Cmd ::Hash ( self . args . arg_file )
2016-12-12 17:19:41 +01:00
} else if self . args . cmd_db & & self . args . cmd_kill {
Cmd ::Blockchain ( BlockchainCmd ::Kill ( KillBlockchain {
spec : spec ,
dirs : dirs ,
pruning : pruning ,
} ) )
2016-07-25 16:09:47 +02:00
} else if self . args . cmd_account {
let account_cmd = if self . args . cmd_new {
let new_acc = NewAccount {
iterations : self . args . flag_keys_iterations ,
path : dirs . keys ,
2016-12-12 16:51:07 +01:00
spec : spec ,
2016-07-25 16:09:47 +02:00
password_file : self . args . flag_password . first ( ) . cloned ( ) ,
} ;
AccountCmd ::New ( new_acc )
} else if self . args . cmd_list {
2016-12-12 16:51:07 +01:00
let list_acc = ListAccounts {
path : dirs . keys ,
spec : spec ,
} ;
AccountCmd ::List ( list_acc )
2016-07-25 16:09:47 +02:00
} else if self . args . cmd_import {
let import_acc = ImportAccounts {
from : self . args . arg_path . clone ( ) ,
to : dirs . keys ,
2016-12-12 16:51:07 +01:00
spec : spec ,
2016-07-25 16:09:47 +02:00
} ;
AccountCmd ::Import ( import_acc )
} else {
unreachable! ( ) ;
} ;
Cmd ::Account ( account_cmd )
2016-10-04 10:44:47 +02:00
} else if self . args . flag_import_geth_keys {
let account_cmd = AccountCmd ::ImportFromGeth (
ImportFromGethAccounts {
2016-12-12 16:51:07 +01:00
spec : spec ,
2016-10-04 10:44:47 +02:00
to : dirs . keys ,
testnet : self . args . flag_testnet
2016-10-06 10:20:05 +02:00
}
2016-10-04 10:44:47 +02:00
) ;
Cmd ::Account ( account_cmd )
2016-07-25 16:09:47 +02:00
} else if self . args . cmd_wallet {
let presale_cmd = ImportWallet {
iterations : self . args . flag_keys_iterations ,
path : dirs . keys ,
2016-12-12 16:51:07 +01:00
spec : spec ,
2016-07-25 16:09:47 +02:00
wallet_path : self . args . arg_path . first ( ) . unwrap ( ) . clone ( ) ,
password_file : self . args . flag_password . first ( ) . cloned ( ) ,
} ;
Cmd ::ImportPresaleWallet ( presale_cmd )
} else if self . args . cmd_import {
let import_cmd = ImportBlockchain {
spec : spec ,
cache_config : cache_config ,
dirs : dirs ,
file_path : self . args . arg_file . clone ( ) ,
2016-08-04 09:22:54 +02:00
format : format ,
2016-07-25 16:09:47 +02:00
pruning : pruning ,
2016-10-14 14:44:56 +02:00
pruning_history : pruning_history ,
2017-01-20 13:25:53 +01:00
pruning_memory : self . args . flag_pruning_memory ,
2016-07-25 16:09:47 +02:00
compaction : compaction ,
2016-07-29 15:36:00 +02:00
wal : wal ,
2016-07-25 16:09:47 +02:00
tracing : tracing ,
2016-10-03 11:13:10 +02:00
fat_db : fat_db ,
2016-07-25 16:09:47 +02:00
vm_type : vm_type ,
2016-10-24 15:09:13 +02:00
check_seal : ! self . args . flag_no_seal_check ,
2016-11-02 19:42:21 +01:00
with_color : logger_config . color ,
2016-12-02 18:21:54 +01:00
verifier_settings : self . verifier_settings ( ) ,
2017-07-27 18:46:09 +02:00
light : self . args . flag_light ,
2016-07-25 16:09:47 +02:00
} ;
Cmd ::Blockchain ( BlockchainCmd ::Import ( import_cmd ) )
} else if self . args . cmd_export {
2016-11-27 11:11:56 +01:00
if self . args . cmd_blocks {
let export_cmd = ExportBlockchain {
spec : spec ,
cache_config : cache_config ,
dirs : dirs ,
file_path : self . args . arg_file . clone ( ) ,
format : format ,
pruning : pruning ,
pruning_history : pruning_history ,
2017-01-20 13:25:53 +01:00
pruning_memory : self . args . flag_pruning_memory ,
2016-11-27 11:11:56 +01:00
compaction : compaction ,
wal : wal ,
tracing : tracing ,
fat_db : fat_db ,
2016-12-27 12:53:56 +01:00
from_block : to_block_id ( & self . args . flag_from ) ? ,
to_block : to_block_id ( & self . args . flag_to ) ? ,
2016-11-27 11:11:56 +01:00
check_seal : ! self . args . flag_no_seal_check ,
} ;
Cmd ::Blockchain ( BlockchainCmd ::Export ( export_cmd ) )
} else if self . args . cmd_state {
let export_cmd = ExportState {
spec : spec ,
cache_config : cache_config ,
dirs : dirs ,
file_path : self . args . arg_file . clone ( ) ,
format : format ,
pruning : pruning ,
pruning_history : pruning_history ,
2017-01-20 13:25:53 +01:00
pruning_memory : self . args . flag_pruning_memory ,
2016-11-27 11:11:56 +01:00
compaction : compaction ,
wal : wal ,
tracing : tracing ,
fat_db : fat_db ,
2016-12-27 12:53:56 +01:00
at : to_block_id ( & self . args . flag_at ) ? ,
2016-11-27 11:11:56 +01:00
storage : ! self . args . flag_no_storage ,
code : ! self . args . flag_no_code ,
2016-11-27 18:16:43 +01:00
min_balance : self . args . flag_min_balance . and_then ( | s | to_u256 ( & s ) . ok ( ) ) ,
max_balance : self . args . flag_max_balance . and_then ( | s | to_u256 ( & s ) . ok ( ) ) ,
2016-11-27 11:11:56 +01:00
} ;
Cmd ::Blockchain ( BlockchainCmd ::ExportState ( export_cmd ) )
} else {
unreachable! ( ) ;
}
2016-08-05 17:00:46 +02:00
} else if self . args . cmd_snapshot {
let snapshot_cmd = SnapshotCommand {
cache_config : cache_config ,
dirs : dirs ,
spec : spec ,
pruning : pruning ,
2016-10-14 14:44:56 +02:00
pruning_history : pruning_history ,
2017-01-20 13:25:53 +01:00
pruning_memory : self . args . flag_pruning_memory ,
2016-08-05 17:00:46 +02:00
tracing : tracing ,
2016-10-03 11:13:10 +02:00
fat_db : fat_db ,
2016-08-05 17:00:46 +02:00
compaction : compaction ,
file_path : self . args . arg_file . clone ( ) ,
wal : wal ,
kind : snapshot ::Kind ::Take ,
2016-12-27 12:53:56 +01:00
block_at : to_block_id ( & self . args . flag_at ) ? ,
2016-08-05 17:00:46 +02:00
} ;
Cmd ::Snapshot ( snapshot_cmd )
} else if self . args . cmd_restore {
let restore_cmd = SnapshotCommand {
cache_config : cache_config ,
dirs : dirs ,
spec : spec ,
pruning : pruning ,
2016-10-14 14:44:56 +02:00
pruning_history : pruning_history ,
2017-01-20 13:25:53 +01:00
pruning_memory : self . args . flag_pruning_memory ,
2016-08-05 17:00:46 +02:00
tracing : tracing ,
2016-10-03 11:13:10 +02:00
fat_db : fat_db ,
2016-08-05 17:00:46 +02:00
compaction : compaction ,
file_path : self . args . arg_file . clone ( ) ,
wal : wal ,
kind : snapshot ::Kind ::Restore ,
2016-12-27 12:53:56 +01:00
block_at : to_block_id ( " latest " ) ? , // unimportant.
2016-08-05 17:00:46 +02:00
} ;
Cmd ::Snapshot ( restore_cmd )
2016-07-25 16:09:47 +02:00
} else {
let daemon = if self . args . cmd_daemon {
Some ( self . args . arg_pid_file . clone ( ) )
} else {
None
} ;
2016-12-02 18:21:54 +01:00
let verifier_settings = self . verifier_settings ( ) ;
2017-02-24 17:36:52 +01:00
// Special presets are present for the dev chain.
let ( gas_pricer , miner_options ) = match spec {
SpecType ::Dev = > ( GasPricerConfig ::Fixed ( 0. into ( ) ) , self . miner_options ( 0 ) ? ) ,
_ = > ( self . gas_pricer_config ( ) ? , self . miner_options ( self . args . flag_reseal_min_period ) ? ) ,
} ;
2016-07-25 16:09:47 +02:00
let run_cmd = RunCmd {
cache_config : cache_config ,
dirs : dirs ,
spec : spec ,
pruning : pruning ,
2016-10-14 14:44:56 +02:00
pruning_history : pruning_history ,
2017-01-20 13:25:53 +01:00
pruning_memory : self . args . flag_pruning_memory ,
2016-07-25 16:09:47 +02:00
daemon : daemon ,
2016-11-02 19:42:21 +01:00
logger_config : logger_config . clone ( ) ,
2016-07-25 16:09:47 +02:00
miner_options : miner_options ,
2017-04-13 16:32:07 +02:00
ws_conf : ws_conf ,
2016-07-25 16:09:47 +02:00
http_conf : http_conf ,
ipc_conf : ipc_conf ,
net_conf : net_conf ,
network_id : network_id ,
2016-12-27 12:53:56 +01:00
acc_conf : self . accounts_config ( ) ? ,
2017-02-24 17:36:52 +01:00
gas_pricer : gas_pricer ,
2016-12-27 12:53:56 +01:00
miner_extras : self . miner_extras ( ) ? ,
2017-01-25 11:03:36 +01:00
stratum : self . stratum_options ( ) ? ,
2016-11-23 20:35:21 +01:00
update_policy : update_policy ,
2016-07-25 16:09:47 +02:00
mode : mode ,
tracing : tracing ,
2016-10-03 11:13:10 +02:00
fat_db : fat_db ,
2016-07-25 16:09:47 +02:00
compaction : compaction ,
2016-07-29 15:36:00 +02:00
wal : wal ,
2016-07-25 16:09:47 +02:00
vm_type : vm_type ,
2016-10-18 18:16:00 +02:00
warp_sync : warp_sync ,
2017-03-29 17:07:58 +02:00
public_node : public_node ,
2016-07-25 16:09:47 +02:00
geth_compatibility : geth_compatibility ,
2017-05-23 12:24:32 +02:00
net_settings : self . network_settings ( ) ? ,
2016-07-25 16:09:47 +02:00
dapps_conf : dapps_conf ,
2017-02-16 14:41:33 +01:00
ipfs_conf : ipfs_conf ,
2017-05-24 12:24:07 +02:00
ui_conf : ui_conf ,
2017-02-20 16:13:21 +01:00
secretstore_conf : secretstore_conf ,
2017-01-06 16:05:58 +01:00
dapp : self . dapp_to_open ( ) ? ,
2016-07-25 16:09:47 +02:00
ui : self . args . cmd_ui ,
name : self . args . flag_identity ,
custom_bootnodes : self . args . flag_bootnodes . is_some ( ) ,
2016-09-02 20:24:59 +02:00
no_periodic_snapshot : self . args . flag_no_periodic_snapshot ,
2016-10-24 15:09:13 +02:00
check_seal : ! self . args . flag_no_seal_check ,
2016-11-22 18:03:35 +01:00
download_old_blocks : ! self . args . flag_no_ancient_blocks ,
2016-12-02 18:21:54 +01:00
verifier_settings : verifier_settings ,
2017-03-22 16:45:50 +01:00
serve_light : ! self . args . flag_no_serve_light ,
light : self . args . flag_light ,
2017-05-04 12:13:50 +02:00
no_persistent_txqueue : self . args . flag_no_persistent_txqueue ,
2016-07-25 16:09:47 +02:00
} ;
Cmd ::Run ( run_cmd )
} ;
2016-11-02 19:42:21 +01:00
Ok ( Execute {
logger : logger_config ,
cmd : cmd ,
} )
2016-07-25 16:09:47 +02:00
}
fn vm_type ( & self ) -> Result < VMType , String > {
if self . args . flag_jitvm {
VMType ::jit ( ) . ok_or ( " Parity is built without the JIT EVM. " . into ( ) )
} else {
Ok ( VMType ::Interpreter )
2016-04-21 16:45:04 +02:00
}
}
2016-07-25 16:09:47 +02:00
fn miner_extras ( & self ) -> Result < MinerExtras , String > {
let extras = MinerExtras {
2016-12-27 12:53:56 +01:00
author : self . author ( ) ? ,
extra_data : self . extra_data ( ) ? ,
gas_floor_target : to_u256 ( & self . args . flag_gas_floor_target ) ? ,
gas_ceil_target : to_u256 ( & self . args . flag_gas_cap ) ? ,
engine_signer : self . engine_signer ( ) ? ,
2016-07-25 16:09:47 +02:00
} ;
Ok ( extras )
}
fn author ( & self ) -> Result < Address , String > {
to_address ( self . args . flag_etherbase . clone ( ) . or ( self . args . flag_author . clone ( ) ) )
}
2016-12-05 22:31:38 +01:00
fn engine_signer ( & self ) -> Result < Address , String > {
2016-12-05 20:23:03 +01:00
to_address ( self . args . flag_engine_signer . clone ( ) )
}
2016-08-04 09:22:54 +02:00
fn format ( & self ) -> Result < Option < DataFormat > , String > {
match self . args . flag_format {
2016-12-27 12:53:56 +01:00
Some ( ref f ) = > Ok ( Some ( f . parse ( ) ? ) ) ,
2016-08-04 09:22:54 +02:00
None = > Ok ( None ) ,
}
}
2016-07-25 16:09:47 +02:00
fn cache_config ( & self ) -> CacheConfig {
match self . args . flag_cache_size . or ( self . args . flag_cache ) {
Some ( size ) = > CacheConfig ::new_with_total_cache_size ( size ) ,
2016-10-07 00:28:42 +02:00
None = > CacheConfig ::new (
self . args . flag_cache_size_db ,
self . args . flag_cache_size_blocks ,
self . args . flag_cache_size_queue ,
self . args . flag_cache_size_state ,
) ,
2016-07-05 17:50:46 +02:00
}
}
2016-07-25 16:09:47 +02:00
fn logger_config ( & self ) -> LogConfig {
LogConfig {
mode : self . args . flag_logging . clone ( ) ,
color : ! self . args . flag_no_color & & ! cfg! ( windows ) ,
file : self . args . flag_log_file . clone ( ) ,
}
2016-04-30 19:58:28 +02:00
}
fn chain ( & self ) -> String {
2017-03-13 12:10:53 +01:00
if let Some ( ref s ) = self . spec_name_override {
s . clone ( )
}
else if self . args . flag_testnet {
2017-03-02 20:24:27 +01:00
" testnet " . to_owned ( )
2016-04-30 19:58:28 +02:00
} else {
self . args . flag_chain . clone ( )
}
}
fn max_peers ( & self ) -> u32 {
2016-07-29 17:30:02 +02:00
let peers = self . args . flag_max_peers as u32 ;
max ( self . min_peers ( ) , peers )
}
2016-10-24 18:25:27 +02:00
fn allow_ips ( & self ) -> Result < AllowIP , String > {
match self . args . flag_allow_ips . as_str ( ) {
" all " = > Ok ( AllowIP ::All ) ,
" public " = > Ok ( AllowIP ::Public ) ,
" private " = > Ok ( AllowIP ::Private ) ,
_ = > Err ( " Invalid IP filter value " . to_owned ( ) ) ,
}
}
2016-07-29 17:30:02 +02:00
fn min_peers ( & self ) -> u32 {
self . args . flag_peers . unwrap_or ( self . args . flag_min_peers ) as u32
2016-04-30 19:58:28 +02:00
}
2016-10-24 18:25:27 +02:00
fn max_pending_peers ( & self ) -> u32 {
self . args . flag_max_pending_peers as u32
}
fn snapshot_peers ( & self ) -> u32 {
self . args . flag_snapshot_peers as u32
}
2016-06-29 20:07:21 +02:00
fn work_notify ( & self ) -> Vec < String > {
self . args . flag_notify_work . as_ref ( ) . map_or_else ( Vec ::new , | s | s . split ( ',' ) . map ( | s | s . to_owned ( ) ) . collect ( ) )
2016-06-29 15:37:11 +02:00
}
2016-07-25 16:09:47 +02:00
fn accounts_config ( & self ) -> Result < AccountsConfig , String > {
let cfg = AccountsConfig {
iterations : self . args . flag_keys_iterations ,
testnet : self . args . flag_testnet ,
password_files : self . args . flag_password . clone ( ) ,
2016-12-27 12:53:56 +01:00
unlocked_accounts : to_addresses ( & self . args . flag_unlock ) ? ,
2017-02-10 01:07:06 +01:00
enable_hardware_wallets : ! self . args . flag_no_hardware_wallets ,
2017-06-06 18:06:40 +02:00
enable_fast_unlock : self . args . flag_fast_unlock ,
2016-06-27 17:23:54 +02:00
} ;
2016-07-25 16:09:47 +02:00
Ok ( cfg )
}
2017-01-25 11:03:36 +01:00
fn stratum_options ( & self ) -> Result < Option < StratumOptions > , String > {
if self . args . flag_stratum {
Ok ( Some ( StratumOptions {
io_path : self . directories ( ) . db ,
listen_addr : self . stratum_interface ( ) ,
2017-05-23 12:24:32 +02:00
port : self . args . flag_ports_shift + self . args . flag_stratum_port ,
2017-01-25 11:03:36 +01:00
secret : self . args . flag_stratum_secret . as_ref ( ) . map ( | s | s . parse ::< H256 > ( ) . unwrap_or_else ( | _ | s . sha3 ( ) ) ) ,
} ) )
} else { Ok ( None ) }
}
2017-02-24 17:36:52 +01:00
fn miner_options ( & self , reseal_min_period : u64 ) -> Result < MinerOptions , String > {
2017-07-01 17:20:49 +02:00
if self . args . flag_force_sealing & & reseal_min_period = = 0 {
return Err ( " Force sealing can't be used with reseal_min_period = 0 " . into ( ) ) ;
}
2016-12-27 12:53:56 +01:00
let reseal = self . args . flag_reseal_on_txs . parse ::< ResealPolicy > ( ) ? ;
2016-07-25 16:09:47 +02:00
let options = MinerOptions {
2016-06-29 15:37:11 +02:00
new_work_notify : self . work_notify ( ) ,
2016-06-27 17:23:54 +02:00
force_sealing : self . args . flag_force_sealing ,
2016-07-25 16:09:47 +02:00
reseal_on_external_tx : reseal . external ,
reseal_on_own_tx : reseal . own ,
2017-07-10 13:36:42 +02:00
reseal_on_uncle : self . args . flag_reseal_on_uncle ,
2016-07-25 16:09:47 +02:00
tx_gas_limit : match self . args . flag_tx_gas_limit {
2016-12-27 12:53:56 +01:00
Some ( ref d ) = > to_u256 ( d ) ? ,
2016-07-25 16:09:47 +02:00
None = > U256 ::max_value ( ) ,
2016-06-27 18:27:06 +02:00
} ,
2016-07-25 16:09:47 +02:00
tx_queue_size : self . args . flag_tx_queue_size ,
2017-07-13 15:12:25 +02:00
tx_queue_memory_limit : if self . args . flag_tx_queue_mem_limit > 0 {
Some ( self . args . flag_tx_queue_mem_limit as usize * 1024 * 1024 )
} else { None } ,
2016-12-27 12:53:56 +01:00
tx_queue_gas_limit : to_gas_limit ( & self . args . flag_tx_queue_gas ) ? ,
tx_queue_strategy : to_queue_strategy ( & self . args . flag_tx_queue_strategy ) ? ,
pending_set : to_pending_set ( & self . args . flag_relay_set ) ? ,
2017-02-24 17:36:52 +01:00
reseal_min_period : Duration ::from_millis ( reseal_min_period ) ,
2017-03-15 14:04:42 +01:00
reseal_max_period : Duration ::from_millis ( self . args . flag_reseal_max_period ) ,
2016-06-29 16:26:19 +02:00
work_queue_size : self . args . flag_work_queue_size ,
2016-06-30 12:56:58 +02:00
enable_resubmission : ! self . args . flag_remove_solved ,
2016-10-27 19:28:34 +02:00
tx_queue_banning : match self . args . flag_tx_time_limit {
Some ( limit ) = > Banning ::Enabled {
min_offends : self . args . flag_tx_queue_ban_count ,
offend_threshold : Duration ::from_millis ( limit ) ,
ban_duration : Duration ::from_secs ( self . args . flag_tx_queue_ban_time as u64 ) ,
} ,
None = > Banning ::Disabled ,
2017-01-22 16:15:22 +01:00
} ,
refuse_service_transactions : self . args . flag_refuse_service_transactions ,
2016-07-25 16:09:47 +02:00
} ;
2016-04-21 16:45:04 +02:00
2016-07-25 16:09:47 +02:00
Ok ( options )
2016-06-23 14:29:16 +02:00
}
2016-06-19 13:20:14 +02:00
2017-05-24 12:24:07 +02:00
fn ui_config ( & self ) -> UiConfiguration {
UiConfiguration {
2016-11-07 17:40:53 +01:00
enabled : self . ui_enabled ( ) ,
2017-07-11 12:23:46 +02:00
ntp_server : self . args . flag_ntp_server . clone ( ) ,
2016-11-07 17:40:53 +01:00
interface : self . ui_interface ( ) ,
2017-05-24 12:24:07 +02:00
port : self . args . flag_ports_shift + self . args . flag_ui_port ,
hosts : self . ui_hosts ( ) ,
2016-04-21 16:45:04 +02:00
}
}
2016-07-25 16:09:47 +02:00
fn dapps_config ( & self ) -> DappsConfiguration {
DappsConfiguration {
enabled : self . dapps_enabled ( ) ,
2017-07-11 12:23:46 +02:00
ntp_server : self . args . flag_ntp_server . clone ( ) ,
2017-01-06 16:05:58 +01:00
dapps_path : PathBuf ::from ( self . directories ( ) . dapps ) ,
extra_dapps : if self . args . cmd_dapp {
self . args . arg_path . iter ( ) . map ( | path | PathBuf ::from ( path ) ) . collect ( )
} else {
vec! [ ]
} ,
2017-07-11 13:45:23 +02:00
extra_embed_on : if self . args . flag_ui_no_validation {
vec! [ ( " localhost " . to_owned ( ) , 3000 ) ]
} else {
vec! [ ]
} ,
2017-01-06 16:05:58 +01:00
}
}
2017-04-08 11:26:16 +02:00
fn secretstore_config ( & self ) -> Result < SecretStoreConfiguration , String > {
Ok ( SecretStoreConfiguration {
2017-02-20 16:13:21 +01:00
enabled : self . secretstore_enabled ( ) ,
2017-04-08 11:26:16 +02:00
self_secret : self . secretstore_self_secret ( ) ? ,
nodes : self . secretstore_nodes ( ) ? ,
2017-02-20 16:13:21 +01:00
interface : self . secretstore_interface ( ) ,
2017-05-23 12:24:32 +02:00
port : self . args . flag_ports_shift + self . args . flag_secretstore_port ,
2017-04-08 11:26:16 +02:00
http_interface : self . secretstore_http_interface ( ) ,
2017-05-23 12:24:32 +02:00
http_port : self . args . flag_ports_shift + self . args . flag_secretstore_http_port ,
2017-02-20 16:13:21 +01:00
data_path : self . directories ( ) . secretstore ,
2017-04-08 11:26:16 +02:00
} )
2017-02-20 16:13:21 +01:00
}
2017-02-16 14:41:33 +01:00
fn ipfs_config ( & self ) -> IpfsConfiguration {
IpfsConfiguration {
enabled : self . args . flag_ipfs_api ,
2017-05-23 12:24:32 +02:00
port : self . args . flag_ports_shift + self . args . flag_ipfs_api_port ,
2017-02-24 10:32:42 +01:00
interface : self . ipfs_interface ( ) ,
cors : self . ipfs_cors ( ) ,
hosts : self . ipfs_hosts ( ) ,
2017-02-16 14:41:33 +01:00
}
}
2017-01-06 16:05:58 +01:00
fn dapp_to_open ( & self ) -> Result < Option < String > , String > {
if ! self . args . cmd_dapp {
return Ok ( None ) ;
2016-04-21 16:45:04 +02:00
}
2017-01-06 16:05:58 +01:00
let path = self . args . arg_path . get ( 0 ) . map ( String ::as_str ) . unwrap_or ( " . " ) ;
let path = Path ::new ( path ) . canonicalize ( )
. map_err ( | e | format! ( " Invalid path: {} . Error: {:?} " , path , e ) ) ? ;
let name = path . file_name ( )
. and_then ( | name | name . to_str ( ) )
. ok_or_else ( | | " Root path is not supported. " . to_owned ( ) ) ? ;
Ok ( Some ( name . into ( ) ) )
2016-04-21 16:45:04 +02:00
}
2016-07-25 16:09:47 +02:00
fn gas_pricer_config ( & self ) -> Result < GasPricerConfig , String > {
2017-01-18 19:44:24 +01:00
fn wei_per_gas ( usd_per_tx : f32 , usd_per_eth : f32 ) -> U256 {
let wei_per_usd : f32 = 1.0e18 / usd_per_eth ;
let gas_per_tx : f32 = 21000.0 ;
let wei_per_gas : f32 = wei_per_usd * usd_per_tx / gas_per_tx ;
U256 ::from_dec_str ( & format! ( " {:.0} " , wei_per_gas ) ) . unwrap ( )
}
2016-07-25 16:09:47 +02:00
if let Some ( d ) = self . args . flag_gasprice . as_ref ( ) {
2016-12-27 12:53:56 +01:00
return Ok ( GasPricerConfig ::Fixed ( to_u256 ( d ) ? ) ) ;
2016-04-21 16:45:04 +02:00
}
2016-12-27 12:53:56 +01:00
let usd_per_tx = to_price ( & self . args . flag_usd_per_tx ) ? ;
2016-07-25 16:09:47 +02:00
if " auto " = = self . args . flag_usd_per_eth . as_str ( ) {
2017-01-18 19:44:24 +01:00
// Just a very rough estimate to avoid accepting
// ZGP transactions before the price is fetched
// if user does not want it.
let last_known_usd_per_eth = 10.0 ;
2016-07-25 16:09:47 +02:00
return Ok ( GasPricerConfig ::Calibrated {
2017-01-18 19:44:24 +01:00
initial_minimum : wei_per_gas ( usd_per_tx , last_known_usd_per_eth ) ,
2016-07-25 16:09:47 +02:00
usd_per_tx : usd_per_tx ,
2016-12-27 12:53:56 +01:00
recalibration_period : to_duration ( self . args . flag_price_update_period . as_str ( ) ) ? ,
2016-07-25 16:09:47 +02:00
} ) ;
2016-04-21 16:45:04 +02:00
}
2016-07-25 16:09:47 +02:00
2016-12-27 12:53:56 +01:00
let usd_per_eth = to_price ( & self . args . flag_usd_per_eth ) ? ;
2017-01-18 19:44:24 +01:00
let wei_per_gas = wei_per_gas ( usd_per_tx , usd_per_eth ) ;
2016-07-25 16:09:47 +02:00
info! (
" Using a fixed conversion rate of Ξ1 = {} ({} wei/gas) " ,
2017-04-19 22:59:02 +02:00
Colour ::White . bold ( ) . paint ( format! ( " US$ {:.2} " , usd_per_eth ) ) ,
2016-07-25 16:09:47 +02:00
Colour ::Yellow . bold ( ) . paint ( format! ( " {} " , wei_per_gas ) )
) ;
2017-01-18 19:44:24 +01:00
Ok ( GasPricerConfig ::Fixed ( wei_per_gas ) )
2016-04-21 16:45:04 +02:00
}
2016-07-25 16:09:47 +02:00
fn extra_data ( & self ) -> Result < Bytes , String > {
match self . args . flag_extradata . as_ref ( ) . or ( self . args . flag_extra_data . as_ref ( ) ) {
2016-08-17 16:06:41 +02:00
Some ( x ) if x . len ( ) < = 32 = > Ok ( x . as_bytes ( ) . to_owned ( ) ) ,
2016-07-25 16:09:47 +02:00
None = > Ok ( version_data ( ) ) ,
Some ( _ ) = > Err ( " Extra data must be at most 32 characters " . into ( ) ) ,
2016-04-21 16:45:04 +02:00
}
}
2016-07-25 16:09:47 +02:00
fn init_reserved_nodes ( & self ) -> Result < Vec < String > , String > {
2016-06-20 14:13:33 +02:00
use std ::fs ::File ;
2016-07-25 16:09:47 +02:00
match self . args . flag_reserved_peers {
Some ( ref path ) = > {
let mut buffer = String ::new ( ) ;
2016-12-27 12:53:56 +01:00
let mut node_file = File ::open ( path ) . map_err ( | e | format! ( " Error opening reserved nodes file: {} " , e ) ) ? ;
node_file . read_to_string ( & mut buffer ) . map_err ( | _ | " Error reading reserved node file " ) ? ;
2017-07-10 13:24:40 +02:00
let lines = buffer . lines ( ) . map ( | s | s . trim ( ) . to_owned ( ) ) . filter ( | s | ! s . is_empty ( ) & & ! s . starts_with ( " # " ) ) . collect ::< Vec < _ > > ( ) ;
2016-07-29 10:22:51 +02:00
if let Some ( invalid ) = lines . iter ( ) . find ( | s | ! is_valid_node_url ( s ) ) {
return Err ( format! ( " Invalid node address format given for a boot node: {} " , invalid ) ) ;
2016-07-25 16:09:47 +02:00
}
2016-07-29 10:22:51 +02:00
Ok ( lines )
2016-07-25 16:09:47 +02:00
} ,
None = > Ok ( Vec ::new ( ) )
2016-06-20 14:13:33 +02:00
}
}
2017-05-23 12:24:32 +02:00
fn net_addresses ( & self ) -> Result < ( SocketAddr , Option < SocketAddr > ) , String > {
let port = self . args . flag_ports_shift + self . args . flag_port ;
let listen_address = SocketAddr ::new ( " 0.0.0.0 " . parse ( ) . unwrap ( ) , port ) ;
2016-04-21 16:45:04 +02:00
let public_address = if self . args . flag_nat . starts_with ( " extip: " ) {
let host = & self . args . flag_nat [ 6 .. ] ;
2016-12-27 12:53:56 +01:00
let host = host . parse ( ) . map_err ( | _ | format! ( " Invalid host given with `--nat extip: {} ` " , host ) ) ? ;
2016-04-30 19:58:28 +02:00
Some ( SocketAddr ::new ( host , port ) )
2016-04-21 16:45:04 +02:00
} else {
2016-07-04 18:21:22 +02:00
None
2016-04-21 16:45:04 +02:00
} ;
2016-07-25 16:09:47 +02:00
Ok ( ( listen_address , public_address ) )
2016-04-21 16:45:04 +02:00
}
2016-07-25 16:09:47 +02:00
fn net_config ( & self ) -> Result < NetworkConfiguration , String > {
2016-04-21 16:45:04 +02:00
let mut ret = NetworkConfiguration ::new ( ) ;
ret . nat_enabled = self . args . flag_nat = = " any " | | self . args . flag_nat = = " upnp " ;
2016-12-27 12:53:56 +01:00
ret . boot_nodes = to_bootnodes ( & self . args . flag_bootnodes ) ? ;
let ( listen , public ) = self . net_addresses ( ) ? ;
2017-05-23 12:24:32 +02:00
ret . listen_address = Some ( format! ( " {} " , listen ) ) ;
2016-08-05 10:32:04 +02:00
ret . public_address = public . map ( | p | format! ( " {} " , p ) ) ;
2017-01-11 12:16:47 +01:00
ret . use_secret = match self . args . flag_node_key . as_ref ( )
2017-05-19 17:06:36 +02:00
. map ( | s | s . parse ::< Secret > ( ) . or_else ( | _ | Secret ::from_unsafe_slice ( & s . sha3 ( ) ) ) . map_err ( | e | format! ( " Invalid key: {:?} " , e ) )
2017-01-11 12:16:47 +01:00
) {
None = > None ,
Some ( Ok ( key ) ) = > Some ( key ) ,
Some ( Err ( err ) ) = > return Err ( err ) ,
} ;
2016-04-21 16:45:04 +02:00
ret . discovery_enabled = ! self . args . flag_no_discovery & & ! self . args . flag_nodiscover ;
2016-07-29 17:30:02 +02:00
ret . max_peers = self . max_peers ( ) ;
ret . min_peers = self . min_peers ( ) ;
2016-10-24 18:25:27 +02:00
ret . snapshot_peers = self . snapshot_peers ( ) ;
2016-12-27 12:53:56 +01:00
ret . allow_ips = self . allow_ips ( ) ? ;
2016-10-24 18:25:27 +02:00
ret . max_pending_peers = self . max_pending_peers ( ) ;
2016-12-15 21:56:45 +01:00
let mut net_path = PathBuf ::from ( self . directories ( ) . base ) ;
2016-04-21 16:45:04 +02:00
net_path . push ( " network " ) ;
ret . config_path = Some ( net_path . to_str ( ) . unwrap ( ) . to_owned ( ) ) ;
2016-12-27 12:53:56 +01:00
ret . reserved_nodes = self . init_reserved_nodes ( ) ? ;
2016-08-05 10:32:04 +02:00
ret . allow_non_reserved = ! self . args . flag_reserved_only ;
2016-07-25 16:09:47 +02:00
Ok ( ret )
2016-04-21 16:45:04 +02:00
}
2016-12-05 15:54:31 +01:00
fn network_id ( & self ) -> Option < u64 > {
2016-11-03 22:22:25 +01:00
self . args . flag_network_id . or ( self . args . flag_networkid )
2016-07-11 09:46:33 +02:00
}
2016-07-25 16:09:47 +02:00
fn rpc_apis ( & self ) -> String {
2017-03-29 17:07:58 +02:00
let mut apis : Vec < & str > = self . args . flag_rpcapi
. as_ref ( )
. unwrap_or ( & self . args . flag_jsonrpc_apis )
. split ( " , " )
. collect ( ) ;
2016-11-06 12:51:53 +01:00
if self . args . flag_geth {
2017-04-06 19:38:33 +02:00
apis . insert ( 0 , " personal " ) ;
2017-03-29 17:07:58 +02:00
}
apis . join ( " , " )
2016-04-30 19:58:28 +02:00
}
2017-02-24 10:32:42 +01:00
fn cors ( cors : Option < & String > ) -> Option < Vec < String > > {
cors . map ( | ref c | c . split ( ',' ) . map ( Into ::into ) . collect ( ) )
}
2016-07-25 16:09:47 +02:00
fn rpc_cors ( & self ) -> Option < Vec < String > > {
2017-02-24 10:32:42 +01:00
let cors = self . args . flag_jsonrpc_cors . as_ref ( ) . or ( self . args . flag_rpccorsdomain . as_ref ( ) ) ;
Self ::cors ( cors )
2016-07-20 12:34:17 +02:00
}
2017-02-24 10:32:42 +01:00
fn ipfs_cors ( & self ) -> Option < Vec < String > > {
Self ::cors ( self . args . flag_ipfs_api_cors . as_ref ( ) )
}
2017-05-23 12:24:32 +02:00
fn hosts ( & self , hosts : & str , interface : & str ) -> Option < Vec < String > > {
if self . args . flag_unsafe_expose {
return None ;
}
if interface = = " 0.0.0.0 " & & hosts = = " none " {
return None ;
}
Self ::parse_hosts ( hosts )
}
fn parse_hosts ( hosts : & str ) -> Option < Vec < String > > {
2017-02-24 10:32:42 +01:00
match hosts {
2016-07-20 12:34:17 +02:00
" none " = > return Some ( Vec ::new ( ) ) ,
2017-04-03 10:27:37 +02:00
" * " | " all " | " any " = > return None ,
2016-07-20 12:34:17 +02:00
_ = > { }
}
2017-02-24 10:32:42 +01:00
let hosts = hosts . split ( ',' ) . map ( Into ::into ) . collect ( ) ;
2016-07-20 12:34:17 +02:00
Some ( hosts )
2016-04-30 19:58:28 +02:00
}
2016-05-13 12:53:33 +02:00
2017-05-24 12:24:07 +02:00
fn ui_hosts ( & self ) -> Option < Vec < String > > {
self . hosts ( & self . args . flag_ui_hosts , & self . ui_interface ( ) )
}
2017-02-24 10:32:42 +01:00
fn rpc_hosts ( & self ) -> Option < Vec < String > > {
2017-05-23 12:24:32 +02:00
self . hosts ( & self . args . flag_jsonrpc_hosts , & self . rpc_interface ( ) )
2017-02-24 10:32:42 +01:00
}
2017-04-13 16:32:07 +02:00
fn ws_hosts ( & self ) -> Option < Vec < String > > {
2017-05-23 12:24:32 +02:00
self . hosts ( & self . args . flag_ws_hosts , & self . ws_interface ( ) )
2017-04-13 16:32:07 +02:00
}
fn ws_origins ( & self ) -> Option < Vec < String > > {
2017-07-11 14:49:35 +02:00
if self . args . flag_unsafe_expose | | self . args . flag_ui_no_validation {
2017-06-03 14:41:42 +02:00
return None ;
}
2017-05-23 12:24:32 +02:00
Self ::parse_hosts ( & self . args . flag_ws_origins )
2017-04-13 16:32:07 +02:00
}
2017-02-24 10:32:42 +01:00
fn ipfs_hosts ( & self ) -> Option < Vec < String > > {
2017-05-23 12:24:32 +02:00
self . hosts ( & self . args . flag_ipfs_api_hosts , & self . ipfs_interface ( ) )
2016-08-25 08:57:13 +02:00
}
2016-07-25 16:09:47 +02:00
fn ipc_config ( & self ) -> Result < IpcConfiguration , String > {
let conf = IpcConfiguration {
enabled : ! ( self . args . flag_ipcdisable | | self . args . flag_ipc_off | | self . args . flag_no_ipc ) ,
socket_addr : self . ipc_path ( ) ,
2016-11-06 12:51:53 +01:00
apis : {
let mut apis = self . args . flag_ipcapi . clone ( ) . unwrap_or ( self . args . flag_ipc_apis . clone ( ) ) ;
if self . args . flag_geth {
2016-11-08 21:45:22 +01:00
if ! apis . is_empty ( ) {
apis . push_str ( " , " ) ;
}
2016-11-06 12:51:53 +01:00
apis . push_str ( " personal " ) ;
}
2016-12-27 12:53:56 +01:00
apis . parse ( ) ?
2016-11-06 12:51:53 +01:00
} ,
2016-07-25 16:09:47 +02:00
} ;
2016-05-13 12:53:33 +02:00
2016-07-25 16:09:47 +02:00
Ok ( conf )
2016-05-14 19:43:29 +02:00
}
2016-07-25 16:09:47 +02:00
fn http_config ( & self ) -> Result < HttpConfiguration , String > {
let conf = HttpConfiguration {
2017-04-03 10:27:37 +02:00
enabled : self . rpc_enabled ( ) ,
2016-07-25 16:09:47 +02:00
interface : self . rpc_interface ( ) ,
2017-05-23 12:24:32 +02:00
port : self . args . flag_ports_shift + self . args . flag_rpcport . unwrap_or ( self . args . flag_jsonrpc_port ) ,
2017-04-06 19:38:33 +02:00
apis : match self . args . flag_public_node {
false = > self . rpc_apis ( ) . parse ( ) ? ,
true = > self . rpc_apis ( ) . parse ::< ApiSet > ( ) ? . retain ( ApiSet ::PublicContext ) ,
} ,
2016-07-25 16:09:47 +02:00
hosts : self . rpc_hosts ( ) ,
cors : self . rpc_cors ( ) ,
2017-07-11 12:22:19 +02:00
server_threads : match self . args . flag_jsonrpc_server_threads {
2017-04-03 10:27:37 +02:00
Some ( threads ) if threads > 0 = > Some ( threads ) ,
None = > None ,
2017-07-11 12:22:19 +02:00
_ = > return Err ( " --jsonrpc-server-threads number needs to be positive. " . into ( ) ) ,
} ,
processing_threads : self . args . flag_jsonrpc_threads ,
2016-07-25 16:09:47 +02:00
} ;
Ok ( conf )
2016-05-04 15:37:09 +02:00
}
2017-04-13 16:32:07 +02:00
fn ws_config ( & self ) -> Result < WsConfiguration , String > {
2017-05-24 12:24:07 +02:00
let ui = self . ui_config ( ) ;
2017-04-13 16:32:07 +02:00
let conf = WsConfiguration {
enabled : self . ws_enabled ( ) ,
interface : self . ws_interface ( ) ,
2017-05-23 12:24:32 +02:00
port : self . args . flag_ports_shift + self . args . flag_ws_port ,
2017-04-13 16:32:07 +02:00
apis : self . args . flag_ws_apis . parse ( ) ? ,
hosts : self . ws_hosts ( ) ,
2017-05-24 12:24:07 +02:00
origins : self . ws_origins ( ) ,
signer_path : self . directories ( ) . signer . into ( ) ,
2017-06-12 15:57:16 +02:00
support_token_api : ! self . args . flag_public_node ,
2017-05-24 12:24:07 +02:00
ui_address : ui . address ( ) ,
2017-04-13 16:32:07 +02:00
} ;
Ok ( conf )
}
2017-05-23 12:24:32 +02:00
fn network_settings ( & self ) -> Result < NetworkSettings , String > {
let http_conf = self . http_config ( ) ? ;
let net_addresses = self . net_addresses ( ) ? ;
Ok ( NetworkSettings {
2016-04-21 19:19:42 +02:00
name : self . args . flag_identity . clone ( ) ,
2016-04-30 19:58:28 +02:00
chain : self . chain ( ) ,
2017-05-23 12:24:32 +02:00
network_port : net_addresses . 0. port ( ) ,
rpc_enabled : http_conf . enabled ,
rpc_interface : http_conf . interface ,
rpc_port : http_conf . port ,
} )
2016-04-21 19:19:42 +02:00
}
2016-05-13 17:32:32 +02:00
2016-11-23 20:35:21 +01:00
fn update_policy ( & self ) -> Result < UpdatePolicy , String > {
Ok ( UpdatePolicy {
enable_downloading : ! self . args . flag_no_download ,
2016-12-11 16:52:41 +01:00
require_consensus : ! self . args . flag_no_consensus ,
2016-11-23 20:35:21 +01:00
filter : match self . args . flag_auto_update . as_ref ( ) {
" none " = > UpdateFilter ::None ,
" critical " = > UpdateFilter ::Critical ,
" all " = > UpdateFilter ::All ,
2016-12-16 21:45:51 +01:00
_ = > return Err ( " Invalid value for `--auto-update`. See `--help` for more information. " . into ( ) ) ,
2016-11-23 20:35:21 +01:00
} ,
2016-12-15 19:23:25 +01:00
track : match self . args . flag_release_track . as_ref ( ) {
2016-12-15 18:51:59 +01:00
" stable " = > ReleaseTrack ::Stable ,
" beta " = > ReleaseTrack ::Beta ,
" nightly " = > ReleaseTrack ::Nightly ,
" testing " = > ReleaseTrack ::Testing ,
" current " = > ReleaseTrack ::Unknown ,
2016-12-16 21:45:51 +01:00
_ = > return Err ( " Invalid value for `--releases-track`. See `--help` for more information. " . into ( ) ) ,
2016-12-15 18:51:59 +01:00
} ,
2016-12-15 19:53:13 +01:00
path : default_hypervisor_path ( ) ,
2016-11-23 20:35:21 +01:00
} )
2016-11-23 16:29:15 +01:00
}
2016-07-25 16:09:47 +02:00
fn directories ( & self ) -> Directories {
2017-03-22 06:23:40 +01:00
use path ;
2016-08-09 17:38:44 +02:00
2017-01-05 14:12:54 +01:00
let local_path = default_local_path ( ) ;
2017-05-29 15:15:54 +02:00
let base_path = self . args . flag_base_path . as_ref ( ) . or_else ( | | self . args . flag_datadir . as_ref ( ) ) . map_or_else ( | | default_data_path ( ) , | s | s . clone ( ) ) ;
let data_path = replace_home ( " " , & base_path ) ;
2017-07-10 12:57:40 +02:00
let is_using_base_path = self . args . flag_base_path . is_some ( ) ;
// If base_path is set and db_path is not we default to base path subdir instead of LOCAL.
let base_db_path = if is_using_base_path & & self . args . flag_db_path . is_none ( ) {
2017-01-18 18:45:30 +01:00
" $BASE/chains "
2017-01-05 14:12:54 +01:00
} else {
2017-01-18 18:45:30 +01:00
self . args . flag_db_path . as_ref ( ) . map_or ( dir ::CHAINS_PATH , | s | & s )
2017-01-05 14:12:54 +01:00
} ;
2017-07-10 12:57:40 +02:00
let cache_path = if is_using_base_path {
" $BASE/cache " . into ( )
} else {
replace_home_and_local ( & data_path , & local_path , & dir ::CACHE_PATH )
} ;
2017-01-18 18:45:30 +01:00
2017-07-10 12:57:40 +02:00
let db_path = replace_home_and_local ( & data_path , & local_path , & base_db_path ) ;
2016-12-12 16:51:07 +01:00
let keys_path = replace_home ( & data_path , & self . args . flag_keys_path ) ;
let dapps_path = replace_home ( & data_path , & self . args . flag_dapps_path ) ;
2017-02-20 16:13:21 +01:00
let secretstore_path = replace_home ( & data_path , & self . args . flag_secretstore_path ) ;
2016-12-12 16:51:07 +01:00
let ui_path = replace_home ( & data_path , & self . args . flag_ui_path ) ;
2016-05-13 17:32:32 +02:00
2017-03-02 20:24:27 +01:00
if self . args . flag_geth & & ! cfg! ( windows ) {
let geth_root = if self . chain ( ) = = " testnet " . to_owned ( ) { path ::ethereum ::test ( ) } else { path ::ethereum ::default ( ) } ;
2016-10-18 16:44:40 +02:00
::std ::fs ::create_dir_all ( geth_root . as_path ( ) ) . unwrap_or_else (
| e | warn! ( " Failed to create '{}' for geth mode: {} " , & geth_root . to_str ( ) . unwrap ( ) , e ) ) ;
2016-08-09 17:38:44 +02:00
}
2016-08-22 18:41:58 +02:00
if cfg! ( feature = " ipc " ) & & ! cfg! ( feature = " windows " ) {
2016-12-12 16:51:07 +01:00
let mut path_buf = PathBuf ::from ( data_path . clone ( ) ) ;
2016-08-22 18:41:58 +02:00
path_buf . push ( " ipc " ) ;
let ipc_path = path_buf . to_str ( ) . unwrap ( ) ;
::std ::fs ::create_dir_all ( ipc_path ) . unwrap_or_else (
| e | warn! ( " Failed to directory '{}' for ipc sockets: {} " , ipc_path , e )
) ;
}
2016-05-13 17:32:32 +02:00
Directories {
keys : keys_path ,
2016-12-15 21:56:45 +01:00
base : data_path ,
2017-07-10 12:57:40 +02:00
cache : cache_path ,
2016-12-15 21:56:45 +01:00
db : db_path ,
2016-06-03 11:51:11 +02:00
dapps : dapps_path ,
2016-11-07 17:40:53 +01:00
signer : ui_path ,
2017-02-20 16:13:21 +01:00
secretstore : secretstore_path ,
2016-05-13 17:32:32 +02:00
}
}
fn ipc_path ( & self ) -> String {
2016-06-15 00:57:49 +02:00
if self . args . flag_geth {
2016-07-25 16:09:47 +02:00
geth_ipc_path ( self . args . flag_testnet )
2016-06-15 00:57:49 +02:00
} else {
2017-05-23 12:24:32 +02:00
parity_ipc_path (
& self . directories ( ) . base ,
& self . args . flag_ipcpath . clone ( ) . unwrap_or ( self . args . flag_ipc_path . clone ( ) ) ,
self . args . flag_ports_shift ,
)
2016-06-13 18:55:24 +02:00
}
}
2017-05-23 12:24:32 +02:00
fn interface ( & self , interface : & str ) -> String {
if self . args . flag_unsafe_expose {
return " 0.0.0.0 " . into ( ) ;
}
2017-02-24 10:32:42 +01:00
match interface {
2016-06-24 12:10:36 +02:00
" all " = > " 0.0.0.0 " ,
" local " = > " 127.0.0.1 " ,
x = > x ,
} . into ( )
}
2017-05-24 12:24:07 +02:00
fn ui_interface ( & self ) -> String {
self . interface ( & self . args . flag_ui_interface )
}
2017-02-24 10:32:42 +01:00
fn rpc_interface ( & self ) -> String {
2017-05-23 12:24:32 +02:00
let rpc_interface = self . args . flag_rpcaddr . clone ( ) . unwrap_or ( self . args . flag_jsonrpc_interface . clone ( ) ) ;
self . interface ( & rpc_interface )
2017-02-24 10:32:42 +01:00
}
2017-04-13 16:32:07 +02:00
fn ws_interface ( & self ) -> String {
2017-05-23 12:24:32 +02:00
self . interface ( & self . args . flag_ws_interface )
2017-04-13 16:32:07 +02:00
}
2017-02-24 10:32:42 +01:00
fn ipfs_interface ( & self ) -> String {
2017-05-23 12:24:32 +02:00
self . interface ( & self . args . flag_ipfs_api_interface )
2017-02-24 10:32:42 +01:00
}
2017-02-20 16:13:21 +01:00
fn secretstore_interface ( & self ) -> String {
2017-05-23 12:24:32 +02:00
self . interface ( & self . args . flag_secretstore_interface )
2017-04-08 11:26:16 +02:00
}
fn secretstore_http_interface ( & self ) -> String {
2017-05-23 12:24:32 +02:00
self . interface ( & self . args . flag_secretstore_http_interface )
2017-04-08 11:26:16 +02:00
}
fn secretstore_self_secret ( & self ) -> Result < Option < Secret > , String > {
match self . args . flag_secretstore_secret {
Some ( ref s ) = > Ok ( Some ( s . parse ( )
. map_err ( | e | format! ( " Invalid secret store secret: {} . Error: {:?} " , s , e ) ) ? ) ) ,
None = > Ok ( None ) ,
}
}
fn secretstore_nodes ( & self ) -> Result < BTreeMap < Public , ( String , u16 ) > , String > {
let mut nodes = BTreeMap ::new ( ) ;
for node in self . args . flag_secretstore_nodes . split ( ',' ) . filter ( | n | n ! = & " " ) {
let public_and_addr : Vec < _ > = node . split ( '@' ) . collect ( ) ;
if public_and_addr . len ( ) ! = 2 {
return Err ( format! ( " Invalid secret store node: {} " , node ) ) ;
}
let ip_and_port : Vec < _ > = public_and_addr [ 1 ] . split ( ':' ) . collect ( ) ;
if ip_and_port . len ( ) ! = 2 {
return Err ( format! ( " Invalid secret store node: {} " , node ) ) ;
}
let public = public_and_addr [ 0 ] . parse ( )
. map_err ( | e | format! ( " Invalid public key in secret store node: {} . Error: {:?} " , public_and_addr [ 0 ] , e ) ) ? ;
let port = ip_and_port [ 1 ] . parse ( )
. map_err ( | e | format! ( " Invalid port in secret store node: {} . Error: {:?} " , ip_and_port [ 1 ] , e ) ) ? ;
nodes . insert ( public , ( ip_and_port [ 0 ] . into ( ) , port ) ) ;
}
Ok ( nodes )
2017-02-20 16:13:21 +01:00
}
2017-01-25 11:03:36 +01:00
fn stratum_interface ( & self ) -> String {
2017-05-23 12:24:32 +02:00
self . interface ( & self . args . flag_stratum_interface )
2017-01-25 11:03:36 +01:00
}
2017-04-03 10:27:37 +02:00
fn rpc_enabled ( & self ) -> bool {
! self . args . flag_jsonrpc_off & & ! self . args . flag_no_jsonrpc
}
2017-04-13 16:32:07 +02:00
fn ws_enabled ( & self ) -> bool {
! self . args . flag_no_ws
}
2016-07-25 16:09:47 +02:00
fn dapps_enabled ( & self ) -> bool {
2017-04-03 10:27:37 +02:00
! self . args . flag_dapps_off & & ! self . args . flag_no_dapps & & self . rpc_enabled ( ) & & cfg! ( feature = " dapps " )
2016-06-24 12:14:46 +02:00
}
2016-06-24 14:20:39 +02:00
2017-02-20 16:13:21 +01:00
fn secretstore_enabled ( & self ) -> bool {
! self . args . flag_no_secretstore & & cfg! ( feature = " secretstore " )
}
2016-11-07 17:40:53 +01:00
fn ui_enabled ( & self ) -> bool {
if self . args . flag_force_ui {
2016-07-22 14:47:31 +02:00
return true ;
}
2016-11-07 17:40:53 +01:00
let ui_disabled = self . args . flag_unlock . is_some ( ) | |
2016-07-22 14:47:31 +02:00
self . args . flag_geth | |
2016-11-07 17:40:53 +01:00
self . args . flag_no_ui ;
2016-07-22 14:47:31 +02:00
2017-06-09 12:26:57 +02:00
! ui_disabled & & cfg! ( feature = " ui-enabled " )
2016-06-24 14:20:39 +02:00
}
2016-12-02 18:21:54 +01:00
fn verifier_settings ( & self ) -> VerifierSettings {
let mut settings = VerifierSettings ::default ( ) ;
settings . scale_verifiers = self . args . flag_scale_verifiers ;
if let Some ( num_verifiers ) = self . args . flag_num_verifiers {
settings . num_verifiers = num_verifiers ;
}
settings
}
2016-04-21 16:45:04 +02:00
}
2016-04-30 19:58:28 +02:00
#[ cfg(test) ]
mod tests {
2017-05-24 12:24:07 +02:00
use std ::io ::Write ;
use std ::fs ::{ File , create_dir } ;
use devtools ::{ RandomTempPath } ;
2016-12-11 15:41:49 +01:00
use ethcore ::client ::{ VMType , BlockId } ;
2016-10-15 14:46:33 +02:00
use ethcore ::miner ::{ MinerOptions , PrioritizationStrategy } ;
2017-05-24 12:24:07 +02:00
use parity_rpc ::NetworkSettings ;
use updater ::{ UpdatePolicy , UpdateFilter , ReleaseTrack } ;
use account ::{ AccountCmd , NewAccount , ImportAccounts , ListAccounts } ;
2016-11-28 12:08:12 +01:00
use blockchain ::{ BlockchainCmd , ImportBlockchain , ExportBlockchain , DataFormat , ExportState } ;
2017-05-24 12:24:07 +02:00
use cli ::Args ;
use dir ::{ Directories , default_hypervisor_path } ;
use helpers ::{ default_network_config } ;
2016-12-12 17:53:17 +01:00
use params ::SpecType ;
2017-05-24 12:24:07 +02:00
use presale ::ImportWallet ;
use rpc ::{ WsConfiguration , UiConfiguration } ;
use run ::RunCmd ;
use super ::* ;
2016-07-25 16:09:47 +02:00
#[ derive(Debug, PartialEq) ]
struct TestPasswordReader ( & 'static str ) ;
2016-04-30 19:58:28 +02:00
fn parse ( args : & [ & str ] ) -> Configuration {
Configuration {
2016-09-11 11:52:12 +02:00
args : Args ::parse_without_config ( args ) . unwrap ( ) ,
2017-03-13 12:10:53 +01:00
spec_name_override : None ,
2016-04-30 19:58:28 +02:00
}
}
2016-07-25 16:09:47 +02:00
#[ test ]
fn test_command_version ( ) {
let args = vec! [ " parity " , " --version " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Version ) ;
2016-07-25 16:09:47 +02:00
}
#[ test ]
fn test_command_account_new ( ) {
let args = vec! [ " parity " , " account " , " new " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Account ( AccountCmd ::New ( NewAccount {
2016-07-25 16:09:47 +02:00
iterations : 10240 ,
2016-12-13 23:38:29 +01:00
path : Directories ::default ( ) . keys ,
2016-07-25 16:09:47 +02:00
password_file : None ,
2016-12-12 17:53:17 +01:00
spec : SpecType ::default ( ) ,
2016-07-25 16:09:47 +02:00
} ) ) ) ;
}
#[ test ]
fn test_command_account_list ( ) {
let args = vec! [ " parity " , " account " , " list " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Account (
2016-12-12 17:53:17 +01:00
AccountCmd ::List ( ListAccounts {
2016-12-13 23:38:29 +01:00
path : Directories ::default ( ) . keys ,
2016-12-12 17:53:17 +01:00
spec : SpecType ::default ( ) ,
} )
2016-11-02 19:42:21 +01:00
) ) ;
2016-07-25 16:09:47 +02:00
}
#[ test ]
fn test_command_account_import ( ) {
let args = vec! [ " parity " , " account " , " import " , " my_dir " , " another_dir " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Account ( AccountCmd ::Import ( ImportAccounts {
2016-07-25 16:09:47 +02:00
from : vec ! [ " my_dir " . into ( ) , " another_dir " . into ( ) ] ,
2016-12-13 23:38:29 +01:00
to : Directories ::default ( ) . keys ,
2016-12-12 17:53:17 +01:00
spec : SpecType ::default ( ) ,
2016-07-25 16:09:47 +02:00
} ) ) ) ;
}
#[ test ]
fn test_command_wallet_import ( ) {
let args = vec! [ " parity " , " wallet " , " import " , " my_wallet.json " , " --password " , " pwd " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::ImportPresaleWallet ( ImportWallet {
2016-07-25 16:09:47 +02:00
iterations : 10240 ,
2016-12-13 23:38:29 +01:00
path : Directories ::default ( ) . keys ,
2016-07-25 16:09:47 +02:00
wallet_path : " my_wallet.json " . into ( ) ,
password_file : Some ( " pwd " . into ( ) ) ,
2016-12-12 17:53:17 +01:00
spec : SpecType ::default ( ) ,
2016-07-25 16:09:47 +02:00
} ) ) ;
}
#[ test ]
fn test_command_blockchain_import ( ) {
let args = vec! [ " parity " , " import " , " blockchain.json " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Blockchain ( BlockchainCmd ::Import ( ImportBlockchain {
2016-07-25 16:09:47 +02:00
spec : Default ::default ( ) ,
cache_config : Default ::default ( ) ,
dirs : Default ::default ( ) ,
file_path : Some ( " blockchain.json " . into ( ) ) ,
2016-08-04 09:22:54 +02:00
format : Default ::default ( ) ,
2016-07-25 16:09:47 +02:00
pruning : Default ::default ( ) ,
2017-02-13 17:15:25 +01:00
pruning_history : 64 ,
2017-05-02 11:40:03 +02:00
pruning_memory : 32 ,
2016-07-25 16:09:47 +02:00
compaction : Default ::default ( ) ,
2016-07-29 15:36:00 +02:00
wal : true ,
2016-07-25 16:09:47 +02:00
tracing : Default ::default ( ) ,
2016-10-03 11:13:10 +02:00
fat_db : Default ::default ( ) ,
2016-07-25 16:09:47 +02:00
vm_type : VMType ::Interpreter ,
2016-10-24 15:09:13 +02:00
check_seal : true ,
2016-11-03 16:11:08 +01:00
with_color : ! cfg! ( windows ) ,
2016-12-02 18:36:00 +01:00
verifier_settings : Default ::default ( ) ,
2017-07-27 18:46:09 +02:00
light : false ,
2016-07-25 16:09:47 +02:00
} ) ) ) ;
}
#[ test ]
fn test_command_blockchain_export ( ) {
2016-11-28 12:08:12 +01:00
let args = vec! [ " parity " , " export " , " blocks " , " blockchain.json " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Blockchain ( BlockchainCmd ::Export ( ExportBlockchain {
2016-07-25 16:09:47 +02:00
spec : Default ::default ( ) ,
cache_config : Default ::default ( ) ,
dirs : Default ::default ( ) ,
file_path : Some ( " blockchain.json " . into ( ) ) ,
pruning : Default ::default ( ) ,
2017-02-13 17:15:25 +01:00
pruning_history : 64 ,
2017-05-02 11:40:03 +02:00
pruning_memory : 32 ,
2016-07-25 16:09:47 +02:00
format : Default ::default ( ) ,
compaction : Default ::default ( ) ,
2016-07-29 15:36:00 +02:00
wal : true ,
2016-07-25 16:09:47 +02:00
tracing : Default ::default ( ) ,
2016-10-03 11:13:10 +02:00
fat_db : Default ::default ( ) ,
2016-11-22 10:24:22 +01:00
from_block : BlockId ::Number ( 1 ) ,
to_block : BlockId ::Latest ,
2016-10-24 15:09:13 +02:00
check_seal : true ,
2016-07-25 16:09:47 +02:00
} ) ) ) ;
}
2016-11-28 12:08:12 +01:00
#[ test ]
fn test_command_state_export ( ) {
let args = vec! [ " parity " , " export " , " state " , " state.json " ] ;
let conf = parse ( & args ) ;
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Blockchain ( BlockchainCmd ::ExportState ( ExportState {
spec : Default ::default ( ) ,
cache_config : Default ::default ( ) ,
dirs : Default ::default ( ) ,
file_path : Some ( " state.json " . into ( ) ) ,
pruning : Default ::default ( ) ,
2017-02-13 17:15:25 +01:00
pruning_history : 64 ,
2017-05-02 11:40:03 +02:00
pruning_memory : 32 ,
2016-11-28 12:08:12 +01:00
format : Default ::default ( ) ,
compaction : Default ::default ( ) ,
wal : true ,
tracing : Default ::default ( ) ,
fat_db : Default ::default ( ) ,
2016-12-04 18:13:23 +01:00
at : BlockId ::Latest ,
2016-11-28 12:08:12 +01:00
storage : true ,
code : true ,
min_balance : None ,
max_balance : None ,
} ) ) ) ;
}
2016-08-04 09:22:54 +02:00
#[ test ]
fn test_command_blockchain_export_with_custom_format ( ) {
2016-11-28 12:08:12 +01:00
let args = vec! [ " parity " , " export " , " blocks " , " --format " , " hex " , " blockchain.json " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-11-02 19:42:21 +01:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Blockchain ( BlockchainCmd ::Export ( ExportBlockchain {
2016-08-04 09:22:54 +02:00
spec : Default ::default ( ) ,
cache_config : Default ::default ( ) ,
dirs : Default ::default ( ) ,
file_path : Some ( " blockchain.json " . into ( ) ) ,
pruning : Default ::default ( ) ,
2017-02-13 17:15:25 +01:00
pruning_history : 64 ,
2017-05-02 11:40:03 +02:00
pruning_memory : 32 ,
2016-08-04 09:22:54 +02:00
format : Some ( DataFormat ::Hex ) ,
compaction : Default ::default ( ) ,
wal : true ,
tracing : Default ::default ( ) ,
2016-10-03 11:13:10 +02:00
fat_db : Default ::default ( ) ,
2016-11-22 10:24:22 +01:00
from_block : BlockId ::Number ( 1 ) ,
to_block : BlockId ::Latest ,
2016-10-24 15:09:13 +02:00
check_seal : true ,
2016-08-04 09:22:54 +02:00
} ) ) ) ;
}
2016-07-25 16:09:47 +02:00
#[ test ]
fn test_command_signer_new_token ( ) {
let args = vec! [ " parity " , " signer " , " new-token " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2016-12-13 23:38:29 +01:00
let expected = Directories ::default ( ) . signer ;
2017-05-24 12:24:07 +02:00
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::SignerToken ( WsConfiguration {
enabled : true ,
interface : " 127.0.0.1 " . into ( ) ,
port : 8546 ,
apis : ApiSet ::UnsafeContext ,
origins : Some ( vec! [ " chrome-extension://* " . into ( ) ] ) ,
hosts : Some ( vec! [ ] ) ,
signer_path : expected . into ( ) ,
ui_address : Some ( ( " 127.0.0.1 " . to_owned ( ) , 8180 ) ) ,
2017-06-12 17:43:23 +02:00
support_token_api : true
2017-05-24 12:24:07 +02:00
} , UiConfiguration {
2016-11-14 11:56:01 +01:00
enabled : true ,
2017-07-27 18:46:09 +02:00
ntp_server : " none " . into ( ) ,
2016-11-14 11:56:01 +01:00
interface : " 127.0.0.1 " . into ( ) ,
port : 8180 ,
2017-05-24 12:24:07 +02:00
hosts : Some ( vec! [ ] ) ,
2016-11-02 19:42:21 +01:00
} ) ) ;
2016-07-25 16:09:47 +02:00
}
#[ test ]
fn test_run_cmd ( ) {
let args = vec! [ " parity " ] ;
2016-09-12 14:11:30 +02:00
let conf = parse ( & args ) ;
2017-02-20 16:13:21 +01:00
let mut expected = RunCmd {
2016-07-25 16:09:47 +02:00
cache_config : Default ::default ( ) ,
dirs : Default ::default ( ) ,
spec : Default ::default ( ) ,
pruning : Default ::default ( ) ,
2017-02-13 17:15:25 +01:00
pruning_history : 64 ,
2017-05-02 11:40:03 +02:00
pruning_memory : 32 ,
2016-07-25 16:09:47 +02:00
daemon : None ,
logger_config : Default ::default ( ) ,
miner_options : Default ::default ( ) ,
2017-04-13 16:32:07 +02:00
ws_conf : Default ::default ( ) ,
2016-07-25 16:09:47 +02:00
http_conf : Default ::default ( ) ,
ipc_conf : Default ::default ( ) ,
net_conf : default_network_config ( ) ,
network_id : None ,
2017-03-29 17:07:58 +02:00
public_node : false ,
2017-03-02 20:04:17 +01:00
warp_sync : true ,
2016-07-25 16:09:47 +02:00
acc_conf : Default ::default ( ) ,
gas_pricer : Default ::default ( ) ,
miner_extras : Default ::default ( ) ,
2016-12-15 19:53:13 +01:00
update_policy : UpdatePolicy { enable_downloading : true , require_consensus : true , filter : UpdateFilter ::Critical , track : ReleaseTrack ::Unknown , path : default_hypervisor_path ( ) } ,
2016-07-25 16:09:47 +02:00
mode : Default ::default ( ) ,
tracing : Default ::default ( ) ,
compaction : Default ::default ( ) ,
2016-07-29 15:36:00 +02:00
wal : true ,
2016-07-25 16:09:47 +02:00
vm_type : Default ::default ( ) ,
geth_compatibility : false ,
net_settings : Default ::default ( ) ,
dapps_conf : Default ::default ( ) ,
2017-02-16 14:41:33 +01:00
ipfs_conf : Default ::default ( ) ,
2017-05-24 12:24:07 +02:00
ui_conf : Default ::default ( ) ,
2017-02-20 16:13:21 +01:00
secretstore_conf : Default ::default ( ) ,
2016-07-25 16:09:47 +02:00
ui : false ,
2017-01-06 16:05:58 +01:00
dapp : None ,
2016-07-25 16:09:47 +02:00
name : " " . into ( ) ,
custom_bootnodes : false ,
2016-10-03 11:13:10 +02:00
fat_db : Default ::default ( ) ,
2016-09-02 20:24:59 +02:00
no_periodic_snapshot : false ,
2017-01-25 11:03:36 +01:00
stratum : None ,
2016-10-24 15:09:13 +02:00
check_seal : true ,
2016-11-22 18:03:35 +01:00
download_old_blocks : true ,
2016-12-02 18:36:00 +01:00
verifier_settings : Default ::default ( ) ,
2017-03-22 16:45:50 +01:00
serve_light : true ,
light : false ,
2017-05-04 12:13:50 +02:00
no_persistent_txqueue : false ,
2017-02-20 16:13:21 +01:00
} ;
expected . secretstore_conf . enabled = cfg! ( feature = " secretstore " ) ;
assert_eq! ( conf . into_command ( ) . unwrap ( ) . cmd , Cmd ::Run ( expected ) ) ;
2016-07-25 16:09:47 +02:00
}
2016-10-15 14:46:33 +02:00
#[ test ]
fn should_parse_mining_options ( ) {
// given
let mut mining_options = MinerOptions ::default ( ) ;
// when
let conf0 = parse ( & [ " parity " ] ) ;
let conf1 = parse ( & [ " parity " , " --tx-queue-strategy " , " gas_factor " ] ) ;
let conf2 = parse ( & [ " parity " , " --tx-queue-strategy " , " gas_price " ] ) ;
let conf3 = parse ( & [ " parity " , " --tx-queue-strategy " , " gas " ] ) ;
// then
2017-02-24 17:36:52 +01:00
let min_period = conf0 . args . flag_reseal_min_period ;
assert_eq! ( conf0 . miner_options ( min_period ) . unwrap ( ) , mining_options ) ;
2016-10-15 14:46:33 +02:00
mining_options . tx_queue_strategy = PrioritizationStrategy ::GasFactorAndGasPrice ;
2017-02-24 17:36:52 +01:00
assert_eq! ( conf1 . miner_options ( min_period ) . unwrap ( ) , mining_options ) ;
2016-10-15 14:46:33 +02:00
mining_options . tx_queue_strategy = PrioritizationStrategy ::GasPriceOnly ;
2017-02-24 17:36:52 +01:00
assert_eq! ( conf2 . miner_options ( min_period ) . unwrap ( ) , mining_options ) ;
2016-10-15 14:46:33 +02:00
mining_options . tx_queue_strategy = PrioritizationStrategy ::GasAndGasPrice ;
2017-02-24 17:36:52 +01:00
assert_eq! ( conf3 . miner_options ( min_period ) . unwrap ( ) , mining_options ) ;
2016-10-15 14:46:33 +02:00
}
2017-07-01 17:20:49 +02:00
#[ test ]
fn should_fail_on_force_reseal_and_reseal_min_period ( ) {
let conf = parse ( & [ " parity " , " --chain " , " dev " , " --force-sealing " ] ) ;
assert! ( conf . miner_options ( 0 ) . is_err ( ) ) ;
}
2016-11-23 20:35:21 +01:00
#[ test ]
fn should_parse_updater_options ( ) {
// when
2016-12-15 19:17:44 +01:00
let conf0 = parse ( & [ " parity " , " --release-track=testing " ] ) ;
2016-12-11 16:52:41 +01:00
let conf1 = parse ( & [ " parity " , " --auto-update " , " all " , " --no-consensus " ] ) ;
2016-12-15 19:19:50 +01:00
let conf2 = parse ( & [ " parity " , " --no-download " , " --auto-update=all " , " --release-track=beta " ] ) ;
let conf3 = parse ( & [ " parity " , " --auto-update=xxx " ] ) ;
2016-11-23 20:35:21 +01:00
// then
2016-12-15 19:53:13 +01:00
assert_eq! ( conf0 . update_policy ( ) . unwrap ( ) , UpdatePolicy { enable_downloading : true , require_consensus : true , filter : UpdateFilter ::Critical , track : ReleaseTrack ::Testing , path : default_hypervisor_path ( ) } ) ;
assert_eq! ( conf1 . update_policy ( ) . unwrap ( ) , UpdatePolicy { enable_downloading : true , require_consensus : false , filter : UpdateFilter ::All , track : ReleaseTrack ::Unknown , path : default_hypervisor_path ( ) } ) ;
assert_eq! ( conf2 . update_policy ( ) . unwrap ( ) , UpdatePolicy { enable_downloading : false , require_consensus : true , filter : UpdateFilter ::All , track : ReleaseTrack ::Beta , path : default_hypervisor_path ( ) } ) ;
2016-11-23 20:35:21 +01:00
assert! ( conf3 . update_policy ( ) . is_err ( ) ) ;
}
2016-04-30 19:58:28 +02:00
#[ test ]
fn should_parse_network_settings ( ) {
// given
// when
let conf = parse ( & [ " parity " , " --testnet " , " --identity " , " testname " ] ) ;
// then
2017-05-23 12:24:32 +02:00
assert_eq! ( conf . network_settings ( ) , Ok ( NetworkSettings {
2016-04-30 19:58:28 +02:00
name : " testname " . to_owned ( ) ,
2017-03-02 20:24:27 +01:00
chain : " testnet " . to_owned ( ) ,
2016-04-30 19:58:28 +02:00
network_port : 30303 ,
2016-05-04 22:09:30 +02:00
rpc_enabled : true ,
2017-05-23 12:24:32 +02:00
rpc_interface : " 127.0.0.1 " . to_owned ( ) ,
2016-04-30 19:58:28 +02:00
rpc_port : 8545 ,
2017-05-23 12:24:32 +02:00
} ) ) ;
2016-04-30 19:58:28 +02:00
}
#[ test ]
fn should_parse_rpc_settings_with_geth_compatiblity ( ) {
// given
fn assert ( conf : Configuration ) {
2017-05-23 12:24:32 +02:00
let net = conf . network_settings ( ) . unwrap ( ) ;
2016-04-30 19:58:28 +02:00
assert_eq! ( net . rpc_enabled , true ) ;
2017-05-23 12:24:32 +02:00
assert_eq! ( net . rpc_interface , " 0.0.0.0 " . to_owned ( ) ) ;
2016-04-30 19:58:28 +02:00
assert_eq! ( net . rpc_port , 8000 ) ;
2016-07-20 12:34:17 +02:00
assert_eq! ( conf . rpc_cors ( ) , Some ( vec! [ " * " . to_owned ( ) ] ) ) ;
2016-04-30 19:58:28 +02:00
assert_eq! ( conf . rpc_apis ( ) , " web3,eth " . to_owned ( ) ) ;
}
// when
let conf1 = parse ( & [ " parity " , " -j " ,
" --jsonrpc-port " , " 8000 " ,
" --jsonrpc-interface " , " all " ,
" --jsonrpc-cors " , " * " ,
" --jsonrpc-apis " , " web3,eth "
] ) ;
let conf2 = parse ( & [ " parity " , " --rpc " ,
" --rpcport " , " 8000 " ,
" --rpcaddr " , " all " ,
" --rpccorsdomain " , " * " ,
" --rpcapi " , " web3,eth "
] ) ;
// then
assert ( conf1 ) ;
assert ( conf2 ) ;
}
2016-07-20 12:34:17 +02:00
#[ test ]
fn should_parse_rpc_hosts ( ) {
// given
// when
let conf0 = parse ( & [ " parity " ] ) ;
let conf1 = parse ( & [ " parity " , " --jsonrpc-hosts " , " none " ] ) ;
let conf2 = parse ( & [ " parity " , " --jsonrpc-hosts " , " all " ] ) ;
2017-05-02 11:41:09 +02:00
let conf3 = parse ( & [ " parity " , " --jsonrpc-hosts " , " parity.io,something.io " ] ) ;
2016-07-20 12:34:17 +02:00
// then
assert_eq! ( conf0 . rpc_hosts ( ) , Some ( Vec ::new ( ) ) ) ;
assert_eq! ( conf1 . rpc_hosts ( ) , Some ( Vec ::new ( ) ) ) ;
assert_eq! ( conf2 . rpc_hosts ( ) , None ) ;
2017-05-02 11:41:09 +02:00
assert_eq! ( conf3 . rpc_hosts ( ) , Some ( vec! [ " parity.io " . into ( ) , " something.io " . into ( ) ] ) ) ;
2016-07-20 12:34:17 +02:00
}
2016-07-22 14:47:31 +02:00
2017-02-24 10:32:42 +01:00
#[ test ]
fn should_parse_ipfs_hosts ( ) {
// given
// when
let conf0 = parse ( & [ " parity " ] ) ;
let conf1 = parse ( & [ " parity " , " --ipfs-api-hosts " , " none " ] ) ;
let conf2 = parse ( & [ " parity " , " --ipfs-api-hosts " , " all " ] ) ;
2017-05-02 11:41:09 +02:00
let conf3 = parse ( & [ " parity " , " --ipfs-api-hosts " , " parity.io,something.io " ] ) ;
2017-02-24 10:32:42 +01:00
// then
assert_eq! ( conf0 . ipfs_hosts ( ) , Some ( Vec ::new ( ) ) ) ;
assert_eq! ( conf1 . ipfs_hosts ( ) , Some ( Vec ::new ( ) ) ) ;
assert_eq! ( conf2 . ipfs_hosts ( ) , None ) ;
2017-05-02 11:41:09 +02:00
assert_eq! ( conf3 . ipfs_hosts ( ) , Some ( vec! [ " parity.io " . into ( ) , " something.io " . into ( ) ] ) ) ;
2017-02-24 10:32:42 +01:00
}
#[ test ]
fn should_parse_ipfs_cors ( ) {
// given
// when
let conf0 = parse ( & [ " parity " ] ) ;
let conf1 = parse ( & [ " parity " , " --ipfs-api-cors " , " * " ] ) ;
2017-05-02 11:41:09 +02:00
let conf2 = parse ( & [ " parity " , " --ipfs-api-cors " , " http://parity.io,http://something.io " ] ) ;
2017-02-24 10:32:42 +01:00
// then
assert_eq! ( conf0 . ipfs_cors ( ) , None ) ;
assert_eq! ( conf1 . ipfs_cors ( ) , Some ( vec! [ " * " . into ( ) ] ) ) ;
2017-05-02 11:41:09 +02:00
assert_eq! ( conf2 . ipfs_cors ( ) , Some ( vec! [ " http://parity.io " . into ( ) , " http://something.io " . into ( ) ] ) ) ;
2017-02-24 10:32:42 +01:00
}
2016-07-22 14:47:31 +02:00
#[ test ]
fn should_disable_signer_in_geth_compat ( ) {
// given
// when
let conf0 = parse ( & [ " parity " , " --geth " ] ) ;
2016-11-07 17:40:53 +01:00
let conf1 = parse ( & [ " parity " , " --geth " , " --force-ui " ] ) ;
2016-07-22 14:47:31 +02:00
// then
2016-11-07 17:40:53 +01:00
assert_eq! ( conf0 . ui_enabled ( ) , false ) ;
assert_eq! ( conf1 . ui_enabled ( ) , true ) ;
2016-07-22 14:47:31 +02:00
}
#[ test ]
fn should_disable_signer_when_account_is_unlocked ( ) {
// given
// when
let conf0 = parse ( & [ " parity " , " --unlock " , " 0x0 " ] ) ;
// then
2016-11-07 17:40:53 +01:00
assert_eq! ( conf0 . ui_enabled ( ) , false ) ;
2016-07-22 14:47:31 +02:00
}
2016-07-29 10:48:05 +02:00
2016-08-02 18:53:53 +02:00
#[ test ]
2017-05-24 12:24:07 +02:00
fn should_parse_ui_configuration ( ) {
2016-08-02 18:53:53 +02:00
// given
// when
2016-11-07 17:40:53 +01:00
let conf0 = parse ( & [ " parity " , " --ui-path " , " signer " ] ) ;
let conf1 = parse ( & [ " parity " , " --ui-path " , " signer " , " --ui-no-validation " ] ) ;
let conf2 = parse ( & [ " parity " , " --ui-path " , " signer " , " --ui-port " , " 3123 " ] ) ;
let conf3 = parse ( & [ " parity " , " --ui-path " , " signer " , " --ui-interface " , " test " ] ) ;
2016-08-02 18:53:53 +02:00
// then
2017-05-24 12:24:07 +02:00
assert_eq! ( conf0 . directories ( ) . signer , " signer " . to_owned ( ) ) ;
assert_eq! ( conf0 . ui_config ( ) , UiConfiguration {
2016-08-23 16:53:24 +02:00
enabled : true ,
2017-07-27 18:46:09 +02:00
ntp_server : " none " . into ( ) ,
2016-08-23 16:53:24 +02:00
interface : " 127.0.0.1 " . into ( ) ,
2017-05-24 12:24:07 +02:00
port : 8180 ,
hosts : Some ( vec! [ ] ) ,
2016-08-23 16:53:24 +02:00
} ) ;
2017-06-04 12:34:03 +02:00
assert! ( conf0 . ws_config ( ) . unwrap ( ) . hosts . is_some ( ) ) ;
2017-05-24 12:24:07 +02:00
assert_eq! ( conf1 . directories ( ) . signer , " signer " . to_owned ( ) ) ;
assert_eq! ( conf1 . ui_config ( ) , UiConfiguration {
2016-08-23 16:53:24 +02:00
enabled : true ,
2017-07-27 18:46:09 +02:00
ntp_server : " none " . into ( ) ,
2016-08-23 16:53:24 +02:00
interface : " 127.0.0.1 " . into ( ) ,
2017-05-24 12:24:07 +02:00
port : 8180 ,
2017-06-04 12:34:03 +02:00
hosts : Some ( vec! [ ] ) ,
2016-08-23 16:53:24 +02:00
} ) ;
2017-07-11 13:45:23 +02:00
assert_eq! ( conf1 . dapps_config ( ) . extra_embed_on , vec! [ ( " localhost " . to_owned ( ) , 3000 ) ] ) ;
2017-07-11 14:49:35 +02:00
assert_eq! ( conf1 . ws_config ( ) . unwrap ( ) . origins , None ) ;
2017-05-24 12:24:07 +02:00
assert_eq! ( conf2 . directories ( ) . signer , " signer " . to_owned ( ) ) ;
assert_eq! ( conf2 . ui_config ( ) , UiConfiguration {
2016-08-23 16:53:24 +02:00
enabled : true ,
2017-07-27 18:46:09 +02:00
ntp_server : " none " . into ( ) ,
2016-08-23 16:53:24 +02:00
interface : " 127.0.0.1 " . into ( ) ,
2017-05-24 12:24:07 +02:00
port : 3123 ,
hosts : Some ( vec! [ ] ) ,
2016-08-23 16:53:24 +02:00
} ) ;
2017-06-04 12:34:03 +02:00
assert! ( conf2 . ws_config ( ) . unwrap ( ) . hosts . is_some ( ) ) ;
2017-05-24 12:24:07 +02:00
assert_eq! ( conf3 . directories ( ) . signer , " signer " . to_owned ( ) ) ;
assert_eq! ( conf3 . ui_config ( ) , UiConfiguration {
2016-08-23 16:53:24 +02:00
enabled : true ,
2017-07-27 18:46:09 +02:00
ntp_server : " none " . into ( ) ,
2016-08-23 16:53:24 +02:00
interface : " test " . into ( ) ,
2017-05-24 12:24:07 +02:00
port : 8180 ,
hosts : Some ( vec! [ ] ) ,
2016-08-23 16:53:24 +02:00
} ) ;
2017-06-04 12:34:03 +02:00
assert! ( conf3 . ws_config ( ) . unwrap ( ) . hosts . is_some ( ) ) ;
2016-08-02 18:53:53 +02:00
}
2017-01-06 16:05:58 +01:00
#[ test ]
fn should_parse_dapp_opening ( ) {
// given
let temp = RandomTempPath ::new ( ) ;
let name = temp . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
create_dir ( temp . as_str ( ) . to_owned ( ) ) . unwrap ( ) ;
// when
let conf0 = parse ( & [ " parity " , " dapp " , temp . to_str ( ) . unwrap ( ) ] ) ;
// then
assert_eq! ( conf0 . dapp_to_open ( ) , Ok ( Some ( name . into ( ) ) ) ) ;
let extra_dapps = conf0 . dapps_config ( ) . extra_dapps ;
assert_eq! ( extra_dapps , vec! [ temp . to_owned ( ) ] ) ;
}
2016-07-29 10:48:05 +02:00
#[ test ]
fn should_not_bail_on_empty_line_in_reserved_peers ( ) {
let temp = RandomTempPath ::new ( ) ;
create_dir ( temp . as_str ( ) . to_owned ( ) ) . unwrap ( ) ;
let filename = temp . as_str ( ) . to_owned ( ) + " /peers " ;
File ::create ( filename . clone ( ) ) . unwrap ( ) . write_all ( b " \n \t \n " ) . unwrap ( ) ;
let args = vec! [ " parity " , " --reserved-peers " , & filename ] ;
2017-03-13 12:10:53 +01:00
let conf = Configuration ::parse ( & args , None ) . unwrap ( ) ;
2016-07-29 10:48:05 +02:00
assert! ( conf . init_reserved_nodes ( ) . is_ok ( ) ) ;
}
2017-02-24 17:36:52 +01:00
2017-07-10 13:24:40 +02:00
#[ test ]
fn should_ignore_comments_in_reserved_peers ( ) {
let temp = RandomTempPath ::new ( ) ;
create_dir ( temp . as_str ( ) . to_owned ( ) ) . unwrap ( ) ;
let filename = temp . as_str ( ) . to_owned ( ) + " /peers_comments " ;
File ::create ( filename . clone ( ) ) . unwrap ( ) . write_all ( b " # Sample comment \n enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@172.0.0.1:30303 \n " ) . unwrap ( ) ;
let args = vec! [ " parity " , " --reserved-peers " , & filename ] ;
let conf = Configuration ::parse ( & args , None ) . unwrap ( ) ;
let reserved_nodes = conf . init_reserved_nodes ( ) ;
assert! ( reserved_nodes . is_ok ( ) ) ;
assert_eq! ( reserved_nodes . unwrap ( ) . len ( ) , 1 ) ;
}
2017-02-24 17:36:52 +01:00
#[ test ]
fn test_dev_chain ( ) {
let args = vec! [ " parity " , " --chain " , " dev " ] ;
let conf = parse ( & args ) ;
match conf . into_command ( ) . unwrap ( ) . cmd {
Cmd ::Run ( c ) = > {
assert_eq! ( c . gas_pricer , GasPricerConfig ::Fixed ( 0. into ( ) ) ) ;
assert_eq! ( c . miner_options . reseal_min_period , Duration ::from_millis ( 0 ) ) ;
} ,
_ = > panic! ( " Should be Cmd::Run " ) ,
}
}
2017-05-23 12:24:32 +02:00
#[ test ]
fn should_apply_ports_shift ( ) {
// given
// when
let conf0 = parse ( & [ " parity " , " --ports-shift " , " 1 " , " --stratum " ] ) ;
let conf1 = parse ( & [ " parity " , " --ports-shift " , " 1 " , " --jsonrpc-port " , " 8544 " ] ) ;
// then
assert_eq! ( conf0 . net_addresses ( ) . unwrap ( ) . 0. port ( ) , 30304 ) ;
assert_eq! ( conf0 . network_settings ( ) . unwrap ( ) . network_port , 30304 ) ;
assert_eq! ( conf0 . network_settings ( ) . unwrap ( ) . rpc_port , 8546 ) ;
assert_eq! ( conf0 . http_config ( ) . unwrap ( ) . port , 8546 ) ;
assert_eq! ( conf0 . ws_config ( ) . unwrap ( ) . port , 8547 ) ;
2017-05-24 12:24:07 +02:00
assert_eq! ( conf0 . ui_config ( ) . port , 8181 ) ;
2017-05-23 12:24:32 +02:00
assert_eq! ( conf0 . secretstore_config ( ) . unwrap ( ) . port , 8084 ) ;
assert_eq! ( conf0 . secretstore_config ( ) . unwrap ( ) . http_port , 8083 ) ;
assert_eq! ( conf0 . ipfs_config ( ) . port , 5002 ) ;
assert_eq! ( conf0 . stratum_options ( ) . unwrap ( ) . unwrap ( ) . port , 8009 ) ;
assert_eq! ( conf1 . net_addresses ( ) . unwrap ( ) . 0. port ( ) , 30304 ) ;
assert_eq! ( conf1 . network_settings ( ) . unwrap ( ) . network_port , 30304 ) ;
assert_eq! ( conf1 . network_settings ( ) . unwrap ( ) . rpc_port , 8545 ) ;
assert_eq! ( conf1 . http_config ( ) . unwrap ( ) . port , 8545 ) ;
assert_eq! ( conf1 . ws_config ( ) . unwrap ( ) . port , 8547 ) ;
2017-05-24 12:24:07 +02:00
assert_eq! ( conf1 . ui_config ( ) . port , 8181 ) ;
2017-05-23 12:24:32 +02:00
assert_eq! ( conf1 . secretstore_config ( ) . unwrap ( ) . port , 8084 ) ;
assert_eq! ( conf1 . secretstore_config ( ) . unwrap ( ) . http_port , 8083 ) ;
assert_eq! ( conf1 . ipfs_config ( ) . port , 5002 ) ;
}
#[ test ]
fn should_expose_all_servers ( ) {
// given
// when
let conf0 = parse ( & [ " parity " , " --unsafe-expose " ] ) ;
// then
assert_eq! ( & conf0 . network_settings ( ) . unwrap ( ) . rpc_interface , " 0.0.0.0 " ) ;
assert_eq! ( & conf0 . http_config ( ) . unwrap ( ) . interface , " 0.0.0.0 " ) ;
assert_eq! ( conf0 . http_config ( ) . unwrap ( ) . hosts , None ) ;
assert_eq! ( & conf0 . ws_config ( ) . unwrap ( ) . interface , " 0.0.0.0 " ) ;
assert_eq! ( conf0 . ws_config ( ) . unwrap ( ) . hosts , None ) ;
2017-06-03 14:41:42 +02:00
assert_eq! ( conf0 . ws_config ( ) . unwrap ( ) . origins , None ) ;
2017-05-24 12:24:07 +02:00
assert_eq! ( & conf0 . ui_config ( ) . interface , " 0.0.0.0 " ) ;
assert_eq! ( conf0 . ui_config ( ) . hosts , None ) ;
2017-05-23 12:24:32 +02:00
assert_eq! ( & conf0 . secretstore_config ( ) . unwrap ( ) . interface , " 0.0.0.0 " ) ;
assert_eq! ( & conf0 . secretstore_config ( ) . unwrap ( ) . http_interface , " 0.0.0.0 " ) ;
assert_eq! ( & conf0 . ipfs_config ( ) . interface , " 0.0.0.0 " ) ;
assert_eq! ( conf0 . ipfs_config ( ) . hosts , None ) ;
}
2016-04-30 19:58:28 +02:00
}