From 1b4f8466e93b2e959773625a81d6b032321f7e1c Mon Sep 17 00:00:00 2001 From: junderw Date: Tue, 25 Jul 2023 20:47:31 -0700 Subject: [PATCH] Fix unwrap that can now possibly be None --- src/new_index/mempool.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/new_index/mempool.rs b/src/new_index/mempool.rs index bdaaaa49..f4b540a3 100644 --- a/src/new_index/mempool.rs +++ b/src/new_index/mempool.rs @@ -206,7 +206,7 @@ impl Mempool { TxHistoryInfo::Funding(info) => { // Liquid requires some additional information from the txo that's not available in the TxHistoryInfo index. #[cfg(feature = "liquid")] - let txo = self.lookup_txo(&entry.get_funded_outpoint()); + let txo = self.lookup_txo(&entry.get_funded_outpoint())?; Some(Utxo { txid: deserialize(&info.txid).expect("invalid txid"), @@ -502,12 +502,18 @@ impl Mempool { processed_count } - pub fn lookup_txo(&self, outpoint: &OutPoint) -> TxOut { + /// Returns None if the lookup fails (mempool transaction RBF-ed etc.) + pub fn lookup_txo(&self, outpoint: &OutPoint) -> Option { let mut outpoints = BTreeSet::new(); outpoints.insert(*outpoint); - self.lookup_txos(&outpoints).remove(outpoint).unwrap() + // This can possibly be None now + self.lookup_txos(&outpoints).remove(outpoint) } + /// For a given set of OutPoints, return a HashMap + /// + /// Not all OutPoints from mempool transactions are guaranteed to be there. + /// Ensure you deal with the None case in your logic. pub fn lookup_txos(&self, outpoints: &BTreeSet) -> HashMap { let _timer = self .latency