use aiken/dict use aiken/list use aiken/transaction.{OutputReference, ScriptContext, Transaction} as tx use aiken/transaction/value type Action { Mint Burn } validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) { mint(rdmr: Action, policy_id: PolicyId, transaction: Transaction) -> Bool { let Transaction { inputs, mint, .. } = transaction expect [Pair(asset_name, amount)] = mint |> value.from_minted_value |> value.tokens(policy_id) |> dict.to_pairs() when rdmr is { Mint -> { expect Some(_input) = list.find(inputs, fn(input) { input.output_reference == utxo_ref }) amount == 1 && asset_name == token_name } Burn -> amount == -1 && asset_name == token_name } } } validator redeem(token_name: ByteArray, policy_id: ByteArray) { spend(_d: Data, _r: Data, _o_ref: Data, transaction: Transaction) -> Bool { let Transaction { mint, .. } = transaction expect [Pair(asset_name, amount)] = mint |> value.from_minted_value |> value.tokens(policy_id) |> dict.to_pairs() amount == -1 && asset_name == token_name } }