-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seperate singleton mint out of object_event file
- Loading branch information
Showing
3 changed files
with
44 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |