Skip to content

Commit 70ded15

Browse files
committed
Move sync_ methods to SyncState
1 parent 277e43e commit 70ded15

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

lightning-transaction-sync/src/common.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lightning::chain::WatchedOutput;
1+
use lightning::chain::{Confirm, WatchedOutput};
22
use bitcoin::{Txid, BlockHash, Transaction, BlockHeader, OutPoint};
33

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

3265

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,
@@ -359,18 +338,6 @@ where
359338
Ok(unconfirmed_txs)
360339
}
361340

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

0 commit comments

Comments
 (0)