Просмотр исходного кода

feat(cdk): allow minting less than paid amount for non-bolt11 payments

For bolt11 payments, enforce exact amount matching between outputs and quote.
For other payment methods, allow minting less than paid amount while preventing overspending.
thesimplekid 2 месяцев назад
Родитель
Сommit
5ef2be36f2
2 измененных файлов с 30 добавлено и 17 удалено
  1. 29 16
      crates/cdk/src/mint/issue/mod.rs
  2. 1 1
      crates/cdk/src/wallet/issue/issue_bolt12.rs

+ 29 - 16
crates/cdk/src/mint/issue/mod.rs

@@ -552,23 +552,36 @@ impl Mint {
             mint_request.verify_signature(pubkey)?;
         }
 
-        let Verification { amount, unit } =
-            match self.verify_outputs(&mut tx, &mint_request.outputs).await {
-                Ok(verification) => verification,
-                Err(err) => {
-                    tracing::debug!("Could not verify mint outputs");
+        let Verification {
+            amount: outputs_amount,
+            unit,
+        } = match self.verify_outputs(&mut tx, &mint_request.outputs).await {
+            Ok(verification) => verification,
+            Err(err) => {
+                tracing::debug!("Could not verify mint outputs");
 
-                    return Err(err);
-                }
-            };
-
-        // We check the total value of blinded messages == mint quote
-        if amount != mint_amount {
-            return Err(Error::TransactionUnbalanced(
-                mint_amount.into(),
-                mint_request.total_amount()?.into(),
-                0,
-            ));
+                return Err(err);
+            }
+        };
+
+        if mint_quote.payment_method == PaymentMethod::Bolt11 {
+            // For bolt11 we enforce that mint amount == quote amount
+            if outputs_amount != mint_amount {
+                return Err(Error::TransactionUnbalanced(
+                    mint_amount.into(),
+                    mint_request.total_amount()?.into(),
+                    0,
+                ));
+            }
+        } else {
+            // For other payments we just make sure outputs is not more then mint amount
+            if outputs_amount > mint_amount {
+                return Err(Error::TransactionUnbalanced(
+                    mint_amount.into(),
+                    mint_request.total_amount()?.into(),
+                    0,
+                ));
+            }
         }
 
         let unit = unit.ok_or(Error::UnsupportedUnit).unwrap();

+ 1 - 1
crates/cdk/src/wallet/issue/issue_bolt12.rs

@@ -97,7 +97,7 @@ impl Wallet {
 
         let quote_info = if let Some(quote) = quote_info {
             if quote.expiry.le(&unix_time()) && quote.expiry.ne(&0) {
-                return Err(Error::ExpiredQuote(quote.expiry, unix_time()));
+                tracing::info!("Minting after expiry");
             }
 
             quote.clone()