Merge milestone/2.1.0 into master (#199)

* version bump for next potential release

* Merge master into milestone/2.1.0 (#182)

* Derive --version output dynamically from cargo package version (#174)

* add --txid to the `wallet txs` command (#176)

* add --txid to the `wallet txs` command

* add test for `wallet txs` command with `--txid` parameter

* Refactor - Split WalletCommAdapter into multiple traits (#180)

* Derive --version output dynamically from cargo package version (#174)

* add server auth argument to http client

* Revert "add server auth argument to http client"

This reverts commit f52a8d2c7cdfb8583af5716ad621eb560811d6ee.

* modify WalletCommAdapter, moving dest argument into fields on implementors,
visiting havok on automated tests, at least one of which is now out of date and failing

* Split WalletCommAdapter into four traits, one for each of its intended behaviors.

* Remove two vestigals
1. args, a stringly typed argument to put_tx
2. NullAdapter, which is no longer used

* Remove unused "params" argument from listen method.

* Re-add previously existing TODO comment

* Fix non-test build

* completely Fix non-test build

* Full Lifecycle API Support (#184)

* refactoring wallet lib traits

* rustfmt

* rustfmt

* add new files

* explicit lifetime specifiers on all wallet traits

* rustfmt

* modify apis to use new walletinst

* rustfmt

* converting controller crate

* rustfmt

* controller crate compiling

* rustfmt

* compilation

* rustfmt

* Remove config from wallet, implement open_wallet, close_wallet in lifecycle provider, remove password + open_with_credentials from WalletBackend + impl

* rustfmt

* full compilation, changing recovery + init to new model

* rustfmt

* wallet initialisation working, init command output and flow identical to v2.0.0 wallet

* rustfmt

* fix listener and owner api startup

* rustfmt

* rustfmt

* move encryption test

* rustfmt

* fix api doctests

* rustfmt

* fix for most tests in controller crate

* rustfmt

* fix for check tests in controller crate

* fix main wallet tests

* rustfmt

* add explicit functions to handle mnemonic recovery, fix CLI recovery workflow

* rustfmt

* update keybase adapter to use new wallet format

* rustfmt

* test fix

* remove debug output
This commit is contained in:
Yeastplume
2019-07-29 13:25:03 +01:00
committed by GitHub
parent 7b6d597d39
commit c40e8a915b
54 changed files with 2405 additions and 1942 deletions
-63
View File
@@ -1,63 +0,0 @@
// Copyright 2018 The Grin Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// Grin configuration file output command
use crate::config::{config, GlobalWalletConfig, GRIN_WALLET_DIR};
use crate::core::global;
use std::env;
/// Create a config file in the current directory
pub fn config_command_wallet(chain_type: &global::ChainTypes, file_name: &str) {
let mut default_config = GlobalWalletConfig::for_chain(chain_type);
let current_dir = env::current_dir().unwrap_or_else(|e| {
panic!("Error creating config file: {}", e);
});
let mut config_file_name = current_dir.clone();
config_file_name.push(file_name);
let mut data_dir_name = current_dir.clone();
data_dir_name.push(GRIN_WALLET_DIR);
if config_file_name.exists() && data_dir_name.exists() {
panic!(
"{} already exists in the target directory. Please remove it first",
file_name
);
}
// just leave as is if file exists but there's no data dir
if config_file_name.exists() {
return;
}
default_config.update_paths(&current_dir);
default_config
.write_to_file(config_file_name.to_str().unwrap())
.unwrap_or_else(|e| {
panic!("Error creating config file: {}", e);
});
println!(
"File {} configured and created",
config_file_name.to_str().unwrap(),
);
let mut api_secret_path = current_dir.clone();
api_secret_path.push(config::API_SECRET_FILE_NAME);
if !api_secret_path.exists() {
config::init_api_secret(&api_secret_path).unwrap();
} else {
config::check_api_secret(&api_secret_path).unwrap();
}
}
+1 -3
View File
@@ -12,10 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
mod config;
mod wallet;
mod wallet_args;
mod wallet_tests;
pub use self::config::config_command_wallet;
pub use self::wallet::{seed_exists, wallet_command};
pub use self::wallet::wallet_command;
+1 -21
View File
@@ -15,34 +15,14 @@
use crate::cmd::wallet_args;
use crate::config::GlobalWalletConfig;
use clap::ArgMatches;
use grin_wallet_config::WalletConfig;
use grin_wallet_impls::{HTTPNodeClient, WalletSeed, SEED_FILE};
use grin_wallet_impls::HTTPNodeClient;
use grin_wallet_libwallet::NodeClient;
use semver::Version;
use std::path::PathBuf;
use std::thread;
use std::time::Duration;
const MIN_COMPAT_NODE_VERSION: &str = "2.0.0-beta.1";
pub fn _init_wallet_seed(wallet_config: WalletConfig, password: &str) {
if let Err(_) = WalletSeed::from_file(&wallet_config, password) {
WalletSeed::init_file(&wallet_config, 32, None, password)
.expect("Failed to create wallet seed file.");
};
}
pub fn seed_exists(wallet_config: WalletConfig) -> bool {
let mut data_file_dir = PathBuf::new();
data_file_dir.push(wallet_config.data_file_dir);
data_file_dir.push(SEED_FILE);
if data_file_dir.exists() {
true
} else {
false
}
}
pub fn wallet_command(wallet_args: &ArgMatches<'_>, config: GlobalWalletConfig) -> i32 {
// just get defaults from the global config
let wallet_config = config.members.unwrap().wallet;
+150 -97
View File
@@ -13,6 +13,7 @@
// limitations under the License.
use crate::api::TLSConfig;
use crate::config::GRIN_WALLET_DIR;
use crate::util::file::get_first_line;
use crate::util::{Mutex, ZeroingString};
/// Argument parsing and error handling for wallet commands
@@ -21,24 +22,20 @@ use failure::Fail;
use grin_wallet_config::WalletConfig;
use grin_wallet_controller::command;
use grin_wallet_controller::{Error, ErrorKind};
use grin_wallet_impls::{instantiate_wallet, WalletSeed};
use grin_wallet_libwallet::{IssueInvoiceTxArgs, NodeClient, WalletInst};
use grin_wallet_impls::{DefaultLCProvider, DefaultWalletImpl};
use grin_wallet_impls::{PathToSlate, SlateGetter as _};
use grin_wallet_libwallet::Slate;
use grin_wallet_libwallet::{IssueInvoiceTxArgs, NodeClient, WalletInst, WalletLCProvider};
use grin_wallet_util::grin_core as core;
use grin_wallet_util::grin_core::core::amount_to_hr_string;
use grin_wallet_util::grin_core::global;
use grin_wallet_util::grin_keychain as keychain;
use linefeed::terminal::Signal;
use linefeed::{Interface, ReadResult};
use rpassword;
use std::path::Path;
use std::path::{Path, PathBuf};
use std::sync::Arc;
// shut up test compilation warnings
#[cfg(not(test))]
use grin_wallet_impls::FileWalletCommAdapter;
#[cfg(not(test))]
use grin_wallet_libwallet::Slate;
#[cfg(not(test))]
use grin_wallet_util::grin_core::core::amount_to_hr_string;
// define what to do on argument error
macro_rules! arg_parse {
( $r:expr ) => {
@@ -116,7 +113,15 @@ fn prompt_replace_seed() -> Result<bool, ParseError> {
}
}
fn prompt_recovery_phrase() -> Result<ZeroingString, ParseError> {
fn prompt_recovery_phrase<L, C, K>(
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
) -> Result<ZeroingString, ParseError>
where
DefaultWalletImpl<'static, C>: WalletInst<'static, L, C, K>,
L: WalletLCProvider<'static, C, K>,
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
let interface = Arc::new(Interface::new("recover")?);
let mut phrase = ZeroingString::from("");
interface.set_report_signal(Signal::Interrupt, true);
@@ -133,7 +138,11 @@ fn prompt_recovery_phrase() -> Result<ZeroingString, ParseError> {
}
}
ReadResult::Input(line) => {
if WalletSeed::from_mnemonic(&line).is_ok() {
let mut w_lock = wallet.lock();
let p = w_lock.lc_provider().unwrap();
if p.validate_mnemonic(ZeroingString::from(line.clone()))
.is_ok()
{
phrase = ZeroingString::from(line);
break;
} else {
@@ -148,7 +157,6 @@ fn prompt_recovery_phrase() -> Result<ZeroingString, ParseError> {
Ok(phrase)
}
#[cfg(not(test))]
fn prompt_pay_invoice(slate: &Slate, method: &str, dest: &str) -> Result<bool, ParseError> {
let interface = Arc::new(Interface::new("pay")?);
let amount = amount_to_hr_string(slate.amount, false);
@@ -207,27 +215,21 @@ fn prompt_pay_invoice(slate: &Slate, method: &str, dest: &str) -> Result<bool, P
// instantiate wallet (needed by most functions)
pub fn inst_wallet(
pub fn inst_wallet<L, C, K>(
config: WalletConfig,
g_args: &command::GlobalArgs,
node_client: impl NodeClient + 'static,
) -> Result<Arc<Mutex<WalletInst<impl NodeClient + 'static, keychain::ExtKeychain>>>, ParseError> {
let passphrase = prompt_password(&g_args.password);
let res = instantiate_wallet(config.clone(), node_client, &passphrase, &g_args.account);
match res {
Ok(p) => Ok(p),
Err(e) => {
let msg = {
match e.kind() {
grin_wallet_impls::ErrorKind::Encryption => {
format!("Error decrypting wallet seed (check provided password)")
}
_ => format!("Error instantiating wallet: {}", e),
}
};
Err(ParseError::ArgumentError(msg))
}
}
node_client: C,
) -> Result<Arc<Mutex<Box<WalletInst<'static, L, C, K>>>>, ParseError>
where
DefaultWalletImpl<'static, C>: WalletInst<'static, L, C, K>,
L: WalletLCProvider<'static, C, K>,
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
let mut wallet = Box::new(DefaultWalletImpl::<'static, C>::new(node_client.clone()).unwrap())
as Box<WalletInst<'static, L, C, K>>;
let lc = wallet.lc_provider().unwrap();
lc.set_wallet_directory(&config.data_file_dir);
Ok(Arc::new(Mutex::new(wallet)))
}
// parses a required value, or throws error with message otherwise
@@ -283,30 +285,42 @@ pub fn parse_global_args(
}
};
let chain_type = match config.chain_type.clone() {
None => {
let param_ref = global::CHAIN_TYPE.read();
param_ref.clone()
}
Some(c) => c,
};
Ok(command::GlobalArgs {
account: account.to_owned(),
show_spent: show_spent,
chain_type: chain_type,
node_api_secret: node_api_secret,
password: password,
tls_conf: tls_conf,
})
}
pub fn parse_init_args(
pub fn parse_init_args<L, C, K>(
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
config: &WalletConfig,
g_args: &command::GlobalArgs,
args: &ArgMatches,
) -> Result<command::InitArgs, ParseError> {
if let Err(e) = WalletSeed::seed_file_exists(config) {
let msg = format!("Not creating wallet - {}", e.inner);
return Err(ParseError::ArgumentError(msg));
}
) -> Result<command::InitArgs, ParseError>
where
DefaultWalletImpl<'static, C>: WalletInst<'static, L, C, K>,
L: WalletLCProvider<'static, C, K>,
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
let list_length = match args.is_present("short_wordlist") {
false => 32,
true => 16,
};
let recovery_phrase = match args.is_present("recover") {
true => Some(prompt_recovery_phrase()?),
true => Some(prompt_recovery_phrase(wallet)?),
false => None,
};
@@ -330,17 +344,25 @@ pub fn parse_init_args(
})
}
pub fn parse_recover_args(
config: &WalletConfig,
pub fn parse_recover_args<L, C, K>(
wallet: Arc<Mutex<Box<dyn WalletInst<'static, L, C, K>>>>,
g_args: &command::GlobalArgs,
args: &ArgMatches,
) -> Result<command::RecoverArgs, ParseError> {
) -> Result<command::RecoverArgs, ParseError>
where
DefaultWalletImpl<'static, C>: WalletInst<'static, L, C, K>,
L: WalletLCProvider<'static, C, K>,
C: NodeClient + 'static,
K: keychain::Keychain + 'static,
{
let (passphrase, recovery_phrase) = {
match args.is_present("display") {
true => (prompt_password(&g_args.password), None),
false => {
let cont = {
if command::wallet_seed_exists(config).is_err() {
let mut w_lock = wallet.lock();
let p = w_lock.lc_provider().unwrap();
if p.wallet_exists(None).unwrap() {
prompt_replace_seed()?
} else {
true
@@ -349,7 +371,7 @@ pub fn parse_recover_args(
if !cont {
return Err(ParseError::CancelledError);
}
let phrase = prompt_recovery_phrase()?;
let phrase = prompt_recovery_phrase(wallet.clone())?;
println!("Please provide a new password for the recovered wallet");
(prompt_password_confirm(), Some(phrase.to_owned()))
}
@@ -363,15 +385,8 @@ pub fn parse_recover_args(
pub fn parse_listen_args(
config: &mut WalletConfig,
g_args: &mut command::GlobalArgs,
args: &ArgMatches,
) -> Result<command::ListenArgs, ParseError> {
// listen args
let pass = match g_args.password.clone() {
Some(p) => Some(p.to_owned()),
None => Some(prompt_password(&None)),
};
g_args.password = pass;
if let Some(port) = args.value_of("port") {
config.api_listen_port = port.parse().unwrap();
}
@@ -621,18 +636,17 @@ pub fn parse_process_invoice_args(
// file input only
let tx_file = parse_required(args, "input")?;
// Now we need to prompt the user whether they want to do this,
// which requires reading the slate
#[cfg(not(test))]
let adapter = FileWalletCommAdapter::new();
#[cfg(not(test))]
let slate = match adapter.receive_tx_async(&tx_file) {
Ok(s) => s,
Err(e) => return Err(ParseError::ArgumentError(format!("{}", e))),
};
if cfg!(not(test)) {
// Now we need to prompt the user whether they want to do this,
// which requires reading the slate
#[cfg(not(test))] // don't prompt during automated testing
prompt_pay_invoice(&slate, method, dest)?;
let slate = match PathToSlate((&tx_file).into()).get_tx() {
Ok(s) => s,
Err(e) => return Err(ParseError::ArgumentError(format!("{}", e))),
};
prompt_pay_invoice(&slate, method, dest)?;
}
Ok(command::ProcessInvoiceArgs {
message: message,
@@ -736,11 +750,14 @@ pub fn parse_cancel_args(args: &ArgMatches) -> Result<command::CancelArgs, Parse
})
}
pub fn wallet_command(
pub fn wallet_command<C>(
wallet_args: &ArgMatches,
mut wallet_config: WalletConfig,
mut node_client: impl NodeClient + 'static,
) -> Result<String, Error> {
mut node_client: C,
) -> Result<String, Error>
where
C: NodeClient + 'static + Clone,
{
if let Some(t) = wallet_config.chain_type.clone() {
core::global::set_mining_mode(t);
}
@@ -762,68 +779,104 @@ pub fn wallet_command(
node_client.set_node_url(&wallet_config.check_node_api_http_addr);
node_client.set_node_api_secret(global_wallet_args.node_api_secret.clone());
// closure to instantiate wallet as needed by each subcommand
let inst_wallet = || {
let res = inst_wallet(wallet_config.clone(), &global_wallet_args, node_client);
res.unwrap_or_else(|e| {
// legacy hack to avoid the need for changes in existing grin-wallet.toml files
// remove `wallet_data` from end of path as
// new lifecycle provider assumes grin_wallet.toml is in root of data directory
let mut top_level_wallet_dir = PathBuf::from(wallet_config.clone().data_file_dir);
if top_level_wallet_dir.ends_with(GRIN_WALLET_DIR) {
top_level_wallet_dir.pop();
wallet_config.data_file_dir = top_level_wallet_dir.to_str().unwrap().into();
}
// Instantiate wallet (doesn't open the wallet)
let wallet =
inst_wallet::<DefaultLCProvider<C, keychain::ExtKeychain>, C, keychain::ExtKeychain>(
wallet_config.clone(),
node_client,
)
.unwrap_or_else(|e| {
println!("{}", e);
std::process::exit(1);
})
};
});
{
let mut wallet_lock = wallet.lock();
let lc = wallet_lock.lc_provider().unwrap();
lc.set_wallet_directory(&wallet_config.data_file_dir);
}
// don't open wallet for certain lifecycle commands
match wallet_args.subcommand() {
("init", Some(_)) => {}
("recover", _) => {}
_ => {
let mut wallet_lock = wallet.lock();
let lc = wallet_lock.lc_provider().unwrap();
lc.open_wallet(None, prompt_password(&global_wallet_args.password))?;
if let Some(account) = wallet_args.value_of("account") {
let wallet_inst = lc.wallet_inst()?;
wallet_inst.set_parent_key_id_by_name(account)?;
}
}
}
let res = match wallet_args.subcommand() {
("init", Some(args)) => {
let a = arg_parse!(parse_init_args(&wallet_config, &global_wallet_args, &args));
command::init(&global_wallet_args, a)
}
("recover", Some(args)) => {
let a = arg_parse!(parse_recover_args(
let a = arg_parse!(parse_init_args(
wallet.clone(),
&wallet_config,
&global_wallet_args,
&args
));
command::recover(&wallet_config, a)
command::init(wallet, &global_wallet_args, a)
}
("recover", Some(args)) => {
let a = arg_parse!(parse_recover_args(
wallet.clone(),
&global_wallet_args,
&args
));
command::recover(wallet, a)
}
("listen", Some(args)) => {
let mut c = wallet_config.clone();
let mut g = global_wallet_args.clone();
let a = arg_parse!(parse_listen_args(&mut c, &mut g, &args));
command::listen(&c, &a, &g)
let a = arg_parse!(parse_listen_args(&mut c, &args));
command::listen(wallet, &c, &a, &global_wallet_args.clone())
}
("owner_api", Some(_)) => {
let mut g = global_wallet_args.clone();
g.tls_conf = None;
command::owner_api(inst_wallet(), &wallet_config, &g)
command::owner_api(wallet, &wallet_config, &g)
}
("web", Some(_)) => command::owner_api(inst_wallet(), &wallet_config, &global_wallet_args),
("web", Some(_)) => command::owner_api(wallet, &wallet_config, &global_wallet_args),
("account", Some(args)) => {
let a = arg_parse!(parse_account_args(&args));
command::account(inst_wallet(), a)
command::account(wallet, a)
}
("send", Some(args)) => {
let a = arg_parse!(parse_send_args(&args));
command::send(
inst_wallet(),
wallet,
a,
wallet_config.dark_background_color_scheme.unwrap_or(true),
)
}
("receive", Some(args)) => {
let a = arg_parse!(parse_receive_args(&args));
command::receive(inst_wallet(), &global_wallet_args, a)
command::receive(wallet, &global_wallet_args, a)
}
("finalize", Some(args)) => {
let a = arg_parse!(parse_finalize_args(&args));
command::finalize(inst_wallet(), a)
command::finalize(wallet, a)
}
("invoice", Some(args)) => {
let a = arg_parse!(parse_issue_invoice_args(&args));
command::issue_invoice_tx(inst_wallet(), a)
command::issue_invoice_tx(wallet, a)
}
("pay", Some(args)) => {
let a = arg_parse!(parse_process_invoice_args(&args));
command::process_invoice(
inst_wallet(),
wallet,
a,
wallet_config.dark_background_color_scheme.unwrap_or(true),
)
@@ -831,21 +884,21 @@ pub fn wallet_command(
("info", Some(args)) => {
let a = arg_parse!(parse_info_args(&args));
command::info(
inst_wallet(),
wallet,
&global_wallet_args,
a,
wallet_config.dark_background_color_scheme.unwrap_or(true),
)
}
("outputs", Some(_)) => command::outputs(
inst_wallet(),
wallet,
&global_wallet_args,
wallet_config.dark_background_color_scheme.unwrap_or(true),
),
("txs", Some(args)) => {
let a = arg_parse!(parse_txs_args(&args));
command::txs(
inst_wallet(),
wallet,
&global_wallet_args,
a,
wallet_config.dark_background_color_scheme.unwrap_or(true),
@@ -853,16 +906,16 @@ pub fn wallet_command(
}
("repost", Some(args)) => {
let a = arg_parse!(parse_repost_args(&args));
command::repost(inst_wallet(), a)
command::repost(wallet, a)
}
("cancel", Some(args)) => {
let a = arg_parse!(parse_cancel_args(&args));
command::cancel(inst_wallet(), a)
command::cancel(wallet, a)
}
("restore", Some(_)) => command::restore(inst_wallet()),
("restore", Some(_)) => command::restore(wallet),
("check", Some(args)) => {
let a = arg_parse!(parse_check_args(&args));
command::check_repair(inst_wallet(), a)
command::check_repair(wallet, a)
}
_ => {
let msg = format!("Unknown wallet command, use 'grin help wallet' for details");
+48 -14
View File
@@ -20,15 +20,16 @@ mod wallet_tests {
use grin_wallet_impls::test_framework::{self, LocalWalletClient, WalletProxy};
use clap::{App, ArgMatches};
use std::path::PathBuf;
use std::sync::Arc;
use std::thread;
use std::time::Duration;
use std::{env, fs};
use util::Mutex;
use util::{Mutex, ZeroingString};
use grin_wallet_config::{GlobalWalletConfig, WalletConfig};
use grin_wallet_impls::{LMDBBackend, WalletSeed};
use grin_wallet_libwallet::{WalletBackend, WalletInst};
use grin_wallet_config::{GlobalWalletConfig, WalletConfig, GRIN_WALLET_DIR};
use grin_wallet_impls::{DefaultLCProvider, DefaultWalletImpl};
use grin_wallet_libwallet::WalletInst;
use grin_wallet_util::grin_core::global::{self, ChainTypes};
use grin_wallet_util::grin_keychain::ExtKeychain;
@@ -121,15 +122,45 @@ mod wallet_tests {
node_client: LocalWalletClient,
passphrase: &str,
account: &str,
) -> Result<Arc<Mutex<WalletInst<LocalWalletClient, ExtKeychain>>>, grin_wallet_controller::Error>
{
) -> Result<
Arc<
Mutex<
Box<
WalletInst<
'static,
DefaultLCProvider<'static, LocalWalletClient, ExtKeychain>,
LocalWalletClient,
ExtKeychain,
>,
>,
>,
>,
grin_wallet_controller::Error,
> {
wallet_config.chain_type = None;
// First test decryption, so we can abort early if we have the wrong password
let _ = WalletSeed::from_file(&wallet_config, passphrase)?;
let mut db_wallet = LMDBBackend::new(wallet_config.clone(), passphrase, node_client)?;
db_wallet.set_parent_key_id_by_name(account)?;
info!("Using LMDB Backend for wallet");
Ok(Arc::new(Mutex::new(db_wallet)))
let mut wallet = Box::new(DefaultWalletImpl::<LocalWalletClient>::new(node_client).unwrap())
as Box<
WalletInst<
DefaultLCProvider<'static, LocalWalletClient, ExtKeychain>,
LocalWalletClient,
ExtKeychain,
>,
>;
let lc = wallet.lc_provider().unwrap();
// legacy hack to avoid the need for changes in existing grin-wallet.toml files
// remove `wallet_data` from end of path as
// new lifecycle provider assumes grin_wallet.toml is in root of data directory
let mut top_level_wallet_dir = PathBuf::from(wallet_config.clone().data_file_dir);
if top_level_wallet_dir.ends_with(GRIN_WALLET_DIR) {
top_level_wallet_dir.pop();
wallet_config.data_file_dir = top_level_wallet_dir.to_str().unwrap().into();
}
lc.set_wallet_directory(&wallet_config.data_file_dir);
lc.open_wallet(None, ZeroingString::from(passphrase))
.unwrap();
let wallet_inst = lc.wallet_inst()?;
wallet_inst.set_parent_key_id_by_name(account)?;
Ok(Arc::new(Mutex::new(wallet)))
}
fn execute_command(
@@ -151,8 +182,11 @@ mod wallet_tests {
fn command_line_test_impl(test_dir: &str) -> Result<(), grin_wallet_controller::Error> {
setup(test_dir);
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy: WalletProxy<LocalWalletClient, ExtKeychain> =
WalletProxy::new(test_dir);
let mut wallet_proxy: WalletProxy<
DefaultLCProvider<LocalWalletClient, ExtKeychain>,
LocalWalletClient,
ExtKeychain,
> = WalletProxy::new(test_dir);
let chain = wallet_proxy.chain.clone();
// load app yaml. If it don't exist, just say so and exit
+16 -17
View File
@@ -26,7 +26,7 @@ use grin_wallet_config as config;
use grin_wallet_util::grin_api as api;
use grin_wallet_util::grin_core as core;
use grin_wallet_util::grin_util as util;
use std::process::exit;
use std::env;
mod cmd;
@@ -79,43 +79,42 @@ fn real_main() -> i32 {
global::ChainTypes::Mainnet
};
// Deal with configuration file creation
let mut current_dir = None;
// special cases for certain lifecycle commands
match args.subcommand() {
// wallet init command should spit out its config file then continue
// (if desired)
("init", Some(init_args)) => {
if init_args.is_present("here") {
cmd::config_command_wallet(&chain_type, config::WALLET_CONFIG_FILE_NAME);
current_dir = Some(env::current_dir().unwrap_or_else(|e| {
panic!("Error creating config file: {}", e);
}));
}
}
("recover", _) => {}
_ => {}
}
// Load relevant config, try and load a wallet config file
let mut w = config::initial_setup_wallet(&chain_type).unwrap_or_else(|e| {
// Use defaults for configuration if config file not found anywhere
let mut config = config::initial_setup_wallet(&chain_type, current_dir).unwrap_or_else(|e| {
panic!("Error loading wallet configuration: {}", e);
});
if !cmd::seed_exists(w.members.as_ref().unwrap().wallet.clone()) {
if "init" == args.subcommand().0 || "recover" == args.subcommand().0 {
} else {
println!("Wallet seed file doesn't exist. Run `grin-wallet init` first");
exit(1);
}
}
config.members.as_mut().unwrap().wallet.chain_type = Some(chain_type);
// Load logging config
let l = w.members.as_mut().unwrap().logging.clone().unwrap();
let l = config.members.as_mut().unwrap().logging.clone().unwrap();
init_logger(Some(l));
info!(
"Using wallet configuration file at {}",
w.config_file_path.as_ref().unwrap().to_str().unwrap()
config.config_file_path.as_ref().unwrap().to_str().unwrap()
);
log_build_info();
global::set_mining_mode(
w.members
config
.members
.as_ref()
.unwrap()
.wallet
@@ -125,5 +124,5 @@ fn real_main() -> i32 {
.clone(),
);
cmd::wallet_command(&args, w)
cmd::wallet_command(&args, config)
}