use crate::cmd::wallet_args;
use crate::config::GlobalWalletConfig;
use clap::ArgMatches;
use grin_wallet_libwallet::NodeClient;
use semver::Version;
use std::thread;
use std::time::Duration;
const MIN_COMPAT_NODE_VERSION: &str = "4.0.0-alpha.1";
pub fn wallet_command<C>(
wallet_args: &ArgMatches<'_>,
config: GlobalWalletConfig,
mut node_client: C,
) -> i32
where
C: NodeClient + 'static,
{
let wallet_config = config.members.clone().unwrap().wallet;
let tor_config = config.members.unwrap().tor;
let global_wallet_args = wallet_args::parse_global_args(&wallet_config, &wallet_args)
.expect("Can't read configuration file");
node_client.set_node_api_secret(global_wallet_args.node_api_secret.clone());
if let Some(v) = node_client.clone().get_version_info() {
if Version::parse(&v.node_version) < Version::parse(MIN_COMPAT_NODE_VERSION) {
println!("The Grin Node in use (version {}) is outdated and incompatible with this wallet version.", v.node_version);
println!(
"Please update the node to version {} or later and try again.",
MIN_COMPAT_NODE_VERSION
);
return 1;
}
}
let res = wallet_args::wallet_command(
wallet_args,
wallet_config,
tor_config,
node_client,
false,
|_| {},
);
thread::sleep(Duration::from_millis(100));
if let Err(e) = res {
println!("Wallet command failed: {}", e);
1
} else {
println!(
"Command '{}' completed successfully",
wallet_args.subcommand().0
);
0
}
}