Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrokonrad committed Jan 23, 2025
1 parent 1f7d71e commit 4de1d12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Binary file modified src/core/libs/lucid_core/pkg/lucid_core_bg.wasm
Binary file not shown.
10 changes: 4 additions & 6 deletions src/core/libs/lucid_core/src/instruction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ impl InstructionBuilder {
return Ok(());
}

let total_input = self
let mut total_input = self
.inputs
.iter()
.fold(Assets::new(), |acc, curr| acc + curr.utxo.assets.clone())
Expand All @@ -1106,13 +1106,11 @@ impl InstructionBuilder {

let target = total_output.clone().clamped_sub(total_input.clone());

let mut current = total_input.clone();

// largest first
for (unit, _) in target
.get_all_others()
.iter()
.chain(Assets::from_lovelace(current.get_lovelace()).iter())
.chain(Assets::from_lovelace(total_input.get_lovelace()).iter())
{
if unit == "lovelace" {
available_selection.sort_by(|a, b| {
Expand All @@ -1124,15 +1122,15 @@ impl InstructionBuilder {
.sort_by(|a, b| a.assets.get_unit(unit).cmp(&b.assets.get_unit(unit)));
}

while current.get_unit(unit) < target.get_unit(unit) {
while total_input.get_unit(unit) < target.get_unit(unit) {
let utxo = available_selection
.pop()
.ok_or(CoreError::ExhaustedInputs(unit.to_string()).to_msg())?;
if utxo.assets.get(unit).is_none() {
return Err(CoreError::ExhaustedInputs(unit.to_string()).to_msg());
}
self.add_input(utxo.clone(), None)?;
current += utxo.assets;
total_input += utxo.assets;
}
}

Expand Down

0 comments on commit 4de1d12

Please sign in to comment.