Skip to content

Commit

Permalink
example(wallet_esplora_async): update to use new sqlite_store::Wallet…
Browse files Browse the repository at this point in the history
…Store
  • Loading branch information
notmandatory committed May 13, 2024
1 parent cc2faae commit 8a408ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion example-crates/wallet_esplora_async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 6 additions & 8 deletions example-crates/wallet_esplora_async/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@ use bdk::{
KeychainKind, SignOptions, Wallet,
};
use bdk_esplora::{esplora_client, EsploraAsyncExt};
use bdk_file_store::Store;
use bdk_sqlite_store::store::Store;

const DB_MAGIC: &str = "bdk_wallet_esplora_async_example";
const SEND_AMOUNT: Amount = Amount::from_sat(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::<bdk::wallet::ChangeSet>::open_or_create_new(DB_MAGIC.as_bytes(), db_path)?;
let db_path = "bdk-esplora-async-example.sqlite";
let db = Store::new(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,
Network::Signet,
)?;

let address = wallet.next_unused_address(KeychainKind::External)?;
Expand All @@ -33,8 +32,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()?;

fn generate_inspect(kind: KeychainKind) -> impl FnMut(u32, &Script) + Send + Sync + 'static {
let mut once = Some(());
Expand Down Expand Up @@ -90,7 +88,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
Expand Down

0 comments on commit 8a408ae

Please sign in to comment.