From c4d6505f5ff5209e9de77775c2aae608ce2256a7 Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Tue, 17 Oct 2023 00:20:09 -0500 Subject: [PATCH] refactor(examples): Add anyhow and remove expect from wallet.try_get_address() --- example-crates/wallet_electrum/Cargo.toml | 1 + example-crates/wallet_electrum/src/main.rs | 6 ++---- example-crates/wallet_esplora_async/Cargo.toml | 1 + example-crates/wallet_esplora_async/src/main.rs | 2 +- example-crates/wallet_esplora_blocking/Cargo.toml | 1 + example-crates/wallet_esplora_blocking/src/main.rs | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/example-crates/wallet_electrum/Cargo.toml b/example-crates/wallet_electrum/Cargo.toml index 37a0f926a3..847cd90d63 100644 --- a/example-crates/wallet_electrum/Cargo.toml +++ b/example-crates/wallet_electrum/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" bdk = { path = "../../crates/bdk" } bdk_electrum = { path = "../../crates/electrum" } bdk_file_store = { path = "../../crates/file_store" } +anyhow = "1" diff --git a/example-crates/wallet_electrum/src/main.rs b/example-crates/wallet_electrum/src/main.rs index d502b1dee6..995464bad5 100644 --- a/example-crates/wallet_electrum/src/main.rs +++ b/example-crates/wallet_electrum/src/main.rs @@ -16,7 +16,7 @@ use bdk_electrum::{ }; use bdk_file_store::Store; -fn main() -> Result<(), Box> { +fn main() -> Result<(), anyhow::Error> { let db_path = std::env::temp_dir().join("bdk-electrum-example"); let db = Store::::new_from_path(DB_MAGIC.as_bytes(), db_path)?; let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)"; @@ -29,9 +29,7 @@ fn main() -> Result<(), Box> { Network::Testnet, )?; - let address = wallet - .try_get_address(bdk::wallet::AddressIndex::New) - .expect("new_address"); + let address = wallet.try_get_address(bdk::wallet::AddressIndex::New)?; println!("Generated Address: {}", address); let balance = wallet.get_balance(); diff --git a/example-crates/wallet_esplora_async/Cargo.toml b/example-crates/wallet_esplora_async/Cargo.toml index f67cecb483..c588a87aa6 100644 --- a/example-crates/wallet_esplora_async/Cargo.toml +++ b/example-crates/wallet_esplora_async/Cargo.toml @@ -10,3 +10,4 @@ bdk = { path = "../../crates/bdk" } bdk_esplora = { path = "../../crates/esplora", features = ["async-https"] } bdk_file_store = { path = "../../crates/file_store" } 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 a3bcfc9aaf..c3afc55d60 100644 --- a/example-crates/wallet_esplora_async/src/main.rs +++ b/example-crates/wallet_esplora_async/src/main.rs @@ -14,7 +14,7 @@ const STOP_GAP: usize = 50; const PARALLEL_REQUESTS: usize = 5; #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> Result<(), anyhow::Error> { let db_path = std::env::temp_dir().join("bdk-esplora-async-example"); let db = Store::::new_from_path(DB_MAGIC.as_bytes(), db_path)?; let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)"; diff --git a/example-crates/wallet_esplora_blocking/Cargo.toml b/example-crates/wallet_esplora_blocking/Cargo.toml index f07f64e482..0679bd8f38 100644 --- a/example-crates/wallet_esplora_blocking/Cargo.toml +++ b/example-crates/wallet_esplora_blocking/Cargo.toml @@ -10,3 +10,4 @@ publish = false bdk = { path = "../../crates/bdk" } bdk_esplora = { path = "../../crates/esplora", features = ["blocking"] } bdk_file_store = { path = "../../crates/file_store" } +anyhow = "1" diff --git a/example-crates/wallet_esplora_blocking/src/main.rs b/example-crates/wallet_esplora_blocking/src/main.rs index 6b8935c4cd..f3e31986a0 100644 --- a/example-crates/wallet_esplora_blocking/src/main.rs +++ b/example-crates/wallet_esplora_blocking/src/main.rs @@ -13,7 +13,7 @@ use bdk::{ use bdk_esplora::{esplora_client, EsploraExt}; use bdk_file_store::Store; -fn main() -> Result<(), Box> { +fn main() -> Result<(), anyhow::Error> { let db_path = std::env::temp_dir().join("bdk-esplora-example"); let db = Store::::new_from_path(DB_MAGIC.as_bytes(), db_path)?; let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)";