Skip to content

Commit 82f4c10

Browse files
committed
Move sync_ methods to SyncState
1 parent e14e2c3 commit 82f4c10

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

lightning-transaction-sync/src/common.rs

Lines changed: 35 additions & 2 deletions
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

lightning-transaction-sync/src/esplora.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ where
123123
continue;
124124
}
125125
num_unconfirmed += unconfirmed_txs.len();
126-
self.sync_unconfirmed_transactions(&mut sync_state, &confirmables, unconfirmed_txs);
126+
sync_state.sync_unconfirmed_transactions(&confirmables, unconfirmed_txs);
127127
},
128128
Err(err) => {
129129
// (Semi-)permanent failure, retry later.
@@ -169,8 +169,7 @@ where
169169
}
170170

171171
num_confirmed += confirmed_txs.len();
172-
self.sync_confirmed_transactions(
173-
&mut sync_state,
172+
sync_state.sync_confirmed_transactions(
174173
&confirmables,
175174
confirmed_txs,
176175
);
@@ -221,26 +220,6 @@ where
221220
Ok(())
222221
}
223222

224-
fn sync_confirmed_transactions(
225-
&self, sync_state: &mut SyncState, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, confirmed_txs: Vec<ConfirmedTx>,
226-
) {
227-
for ctx in confirmed_txs {
228-
for c in confirmables {
229-
c.transactions_confirmed(
230-
&ctx.block_header,
231-
&[(ctx.pos, &ctx.tx)],
232-
ctx.block_height,
233-
);
234-
}
235-
236-
sync_state.watched_transactions.remove(&ctx.tx.txid());
237-
238-
for input in &ctx.tx.input {
239-
sync_state.watched_outputs.remove(&input.previous_output);
240-
}
241-
}
242-
}
243-
244223
#[maybe_async]
245224
fn get_confirmed_transactions(
246225
&self, sync_state: &SyncState,
@@ -360,18 +339,6 @@ where
360339
Ok(unconfirmed_txs)
361340
}
362341

363-
fn sync_unconfirmed_transactions(
364-
&self, sync_state: &mut SyncState, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, unconfirmed_txs: Vec<Txid>,
365-
) {
366-
for txid in unconfirmed_txs {
367-
for c in confirmables {
368-
c.transaction_unconfirmed(&txid);
369-
}
370-
371-
sync_state.watched_transactions.insert(txid);
372-
}
373-
}
374-
375342
/// Returns a reference to the underlying esplora client.
376343
pub fn client(&self) -> &EsploraClientType {
377344
&self.client

0 commit comments

Comments
 (0)