Skip to content

Commit 3b36277

Browse files
Use async with esplora-reqwest
We previously had the esplora-reqwest feature, but it would use sync reqwest, as the "async-interface" feature in BDK wasn't set. This commit sets this feature so that using `esplora-reqwest` always uses async mode.
1 parent a9dffc3 commit 3b36277

File tree

5 files changed

+42
-7
lines changed

5 files changed

+42
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Rewrite relevant doc comments as `structopt` help document.
1212
- Update `bdk` and `bdk-reserves` to v0.19.0.
1313
- Change default database to `sqlite`.
14+
- Change the `esplora-reqwest` feature to always use async mode
1415

1516
## [0.5.0]
1617

Cargo.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fd-lock = { version = "=3.0.2", optional = true }
2727
regex = { version = "1", optional = true }
2828
bdk-reserves = { version = "0.19", optional = true}
2929
electrsd = { version= "0.12", features = ["trigger", "bitcoind_22_0"], optional = true}
30+
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
3031

3132
[features]
3233
default = ["repl", "sqlite-db"]
@@ -44,7 +45,8 @@ electrum = ["bdk/electrum"]
4445
compact_filters = ["bdk/compact_filters"]
4546
esplora = []
4647
esplora-ureq = ["esplora", "bdk/use-esplora-ureq"]
47-
esplora-reqwest = ["esplora", "bdk/use-esplora-reqwest"]
48+
async-interface = ["bdk/async-interface"]
49+
esplora-reqwest = ["esplora", "bdk/use-esplora-reqwest", "async-interface"]
4850

4951
# Use this to consensus verify transactions at sync time
5052
verify = ["bdk/verify"]
@@ -65,4 +67,4 @@ regtest-node = []
6567
regtest-bitcoin = ["regtest-node" , "rpc", "electrsd"]
6668
regtest-electrum = ["regtest-node", "electrum", "electrsd/electrs_0_8_10"]
6769
regtest-esplora-ureq = ["regtest-node", "esplora-ureq", "electrsd/esplora_a33e97e1"]
68-
regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]
70+
regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]

src/handlers.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ use bdk::{
6565
bitcoin::{Address, OutPoint, TxOut},
6666
blockchain::Capability,
6767
};
68+
use bdk_macros::maybe_async;
6869
#[cfg(any(
6970
feature = "electrum",
7071
feature = "esplora",
7172
feature = "compact_filters",
7273
feature = "rpc"
7374
))]
7475
use bdk_macros::maybe_await;
75-
use bdk_macros::maybe_async;
7676
#[cfg(feature = "reserves")]
7777
use bdk_reserves::reserves::verify_proof;
7878
#[cfg(feature = "reserves")]
@@ -557,6 +557,7 @@ pub fn get_outpoints_for_address(
557557
.collect()
558558
}
559559

560+
#[maybe_async]
560561
pub fn handle_command(
561562
cli_opts: CliOpts,
562563
network: Network,
@@ -577,7 +578,11 @@ pub fn handle_command(
577578
let database = open_database(&wallet_opts)?;
578579
let blockchain = new_blockchain(network, &wallet_opts, &_backend)?;
579580
let wallet = new_wallet(network, &wallet_opts, database)?;
580-
let result = handle_online_wallet_subcommand(&wallet, &blockchain, online_subcommand)?;
581+
let result = maybe_await!(handle_online_wallet_subcommand(
582+
&wallet,
583+
&blockchain,
584+
online_subcommand
585+
))?;
581586
serde_json::to_string_pretty(&result)?
582587
}
583588
CliSubCommand::Wallet {
@@ -657,11 +662,11 @@ pub fn handle_command(
657662
))]
658663
ReplSubCommand::OnlineWalletSubCommand(online_subcommand) => {
659664
let blockchain = new_blockchain(network, &wallet_opts, &_backend)?;
660-
handle_online_wallet_subcommand(
665+
maybe_await!(handle_online_wallet_subcommand(
661666
&wallet,
662667
&blockchain,
663668
online_subcommand,
664-
)
669+
))
665670
}
666671
ReplSubCommand::OfflineWalletSubCommand(offline_subcommand) => {
667672
handle_offline_wallet_subcommand(

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ use log::{debug, error, warn};
2424
use crate::commands::CliOpts;
2525
use crate::handlers::*;
2626
use bdk::{bitcoin, Error};
27+
use bdk_macros::{maybe_async, maybe_await};
2728
use structopt::StructOpt;
2829

2930
#[cfg(feature = "repl")]
3031
const REPL_LINE_SPLIT_REGEX: &str = r#""([^"]*)"|'([^']*)'|([\w\-]+)"#;
3132

33+
#[maybe_async]
34+
#[cfg_attr(feature = "async-interface", tokio::main)]
3235
fn main() {
3336
env_logger::init();
3437

@@ -96,7 +99,7 @@ fn main() {
9699
#[cfg(not(feature = "regtest-node"))]
97100
let backend = Nodes::None;
98101

99-
match handle_command(cli_opts, network, backend) {
102+
match maybe_await!(handle_command(cli_opts, network, backend)) {
100103
Ok(result) => println!("{}", result),
101104
Err(e) => {
102105
match e {

0 commit comments

Comments
 (0)