Skip to content

Commit fa0d015

Browse files
authored
Merge pull request #2685 from tnull/2022-12-add-electrum-sync
Add electrum support to `lightning-transaction-sync`
2 parents a0183d7 + 31ea90e commit fa0d015

File tree

16 files changed

+811
-250
lines changed

16 files changed

+811
-250
lines changed

ci/ci-tests.sh

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ if [[ $RUSTC_MINOR_VERSION -gt 67 && "$HOST_PLATFORM" != *windows* ]]; then
6868
cargo check --verbose --color always --features esplora-async
6969
cargo test --verbose --color always --features esplora-async-https
7070
cargo check --verbose --color always --features esplora-async-https
71+
cargo test --verbose --color always --features electrum
72+
cargo check --verbose --color always --features electrum
7173
popd
7274
fi
7375

lightning-transaction-sync/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ 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"]
19+
esplora-async-https = ["esplora-async", "esplora-client/async-https-rustls"]
2020
esplora-blocking = ["esplora-client/blocking"]
21+
electrum = ["electrum-client"]
2122
async-interface = []
2223

2324
[dependencies]
@@ -26,10 +27,9 @@ bitcoin = { version = "0.30.2", default-features = false }
2627
bdk-macros = "0.6"
2728
futures = { version = "0.3", optional = true }
2829
esplora-client = { version = "0.6", default-features = false, optional = true }
29-
reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
30+
electrum-client = { version = "0.18.0", optional = true }
3031

3132
[dev-dependencies]
32-
lightning = { version = "0.0.118", path = "../lightning", features = ["std"] }
33+
lightning = { version = "0.0.118", path = "../lightning", features = ["std", "_test_utils"] }
3334
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
34-
electrum-client = "0.18.0"
3535
tokio = { version = "1.14.0", features = ["full"] }

lightning-transaction-sync/src/common.rs

+36-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use lightning::chain::WatchedOutput;
1+
use lightning::chain::{Confirm, WatchedOutput};
22
use bitcoin::{Txid, BlockHash, Transaction, OutPoint};
3-
use bitcoin::blockdata::block::Header;
3+
use bitcoin::block::Header;
44

55
use std::collections::{HashSet, HashMap};
66

@@ -28,6 +28,39 @@ impl SyncState {
2828
pending_sync: false,
2929
}
3030
}
31+
pub fn sync_unconfirmed_transactions(
32+
&mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
33+
unconfirmed_txs: Vec<Txid>,
34+
) {
35+
for txid in unconfirmed_txs {
36+
for c in confirmables {
37+
c.transaction_unconfirmed(&txid);
38+
}
39+
40+
self.watched_transactions.insert(txid);
41+
}
42+
}
43+
44+
pub fn sync_confirmed_transactions(
45+
&mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
46+
confirmed_txs: Vec<ConfirmedTx>
47+
) {
48+
for ctx in confirmed_txs {
49+
for c in confirmables {
50+
c.transactions_confirmed(
51+
&ctx.block_header,
52+
&[(ctx.pos, &ctx.tx)],
53+
ctx.block_height,
54+
);
55+
}
56+
57+
self.watched_transactions.remove(&ctx.tx.txid());
58+
59+
for input in &ctx.tx.input {
60+
self.watched_outputs.remove(&input.previous_output);
61+
}
62+
}
63+
}
3164
}
3265

3366

@@ -68,6 +101,7 @@ impl FilterQueue {
68101
}
69102
}
70103

104+
#[derive(Debug)]
71105
pub(crate) struct ConfirmedTx {
72106
pub tx: Transaction,
73107
pub block_header: Header,

0 commit comments

Comments
 (0)