From 7ba8a0c179fc10a9aa868debf34536c07ae770c2 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Wed, 27 Mar 2024 11:03:52 -0400 Subject: [PATCH] rework amount requirement so it doesn't try to get the allotment before all new requirements are complete --- .../transaction_builder/requirement/amount.rs | 19 ++++--------------- .../transaction_builder/requirement/mana.rs | 6 ++++-- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs index c11324eb81..775aee12b2 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/amount.rs @@ -32,7 +32,7 @@ pub(crate) fn sdruc_not_expired( impl TransactionBuilder { pub(crate) fn fulfill_amount_requirement(&mut self) -> Result<(), TransactionBuilderError> { - let (mut input_amount, mut output_amount) = self.amount_balance()?; + let (input_amount, output_amount) = self.amount_balance()?; if input_amount >= output_amount { log::debug!("Amount requirement already fulfilled"); return Ok(()); @@ -43,22 +43,11 @@ impl TransactionBuilder { if !self.allow_additional_input_selection { return Err(TransactionBuilderError::AdditionalInputsRequired(Requirement::Amount)); } - if self.available_inputs.is_empty() { - return Err(TransactionBuilderError::InsufficientAmount { - found: input_amount, - required: output_amount, - }); - } - while let Some(input) = self.next_input_for_amount(output_amount - input_amount, self.latest_slot_commitment_id) - { + if let Some(input) = self.next_input_for_amount(output_amount - input_amount, self.latest_slot_commitment_id) { + self.requirements.push(Requirement::Amount); self.select_input(input)?; - (input_amount, output_amount) = self.amount_balance()?; - if input_amount >= output_amount { - break; - } - } - if output_amount > input_amount { + } else { return Err(TransactionBuilderError::InsufficientAmount { found: input_amount, required: output_amount, diff --git a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs index 5abf3a88f6..77ecb885c1 100644 --- a/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs +++ b/sdk/src/client/api/block_builder/transaction_builder/requirement/mana.rs @@ -202,8 +202,10 @@ impl TransactionBuilder { match &required_address { Address::Ed25519(_) | Address::ImplicitAccountCreation(_) => {} _ => { - log::debug!("MissingInputWithEd25519Address from null_transaction_unlocks required_address {required_address:?}"); - log::debug!("Tx Builder {self:?}"); + log::debug!( + "MissingInputWithEd25519Address from null_transaction_unlocks required_address {required_address:?}" + ); + log::debug!("Tx Builder {self:#?}"); Err(TransactionBuilderError::MissingInputWithEd25519Address)? } }