Skip to content

Commit a991cf6

Browse files
committed
refactor(examples): Add anyhow and remove expect from wallet.try_get_address()
1 parent 242f111 commit a991cf6

File tree

6 files changed

+7
-6
lines changed

6 files changed

+7
-6
lines changed

example-crates/wallet_electrum/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2021"
77
bdk = { path = "../../crates/bdk" }
88
bdk_electrum = { path = "../../crates/electrum" }
99
bdk_file_store = { path = "../../crates/file_store" }
10+
anyhow = "1"

example-crates/wallet_electrum/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bdk_electrum::{
1616
};
1717
use bdk_file_store::Store;
1818

19-
fn main() -> Result<(), Box<dyn std::error::Error>> {
19+
fn main() -> Result<(), anyhow::Error> {
2020
let db_path = std::env::temp_dir().join("bdk-electrum-example");
2121
let db = Store::<bdk::wallet::ChangeSet>::new_from_path(DB_MAGIC.as_bytes(), db_path)?;
2222
let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)";
@@ -29,9 +29,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2929
Network::Testnet,
3030
)?;
3131

32-
let address = wallet
33-
.try_get_address(bdk::wallet::AddressIndex::New)
34-
.expect("new_address");
32+
let address = wallet.try_get_address(bdk::wallet::AddressIndex::New)?;
3533
println!("Generated Address: {}", address);
3634

3735
let balance = wallet.get_balance();

example-crates/wallet_esplora_async/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ bdk = { path = "../../crates/bdk" }
1010
bdk_esplora = { path = "../../crates/esplora", features = ["async-https"] }
1111
bdk_file_store = { path = "../../crates/file_store" }
1212
tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros"] }
13+
anyhow = "1"

example-crates/wallet_esplora_async/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const STOP_GAP: usize = 50;
1414
const PARALLEL_REQUESTS: usize = 5;
1515

1616
#[tokio::main]
17-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
17+
async fn main() -> Result<(), anyhow::Error> {
1818
let db_path = std::env::temp_dir().join("bdk-esplora-async-example");
1919
let db = Store::<bdk::wallet::ChangeSet>::new_from_path(DB_MAGIC.as_bytes(), db_path)?;
2020
let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)";

example-crates/wallet_esplora_blocking/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ publish = false
1010
bdk = { path = "../../crates/bdk" }
1111
bdk_esplora = { path = "../../crates/esplora", features = ["blocking"] }
1212
bdk_file_store = { path = "../../crates/file_store" }
13+
anyhow = "1"

example-crates/wallet_esplora_blocking/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use bdk::{
1313
use bdk_esplora::{esplora_client, EsploraExt};
1414
use bdk_file_store::Store;
1515

16-
fn main() -> Result<(), Box<dyn std::error::Error>> {
16+
fn main() -> Result<(), anyhow::Error> {
1717
let db_path = std::env::temp_dir().join("bdk-esplora-example");
1818
let db = Store::<bdk::wallet::ChangeSet>::new_from_path(DB_MAGIC.as_bytes(), db_path)?;
1919
let external_descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/0/*)";

0 commit comments

Comments
 (0)