chore: use correct arguments in gift card validators
This commit is contained in:
parent
c87f459ce7
commit
b57f840cad
|
@ -22,14 +22,11 @@ validator redeem(creator: ByteArray) {
|
||||||
// Each spend input checks for a token name matching the datum being burned
|
// Each spend input checks for a token name matching the datum being burned
|
||||||
datum: SpendTokenName,
|
datum: SpendTokenName,
|
||||||
_r: Data,
|
_r: Data,
|
||||||
ctx: ScriptContext,
|
own_ref: OutputReference,
|
||||||
|
transaction: Transaction,
|
||||||
) {
|
) {
|
||||||
let ScriptContext { transaction, purpose } = ctx
|
|
||||||
|
|
||||||
let Transaction { inputs, mint, .. } = transaction
|
let Transaction { inputs, mint, .. } = transaction
|
||||||
|
|
||||||
expect Spend(own_ref) = purpose
|
|
||||||
|
|
||||||
expect Some(own_input) =
|
expect Some(own_input) =
|
||||||
list.find(inputs, fn(input) { input.output_reference == own_ref })
|
list.find(inputs, fn(input) { input.output_reference == own_ref })
|
||||||
|
|
||||||
|
@ -47,12 +44,7 @@ validator redeem(creator: ByteArray) {
|
||||||
) == -1
|
) == -1
|
||||||
}
|
}
|
||||||
|
|
||||||
mint(rdmr: Action, ctx: ScriptContext) -> Bool {
|
mint(rdmr: Action, policy_id: PolicyId, transaction: Transaction) -> Bool {
|
||||||
// get values from transaction and purpose
|
|
||||||
let ScriptContext { transaction, purpose } = ctx
|
|
||||||
|
|
||||||
expect tx.Mint(policy_id) = purpose
|
|
||||||
|
|
||||||
let Transaction { inputs, mint, extra_signatories, outputs, .. } =
|
let Transaction { inputs, mint, extra_signatories, outputs, .. } =
|
||||||
transaction
|
transaction
|
||||||
|
|
||||||
|
@ -65,14 +57,18 @@ validator redeem(creator: ByteArray) {
|
||||||
when rdmr is {
|
when rdmr is {
|
||||||
Mint(total) -> {
|
Mint(total) -> {
|
||||||
expect [input, ..] = inputs
|
expect [input, ..] = inputs
|
||||||
|
|
||||||
// Base is created from serializing a utxo ref being spent. Thus this guarantees a unique base
|
// Base is created from serializing a utxo ref being spent. Thus this guarantees a unique base
|
||||||
let base = builtin.serialise_data(input.output_reference)
|
let base = builtin.serialise_data(input.output_reference)
|
||||||
|
|
||||||
// Create a list of expected token names
|
// Create a list of expected token names
|
||||||
let expected_minted_token_names =
|
let expected_minted_token_names =
|
||||||
create_expected_minted_nfts(base, total, [])
|
create_expected_minted_nfts(base, total, [])
|
||||||
|
|
||||||
// Check contract creator is a signer of this tx
|
// Check contract creator is a signer of this tx
|
||||||
let signature_check =
|
let signature_check =
|
||||||
list.any(extra_signatories, fn(n) { creator == n })
|
list.any(extra_signatories, fn(n) { creator == n })
|
||||||
|
|
||||||
// Support multiple gift card creation by allowing a
|
// Support multiple gift card creation by allowing a
|
||||||
// 'number of tokens minted' == 'outputs with datum being token name'
|
// 'number of tokens minted' == 'outputs with datum being token name'
|
||||||
signature_check && check_mint_and_outputs(
|
signature_check && check_mint_and_outputs(
|
||||||
|
|
|
@ -9,11 +9,7 @@ type Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
|
validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
|
||||||
mint(rdmr: Action, ctx: ScriptContext) -> Bool {
|
mint(rdmr: Action, policy_id: PolicyId, transaction: Transaction) -> Bool {
|
||||||
let ScriptContext { transaction, purpose } = ctx
|
|
||||||
|
|
||||||
expect tx.Mint(policy_id) = purpose
|
|
||||||
|
|
||||||
let Transaction { inputs, mint, .. } = transaction
|
let Transaction { inputs, mint, .. } = transaction
|
||||||
|
|
||||||
expect [Pair(asset_name, amount)] =
|
expect [Pair(asset_name, amount)] =
|
||||||
|
@ -26,6 +22,7 @@ validator gift_card(token_name: ByteArray, utxo_ref: OutputReference) {
|
||||||
Mint -> {
|
Mint -> {
|
||||||
expect Some(_input) =
|
expect Some(_input) =
|
||||||
list.find(inputs, fn(input) { input.output_reference == utxo_ref })
|
list.find(inputs, fn(input) { input.output_reference == utxo_ref })
|
||||||
|
|
||||||
amount == 1 && asset_name == token_name
|
amount == 1 && asset_name == token_name
|
||||||
}
|
}
|
||||||
Burn -> 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) {
|
validator redeem(token_name: ByteArray, policy_id: ByteArray) {
|
||||||
spend(_d: Data, _r: Data, ctx: ScriptContext) -> Bool {
|
spend(_d: Data, _r: Data, _o_ref: Data, transaction: Transaction) -> Bool {
|
||||||
let ScriptContext { transaction, .. } = ctx
|
|
||||||
|
|
||||||
let Transaction { mint, .. } = transaction
|
let Transaction { mint, .. } = transaction
|
||||||
|
|
||||||
expect [Pair(asset_name, amount)] =
|
expect [Pair(asset_name, amount)] =
|
||||||
|
|
Loading…
Reference in New Issue