]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add ChannelMonitor::transactions_confirmed
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 24 Mar 2021 22:47:44 +0000 (18:47 -0400)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 14 Apr 2021 19:57:05 +0000 (12:57 -0700)
Define an Electrum-friendly interface for ChannelMonitor where
transactions are confirmed independently of updating the last connected
block.

lightning/src/chain/channelmonitor.rs

index 0fb04c457d18b019ec1dab4c785ddb1e4f597f92..1a0b3dcdfcaeee1ea2b48b863496e08ff5182dab 100644 (file)
@@ -1303,6 +1303,30 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
                self.inner.lock().unwrap().block_disconnected(
                        header, height, broadcaster, fee_estimator, logger)
        }
+
+       /// Processes transactions from a block with the given header and height, returning new outputs
+       /// to watch. See [`block_connected`] for details.
+       ///
+       /// TODO: Expand docs.
+       ///
+       /// [`block_connected`]: Self::block_connected
+       pub fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
+               &self,
+               header: &BlockHeader,
+               txdata: &TransactionData,
+               height: u32,
+               broadcaster: B,
+               fee_estimator: F,
+               logger: L,
+       ) -> Vec<(Txid, Vec<(u32, TxOut)>)>
+       where
+               B::Target: BroadcasterInterface,
+               F::Target: FeeEstimator,
+               L::Target: Logger,
+       {
+               self.inner.lock().unwrap().transactions_confirmed(
+                       header, txdata, height, broadcaster, fee_estimator, logger)
+       }
 }
 
 impl<Signer: Sign> ChannelMonitorImpl<Signer> {
@@ -2003,6 +2027,24 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                where B::Target: BroadcasterInterface,
                      F::Target: FeeEstimator,
                                        L::Target: Logger,
+       {
+               self.best_block = BestBlock::new(header.block_hash(), height);
+               self.transactions_confirmed(header, txdata, height, broadcaster, fee_estimator, logger)
+       }
+
+       fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
+               &mut self,
+               header: &BlockHeader,
+               txdata: &TransactionData,
+               height: u32,
+               broadcaster: B,
+               fee_estimator: F,
+               logger: L,
+       ) -> Vec<(Txid, Vec<(u32, TxOut)>)>
+       where
+               B::Target: BroadcasterInterface,
+               F::Target: FeeEstimator,
+               L::Target: Logger,
        {
                let txn_matched = self.filter_block(txdata);
                for tx in &txn_matched {
@@ -2135,7 +2177,6 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                }
 
                self.onchain_tx_handler.update_claims_view(&txn_matched, claimable_outpoints, Some(height), &&*broadcaster, &&*fee_estimator, &&*logger);
-               self.best_block = BestBlock::new(block_hash, height);
 
                // Determine new outputs to watch by comparing against previously known outputs to watch,
                // updating the latter in the process.