-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};
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);
+ }
+ }
+ }
}
continue;
}
num_unconfirmed += unconfirmed_txs.len();
- self.sync_unconfirmed_transactions(&mut sync_state, &confirmables, unconfirmed_txs);
+ sync_state.sync_unconfirmed_transactions(&confirmables, unconfirmed_txs);
},
Err(err) => {
// (Semi-)permanent failure, retry later.
}
num_confirmed += confirmed_txs.len();
- self.sync_confirmed_transactions(
- &mut sync_state,
+ sync_state.sync_confirmed_transactions(
&confirmables,
confirmed_txs,
);
Ok(())
}
- fn sync_confirmed_transactions(
- &self, sync_state: &mut SyncState, 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,
- );
- }
-
- sync_state.watched_transactions.remove(&ctx.tx.txid());
-
- for input in &ctx.tx.input {
- sync_state.watched_outputs.remove(&input.previous_output);
- }
- }
- }
-
#[maybe_async]
fn get_confirmed_transactions(
&self, sync_state: &SyncState,
Ok(unconfirmed_txs)
}
- fn sync_unconfirmed_transactions(
- &self, sync_state: &mut SyncState, confirmables: &Vec<&(dyn Confirm + Sync + Send)>, unconfirmed_txs: Vec<Txid>,
- ) {
- for txid in unconfirmed_txs {
- for c in confirmables {
- c.transaction_unconfirmed(&txid);
- }
-
- sync_state.watched_transactions.insert(txid);
- }
- }
-
/// Returns a reference to the underlying esplora client.
pub fn client(&self) -> &EsploraClientType {
&self.client