@@ -69,7 +69,7 @@ type NFTAsset {
69
69
asset: AssetName ,
70
70
}
71
71
72
- validator (state_token: NFTAsset ) {
72
+ validator (init_input: OutputReference ) {
73
73
/// remember `rdr` still needs to be wrapped in a index 1 constr for multivalidator purposes
74
74
fn conditional_spend (state: State , rdr: Data , ctx: ScriptContext ) -> Bool {
75
75
let ScriptContext { transaction, purpose } = ctx
@@ -102,8 +102,6 @@ validator(state_token: NFTAsset) {
102
102
103
103
let State { owner, redelegation_condition, .. } = state
104
104
105
- let NFTAsset { policy: nft_policy, asset: nft_asset } = state_token
106
-
107
105
let Interval { lower_bound, upper_bound } = validity_range
108
106
109
107
let IntervalBound { bound_type, is_inclusive: upper_inclusive } =
@@ -117,34 +115,28 @@ validator(state_token: NFTAsset) {
117
115
expect Finite (lower) = bound_type
118
116
119
117
// Checks current owner is valid
120
- expect True =
118
+ expect
121
119
when owner is {
122
120
// An owner can be a public key, a spent NFT, or a burned receipt token that was minted by this script
123
121
PKH (signer) -> list.has (extra_signatories, signer)
124
122
// In this case the redeemer out ref refers to some other input that holds the nft
125
123
// that we check is spent
126
124
NFT (policy, token_name) -> {
127
125
expect nft_input_owner: OutputReference = rdr
128
-
129
126
expect Some (nft_input) =
130
127
list.find (
131
128
inputs,
132
129
fn (input) { input.output_reference == nft_input_owner },
133
130
)
134
-
135
131
quantity_of (nft_input.output.value, policy, token_name) == 1
136
132
}
137
-
138
133
Receipt (token_name) -> {
139
134
let x = mint |> from_minted_value |> quantity_of (own_pkh, token_name)
140
-
141
135
x == - 1
142
136
}
143
137
}
144
-
145
- // Check input contains parameterized NFT
146
- expect True = quantity_of (in_value, nft_policy, nft_asset) == 1
147
-
138
+ // Check input contains init NFT
139
+ expect quantity_of (in_value, own_pkh, "" ) == 1
148
140
// Validates non-recursive conditions
149
141
let tx_condition_runner =
150
142
fn (cond: TxCondition ) -> Bool {
@@ -178,7 +170,7 @@ validator(state_token: NFTAsset) {
178
170
}
179
171
}
180
172
181
- expect True =
173
+ expect
182
174
when redelegation_condition is {
183
175
Is (tx_cond) -> tx_condition_runner (tx_cond)
184
176
Not (tx_cond) -> !tx_condition_runner (tx_cond)
@@ -187,17 +179,12 @@ validator(state_token: NFTAsset) {
187
179
Or (conds) ->
188
180
validate_stake_conditions (conds, False , tx_condition_runner)
189
181
}
190
-
191
182
// find output with same address and nft state token
192
183
expect Some (Output { datum: InlineDatum (out_datum), .. }) =
193
184
list.find (
194
185
outputs,
195
186
fn (output) {
196
- output.address == in_address && quantity_of (
197
- output.value,
198
- nft_policy,
199
- nft_asset,
200
- ) == 1
187
+ output.address == in_address && quantity_of (output.value, own_pkh, "" ) == 1
201
188
},
202
189
)
203
190
@@ -222,35 +209,67 @@ validator(state_token: NFTAsset) {
222
209
..
223
210
} = transaction
224
211
225
- let NFTAsset { policy: nft_policy, asset: nft_asset } = state_token
226
-
227
212
when purpose is {
228
213
Mint (own_policy) -> {
214
+ let minted_under_policy =
215
+ mint
216
+ |> from_minted_value
217
+ |> tokens (own_policy)
218
+ |> dict.to_list
219
+
229
220
expect [first_input, .. ] = inputs
230
221
231
- let asset_name = first_input.output_reference |> builtin.serialise_data
232
-
233
- mint
234
- |> from_minted_value
235
- |> tokens (own_policy)
236
- |> dict.to_list
237
- |> check_mint_to_output_datum (
238
- outputs,
239
- asset_name,
240
- state_token,
241
- ScriptCredential (own_policy),
242
- )
222
+ let asset_name =
223
+ first_input.output_reference
224
+ |> builtin.serialise_data
225
+ |> builtin.blake2b_256
226
+
227
+ when minted_under_policy is {
228
+ // impossible case
229
+ [] -> False
230
+ [(minted_asset_name, 1 ), .. rest] if minted_asset_name == "" -> {
231
+ expect [output, .. ] = outputs
232
+
233
+ let Output { address, value, .. } = output
234
+
235
+ and {
236
+ address.payment_credential == ScriptCredential (own_policy),
237
+ value.quantity_of (value, own_policy, "" ) == 1 ,
238
+ list.any (
239
+ inputs,
240
+ fn (input) { input.output_reference == init_input },
241
+ ),
242
+ check_mint_to_output_datum (
243
+ rest,
244
+ outputs,
245
+ asset_name,
246
+ ScriptCredential (own_policy),
247
+ own_policy,
248
+ ),
249
+ }
250
+ }
251
+
252
+ all ->
253
+ check_mint_to_output_datum (
254
+ all,
255
+ outputs,
256
+ asset_name,
257
+ ScriptCredential (own_policy),
258
+ own_policy,
259
+ )
260
+ }
243
261
}
244
262
245
263
WithdrawFrom (cred) -> {
246
264
expect Inline (cred) = cred
265
+ expect ScriptCredential (own_policy) = cred
247
266
248
267
let find_predicate =
249
268
fn (input: Input ) {
250
269
let output = input.output
251
270
252
271
output.address.payment_credential == cred && (
253
- output.value |> quantity_of (nft_policy, nft_asset )
272
+ output.value |> quantity_of (own_policy, "" )
254
273
) == 1
255
274
}
256
275
@@ -308,20 +327,19 @@ validator(state_token: NFTAsset) {
308
327
delegator,
309
328
} -> {
310
329
expect Inline (cred) = delegator
330
+ expect ScriptCredential (own_policy) = cred
311
331
// Checks for state token is spent
312
332
list.any (
313
333
inputs,
314
334
fn (input) {
315
335
let output = input.output
316
336
317
337
output.address.payment_credential == cred && (
318
- output.value |> quantity_of (nft_policy, nft_asset )
338
+ output.value |> quantity_of (own_policy, "" )
319
339
) == 1
320
340
},
321
341
)
322
342
}
323
-
324
- CredentialRegistration (_) -> True
325
343
_ -> False
326
344
}
327
345
_ -> False
@@ -484,25 +502,22 @@ fn check_mint_to_output_datum(
484
502
minted_assets: List < (ByteArray , Int )> ,
485
503
outputs: List < Output > ,
486
504
expected_asset: ByteArray ,
487
- expected_nft: NFTAsset ,
488
- validator_cred: PaymentCredential ,
505
+ validator_cred: Credential ,
506
+ validator_policy: PolicyId ,
489
507
) -> Bool {
490
508
when minted_assets is {
491
509
[] -> True
492
510
[(minted_asset_name, quantity), .. rest_assets] ->
493
511
if quantity == 1 {
494
- expect True = expected_asset == minted_asset_name
495
-
496
- expect True =
512
+ expect expected_asset == minted_asset_name
513
+ expect
497
514
list.any (
498
515
outputs,
499
516
fn (output) {
500
517
let Output { address, value, datum, .. } = output
501
-
502
518
if address.payment_credential == validator_cred {
503
519
// Check for nft present
504
- let NFTAsset { policy, asset } = expected_nft
505
- if quantity_of (value, policy, asset) == 1 {
520
+ if quantity_of (value, validator_policy, "" ) == 1 {
506
521
// Check for receipt datum for minted receipt token
507
522
expect InlineDatum (data) = datum
508
523
expect OwnerCheck { owner: Receipt (asset), .. }: OwnerCheck =
@@ -516,21 +531,20 @@ fn check_mint_to_output_datum(
516
531
}
517
532
},
518
533
)
519
-
520
534
check_mint_to_output_datum (
521
535
rest_assets,
522
536
outputs,
523
537
expected_asset,
524
- expected_nft,
525
538
validator_cred,
539
+ validator_policy,
526
540
)
527
541
} else if quantity == - 1 {
528
542
check_mint_to_output_datum (
529
543
rest_assets,
530
544
outputs,
531
545
expected_asset,
532
- expected_nft,
533
546
validator_cred,
547
+ validator_policy,
534
548
)
535
549
} else {
536
550
False
0 commit comments