chore: fix the issue in gift card
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use aiken/collection/dict
|
||||
use aiken/collection/list
|
||||
use cardano/assets.{PolicyId}
|
||||
use cardano/credential.{Script}
|
||||
use cardano/transaction.{OutputReference, Transaction} as tx
|
||||
|
||||
pub type Action {
|
||||
@@ -9,6 +10,22 @@ pub type Action {
|
||||
}
|
||||
|
||||
validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
|
||||
spend(_d, _r, own_ref: OutputReference, transaction: Transaction) {
|
||||
let Transaction { mint, inputs, .. } = transaction
|
||||
|
||||
expect Some(own_input) =
|
||||
list.find(inputs, fn(input) { input.output_reference == own_ref })
|
||||
|
||||
expect Script(policy_id) = own_input.output.address.payment_credential
|
||||
|
||||
expect [Pair(asset_name, amount)] =
|
||||
mint
|
||||
|> assets.tokens(policy_id)
|
||||
|> dict.to_pairs()
|
||||
|
||||
amount == -1 && asset_name == token_name
|
||||
}
|
||||
|
||||
mint(rdmr: Action, policy_id: PolicyId, transaction: Transaction) {
|
||||
let Transaction { inputs, mint, .. } = transaction
|
||||
|
||||
@@ -32,20 +49,3 @@ validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
||||
validator redeem(token_name: ByteArray, policy_id: ByteArray) {
|
||||
spend(_d, _r, _o_ref: Data, transaction: Transaction) {
|
||||
let Transaction { mint, .. } = transaction
|
||||
|
||||
expect [Pair(asset_name, amount)] =
|
||||
mint
|
||||
|> assets.tokens(policy_id)
|
||||
|> dict.to_pairs()
|
||||
|
||||
amount == -1 && asset_name == token_name
|
||||
}
|
||||
|
||||
else(_) {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user