{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Cardano.Ledger.Rules.ValidationMode (
lblStatic,
(?!#),
(?!#:),
failBecauseS,
applySTSNonStatic,
applySTSValidateSuchThat,
Inject (..),
Test,
runTest,
runTestOnSignal,
)
where
import Cardano.Ledger.BaseTypes (Inject (..))
import Cardano.Ledger.Core
import Control.State.Transition.Extended
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NE
import Validation
applySTSValidateSuchThat ::
forall s m rtype.
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
([Label] -> Bool) ->
RuleContext rtype s ->
m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSValidateSuchThat :: forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
([Label] -> Bool)
-> RuleContext rtype s
-> m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSValidateSuchThat [Label] -> Bool
cond =
forall s (m :: * -> *) (rtype :: RuleType) (ep :: EventPolicy).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
ApplySTSOpts ep
-> RuleContext rtype s
-> m (Either
(NonEmpty (PredicateFailure s)) (EventReturnType ep s (State s)))
applySTSOptsEither ApplySTSOpts 'EventPolicyDiscard
opts
where
opts :: ApplySTSOpts 'EventPolicyDiscard
opts =
ApplySTSOpts
{ asoAssertions :: AssertionPolicy
asoAssertions = AssertionPolicy
AssertionsOff
, asoValidation :: ValidationPolicy
asoValidation = ([Label] -> Bool) -> ValidationPolicy
ValidateSuchThat [Label] -> Bool
cond
, asoEvents :: SingEP 'EventPolicyDiscard
asoEvents = SingEP 'EventPolicyDiscard
EPDiscard
}
lblStatic :: Label
lblStatic :: Label
lblStatic = Label
"static"
(?!#) :: Bool -> PredicateFailure sts -> Rule sts ctx ()
?!# :: forall sts (ctx :: RuleType).
Bool -> PredicateFailure sts -> Rule sts ctx ()
(?!#) = forall sts (ctx :: RuleType).
NonEmpty Label -> Bool -> PredicateFailure sts -> Rule sts ctx ()
labeledPred forall a b. (a -> b) -> a -> b
$ Label
lblStatic forall a. a -> [a] -> NonEmpty a
NE.:| []
infix 1 ?!#
(?!#:) :: Either e () -> (e -> PredicateFailure sts) -> Rule sts ctx ()
?!#: :: forall e sts (ctx :: RuleType).
Either e () -> (e -> PredicateFailure sts) -> Rule sts ctx ()
(?!#:) = forall e sts (ctx :: RuleType).
NonEmpty Label
-> Either e () -> (e -> PredicateFailure sts) -> Rule sts ctx ()
labeledPredE forall a b. (a -> b) -> a -> b
$ Label
lblStatic forall a. a -> [a] -> NonEmpty a
NE.:| []
infix 1 ?!#:
failBecauseS :: PredicateFailure sts -> Rule sts ctx ()
failBecauseS :: forall sts (ctx :: RuleType).
PredicateFailure sts -> Rule sts ctx ()
failBecauseS = (Bool
False forall sts (ctx :: RuleType).
Bool -> PredicateFailure sts -> Rule sts ctx ()
?!#)
applySTSNonStatic ::
forall s m rtype.
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s ->
m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSNonStatic :: forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
RuleContext rtype s
-> m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSNonStatic = forall s (m :: * -> *) (rtype :: RuleType).
(STS s, RuleTypeRep rtype, m ~ BaseM s) =>
([Label] -> Bool)
-> RuleContext rtype s
-> m (Either (NonEmpty (PredicateFailure s)) (State s))
applySTSValidateSuchThat (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
notElem Label
lblStatic)
type Test failure = Validation (NonEmpty failure) ()
runTest :: InjectRuleFailure rule f era => Test (f era) -> Rule (EraRule rule era) ctx ()
runTest :: forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest = forall e sts (ctx :: RuleType).
(e -> PredicateFailure sts)
-> Validation (NonEmpty e) () -> Rule sts ctx ()
validateTrans forall (rule :: Symbol) (t :: * -> *) era.
InjectRuleFailure rule t era =>
t era -> EraRuleFailure rule era
injectFailure
runTestOnSignal :: InjectRuleFailure rule f era => Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal :: forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal = forall e sts (ctx :: RuleType).
(e -> PredicateFailure sts)
-> NonEmpty Label -> Validation (NonEmpty e) () -> Rule sts ctx ()
validateTransLabeled forall (rule :: Symbol) (t :: * -> *) era.
InjectRuleFailure rule t era =>
t era -> EraRuleFailure rule era
injectFailure forall a b. (a -> b) -> a -> b
$ Label
lblStatic forall a. a -> [a] -> NonEmpty a
NE.:| []