Made the wallet's Network configurable

This commit is contained in:
Dave Hrycyszyn
2024-06-25 15:05:33 +01:00
parent 7effe9455f
commit a6105cf2bf
2 changed files with 6 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
use std::{collections::BTreeSet, fs, io::Write, str::FromStr}; use std::{collections::BTreeSet, fs, io::Write};
use bdk::keys::bip39::Mnemonic; use bdk::keys::bip39::Mnemonic;
use bdk_esplora::{ use bdk_esplora::{
@@ -20,6 +20,7 @@ use crate::utils;
const STOP_GAP: usize = 50; const STOP_GAP: usize = 50;
const PARALLEL_REQUESTS: usize = 5; const PARALLEL_REQUESTS: usize = 5;
/// A wallet that uses the Esplora client to interact with the Bitcoin network.
pub struct EsploraWallet { pub struct EsploraWallet {
wallet: Wallet, wallet: Wallet,
db: Store<KeychainKind, ConfirmationTimeHeightAnchor>, db: Store<KeychainKind, ConfirmationTimeHeightAnchor>,
@@ -124,8 +125,8 @@ impl EsploraWallet {
} }
} }
/// Creates a Bitcoin Signet descriptor wallet with the mnemonic in the given user directory. /// Creates a Bitcoin descriptor wallet with the mnemonic in the given user directory.
pub(crate) fn create_wallet(name: &str) -> anyhow::Result<EsploraWallet> { pub(crate) fn create_wallet(name: &str, network: Network) -> anyhow::Result<EsploraWallet> {
let keys_dir = utils::home(name); let keys_dir = utils::home(name);
let mnemonic_path = crate::utils::side_paths(keys_dir).1; // TODO: this tuple stinks let mnemonic_path = crate::utils::side_paths(keys_dir).1; // TODO: this tuple stinks
@@ -157,7 +158,7 @@ pub(crate) fn create_wallet(name: &str) -> anyhow::Result<EsploraWallet> {
&external_descriptor, &external_descriptor,
&internal_descriptor, &internal_descriptor,
changeset, changeset,
Network::Signet, network,
) )
.expect("problem setting up wallet"); .expect("problem setting up wallet");

View File

@@ -11,7 +11,7 @@ use crate::bitcoin::clients;
/// Also, it very handily works with the mutinynet.com esplora server, which is configured /// Also, it very handily works with the mutinynet.com esplora server, which is configured
/// with 30 second block times. /// with 30 second block times.
pub(crate) async fn run() -> Result<(), anyhow::Error> { pub(crate) async fn run() -> Result<(), anyhow::Error> {
let mut dave = clients::esplora::create_wallet("dave")?; let mut dave = clients::esplora::create_wallet("dave", Network::Signet)?;
let _next_address = dave.next_unused_address()?; let _next_address = dave.next_unused_address()?;