Skip to content

Commit

Permalink
Fix insert_spent
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 committed Oct 11, 2024
1 parent 3ad2f1e commit 7b76a30
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
24 changes: 7 additions & 17 deletions rusk-wallet/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ impl Cache {
pk_bs58: &str,
block_height: u64,
note_data: (Note, BlsScalar),
cf_name: Option<String>,
) -> Result<(), Error> {
let cf_name = pk_bs58;
let cf_name = match cf_name {
Some(x) => x,
None => pk_bs58.to_string(),
};

let cf = self
.db
.cf_handle(cf_name)
.cf_handle(&cf_name)
.ok_or(Error::CacheDatabaseCorrupted)?;

let (note, nullifier) = note_data;
Expand Down Expand Up @@ -86,21 +90,7 @@ impl Cache {
) -> Result<(), Error> {
let cf_name = format!("spent_{pk_bs58}");

let cf = self
.db
.cf_handle(&cf_name)
.ok_or(Error::CacheDatabaseCorrupted)?;

let (note, nullifier) = note_data;

let leaf = NoteLeaf { block_height, note };
let data = rkyv::to_bytes::<NoteLeaf, TREE_LEAF>(&leaf)
.map_err(|_| Error::Rkyv)?;
let key = nullifier.to_bytes();

self.db.put_cf(&cf, key, data)?;

Ok(())
self.insert(pk_bs58, block_height, note_data, Some(cf_name))
}

pub(crate) fn spend_notes(
Expand Down
2 changes: 1 addition & 1 deletion rusk-wallet/src/clients/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub(crate) async fn sync_db(

match spent {
true => cache.insert_spent(&pk_bs58, *block_height, note),
false => cache.insert(&pk_bs58, *block_height, note),
false => cache.insert(&pk_bs58, *block_height, note, None),
}?;
}
}
Expand Down

0 comments on commit 7b76a30

Please sign in to comment.