Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add electrum support to lightning-transaction-sync #2685

Merged
merged 10 commits into from
Nov 27, 2023
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);
}
tnull marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading