Skip to content

Commit a9d7726

Browse files
committed
Merge #115: Use async with esplora-reqwest
8d876ef Use async with esplora-reqwest (Daniela Brozzoni) a9dffc3 Remove wrong 'cfg()' (Daniela Brozzoni) Pull request description: ### Description 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. ### Notes to the reviewers ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk-cli/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing #### New Features: * [x] I've added tests for the new feature * [ ] I've added docs for the new feature * [x] I've updated `CHANGELOG.md` ACKs for top commit: afilini: reACK 8d876ef Tree-SHA512: 3e6c8ebc0c9ac772f28a6282b7478b436d519fdd081e98f282c00d520cc2ed400636407be2e4ba9f9203bd7141cc35bdc85430f9689c300f01945b76d411cf68
2 parents be36eeb + 8d876ef commit a9d7726

File tree

5 files changed

+196
-7
lines changed

5 files changed

+196
-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: 177 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"], optional = true }
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", "tokio"]
49+
esplora-reqwest = ["esplora", "bdk/use-esplora-reqwest", "bdk/reqwest-default-tls", "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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +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
))]
74-
use bdk_macros::{maybe_async, maybe_await};
75+
use bdk_macros::maybe_await;
7576
#[cfg(feature = "reserves")]
7677
use bdk_reserves::reserves::verify_proof;
7778
#[cfg(feature = "reserves")]
@@ -556,6 +557,7 @@ pub fn get_outpoints_for_address(
556557
.collect()
557558
}
558559

560+
#[maybe_async]
559561
pub fn handle_command(
560562
cli_opts: CliOpts,
561563
network: Network,
@@ -576,7 +578,11 @@ pub fn handle_command(
576578
let database = open_database(&wallet_opts)?;
577579
let blockchain = new_blockchain(network, &wallet_opts, &_backend)?;
578580
let wallet = new_wallet(network, &wallet_opts, database)?;
579-
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+
))?;
580586
serde_json::to_string_pretty(&result)?
581587
}
582588
CliSubCommand::Wallet {
@@ -656,11 +662,11 @@ pub fn handle_command(
656662
))]
657663
ReplSubCommand::OnlineWalletSubCommand(online_subcommand) => {
658664
let blockchain = new_blockchain(network, &wallet_opts, &_backend)?;
659-
handle_online_wallet_subcommand(
665+
maybe_await!(handle_online_wallet_subcommand(
660666
&wallet,
661667
&blockchain,
662668
online_subcommand,
663-
)
669+
))
664670
}
665671
ReplSubCommand::OfflineWalletSubCommand(offline_subcommand) => {
666672
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)