Browse Source

log amount miss match for verify melt

thesimplekid 1 year ago
parent
commit
ba2e4cf1f3
2 changed files with 15 additions and 7 deletions
  1. 14 6
      crates/cashu-sdk/src/mint.rs
  2. 1 1
      crates/cashu/src/error.rs

+ 14 - 6
crates/cashu-sdk/src/mint.rs

@@ -17,6 +17,7 @@ use cashu::nuts::nut08::MeltResponse;
 use cashu::nuts::*;
 use cashu::secret::Secret;
 use cashu::Amount;
+use tracing::debug;
 
 pub struct Mint {
     //    pub pubkey: PublicKey,
@@ -245,12 +246,17 @@ impl Mint {
             self.fee_reserve.min_fee_reserve
         };
 
-        if proofs_total
-            < melt_request
-                .invoice_amount()
-                .map_err(|_| Error::InvoiceAmountUndefined)?
-                + fee_reserve
-        {
+        let required_total = melt_request
+            .invoice_amount()
+            .map_err(|_| Error::InvoiceAmountUndefined)?
+            + fee_reserve;
+
+        if proofs_total < required_total {
+            debug!(
+                "Insufficient Proofs: Got: {}, Required: {}",
+                proofs_total.to_sat().to_string(),
+                required_total.to_sat().to_string()
+            );
             return Err(Error::Amount);
         }
 
@@ -274,6 +280,8 @@ impl Mint {
         preimage: &str,
         total_spent: Amount,
     ) -> Result<MeltResponse, Error> {
+        self.verify_melt_request(melt_request)?;
+
         let secrets = Vec::with_capacity(melt_request.proofs.len());
         for secret in secrets {
             self.spent_secrets.insert(secret);

+ 1 - 1
crates/cashu/src/error.rs

@@ -33,7 +33,7 @@ impl fmt::Display for Error {
             Error::CustomError(err) => write!(f, "{}", err),
             Error::HexError(err) => write!(f, "{}", err),
             Error::AmountKey => write!(f, "No Key for amount"),
-            Error::Amount => write!(f, "Amount miss match"),
+            Error::Amount => write!(f, "Amount miss match."),
             Error::TokenSpent => write!(f, "Token Spent"),
             Error::TokenNotVerifed => write!(f, "Token Not Verified"),
             Error::InvoiceAmountUndefined => write!(f, "Invoice without amount"),