Add 'recover' option to grin wallet init (#2330)

* Only update outputs with unconfirmed transactions outstanding

* add further check for Unspent output that have been spent to check_repair

* rename  to

* make updating all outputs optional API parameter. do full update before a wallet check, remove unspent->spent check from check process

* rustfmt

* typo

* add recover from phrase option to init

* rustfmt

* don't panic if recover is cancelled, grin-wallet.toml is created but wallet_data dir doesn't yet exits

* rustfmt
This commit is contained in:
Yeastplume
2019-01-10 12:06:12 +00:00
committed by GitHub
parent 4191b15410
commit cd9a539288
11 changed files with 53 additions and 12 deletions
+12 -2
View File
@@ -13,7 +13,7 @@
// limitations under the License.
/// Grin configuration file output command
use crate::config::{GlobalConfig, GlobalWalletConfig};
use crate::config::{GlobalConfig, GlobalWalletConfig, GRIN_WALLET_DIR};
use crate::core::global;
use std::env;
@@ -52,12 +52,22 @@ pub fn config_command_wallet(chain_type: &global::ChainTypes, file_name: &str) {
});
let mut config_file_name = current_dir.clone();
config_file_name.push(file_name);
if config_file_name.exists() {
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())
+1 -1
View File
@@ -22,7 +22,7 @@ use std::time::Duration;
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, password)
WalletSeed::init_file(&wallet_config, 32, None, password)
.expect("Failed to create wallet seed file.");
};
}
+14 -1
View File
@@ -233,15 +233,28 @@ pub fn parse_init_args(
false => 32,
true => 16,
};
println!("Please enter a password for your new wallet");
let recovery_phrase = match args.is_present("recover") {
true => Some(prompt_recovery_phrase()?),
false => None,
};
if recovery_phrase.is_some() {
println!("Please provide a new password for the recovered wallet");
} else {
println!("Please enter a password for your new wallet");
}
let password = match g_args.password.clone() {
Some(p) => p,
None => prompt_password_confirm(),
};
Ok(command::InitArgs {
list_length: list_length,
password: password,
config: config.clone(),
recovery_phrase: recovery_phrase,
restore: false,
})
}
+5
View File
@@ -284,6 +284,11 @@ subcommands:
short: s
long: short_wordlist
takes_value: false
- recover:
help: Initialize new wallet using a recovery phrase
short: r
long: recover
takes_value: false
- recover:
about: Recover a wallet.seed file from a recovery phrase (default) or displays a recovery phrase for an existing seed file
args: