From 06f63101b39c22fca74d357fe4f203324e0cd14c Mon Sep 17 00:00:00 2001 From: microproofs Date: Sat, 17 Jun 2023 17:25:44 -0400 Subject: [PATCH] chore: update some parts of the code for clarity --- validators/stakinator3000.ak | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/validators/stakinator3000.ak b/validators/stakinator3000.ak index 3907307..9306e02 100644 --- a/validators/stakinator3000.ak +++ b/validators/stakinator3000.ak @@ -56,6 +56,12 @@ type State { stake_registration: PosixTime, } +type OwnerCheck { + owner: Owner, + field1: Data, + field2: Data, +} + type NFTAsset { policy: PolicyId, asset: AssetName, @@ -89,6 +95,7 @@ validator(state_token: NFTAsset) { let Address { payment_credential, .. } = in_address + // Some destructuring fields in the script context expect ScriptCredential(own_pkh) = payment_credential let State { owner, redelegation_condition, .. } = state @@ -136,6 +143,7 @@ validator(state_token: NFTAsset) { // Check input contains parameterized NFT expect True = quantity_of(in_value, nft_policy, nft_asset) == 1 + // Validates non-recursive conditions let tx_condition_runner = fn(cond: TxCondition) -> Bool { when cond is { @@ -241,14 +249,16 @@ validator(state_token: NFTAsset) { ) == 1 } + // State token is spent and spend validator will perform owner check if list.any(inputs, find_predicate) { True } else { + // Not spend so we must check for owner expect Some(Input { output: Output { datum, .. }, .. }) = list.find(reference_inputs, find_predicate) expect InlineDatum(datum) = datum - expect State { owner, .. }: State = datum + expect OwnerCheck { owner, .. }: OwnerCheck = datum // Checks current owner is valid when owner is { @@ -480,12 +490,6 @@ fn validate_other_conditions( } } -type OwnerCheck { - owner: Owner, - field1: Data, - field2: Data, -} - // Check each minted token name is in the expected list, has quantity of 1, // and has a corresponding ouput with datum containing token name. // Alternatively allow for token burning