From 9bb4da476d63a9b2c2a0a2c1f42041b9cb6bc874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20=C5=9Aled=C5=BA?= Date: Sat, 31 Jan 2026 03:24:36 +0100 Subject: [PATCH] Shorten error codes across all validator contracts Renamed verbose error codes to more concise versions: - ERROR-*-VALIDATOR-X -> ERR-*-X (removed -VALIDATOR suffix) - ERROR-*-MINTING-POLICY-X -> ERR-*-X (removed -MINTING-POLICY suffix) - Further shortened module prefixes for better readability Specific renamings: - OnRisk: ERROR-ON-RISK-VALIDATOR-X -> ERR-ON-RISK-X - Funding: ERROR-FUNDING-VALIDATOR-X -> ERR-FUND-X - Initiated: ERROR-INITIATED-VALIDATOR-X -> ERR-INIT-X - Insurance: ERROR-INSURANCE-MAIN-VALIDATOR-X -> ERR-MAIN-X - PiggyBank: ERROR-PIGGY-BANK-VALIDATOR-X -> ERR-PBANK-X - Cancelled: ERROR-CANCELLED-VALIDATOR-X -> ERR-CANC-X - InsuranceId: ERROR-INSURANCE-ID-MINTING-POLICY-X -> ERR-IID-X - SystemId: ERROR-SYSTEM-ID-MINTING-POLICY-X -> ERR-SID-X This improves code readability and reduces on-chain script sizes. --- src/Fida/Contract/Insurance.hs | 16 +-- src/Fida/Contract/Insurance/InsuranceId.hs | 4 +- .../Contract/Insurance/Lifecycle/Cancelled.hs | 2 +- .../Contract/Insurance/Lifecycle/Funding.hs | 28 ++-- .../Contract/Insurance/Lifecycle/Initiated.hs | 30 ++-- .../Contract/Insurance/Lifecycle/OnRisk.hs | 60 ++++---- src/Fida/Contract/Insurance/PiggyBank.hs | 132 +++++++++--------- src/Fida/Contract/SystemId.hs | 4 +- 8 files changed, 140 insertions(+), 136 deletions(-) diff --git a/src/Fida/Contract/Insurance.hs b/src/Fida/Contract/Insurance.hs index 74327c6..a4c624d 100644 --- a/src/Fida/Contract/Insurance.hs +++ b/src/Fida/Contract/Insurance.hs @@ -36,13 +36,13 @@ import PlutusTx.Prelude -- -- On chain errors: -- --- ERROR-INSURANCE-MAIN-VALIDATOR-0: illegal action for main validator +-- ERR-MAIN-0: illegal action for main validator -- --- ERROR-INSURANCE-MAIN-VALIDATOR-1: TODO +-- ERR-MAIN-1: TODO -- --- ERROR-INSURANCE-MAIN-VALIDATOR-2: TODO +-- ERR-MAIN-2: TODO -- --- ERROR-INSURANCE-MAIN-VALIDATOR-3: TODO +-- ERR-MAIN-3: TODO {-# INLINEABLE mkInsurancePolicyValidator #-} mkInsurancePolicyValidator :: InsuranceId -> @@ -59,8 +59,8 @@ mkInsurancePolicyValidator iid d (PolicyFunding r) sc = mkInsurancePolicyValidator iid d (PolicyOnRisk r) sc = lifecycleOnRiskStateValidator iid d r sc mkInsurancePolicyValidator (InsuranceId cs) d@(InsuranceInfo {iInfoStartDate, iInfoInsurancePeriod, iInfoState, iInfoFundingDeadline}) PolicyExpire sc = - traceIfFalse "ERROR-INSURANCE-MAIN-VALIDATOR-2" hasExpired - && traceIfFalse "ERROR-INSURANCE-MAIN-VALIDATOR-3" correctOutputDatum + traceIfFalse "ERR-MAIN-2" hasExpired + && traceIfFalse "ERR-MAIN-3" correctOutputDatum where txInfo = scriptContextTxInfo sc @@ -68,7 +68,7 @@ mkInsurancePolicyValidator (InsuranceId cs) d@(InsuranceInfo {iInfoStartDate, iI case (iInfoState, iInfoStartDate) of (Funding, _) -> iInfoFundingDeadline (OnRisk, Just startDate) -> startDate + fromMilliSeconds iInfoInsurancePeriod - _ -> traceError "ERROR-INSURANCE-MAIN-VALIDATOR-1" + _ -> traceError "ERR-MAIN-1" hasExpired = expireDate `before` txInfoValidRange txInfo @@ -76,7 +76,7 @@ mkInsurancePolicyValidator (InsuranceId cs) d@(InsuranceInfo {iInfoStartDate, iI correctOutputDatum = outputDatum == untypedUpdatePolicyState d Expired mkInsurancePolicyValidator _ _ _ _ = - trace "ERROR-INSURANCE-MAIN-VALIDATOR-0" False + trace "ERR-MAIN-0" False {-# INLINEABLE mkInsurancePolicyValidatorUntyped #-} mkInsurancePolicyValidatorUntyped :: diff --git a/src/Fida/Contract/Insurance/InsuranceId.hs b/src/Fida/Contract/Insurance/InsuranceId.hs index 3223c94..6958c24 100644 --- a/src/Fida/Contract/Insurance/InsuranceId.hs +++ b/src/Fida/Contract/Insurance/InsuranceId.hs @@ -37,14 +37,14 @@ PlutusTx.makeLift ''InsuranceId {-# INLINEABLE mkInsuranceIdMintingPolicy #-} mkInsuranceIdMintingPolicy :: TxOutRef -> () -> ScriptContext -> Bool mkInsuranceIdMintingPolicy ref _ (ScriptContext txInfo (Minting _)) = - traceIfFalse "ERROR-INSURANCE-ID-MINTING-POLICY-0" isTxOutRefUsed + traceIfFalse "ERR-IID-0" isTxOutRefUsed where -- Ensure that the TxOutRef is used by the transaction. -- This parameter ensures the uniqueness of the currency symbol. isTxOutRefUsed = ref `elem` map txInInfoOutRef (txInfoInputs txInfo) mkInsuranceIdMintingPolicy _ _ _ = - trace "ERROR-INSURANCE-ID-MINTING-POLICY-1" False + trace "ERR-IID-1" False {-# INLINEABLE mkInsuranceIdMintingPolicyUntyped #-} mkInsuranceIdMintingPolicyUntyped :: diff --git a/src/Fida/Contract/Insurance/Lifecycle/Cancelled.hs b/src/Fida/Contract/Insurance/Lifecycle/Cancelled.hs index bc1dfd5..107f252 100644 --- a/src/Fida/Contract/Insurance/Lifecycle/Cancelled.hs +++ b/src/Fida/Contract/Insurance/Lifecycle/Cancelled.hs @@ -16,4 +16,4 @@ lifecycleCancelledStateValidator :: InsurancePolicyRedeemer -> ScriptContext -> Bool -lifecycleCancelledStateValidator _ _ _ _ = trace "ERROR-CANCELLED-VALIDATOR-0" False +lifecycleCancelledStateValidator _ _ _ _ = trace "ERR-CANC-0" False diff --git a/src/Fida/Contract/Insurance/Lifecycle/Funding.hs b/src/Fida/Contract/Insurance/Lifecycle/Funding.hs index d247c7c..0076ae2 100644 --- a/src/Fida/Contract/Insurance/Lifecycle/Funding.hs +++ b/src/Fida/Contract/Insurance/Lifecycle/Funding.hs @@ -39,19 +39,19 @@ import PlutusTx.Prelude -- -- On chain errors: -- --- ERROR-FUNDING-VALIDATOR-0: Illegal action for Funding state +-- ERR-FUND-0: Illegal action for Funding state -- --- ERROR-FUNDING-VALIDATOR-1: the tx is not signed by the policy authority +-- ERR-FUND-1: the tx is not signed by the policy authority -- --- ERROR-FUNDING-VALIDATOR-2: the output datum is not updated correctly +-- ERR-FUND-2: the output datum is not updated correctly -- --- ERROR-FUNDING-VALIDATOR-3: the number of sold fida cards is smaller than the number of fida cards +-- ERR-FUND-3: the number of sold fida cards is smaller than the number of fida cards -- --- ERROR-FUNDING-VALIDATOR-4: the output datum is not updated correctly +-- ERR-FUND-4: the output datum is not updated correctly -- --- ERROR-FUNDING-VALIDATOR-5: start date must be before valid range +-- ERR-FUND-5: start date must be before valid range -- --- ERROR-FUNDING-VALIDATOR-6: tx is not signed by the policy holder or policy authority +-- ERR-FUND-6: tx is not signed by the policy holder or policy authority {-# INLINEABLE lifecycleFundingStateValidator #-} lifecycleFundingStateValidator :: InsuranceId -> @@ -60,8 +60,8 @@ lifecycleFundingStateValidator :: ScriptContext -> Bool lifecycleFundingStateValidator (InsuranceId cs) d@InsuranceInfo {iInfoPolicyAuthority} PolicyFundingCancel sc = - traceIfFalse "ERROR-FUNDING-VALIDATOR-1" isSigned - && traceIfFalse "ERROR-FUNDING-VALIDATOR-2" hasCorrectOutput + traceIfFalse "ERR-FUND-1" isSigned + && traceIfFalse "ERR-FUND-2" hasCorrectOutput where isSigned = isSignedByTheAuthority sc iInfoPolicyAuthority @@ -69,10 +69,10 @@ lifecycleFundingStateValidator (InsuranceId cs) d@InsuranceInfo {iInfoPolicyAuth hasCorrectOutput = outputDatum == untypedUpdatePolicyState d Cancelled lifecycleFundingStateValidator (InsuranceId cs) (iinfo@InsuranceInfo {iInfoState = Funding, iInfoFidaCardNumber, iInfoPolicyHolder, iInfoPolicyAuthority}) (PolicyFundingFundingComplete startDate) sc = - traceIfFalse "ERROR-FUNDING-VALIDATOR-3" (fidaCardsSold >= iInfoFidaCardNumber) - && traceIfFalse "ERROR-FUNDING-VALIDATOR-4" hasCorrectOutput - && traceIfFalse "ERROR-FUNDING-VALIDATOR-5" isStartDateCorrect - && traceIfFalse "ERROR-FUNDING-VALIDATOR-6" (isSignedByPolicyHolder || isSignedByAuthority') + traceIfFalse "ERR-FUND-3" (fidaCardsSold >= iInfoFidaCardNumber) + && traceIfFalse "ERR-FUND-4" hasCorrectOutput + && traceIfFalse "ERR-FUND-5" isStartDateCorrect + && traceIfFalse "ERR-FUND-6" (isSignedByPolicyHolder || isSignedByAuthority') where txInfo = scriptContextTxInfo sc @@ -97,4 +97,4 @@ lifecycleFundingStateValidator (InsuranceId cs) (iinfo@InsuranceInfo {iInfoState isSignedByPolicyHolder = txSignedBy txInfo iInfoPolicyHolder isSignedByAuthority' = isSignedByTheAuthority sc iInfoPolicyAuthority -lifecycleFundingStateValidator _ _ _ _ = trace "ERROR-FUNDING-VALIDATOR-0" False +lifecycleFundingStateValidator _ _ _ _ = trace "ERR-FUND-0" False diff --git a/src/Fida/Contract/Insurance/Lifecycle/Initiated.hs b/src/Fida/Contract/Insurance/Lifecycle/Initiated.hs index aa2cc7b..ea9b767 100644 --- a/src/Fida/Contract/Insurance/Lifecycle/Initiated.hs +++ b/src/Fida/Contract/Insurance/Lifecycle/Initiated.hs @@ -49,21 +49,21 @@ import PlutusTx.Prelude -- -- On chain errors: -- --- ERROR-INITIATED-VALIDATOR-0: Illegal action for Initiated state +-- ERR-INIT-0: Illegal action for Initiated state -- --- ERROR-INITIATED-VALIDATOR-1: Transaction not signed by policy authority +-- ERR-INIT-1: Transaction not signed by policy authority -- --- ERROR-INITIATED-VALIDATOR-2: Insurance policy state not changed to Cancelled +-- ERR-INIT-2: Insurance policy state not changed to Cancelled -- --- ERROR-INITIATED-VALIDATOR-3: Payments not properly distributed +-- ERR-INIT-3: Payments not properly distributed -- --- ERROR-INITIATED-VALIDATOR-4: UTxO with policy datum was not spent +-- ERR-INIT-4: UTxO with policy datum was not spent -- --- ERROR-INITIATED-VALIDATOR-5: Payment info not marked by NFT +-- ERR-INIT-5: Payment info not marked by NFT -- --- ERROR-INITIATED-VALIDATOR-6: Insurance policy state not changed to Funding +-- ERR-INIT-6: Insurance policy state not changed to Funding -- --- ERROR-INITIATED-VALIDATOR-7: UTxO with premium payment was not spent +-- ERR-INIT-7: UTxO with premium payment was not spent {-# INLINEABLE lifecycleInitiatedStateValidator #-} lifecycleInitiatedStateValidator :: InsuranceId -> @@ -72,8 +72,8 @@ lifecycleInitiatedStateValidator :: ScriptContext -> Bool lifecycleInitiatedStateValidator (InsuranceId cs) datum@(InsuranceInfo {iInfoState = Initiated}) PolicyInitiatedCancel sc = - traceIfFalse "ERROR-INITIATED-VALIDATOR-1" isSigned - && traceIfFalse "ERROR-INITIATED-VALIDATOR-2" hasCorrectOutput + traceIfFalse "ERR-INIT-1" isSigned + && traceIfFalse "ERR-INIT-2" hasCorrectOutput where isSigned = isSignedByTheAuthority sc $ iInfoPolicyAuthority datum @@ -81,8 +81,8 @@ lifecycleInitiatedStateValidator (InsuranceId cs) datum@(InsuranceInfo {iInfoSta hasCorrectOutput = outputDatum == untypedUpdatePolicyState datum Cancelled lifecycleInitiatedStateValidator (InsuranceId cs) PremiumPaymentInfo {..} PolicyInitiatedPayPremium sc = - traceIfFalse "ERROR-INITIATED-VALIDATOR-3" (length (nub payments) == length ppInfoPiggyBanks) - && traceIfNotSingleton "ERROR-INITIATED-VALIDATOR-4" isPolicyInfoSpent + traceIfFalse "ERR-INIT-3" (length (nub payments) == length ppInfoPiggyBanks) + && traceIfNotSingleton "ERR-INIT-4" isPolicyInfoSpent where txInfo = scriptContextTxInfo sc @@ -103,8 +103,8 @@ lifecycleInitiatedStateValidator (InsuranceId cs) PremiumPaymentInfo {..} Policy in paid >= ppInfoPremiumAmountPerPiggyBank && paid == amount ] lifecycleInitiatedStateValidator (InsuranceId cs) d@InsuranceInfo {} PolicyInitiatedPayPremium sc = - traceIfFalse "ERROR-INITIATED-VALIDATOR-6" hasCorrectOutput - && traceIfNotSingleton "ERROR-INITIATED-VALIDATOR-7" isPremiumPaymentSpent + traceIfFalse "ERR-INIT-6" hasCorrectOutput + && traceIfNotSingleton "ERR-INIT-7" isPremiumPaymentSpent where txInfo = scriptContextTxInfo sc @@ -119,4 +119,4 @@ lifecycleInitiatedStateValidator (InsuranceId cs) d@InsuranceInfo {} PolicyIniti , valueOf value cs policyPaymentTokenName == 1 ] lifecycleInitiatedStateValidator _ _ _ _ = - trace "ERROR-INITIATED-VALIDATOR-0" False + trace "ERR-INIT-0" False diff --git a/src/Fida/Contract/Insurance/Lifecycle/OnRisk.hs b/src/Fida/Contract/Insurance/Lifecycle/OnRisk.hs index 7b25aa8..3153959 100644 --- a/src/Fida/Contract/Insurance/Lifecycle/OnRisk.hs +++ b/src/Fida/Contract/Insurance/Lifecycle/OnRisk.hs @@ -25,31 +25,31 @@ import Plutus.V2.Ledger.Contexts (txSignedBy) import PlutusTx.Prelude -- | --- ERROR-ON-RISK-VALIDATOR-0: Output datum doesn't match the updated datum +-- ERR-ON-RISK-0: Output datum doesn't match the updated datum -- --- ERROR-ON-RISK-VALIDATOR-1: Not signed by the policy holder +-- ERR-ON-RISK-1: Not signed by the policy holder -- --- ERROR-ON-RISK-VALIDATOR-2: Not signed by the policy authority +-- ERR-ON-RISK-2: Not signed by the policy authority -- --- ERROR-ON-RISK-VALIDATOR-3: Output datum doesn't match the updated datum +-- ERR-ON-RISK-3: Output datum doesn't match the updated datum -- --- ERROR-ON-RISK-VALIDATOR-4: Not signed by the policy holder +-- ERR-ON-RISK-4: Not signed by the policy holder or by the policy authority -- --- ERROR-ON-RISK-VALIDATOR-5: Output datum doesn't match the updated datum +-- ERR-ON-RISK-5: Output datum doesn't match the updated datum -- --- ERROR-ON-RISK-VALIDATOR-6: Not signed by the policy authority +-- ERR-ON-RISK-6: Not signed by the policy authority -- --- ERROR-ON-RISK-VALIDATOR-7: Output datum doesn't match the updated datum +-- ERR-ON-RISK-7: Output datum doesn't match the updated datum -- --- ERROR-ON-RISK-VALIDATOR-8: Not signed by the policy authority +-- ERR-ON-RISK-8: Not signed by the policy authority -- --- ERROR-ON-RISK-VALIDATOR-9: Output datum doesn't match the updated datum +-- ERR-ON-RISK-9: Output datum doesn't match the updated datum -- --- ERROR-ON-RISK-VALIDATOR-10: Output datum doesn't match the updated datum +-- ERR-ON-RISK-10: Output datum doesn't match the updated datum -- --- ERROR-ON-RISK-VALIDATOR-11: Claim expired +-- ERR-ON-RISK-11: Claim expired -- --- ERROR-ON-RISK-VALIDATOR-12: Not signed by the policy holder +-- ERR-ON-RISK-12: Not signed by the policy holder {-# INLINEABLE lifecycleOnRiskStateValidator #-} lifecycleOnRiskStateValidator :: InsuranceId -> @@ -58,8 +58,8 @@ lifecycleOnRiskStateValidator :: ScriptContext -> Bool lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoState = OnRisk}) (PolicyOnRiskCreateClaim c@(ClaimInfo {claimAccepted, claimDate})) sc = - traceIfFalse "ERROR-ON-RISK-VALIDATOR-0" correctOutputDatum - && traceIfFalse "ERROR-ON-RISK-VALIDATOR-1" isSignedByPolicyHolder + traceIfFalse "ERR-ON-RISK-0" correctOutputDatum + && traceIfFalse "ERR-ON-RISK-1" isSignedByPolicyHolder where isSignedByPolicyHolder = txSignedBy (scriptContextTxInfo sc) (iInfoPolicyHolder d) @@ -74,31 +74,35 @@ lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoState = On && claimAccepted == False && isClaimDateValid lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoPolicyAuthority, iInfoClaim = Just c}) PolicyOnRiskAcceptClaim sc = - traceIfFalse "ERROR-ON-RISK-VALIDATOR-2" (isSignedByTheAuthority sc iInfoPolicyAuthority) - && traceIfFalse "ERROR-ON-RISK-VALIDATOR-3" correctOutputDatum + traceIfFalse "ERR-ON-RISK-2" (isSignedByTheAuthority sc iInfoPolicyAuthority) + && traceIfFalse "ERR-ON-RISK-3" correctOutputDatum where outputDatum = untypedOutputDatum cs sc policyInfoTokenName correctOutputDatum = outputDatum == untypedUpdateClaim d c {claimAccepted = True} -lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoPolicyHolder, iInfoClaim = Just _}) PolicyOnRiskCloseClaim sc = - traceIfFalse "ERROR-ON-RISK-VALIDATOR-4" (txSignedBy txInfo iInfoPolicyHolder) - && traceIfFalse "ERROR-ON-RISK-VALIDATOR-5" correctOutputDatum +lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoPolicyAuthority, iInfoPolicyHolder, iInfoClaim = Just _}) PolicyOnRiskCloseClaim sc = + traceIfFalse "ERR-ON-RISK-4" (isSignedByAuth || isSignedByPolicyHolder) + && traceIfFalse "ERR-ON-RISK-5" correctOutputDatum where txInfo = scriptContextTxInfo sc outputDatum = untypedOutputDatum cs sc policyInfoTokenName correctOutputDatum = outputDatum == untypedUnsetClaim d + + isSignedByAuth = isSignedByTheAuthority sc iInfoPolicyAuthority + + isSignedByPolicyHolder = txSignedBy txInfo iInfoPolicyHolder lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoPolicyAuthority}) PolicyOnRiskFailClaim sc = - traceIfFalse "ERROR-ON-RISK-VALIDATOR-6" (isSignedByTheAuthority sc iInfoPolicyAuthority) - && traceIfFalse "ERROR-ON-RISK-VALIDATOR-7" correctOutputDatum + traceIfFalse "ERR-ON-RISK-6" (isSignedByTheAuthority sc iInfoPolicyAuthority) + && traceIfFalse "ERR-ON-RISK-7" correctOutputDatum where outputDatum = untypedOutputDatum cs sc policyInfoTokenName correctOutputDatum = outputDatum == untypedUnsetClaim d lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoPolicyAuthority}) PolicyOnRiskCancel sc = - traceIfFalse "ERROR-ON-RISK-VALIDATOR-8" isSigned - && traceIfFalse "ERROR-ON-RISK-VALIDATOR-9" correctOutput + traceIfFalse "ERR-ON-RISK-8" isSigned + && traceIfFalse "ERR-ON-RISK-9" correctOutput where isSigned = isSignedByTheAuthority sc iInfoPolicyAuthority @@ -106,8 +110,8 @@ lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoPolicyAuth correctOutput = outputDatum == untypedUpdatePolicyState d Cancelled lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoClaim = Just (ClaimInfo {claimDate}), iInfoClaimTimeToLive}) PolicyOnRiskExpireClaim sc = - traceIfFalse "ERROR-ON-RISK-VALIDATOR-10" correctOutputDatum - && traceIfFalse "ERROR-ON-RISK-VALIDATOR-11" claimExpired + traceIfFalse "ERR-ON-RISK-10" correctOutputDatum + && traceIfFalse "ERR-ON-RISK-11" claimExpired where outputDatum = untypedOutputDatum cs sc policyInfoTokenName @@ -117,7 +121,7 @@ lifecycleOnRiskStateValidator (InsuranceId cs) d@(InsuranceInfo {iInfoClaim = Ju claimExpired = before claimDeadLine (txInfoValidRange $ scriptContextTxInfo sc) lifecycleOnRiskStateValidator (InsuranceId cs) PolicyClaimPayment PolicyOnRiskClaimPayment sc = - traceIfNotSingleton "ERROR-ON-RISK-VALIDATOR-12" isSignedByPolicyHolder + traceIfNotSingleton "ERR-ON-RISK-12" isSignedByPolicyHolder where txInfo = scriptContextTxInfo sc @@ -127,4 +131,4 @@ lifecycleOnRiskStateValidator (InsuranceId cs) PolicyClaimPayment PolicyOnRiskCl , txSignedBy txInfo iInfoPolicyHolder ] lifecycleOnRiskStateValidator _ _ _ _ = - trace "ERROR-ON-RISK-VALIDATOR-13" False + trace "ERR-ON-RISK-13" False diff --git a/src/Fida/Contract/Insurance/PiggyBank.hs b/src/Fida/Contract/Insurance/PiggyBank.hs index b2e3be9..260fb05 100644 --- a/src/Fida/Contract/Insurance/PiggyBank.hs +++ b/src/Fida/Contract/Insurance/PiggyBank.hs @@ -55,69 +55,69 @@ import PlutusTx.Prelude -- -- On chain errors: -- --- ERROR-PIGGY-BANK-VALIDATOR-0: output datum doesn't say that the card is sold +-- ERR-PBANK-0: output datum doesn't say that the card is sold -- --- ERROR-PIGGY-BANK-VALIDATOR-1: output datum doesn't match input datum +-- ERR-PBANK-1: output datum doesn't match input datum -- --- ERROR-PIGGY-BANK-VALIDATOR-2: own input not found +-- ERR-PBANK-2: own input not found -- --- ERROR-PIGGY-BANK-VALIDATOR-3: correct output datum not found +-- ERR-PBANK-3: correct output datum not found -- --- ERROR-PIGGY-BANK-VALIDATOR-4: fida card not paid for +-- ERR-PBANK-4: fida card not paid for -- --- ERROR-PIGGY-BANK-VALIDATOR-5: output datum doesn't say that the card is not sold +-- ERR-PBANK-5: output datum doesn't say that the card is not sold -- --- ERROR-PIGGY-BANK-VALIDATOR-6: output datum doesn't match input datum +-- ERR-PBANK-6: output datum doesn't match input datum -- --- ERROR-PIGGY-BANK-VALIDATOR-7: not a fida card owner +-- ERR-PBANK-7: not a fida card owner -- --- ERROR-PIGGY-BANK-VALIDATOR-8: invalid claimed premium amount +-- ERR-PBANK-8: invalid claimed premium amount -- --- ERROR-PIGGY-BANK-VALIDATOR-9: no reference input with insurance info +-- ERR-PBANK-9: no reference input with insurance info -- --- ERROR-PIGGY-BANK-VALIDATOR-10: insurance policy has not been started (no start date) +-- ERR-PBANK-10: insurance policy has not been started (no start date) -- --- ERROR-PIGGY-BANK-VALIDATOR-11: claim is not accepted +-- ERR-PBANK-11: claim is not accepted -- --- ERROR-PIGGY-BANK-VALIDATOR-12: incorect collateral diff amount (to much collateral withdraw) +-- ERR-PBANK-12: incorect collateral diff amount (to much collateral withdraw) -- --- ERROR-PIGGY-BANK-VALIDATOR-13: claim was already paid +-- ERR-PBANK-13: claim was already paid -- --- ERROR-PIGGY-BANK-VALIDATOR-14: claim was not marked as paid +-- ERR-PBANK-14: claim was not marked as paid -- --- ERROR-PIGGY-BANK-VALIDATOR-15: paid for claim was not correct +-- ERR-PBANK-15: paid for claim was not correct -- --- ERROR-PIGGY-BANK-VALIDATOR-16: unauthorised access +-- ERR-PBANK-16: unauthorised access -- --- ERROR-PIGGY-BANK-VALIDATOR-17: fida card value can't be changed +-- ERR-PBANK-17: fida card value can't be changed -- --- ERROR-PIGGY-BANK-VALIDATOR-18: no reference input with insurance info +-- ERR-PBANK-18: no reference input with insurance info -- --- ERROR-PIGGY-BANK-VALIDATOR-19: own consumed input not found +-- ERR-PBANK-19: own consumed input not found -- --- ERROR-PIGGY-BANK-VALIDATOR-20: no output with correct datum +-- ERR-PBANK-20: no output with correct datum -- --- ERROR-PIGGY-BANK-VALIDATOR-21: policy is not cancelled +-- ERR-PBANK-21: policy is not cancelled -- --- ERROR-PIGGY-BANK-VALIDATOR-22: not signed by the policy holder +-- ERR-PBANK-22: not signed by the policy holder -- --- ERROR-PIGGY-BANK-VALIDATOR-23: invalid claimed premium amount +-- ERR-PBANK-23: invalid claimed premium amount -- --- ERROR-PIGGY-BANK-VALIDATOR-24: no reference input with insurance info +-- ERR-PBANK-24: no reference input with insurance info -- --- ERROR-PIGGY-BANK-VALIDATOR-25: policy is not cancelled +-- ERR-PBANK-25: policy is not cancelled -- --- ERROR-PIGGY-BANK-VALIDATOR-26: not a fida card owner +-- ERR-PBANK-26: not a fida card owner -- --- ERROR-PIGGY-BANK-VALIDATOR-27: policy is not cancelled +-- ERR-PBANK-27: policy is not cancelled -- --- ERROR-PIGGY-BANK-VALIDATOR-28: policy is not expired +-- ERR-PBANK-28: policy is not expired -- --- ERROR-PIGGY-BANK-VALIDATOR-29: not a fida card owner +-- ERR-PBANK-29: not a fida card owner -- --- ERROR-PIGGY-BANK-VALIDATOR-30: claim was not paid +-- ERR-PBANK-30: claim was not paid -- --- ERROR-PIGGY-BANK-VALIDATOR-31: no reference input with insurance info +-- ERR-PBANK-31: no reference input with insurance info {-# INLINEABLE mkPiggyBankValidator #-} @@ -129,22 +129,22 @@ mkPiggyBankValidator :: ScriptContext -> Bool mkPiggyBankValidator (InsuranceId cs) _ datum@(PBankFidaCard {pbfcIsSold = False, pbfcFidaCardValue}) BuyFidaCard sc = - traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-0" isSold + traceIfFalse "ERR-PBANK-0" isSold where inputLovelace = case findOwnInput sc of Just (TxInInfo _ (TxOut _ value _ _)) -> lovelaceValueOf value - Nothing -> traceError "ERROR-PIGGY-BANK-VALIDATOR-2" + Nothing -> traceError "ERR-PBANK-2" isSold = Just outputDatum' == untypedSetFidaCardSold datum outputDatum' = case untypedOutput cs sc fidaCardStatusTokenName of - Nothing -> traceError "ERROR-PIGGY-BANK-VALIDATOR-3" + Nothing -> traceError "ERR-PBANK-3" Just (TxOut _ v (OutputDatum (Datum d)) _) | lovelaceValueOf v >= pbfcFidaCardValue + inputLovelace -> d - | otherwise -> traceError "ERROR-PIGGY-BANK-VALIDATOR-4" + | otherwise -> traceError "ERR-PBANK-4" mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcIsSold = True, pbfcFidaCardValue}) SellFidaCard scriptContext = - traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-5" (not pbfcIsSold) - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-6" (pbfcFidaCardValue == pbfcFidaCardValue') + traceIfFalse "ERR-PBANK-5" (not pbfcIsSold) + && traceIfFalse "ERR-PBANK-6" (pbfcFidaCardValue == pbfcFidaCardValue') where datum = fromSingleton @@ -157,10 +157,10 @@ mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcIsSold (pbfcIsSold, pbfcFidaCardValue') = case datum of Just (PBankFidaCard {pbfcIsSold = isSold, pbfcFidaCardValue = cardValue}) -> (isSold, cardValue) - _ -> traceError "ERROR-PIGGY-BANK-VALIDATOR-8" + _ -> traceError "ERR-PBANK-8" mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) datum@(PBankPremium initAmount refund) ClaimPremium sc = - traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-7" isFidaCardOwner - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-8" isClaimedPremiumAmountValid + traceIfFalse "ERR-PBANK-7" isFidaCardOwner + && traceIfFalse "ERR-PBANK-8" isClaimedPremiumAmountValid where txInfo = scriptContextTxInfo sc isFidaCardOwner = valueOf (valueSpent txInfo) cs (fidaCardTokenName n) == 1 @@ -174,7 +174,7 @@ mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) datum@(PBankPremium initAmo (maybePolicyStartDate, paymentIntervals) = unsafeFromSingleton' - "ERROR-PIGGY-BANK-VALIDATOR-9" + "ERR-PBANK-9" [ (iInfoStartDate, iInfoInstallments) | InsuranceInfo {..} <- referenceDatums cs sc policyInfoTokenName ] @@ -182,17 +182,17 @@ mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) datum@(PBankPremium initAmo availablePremium = case maybePolicyStartDate of Just start -> unlockedPremiumToClaim (txInfoValidRange txInfo) initAmount paymentIntervals start - Nothing -> traceError "ERROR-PIGGY-BANK-VALIDATOR-10" + Nothing -> traceError "ERR-PBANK-10" isClaimedPremiumAmountValid = lockedPremium >= initAmount - refund - availablePremium mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcIsSold = True, pbfcFidaCardValue, pbfcPaidClaims}) PayForClaimWithCollateral sc = - traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-11" isClaimAccepted - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-12" collateralDiffAmountCorrect - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-13" claimNotPaidYet - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-14" claimMarkedAsPaid - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-15" isPaidCorrect - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-16" (isAfterClaimTimeToPay || isFidaCardOwner) - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-17" isFidaCardValueTheSame + traceIfFalse "ERR-PBANK-11" isClaimAccepted + && traceIfFalse "ERR-PBANK-12" collateralDiffAmountCorrect + && traceIfFalse "ERR-PBANK-13" claimNotPaidYet + && traceIfFalse "ERR-PBANK-14" claimMarkedAsPaid + && traceIfFalse "ERR-PBANK-15" isPaidCorrect + && traceIfFalse "ERR-PBANK-16" (isAfterClaimTimeToPay || isFidaCardOwner) + && traceIfFalse "ERR-PBANK-17" isFidaCardValueTheSame where txInfo = scriptContextTxInfo sc @@ -207,7 +207,7 @@ mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcIsSold , iInfoFidaCardNumber , iInfoClaimTimeToPay ) - _ -> traceError "ERROR-PIGGY-BANK-VALIDATOR-18" + _ -> traceError "ERR-PBANK-18" paid = lovelaceValueOf $ @@ -220,11 +220,11 @@ mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcIsSold inputCollateral = case findOwnInput sc of Just (TxInInfo _ (TxOut _ value _ _)) -> lovelaceValueOf value - Nothing -> traceError "ERROR-PIGGY-BANK-VALIDATOR-19" + Nothing -> traceError "ERR-PBANK-19" (outputCollateral, paidClaims, pbfcFidaCardValue'') = case output cs sc fidaCardStatusTokenName of Just (TxOut _ value _ _, PBankFidaCard {pbfcPaidClaims = pbfcPaidClaims', pbfcFidaCardValue = pbfcFidaCardValue'}) -> (lovelaceValueOf value, pbfcPaidClaims', pbfcFidaCardValue') - _ -> traceError "ERROR-PIGGY-BANK-VALIDATOR-20" + _ -> traceError "ERR-PBANK-20" collateralDiffAmountCorrect = claimAmount >= iInfoFidaCardNumber * (inputCollateral - outputCollateral) @@ -244,16 +244,16 @@ mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcIsSold -- TODO ClaimPremiumOnCancel rename to RefundPremium -- mkPiggyBankValidator (InsuranceId cs) _ datum@(PBankPremium initAmount refund) ClaimPremiumOnCancel sc = - traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-21" isPolicyCancelled - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-22" isSignedByPolicyHolder - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-23" isClaimedPremiumAmountValid - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-32" (refund == 0) + traceIfFalse "ERR-PBANK-21" isPolicyCancelled + && traceIfFalse "ERR-PBANK-22" isSignedByPolicyHolder + && traceIfFalse "ERR-PBANK-23" isClaimedPremiumAmountValid + && traceIfFalse "ERR-PBANK-32" (refund == 0) where txInfo = scriptContextTxInfo sc (policyState, policyHolder, maybePolicyStartDate, paymentIntervals) = unsafeFromSingleton' - "ERROR-PIGGY-BANK-VALIDATOR-24" + "ERR-PBANK-24" [ (iInfoState, iInfoPolicyHolder, iInfoStartDate, iInfoInstallments) | InsuranceInfo {..} <- referenceDatums cs sc policyInfoTokenName ] @@ -284,23 +284,23 @@ mkPiggyBankValidator (InsuranceId cs) _ datum@(PBankPremium initAmount refund) C isClaimedPremiumAmountValid = spendValue - lockedPremium <= refundAmount mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {}) UnlockCollateralOnCancel sc = - traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-25" isPolicyCancelled - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-26" isFidaCardOwner + traceIfFalse "ERR-PBANK-25" isPolicyCancelled + && traceIfFalse "ERR-PBANK-26" isFidaCardOwner where txInfo = scriptContextTxInfo sc isPolicyCancelled = unsafeFromSingleton' - "ERROR-PIGGY-BANK-VALIDATOR-27" + "ERR-PBANK-27" [ iInfoState == Cancelled | InsuranceInfo {..} <- referenceDatums cs sc policyInfoTokenName ] isFidaCardOwner = valueOf (valueSpent txInfo) cs (fidaCardTokenName n) == 1 mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcPaidClaims}) UnlockCollateral sc = - traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-28" isPolicyExpired - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-29" isFidaCardOwner - && traceIfFalse "ERROR-PIGGY-BANK-VALIDATOR-30" isClaimPaid + traceIfFalse "ERR-PBANK-28" isPolicyExpired + && traceIfFalse "ERR-PBANK-29" isFidaCardOwner + && traceIfFalse "ERR-PBANK-30" isClaimPaid where txInfo = scriptContextTxInfo sc @@ -310,14 +310,14 @@ mkPiggyBankValidator (InsuranceId cs) (FidaCardId n) (PBankFidaCard {pbfcPaidCla | iInfo@InsuranceInfo {..} <- referenceDatums cs sc policyInfoTokenName ] of [x] -> x - _ -> traceError "ERROR-PIGGY-BANK-VALIDATOR-31" + _ -> traceError "ERR-PBANK-31" isPolicyExpired = iInfoState == Expired isFidaCardOwner = valueOf (valueSpent txInfo) cs (fidaCardTokenName n) == 1 isClaimPaid = fromMaybe True (((`elem` pbfcPaidClaims) . claimId) <$> mClaim) mkPiggyBankValidator _ _ _ _ _ = - traceError "ERROR-PIGGY-BANK-VALIDATOR-32" + traceError "ERR-PBANK-32" {-# INLINEABLE mkPiggyBankValidatorUntyped #-} mkPiggyBankValidatorUntyped :: diff --git a/src/Fida/Contract/SystemId.hs b/src/Fida/Contract/SystemId.hs index 6fcaf58..a9794db 100644 --- a/src/Fida/Contract/SystemId.hs +++ b/src/Fida/Contract/SystemId.hs @@ -25,11 +25,11 @@ newtype SystemId = SystemId CurrencySymbol {-# INLINEABLE mkSystemIdMintingPolicy #-} mkSystemIdMintingPolicy :: SystemGovernance -> SystemMagic -> () -> ScriptContext -> Bool mkSystemIdMintingPolicy (SystemGovernance pkh) _ _ (ScriptContext txInfo (Minting _)) = - traceIfFalse "ERROR-SYSTEM-ID-MINTING-POLICY-0" isSignedBySystem + traceIfFalse "ERR-SID-0" isSignedBySystem where isSignedBySystem = txSignedBy txInfo pkh mkSystemIdMintingPolicy _ _ _ _ = - trace "ERROR-SYSTEM_ID-MINTING-POLICY-1" False + trace "ERR-SID-1" False {-# INLINEABLE mkSystemIdMintingPolicyUntyped #-} mkSystemIdMintingPolicyUntyped ::