diff --git a/validators/account.ak b/validators/account.ak index 6f7a0d0..dfac8b7 100644 --- a/validators/account.ak +++ b/validators/account.ak @@ -65,6 +65,7 @@ type State { type Intention { condition: IntentionCondition, + /// The Ints in value leaving should always be negative value_leaving: List<(PolicyId, AssetName, Int)>, nonce: OutputReference, /// User to track ordering number. Useful for dexes to ensure @@ -204,6 +205,48 @@ validator { ref_input if address.payment_credential == pc { + expect [(_, 1)] = + value |> value.tokens(own_policy_id) |> dict.to_list + + expect InlineDatum(datum) = datum + + expect ControlState { owner }: State = datum + + expect [account_intention_list, ..other_account_intentions] = + acc + + let account_value_used_nonces = + list.foldl( + inputs, + (value.zero(), 0), + fn(input: Input, acc) { + let Input { output, .. } = input + if output.address == address { + let Output { value, datum, .. } = output + + expect InlineDatum(dat) = datum + + let (acc_value, unused_nonces) = acc + + let combined_value = value.merge(acc_value, value) + + let non_datum_return = + fn() { (combined_value, unused_nonces) } + + builtin.choose_data( + dat, + (combined_value, unused_nonces + 1), + non_datum_return(), + non_datum_return(), + non_datum_return(), + non_datum_return(), + ) + } else { + acc + } + }, + ) + todo } else { acc