Skip to content

Commit

Permalink
Trigger event for ProofState
Browse files Browse the repository at this point in the history
Ref[1]

[1] #394 (review)
  • Loading branch information
crodas committed Oct 28, 2024
1 parent d7f5791 commit 3395cd1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
11 changes: 11 additions & 0 deletions crates/cdk/src/mint/check_spendable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ impl Mint {
return Err(Error::TokenAlreadySpent);
}

for public_key in ys {
self.pubsub_manager.broadcast(
ProofState {
y: *public_key,
state: proof_state,
witness: None,
}
.into(),
);
}

Ok(())
}
}
25 changes: 24 additions & 1 deletion crates/cdk/src/mint/melt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use crate::{
Amount, Error,
};

use super::ProofState;
use super::{
CurrencyUnit, MeltBolt11Request, MeltQuote, MeltQuoteBolt11Request, MeltQuoteBolt11Response,
Mint, NotificationPayload, PaymentMethod, PublicKey, State,
Mint, PaymentMethod, PublicKey, State,
};

impl Mint {
Expand Down Expand Up @@ -363,6 +364,17 @@ impl Mint {
.melt_quote_status(&quote, None, None, MeltQuoteState::Unpaid);
}

for public_key in input_ys {
self.pubsub_manager.broadcast(
ProofState {
y: public_key,
state: State::Unspent,
witness: None,
}
.into(),
);
}

Ok(())
}

Expand Down Expand Up @@ -607,6 +619,17 @@ impl Mint {
MeltQuoteState::Paid,
);

for public_key in input_ys {
self.pubsub_manager.broadcast(
ProofState {
y: public_key,
state: State::Spent,
witness: None,
}
.into(),
);
}

let mut change = None;

// Check if there is change to return
Expand Down
13 changes: 12 additions & 1 deletion crates/cdk/src/mint/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::nuts::nut00::ProofsMethods;
use crate::Error;

use super::nut11::{enforce_sig_flag, EnforceSigFlag};
use super::{Id, Mint, PublicKey, SigFlag, State, SwapRequest, SwapResponse};
use super::{Id, Mint, ProofState, PublicKey, SigFlag, State, SwapRequest, SwapResponse};

impl Mint {
/// Process Swap
Expand Down Expand Up @@ -166,6 +166,17 @@ impl Mint {
.update_proofs_states(&input_ys, State::Spent)
.await?;

for pub_key in input_ys {
self.pubsub_manager.broadcast(
ProofState {
y: pub_key,
state: State::Spent,
witness: None,
}
.into(),
);
}

self.localstore
.add_blind_signatures(
&swap_request
Expand Down

0 comments on commit 3395cd1

Please sign in to comment.