diff --git a/aiken.lock b/aiken.lock index e4a7aef..48e8f09 100644 --- a/aiken.lock +++ b/aiken.lock @@ -13,4 +13,4 @@ requirements = [] source = "github" [etags] -"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1700966727, nanos_since_epoch = 192028417 }, "cf946239d3dd481ed41f20e56bf24910b5229ea35aa171a708edc2a47fc20a7b"] +"aiken-lang/stdlib@main" = [{ secs_since_epoch = 1716680697, nanos_since_epoch = 311385814 }, "dfda6bc70aad760f7f836c0db06b07e0a398bb3667f4d944d7d7255d54a454af"] diff --git a/lib/sundae/multisig.ak b/lib/sundae/multisig.ak index f836383..4b57f06 100644 --- a/lib/sundae/multisig.ak +++ b/lib/sundae/multisig.ak @@ -1,10 +1,9 @@ -use aiken/bytearray use aiken/interval.{Finite, Interval, IntervalBound} use aiken/list -use aiken/dict.{Dict} +use aiken/pairs use aiken/time.{PosixTime} use aiken/transaction.{ValidityRange} -use aiken/transaction/credential.{StakeCredential, Inline, ScriptCredential} +use aiken/transaction/credential.{Inline, ScriptCredential, StakeCredential} use sundae/test_utils.{trace_example} pub type MultisigScript { @@ -21,14 +20,20 @@ pub fn satisfied( script: MultisigScript, signatories: List, valid_range: ValidityRange, - withdrawals: Dict, + withdrawals: Pairs, ) -> Bool { when script is { Signature { key_hash } -> list.has(signatories, key_hash) AllOf { scripts } -> - list.all(scripts, fn(s) { satisfied(s, signatories, valid_range, withdrawals) }) + list.all( + scripts, + fn(s) { satisfied(s, signatories, valid_range, withdrawals) }, + ) AnyOf { scripts } -> - list.any(scripts, fn(s) { satisfied(s, signatories, valid_range, withdrawals) }) + list.any( + scripts, + fn(s) { satisfied(s, signatories, valid_range, withdrawals) }, + ) AtLeast { required, scripts } -> required <= list.count( scripts, @@ -55,7 +60,8 @@ pub fn satisfied( } _ -> False } - Script { script_hash } -> dict.has_key(withdrawals, Inline(ScriptCredential(script_hash))) + Script { script_hash } -> + pairs.has_key(withdrawals, Inline(ScriptCredential(script_hash))) } } @@ -106,30 +112,25 @@ test satisfying() { }, } } - let no_w = dict.new() - let correct_credential = Inline(ScriptCredential("some_script")) - let incorrect_credential = Inline(ScriptCredential("other_script")) - let compare_credential = fn(a: StakeCredential, b: StakeCredential) -> Ordering { - when a is { - Inline(ScriptCredential(a))-> { - when b is { - Inline(ScriptCredential(b)) -> bytearray.compare(a, b) - _ -> Less - } - } - _ -> Greater - } - } - let correct_w = dict.new() - |> dict.insert(correct_credential, 0, compare_credential) - let incorrect_w = dict.new() - |> dict.insert(incorrect_credential, 0, compare_credential) - let both_w = dict.new() - |> dict.insert(correct_credential, 0, compare_credential) - |> dict.insert(incorrect_credential, 0, compare_credential) + let no_w: Pairs = + [] + let correct_w = + [Pair(Inline(ScriptCredential("some_script")), 0)] + let incorrect_w = + [Pair(Inline(ScriptCredential("other_script")), 0)] + let both_w = + [ + Pair(Inline(ScriptCredential("some_script")), 0), + Pair(Inline(ScriptCredential("other_script")), 0), + ] // Helper method because ? binds more tightly than ! let unsatisfied = - fn(n: MultisigScript, s: List, v: ValidityRange, w: Dict) { + fn( + n: MultisigScript, + s: List, + v: ValidityRange, + w: Pairs, + ) { !satisfied(n, s, v, w) } list.all(