Ver Fonte

Fix melt change amount

David Caseria há 6 meses atrás
pai
commit
4ba2b07418
1 ficheiros alterados com 6 adições e 1 exclusões
  1. 6 1
      crates/cdk/src/wallet/mod.rs

+ 6 - 1
crates/cdk/src/wallet/mod.rs

@@ -1391,6 +1391,11 @@ impl Wallet {
             return Err(Error::UnknownQuote);
         };
 
+        let proofs_total = Amount::try_sum(proofs.iter().map(|p| p.amount))?;
+        if proofs_total < quote_info.amount + quote_info.fee_reserve {
+            return Err(Error::InsufficientFunds);
+        }
+
         let ys = proofs
             .iter()
             .map(|p| p.y())
@@ -1410,7 +1415,7 @@ impl Wallet {
             active_keyset_id,
             count,
             self.xpriv,
-            quote_info.fee_reserve,
+            proofs_total - quote_info.amount,
         )?;
 
         let melt_response = self