Refactored wallet creation so it's outside of either esplora or electrum client code
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
use crate::{bitcoin, utils};
|
use crate::{bitcoin, utils};
|
||||||
use bdk::bitcoin::psbt::PartiallySignedTransaction;
|
use bdk::bitcoin::psbt::PartiallySignedTransaction;
|
||||||
use bdk::bitcoin::Network;
|
|
||||||
use bdk::database::MemoryDatabase;
|
use bdk::database::MemoryDatabase;
|
||||||
use bdk::keys::ExtendedKey;
|
use bdk::wallet::AddressIndex::New;
|
||||||
use bdk::template::Bip84;
|
use bdk::wallet::{AddressIndex, AddressInfo};
|
||||||
use bdk::wallet::AddressIndex::{self, New};
|
|
||||||
use bdk::wallet::AddressInfo;
|
|
||||||
use bdk::{blockchain::ElectrumBlockchain, electrum_client, SyncOptions};
|
use bdk::{blockchain::ElectrumBlockchain, electrum_client, SyncOptions};
|
||||||
use bdk::{FeeRate, KeychainKind, SignOptions, TransactionDetails, Wallet};
|
use bdk::{FeeRate, SignOptions, TransactionDetails, Wallet};
|
||||||
|
|
||||||
/// DEPRECATED
|
/// DEPRECATED
|
||||||
///
|
///
|
||||||
@@ -24,8 +21,8 @@ pub async fn run() -> Result<(), anyhow::Error> {
|
|||||||
let dave_key = bitcoin::keys::load_from_file(&dave).unwrap();
|
let dave_key = bitcoin::keys::load_from_file(&dave).unwrap();
|
||||||
let sammy_key = bitcoin::keys::load_from_file(&sammy).unwrap();
|
let sammy_key = bitcoin::keys::load_from_file(&sammy).unwrap();
|
||||||
|
|
||||||
let dave_wallet = create_wallet(dave_key)?;
|
let dave_wallet = bitcoin::clients::create_wallet(dave_key)?;
|
||||||
let sammy_wallet = create_wallet(sammy_key)?;
|
let sammy_wallet = bitcoin::clients::create_wallet(sammy_key)?;
|
||||||
|
|
||||||
let dave_address = dave_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
let dave_address = dave_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
||||||
let sammy_address = sammy_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
let sammy_address = sammy_wallet.get_address(AddressIndex::Peek(0))?.to_string();
|
||||||
@@ -57,24 +54,24 @@ pub async fn run() -> Result<(), anyhow::Error> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a BDK wallet using BIP 84 descriptor ("m/84h/1h/0h/0" and "m/84h/1h/0h/1")
|
// /// 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>> {
|
// pub fn create_wallet(xkey: ExtendedKey) -> anyhow::Result<Wallet<MemoryDatabase>> {
|
||||||
let xprv = xkey
|
// let xprv = xkey
|
||||||
.into_xprv(Network::Testnet)
|
// .into_xprv(Network::Testnet)
|
||||||
.expect("couldn't turn xkey into xprv");
|
// .expect("couldn't turn xkey into xprv");
|
||||||
|
|
||||||
let external_descriptor = Bip84(xprv, KeychainKind::External);
|
// let external_descriptor = Bip84(xprv, KeychainKind::External);
|
||||||
let internal_descriptor = Some(Bip84(xprv, KeychainKind::Internal));
|
// let internal_descriptor = Some(Bip84(xprv, KeychainKind::Internal));
|
||||||
|
|
||||||
let wallet = Wallet::new(
|
// let wallet = Wallet::new(
|
||||||
external_descriptor,
|
// external_descriptor,
|
||||||
internal_descriptor,
|
// internal_descriptor,
|
||||||
Network::Testnet,
|
// Network::Testnet,
|
||||||
MemoryDatabase::default(),
|
// MemoryDatabase::default(),
|
||||||
)?;
|
// )?;
|
||||||
|
|
||||||
Ok(wallet)
|
// Ok(wallet)
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn display_balance(wallet: &Wallet<MemoryDatabase>) {
|
fn display_balance(wallet: &Wallet<MemoryDatabase>) {
|
||||||
println!(
|
println!(
|
||||||
|
|||||||
@@ -1,2 +1,27 @@
|
|||||||
|
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;
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ async fn setup(name: &String) -> SideNode {
|
|||||||
let side_dir = utils::home(name);
|
let side_dir = utils::home(name);
|
||||||
let bft_crdt_keys = bft_crdt::keys::load_from_file(&side_dir);
|
let bft_crdt_keys = bft_crdt::keys::load_from_file(&side_dir);
|
||||||
let keys = bitcoin::keys::load_from_file(&side_dir).unwrap();
|
let keys = bitcoin::keys::load_from_file(&side_dir).unwrap();
|
||||||
let bitcoin_wallet = bitcoin::clients::electrum::create_wallet(keys).unwrap();
|
let bitcoin_wallet = bitcoin::clients::create_wallet(keys).unwrap();
|
||||||
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);
|
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);
|
||||||
|
|
||||||
// Channels for internal communication, and a tokio task for stdin input
|
// Channels for internal communication, and a tokio task for stdin input
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ async fn setup(_: &str) -> SideNode {
|
|||||||
let bft_crdt_keys = make_keypair();
|
let bft_crdt_keys = make_keypair();
|
||||||
let mnemonic_words = bitcoin::keys::make_mnemonic();
|
let mnemonic_words = bitcoin::keys::make_mnemonic();
|
||||||
let keys = bitcoin::keys::get(mnemonic_words).unwrap();
|
let keys = bitcoin::keys::get(mnemonic_words).unwrap();
|
||||||
let bitcoin_wallet = bitcoin::clients::electrum::create_wallet(keys).unwrap();
|
let bitcoin_wallet = bitcoin::clients::create_wallet(keys).unwrap();
|
||||||
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);
|
let crdt = BaseCrdt::<TransactionList>::new(&bft_crdt_keys);
|
||||||
|
|
||||||
// Channels for internal communication, and a tokio task for stdin input
|
// Channels for internal communication, and a tokio task for stdin input
|
||||||
|
|||||||
Reference in New Issue
Block a user