Skip to content

Commit

Permalink
Merge pull request #2685 from tnull/2022-12-add-electrum-sync
Browse files Browse the repository at this point in the history
Add electrum support to `lightning-transaction-sync`
  • Loading branch information
TheBlueMatt authored Nov 27, 2023
2 parents a0183d7 + 31ea90e commit fa0d015
Show file tree
Hide file tree
Showing 16 changed files with 811 additions and 250 deletions.
2 changes: 2 additions & 0 deletions ci/ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ if [[ $RUSTC_MINOR_VERSION -gt 67 && "$HOST_PLATFORM" != *windows* ]]; then
cargo check --verbose --color always --features esplora-async
cargo test --verbose --color always --features esplora-async-https
cargo check --verbose --color always --features esplora-async-https
cargo test --verbose --color always --features electrum
cargo check --verbose --color always --features electrum
popd
fi

Expand Down
8 changes: 4 additions & 4 deletions lightning-transaction-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
default = []
esplora-async = ["async-interface", "esplora-client/async", "futures"]
esplora-async-https = ["esplora-async", "reqwest/rustls-tls"]
esplora-async-https = ["esplora-async", "esplora-client/async-https-rustls"]
esplora-blocking = ["esplora-client/blocking"]
electrum = ["electrum-client"]
async-interface = []

[dependencies]
Expand All @@ -26,10 +27,9 @@ bitcoin = { version = "0.30.2", default-features = false }
bdk-macros = "0.6"
futures = { version = "0.3", optional = true }
esplora-client = { version = "0.6", default-features = false, optional = true }
reqwest = { version = "0.11", optional = true, default-features = false, features = ["json"] }
electrum-client = { version = "0.18.0", optional = true }

[dev-dependencies]
lightning = { version = "0.0.118", path = "../lightning", features = ["std"] }
lightning = { version = "0.0.118", path = "../lightning", features = ["std", "_test_utils"] }
electrsd = { version = "0.26.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
electrum-client = "0.18.0"
tokio = { version = "1.14.0", features = ["full"] }
38 changes: 36 additions & 2 deletions lightning-transaction-sync/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lightning::chain::WatchedOutput;
use lightning::chain::{Confirm, WatchedOutput};
use bitcoin::{Txid, BlockHash, Transaction, OutPoint};
use bitcoin::blockdata::block::Header;
use bitcoin::block::Header;

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

Expand Down Expand Up @@ -28,6 +28,39 @@ impl SyncState {
pending_sync: false,
}
}
pub fn sync_unconfirmed_transactions(
&mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
unconfirmed_txs: Vec<Txid>,
) {
for txid in unconfirmed_txs {
for c in confirmables {
c.transaction_unconfirmed(&txid);
}

self.watched_transactions.insert(txid);
}
}

pub fn sync_confirmed_transactions(
&mut self, confirmables: &Vec<&(dyn Confirm + Sync + Send)>,
confirmed_txs: Vec<ConfirmedTx>
) {
for ctx in confirmed_txs {
for c in confirmables {
c.transactions_confirmed(
&ctx.block_header,
&[(ctx.pos, &ctx.tx)],
ctx.block_height,
);
}

self.watched_transactions.remove(&ctx.tx.txid());

for input in &ctx.tx.input {
self.watched_outputs.remove(&input.previous_output);
}
}
}
}


Expand Down Expand Up @@ -68,6 +101,7 @@ impl FilterQueue {
}
}

#[derive(Debug)]
pub(crate) struct ConfirmedTx {
pub tx: Transaction,
pub block_header: Header,
Expand Down
Loading

0 comments on commit fa0d015

Please sign in to comment.