diff --git a/example-crates/wallet_esplora_async/Cargo.toml b/example-crates/wallet_esplora_async/Cargo.toml index c588a87aa6..9750197322 100644 --- a/example-crates/wallet_esplora_async/Cargo.toml +++ b/example-crates/wallet_esplora_async/Cargo.toml @@ -8,6 +8,6 @@ edition = "2021" [dependencies] bdk = { path = "../../crates/bdk" } bdk_esplora = { path = "../../crates/esplora", features = ["async-https"] } -bdk_file_store = { path = "../../crates/file_store" } +bdk_sqlite_store = { path = "../../crates/sqlite_store", features = ["bdk"] } tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] } anyhow = "1" diff --git a/example-crates/wallet_esplora_async/src/main.rs b/example-crates/wallet_esplora_async/src/main.rs index 690cd87e24..c7889c4d2a 100644 --- a/example-crates/wallet_esplora_async/src/main.rs +++ b/example-crates/wallet_esplora_async/src/main.rs @@ -1,31 +1,31 @@ use std::{io::Write, str::FromStr}; +use bdk::bitcoin::key::Secp256k1; +use bdk::bitcoin::Network::Signet; +use bdk::miniscript::Descriptor; use bdk::{ bitcoin::{Address, Network}, wallet::{AddressIndex, Update}, SignOptions, Wallet, }; use bdk_esplora::{esplora_client, EsploraAsyncExt}; -use bdk_file_store::Store; +use bdk_sqlite_store::wallet::WalletStore; -const DB_MAGIC: &str = "bdk_wallet_esplora_async_example"; const SEND_AMOUNT: u64 = 5000; const STOP_GAP: usize = 50; const PARALLEL_REQUESTS: usize = 5; #[tokio::main] async fn main() -> Result<(), anyhow::Error> { - let db_path = std::env::temp_dir().join("bdk-esplora-async-example"); - let db = Store::::open_or_create_new(DB_MAGIC.as_bytes(), db_path)?; - let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)"; - let internal_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/*)"; - - let mut wallet = Wallet::new_or_load( - external_descriptor, - Some(internal_descriptor), - db, - Network::Testnet, - )?; + let db_path = "bdk-esplora-async-example.sqlite"; + let db = WalletStore::new(db_path)?; + + let secp = Secp256k1::new(); + let external_descriptor = Descriptor::parse_descriptor(&secp, "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)").unwrap(); + let internal_descriptor = Descriptor::parse_descriptor(&secp, "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/*)").unwrap(); + + let mut wallet = + Wallet::new_or_load(external_descriptor, Some(internal_descriptor), db, Signet)?; let address = wallet.try_get_address(AddressIndex::New)?; println!("Generated Address: {}", address); @@ -34,8 +34,7 @@ async fn main() -> Result<(), anyhow::Error> { println!("Wallet balance before syncing: {} sats", balance.total()); print!("Syncing..."); - let client = - esplora_client::Builder::new("https://blockstream.info/testnet/api").build_async()?; + let client = esplora_client::Builder::new("http://signet.bitcoindevkit.net").build_async()?; let prev_tip = wallet.latest_checkpoint(); let keychain_spks = wallet @@ -79,7 +78,7 @@ async fn main() -> Result<(), anyhow::Error> { } let faucet_address = Address::from_str("mkHS9ne12qx9pS9VojpwU5xtRd4T7X7ZUt")? - .require_network(Network::Testnet)?; + .require_network(Network::Signet)?; let mut tx_builder = wallet.build_tx(); tx_builder