mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-18 21:25:09 +01:00
feat(cdk): add melt quote state transition validation (#1188)
Add state machine validation for melt quote transitions to prevent invalid state changes. Includes new error types and validation logic for Unpaid, Pending, Paid, and Failed states.
This commit is contained in:
@@ -28,7 +28,7 @@ use cdk_common::nut00::ProofsMethods;
|
||||
use cdk_common::payment::PaymentIdentifier;
|
||||
use cdk_common::quote_id::QuoteId;
|
||||
use cdk_common::secret::Secret;
|
||||
use cdk_common::state::check_state_transition;
|
||||
use cdk_common::state::{check_melt_quote_state_transition, check_state_transition};
|
||||
use cdk_common::util::unix_time;
|
||||
use cdk_common::{
|
||||
Amount, BlindSignature, BlindSignatureDleq, BlindedMessage, CurrencyUnit, Id, MeltQuoteState,
|
||||
@@ -1043,6 +1043,8 @@ VALUES (:quote_id, :amount, :timestamp);
|
||||
.transpose()?
|
||||
.ok_or(Error::QuoteNotFound)?;
|
||||
|
||||
check_melt_quote_state_transition(quote.state, state)?;
|
||||
|
||||
let rec = if state == MeltQuoteState::Paid {
|
||||
let current_time = unix_time();
|
||||
query(r#"UPDATE melt_quote SET state = :state, paid_time = :paid_time, payment_preimage = :payment_preimage WHERE id = :id"#)?
|
||||
|
||||
Reference in New Issue
Block a user