From 5fe8b11654b146b03d7a386ea0e6b701ebfcf6b4 Mon Sep 17 00:00:00 2001 From: David Caseria Date: Fri, 27 Jun 2025 11:45:00 -0400 Subject: [PATCH] Provide option to limit the send token size --- crates/cdk/src/wallet/send.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/cdk/src/wallet/send.rs b/crates/cdk/src/wallet/send.rs index 2b8cb772..a98547b4 100644 --- a/crates/cdk/src/wallet/send.rs +++ b/crates/cdk/src/wallet/send.rs @@ -156,18 +156,18 @@ impl Wallet { .update_proofs_state(proofs.ys()?, State::Reserved) .await?; - // Check if proofs are exact send amount - let proofs_exact_amount = proofs.total_amount()? == amount + send_fee; + // Check if proofs are exact send amount (and does not exceed max_proofs) + let mut exact_proofs = proofs.total_amount()? == amount + send_fee; + if let Some(max_proofs) = opts.max_proofs { + exact_proofs &= proofs.len() <= max_proofs; + } // Split proofs to swap and send let mut proofs_to_swap = Proofs::new(); let mut proofs_to_send = Proofs::new(); if force_swap { proofs_to_swap = proofs; - } else if proofs_exact_amount - || opts.send_kind.is_offline() - || opts.send_kind.has_tolerance() - { + } else if exact_proofs || opts.send_kind.is_offline() || opts.send_kind.has_tolerance() { proofs_to_send = proofs; } else { let mut remaining_send_amounts = send_amounts.clone(); @@ -420,6 +420,9 @@ pub struct SendOptions { /// /// When this is true the token created will include the amount of fees needed to redeem the token (amount + fee_to_redeem) pub include_fee: bool, + /// Maximum number of proofs to include in the token + /// Default is `None`, which means all selected proofs will be included. + pub max_proofs: Option, /// Metadata pub metadata: HashMap, }