From 9bc8585944cb8adf7754e4d237d77043a0d26571 Mon Sep 17 00:00:00 2001 From: keyanmaskoot Date: Thu, 18 Apr 2024 19:05:04 +0200 Subject: [PATCH] fix: total output count was passed by mistake --- .../singular-utxo-indexer-one-to-many.ak | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/aiken-design-patterns/singular-utxo-indexer-one-to-many.ak b/lib/aiken-design-patterns/singular-utxo-indexer-one-to-many.ak index b832dc9..9f307e5 100644 --- a/lib/aiken-design-patterns/singular-utxo-indexer-one-to-many.ak +++ b/lib/aiken-design-patterns/singular-utxo-indexer-one-to-many.ak @@ -19,20 +19,18 @@ pub fn spend( expect input_validator(input)? - let output_count = list.length(outputs) - - let (_, out_utxos) = + let (_, out_utxos, output_count) = list.foldr( out_ixs, - (output_count, []), - fn(curr_ix, acc_tuple) { - let (prev_ix, acc) = acc_tuple + (list.length(outputs), [], 0), + fn(curr_ix, acc_triplet) { + let (prev_ix, acc, count) = acc_triplet // Folding from right and expecting ascending order from head to tail // (for a more intuitive API) to disallow duplicates. if curr_ix < prev_ix { expect Some(out_utxo) = outputs |> list.at(curr_ix) expect input_output_validator(in_utxo, out_utxo)? - (curr_ix, acc |> list.push(out_utxo)) + (curr_ix, acc |> list.push(out_utxo), count + 1) } else { fail @"Output indices must be in ascending order" }