Skip to content

Commit 6aa1cf9

Browse files
authored
Merge pull request #2085 from tnull/2023-03-introduce-async-https-feature
Support HTTPS Esplora endpoints in `lightning-transaction-sync` via new feature
2 parents a386d44 + 09038ee commit 6aa1cf9

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,21 @@ jobs:
127127
cd lightning-transaction-sync
128128
cargo build --verbose --color always --features esplora-blocking
129129
cargo build --verbose --color always --features esplora-async
130+
cargo build --verbose --color always --features esplora-async-https
130131
- name: Build transaction sync clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
131132
if: "matrix.build-tx-sync && matrix.coverage"
132133
run: |
133134
cd lightning-transaction-sync
134135
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-blocking
135136
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async
137+
RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features esplora-async-https
136138
- name: Test transaction sync clients on Rust ${{ matrix.toolchain }} with features
137139
if: "matrix.build-tx-sync"
138140
run: |
139141
cd lightning-transaction-sync
140142
cargo test --verbose --color always --features esplora-blocking
141143
cargo test --verbose --color always --features esplora-async
144+
cargo test --verbose --color always --features esplora-async-https
142145
- name: Test backtrace-debug builds on Rust ${{ matrix.toolchain }}
143146
if: "matrix.toolchain == 'stable'"
144147
shell: bash # Default on Winblows is powershell

lightning-transaction-sync/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"]
1616
[features]
1717
default = []
1818
esplora-async = ["async-interface", "esplora-client/async", "futures"]
19+
esplora-async-https = ["esplora-async", "reqwest/rustls-tls"]
1920
esplora-blocking = ["esplora-client/blocking"]
2021
async-interface = []
2122

@@ -25,6 +26,7 @@ bitcoin = { version = "0.29.0", default-features = false }
2526
bdk-macros = "0.6"
2627
futures = { version = "0.3", optional = true }
2728
esplora-client = { version = "0.3.0", default-features = false, optional = true }
29+
reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
2830

2931
[dev-dependencies]
3032
lightning = { version = "0.0.114", path = "../lightning", features = ["std"] }

lightning-transaction-sync/src/esplora.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::error::{TxSyncError, InternalError};
22
use crate::common::{SyncState, FilterQueue, ConfirmedTx};
33

44
use lightning::util::logger::Logger;
5-
use lightning::{log_error, log_given_level, log_info, log_internal, log_debug, log_trace};
5+
use lightning::{log_error, log_info, log_debug, log_trace};
66
use lightning::chain::WatchedOutput;
77
use lightning::chain::{Confirm, Filter};
88

lightning-transaction-sync/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
//!
88
//! ## Features and Backend Support
99
//!
10-
//!- `esplora_blocking` enables syncing against an Esplora backend based on a blocking client.
11-
//!- `esplora_async` enables syncing against an Esplora backend based on an async client.
10+
//!- `esplora-blocking` enables syncing against an Esplora backend based on a blocking client.
11+
//!- `esplora-async` enables syncing against an Esplora backend based on an async client.
12+
//!- `esplora-async-https` enables the async Esplora client with support for HTTPS.
1213
//!
1314
//! ## Version Compatibility
1415
//!

lightning-transaction-sync/tests/integration_tests.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,20 @@ async fn test_esplora_syncs() {
348348
_ => panic!("Unexpected event"),
349349
}
350350
}
351+
352+
#[tokio::test]
353+
#[cfg(any(feature = "esplora-async-https", feature = "esplora-blocking"))]
354+
async fn test_esplora_connects_to_public_server() {
355+
let mut logger = TestLogger {};
356+
let esplora_url = "https://blockstream.info/api".to_string();
357+
let tx_sync = EsploraSyncClient::new(esplora_url, &mut logger);
358+
let confirmable = TestConfirmable::new();
359+
360+
// Check we connect and pick up on new best blocks
361+
assert_eq!(confirmable.best_block.lock().unwrap().1, 0);
362+
#[cfg(feature = "esplora-async-https")]
363+
tx_sync.sync(vec![&confirmable]).await.unwrap();
364+
#[cfg(feature = "esplora-blocking")]
365+
tx_sync.sync(vec![&confirmable]).unwrap();
366+
assert_ne!(confirmable.best_block.lock().unwrap().1, 0);
367+
}

0 commit comments

Comments
 (0)