Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mj10021 committed Feb 15, 2024
1 parent 4334037 commit 8055d2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions src/subcommand/wallet/restore.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use {
super::*,
std::io,
std::{borrow::Cow, io, io::Write},
};

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -34,12 +34,15 @@ impl Restore {
} else if let Some(Some(mnemonic)) = self.mnemonic {
wallet.initialize(mnemonic.to_seed(self.passphrase.unwrap_or_default()))?;
} else if let Some(None) = self.mnemonic {
let mut buffer = Vec::new();
println!("Please input your seed phrase:");
io::stdin().read_to_end(&mut buffer)?;
let msg = format!("invalid input as bytes, expected [u8; 64] read [u8; {}]", buffer.len());
wallet.initialize(buffer.try_into().expect(&msg))?
} else {unreachable!()}
let mut buffer = String::new();
io::stdout().write_all(b"Please input your seed phrase:")?;
io::stdin().read_to_string(&mut buffer)?;
let buffer = Cow::<str>::Owned(buffer);
let mnemonic: Mnemonic = Mnemonic::parse(buffer)?;
wallet.initialize(mnemonic.to_seed(self.passphrase.unwrap_or_default()))?
} else {
unreachable!()
}

Ok(None)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/command_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl CommandBuilder {
..self
}
}

pub(crate) fn stderr_regex(self, expected_stderr: impl AsRef<str>) -> Self {
Self {
expected_stderr: Expected::regex(expected_stderr.as_ref()),
Expand Down
3 changes: 2 additions & 1 deletion tests/wallet/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ fn restore_with_blank_mnemonic_generates_same_descriptors() {
let rpc_server = test_bitcoincore_rpc::spawn();

CommandBuilder::new(["wallet", "restore", "--mnemonic"])
.stdin(mnemonic.to_string().as_bytes().to_vec())
.stdout_regex("Please input your seed phrase:")
.stdin(mnemonic.to_string().into_bytes())
.bitcoin_rpc_server(&rpc_server)
.run_and_extract_stdout();

Expand Down

0 comments on commit 8055d2f

Please sign in to comment.