From 3ad99c7a3d32c5b9601524ee4ea0e40551262b8a Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 19 Sep 2019 13:40:09 -0700 Subject: [PATCH] Warning check for duplicate note insertion --- src/lightwallet/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lightwallet/mod.rs b/src/lightwallet/mod.rs index 36e6a2e..8c55dcd 100644 --- a/src/lightwallet/mod.rs +++ b/src/lightwallet/mod.rs @@ -771,8 +771,7 @@ impl LightWallet { info!("Txid {} belongs to wallet", tx.txid); - for spend in &tx.shielded_spends { - // TODO: Add up the spent value here and add it to the WalletTx as a Spent + for spend in &tx.shielded_spends { let txid = nfs .iter() .find(|(nf, _, _)| &nf[..] == &spend.nf[..]) @@ -801,16 +800,19 @@ impl LightWallet { } let tx_entry = txs.get_mut(&tx.txid).unwrap(); tx_entry.total_shielded_value_spent = total_shielded_value_spent; + // Save notes. for output in tx .shielded_outputs .into_iter() { info!("Received sapling output"); - tx_entry.notes.push(SaplingNoteData::new( - &self.extfvks[output.account], - output - )); + + let new_note = SaplingNoteData::new(&self.extfvks[output.account], output); + match tx_entry.notes.iter().find(|nd| nd.nullifier == new_note.nullifier) { + None => tx_entry.notes.push(new_note), + Some(_) => warn!("Tried to insert duplicate note for Tx {}", tx.txid) + }; } }