Browse Source

prevent unwrap(), poisoned data

pull/27/head
Deniod 6 months ago
parent
commit
35ce90eec9
  1. 45
      lib/src/lightwallet.rs

45
lib/src/lightwallet.rs

@ -1470,26 +1470,43 @@ pub fn scan_full_tx(&self, tx: &Transaction, height: i32, datetime: u64) {
// Do it in a short scope because of the write lock.
{
info!("A sapling output was sent in {}", tx.txid());
let mut txs = self.txs.write().unwrap();
if txs.get(&tx.txid()).unwrap().outgoing_metadata.iter()
.find(|om| om.address == address && om.value == note.value && om.memo == memo)
.is_some() {
warn!("Duplicate outgoing metadata");
continue;
}
match self.txs.write() {
Ok(mut txs) => {
match txs.get(&tx.txid()) {
Some(wtx) => {
if wtx.outgoing_metadata.iter()
.any(|om| om.address == address && om.value == note.value && om.memo == memo)
{
warn!("Duplicate outgoing metadata");
continue;
}
// Write the outgoing metadata
txs.get_mut(&tx.txid()).unwrap()
.outgoing_metadata
.push(OutgoingTxMetadata{
address, value: note.value, memo,
});
// Write the outgoing metadata
txs.get_mut(&tx.txid()).unwrap()
.outgoing_metadata
.push(OutgoingTxMetadata {
address,
value: note.value,
memo,
});
},
None => {
error!("Can not find any entry for txid : {}", tx.txid());
continue;
}
}
},
Err(poisoned) => {
error!("Lock is poisoned: {}", poisoned);
return;
}
}
}
},
None => {}
};
}
}
}
// Mark this Tx as scanned
{
let mut txs = self.txs.write().unwrap();

Loading…
Cancel
Save