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.
This commit is contained in:
Elias Rohrer 2023-03-08 12:05:57 +01:00
parent ccac926671
commit 7a30f3e118
No known key found for this signature in database
GPG key ID: 36153082BDF676FD
4 changed files with 25 additions and 2 deletions

View file

@ -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

View file

@ -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"] }

View file

@ -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
//!

View file

@ -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);
}