Temporarily using the 'specialize-dict-key' branch from the stdlib which makes use of Pair where relevant. Once this is merged back into 'main' we should update the acceptance test toml files to keep getting them automatically upgraded. This commit also fixes an oversight in the reification of data-types now properly distinguishing between pairs and 2-tuples. Co-authored-by: Microproofs <kasey.white@cardanofoundation.org>
44 lines
1.0 KiB
Plaintext
44 lines
1.0 KiB
Plaintext
use aiken/dict
|
|
use aiken/list
|
|
use aiken/transaction.{Mint, ScriptContext}
|
|
use aiken/transaction/value
|
|
|
|
validator {
|
|
fn mint(redeemer: Data, ctx: ScriptContext) {
|
|
and {
|
|
assert_purpose(ctx),
|
|
assert_mint(ctx.purpose, ctx.transaction),
|
|
assert_redeemers(ctx, redeemer),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn assert_purpose(ctx) {
|
|
expect [my_policy_id] =
|
|
ctx.transaction.mint
|
|
|> value.from_minted_value
|
|
|> value.without_lovelace
|
|
|> value.policies
|
|
|
|
expect Mint(policy_id) = ctx.purpose
|
|
|
|
my_policy_id == policy_id
|
|
}
|
|
|
|
fn assert_mint(purpose, transaction) {
|
|
expect Mint(policy_id) = purpose
|
|
let tokens =
|
|
value.tokens(transaction.mint |> value.from_minted_value, policy_id)
|
|
|
|
when dict.get(tokens, #"666f6f") is {
|
|
None -> fail @"token not found"
|
|
Some(quantity) -> quantity == 1337
|
|
}
|
|
}
|
|
|
|
fn assert_redeemers(ctx, my_redeemer) {
|
|
expect Some(Pair(_, redeemer)) =
|
|
list.find(ctx.transaction.redeemers, fn(kv) { kv.1st == ctx.purpose })
|
|
my_redeemer == redeemer && list.length(ctx.transaction.redeemers) == 1
|
|
}
|