Skip to content

Commit

Permalink
Fix unwrap that can now possibly be None
Browse files Browse the repository at this point in the history
  • Loading branch information
junderw committed Jul 26, 2023
1 parent 96e4324 commit 1b4f846
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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<TxOut> {
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<OutPoint, TxOut>
///
/// 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<OutPoint>) -> HashMap<OutPoint, TxOut> {
let _timer = self
.latency
Expand Down

0 comments on commit 1b4f846

Please sign in to comment.