]> Untitled Git - bdk-cli/commitdiff
Use async with esplora-reqwest
authorDaniela Brozzoni <danielabrozzoni@protonmail.com>
Wed, 24 Aug 2022 22:06:53 +0000 (23:06 +0100)
committerDaniela Brozzoni <danielabrozzoni@protonmail.com>
Fri, 2 Sep 2022 14:32:46 +0000 (16:32 +0200)
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.

CHANGELOG.md
Cargo.lock
Cargo.toml
src/handlers.rs
src/main.rs

index 41f1481c9d7ce6fcfe71f1a0baba62d351260490..a28e5ca8fa4816f500f5fb941617bcdd1f56d844 100644 (file)
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 - Rewrite relevant doc comments as `structopt` help document.
 - Update `bdk` and `bdk-reserves` to v0.19.0.
 - Change default database to `sqlite`.
+- Change the `esplora-reqwest` feature to always use async mode
 
 ## [0.5.0]
 
index 49c1c251e5d6b96fece63b0de7d9ae4ad0837b06..49e5ab63b2b8c0b06d4ee3ca863309674b0226f8 100644 (file)
@@ -149,6 +149,7 @@ dependencies = [
  "rustyline",
  "serde_json",
  "structopt",
+ "tokio",
  "zeroize",
 ]
 
@@ -480,6 +481,22 @@ dependencies = [
  "url",
 ]
 
+[[package]]
+name = "core-foundation"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
+[[package]]
+name = "core-foundation-sys"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
+
 [[package]]
 name = "crc32fast"
 version = "1.3.2"
@@ -698,6 +715,21 @@ version = "1.0.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
 
+[[package]]
+name = "foreign-types"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
+dependencies = [
+ "foreign-types-shared",
+]
+
+[[package]]
+name = "foreign-types-shared"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
+
 [[package]]
 name = "form_urlencoded"
 version = "1.0.1"
@@ -983,6 +1015,19 @@ dependencies = [
  "want",
 ]
 
+[[package]]
+name = "hyper-tls"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
+dependencies = [
+ "bytes",
+ "hyper",
+ "native-tls",
+ "tokio",
+ "tokio-native-tls",
+]
+
 [[package]]
 name = "idna"
 version = "0.2.1"
@@ -1195,6 +1240,24 @@ dependencies = [
  "windows-sys 0.36.1",
 ]
 
+[[package]]
+name = "native-tls"
+version = "0.2.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9"
+dependencies = [
+ "lazy_static",
+ "libc",
+ "log",
+ "openssl",
+ "openssl-probe",
+ "openssl-sys",
+ "schannel",
+ "security-framework",
+ "security-framework-sys",
+ "tempfile",
+]
+
 [[package]]
 name = "nibble_vec"
 version = "0.1.0"
@@ -1227,12 +1290,67 @@ dependencies = [
  "minimal-lexical",
 ]
 
+[[package]]
+name = "num_cpus"
+version = "1.13.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1"
+dependencies = [
+ "hermit-abi",
+ "libc",
+]
+
 [[package]]
 name = "once_cell"
 version = "1.12.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
 
+[[package]]
+name = "openssl"
+version = "0.10.41"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0"
+dependencies = [
+ "bitflags",
+ "cfg-if",
+ "foreign-types",
+ "libc",
+ "once_cell",
+ "openssl-macros",
+ "openssl-sys",
+]
+
+[[package]]
+name = "openssl-macros"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "openssl-probe"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
+
+[[package]]
+name = "openssl-sys"
+version = "0.9.75"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f"
+dependencies = [
+ "autocfg 1.1.0",
+ "cc",
+ "libc",
+ "pkg-config",
+ "vcpkg",
+]
+
 [[package]]
 name = "parking_lot"
 version = "0.11.2"
@@ -1597,17 +1715,20 @@ dependencies = [
  "http",
  "http-body",
  "hyper",
+ "hyper-tls",
  "ipnet",
  "js-sys",
  "lazy_static",
  "log",
  "mime",
+ "native-tls",
  "percent-encoding",
  "pin-project-lite",
  "serde",
  "serde_json",
  "serde_urlencoded",
  "tokio",
+ "tokio-native-tls",
  "tokio-socks",
  "tower-service",
  "url",
@@ -1727,6 +1848,16 @@ version = "1.0.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
 
+[[package]]
+name = "schannel"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2"
+dependencies = [
+ "lazy_static",
+ "windows-sys 0.36.1",
+]
+
 [[package]]
 name = "scopeguard"
 version = "1.1.0"
@@ -1792,6 +1923,29 @@ dependencies = [
  "cc",
 ]
 
+[[package]]
+name = "security-framework"
+version = "2.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c"
+dependencies = [
+ "bitflags",
+ "core-foundation",
+ "core-foundation-sys",
+ "libc",
+ "security-framework-sys",
+]
+
+[[package]]
+name = "security-framework-sys"
+version = "2.6.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
 [[package]]
 name = "semver"
 version = "0.9.0"
@@ -2151,12 +2305,35 @@ dependencies = [
  "libc",
  "memchr",
  "mio",
+ "num_cpus",
  "once_cell",
  "pin-project-lite",
  "socket2",
+ "tokio-macros",
  "winapi",
 ]
 
+[[package]]
+name = "tokio-macros"
+version = "1.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "tokio-native-tls"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
+dependencies = [
+ "native-tls",
+ "tokio",
+]
+
 [[package]]
 name = "tokio-socks"
 version = "0.5.1"
index 8ec25994f25ecc9f89a6957e83ab673441c685b0..df0307bc0ffe53961bcd7bf2cdaeb47ffd1aafc2 100644 (file)
@@ -27,6 +27,7 @@ fd-lock = { version = "=3.0.2", optional = true }
 regex = { version = "1", optional = true }
 bdk-reserves = { version = "0.19", optional = true}
 electrsd = { version= "0.12", features = ["trigger", "bitcoind_22_0"], optional = true}
+tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"], optional = true }
 
 [features]
 default = ["repl", "sqlite-db"]
@@ -44,7 +45,8 @@ electrum = ["bdk/electrum"]
 compact_filters = ["bdk/compact_filters"]
 esplora = []
 esplora-ureq = ["esplora", "bdk/use-esplora-ureq"]
-esplora-reqwest = ["esplora", "bdk/use-esplora-reqwest"]
+async-interface = ["bdk/async-interface", "tokio"]
+esplora-reqwest = ["esplora", "bdk/use-esplora-reqwest", "bdk/reqwest-default-tls", "async-interface"]
 
 # Use this to consensus verify transactions at sync time
 verify = ["bdk/verify"]
@@ -65,4 +67,4 @@ regtest-node = []
 regtest-bitcoin = ["regtest-node" , "rpc", "electrsd"]
 regtest-electrum = ["regtest-node", "electrum", "electrsd/electrs_0_8_10"]
 regtest-esplora-ureq = ["regtest-node", "esplora-ureq", "electrsd/esplora_a33e97e1"]
-regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]
\ No newline at end of file
+regtest-esplora-reqwest = ["regtest-node", "esplora-reqwest", "electrsd/esplora_a33e97e1"]
index 3806b03393d750dc37d8a740ed3790fa0b234f92..aa25b5e43515dd55304d9928d4e785630a94fc39 100644 (file)
@@ -65,6 +65,7 @@ use bdk::{
     bitcoin::{Address, OutPoint, TxOut},
     blockchain::Capability,
 };
+use bdk_macros::maybe_async;
 #[cfg(any(
     feature = "electrum",
     feature = "esplora",
@@ -72,7 +73,6 @@ use bdk::{
     feature = "rpc"
 ))]
 use bdk_macros::maybe_await;
-use bdk_macros::maybe_async;
 #[cfg(feature = "reserves")]
 use bdk_reserves::reserves::verify_proof;
 #[cfg(feature = "reserves")]
@@ -557,6 +557,7 @@ pub fn get_outpoints_for_address(
         .collect()
 }
 
+#[maybe_async]
 pub fn handle_command(
     cli_opts: CliOpts,
     network: Network,
@@ -577,7 +578,11 @@ pub fn handle_command(
             let database = open_database(&wallet_opts)?;
             let blockchain = new_blockchain(network, &wallet_opts, &_backend)?;
             let wallet = new_wallet(network, &wallet_opts, database)?;
-            let result = handle_online_wallet_subcommand(&wallet, &blockchain, online_subcommand)?;
+            let result = maybe_await!(handle_online_wallet_subcommand(
+                &wallet,
+                &blockchain,
+                online_subcommand
+            ))?;
             serde_json::to_string_pretty(&result)?
         }
         CliSubCommand::Wallet {
@@ -657,11 +662,11 @@ pub fn handle_command(
                             ))]
                             ReplSubCommand::OnlineWalletSubCommand(online_subcommand) => {
                                 let blockchain = new_blockchain(network, &wallet_opts, &_backend)?;
-                                handle_online_wallet_subcommand(
+                                maybe_await!(handle_online_wallet_subcommand(
                                     &wallet,
                                     &blockchain,
                                     online_subcommand,
-                                )
+                                ))
                             }
                             ReplSubCommand::OfflineWalletSubCommand(offline_subcommand) => {
                                 handle_offline_wallet_subcommand(
index edb3e4df74941366de465597cc4c0bd9c5a4930a..fced15427f4eaee1e24e7152a8d34f3addaecb4c 100644 (file)
@@ -24,11 +24,14 @@ use log::{debug, error, warn};
 use crate::commands::CliOpts;
 use crate::handlers::*;
 use bdk::{bitcoin, Error};
+use bdk_macros::{maybe_async, maybe_await};
 use structopt::StructOpt;
 
 #[cfg(feature = "repl")]
 const REPL_LINE_SPLIT_REGEX: &str = r#""([^"]*)"|'([^']*)'|([\w\-]+)"#;
 
+#[maybe_async]
+#[cfg_attr(feature = "async-interface", tokio::main)]
 fn main() {
     env_logger::init();
 
@@ -96,7 +99,7 @@ fn main() {
     #[cfg(not(feature = "regtest-node"))]
     let backend = Nodes::None;
 
-    match handle_command(cli_opts, network, backend) {
+    match maybe_await!(handle_command(cli_opts, network, backend)) {
         Ok(result) => println!("{}", result),
         Err(e) => {
             match e {