From d74a1cc73e896e8413793248126ca050f888d610 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Sat, 9 May 2020 17:06:15 -0700 Subject: [PATCH] Allow overwriteing when restoring --- cli/src/lib.rs | 2 +- lib/src/lightclient.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 8b34794..7e8d56f 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -87,7 +87,7 @@ pub fn startup(server: http::Uri, dangerous: bool, seed: Option, birthda let (config, latest_block_height) = LightClientConfig::create(server.clone(), dangerous)?; let lightclient = match seed { - Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, birthday)?), + Some(phrase) => Arc::new(LightClient::new_from_phrase(phrase, &config, birthday, false)?), None => { if config.wallet_exists() { Arc::new(LightClient::read_from_disk(&config)?) diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index e298445..111c955 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -348,8 +348,8 @@ impl LightClient { Ok(l) } - pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, birthday: u64) -> io::Result { - if config.wallet_exists() { + pub fn new_from_phrase(seed_phrase: String, config: &LightClientConfig, birthday: u64, overwrite: bool) -> io::Result { + if !overwrite && config.wallet_exists() { return Err(Error::new(ErrorKind::AlreadyExists, "Cannot create a new wallet from seed, because a wallet already exists")); } @@ -1243,7 +1243,7 @@ pub mod tests { assert!(LightClient::new(&config, 0).is_err()); // new_from_phrase will not work either, again, because wallet file exists - assert!(LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0).is_err()); + assert!(LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0, false).is_err()); // Creating a lightclient to the same dir without a seed should re-read the same wallet // file and therefore the same seed phrase @@ -1262,7 +1262,7 @@ pub mod tests { assert!(LightClient::read_from_disk(&config).is_err()); // New from phrase should work becase a file doesn't exist already - let lc = LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0).unwrap(); + let lc = LightClient::new_from_phrase(TEST_SEED.to_string(), &config, 0, false).unwrap(); assert_eq!(TEST_SEED.to_string(), lc.do_seed_phrase().unwrap()["seed"].as_str().unwrap().to_string()); lc.do_save().unwrap();