]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Move `sync_` methods to `SyncState`
authorElias Rohrer <dev@tnull.de>
Tue, 7 Nov 2023 08:21:40 +0000 (09:21 +0100)
committerElias Rohrer <dev@tnull.de>
Thu, 23 Nov 2023 08:30:57 +0000 (09:30 +0100)
lightning-transaction-sync/src/common.rs
lightning-transaction-sync/src/esplora.rs

index 45f18afb99bb07632c9590c1bc4e97c686dcab90..91a9c90b2e8f86bec41e9a1ccb8d5f86587f2a40 100644 (file)
@@ -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);
+                       }
+               }
+       }
 }
 
 
index 1a3ae2c224dfcc5657a9416508c58fec9518e155..3f0d4828355161ac0a807a9004636ad3961814ac 100644 (file)
@@ -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