Skip to content

Commit

Permalink
Merge pull request #747 from zancas/fixed_spent_at_height_removal
Browse files Browse the repository at this point in the history
@fluidvanadium discovered that this wasn't used in the workspace
  • Loading branch information
zancas authored Dec 6, 2023
2 parents c413bab + 3d931e7 commit 69d9931
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 54 deletions.
1 change: 1 addition & 0 deletions zingolib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- LightClient pub fn do_save
- LightClient pub fn do_save_to_buffer
- LightClient pub fn do_save_to_buffer_sync
- LightWallet pub fn fix_spent_at_height
54 changes: 0 additions & 54 deletions zingolib/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use shardtree::ShardTree;
use std::convert::Infallible;
use std::{
cmp,
collections::HashMap,
io::{self, Error, ErrorKind, Read, Write},
sync::{atomic::AtomicU64, mpsc::channel, Arc},
time::SystemTime,
Expand Down Expand Up @@ -343,59 +342,6 @@ impl LightWallet {
Err("No message matched".to_string())
}

// Add the spent_at_height for each sapling note that has been spent. This field was added in wallet version 8,
// so for older wallets, it will need to be added
pub async fn fix_spent_at_height(&self) {
// First, build an index of all the transaction_ids and the heights at which they were spent.
let spent_transaction_id_map: HashMap<_, _> = self
.transaction_context
.transaction_metadata_set
.read()
.await
.current
.iter()
.map(|(transaction_id, wtx)| (*transaction_id, wtx.block_height))
.collect();

// Go over all the sapling notes that might need updating
self.transaction_context
.transaction_metadata_set
.write()
.await
.current
.values_mut()
.for_each(|wtx| {
wtx.sapling_notes
.iter_mut()
.filter(|nd| nd.spent.is_some() && nd.spent.unwrap().1 == 0)
.for_each(|nd| {
let transaction_id = nd.spent.unwrap().0;
if let Some(height) = spent_transaction_id_map.get(&transaction_id).copied()
{
nd.spent = Some((transaction_id, height.into()));
}
})
});

// Go over all the Utxos that might need updating
self.transaction_context
.transaction_metadata_set
.write()
.await
.current
.values_mut()
.for_each(|wtx| {
wtx.transparent_notes
.iter_mut()
.filter(|utxo| utxo.spent.is_some() && utxo.spent_at_height.is_none())
.for_each(|utxo| {
utxo.spent_at_height = spent_transaction_id_map
.get(&utxo.spent.unwrap())
.map(|b| u32::from(*b) as i32);
})
});
}

async fn get_all_domain_specific_notes<D>(&self) -> Vec<D::SpendableNoteAT>
where
D: DomainWalletExt,
Expand Down

0 comments on commit 69d9931

Please sign in to comment.