mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
Move sync_
methods to SyncState
This commit is contained in:
parent
e14e2c3fba
commit
82f4c10e18
2 changed files with 37 additions and 37 deletions
|
@ -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};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ where
|
|||
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.
|
||||
|
@ -169,8 +169,7 @@ where
|
|||
}
|
||||
|
||||
num_confirmed += confirmed_txs.len();
|
||||
self.sync_confirmed_transactions(
|
||||
&mut sync_state,
|
||||
sync_state.sync_confirmed_transactions(
|
||||
&confirmables,
|
||||
confirmed_txs,
|
||||
);
|
||||
|
@ -221,26 +220,6 @@ where
|
|||
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,
|
||||
|
@ -360,18 +339,6 @@ where
|
|||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue