chore: use correct arguments in gift card validators

This commit is contained in:
rvcas 2024-08-26 15:45:37 -04:00
parent c87f459ce7
commit b57f840cad
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
2 changed files with 10 additions and 19 deletions

View File

@ -22,14 +22,11 @@ validator redeem(creator: ByteArray) {
// Each spend input checks for a token name matching the datum being burned
datum: SpendTokenName,
_r: Data,
ctx: ScriptContext,
own_ref: OutputReference,
transaction: Transaction,
) {
let ScriptContext { transaction, purpose } = ctx
let Transaction { inputs, mint, .. } = transaction
expect Spend(own_ref) = purpose
expect Some(own_input) =
list.find(inputs, fn(input) { input.output_reference == own_ref })
@ -47,12 +44,7 @@ validator redeem(creator: ByteArray) {
) == -1
}
mint(rdmr: Action, ctx: ScriptContext) -> Bool {
// get values from transaction and purpose
let ScriptContext { transaction, purpose } = ctx
expect tx.Mint(policy_id) = purpose
mint(rdmr: Action, policy_id: PolicyId, transaction: Transaction) -> Bool {
let Transaction { inputs, mint, extra_signatories, outputs, .. } =
transaction
@ -65,14 +57,18 @@ validator redeem(creator: ByteArray) {
when rdmr is {
Mint(total) -> {
expect [input, ..] = inputs
// Base is created from serializing a utxo ref being spent. Thus this guarantees a unique base
let base = builtin.serialise_data(input.output_reference)
// Create a list of expected token names
let expected_minted_token_names =
create_expected_minted_nfts(base, total, [])
// Check contract creator is a signer of this tx
let signature_check =
list.any(extra_signatories, fn(n) { creator == n })
// Support multiple gift card creation by allowing a
// 'number of tokens minted' == 'outputs with datum being token name'
signature_check && check_mint_and_outputs(

View File

@ -9,11 +9,7 @@ type Action {
}
validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
mint(rdmr: Action, ctx: ScriptContext) -> Bool {
let ScriptContext { transaction, purpose } = ctx
expect tx.Mint(policy_id) = purpose
mint(rdmr: Action, policy_id: PolicyId, transaction: Transaction) -> Bool {
let Transaction { inputs, mint, .. } = transaction
expect [Pair(asset_name, amount)] =
@ -26,6 +22,7 @@ validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
Mint -> {
expect Some(_input) =
list.find(inputs, fn(input) { input.output_reference == utxo_ref })
amount == 1 && asset_name == token_name
}
Burn -> amount == -1 && asset_name == token_name
@ -34,9 +31,7 @@ validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
}
validator redeem(token_name: ByteArray, policy_id: ByteArray) {
spend(_d: Data, _r: Data, ctx: ScriptContext) -> Bool {
let ScriptContext { transaction, .. } = ctx
spend(_d: Data, _r: Data, _o_ref: Data, transaction: Transaction) -> Bool {
let Transaction { mint, .. } = transaction
expect [Pair(asset_name, amount)] =