Skip to content

Commit

Permalink
seperate singleton mint out of object_event file
Browse files Browse the repository at this point in the history
  • Loading branch information
mgpai22 committed Jan 23, 2024
1 parent 943cff7 commit 00c52c3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 39 deletions.
20 changes: 10 additions & 10 deletions plutus.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": []
Expand Down
32 changes: 3 additions & 29 deletions validators/object_event.ak
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -15,11 +16,6 @@ type Event {
SpendEvent
}

type Action {
SingletonMint
SingletonBurn
}

validator(payment_credential: PaymentCredential, fee_value_lovelace: Int) {
fn object_event(
datum: ObjectDatum,
Expand All @@ -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,
Expand Down
31 changes: 31 additions & 0 deletions validators/singleton.ak
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 00c52c3

Please sign in to comment.