Skip to content

Commit 135cff1

Browse files
committed
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.
1 parent b5d88a5 commit 135cff1

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use chain;
4545
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
4646
use chain::transaction::{OutPoint, TransactionData};
4747
use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, KeysInterface};
48+
use chain::Filter;
4849
use util::logger::Logger;
4950
use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48};
5051
use util::byte_utils;
@@ -1171,6 +1172,20 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
11711172
self.inner.lock().unwrap().get_outputs_to_watch().clone()
11721173
}
11731174

1175+
/// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
1176+
/// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
1177+
/// have been registered.
1178+
pub fn load_outputs_to_watch<F: Deref>(&self, filter: F) where F::Target: chain::Filter {
1179+
let lock = self.inner.lock().unwrap();
1180+
filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1);
1181+
for (txid, outputs) in lock.get_outputs_to_watch().iter() {
1182+
for (index, script_pubkey) in outputs.iter() {
1183+
assert!(*index <= u16::max_value() as u32);
1184+
filter.register_output(&OutPoint { txid: *txid, index: *index as u16 }, script_pubkey);
1185+
}
1186+
}
1187+
}
1188+
11741189
/// Get the list of HTLCs who's status has been updated on chain. This should be called by
11751190
/// ChannelManager via [`chain::Watch::release_pending_monitor_events`].
11761191
///

0 commit comments

Comments
 (0)