mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 11:31:08 +03:00
User experience ux1 (#610)
* better error messages when `wallet restore` fails * wallet info: show height, and where we got the height number from * make "grin wallet listen" show some more lifesigns, so users can know it's running fine
This commit is contained in:
parent
bff92128e7
commit
40bc3386d5
3 changed files with 21 additions and 20 deletions
|
@ -17,19 +17,17 @@ use keychain::Keychain;
|
||||||
use core::core::amount_to_hr_string;
|
use core::core::amount_to_hr_string;
|
||||||
use types::{WalletConfig, WalletData, OutputStatus};
|
use types::{WalletConfig, WalletData, OutputStatus};
|
||||||
use prettytable;
|
use prettytable;
|
||||||
use term;
|
|
||||||
use std::io::prelude::*;
|
|
||||||
|
|
||||||
pub fn show_info(config: &WalletConfig, keychain: &Keychain) {
|
pub fn show_info(config: &WalletConfig, keychain: &Keychain) {
|
||||||
let result = checker::refresh_outputs(&config, &keychain);
|
let result = checker::refresh_outputs(&config, &keychain);
|
||||||
|
|
||||||
|
|
||||||
let _ = WalletData::read_wallet(&config.data_file_dir, |wallet_data| {
|
let _ = WalletData::read_wallet(&config.data_file_dir, |wallet_data| {
|
||||||
let current_height = match checker::get_tip_from_node(config) {
|
let (current_height, from) = match checker::get_tip_from_node(config) {
|
||||||
Ok(tip) => tip.height,
|
Ok(tip) => (tip.height, "from server node"),
|
||||||
Err(_) => match wallet_data.outputs.values().map(|out| out.height).max() {
|
Err(_) => match wallet_data.outputs.values().map(|out| out.height).max() {
|
||||||
Some(height) => height,
|
Some(height) => (height, "from wallet"),
|
||||||
None => 0,
|
None => (0, "node/wallet unavailable"),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let mut unspent_total=0;
|
let mut unspent_total=0;
|
||||||
|
@ -55,15 +53,7 @@ pub fn show_info(config: &WalletConfig, keychain: &Keychain) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
println!("\n____ Wallet Summary Info at {} ({}) ____\n", current_height, from);
|
||||||
println!();
|
|
||||||
let title=format!("Wallet Summary Info - Block Height: {}", current_height);
|
|
||||||
let mut t = term::stdout().unwrap();
|
|
||||||
t.fg(term::color::MAGENTA).unwrap();
|
|
||||||
writeln!(t, "{}", title).unwrap();
|
|
||||||
writeln!(t, "--------------------------").unwrap();
|
|
||||||
t.reset().unwrap();
|
|
||||||
|
|
||||||
let mut table = table!(
|
let mut table = table!(
|
||||||
[bFG->"Total", FG->amount_to_hr_string(unspent_total+unconfirmed_total)],
|
[bFG->"Total", FG->amount_to_hr_string(unspent_total+unconfirmed_total)],
|
||||||
[bFY->"Awaiting Confirmation", FY->amount_to_hr_string(unconfirmed_total)],
|
[bFY->"Awaiting Confirmation", FY->amount_to_hr_string(unconfirmed_total)],
|
||||||
|
|
|
@ -28,7 +28,12 @@ pub fn get_chain_height(config: &WalletConfig) -> Result<u64, Error> {
|
||||||
Ok(tip) => Ok(tip.height),
|
Ok(tip) => Ok(tip.height),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// if we got anything other than 200 back from server, bye
|
// if we got anything other than 200 back from server, bye
|
||||||
error!(LOGGER, "Restore failed... unable to contact node: {}", e);
|
error!(
|
||||||
|
LOGGER,
|
||||||
|
"get_chain_height: Restore failed... unable to contact API {}. Error: {}",
|
||||||
|
config.check_node_api_http_addr,
|
||||||
|
e
|
||||||
|
);
|
||||||
Err(Error::Node(e))
|
Err(Error::Node(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +111,12 @@ pub fn utxos_batch_block(
|
||||||
Ok(outputs) => Ok(outputs),
|
Ok(outputs) => Ok(outputs),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// if we got anything other than 200 back from server, bye
|
// if we got anything other than 200 back from server, bye
|
||||||
error!(LOGGER, "Restore failed... unable to contact node: {}", e);
|
error!(
|
||||||
|
LOGGER,
|
||||||
|
"utxos_batch_block: Restore failed... unable to contact API {}. Error: {}",
|
||||||
|
config.check_node_api_http_addr,
|
||||||
|
e
|
||||||
|
);
|
||||||
Err(Error::Node(e))
|
Err(Error::Node(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,8 @@ pub fn start_rest_apis(wallet_config: WalletConfig, keychain: Keychain) {
|
||||||
|
|
||||||
let mut apis = ApiServer::new("/v1".to_string());
|
let mut apis = ApiServer::new("/v1".to_string());
|
||||||
apis.register_handler(router);
|
apis.register_handler(router);
|
||||||
apis.start(wallet_config.api_listen_addr()).unwrap_or_else(|e| {
|
match apis.start(wallet_config.api_listen_addr()) {
|
||||||
error!(LOGGER, "Failed to start Grin wallet receiver: {}.", e);
|
Err(e) => error!(LOGGER, "Failed to start Grin wallet listener: {}.", e),
|
||||||
});
|
Ok(_) => info!(LOGGER, "Wallet listener started"),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue