From 7a30f3e1181b4a9f053bbfd4b728b92457089454 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Wed, 8 Mar 2023 12:05:57 +0100 Subject: [PATCH] Support HTTPS Esplora endpoints via new feature To support HTTPS endpoints, the async HTTP library `reqwest` needs one of the `-tls` features enabled. While the users could specify this in their own cargo dependencies, we here provide a new `esplora-async-https` feature for conveinience. --- .github/workflows/build.yml | 3 +++ lightning-transaction-sync/Cargo.toml | 2 ++ lightning-transaction-sync/src/lib.rs | 5 +++-- .../tests/integration_tests.rs | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c1472a10..10f71bda0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -127,18 +127,21 @@ jobs: cd lightning-transaction-sync cargo build --verbose --color always --features esplora-blocking cargo build --verbose --color always --features esplora-async + cargo build --verbose --color always --features esplora-async-https - name: Build transaction sync clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation if: "matrix.build-tx-sync && matrix.coverage" run: | cd lightning-transaction-sync RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async + RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async-https - name: Test transaction sync clients on Rust ${{ matrix.toolchain }} with features if: "matrix.build-tx-sync" run: | cd lightning-transaction-sync cargo test --verbose --color always --features esplora-blocking cargo test --verbose --color always --features esplora-async + cargo test --verbose --color always --features esplora-async-https - name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }} if: "matrix.toolchain == 'stable'" shell: bash # Default on Winblows is powershell diff --git a/lightning-transaction-sync/Cargo.toml b/lightning-transaction-sync/Cargo.toml index 395410951..4ad581947 100644 --- a/lightning-transaction-sync/Cargo.toml +++ b/lightning-transaction-sync/Cargo.toml @@ -16,6 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"] [features] default = [] esplora-async = ["async-interface", "esplora-client/async", "futures"] +esplora-async-https = ["esplora-async", "reqwest/rustls-tls"] esplora-blocking = ["esplora-client/blocking"] async-interface = [] @@ -25,6 +26,7 @@ bitcoin = { version = "0.29.0", default-features = false } bdk-macros = "0.6" futures = { version = "0.3", optional = true } esplora-client = { version = "0.3.0", default-features = false, optional = true } +reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] } [dev-dependencies] lightning = { version = "0.0.114", path = "../lightning", features = ["std"] } diff --git a/lightning-transaction-sync/src/lib.rs b/lightning-transaction-sync/src/lib.rs index 791490d9d..05b71d21b 100644 --- a/lightning-transaction-sync/src/lib.rs +++ b/lightning-transaction-sync/src/lib.rs @@ -7,8 +7,9 @@ //! //! ## Features and Backend Support //! -//!- `esplora_blocking` enables syncing against an Esplora backend based on a blocking client. -//!- `esplora_async` enables syncing against an Esplora backend based on an async client. +//!- `esplora-blocking` enables syncing against an Esplora backend based on a blocking client. +//!- `esplora-async` enables syncing against an Esplora backend based on an async client. +//!- `esplora-async-https` enables the async Esplora client with support for HTTPS. //! //! ## Version Compatibility //! diff --git a/lightning-transaction-sync/tests/integration_tests.rs b/lightning-transaction-sync/tests/integration_tests.rs index 276aeabf9..d2f0c70a1 100644 --- a/lightning-transaction-sync/tests/integration_tests.rs +++ b/lightning-transaction-sync/tests/integration_tests.rs @@ -348,3 +348,20 @@ async fn test_esplora_syncs() { _ => panic!("Unexpected event"), } } + +#[tokio::test] +#[cfg(any(feature = "esplora-async-https", feature = "esplora-blocking"))] +async fn test_esplora_connects_to_public_server() { + let mut logger = TestLogger {}; + let esplora_url = "https://blockstream.info/api".to_string(); + let tx_sync = EsploraSyncClient::new(esplora_url, &mut logger); + let confirmable = TestConfirmable::new(); + + // Check we connect and pick up on new best blocks + assert_eq!(confirmable.best_block.lock().unwrap().1, 0); + #[cfg(feature = "esplora-async-https")] + tx_sync.sync(vec![&confirmable]).await.unwrap(); + #[cfg(feature = "esplora-blocking")] + tx_sync.sync(vec![&confirmable]).unwrap(); + assert_ne!(confirmable.best_block.lock().unwrap().1, 0); +} -- 2.39.5