From 00c52c382483d69862defc681837b04b8a87a79d Mon Sep 17 00:00:00 2001 From: mgpai <64056966+mgpai22@users.noreply.github.com> Date: Tue, 23 Jan 2024 01:08:17 -0500 Subject: [PATCH] seperate singleton mint out of object_event file --- plutus.json | 20 ++++++++++---------- validators/object_event.ak | 32 +++----------------------------- validators/singleton.ak | 31 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 validators/singleton.ak diff --git a/plutus.json b/plutus.json index cfa16e7..d865fe2 100644 --- a/plutus.json +++ b/plutus.json @@ -43,11 +43,11 @@ "hash": "ee750189018645e79cd4cc9d85b1453bd4ef3ebde2d18d5cb1ad0aa9" }, { - "title": "object_event.singleton_mint_and_burn", + "title": "singleton.singleton_mint_and_burn", "redeemer": { "title": "rdmr", "schema": { - "$ref": "#/definitions/object_event~1Action" + "$ref": "#/definitions/singleton~1Action" } }, "parameters": [ @@ -145,34 +145,34 @@ } ] }, - "object_event/Action": { - "title": "Action", + "object_event/Event": { + "title": "Event", "anyOf": [ { - "title": "SingletonMint", + "title": "RecreateEvent", "dataType": "constructor", "index": 0, "fields": [] }, { - "title": "SingletonBurn", + "title": "SpendEvent", "dataType": "constructor", "index": 1, "fields": [] } ] }, - "object_event/Event": { - "title": "Event", + "singleton/Action": { + "title": "Action", "anyOf": [ { - "title": "RecreateEvent", + "title": "Mint", "dataType": "constructor", "index": 0, "fields": [] }, { - "title": "SpendEvent", + "title": "Burn", "dataType": "constructor", "index": 1, "fields": [] diff --git a/validators/object_event.ak b/validators/object_event.ak index 5b12ef3..3966c5b 100644 --- a/validators/object_event.ak +++ b/validators/object_event.ak @@ -1,8 +1,9 @@ use aiken/dict use aiken/list use aiken/string -use aiken/transaction.{OutputReference, ScriptContext, Transaction} as tx -use aiken/transaction.{Input, Mint, Output, Spend} +use aiken/transaction.{ + Input, Output, OutputReference, ScriptContext, Spend, Transaction, +} use aiken/transaction/credential.{Address, PaymentCredential, ScriptCredential} use aiken/transaction/value use winter_protocol/datums.{ObjectDatum, valid_datum_recreation} @@ -15,11 +16,6 @@ type Event { SpendEvent } -type Action { - SingletonMint - SingletonBurn -} - validator(payment_credential: PaymentCredential, fee_value_lovelace: Int) { fn object_event( datum: ObjectDatum, @@ -45,28 +41,6 @@ validator(payment_credential: PaymentCredential, fee_value_lovelace: Int) { } } -validator(token_name: ByteArray, utxo_ref: OutputReference) { - fn singleton_mint_and_burn(rdmr: Action, ctx: ScriptContext) -> Bool { - let ScriptContext { transaction, purpose } = ctx - expect tx.Mint(policy_id) = purpose - let Transaction { inputs, mint, .. } = transaction - expect [(asset_name, amount)] = - mint - |> value.from_minted_value - |> value.tokens(policy_id) - |> dict.to_list() - - when rdmr is { - SingletonMint -> { - expect - list.any(inputs, fn(input) { input.output_reference == utxo_ref }) - amount == 1 && asset_name == token_name - } - SingletonBurn -> amount == -1 && asset_name == token_name - } - } -} - fn valid_recreate_event( my_output_reference: OutputReference, ctx: ScriptContext, diff --git a/validators/singleton.ak b/validators/singleton.ak new file mode 100644 index 0000000..f581a60 --- /dev/null +++ b/validators/singleton.ak @@ -0,0 +1,31 @@ +use aiken/dict +use aiken/list +use aiken/transaction.{OutputReference, ScriptContext, Transaction} as tx +use aiken/transaction/value + +type Action { + Mint + Burn +} + +validator(token_name: ByteArray, utxo_ref: OutputReference) { + fn singleton_mint_and_burn(rdmr: Action, ctx: ScriptContext) -> Bool { + let ScriptContext { transaction, purpose } = ctx + expect tx.Mint(policy_id) = purpose + let Transaction { inputs, mint, .. } = transaction + expect [(asset_name, amount)] = + mint + |> value.from_minted_value + |> value.tokens(policy_id) + |> dict.to_list() + + when rdmr is { + Mint -> { + expect + list.any(inputs, fn(input) { input.output_reference == utxo_ref }) + amount == 1 && asset_name == token_name + } + Burn -> amount == -1 && asset_name == token_name + } + } +}