Skip to content

Commit

Permalink
mark spent notes
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Apr 3, 2024
1 parent 23a2ae8 commit 2f28306
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions zcash_client_backend/src/data_api/mem_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ impl WalletWrite for MemoryWalletDb {
transaction.sapling_outputs().iter().map(|o| {
// Insert the Sapling nullifiers of the spent notes into the `sapling_spends` map.
let nullifier = o.note().nf(&nk, o.note_commitment_tree_position().into());
// TODO: Populate the bool field properly.
self.sapling_spends.entry(nullifier).or_insert((txid, true));
self.sapling_spends
.entry(nullifier)
.or_insert((txid, false));

// Insert the memo into the `memos` map.
let note_id = NoteId::new(
Expand All @@ -429,7 +430,7 @@ impl WalletWrite for MemoryWalletDb {
if let Some(nullifier) = o.nf() {
self.orchard_spends
.entry(*nullifier)
.or_insert((txid, true));
.or_insert((txid, false));
}

// Insert the memo into the `memos` map.
Expand Down Expand Up @@ -462,6 +463,23 @@ impl WalletWrite for MemoryWalletDb {
},
);

// Mark the Sapling nullifiers of the spent notes as spent in the `sapling_spends` map.
transaction.sapling_spends().iter().map(|s| {
let nullifier = s.nf();
if let Some((txid, spent)) = self.sapling_spends.get_mut(&nullifier) {
*spent = true;
}
});

#[cfg(feature = "orchard")]
// Mark the Orchard nullifiers of the spent notes as spent in the `orchard_spends` map.
transaction.orchard_spends().iter().map(|s| {
let nullifier = s.nf();
if let Some((txid, spent)) = self.orchard_spends.get_mut(&nullifier) {
*spent = true;
}
});

// TODO: Is `self.tx_idx` field filled with all the transaction ids from the scanned blocks ?
self.tx_idx.insert(txid, block.block_height);
transactions.insert(txid, transaction);
Expand Down Expand Up @@ -490,10 +508,6 @@ impl WalletWrite for MemoryWalletDb {
self.orchard_tree
.batch_insert(pos, block_commitments.orchard.into_iter());
}

// TODO: Received notes need to be made available for note selection & balance calculation

// TODO: Spent notes need to be made unavailable for note selection & balance calculation
}

Ok(())
Expand Down

0 comments on commit 2f28306

Please sign in to comment.