Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdk_sdk):remove spent proof and update db state #393

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions crates/cdk/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::mint_url::MintUrl;
use crate::nuts::nut00::token::Token;
use crate::nuts::{
nut10, CurrencyUnit, Id, Keys, MintInfo, MintQuoteState, PreMintSecrets, Proof, Proofs,
RestoreRequest, SpendingConditions, State,
PublicKey, RestoreRequest, SpendingConditions, State,
};
use crate::types::ProofInfo;
use crate::{Amount, HttpClient};
Expand Down Expand Up @@ -321,7 +321,7 @@ impl Wallet {

let unspent_proofs: Vec<Proof> = proofs
.iter()
.zip(states)
.zip(states.clone())
.filter(|(_, state)| !state.state.eq(&State::Spent))
.map(|(p, _)| p)
.cloned()
Expand All @@ -336,8 +336,15 @@ impl Wallet {
})
.collect::<Result<Vec<ProofInfo>, _>>()?;

let spent_public_keys: Vec<PublicKey> = proofs
.iter()
.zip(states)
.filter(|(_, state)| state.state == State::Spent)
.filter_map(|(p, _)| p.y().ok())
.collect();

mubarak23 marked this conversation as resolved.
Show resolved Hide resolved
self.localstore
.update_proofs(unspent_proofs, vec![])
.update_proofs(unspent_proofs, spent_public_keys)
mubarak23 marked this conversation as resolved.
Show resolved Hide resolved
.await?;

empty_batch = 0;
Expand Down
Loading