Merge pull request #833 from TheBlueMatt/2021-03-no-xs
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Mon, 8 Mar 2021 21:37:27 +0000 (13:37 -0800)
committerGitHub <noreply@github.com>
Mon, 8 Mar 2021 21:37:27 +0000 (13:37 -0800)
Drop C bindings (which are now in a separate repo)

lightning/src/chain/chainmonitor.rs
lightning/src/chain/channelmonitor.rs

index de826d054d3716bd41df35e03706ac3e900c1322..0cf2d56a14eb5a79bb489b7fb7c27e80c7305597 100644 (file)
@@ -193,12 +193,7 @@ where C::Target: chain::Filter,
                        log_trace!(self.logger, "Got new Channel Monitor for channel {}", log_bytes!(funding_txo.0.to_channel_id()[..]));
 
                        if let Some(ref chain_source) = self.chain_source {
-                               chain_source.register_tx(&funding_txo.0.txid, &funding_txo.1);
-                               for (txid, outputs) in monitor.get_outputs_to_watch().iter() {
-                                       for (idx, script_pubkey) in outputs.iter() {
-                                               chain_source.register_output(&OutPoint { txid: *txid, index: *idx as u16 }, script_pubkey);
-                                       }
-                               }
+                               monitor.load_outputs_to_watch(chain_source);
                        }
                }
                entry.insert(monitor);
index 2352661271f46d8f48bb35703b6e1579951381dd..c2c791c4b172b8335c43117ff191e93320c3cddc 100644 (file)
@@ -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;
@@ -1165,10 +1166,23 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
 
        /// Gets a list of txids, with their output scripts (in the order they appear in the
        /// transaction), which we must learn about spends of via block_connected().
-       ///
-       /// (C-not exported) because we have no HashMap bindings
-       pub fn get_outputs_to_watch(&self) -> HashMap<Txid, Vec<(u32, Script)>> {
-               self.inner.lock().unwrap().get_outputs_to_watch().clone()
+       pub fn get_outputs_to_watch(&self) -> Vec<(Txid, Vec<(u32, Script)>)> {
+               self.inner.lock().unwrap().get_outputs_to_watch()
+                       .iter().map(|(txid, outputs)| (*txid, outputs.clone())).collect()
+       }
+
+       /// 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<F: Deref>(&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