From: Matt Corallo Date: Sun, 7 Mar 2021 17:58:14 +0000 (-0500) Subject: Add utility in `ChannelMonitor` to reload `chain::Filter` data X-Git-Tag: v0.0.13~4^2~2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=135cff1c954339c3a07d4ea7e970e440632fc5a9;p=rust-lightning Add utility in `ChannelMonitor` to reload `chain::Filter` data The deserialization process for `ChannelManager`/`ChannelMonitor` data includes reloading any relevant `chain::Filter` with data provided from the `ChannelMonitor`, but its nice if we adapt the data to `chain::Filter` calls for users. --- diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 235266127..47ccdc16c 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -45,6 +45,7 @@ use chain; use chain::chaininterface::{BroadcasterInterface, FeeEstimator}; use chain::transaction::{OutPoint, TransactionData}; use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, KeysInterface}; +use chain::Filter; use util::logger::Logger; use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48}; use util::byte_utils; @@ -1171,6 +1172,20 @@ impl ChannelMonitor { self.inner.lock().unwrap().get_outputs_to_watch().clone() } + /// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly + /// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs + /// have been registered. + pub fn load_outputs_to_watch(&self, filter: F) where F::Target: chain::Filter { + let lock = self.inner.lock().unwrap(); + filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1); + for (txid, outputs) in lock.get_outputs_to_watch().iter() { + for (index, script_pubkey) in outputs.iter() { + assert!(*index <= u16::max_value() as u32); + filter.register_output(&OutPoint { txid: *txid, index: *index as u16 }, script_pubkey); + } + } + } + /// Get the list of HTLCs who's status has been updated on chain. This should be called by /// ChannelManager via [`chain::Watch::release_pending_monitor_events`]. ///