Moved the Electrum client back down

This commit is contained in:
Dave Hrycyszyn
2024-07-24 16:52:35 +01:00
parent e2c963983c
commit b78aadabff
5 changed files with 35 additions and 32 deletions

View File

@@ -1,10 +1,13 @@
use crate::{bitcoin, utils};
use bdk::bitcoin::psbt::PartiallySignedTransaction;
use bdk::database::MemoryDatabase;
use bdk::wallet::AddressIndex::New;
use bdk::wallet::{AddressIndex, AddressInfo};
use bdk::{
bitcoin::Network, database::MemoryDatabase, keys::ExtendedKey, template::Bip84, KeychainKind,
Wallet,
};
use bdk::{blockchain::ElectrumBlockchain, electrum_client, SyncOptions};
use bdk::{FeeRate, SignOptions, TransactionDetails, Wallet};
use bdk::{FeeRate, SignOptions, TransactionDetails};
/// DEPRECATED
///
@@ -21,8 +24,8 @@ pub async fn run() -> Result<(), anyhow::Error> {
let dave_key = bitcoin::keys::load_from_file(&dave).unwrap();
let sammy_key = bitcoin::keys::load_from_file(&sammy).unwrap();
let dave_wallet = bitcoin::clients::create_wallet(dave_key)?;
let sammy_wallet = bitcoin::clients::create_wallet(sammy_key)?;
let dave_wallet = bitcoin::clients::electrum::create_wallet(dave_key)?;
let sammy_wallet = bitcoin::clients::electrum::create_wallet(sammy_key)?;
let dave_address = dave_wallet.get_address(AddressIndex::Peek(0))?.to_string();
let sammy_address = sammy_wallet.get_address(AddressIndex::Peek(0))?.to_string();
@@ -54,6 +57,25 @@ pub async fn run() -> Result<(), anyhow::Error> {
Ok(())
}
/// Create a BDK wallet using BIP 84 descriptor ("m/84h/1h/0h/0" and "m/84h/1h/0h/1")
pub fn create_wallet(xkey: ExtendedKey) -> anyhow::Result<Wallet<MemoryDatabase>> {
let xprv = xkey
.into_xprv(Network::Testnet)
.expect("couldn't turn xkey into xprv");
let external_descriptor = Bip84(xprv, KeychainKind::External);
let internal_descriptor = Some(Bip84(xprv, KeychainKind::Internal));
let wallet = Wallet::new(
external_descriptor,
internal_descriptor,
Network::Testnet,
MemoryDatabase::default(),
)?;
Ok(wallet)
}
fn display_balance(wallet: &Wallet<MemoryDatabase>) {
println!(
"Wallet balance for {} after syncing: {:?} sats on network {}",

View File

@@ -1,27 +1,3 @@
use bdk::{
bitcoin::Network, database::MemoryDatabase, keys::ExtendedKey, template::Bip84, KeychainKind,
Wallet,
};
// Re-enable this if we want to use alongside a fullnode.
// pub mod electrum;
pub mod electrum;
pub mod esplora;
/// Create a BDK wallet using BIP 84 descriptor ("m/84h/1h/0h/0" and "m/84h/1h/0h/1")
pub fn create_wallet(xkey: ExtendedKey) -> anyhow::Result<Wallet<MemoryDatabase>> {
let xprv = xkey
.into_xprv(Network::Testnet)
.expect("couldn't turn xkey into xprv");
let external_descriptor = Bip84(xprv, KeychainKind::External);
let internal_descriptor = Some(Bip84(xprv, KeychainKind::Internal));
let wallet = Wallet::new(
external_descriptor,
internal_descriptor,
Network::Testnet,
MemoryDatabase::default(),
)?;
Ok(wallet)
}