From e98f5f2d78d8894e519d91cbfa9a8f1328ef6d6c Mon Sep 17 00:00:00 2001 From: Ryan Breen Date: Tue, 4 Oct 2022 08:37:41 -0400 Subject: [PATCH] adding testnet/bitcoin differentiation --- src/cli.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 3cbdfb4..8b0ac6f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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, } @@ -72,11 +76,11 @@ impl Cli { let xkey: ExtendedKey = 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") @@ -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)]