Skip to content

Commit

Permalink
rework amount requirement so it doesn't try to get the allotment befo…
Browse files Browse the repository at this point in the history
…re all new requirements are complete
  • Loading branch information
Alex Coats committed Mar 27, 2024
1 parent 64a0395 commit 7ba8a0c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
}
}
Expand Down

0 comments on commit 7ba8a0c

Please sign in to comment.