Skip to content

Commit

Permalink
Merge pull request #4 from ursuscamp/bdk
Browse files Browse the repository at this point in the history
adding testnet/bitcoin differentiation
  • Loading branch information
ursuscamp authored Oct 4, 2022
2 parents 489339b + e98f5f2 commit 2d356ed
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ pub struct Cli {
#[clap(short, long)]
long: bool,

/// Switch to testnet mode
#[clap(short, long)]
testnet: bool,

#[clap(subcommand)]
pub action: Action,
}
Expand Down Expand Up @@ -72,11 +76,11 @@ impl Cli {
let xkey: ExtendedKey<miniscript::Segwitv0> = seed
.into_extended_key()
.context("Failed to convert mnemonic into an extended key")?;
let xprv = xkey.into_xprv(Network::Testnet).unwrap();
let xprv = xkey.into_xprv(self.network()).unwrap();
Wallet::new(
Bip84(xprv.clone(), KeychainKind::External),
Some(Bip84(xprv.clone(), KeychainKind::External)),
Network::Testnet,
self.network(),
MemoryDatabase::default(),
)
.context("Failed to create wallet")
Expand Down Expand Up @@ -110,6 +114,14 @@ impl Cli {
print!("{descriptor}");
Ok(())
}

fn network(&self) -> Network {
if self.testnet {
Network::Testnet
} else {
Network::Bitcoin
}
}
}

#[derive(clap::Subcommand, Clone)]
Expand Down

0 comments on commit 2d356ed

Please sign in to comment.