Skip to content

Commit

Permalink
Refactor lookup_txos() to use zip()
Browse files Browse the repository at this point in the history
Following #89 (comment)
  • Loading branch information
shesek authored and philippem committed Aug 13, 2024
1 parent 75e79f8 commit fca4867
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,16 +1030,15 @@ fn get_previous_txos(block_entries: &[BlockEntry]) -> BTreeSet<OutPoint> {

fn lookup_txos(txstore_db: &DB, outpoints: BTreeSet<OutPoint>) -> Result<HashMap<OutPoint, TxOut>> {
let keys = outpoints.iter().map(TxOutRow::key).collect::<Vec<_>>();
let mut remain_outpoints = outpoints.into_iter();
txstore_db
.multi_get(keys)
.into_iter()
.map(|res| {
let outpoint = remain_outpoints.next().unwrap();
match res.unwrap() {
Some(txo) => Ok((outpoint, deserialize(&txo).expect("failed to parse TxOut"))),
None => Err(format!("missing txo {}", outpoint).into()),
}
.zip(outpoints)
.map(|(res, outpoint)| {
let txo = res
.unwrap()
.ok_or_else(|| format!("missing txo {}", outpoint))?;
Ok((outpoint, deserialize(&txo).expect("failed to parse TxOut")))
})
.collect()
}
Expand Down

0 comments on commit fca4867

Please sign in to comment.