From b4f54bf1157dcf0ba730cc0390b4072a6d4df279 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Tue, 7 Jan 2025 18:21:44 +0100 Subject: [PATCH] pay: detect insufficient state early --- src/pay.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pay.rs b/src/pay.rs index 43fc017..8123562 100644 --- a/src/pay.rs +++ b/src/pay.rs @@ -187,7 +187,7 @@ where Self::Descr: DescriptorRgb .collect(); state.sort_by_key(|(sum, _, _)| *sum); let mut sum = Amount::ZERO; - state + let selection = state .iter() .rev() .take_while(|(val, _, _)| { @@ -199,7 +199,12 @@ where Self::Descr: DescriptorRgb } }) .map(|(_, seal, _)| *seal) - .collect::>() + .collect::>(); + if sum < amount { + bset![] + } else { + selection + } } InvoiceState::Data(NonFungible::RGB21(allocation)) => { let data_state = DataState::from(allocation); @@ -220,6 +225,9 @@ where Self::Descr: DescriptorRgb )] } }; + if prev_outputs.is_empty() { + return Err(CompositionError::InsufficientState); + } let prev_outpoints = prev_outputs .iter() // TODO: Support liquid