|
1 | | -use lightning::chain::WatchedOutput; |
| 1 | +use lightning::chain::{Confirm, WatchedOutput}; |
2 | 2 | use bitcoin::{Txid, BlockHash, Transaction, OutPoint}; |
3 | | -use bitcoin::blockdata::block::Header; |
| 3 | +use bitcoin::block::Header; |
4 | 4 |
|
5 | 5 | use std::collections::{HashSet, HashMap}; |
6 | 6 |
|
@@ -28,6 +28,39 @@ impl SyncState { |
28 | 28 | pending_sync: false, |
29 | 29 | } |
30 | 30 | } |
| 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 | + } |
31 | 64 | } |
32 | 65 |
|
33 | 66 |
|
@@ -68,6 +101,7 @@ impl FilterQueue { |
68 | 101 | } |
69 | 102 | } |
70 | 103 |
|
| 104 | +#[derive(Debug)] |
71 | 105 | pub(crate) struct ConfirmedTx { |
72 | 106 | pub tx: Transaction, |
73 | 107 | pub block_header: Header, |
|
0 commit comments