Use info! for blockchain status rather than stdout.

This commit is contained in:
Gav Wood 2016-12-16 11:00:17 +01:00
parent 396ab5b361
commit 90d3d330f5
No known key found for this signature in database
GPG Key ID: C49C1ACA1CC9B252
2 changed files with 15 additions and 11 deletions

View File

@ -133,7 +133,7 @@ pub struct ExportState {
pub max_balance: Option<U256>,
}
pub fn execute(cmd: BlockchainCmd) -> Result<String, String> {
pub fn execute(cmd: BlockchainCmd) -> Result<(), String> {
match cmd {
BlockchainCmd::Kill(kill_cmd) => kill_db(kill_cmd),
BlockchainCmd::Import(import_cmd) => execute_import(import_cmd),
@ -142,7 +142,7 @@ pub fn execute(cmd: BlockchainCmd) -> Result<String, String> {
}
}
fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
fn execute_import(cmd: ImportBlockchain) -> Result<(), String> {
let timer = Instant::now();
// Setup panic handler
@ -293,7 +293,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
let report = client.report();
let ms = timer.elapsed().as_milliseconds();
Ok(format!("Import completed in {} seconds, {} blocks, {} blk/s, {} transactions, {} tx/s, {} Mgas, {} Mgas/s",
info!("Import completed in {} seconds, {} blocks, {} blk/s, {} transactions, {} tx/s, {} Mgas, {} Mgas/s",
ms / 1000,
report.blocks_imported,
(report.blocks_imported * 1000) as u64 / ms,
@ -301,7 +301,8 @@ fn execute_import(cmd: ImportBlockchain) -> Result<String, String> {
(report.transactions_applied * 1000) as u64 / ms,
report.gas_processed / From::from(1_000_000),
(report.gas_processed / From::from(ms * 1000)).low_u64(),
).into())
);
Ok(())
}
fn start_client(
@ -368,7 +369,7 @@ fn start_client(
Ok(service)
}
fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
fn execute_export(cmd: ExportBlockchain) -> Result<(), String> {
// Setup panic handler
let service = try!(start_client(cmd.dirs, cmd.spec, cmd.pruning, cmd.pruning_history, cmd.tracing, cmd.fat_db, cmd.compaction, cmd.wal, cmd.cache_config));
let panic_handler = PanicHandler::new_in_arc();
@ -396,10 +397,11 @@ fn execute_export(cmd: ExportBlockchain) -> Result<String, String> {
}
}
Ok("Export completed.".into())
info!("Export completed.");
Ok(())
}
fn execute_export_state(cmd: ExportState) -> Result<String, String> {
fn execute_export_state(cmd: ExportState) -> Result<(), String> {
// Setup panic handler
let service = try!(start_client(cmd.dirs, cmd.spec, cmd.pruning, cmd.pruning_history, cmd.tracing, cmd.fat_db, cmd.compaction, cmd.wal, cmd.cache_config));
let panic_handler = PanicHandler::new_in_arc();
@ -475,10 +477,11 @@ fn execute_export_state(cmd: ExportState) -> Result<String, String> {
}
}
out.write_fmt(format_args!("\n]}}")).expect("Write error");
Ok("Export completed.".into())
info!("Export completed.");
Ok(())
}
pub fn kill_db(cmd: KillBlockchain) -> Result<String, String> {
pub fn kill_db(cmd: KillBlockchain) -> Result<(), String> {
let spec = try!(cmd.spec.spec());
let genesis_hash = spec.genesis_header().hash();
let db_dirs = cmd.dirs.database(genesis_hash, None, spec.data_dir);
@ -487,7 +490,8 @@ pub fn kill_db(cmd: KillBlockchain) -> Result<String, String> {
let algorithm = cmd.pruning.to_algorithm(&user_defaults);
let dir = db_dirs.db_path(algorithm);
try!(fs::remove_dir_all(&dir).map_err(|e| format!("Error removing database: {:?}", e)));
Ok("Database deleted.".to_owned())
info!("Database deleted.");
Ok(())
}
#[cfg(test)]

View File

@ -156,7 +156,7 @@ fn execute(command: Execute, can_restart: bool) -> Result<PostExecutionAction, S
Cmd::Hash(maybe_file) => print_hash_of(maybe_file).map(|s| PostExecutionAction::Print(s)),
Cmd::Account(account_cmd) => account::execute(account_cmd).map(|s| PostExecutionAction::Print(s)),
Cmd::ImportPresaleWallet(presale_cmd) => presale::execute(presale_cmd).map(|s| PostExecutionAction::Print(s)),
Cmd::Blockchain(blockchain_cmd) => blockchain::execute(blockchain_cmd).map(|s| PostExecutionAction::Print(s)),
Cmd::Blockchain(blockchain_cmd) => blockchain::execute(blockchain_cmd).map(|_| PostExecutionAction::Quit),
Cmd::SignerToken(signer_cmd) => signer::execute(signer_cmd).map(|s| PostExecutionAction::Print(s)),
Cmd::SignerSign { id, pwfile, port, authfile } => rpc_cli::signer_sign(id, pwfile, port, authfile).map(|s| PostExecutionAction::Print(s)),
Cmd::SignerList { port, authfile } => rpc_cli::signer_list(port, authfile).map(|s| PostExecutionAction::Print(s)),