Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow outputting different formats for bitcoin import-hd command #279

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions wagyu/cli/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl BitcoinWallet {
mnemonic: &str,
password: &Option<&str>,
path: &str,
format: &BitcoinFormat,
) -> Result<Self, CLIError> {
let mnemonic = BitcoinMnemonic::<N, W>::from_phrase(&mnemonic)?;
let master_extended_private_key = mnemonic.to_extended_private_key(password.clone())?;
Expand All @@ -110,7 +111,7 @@ impl BitcoinWallet {
let extended_public_key = extended_private_key.to_extended_public_key();
let private_key = extended_private_key.to_private_key();
let public_key = extended_public_key.to_public_key();
let address = public_key.to_address(&extended_private_key.format())?;
let address = public_key.to_address(format)?;
let compressed = private_key.is_compressed();
Ok(Self {
path: Some(path.to_string()),
Expand Down Expand Up @@ -582,7 +583,7 @@ impl BitcoinOptions {
}

/// Sets `format` to the specified format, overriding its previous state.
/// If the specified argument is `None`, then no change occurs.
/// If the specified argument is `None` or unrecognized, then no change occurs.
fn format(&mut self, argument: Option<&str>) {
match argument {
Some("legacy") => self.format = BitcoinFormat::P2PKH,
Expand Down Expand Up @@ -748,7 +749,7 @@ impl CLI for BitcoinCLI {
}
("import-hd", Some(arguments)) => {
options.subcommand = Some("import-hd".into());
options.parse(arguments, &["json", "network"]);
options.parse(arguments, &["format", "json", "network"]);
options.parse(
arguments,
&[
Expand Down Expand Up @@ -820,17 +821,17 @@ impl CLI for BitcoinCLI {

match options.to_derivation_path(true) {
Some(path) => vec![BitcoinWallet::from_mnemonic::<N, ChineseSimplified>(
&mnemonic, password, &path,
&mnemonic, password, &path, &options.format,
)
.or(BitcoinWallet::from_mnemonic::<N, ChineseTraditional>(
&mnemonic, password, &path,
&mnemonic, password, &path, &options.format,
))
.or(BitcoinWallet::from_mnemonic::<N, English>(&mnemonic, password, &path))
.or(BitcoinWallet::from_mnemonic::<N, French>(&mnemonic, password, &path))
.or(BitcoinWallet::from_mnemonic::<N, Italian>(&mnemonic, password, &path))
.or(BitcoinWallet::from_mnemonic::<N, Japanese>(&mnemonic, password, &path))
.or(BitcoinWallet::from_mnemonic::<N, Korean>(&mnemonic, password, &path))
.or(BitcoinWallet::from_mnemonic::<N, Spanish>(&mnemonic, password, &path))?],
.or(BitcoinWallet::from_mnemonic::<N, English>(&mnemonic, password, &path, &options.format))
.or(BitcoinWallet::from_mnemonic::<N, French>(&mnemonic, password, &path, &options.format))
.or(BitcoinWallet::from_mnemonic::<N, Italian>(&mnemonic, password, &path, &options.format))
.or(BitcoinWallet::from_mnemonic::<N, Japanese>(&mnemonic, password, &path, &options.format))
.or(BitcoinWallet::from_mnemonic::<N, Korean>(&mnemonic, password, &path, &options.format))
.or(BitcoinWallet::from_mnemonic::<N, Spanish>(&mnemonic, password, &path, &options.format))?],
None => vec![],
}
} else if let Some(extended_private_key) = options.extended_private_key.clone() {
Expand Down
2 changes: 2 additions & 0 deletions wagyu/cli/parameters/subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub const HD_BITCOIN: SubCommandType = (
&[
option::COUNT,
option::DERIVATION_BITCOIN,
option::FORMAT_BITCOIN,
option::LANGUAGE_HD,
option::NETWORK_HD_BITCOIN,
option::PASSWORD_HD,
Expand Down Expand Up @@ -137,6 +138,7 @@ pub const IMPORT_HD_BITCOIN: SubCommandType = (
option::DERIVATION_IMPORT_BITCOIN,
option::EXTENDED_PUBLIC,
option::EXTENDED_PRIVATE,
option::FORMAT_IMPORT_BITCOIN,
option::NETWORK_IMPORT_HD_BITCOIN,
option::INDEX_IMPORT_HD,
option::MNEMONIC,
Expand Down