Skip to content

Commit 154dfe5

Browse files
TheBlueMattjkczyz
andcommitted
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 <[email protected]> Co-authored-by: Matt Corallo <[email protected]>
1 parent 135cff1 commit 154dfe5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,16 +1166,15 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
11661166

11671167
/// Gets a list of txids, with their output scripts (in the order they appear in the
11681168
/// transaction), which we must learn about spends of via block_connected().
1169-
///
1170-
/// (C-not exported) because we have no HashMap bindings
1171-
pub fn get_outputs_to_watch(&self) -> HashMap<Txid, Vec<(u32, Script)>> {
1172-
self.inner.lock().unwrap().get_outputs_to_watch().clone()
1169+
pub fn get_outputs_to_watch(&self) -> Vec<(Txid, Vec<(u32, Script)>)> {
1170+
self.inner.lock().unwrap().get_outputs_to_watch()
1171+
.iter().map(|(txid, outputs)| (*txid, outputs.clone())).collect()
11731172
}
11741173

11751174
/// Loads the funding txo and outputs to watch into the given `chain::Filter` by repeatedly
11761175
/// calling `chain::Filter::register_output` and `chain::Filter::register_tx` until all outputs
11771176
/// have been registered.
1178-
pub fn load_outputs_to_watch<F: Deref>(&self, filter: F) where F::Target: chain::Filter {
1177+
pub fn load_outputs_to_watch<F: Deref>(&self, filter: &F) where F::Target: chain::Filter {
11791178
let lock = self.inner.lock().unwrap();
11801179
filter.register_tx(&lock.get_funding_txo().0.txid, &lock.get_funding_txo().1);
11811180
for (txid, outputs) in lock.get_outputs_to_watch().iter() {

0 commit comments

Comments
 (0)