-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25e4a1d
commit b08f3ee
Showing
1 changed file
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use aiken/dict as dict | ||
use aiken/list as list | ||
use aiken/transaction.{Input, OutputReference, ScriptContext, Transaction} as tx | ||
use aiken/transaction/value.{AssetName, MintedValue, PolicyId} | ||
|
||
validator { | ||
fn free_minting(_redeemer: Void, _ctx: ScriptContext) -> Bool { | ||
True | ||
} | ||
} | ||
|
||
type Mode { | ||
Minting | ||
Burning | ||
} | ||
|
||
validator(token_name: ByteArray, oref: OutputReference) { | ||
fn nft(redeemer: Mode, ctx: ScriptContext) -> Bool { | ||
expect tx.Mint(policy_id) = ctx.purpose | ||
|
||
let Transaction { inputs, mint, .. } = ctx.transaction | ||
|
||
when redeemer is { | ||
Minting -> | ||
has_utxo(oref, inputs)? && check_mint(policy_id, token_name, mint, 1)? | ||
Burning -> check_mint(policy_id, token_name, mint, -1)? | ||
} | ||
} | ||
} | ||
|
||
fn has_utxo(oref: OutputReference, inputs: List<Input>) { | ||
list.any(inputs, fn(input) { input.output_reference == oref }) | ||
} | ||
|
||
fn check_mint(cs: PolicyId, tn: AssetName, mint: MintedValue, mint_qty: Int) { | ||
expect [(asset_name, qty)] = | ||
mint | ||
|> value.from_minted_value | ||
|> value.tokens(cs) | ||
|> dict.to_list() | ||
(qty == mint_qty)? && (asset_name == tn)? | ||
} |