From: Matt Corallo Date: Sun, 7 Mar 2021 18:00:11 +0000 (-0500) Subject: Make `get_outputs_to_watch` return a `Vec` instead of a `HashMap` X-Git-Tag: v0.0.13~4^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=154dfe57555b154c1f399c2328196b2a5da69689;hp=135cff1c954339c3a07d4ea7e970e440632fc5a9;p=rust-lightning Make `get_outputs_to_watch` return a `Vec` instead of a `HashMap` `get_outputs_to_watch` returned a reference to an existing `HashMap` avoiding extra clones, but there isn't a huge reason to do so now that we have to clone to copy it out of the `ChannelMonitor` mutex. Instead, return a `Vec` since it may be less memory and it allows us to have a bindings C mapping for the function. Co-authored-by: Jeffrey Czyz Co-authored-by: Matt Corallo --- diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 47ccdc16..c2c791c4 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -1166,16 +1166,15 @@ impl ChannelMonitor { /// 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> { - 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(&self, filter: F) where F::Target: chain::Filter { + 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() {