Wallet command exit status on error (#1253)

This commit is contained in:
Ignotus Peverell 2018-07-12 20:05:43 +01:00 committed by GitHub
parent bdfd5405c0
commit 12a2fc4f5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -659,143 +659,145 @@ fn wallet_command(wallet_args: &ArgMatches, global_config: GlobalConfig) {
} }
// Handle single-use (command line) owner commands // Handle single-use (command line) owner commands
{ let wallet = Arc::new(Mutex::new(instantiate_wallet(
let wallet = Arc::new(Mutex::new(instantiate_wallet( wallet_config.clone(),
wallet_config.clone(), passphrase,
passphrase, use_db,
use_db, )));
))); let res = wallet::controller::owner_single_use(wallet, |api| {
let _res = wallet::controller::owner_single_use(wallet, |api| { match wallet_args.subcommand() {
match wallet_args.subcommand() { ("send", Some(send_args)) => {
("send", Some(send_args)) => { let amount = send_args
let amount = send_args .value_of("amount")
.value_of("amount") .expect("Amount to send required");
.expect("Amount to send required"); let amount = core::core::amount_from_hr_string(amount)
let amount = core::core::amount_from_hr_string(amount) .expect("Could not parse amount as a number with optional decimal point.");
.expect("Could not parse amount as a number with optional decimal point."); let minimum_confirmations: u64 = send_args
let minimum_confirmations: u64 = send_args .value_of("minimum_confirmations")
.value_of("minimum_confirmations") .unwrap()
.unwrap() .parse()
.parse() .expect("Could not parse minimum_confirmations as a whole number.");
.expect("Could not parse minimum_confirmations as a whole number."); let selection_strategy = send_args
let selection_strategy = send_args .value_of("selection_strategy")
.value_of("selection_strategy") .expect("Selection strategy required");
.expect("Selection strategy required"); let dest = send_args
let dest = send_args .value_of("dest")
.value_of("dest") .expect("Destination wallet address required");
.expect("Destination wallet address required"); let mut fluff = false;
let mut fluff = false; if send_args.is_present("fluff") {
if send_args.is_present("fluff") { fluff = true;
fluff = true; }
} let max_outputs = 500;
let max_outputs = 500; let result = api.issue_send_tx(
let result = api.issue_send_tx( amount,
amount, minimum_confirmations,
minimum_confirmations, dest,
dest, max_outputs,
max_outputs, selection_strategy == "all",
selection_strategy == "all",
); );
let slate = match result { let slate = match result {
Ok(s) => { Ok(s) => {
info!( info!(
LOGGER, LOGGER,
"Tx created: {} grin to {} (strategy '{}')", "Tx created: {} grin to {} (strategy '{}')",
amount_to_hr_string(amount), amount_to_hr_string(amount),
dest, dest,
selection_strategy, selection_strategy,
); );
s s
} }
Err(e) => { Err(e) => {
error!(LOGGER, "Tx not created: {:?}", e); error!(LOGGER, "Tx not created: {:?}", e);
match e.kind() { match e.kind() {
// user errors, don't backtrace // user errors, don't backtrace
libwallet::ErrorKind::NotEnoughFunds { .. } => {} libwallet::ErrorKind::NotEnoughFunds { .. } => {}
libwallet::ErrorKind::FeeDispute { .. } => {} libwallet::ErrorKind::FeeDispute { .. } => {}
libwallet::ErrorKind::FeeExceedsAmount { .. } => {} libwallet::ErrorKind::FeeExceedsAmount { .. } => {}
_ => { _ => {
// otherwise give full dump // otherwise give full dump
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap()); error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
} }
}; };
panic!(); panic!();
} }
}; };
let result = api.post_tx(&slate, fluff); let result = api.post_tx(&slate, fluff);
match result { match result {
Ok(_) => { Ok(_) => {
info!( info!(
LOGGER, LOGGER,
"Tx sent", "Tx sent",
); );
Ok(()) Ok(())
} }
Err(e) => { Err(e) => {
error!(LOGGER, "Tx not sent: {:?}", e); error!(LOGGER, "Tx not sent: {:?}", e);
Err(e) Err(e)
}
} }
} }
("burn", Some(send_args)) => {
let amount = send_args
.value_of("amount")
.expect("Amount to burn required");
let amount = core::core::amount_from_hr_string(amount)
.expect("Could not parse amount as number with optional decimal point.");
let minimum_confirmations: u64 = send_args
.value_of("minimum_confirmations")
.unwrap()
.parse()
.expect("Could not parse minimum_confirmations as a whole number.");
let max_outputs = 500;
api.issue_burn_tx(amount, minimum_confirmations, max_outputs)
.unwrap_or_else(|e| {
panic!("Error burning tx: {:?} Config: {:?}", e, wallet_config)
});
Ok(())
}
("info", Some(_)) => {
let (validated, wallet_info) =
api.retrieve_summary_info(true).unwrap_or_else(|e| {
panic!(
"Error getting wallet info: {:?} Config: {:?}",
e, wallet_config
)
});
wallet::display::info(&wallet_info, validated);
Ok(())
}
("outputs", Some(_)) => {
let (height, validated) = api.node_height()?;
let (_, outputs) = api.retrieve_outputs(show_spent, true)?;
let _res =
wallet::display::outputs(height, validated, outputs).unwrap_or_else(|e| {
panic!(
"Error getting wallet outputs: {:?} Config: {:?}",
e, wallet_config
)
});
Ok(())
}
("restore", Some(_)) => {
let result = api.restore();
match result {
Ok(_) => {
info!(LOGGER, "Wallet restore complete",);
Ok(())
}
Err(e) => {
error!(LOGGER, "Wallet restore failed: {:?}", e);
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
Err(e)
}
}
}
_ => panic!("Unknown wallet command, use 'grin help wallet' for details"),
} }
}); ("burn", Some(send_args)) => {
} let amount = send_args
.value_of("amount")
.expect("Amount to burn required");
let amount = core::core::amount_from_hr_string(amount)
.expect("Could not parse amount as number with optional decimal point.");
let minimum_confirmations: u64 = send_args
.value_of("minimum_confirmations")
.unwrap()
.parse()
.expect("Could not parse minimum_confirmations as a whole number.");
let max_outputs = 500;
api.issue_burn_tx(amount, minimum_confirmations, max_outputs)
.unwrap_or_else(|e| {
panic!("Error burning tx: {:?} Config: {:?}", e, wallet_config)
});
Ok(())
}
("info", Some(_)) => {
let (validated, wallet_info) =
api.retrieve_summary_info(true).unwrap_or_else(|e| {
panic!(
"Error getting wallet info: {:?} Config: {:?}",
e, wallet_config
)
});
wallet::display::info(&wallet_info, validated);
Ok(())
}
("outputs", Some(_)) => {
let (height, validated) = api.node_height()?;
let (_, outputs) = api.retrieve_outputs(show_spent, true)?;
let _res =
wallet::display::outputs(height, validated, outputs).unwrap_or_else(|e| {
panic!(
"Error getting wallet outputs: {:?} Config: {:?}",
e, wallet_config
)
});
Ok(())
}
("restore", Some(_)) => {
let result = api.restore();
match result {
Ok(_) => {
info!(LOGGER, "Wallet restore complete",);
Ok(())
}
Err(e) => {
error!(LOGGER, "Wallet restore failed: {:?}", e);
error!(LOGGER, "Backtrace: {}", e.backtrace().unwrap());
Err(e)
}
}
}
_ => panic!("Unknown wallet command, use 'grin help wallet' for details"),
}
});
// we need to give log output a chance to catch up before exiting // we need to give log output a chance to catch up before exiting
thread::sleep(Duration::from_millis(100)); thread::sleep(Duration::from_millis(100));
if res.is_err() {
exit(1);
}
} }