diff --git a/crates/cdk/src/mint/mod.rs b/crates/cdk/src/mint/mod.rs index ee1a6f0c4..a037da075 100644 --- a/crates/cdk/src/mint/mod.rs +++ b/crates/cdk/src/mint/mod.rs @@ -857,11 +857,26 @@ impl Mint { &self, melt_request: &MeltBolt11Request, ) -> Result { - let ys: Vec = melt_request + let state = self + .localstore + .update_melt_quote_state(&melt_request.quote, MeltQuoteState::Pending) + .await?; + + match state { + MeltQuoteState::Unpaid => (), + MeltQuoteState::Pending => { + return Err(Error::PendingQuote); + } + MeltQuoteState::Paid => { + return Err(Error::PaidQuote); + } + } + + let ys = melt_request .inputs .iter() - .flat_map(|p| hash_to_curve(&p.secret.to_bytes())) - .collect(); + .map(|p| hash_to_curve(&p.secret.to_bytes())) + .collect::, _>>()?; // Ensure proofs are unique and not being double spent if melt_request.inputs.len() != ys.iter().collect::>().len() { @@ -877,21 +892,6 @@ impl Mint { self.verify_proof(proof).await?; } - let state = self - .localstore - .update_melt_quote_state(&melt_request.quote, MeltQuoteState::Pending) - .await?; - - match state { - MeltQuoteState::Unpaid => (), - MeltQuoteState::Pending => { - return Err(Error::PendingQuote); - } - MeltQuoteState::Paid => { - return Err(Error::PaidQuote); - } - } - let quote = self .localstore .get_melt_quote(&melt_request.quote) @@ -933,13 +933,13 @@ impl Mint { keyset_units.insert(keyset.unit); } - if let Some(outputs) = &melt_request.outputs { - let EnforceSigFlag { sig_flag, .. } = enforce_sig_flag(melt_request.inputs.clone()); + let EnforceSigFlag { sig_flag, .. } = enforce_sig_flag(melt_request.inputs.clone()); - if sig_flag.eq(&SigFlag::SigAll) { - return Err(Error::SigAllUsedInMelt); - } + if sig_flag.eq(&SigFlag::SigAll) { + return Err(Error::SigAllUsedInMelt); + } + if let Some(outputs) = &melt_request.outputs { let output_keysets_ids: HashSet = outputs.iter().map(|b| b.keyset_id).collect(); for id in output_keysets_ids { let keyset = self