{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}

module Cardano.Ledger.Alonzo.Rules.Utxo (
  AlonzoUTXO,
  AlonzoUtxoPredFailure (..),
  allegraToAlonzoUtxoPredFailure,
  AlonzoUtxoEvent (..),
  validateCollateralContainsNonADA,
  validateExUnitsTooBigUTxO,
  validateOutputTooBigUTxO,
  validateInsufficientCollateral,
  validateOutsideForecast,
  validateScriptsNotPaidUTxO,
  validateTooManyCollateralInputs,
  validateWrongNetworkInTxBody,
  vKeyLocked,
) where

import Cardano.Ledger.Address (
  Addr (..),
  CompactAddr,
  RewardAccount,
  isBootstrapCompactAddr,
  isPayCredScriptCompactAddr,
 )
import Cardano.Ledger.Allegra.Rules (AllegraUtxoPredFailure, shelleyToAllegraUtxoPredFailure)
import qualified Cardano.Ledger.Allegra.Rules as Allegra
import Cardano.Ledger.Allegra.Scripts (ValidityInterval (..))
import Cardano.Ledger.Alonzo.Era (AlonzoEra, AlonzoUTXO)
import Cardano.Ledger.Alonzo.PParams
import Cardano.Ledger.Alonzo.Rules.Ppup ()
import Cardano.Ledger.Alonzo.Rules.Utxos (AlonzoUTXOS, AlonzoUtxosPredFailure)
import Cardano.Ledger.Alonzo.Scripts (ExUnits (..), pointWiseExUnits)
import Cardano.Ledger.Alonzo.Tx (AlonzoEraTx (..), totExUnits)
import Cardano.Ledger.Alonzo.TxBody (
  AllegraEraTxBody (..),
  AlonzoEraTxBody (..),
  AlonzoEraTxOut (..),
  MaryEraTxBody (..),
 )
import Cardano.Ledger.Alonzo.TxWits (AlonzoEraTxWits (..), unRedeemersL)
import Cardano.Ledger.BaseTypes (
  Mismatch (..),
  Network,
  ProtVer (..),
  Relation (..),
  ShelleyBase,
  StrictMaybe (..),
  epochInfo,
  knownNonZero,
  networkId,
  systemStart,
  (%.),
 )
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..), serialize)
import Cardano.Ledger.Binary.Coders (
  Decode (..),
  Encode (..),
  Wrapped (Open),
  decode,
  encode,
  (!>),
  (<!),
 )
import Cardano.Ledger.Coin (Coin (unCoin), DeltaCoin, rationalToCoinViaCeiling, toDeltaCoin)
import Cardano.Ledger.Core
import Cardano.Ledger.Credential (Credential (..))
import Cardano.Ledger.Rules.ValidationMode (
  Test,
  runTest,
  runTestOnSignal,
 )
import Cardano.Ledger.Shelley.LedgerState (UTxOState (utxosUtxo))
import Cardano.Ledger.Shelley.Rules (ShelleyPpupPredFailure, ShelleyUtxoPredFailure, UtxoEnv (..))
import qualified Cardano.Ledger.Shelley.Rules as Shelley
import Cardano.Ledger.State
import Cardano.Ledger.TxIn (TxIn)
import qualified Cardano.Ledger.Val as Val
import Cardano.Slotting.EpochInfo.API (EpochInfo, epochInfoSlotToUTCTime)
import Cardano.Slotting.EpochInfo.Extend (unsafeLinearExtendEpochInfo)
import Cardano.Slotting.Slot (SlotNo)
import Cardano.Slotting.Time (SystemStart)
import Control.DeepSeq (NFData)
import Control.Monad (unless)
import Control.Monad.Trans.Reader (asks)
import Control.SetAlgebra (eval, (◁))
import Control.State.Transition.Extended
import qualified Data.ByteString.Lazy as BSL (length)
import Data.Coerce (coerce)
import Data.Either (isRight)
import Data.Foldable as F (foldl', sequenceA_, toList)
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (NoThunks)
import Numeric.Natural (Natural)
import Validation

-- ==========================================================

data AlonzoUtxoPredFailure era
  = -- | The bad transaction inputs
    BadInputsUTxO
      (Set TxIn)
  | OutsideValidityIntervalUTxO
      -- | transaction's validity interval
      ValidityInterval
      -- | current slot
      SlotNo
  | MaxTxSizeUTxO (Mismatch 'RelLTEQ Integer)
  | InputSetEmptyUTxO
  | FeeTooSmallUTxO (Mismatch 'RelGTEQ Coin)
  | ValueNotConservedUTxO (Mismatch 'RelEQ (Value era))
  | -- | the set of addresses with incorrect network IDs
    WrongNetwork
      -- | the expected network id
      Network
      -- | the set of addresses with incorrect network IDs
      (Set Addr)
  | WrongNetworkWithdrawal
      -- | the expected network id
      Network
      -- | the set of reward addresses with incorrect network IDs
      (Set RewardAccount)
  | -- | list of supplied transaction outputs that are too small
    OutputTooSmallUTxO
      [TxOut era]
  | -- | Subtransition Failures
    UtxosFailure (PredicateFailure (EraRule "UTXOS" era))
  | -- | list of supplied bad transaction outputs
    OutputBootAddrAttrsTooBig
      [TxOut era]
  | -- Kept for backwards compatibility: no longer used because the `MultiAsset` type of mint doesn't allow for this possibility
    TriesToForgeADA
  | -- | list of supplied bad transaction output triples (actualSize,PParameterMaxValue,TxOut)
    OutputTooBigUTxO
      [(Integer, Integer, TxOut era)]
  | InsufficientCollateral
      -- | balance computed
      DeltaCoin
      -- | the required collateral for the given fee
      Coin
  | -- | The UTxO entries which have the wrong kind of script
    ScriptsNotPaidUTxO
      (UTxO era)
  | ExUnitsTooBigUTxO (Mismatch 'RelLTEQ ExUnits)
  | -- | The inputs marked for use as fees contain non-ADA tokens
    CollateralContainsNonADA (Value era)
  | -- | Wrong Network ID in body
    WrongNetworkInTxBody (Mismatch 'RelEQ Network)
  | -- | slot number outside consensus forecast range
    OutsideForecast
      SlotNo
  | -- | There are too many collateral inputs
    TooManyCollateralInputs (Mismatch 'RelLTEQ Natural)
  | NoCollateralInputs
  deriving ((forall x.
 AlonzoUtxoPredFailure era -> Rep (AlonzoUtxoPredFailure era) x)
-> (forall x.
    Rep (AlonzoUtxoPredFailure era) x -> AlonzoUtxoPredFailure era)
-> Generic (AlonzoUtxoPredFailure era)
forall x.
Rep (AlonzoUtxoPredFailure era) x -> AlonzoUtxoPredFailure era
forall x.
AlonzoUtxoPredFailure era -> Rep (AlonzoUtxoPredFailure era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x.
Rep (AlonzoUtxoPredFailure era) x -> AlonzoUtxoPredFailure era
forall era x.
AlonzoUtxoPredFailure era -> Rep (AlonzoUtxoPredFailure era) x
$cfrom :: forall era x.
AlonzoUtxoPredFailure era -> Rep (AlonzoUtxoPredFailure era) x
from :: forall x.
AlonzoUtxoPredFailure era -> Rep (AlonzoUtxoPredFailure era) x
$cto :: forall era x.
Rep (AlonzoUtxoPredFailure era) x -> AlonzoUtxoPredFailure era
to :: forall x.
Rep (AlonzoUtxoPredFailure era) x -> AlonzoUtxoPredFailure era
Generic)

type instance EraRuleFailure "UTXO" AlonzoEra = AlonzoUtxoPredFailure AlonzoEra

instance InjectRuleFailure "UTXO" AlonzoUtxoPredFailure AlonzoEra

instance InjectRuleFailure "UTXO" ShelleyPpupPredFailure AlonzoEra where
  injectFailure :: ShelleyPpupPredFailure AlonzoEra -> EraRuleFailure "UTXO" AlonzoEra
injectFailure = PredicateFailure (EraRule "UTXOS" AlonzoEra)
-> AlonzoUtxoPredFailure AlonzoEra
AlonzoUtxosPredFailure AlonzoEra -> AlonzoUtxoPredFailure AlonzoEra
forall era.
PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
UtxosFailure (AlonzoUtxosPredFailure AlonzoEra
 -> AlonzoUtxoPredFailure AlonzoEra)
-> (ShelleyPpupPredFailure AlonzoEra
    -> AlonzoUtxosPredFailure AlonzoEra)
-> ShelleyPpupPredFailure AlonzoEra
-> AlonzoUtxoPredFailure AlonzoEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyPpupPredFailure AlonzoEra
-> EraRuleFailure "UTXOS" AlonzoEra
ShelleyPpupPredFailure AlonzoEra
-> AlonzoUtxosPredFailure AlonzoEra
forall (rule :: Symbol) (t :: * -> *) era.
InjectRuleFailure rule t era =>
t era -> EraRuleFailure rule era
injectFailure

instance InjectRuleFailure "UTXO" ShelleyUtxoPredFailure AlonzoEra where
  injectFailure :: ShelleyUtxoPredFailure AlonzoEra -> EraRuleFailure "UTXO" AlonzoEra
injectFailure = AllegraUtxoPredFailure AlonzoEra -> AlonzoUtxoPredFailure AlonzoEra
forall (t :: * -> *) era.
(EraRuleFailure "PPUP" era ~ t era,
 InjectRuleFailure "UTXOS" t era) =>
AllegraUtxoPredFailure era -> AlonzoUtxoPredFailure era
allegraToAlonzoUtxoPredFailure (AllegraUtxoPredFailure AlonzoEra
 -> AlonzoUtxoPredFailure AlonzoEra)
-> (ShelleyUtxoPredFailure AlonzoEra
    -> AllegraUtxoPredFailure AlonzoEra)
-> ShelleyUtxoPredFailure AlonzoEra
-> AlonzoUtxoPredFailure AlonzoEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ShelleyUtxoPredFailure AlonzoEra
-> AllegraUtxoPredFailure AlonzoEra
forall era.
ShelleyUtxoPredFailure era -> AllegraUtxoPredFailure era
shelleyToAllegraUtxoPredFailure

instance InjectRuleFailure "UTXO" AllegraUtxoPredFailure AlonzoEra where
  injectFailure :: AllegraUtxoPredFailure AlonzoEra -> EraRuleFailure "UTXO" AlonzoEra
injectFailure = AllegraUtxoPredFailure AlonzoEra -> EraRuleFailure "UTXO" AlonzoEra
AllegraUtxoPredFailure AlonzoEra -> AlonzoUtxoPredFailure AlonzoEra
forall (t :: * -> *) era.
(EraRuleFailure "PPUP" era ~ t era,
 InjectRuleFailure "UTXOS" t era) =>
AllegraUtxoPredFailure era -> AlonzoUtxoPredFailure era
allegraToAlonzoUtxoPredFailure

instance InjectRuleFailure "UTXO" AlonzoUtxosPredFailure AlonzoEra where
  injectFailure :: AlonzoUtxosPredFailure AlonzoEra -> EraRuleFailure "UTXO" AlonzoEra
injectFailure = PredicateFailure (EraRule "UTXOS" AlonzoEra)
-> AlonzoUtxoPredFailure AlonzoEra
AlonzoUtxosPredFailure AlonzoEra -> EraRuleFailure "UTXO" AlonzoEra
forall era.
PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
UtxosFailure

deriving stock instance
  ( Era era
  , Show (Value era)
  , Show (TxOut era)
  , Show (TxBody era)
  , Show (PredicateFailure (EraRule "UTXOS" era))
  ) =>
  Show (AlonzoUtxoPredFailure era)

deriving stock instance
  ( Era era
  , Eq (Value era)
  , Eq (TxOut era)
  , Eq (PredicateFailure (EraRule "UTXOS" era))
  ) =>
  Eq (AlonzoUtxoPredFailure era)

instance
  ( NoThunks (Value era)
  , NoThunks (UTxO era)
  , NoThunks (PredicateFailure (EraRule "UTXOS" era))
  , NoThunks (TxOut era)
  ) =>
  NoThunks (AlonzoUtxoPredFailure era)

instance
  ( Era era
  , NFData (Value era)
  , NFData (UTxO era)
  , NFData (PredicateFailure (EraRule "UTXOS" era))
  , NFData (TxOut era)
  ) =>
  NFData (AlonzoUtxoPredFailure era)

newtype AlonzoUtxoEvent era
  = UtxosEvent (Event (EraRule "UTXOS" era))
  deriving ((forall x. AlonzoUtxoEvent era -> Rep (AlonzoUtxoEvent era) x)
-> (forall x. Rep (AlonzoUtxoEvent era) x -> AlonzoUtxoEvent era)
-> Generic (AlonzoUtxoEvent era)
forall x. Rep (AlonzoUtxoEvent era) x -> AlonzoUtxoEvent era
forall x. AlonzoUtxoEvent era -> Rep (AlonzoUtxoEvent era) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall era x. Rep (AlonzoUtxoEvent era) x -> AlonzoUtxoEvent era
forall era x. AlonzoUtxoEvent era -> Rep (AlonzoUtxoEvent era) x
$cfrom :: forall era x. AlonzoUtxoEvent era -> Rep (AlonzoUtxoEvent era) x
from :: forall x. AlonzoUtxoEvent era -> Rep (AlonzoUtxoEvent era) x
$cto :: forall era x. Rep (AlonzoUtxoEvent era) x -> AlonzoUtxoEvent era
to :: forall x. Rep (AlonzoUtxoEvent era) x -> AlonzoUtxoEvent era
Generic)

deriving instance Show (Event (EraRule "UTXOS" era)) => Show (AlonzoUtxoEvent era)

deriving instance Eq (Event (EraRule "UTXOS" era)) => Eq (AlonzoUtxoEvent era)

instance NFData (Event (EraRule "UTXOS" era)) => NFData (AlonzoUtxoEvent era)

-- | Returns true for VKey locked addresses, and false for any kind of
-- script-locked address.
isKeyHashAddr :: Addr -> Bool
isKeyHashAddr :: Addr -> Bool
isKeyHashAddr (AddrBootstrap BootstrapAddress
_) = Bool
True
isKeyHashAddr (Addr Network
_ (KeyHashObj KeyHash 'Payment
_) StakeReference
_) = Bool
True
isKeyHashAddr Addr
_ = Bool
False

-- | This is equivalent to `isKeyHashAddr`, but for compacted version of an address.
isKeyHashCompactAddr :: CompactAddr -> Bool
isKeyHashCompactAddr :: CompactAddr -> Bool
isKeyHashCompactAddr CompactAddr
cAddr =
  CompactAddr -> Bool
isBootstrapCompactAddr CompactAddr
cAddr Bool -> Bool -> Bool
|| Bool -> Bool
not (CompactAddr -> Bool
isPayCredScriptCompactAddr CompactAddr
cAddr)

vKeyLocked :: EraTxOut era => TxOut era -> Bool
vKeyLocked :: forall era. EraTxOut era => TxOut era -> Bool
vKeyLocked TxOut era
txOut =
  case TxOut era
txOut TxOut era
-> Getting
     (Either Addr CompactAddr) (TxOut era) (Either Addr CompactAddr)
-> Either Addr CompactAddr
forall s a. s -> Getting a s a -> a
^. Getting
  (Either Addr CompactAddr) (TxOut era) (Either Addr CompactAddr)
forall era.
EraTxOut era =>
Lens' (TxOut era) (Either Addr CompactAddr)
Lens' (TxOut era) (Either Addr CompactAddr)
addrEitherTxOutL of
    Left Addr
addr -> Addr -> Bool
isKeyHashAddr Addr
addr
    Right CompactAddr
cAddr -> CompactAddr -> Bool
isKeyHashCompactAddr CompactAddr
cAddr

-- | feesOK is a predicate with several parts. Some parts only apply in special circumstances.
--   1) The fee paid is >= the minimum fee
--   2) If the total ExUnits are 0 in both Memory and Steps, no further part needs to be checked.
--   3) The collateral consists only of VKey addresses
--   4) The collateral is sufficient to cover the appropriate percentage of the
--      fee marked in the transaction
--   5) The collateral inputs do not contain any non-ADA part
--   6) There is at least one collateral input
--   As a TransitionRule it will return (), and produce a validation failure (rather than
--   return) if any of the required parts are False.
feesOK ::
  forall era.
  ( AlonzoEraTx era
  , EraUTxO era
  ) =>
  PParams era ->
  Tx era ->
  UTxO era ->
  Test (AlonzoUtxoPredFailure era)
feesOK :: forall era.
(AlonzoEraTx era, EraUTxO era) =>
PParams era
-> Tx era -> UTxO era -> Test (AlonzoUtxoPredFailure era)
feesOK PParams era
pp Tx era
tx u :: UTxO era
u@(UTxO Map TxIn (TxOut era)
utxo) =
  let txBody :: TxBody era
txBody = Tx era
tx Tx era -> Getting (TxBody era) (Tx era) (TxBody era) -> TxBody era
forall s a. s -> Getting a s a -> a
^. Getting (TxBody era) (Tx era) (TxBody era)
forall era. EraTx era => Lens' (Tx era) (TxBody era)
Lens' (Tx era) (TxBody era)
bodyTxL
      collateral :: Set TxIn
collateral = TxBody era
txBody TxBody era
-> Getting (Set TxIn) (TxBody era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. Getting (Set TxIn) (TxBody era) (Set TxIn)
forall era. AlonzoEraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody era) (Set TxIn)
collateralInputsTxBodyL -- Inputs allocated to pay txfee
      -- restrict Utxo to those inputs we use to pay fees.
      utxoCollateral :: Map TxIn (TxOut era)
utxoCollateral = Exp (Map TxIn (TxOut era)) -> Map TxIn (TxOut era)
forall s t. Embed s t => Exp t -> s
eval (Set TxIn
collateral Set TxIn -> Map TxIn (TxOut era) -> Exp (Map TxIn (TxOut era))
forall k s1 s2 (f :: * -> * -> *) v.
(Ord k, HasExp s1 (Sett k ()), HasExp s2 (f k v)) =>
s1 -> s2 -> Exp (f k v)
 Map TxIn (TxOut era)
utxo)
      theFee :: Coin
theFee = TxBody era
txBody TxBody era -> Getting Coin (TxBody era) Coin -> Coin
forall s a. s -> Getting a s a -> a
^. Getting Coin (TxBody era) Coin
forall era. EraTxBody era => Lens' (TxBody era) Coin
Lens' (TxBody era) Coin
feeTxBodyL
      minFee :: Coin
minFee = PParams era -> Tx era -> UTxO era -> Coin
forall era.
EraUTxO era =>
PParams era -> Tx era -> UTxO era -> Coin
getMinFeeTxUtxo PParams era
pp Tx era
tx UTxO era
u
   in [Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()]
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Applicative f) =>
t (f a) -> f ()
sequenceA_
        [ -- Part 1: minfee pp tx ≤ txfee txb
          Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless
            (Coin
minFee Coin -> Coin -> Bool
forall a. Ord a => a -> a -> Bool
<= Coin
theFee)
            (Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
FeeTooSmallUTxO Mismatch {mismatchSupplied :: Coin
mismatchSupplied = Coin
theFee, mismatchExpected :: Coin
mismatchExpected = Coin
minFee})
        , -- Part 2: (txrdmrs tx ≠ ∅ ⇒ validateCollateral)
          Bool
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool
forall a. Map (PlutusPurpose AsIx era) a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool)
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool
forall a b. (a -> b) -> a -> b
$ Tx era
tx Tx era
-> Getting
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
     (Tx era)
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits)
forall s a. s -> Getting a s a -> a
^. (TxWits era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> Tx era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Tx era)
forall era. EraTx era => Lens' (Tx era) (TxWits era)
Lens' (Tx era) (TxWits era)
witsTxL ((TxWits era
  -> Const
       (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
 -> Tx era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Tx era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Const
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> TxWits era
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> Getting
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
     (Tx era)
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Redeemers era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
-> TxWits era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era)
forall era.
AlonzoEraTxWits era =>
Lens' (TxWits era) (Redeemers era)
Lens' (TxWits era) (Redeemers era)
rdmrsTxWitsL ((Redeemers era
  -> Const
       (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
 -> TxWits era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Const
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> Redeemers era
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
-> (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> TxWits era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> Redeemers era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era)
forall era.
AlonzoEraScript era =>
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
unRedeemersL) (Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$
            PParams era
-> TxBody era
-> Map TxIn (TxOut era)
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall era.
(EraTxBody era, AlonzoEraPParams era) =>
PParams era
-> TxBody era
-> Map TxIn (TxOut era)
-> Test (AlonzoUtxoPredFailure era)
validateCollateral PParams era
pp TxBody era
txBody Map TxIn (TxOut era)
utxoCollateral
        ]

validateCollateral ::
  ( EraTxBody era
  , AlonzoEraPParams era
  ) =>
  PParams era ->
  TxBody era ->
  Map.Map TxIn (TxOut era) ->
  Test (AlonzoUtxoPredFailure era)
validateCollateral :: forall era.
(EraTxBody era, AlonzoEraPParams era) =>
PParams era
-> TxBody era
-> Map TxIn (TxOut era)
-> Test (AlonzoUtxoPredFailure era)
validateCollateral PParams era
pp TxBody era
txb Map TxIn (TxOut era)
utxoCollateral =
  [Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()]
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Applicative f) =>
t (f a) -> f ()
sequenceA_
    [ -- Part 3: (∀(a,_,_) ∈ range (collateral txb ◁ utxo), a ∈ Addrvkey)
      Map TxIn (TxOut era)
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall era.
EraTxOut era =>
Map TxIn (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateScriptsNotPaidUTxO Map TxIn (TxOut era)
utxoCollateral
    , -- Part 4: balance ∗ 100 ≥ txfee txb ∗ (collateralPercent pp)
      PParams era
-> TxBody era
-> DeltaCoin
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall era.
(EraTxBody era, AlonzoEraPParams era) =>
PParams era
-> TxBody era -> DeltaCoin -> Test (AlonzoUtxoPredFailure era)
validateInsufficientCollateral PParams era
pp TxBody era
txb DeltaCoin
bal
    , -- Part 5: isAdaOnly balance
      Map TxIn (TxOut era)
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall (f :: * -> *) era.
(Foldable f, EraTxOut era) =>
f (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateCollateralContainsNonADA Map TxIn (TxOut era)
utxoCollateral
    , -- Part 6: (∀(a,_,_) ∈ range (collateral txb ◁ utxo), a ∈ Addrvkey)
      Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureIf (Map TxIn (TxOut era) -> Bool
forall a. Map TxIn a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null Map TxIn (TxOut era)
utxoCollateral) AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
NoCollateralInputs
    ]
  where
    bal :: DeltaCoin
bal = Coin -> DeltaCoin
toDeltaCoin (Coin -> DeltaCoin) -> Coin -> DeltaCoin
forall a b. (a -> b) -> a -> b
$ Map TxIn (TxOut era) -> Coin
forall era (f :: * -> *).
(EraTxOut era, Foldable f) =>
f (TxOut era) -> Coin
sumAllCoin Map TxIn (TxOut era)
utxoCollateral

-- > (∀(a,_,_) ∈ range (collateral txb ◁ utxo), a ∈ Addrvkey)
validateScriptsNotPaidUTxO ::
  EraTxOut era =>
  Map.Map TxIn (TxOut era) ->
  Test (AlonzoUtxoPredFailure era)
validateScriptsNotPaidUTxO :: forall era.
EraTxOut era =>
Map TxIn (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateScriptsNotPaidUTxO Map TxIn (TxOut era)
utxoCollateral =
  Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless ((TxOut era -> Bool) -> Map TxIn (TxOut era) -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all TxOut era -> Bool
forall era. EraTxOut era => TxOut era -> Bool
vKeyLocked Map TxIn (TxOut era)
utxoCollateral) (AlonzoUtxoPredFailure era
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$
    UTxO era -> AlonzoUtxoPredFailure era
forall era. UTxO era -> AlonzoUtxoPredFailure era
ScriptsNotPaidUTxO (Map TxIn (TxOut era) -> UTxO era
forall era. Map TxIn (TxOut era) -> UTxO era
UTxO ((TxOut era -> Bool) -> Map TxIn (TxOut era) -> Map TxIn (TxOut era)
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Bool -> Bool
not (Bool -> Bool) -> (TxOut era -> Bool) -> TxOut era -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TxOut era -> Bool
forall era. EraTxOut era => TxOut era -> Bool
vKeyLocked) Map TxIn (TxOut era)
utxoCollateral))

-- > balance ∗ 100 ≥ txfee txb ∗ (collateralPercent pp)
validateInsufficientCollateral ::
  ( EraTxBody era
  , AlonzoEraPParams era
  ) =>
  PParams era ->
  TxBody era ->
  DeltaCoin ->
  Test (AlonzoUtxoPredFailure era)
validateInsufficientCollateral :: forall era.
(EraTxBody era, AlonzoEraPParams era) =>
PParams era
-> TxBody era -> DeltaCoin -> Test (AlonzoUtxoPredFailure era)
validateInsufficientCollateral PParams era
pp TxBody era
txBody DeltaCoin
bal =
  Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless (Int -> DeltaCoin -> DeltaCoin
forall t i. (Val t, Integral i) => i -> t -> t
Val.scale (Int
100 :: Int) DeltaCoin
bal DeltaCoin -> DeltaCoin -> Bool
forall a. Ord a => a -> a -> Bool
>= Natural -> DeltaCoin -> DeltaCoin
forall t i. (Val t, Integral i) => i -> t -> t
Val.scale Natural
collPerc (Coin -> DeltaCoin
toDeltaCoin Coin
txfee)) (AlonzoUtxoPredFailure era
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$
    DeltaCoin -> Coin -> AlonzoUtxoPredFailure era
forall era. DeltaCoin -> Coin -> AlonzoUtxoPredFailure era
InsufficientCollateral DeltaCoin
bal (Coin -> AlonzoUtxoPredFailure era)
-> Coin -> AlonzoUtxoPredFailure era
forall a b. (a -> b) -> a -> b
$
      Rational -> Coin
rationalToCoinViaCeiling (Rational -> Coin) -> Rational -> Coin
forall a b. (a -> b) -> a -> b
$
        (Natural -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
collPerc Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Coin -> Integer
unCoin Coin
txfee) Integer -> NonZero Integer -> Rational
forall a. Integral a => a -> NonZero a -> Ratio a
%. forall (n :: Natural). (KnownNat n, 1 <= n) => NonZero Integer
knownNonZero @100
  where
    txfee :: Coin
txfee = TxBody era
txBody TxBody era -> Getting Coin (TxBody era) Coin -> Coin
forall s a. s -> Getting a s a -> a
^. Getting Coin (TxBody era) Coin
forall era. EraTxBody era => Lens' (TxBody era) Coin
Lens' (TxBody era) Coin
feeTxBodyL -- Coin supplied to pay fees
    collPerc :: Natural
collPerc = PParams era
pp PParams era -> Getting Natural (PParams era) Natural -> Natural
forall s a. s -> Getting a s a -> a
^. Getting Natural (PParams era) Natural
forall era. AlonzoEraPParams era => Lens' (PParams era) Natural
Lens' (PParams era) Natural
ppCollateralPercentageL

-- > isAdaOnly balance
validateCollateralContainsNonADA ::
  (Foldable f, EraTxOut era) =>
  f (TxOut era) ->
  Test (AlonzoUtxoPredFailure era)
validateCollateralContainsNonADA :: forall (f :: * -> *) era.
(Foldable f, EraTxOut era) =>
f (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateCollateralContainsNonADA f (TxOut era)
collateralTxOuts =
  Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless (f (TxOut era) -> Bool
forall era (f :: * -> *).
(EraTxOut era, Foldable f) =>
f (TxOut era) -> Bool
areAllAdaOnly f (TxOut era)
collateralTxOuts) (AlonzoUtxoPredFailure era
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$
    Value era -> AlonzoUtxoPredFailure era
forall era. Value era -> AlonzoUtxoPredFailure era
CollateralContainsNonADA (Value era -> AlonzoUtxoPredFailure era)
-> Value era -> AlonzoUtxoPredFailure era
forall a b. (a -> b) -> a -> b
$
      f (TxOut era) -> Value era
forall era (f :: * -> *).
(EraTxOut era, Foldable f) =>
f (TxOut era) -> Value era
sumAllValue f (TxOut era)
collateralTxOuts

-- | If tx has non-native scripts, end of validity interval must translate to time
--
-- > (_,i_f) := txvldt tx
-- > ◇ ∉ { txrdmrs tx, i_f } ⇒ epochInfoSlotToUTCTime epochInfo systemTime i_f ≠ ◇
validateOutsideForecast ::
  ( MaryEraTxBody era
  , AlonzoEraTxWits era
  , EraTx era
  ) =>
  EpochInfo (Either a) ->
  -- | Current slot number
  SlotNo ->
  SystemStart ->
  Tx era ->
  Test (AlonzoUtxoPredFailure era)
validateOutsideForecast :: forall era a.
(MaryEraTxBody era, AlonzoEraTxWits era, EraTx era) =>
EpochInfo (Either a)
-> SlotNo
-> SystemStart
-> Tx era
-> Test (AlonzoUtxoPredFailure era)
validateOutsideForecast EpochInfo (Either a)
ei SlotNo
slotNo SystemStart
sysSt Tx era
tx =
  {-   (_,i_f) := txvldt tx   -}
  case Tx era
tx Tx era
-> Getting ValidityInterval (Tx era) ValidityInterval
-> ValidityInterval
forall s a. s -> Getting a s a -> a
^. (TxBody era -> Const ValidityInterval (TxBody era))
-> Tx era -> Const ValidityInterval (Tx era)
forall era. EraTx era => Lens' (Tx era) (TxBody era)
Lens' (Tx era) (TxBody era)
bodyTxL ((TxBody era -> Const ValidityInterval (TxBody era))
 -> Tx era -> Const ValidityInterval (Tx era))
-> ((ValidityInterval -> Const ValidityInterval ValidityInterval)
    -> TxBody era -> Const ValidityInterval (TxBody era))
-> Getting ValidityInterval (Tx era) ValidityInterval
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ValidityInterval -> Const ValidityInterval ValidityInterval)
-> TxBody era -> Const ValidityInterval (TxBody era)
forall era.
AllegraEraTxBody era =>
Lens' (TxBody era) ValidityInterval
Lens' (TxBody era) ValidityInterval
vldtTxBodyL of
    ValidityInterval StrictMaybe SlotNo
_ (SJust SlotNo
ifj)
      | Bool -> Bool
not (Bool -> Bool)
-> (Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool)
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool
forall a. Map (PlutusPurpose AsIx era) a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool)
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits) -> Bool
forall a b. (a -> b) -> a -> b
$ Tx era
tx Tx era
-> Getting
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
     (Tx era)
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
-> Map (PlutusPurpose AsIx era) (Data era, ExUnits)
forall s a. s -> Getting a s a -> a
^. (TxWits era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> Tx era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Tx era)
forall era. EraTx era => Lens' (Tx era) (TxWits era)
Lens' (Tx era) (TxWits era)
witsTxL ((TxWits era
  -> Const
       (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
 -> Tx era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Tx era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Const
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> TxWits era
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> Getting
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
     (Tx era)
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Redeemers era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
-> TxWits era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era)
forall era.
AlonzoEraTxWits era =>
Lens' (TxWits era) (Redeemers era)
Lens' (TxWits era) (Redeemers era)
rdmrsTxWitsL ((Redeemers era
  -> Const
       (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
 -> TxWits era
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era))
-> ((Map (PlutusPurpose AsIx era) (Data era, ExUnits)
     -> Const
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
          (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
    -> Redeemers era
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era))
-> (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
    -> Const
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
         (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> TxWits era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (TxWits era)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map (PlutusPurpose AsIx era) (Data era, ExUnits)
 -> Const
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
      (Map (PlutusPurpose AsIx era) (Data era, ExUnits)))
-> Redeemers era
-> Const
     (Map (PlutusPurpose AsIx era) (Data era, ExUnits)) (Redeemers era)
forall era.
AlonzoEraScript era =>
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
Lens'
  (Redeemers era) (Map (PlutusPurpose AsIx era) (Data era, ExUnits))
unRedeemersL ->
          let ei' :: EpochInfo (Either a)
ei' = SlotNo -> EpochInfo (Either a) -> EpochInfo (Either a)
forall (m :: * -> *).
Monad m =>
SlotNo -> EpochInfo m -> EpochInfo m
unsafeLinearExtendEpochInfo SlotNo
slotNo EpochInfo (Either a)
ei
           in -- ◇ ∉ { txrdmrs tx, i_f } ⇒
              Bool
-> AlonzoUtxoPredFailure era -> Test (AlonzoUtxoPredFailure era)
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless (Either a UTCTime -> Bool
forall a b. Either a b -> Bool
isRight (EpochInfo (Either a) -> SystemStart -> SlotNo -> Either a UTCTime
forall (m :: * -> *).
(HasCallStack, Monad m) =>
EpochInfo m -> SystemStart -> SlotNo -> m UTCTime
epochInfoSlotToUTCTime EpochInfo (Either a)
ei' SystemStart
sysSt SlotNo
ifj)) (AlonzoUtxoPredFailure era -> Test (AlonzoUtxoPredFailure era))
-> AlonzoUtxoPredFailure era -> Test (AlonzoUtxoPredFailure era)
forall a b. (a -> b) -> a -> b
$ SlotNo -> AlonzoUtxoPredFailure era
forall era. SlotNo -> AlonzoUtxoPredFailure era
OutsideForecast SlotNo
ifj
    ValidityInterval
_ -> () -> Test (AlonzoUtxoPredFailure era)
forall a. a -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

-- | Ensure that there are no `TxOut`s that have value less than the sized @coinsPerUTxOWord@
--
-- > ∀ txout ∈ txouts txb, getValue txout ≥ inject (utxoEntrySize txout ∗ coinsPerUTxOWord pp)
validateOutputTooSmallUTxO ::
  (AlonzoEraTxOut era, Foldable f) =>
  PParams era ->
  f (TxOut era) ->
  Test (AlonzoUtxoPredFailure era)
validateOutputTooSmallUTxO :: forall era (f :: * -> *).
(AlonzoEraTxOut era, Foldable f) =>
PParams era -> f (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateOutputTooSmallUTxO PParams era
pp f (TxOut era)
outputs =
  Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless ([TxOut era] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TxOut era]
outputsTooSmall) (AlonzoUtxoPredFailure era
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$ [TxOut era] -> AlonzoUtxoPredFailure era
forall era. [TxOut era] -> AlonzoUtxoPredFailure era
OutputTooSmallUTxO [TxOut era]
outputsTooSmall
  where
    outputsTooSmall :: [TxOut era]
outputsTooSmall =
      (TxOut era -> Bool) -> [TxOut era] -> [TxOut era]
forall a. (a -> Bool) -> [a] -> [a]
filter
        ( \TxOut era
txOut ->
            let v :: Value era
v = TxOut era
txOut TxOut era
-> Getting (Value era) (TxOut era) (Value era) -> Value era
forall s a. s -> Getting a s a -> a
^. Getting (Value era) (TxOut era) (Value era)
forall era. EraTxOut era => Lens' (TxOut era) (Value era)
Lens' (TxOut era) (Value era)
valueTxOutL
             in -- pointwise is used because non-ada amounts must be >= 0 too
                Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ (Integer -> Integer -> Bool) -> Value era -> Value era -> Bool
forall t. Val t => (Integer -> Integer -> Bool) -> t -> t -> Bool
Val.pointwise Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
(>=) Value era
v (Coin -> Value era
forall t s. Inject t s => t -> s
Val.inject (Coin -> Value era) -> Coin -> Value era
forall a b. (a -> b) -> a -> b
$ PParams era -> TxOut era -> Coin
forall era. EraTxOut era => PParams era -> TxOut era -> Coin
getMinCoinTxOut PParams era
pp TxOut era
txOut)
        )
        (f (TxOut era) -> [TxOut era]
forall a. f a -> [a]
forall (t :: * -> *) a. Foldable t => t a -> [a]
toList f (TxOut era)
outputs)

-- | Ensure that there are no `TxOut`s that have `Value` of size larger
-- than @MaxValSize@. We use serialized length of `Value` because this Value
-- size is being limited inside a serialized `Tx`.
--
-- > ∀ txout ∈ txouts txb, serSize (getValue txout) ≤ maxValSize pp
validateOutputTooBigUTxO ::
  ( EraTxOut era
  , AlonzoEraPParams era
  , Foldable f
  ) =>
  PParams era ->
  f (TxOut era) ->
  Test (AlonzoUtxoPredFailure era)
validateOutputTooBigUTxO :: forall era (f :: * -> *).
(EraTxOut era, AlonzoEraPParams era, Foldable f) =>
PParams era -> f (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateOutputTooBigUTxO PParams era
pp f (TxOut era)
outputs =
  Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless ([(Integer, Integer, TxOut era)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Integer, Integer, TxOut era)]
outputsTooBig) (AlonzoUtxoPredFailure era
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$ [(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
forall era.
[(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
OutputTooBigUTxO [(Integer, Integer, TxOut era)]
outputsTooBig
  where
    maxValSize :: Natural
maxValSize = PParams era
pp PParams era -> Getting Natural (PParams era) Natural -> Natural
forall s a. s -> Getting a s a -> a
^. Getting Natural (PParams era) Natural
forall era. AlonzoEraPParams era => Lens' (PParams era) Natural
Lens' (PParams era) Natural
ppMaxValSizeL
    protVer :: ProtVer
protVer = PParams era
pp PParams era -> Getting ProtVer (PParams era) ProtVer -> ProtVer
forall s a. s -> Getting a s a -> a
^. Getting ProtVer (PParams era) ProtVer
forall era. EraPParams era => Lens' (PParams era) ProtVer
Lens' (PParams era) ProtVer
ppProtocolVersionL
    outputsTooBig :: [(Integer, Integer, TxOut era)]
outputsTooBig = ([(Integer, Integer, TxOut era)]
 -> TxOut era -> [(Integer, Integer, TxOut era)])
-> [(Integer, Integer, TxOut era)]
-> f (TxOut era)
-> [(Integer, Integer, TxOut era)]
forall b a. (b -> a -> b) -> b -> f a -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl' [(Integer, Integer, TxOut era)]
-> TxOut era -> [(Integer, Integer, TxOut era)]
accum [] f (TxOut era)
outputs
    accum :: [(Integer, Integer, TxOut era)]
-> TxOut era -> [(Integer, Integer, TxOut era)]
accum [(Integer, Integer, TxOut era)]
ans TxOut era
txOut =
      let v :: Value era
v = TxOut era
txOut TxOut era
-> Getting (Value era) (TxOut era) (Value era) -> Value era
forall s a. s -> Getting a s a -> a
^. Getting (Value era) (TxOut era) (Value era)
forall era. EraTxOut era => Lens' (TxOut era) (Value era)
Lens' (TxOut era) (Value era)
valueTxOutL
          serSize :: Natural
serSize = Int64 -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int64 -> Natural) -> Int64 -> Natural
forall a b. (a -> b) -> a -> b
$ ByteString -> Int64
BSL.length (ByteString -> Int64) -> ByteString -> Int64
forall a b. (a -> b) -> a -> b
$ Version -> Value era -> ByteString
forall a. EncCBOR a => Version -> a -> ByteString
serialize (ProtVer -> Version
pvMajor ProtVer
protVer) Value era
v
       in if Natural
serSize Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
> Natural
maxValSize
            then (Natural -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
serSize, Natural -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
maxValSize, TxOut era
txOut) (Integer, Integer, TxOut era)
-> [(Integer, Integer, TxOut era)]
-> [(Integer, Integer, TxOut era)]
forall a. a -> [a] -> [a]
: [(Integer, Integer, TxOut era)]
ans
            else [(Integer, Integer, TxOut era)]
ans

-- | Ensure if NetworkId is present in the txbody it matches the global NetworkId
--
-- > (txnetworkid txb = NetworkId) ∨ (txnetworkid txb = ◇)
validateWrongNetworkInTxBody ::
  AlonzoEraTxBody era =>
  Network ->
  TxBody era ->
  Test (AlonzoUtxoPredFailure era)
validateWrongNetworkInTxBody :: forall era.
AlonzoEraTxBody era =>
Network -> TxBody era -> Test (AlonzoUtxoPredFailure era)
validateWrongNetworkInTxBody Network
netId TxBody era
txBody =
  case TxBody era
txBody TxBody era
-> Getting (StrictMaybe Network) (TxBody era) (StrictMaybe Network)
-> StrictMaybe Network
forall s a. s -> Getting a s a -> a
^. Getting (StrictMaybe Network) (TxBody era) (StrictMaybe Network)
forall era.
AlonzoEraTxBody era =>
Lens' (TxBody era) (StrictMaybe Network)
Lens' (TxBody era) (StrictMaybe Network)
networkIdTxBodyL of
    StrictMaybe Network
SNothing -> () -> Test (AlonzoUtxoPredFailure era)
forall a. a -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
    SJust Network
bid ->
      Bool
-> AlonzoUtxoPredFailure era -> Test (AlonzoUtxoPredFailure era)
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless (Network
netId Network -> Network -> Bool
forall a. Eq a => a -> a -> Bool
== Network
bid) (AlonzoUtxoPredFailure era -> Test (AlonzoUtxoPredFailure era))
-> AlonzoUtxoPredFailure era -> Test (AlonzoUtxoPredFailure era)
forall a b. (a -> b) -> a -> b
$
        Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era
WrongNetworkInTxBody Mismatch {mismatchSupplied :: Network
mismatchSupplied = Network
bid, mismatchExpected :: Network
mismatchExpected = Network
netId}

-- | Ensure that execution units to not exceed the maximum allowed @maxTxExUnits@ parameter.
--
-- > totExunits tx ≤ maxTxExUnits pp
validateExUnitsTooBigUTxO ::
  ( AlonzoEraTxWits era
  , EraTx era
  , AlonzoEraPParams era
  ) =>
  PParams era ->
  Tx era ->
  Test (AlonzoUtxoPredFailure era)
validateExUnitsTooBigUTxO :: forall era.
(AlonzoEraTxWits era, EraTx era, AlonzoEraPParams era) =>
PParams era -> Tx era -> Test (AlonzoUtxoPredFailure era)
validateExUnitsTooBigUTxO PParams era
pp Tx era
tx =
  Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless ((Natural -> Natural -> Bool) -> ExUnits -> ExUnits -> Bool
pointWiseExUnits Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
(<=) ExUnits
totalExUnits ExUnits
maxTxExUnits) (AlonzoUtxoPredFailure era
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$
    Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era
ExUnitsTooBigUTxO Mismatch {mismatchSupplied :: ExUnits
mismatchSupplied = ExUnits
totalExUnits, mismatchExpected :: ExUnits
mismatchExpected = ExUnits
maxTxExUnits}
  where
    maxTxExUnits :: ExUnits
maxTxExUnits = PParams era
pp PParams era -> Getting ExUnits (PParams era) ExUnits -> ExUnits
forall s a. s -> Getting a s a -> a
^. Getting ExUnits (PParams era) ExUnits
forall era. AlonzoEraPParams era => Lens' (PParams era) ExUnits
Lens' (PParams era) ExUnits
ppMaxTxExUnitsL
    -- This sums up the ExUnits for all embedded Plutus Scripts anywhere in the transaction:
    totalExUnits :: ExUnits
totalExUnits = Tx era -> ExUnits
forall era. (EraTx era, AlonzoEraTxWits era) => Tx era -> ExUnits
totExUnits Tx era
tx

-- | Ensure that number of collaterals does not exceed the allowed @maxCollInputs@ parameter.
--
-- > ‖collateral tx‖  ≤  maxCollInputs pp
validateTooManyCollateralInputs ::
  AlonzoEraTxBody era =>
  PParams era ->
  TxBody era ->
  Test (AlonzoUtxoPredFailure era)
validateTooManyCollateralInputs :: forall era.
AlonzoEraTxBody era =>
PParams era -> TxBody era -> Test (AlonzoUtxoPredFailure era)
validateTooManyCollateralInputs PParams era
pp TxBody era
txBody =
  Bool
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall e. Bool -> e -> Validation (NonEmpty e) ()
failureUnless (Natural
numColl Natural -> Natural -> Bool
forall a. Ord a => a -> a -> Bool
<= Natural
maxColl) (AlonzoUtxoPredFailure era
 -> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ())
-> AlonzoUtxoPredFailure era
-> Validation (NonEmpty (AlonzoUtxoPredFailure era)) ()
forall a b. (a -> b) -> a -> b
$
    Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era
TooManyCollateralInputs Mismatch {mismatchSupplied :: Natural
mismatchSupplied = Natural
numColl, mismatchExpected :: Natural
mismatchExpected = Natural
maxColl}
  where
    maxColl, numColl :: Natural
    maxColl :: Natural
maxColl = PParams era
pp PParams era -> Getting Natural (PParams era) Natural -> Natural
forall s a. s -> Getting a s a -> a
^. Getting Natural (PParams era) Natural
forall era. AlonzoEraPParams era => Lens' (PParams era) Natural
Lens' (PParams era) Natural
ppMaxCollateralInputsL
    numColl :: Natural
numColl = Int -> Natural
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Natural) -> (Set TxIn -> Int) -> Set TxIn -> Natural
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Set TxIn -> Int
forall a. Set a -> Int
Set.size (Set TxIn -> Natural) -> Set TxIn -> Natural
forall a b. (a -> b) -> a -> b
$ TxBody era
txBody TxBody era
-> Getting (Set TxIn) (TxBody era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. Getting (Set TxIn) (TxBody era) (Set TxIn)
forall era. AlonzoEraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody era) (Set TxIn)
collateralInputsTxBodyL

-- ================================================================

-- | The UTxO transition rule for the Alonzo eras.
utxoTransition ::
  forall era.
  ( EraUTxO era
  , AlonzoEraTx era
  , ProtVerAtMost era 8
  , EraRule "UTXO" era ~ AlonzoUTXO era
  , InjectRuleFailure "UTXO" ShelleyUtxoPredFailure era
  , InjectRuleFailure "UTXO" AlonzoUtxoPredFailure era
  , InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
  , Embed (EraRule "UTXOS" era) (AlonzoUTXO era)
  , Environment (EraRule "UTXOS" era) ~ UtxoEnv era
  , State (EraRule "UTXOS" era) ~ UTxOState era
  , Signal (EraRule "UTXOS" era) ~ Tx era
  , EraCertState era
  , SafeToHash (TxWits era)
  ) =>
  TransitionRule (EraRule "UTXO" era)
utxoTransition :: forall era.
(EraUTxO era, AlonzoEraTx era, ProtVerAtMost era 8,
 EraRule "UTXO" era ~ AlonzoUTXO era,
 InjectRuleFailure "UTXO" ShelleyUtxoPredFailure era,
 InjectRuleFailure "UTXO" AlonzoUtxoPredFailure era,
 InjectRuleFailure "UTXO" AllegraUtxoPredFailure era,
 Embed (EraRule "UTXOS" era) (AlonzoUTXO era),
 Environment (EraRule "UTXOS" era) ~ UtxoEnv era,
 State (EraRule "UTXOS" era) ~ UTxOState era,
 Signal (EraRule "UTXOS" era) ~ Tx era, EraCertState era,
 SafeToHash (TxWits era)) =>
TransitionRule (EraRule "UTXO" era)
utxoTransition = do
  TRC (UtxoEnv SlotNo
slot PParams era
pp CertState era
dpstate, State (AlonzoUTXO era)
utxos, Signal (AlonzoUTXO era)
tx) <- Rule
  (AlonzoUTXO era)
  'Transition
  (RuleContext 'Transition (AlonzoUTXO era))
F (Clause (AlonzoUTXO era) 'Transition) (TRC (AlonzoUTXO era))
forall sts (rtype :: RuleType).
Rule sts rtype (RuleContext rtype sts)
judgmentContext
  let utxo :: UTxO era
utxo = UTxOState era -> UTxO era
forall era. UTxOState era -> UTxO era
utxosUtxo State (AlonzoUTXO era)
UTxOState era
utxos

  {-   txb := txbody tx   -}
  let txBody :: TxBody era
txBody = Tx era
Signal (AlonzoUTXO era)
tx Tx era -> Getting (TxBody era) (Tx era) (TxBody era) -> TxBody era
forall s a. s -> Getting a s a -> a
^. Getting (TxBody era) (Tx era) (TxBody era)
forall era. EraTx era => Lens' (Tx era) (TxBody era)
Lens' (Tx era) (TxBody era)
bodyTxL
      inputsAndCollateral :: Set TxIn
inputsAndCollateral =
        Set TxIn -> Set TxIn -> Set TxIn
forall a. Ord a => Set a -> Set a -> Set a
Set.union
          (TxBody era
txBody TxBody era
-> Getting (Set TxIn) (TxBody era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. Getting (Set TxIn) (TxBody era) (Set TxIn)
forall era. EraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody era) (Set TxIn)
inputsTxBodyL)
          (TxBody era
txBody TxBody era
-> Getting (Set TxIn) (TxBody era) (Set TxIn) -> Set TxIn
forall s a. s -> Getting a s a -> a
^. Getting (Set TxIn) (TxBody era) (Set TxIn)
forall era. AlonzoEraTxBody era => Lens' (TxBody era) (Set TxIn)
Lens' (TxBody era) (Set TxIn)
collateralInputsTxBodyL)

  {- ininterval slot (txvld txb) -}
  Test (AllegraUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (AllegraUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (AllegraUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$
    SlotNo -> TxBody era -> Test (AllegraUtxoPredFailure era)
forall era.
AllegraEraTxBody era =>
SlotNo -> TxBody era -> Test (AllegraUtxoPredFailure era)
Allegra.validateOutsideValidityIntervalUTxO SlotNo
slot TxBody era
txBody

  SystemStart
sysSt <- BaseM (AlonzoUTXO era) SystemStart
-> Rule (AlonzoUTXO era) 'Transition SystemStart
forall sts a (ctx :: RuleType).
STS sts =>
BaseM sts a -> Rule sts ctx a
liftSTS (BaseM (AlonzoUTXO era) SystemStart
 -> Rule (AlonzoUTXO era) 'Transition SystemStart)
-> BaseM (AlonzoUTXO era) SystemStart
-> Rule (AlonzoUTXO era) 'Transition SystemStart
forall a b. (a -> b) -> a -> b
$ (Globals -> SystemStart) -> ReaderT Globals Identity SystemStart
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
asks Globals -> SystemStart
systemStart
  EpochInfo (Either Text)
ei <- BaseM (AlonzoUTXO era) (EpochInfo (Either Text))
-> Rule (AlonzoUTXO era) 'Transition (EpochInfo (Either Text))
forall sts a (ctx :: RuleType).
STS sts =>
BaseM sts a -> Rule sts ctx a
liftSTS (BaseM (AlonzoUTXO era) (EpochInfo (Either Text))
 -> Rule (AlonzoUTXO era) 'Transition (EpochInfo (Either Text)))
-> BaseM (AlonzoUTXO era) (EpochInfo (Either Text))
-> Rule (AlonzoUTXO era) 'Transition (EpochInfo (Either Text))
forall a b. (a -> b) -> a -> b
$ (Globals -> EpochInfo (Either Text))
-> ReaderT Globals Identity (EpochInfo (Either Text))
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
asks Globals -> EpochInfo (Either Text)
epochInfo

  {- epochInfoSlotToUTCTime epochInfo systemTime i_f ≠ ◇ -}
  Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (AlonzoUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ EpochInfo (Either Text)
-> SlotNo
-> SystemStart
-> Tx era
-> Test (AlonzoUtxoPredFailure era)
forall era a.
(MaryEraTxBody era, AlonzoEraTxWits era, EraTx era) =>
EpochInfo (Either a)
-> SlotNo
-> SystemStart
-> Tx era
-> Test (AlonzoUtxoPredFailure era)
validateOutsideForecast EpochInfo (Either Text)
ei SlotNo
slot SystemStart
sysSt Tx era
Signal (AlonzoUTXO era)
tx

  {-   txins txb ≠ ∅   -}
  Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal (Test (ShelleyUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ TxBody era -> Test (ShelleyUtxoPredFailure era)
forall era.
EraTxBody era =>
TxBody era -> Test (ShelleyUtxoPredFailure era)
Shelley.validateInputSetEmptyUTxO TxBody era
txBody

  {-   feesOK pp tx utxo   -}
  Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (AlonzoUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ PParams era
-> Tx era -> UTxO era -> Test (AlonzoUtxoPredFailure era)
forall era.
(AlonzoEraTx era, EraUTxO era) =>
PParams era
-> Tx era -> UTxO era -> Test (AlonzoUtxoPredFailure era)
feesOK PParams era
pp Tx era
Signal (AlonzoUTXO era)
tx UTxO era
utxo -- Generalizes the fee to small from earlier Era's

  {- inputsAndCollateral = txins txb ∪ collateral txb -}
  {- (txins txb) ∪ (collateral txb) ⊆ dom utxo   -}
  Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (ShelleyUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ UTxO era -> Set TxIn -> Test (ShelleyUtxoPredFailure era)
forall era.
UTxO era -> Set TxIn -> Test (ShelleyUtxoPredFailure era)
Shelley.validateBadInputsUTxO UTxO era
utxo Set TxIn
inputsAndCollateral

  {- consumed pp utxo txb = produced pp poolParams txb -}
  Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (ShelleyUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ PParams era
-> UTxO era
-> CertState era
-> TxBody era
-> Test (ShelleyUtxoPredFailure era)
forall era.
(EraUTxO era, EraCertState era) =>
PParams era
-> UTxO era
-> CertState era
-> TxBody era
-> Test (ShelleyUtxoPredFailure era)
Shelley.validateValueNotConservedUTxO PParams era
pp UTxO era
utxo CertState era
dpstate TxBody era
txBody

  {- adaPolicy ∉ supp mint tx
     above check not needed because mint field of type MultiAsset cannot contain ada -}

  let outputs :: StrictSeq (TxOut era)
outputs = TxBody era
txBody TxBody era
-> Getting
     (StrictSeq (TxOut era)) (TxBody era) (StrictSeq (TxOut era))
-> StrictSeq (TxOut era)
forall s a. s -> Getting a s a -> a
^. Getting
  (StrictSeq (TxOut era)) (TxBody era) (StrictSeq (TxOut era))
forall era.
EraTxBody era =>
Lens' (TxBody era) (StrictSeq (TxOut era))
Lens' (TxBody era) (StrictSeq (TxOut era))
outputsTxBodyL
  {-   ∀ txout ∈ txouts txb, getValuetxout ≥ inject (uxoEntrySizetxout ∗ coinsPerUTxOWord p) -}
  Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (AlonzoUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ PParams era
-> StrictSeq (TxOut era) -> Test (AlonzoUtxoPredFailure era)
forall era (f :: * -> *).
(AlonzoEraTxOut era, Foldable f) =>
PParams era -> f (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateOutputTooSmallUTxO PParams era
pp StrictSeq (TxOut era)
outputs

  {-   ∀ txout ∈ txouts txb, serSize (getValue txout) ≤ maxValSize pp   -}
  Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (AlonzoUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ PParams era
-> StrictSeq (TxOut era) -> Test (AlonzoUtxoPredFailure era)
forall era (f :: * -> *).
(EraTxOut era, AlonzoEraPParams era, Foldable f) =>
PParams era -> f (TxOut era) -> Test (AlonzoUtxoPredFailure era)
validateOutputTooBigUTxO PParams era
pp StrictSeq (TxOut era)
outputs

  {- ∀ ( _ ↦ (a,_)) ∈ txoutstxb,  a ∈ Addrbootstrap → bootstrapAttrsSize a ≤ 64 -}
  Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal (Test (ShelleyUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ StrictSeq (TxOut era) -> Test (ShelleyUtxoPredFailure era)
forall era (f :: * -> *).
(EraTxOut era, Foldable f) =>
f (TxOut era) -> Test (ShelleyUtxoPredFailure era)
Shelley.validateOutputBootAddrAttrsTooBig StrictSeq (TxOut era)
outputs

  Network
netId <- BaseM (AlonzoUTXO era) Network
-> Rule (AlonzoUTXO era) 'Transition Network
forall sts a (ctx :: RuleType).
STS sts =>
BaseM sts a -> Rule sts ctx a
liftSTS (BaseM (AlonzoUTXO era) Network
 -> Rule (AlonzoUTXO era) 'Transition Network)
-> BaseM (AlonzoUTXO era) Network
-> Rule (AlonzoUTXO era) 'Transition Network
forall a b. (a -> b) -> a -> b
$ (Globals -> Network) -> ReaderT Globals Identity Network
forall (m :: * -> *) r a. Monad m => (r -> a) -> ReaderT r m a
asks Globals -> Network
networkId

  {- ∀(_ → (a, _)) ∈ txouts txb, netId a = NetworkId -}
  Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal (Test (ShelleyUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ Network
-> StrictSeq (TxOut era) -> Test (ShelleyUtxoPredFailure era)
forall era (f :: * -> *).
(EraTxOut era, Foldable f) =>
Network -> f (TxOut era) -> Test (ShelleyUtxoPredFailure era)
Shelley.validateWrongNetwork Network
netId StrictSeq (TxOut era)
outputs

  {- ∀(a → ) ∈ txwdrls txb, netId a = NetworkId -}
  Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal (Test (ShelleyUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ Network -> TxBody era -> Test (ShelleyUtxoPredFailure era)
forall era.
EraTxBody era =>
Network -> TxBody era -> Test (ShelleyUtxoPredFailure era)
Shelley.validateWrongNetworkWithdrawal Network
netId TxBody era
txBody

  {- (txnetworkid txb = NetworkId) ∨ (txnetworkid txb = ◇) -}
  Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal (Test (AlonzoUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ Network -> TxBody era -> Test (AlonzoUtxoPredFailure era)
forall era.
AlonzoEraTxBody era =>
Network -> TxBody era -> Test (AlonzoUtxoPredFailure era)
validateWrongNetworkInTxBody Network
netId TxBody era
txBody

  {- txsize tx ≤ maxTxSize pp -}
  Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTestOnSignal (Test (ShelleyUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (ShelleyUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ PParams era -> Tx era -> Test (ShelleyUtxoPredFailure era)
forall era.
EraTx era =>
PParams era -> Tx era -> Test (ShelleyUtxoPredFailure era)
Shelley.validateMaxTxSizeUTxO PParams era
pp Tx era
Signal (AlonzoUTXO era)
tx

  {-   totExunits tx ≤ maxTxExUnits pp    -}
  Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall (rule :: Symbol) (f :: * -> *) era (ctx :: RuleType).
InjectRuleFailure rule f era =>
Test (f era) -> Rule (EraRule rule era) ctx ()
runTest (Test (AlonzoUtxoPredFailure era)
 -> Rule (EraRule "UTXO" era) 'Transition ())
-> Test (AlonzoUtxoPredFailure era)
-> Rule (EraRule "UTXO" era) 'Transition ()
forall a b. (a -> b) -> a -> b
$ PParams era -> Tx era -> Test (AlonzoUtxoPredFailure era)
forall era.
(AlonzoEraTxWits era, EraTx era, AlonzoEraPParams era) =>
PParams era -> Tx era -> Test (AlonzoUtxoPredFailure era)
validateExUnitsTooBigUTxO PParams era
pp Tx era
Signal (AlonzoUTXO era)
tx

  {-   ‖collateral tx‖  ≤  maxCollInputs pp   -}

  forall sub super (rtype :: RuleType).
Embed sub super =>
RuleContext rtype sub -> Rule super rtype (State sub)
trans @(EraRule "UTXOS" era) (TRC (EraRule "UTXOS" era)
 -> F (Clause (AlonzoUTXO era) 'Transition) (UTxOState era))
-> F (Clause (AlonzoUTXO era) 'Transition)
     (TRC (EraRule "UTXOS" era))
-> F (Clause (AlonzoUTXO era) 'Transition) (UTxOState era)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< TRC (AlonzoUTXO era) -> TRC (EraRule "UTXOS" era)
forall a b. Coercible a b => a -> b
coerce (TRC (AlonzoUTXO era) -> TRC (EraRule "UTXOS" era))
-> F (Clause (AlonzoUTXO era) 'Transition) (TRC (AlonzoUTXO era))
-> F (Clause (AlonzoUTXO era) 'Transition)
     (TRC (EraRule "UTXOS" era))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Rule
  (AlonzoUTXO era)
  'Transition
  (RuleContext 'Transition (AlonzoUTXO era))
F (Clause (AlonzoUTXO era) 'Transition) (TRC (AlonzoUTXO era))
forall sts (rtype :: RuleType).
Rule sts rtype (RuleContext rtype sts)
judgmentContext

--------------------------------------------------------------------------------
-- AlonzoUTXO STS
--------------------------------------------------------------------------------

instance
  forall era.
  ( EraUTxO era
  , AlonzoEraTx era
  , Embed (EraRule "UTXOS" era) (AlonzoUTXO era)
  , Environment (EraRule "UTXOS" era) ~ UtxoEnv era
  , State (EraRule "UTXOS" era) ~ UTxOState era
  , Signal (EraRule "UTXOS" era) ~ Tx era
  , EraRule "UTXO" era ~ AlonzoUTXO era
  , InjectRuleFailure "UTXO" ShelleyUtxoPredFailure era
  , InjectRuleFailure "UTXO" AlonzoUtxoPredFailure era
  , InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
  , ProtVerAtMost era 8
  , EraCertState era
  , SafeToHash (TxWits era)
  ) =>
  STS (AlonzoUTXO era)
  where
  type State (AlonzoUTXO era) = UTxOState era
  type Signal (AlonzoUTXO era) = Tx era
  type Environment (AlonzoUTXO era) = UtxoEnv era
  type BaseM (AlonzoUTXO era) = ShelleyBase
  type PredicateFailure (AlonzoUTXO era) = AlonzoUtxoPredFailure era
  type Event (AlonzoUTXO era) = AlonzoUtxoEvent era

  initialRules :: [InitialRule (AlonzoUTXO era)]
initialRules = []
  transitionRules :: [TransitionRule (AlonzoUTXO era)]
transitionRules = [TransitionRule (EraRule "UTXO" era)
TransitionRule (AlonzoUTXO era)
forall era.
(EraUTxO era, AlonzoEraTx era, ProtVerAtMost era 8,
 EraRule "UTXO" era ~ AlonzoUTXO era,
 InjectRuleFailure "UTXO" ShelleyUtxoPredFailure era,
 InjectRuleFailure "UTXO" AlonzoUtxoPredFailure era,
 InjectRuleFailure "UTXO" AllegraUtxoPredFailure era,
 Embed (EraRule "UTXOS" era) (AlonzoUTXO era),
 Environment (EraRule "UTXOS" era) ~ UtxoEnv era,
 State (EraRule "UTXOS" era) ~ UTxOState era,
 Signal (EraRule "UTXOS" era) ~ Tx era, EraCertState era,
 SafeToHash (TxWits era)) =>
TransitionRule (EraRule "UTXO" era)
utxoTransition]
  assertions :: [Assertion (AlonzoUTXO era)]
assertions = [Assertion (AlonzoUTXO era)
forall era (rule :: * -> *).
(EraTx era, SafeToHash (TxWits era), Signal (rule era) ~ Tx era) =>
Assertion (rule era)
Shelley.validSizeComputationCheck]

instance
  ( Era era
  , STS (AlonzoUTXOS era)
  , PredicateFailure (EraRule "UTXOS" era) ~ AlonzoUtxosPredFailure era
  , Event (EraRule "UTXOS" era) ~ Event (AlonzoUTXOS era)
  ) =>
  Embed (AlonzoUTXOS era) (AlonzoUTXO era)
  where
  wrapFailed :: PredicateFailure (AlonzoUTXOS era)
-> PredicateFailure (AlonzoUTXO era)
wrapFailed = PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
PredicateFailure (AlonzoUTXOS era)
-> PredicateFailure (AlonzoUTXO era)
forall era.
PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
UtxosFailure
  wrapEvent :: Event (AlonzoUTXOS era) -> Event (AlonzoUTXO era)
wrapEvent = Event (EraRule "UTXOS" era) -> AlonzoUtxoEvent era
Event (AlonzoUTXOS era) -> Event (AlonzoUTXO era)
forall era. Event (EraRule "UTXOS" era) -> AlonzoUtxoEvent era
UtxosEvent

--------------------------------------------------------------------------------
-- Serialisation
--------------------------------------------------------------------------------

instance
  ( Era era
  , EncCBOR (TxOut era)
  , EncCBOR (Value era)
  , EncCBOR (PredicateFailure (EraRule "UTXOS" era))
  ) =>
  EncCBOR (AlonzoUtxoPredFailure era)
  where
  encCBOR :: AlonzoUtxoPredFailure era -> Encoding
encCBOR AlonzoUtxoPredFailure era
x = Encode 'Open (AlonzoUtxoPredFailure era) -> Encoding
forall (w :: Wrapped) t. Encode w t -> Encoding
encode (AlonzoUtxoPredFailure era
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall era.
(Era era, EncCBOR (TxOut era), EncCBOR (Value era),
 EncCBOR (PredicateFailure (EraRule "UTXOS" era))) =>
AlonzoUtxoPredFailure era
-> Encode 'Open (AlonzoUtxoPredFailure era)
encFail AlonzoUtxoPredFailure era
x)

encFail ::
  forall era.
  ( Era era
  , EncCBOR (TxOut era)
  , EncCBOR (Value era)
  , EncCBOR (PredicateFailure (EraRule "UTXOS" era))
  ) =>
  AlonzoUtxoPredFailure era ->
  Encode 'Open (AlonzoUtxoPredFailure era)
encFail :: forall era.
(Era era, EncCBOR (TxOut era), EncCBOR (Value era),
 EncCBOR (PredicateFailure (EraRule "UTXOS" era))) =>
AlonzoUtxoPredFailure era
-> Encode 'Open (AlonzoUtxoPredFailure era)
encFail (BadInputsUTxO Set TxIn
ins) =
  (Set TxIn -> AlonzoUtxoPredFailure era)
-> Word -> Encode 'Open (Set TxIn -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era. Set TxIn -> AlonzoUtxoPredFailure era
BadInputsUTxO @era) Word
0 Encode 'Open (Set TxIn -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Set TxIn)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Set TxIn -> Encode ('Closed 'Dense) (Set TxIn)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Set TxIn
ins
encFail (OutsideValidityIntervalUTxO ValidityInterval
a SlotNo
b) =
  (ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era
forall era. ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era
OutsideValidityIntervalUTxO Word
1 Encode
  'Open (ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) ValidityInterval
-> Encode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> ValidityInterval -> Encode ('Closed 'Dense) ValidityInterval
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To ValidityInterval
a Encode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) SlotNo
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> SlotNo -> Encode ('Closed 'Dense) SlotNo
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To SlotNo
b
encFail (MaxTxSizeUTxO Mismatch 'RelLTEQ Integer
m) =
  (Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era
MaxTxSizeUTxO Word
2 Encode
  'Open (Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Mismatch 'RelLTEQ Integer)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Mismatch 'RelLTEQ Integer
-> Encode ('Closed 'Dense) (Mismatch 'RelLTEQ Integer)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Mismatch 'RelLTEQ Integer
m
encFail AlonzoUtxoPredFailure era
InputSetEmptyUTxO =
  AlonzoUtxoPredFailure era
-> Word -> Encode 'Open (AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
InputSetEmptyUTxO Word
3
encFail (FeeTooSmallUTxO Mismatch 'RelGTEQ Coin
m) =
  (Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
FeeTooSmallUTxO Word
4 Encode 'Open (Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Mismatch 'RelGTEQ Coin)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Mismatch 'RelGTEQ Coin
-> Encode ('Closed 'Dense) (Mismatch 'RelGTEQ Coin)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Mismatch 'RelGTEQ Coin
m
encFail (ValueNotConservedUTxO Mismatch 'RelEQ (Value era)
m) =
  (Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era.
Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era
ValueNotConservedUTxO @era) Word
5 Encode
  'Open (Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Mismatch 'RelEQ (Value era))
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Mismatch 'RelEQ (Value era)
-> Encode ('Closed 'Dense) (Mismatch 'RelEQ (Value era))
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Mismatch 'RelEQ (Value era)
m
encFail (OutputTooSmallUTxO [TxOut era]
outs) =
  ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Word -> Encode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era. [TxOut era] -> AlonzoUtxoPredFailure era
OutputTooSmallUTxO @era) Word
6 Encode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) [TxOut era]
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> [TxOut era] -> Encode ('Closed 'Dense) [TxOut era]
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To [TxOut era]
outs
encFail (UtxosFailure PredicateFailure (EraRule "UTXOS" era)
a) =
  (PredicateFailure (EraRule "UTXOS" era)
 -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open
     (PredicateFailure (EraRule "UTXOS" era)
      -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era.
PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
UtxosFailure @era) Word
7 Encode
  'Open
  (PredicateFailure (EraRule "UTXOS" era)
   -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (PredicateFailure (EraRule "UTXOS" era))
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> PredicateFailure (EraRule "UTXOS" era)
-> Encode ('Closed 'Dense) (PredicateFailure (EraRule "UTXOS" era))
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To PredicateFailure (EraRule "UTXOS" era)
a
encFail (WrongNetwork Network
right Set Addr
wrongs) =
  (Network -> Set Addr -> AlonzoUtxoPredFailure era)
-> Word
-> Encode 'Open (Network -> Set Addr -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era. Network -> Set Addr -> AlonzoUtxoPredFailure era
WrongNetwork @era) Word
8 Encode 'Open (Network -> Set Addr -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) Network
-> Encode 'Open (Set Addr -> AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Network -> Encode ('Closed 'Dense) Network
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Network
right Encode 'Open (Set Addr -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Set Addr)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Set Addr -> Encode ('Closed 'Dense) (Set Addr)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Set Addr
wrongs
encFail (WrongNetworkWithdrawal Network
right Set RewardAccount
wrongs) =
  (Network -> Set RewardAccount -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (Network -> Set RewardAccount -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era.
Network -> Set RewardAccount -> AlonzoUtxoPredFailure era
WrongNetworkWithdrawal @era) Word
9 Encode
  'Open (Network -> Set RewardAccount -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) Network
-> Encode 'Open (Set RewardAccount -> AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Network -> Encode ('Closed 'Dense) Network
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Network
right Encode 'Open (Set RewardAccount -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Set RewardAccount)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Set RewardAccount -> Encode ('Closed 'Dense) (Set RewardAccount)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Set RewardAccount
wrongs
encFail (OutputBootAddrAttrsTooBig [TxOut era]
outs) =
  ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Word -> Encode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era. [TxOut era] -> AlonzoUtxoPredFailure era
OutputBootAddrAttrsTooBig @era) Word
10 Encode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) [TxOut era]
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> [TxOut era] -> Encode ('Closed 'Dense) [TxOut era]
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To [TxOut era]
outs
encFail AlonzoUtxoPredFailure era
TriesToForgeADA =
  AlonzoUtxoPredFailure era
-> Word -> Encode 'Open (AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
TriesToForgeADA Word
11
encFail (OutputTooBigUTxO [(Integer, Integer, TxOut era)]
outs) =
  ([(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open
     ([(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum (forall era.
[(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
OutputTooBigUTxO @era) Word
12 Encode
  'Open
  ([(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) [(Integer, Integer, TxOut era)]
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> [(Integer, Integer, TxOut era)]
-> Encode ('Closed 'Dense) [(Integer, Integer, TxOut era)]
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To [(Integer, Integer, TxOut era)]
outs
encFail (InsufficientCollateral DeltaCoin
a Coin
b) =
  (DeltaCoin -> Coin -> AlonzoUtxoPredFailure era)
-> Word
-> Encode 'Open (DeltaCoin -> Coin -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum DeltaCoin -> Coin -> AlonzoUtxoPredFailure era
forall era. DeltaCoin -> Coin -> AlonzoUtxoPredFailure era
InsufficientCollateral Word
13 Encode 'Open (DeltaCoin -> Coin -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) DeltaCoin
-> Encode 'Open (Coin -> AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> DeltaCoin -> Encode ('Closed 'Dense) DeltaCoin
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To DeltaCoin
a Encode 'Open (Coin -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) Coin
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Coin -> Encode ('Closed 'Dense) Coin
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Coin
b
encFail (ScriptsNotPaidUTxO UTxO era
a) =
  (UTxO era -> AlonzoUtxoPredFailure era)
-> Word -> Encode 'Open (UTxO era -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum UTxO era -> AlonzoUtxoPredFailure era
forall era. UTxO era -> AlonzoUtxoPredFailure era
ScriptsNotPaidUTxO Word
14 Encode 'Open (UTxO era -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (UTxO era)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> UTxO era -> Encode ('Closed 'Dense) (UTxO era)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To UTxO era
a
encFail (ExUnitsTooBigUTxO Mismatch 'RelLTEQ ExUnits
m) =
  (Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era
ExUnitsTooBigUTxO Word
15 Encode
  'Open (Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Mismatch 'RelLTEQ ExUnits)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Mismatch 'RelLTEQ ExUnits
-> Encode ('Closed 'Dense) (Mismatch 'RelLTEQ ExUnits)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Mismatch 'RelLTEQ ExUnits
m
encFail (CollateralContainsNonADA Value era
a) =
  (Value era -> AlonzoUtxoPredFailure era)
-> Word -> Encode 'Open (Value era -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum Value era -> AlonzoUtxoPredFailure era
forall era. Value era -> AlonzoUtxoPredFailure era
CollateralContainsNonADA Word
16 Encode 'Open (Value era -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Value era)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Value era -> Encode ('Closed 'Dense) (Value era)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Value era
a
encFail (WrongNetworkInTxBody Mismatch 'RelEQ Network
m) =
  (Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era
WrongNetworkInTxBody Word
17 Encode 'Open (Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Mismatch 'RelEQ Network)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Mismatch 'RelEQ Network
-> Encode ('Closed 'Dense) (Mismatch 'RelEQ Network)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Mismatch 'RelEQ Network
m
encFail (OutsideForecast SlotNo
a) =
  (SlotNo -> AlonzoUtxoPredFailure era)
-> Word -> Encode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum SlotNo -> AlonzoUtxoPredFailure era
forall era. SlotNo -> AlonzoUtxoPredFailure era
OutsideForecast Word
18 Encode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) SlotNo
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> SlotNo -> Encode ('Closed 'Dense) SlotNo
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To SlotNo
a
encFail (TooManyCollateralInputs Mismatch 'RelLTEQ Natural
m) =
  (Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era)
-> Word
-> Encode
     'Open (Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era
TooManyCollateralInputs Word
19 Encode
  'Open (Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era)
-> Encode ('Closed 'Dense) (Mismatch 'RelLTEQ Natural)
-> Encode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) a t (r :: Density).
Encode w (a -> t) -> Encode ('Closed r) a -> Encode w t
!> Mismatch 'RelLTEQ Natural
-> Encode ('Closed 'Dense) (Mismatch 'RelLTEQ Natural)
forall t. EncCBOR t => t -> Encode ('Closed 'Dense) t
To Mismatch 'RelLTEQ Natural
m
encFail AlonzoUtxoPredFailure era
NoCollateralInputs =
  AlonzoUtxoPredFailure era
-> Word -> Encode 'Open (AlonzoUtxoPredFailure era)
forall t. t -> Word -> Encode 'Open t
Sum AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
NoCollateralInputs Word
20

decFail ::
  ( Era era
  , DecCBOR (TxOut era)
  , DecCBOR (Value era)
  , DecCBOR (PredicateFailure (EraRule "UTXOS" era))
  ) =>
  Word ->
  Decode 'Open (AlonzoUtxoPredFailure era)
decFail :: forall era.
(Era era, DecCBOR (TxOut era), DecCBOR (Value era),
 DecCBOR (PredicateFailure (EraRule "UTXOS" era))) =>
Word -> Decode 'Open (AlonzoUtxoPredFailure era)
decFail Word
0 = (Set TxIn -> AlonzoUtxoPredFailure era)
-> Decode 'Open (Set TxIn -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Set TxIn -> AlonzoUtxoPredFailure era
forall era. Set TxIn -> AlonzoUtxoPredFailure era
BadInputsUTxO Decode 'Open (Set TxIn -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Set TxIn)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Set TxIn)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
1 = (ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era
forall era. ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era
OutsideValidityIntervalUTxO Decode
  'Open (ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) ValidityInterval
-> Decode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) ValidityInterval
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) SlotNo
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) SlotNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
2 = (Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era
MaxTxSizeUTxO Decode
  'Open (Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Mismatch 'RelLTEQ Integer)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Mismatch 'RelLTEQ Integer)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
3 = AlonzoUtxoPredFailure era
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
InputSetEmptyUTxO
decFail Word
4 = (Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
FeeTooSmallUTxO Decode 'Open (Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Mismatch 'RelGTEQ Coin)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Mismatch 'RelGTEQ Coin)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
5 = (Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era
forall era.
Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era
ValueNotConservedUTxO Decode
  'Open (Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Mismatch 'RelEQ (Value era))
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Mismatch 'RelEQ (Value era))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
6 = ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Decode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD [TxOut era] -> AlonzoUtxoPredFailure era
forall era. [TxOut era] -> AlonzoUtxoPredFailure era
OutputTooSmallUTxO Decode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) [TxOut era]
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) [TxOut era]
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
7 = (PredicateFailure (EraRule "UTXOS" era)
 -> AlonzoUtxoPredFailure era)
-> Decode
     'Open
     (PredicateFailure (EraRule "UTXOS" era)
      -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
forall era.
PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
UtxosFailure Decode
  'Open
  (PredicateFailure (EraRule "UTXOS" era)
   -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (PredicateFailure (EraRule "UTXOS" era))
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (PredicateFailure (EraRule "UTXOS" era))
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
8 = (Network -> Set Addr -> AlonzoUtxoPredFailure era)
-> Decode 'Open (Network -> Set Addr -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Network -> Set Addr -> AlonzoUtxoPredFailure era
forall era. Network -> Set Addr -> AlonzoUtxoPredFailure era
WrongNetwork Decode 'Open (Network -> Set Addr -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) Network
-> Decode 'Open (Set Addr -> AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) Network
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode 'Open (Set Addr -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Set Addr)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Set Addr)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
9 = (Network -> Set RewardAccount -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (Network -> Set RewardAccount -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Network -> Set RewardAccount -> AlonzoUtxoPredFailure era
forall era.
Network -> Set RewardAccount -> AlonzoUtxoPredFailure era
WrongNetworkWithdrawal Decode
  'Open (Network -> Set RewardAccount -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) Network
-> Decode 'Open (Set RewardAccount -> AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) Network
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode 'Open (Set RewardAccount -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Set RewardAccount)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Set RewardAccount)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
10 = ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Decode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD [TxOut era] -> AlonzoUtxoPredFailure era
forall era. [TxOut era] -> AlonzoUtxoPredFailure era
OutputBootAddrAttrsTooBig Decode 'Open ([TxOut era] -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) [TxOut era]
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) [TxOut era]
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
11 = AlonzoUtxoPredFailure era
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
TriesToForgeADA
decFail Word
12 =
  let fromRestricted :: (Int, Int, TxOut era) -> (Integer, Integer, TxOut era)
      fromRestricted :: forall era. (Int, Int, TxOut era) -> (Integer, Integer, TxOut era)
fromRestricted (Int
sz, Int
mv, TxOut era
txOut) = (Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
sz, Int -> Integer
forall a. Integral a => a -> Integer
toInteger Int
mv, TxOut era
txOut)
   in ([(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era)
-> Decode
     'Open
     ([(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD [(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
forall era.
[(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
OutputTooBigUTxO Decode
  'Open
  ([(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era)
-> Decode ('Closed 'Dense) [(Integer, Integer, TxOut era)]
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! (forall s. Decoder s [(Integer, Integer, TxOut era)])
-> Decode ('Closed 'Dense) [(Integer, Integer, TxOut era)]
forall t. (forall s. Decoder s t) -> Decode ('Closed 'Dense) t
D (((Int, Int, TxOut era) -> (Integer, Integer, TxOut era))
-> [(Int, Int, TxOut era)] -> [(Integer, Integer, TxOut era)]
forall a b. (a -> b) -> [a] -> [b]
map (Int, Int, TxOut era) -> (Integer, Integer, TxOut era)
forall era. (Int, Int, TxOut era) -> (Integer, Integer, TxOut era)
fromRestricted ([(Int, Int, TxOut era)] -> [(Integer, Integer, TxOut era)])
-> Decoder s [(Int, Int, TxOut era)]
-> Decoder s [(Integer, Integer, TxOut era)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s [(Int, Int, TxOut era)]
forall s. Decoder s [(Int, Int, TxOut era)]
forall a s. DecCBOR a => Decoder s a
decCBOR)
decFail Word
13 = (DeltaCoin -> Coin -> AlonzoUtxoPredFailure era)
-> Decode 'Open (DeltaCoin -> Coin -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD DeltaCoin -> Coin -> AlonzoUtxoPredFailure era
forall era. DeltaCoin -> Coin -> AlonzoUtxoPredFailure era
InsufficientCollateral Decode 'Open (DeltaCoin -> Coin -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) DeltaCoin
-> Decode 'Open (Coin -> AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) DeltaCoin
forall t (w :: Wrapped). DecCBOR t => Decode w t
From Decode 'Open (Coin -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) Coin
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) Coin
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
14 = (UTxO era -> AlonzoUtxoPredFailure era)
-> Decode 'Open (UTxO era -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD UTxO era -> AlonzoUtxoPredFailure era
forall era. UTxO era -> AlonzoUtxoPredFailure era
ScriptsNotPaidUTxO Decode 'Open (UTxO era -> AlonzoUtxoPredFailure era)
-> Decode ('Closed 'Dense) (UTxO era)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! (forall s. Decoder s (UTxO era))
-> Decode ('Closed 'Dense) (UTxO era)
forall t. (forall s. Decoder s t) -> Decode ('Closed 'Dense) t
D (Map TxIn (TxOut era) -> UTxO era
forall era. Map TxIn (TxOut era) -> UTxO era
UTxO (Map TxIn (TxOut era) -> UTxO era)
-> Decoder s (Map TxIn (TxOut era)) -> Decoder s (UTxO era)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s (Map TxIn (TxOut era))
forall s. Decoder s (Map TxIn (TxOut era))
forall a s. DecCBOR a => Decoder s a
decCBOR)
decFail Word
15 = (Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era
ExUnitsTooBigUTxO Decode
  'Open (Mismatch 'RelLTEQ ExUnits -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Mismatch 'RelLTEQ ExUnits)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Mismatch 'RelLTEQ ExUnits)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
16 = (Value era -> AlonzoUtxoPredFailure era)
-> Decode 'Open (Value era -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Value era -> AlonzoUtxoPredFailure era
forall era. Value era -> AlonzoUtxoPredFailure era
CollateralContainsNonADA Decode 'Open (Value era -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Value era)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Value era)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
17 = (Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era
WrongNetworkInTxBody Decode 'Open (Mismatch 'RelEQ Network -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Mismatch 'RelEQ Network)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Mismatch 'RelEQ Network)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
18 = (SlotNo -> AlonzoUtxoPredFailure era)
-> Decode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD SlotNo -> AlonzoUtxoPredFailure era
forall era. SlotNo -> AlonzoUtxoPredFailure era
OutsideForecast Decode 'Open (SlotNo -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) SlotNo
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) SlotNo
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
19 = (Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era)
-> Decode
     'Open (Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era
TooManyCollateralInputs Decode
  'Open (Mismatch 'RelLTEQ Natural -> AlonzoUtxoPredFailure era)
-> Decode ('Closed Any) (Mismatch 'RelLTEQ Natural)
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall a (w1 :: Wrapped) t (w :: Density).
Typeable a =>
Decode w1 (a -> t) -> Decode ('Closed w) a -> Decode w1 t
<! Decode ('Closed Any) (Mismatch 'RelLTEQ Natural)
forall t (w :: Wrapped). DecCBOR t => Decode w t
From
decFail Word
20 = AlonzoUtxoPredFailure era
-> Decode 'Open (AlonzoUtxoPredFailure era)
forall t. t -> Decode 'Open t
SumD AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
NoCollateralInputs
decFail Word
n = Word -> Decode 'Open (AlonzoUtxoPredFailure era)
forall (w :: Wrapped) t. Word -> Decode w t
Invalid Word
n

instance
  ( Era era
  , DecCBOR (TxOut era)
  , DecCBOR (Value era)
  , EncCBOR (Value era)
  , DecCBOR (PredicateFailure (EraRule "UTXOS" era))
  ) =>
  DecCBOR (AlonzoUtxoPredFailure era)
  where
  decCBOR :: forall s. Decoder s (AlonzoUtxoPredFailure era)
decCBOR = Decode ('Closed 'Dense) (AlonzoUtxoPredFailure era)
-> Decoder s (AlonzoUtxoPredFailure era)
forall t (w :: Wrapped) s. Typeable t => Decode w t -> Decoder s t
decode (Text
-> (Word -> Decode 'Open (AlonzoUtxoPredFailure era))
-> Decode ('Closed 'Dense) (AlonzoUtxoPredFailure era)
forall t.
Text -> (Word -> Decode 'Open t) -> Decode ('Closed 'Dense) t
Summands Text
"UtxoPredicateFailure" Word -> Decode 'Open (AlonzoUtxoPredFailure era)
forall era.
(Era era, DecCBOR (TxOut era), DecCBOR (Value era),
 DecCBOR (PredicateFailure (EraRule "UTXOS" era))) =>
Word -> Decode 'Open (AlonzoUtxoPredFailure era)
decFail)

-- =====================================================
-- Injecting from one PredicateFailure to another

allegraToAlonzoUtxoPredFailure ::
  forall t era.
  ( EraRuleFailure "PPUP" era ~ t era
  , InjectRuleFailure "UTXOS" t era
  ) =>
  AllegraUtxoPredFailure era ->
  AlonzoUtxoPredFailure era
allegraToAlonzoUtxoPredFailure :: forall (t :: * -> *) era.
(EraRuleFailure "PPUP" era ~ t era,
 InjectRuleFailure "UTXOS" t era) =>
AllegraUtxoPredFailure era -> AlonzoUtxoPredFailure era
allegraToAlonzoUtxoPredFailure = \case
  Allegra.BadInputsUTxO Set TxIn
x -> Set TxIn -> AlonzoUtxoPredFailure era
forall era. Set TxIn -> AlonzoUtxoPredFailure era
BadInputsUTxO Set TxIn
x
  Allegra.OutsideValidityIntervalUTxO ValidityInterval
vi SlotNo
slotNo -> ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era
forall era. ValidityInterval -> SlotNo -> AlonzoUtxoPredFailure era
OutsideValidityIntervalUTxO ValidityInterval
vi SlotNo
slotNo
  Allegra.MaxTxSizeUTxO Mismatch 'RelLTEQ Integer
m -> Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelLTEQ Integer -> AlonzoUtxoPredFailure era
MaxTxSizeUTxO Mismatch 'RelLTEQ Integer
m
  AllegraUtxoPredFailure era
Allegra.InputSetEmptyUTxO -> AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
InputSetEmptyUTxO
  Allegra.FeeTooSmallUTxO Mismatch 'RelGTEQ Coin
m -> Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
forall era. Mismatch 'RelGTEQ Coin -> AlonzoUtxoPredFailure era
FeeTooSmallUTxO Mismatch 'RelGTEQ Coin
m
  Allegra.ValueNotConservedUTxO Mismatch 'RelEQ (Value era)
m -> Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era
forall era.
Mismatch 'RelEQ (Value era) -> AlonzoUtxoPredFailure era
ValueNotConservedUTxO Mismatch 'RelEQ (Value era)
m
  Allegra.WrongNetwork Network
x Set Addr
y -> Network -> Set Addr -> AlonzoUtxoPredFailure era
forall era. Network -> Set Addr -> AlonzoUtxoPredFailure era
WrongNetwork Network
x Set Addr
y
  Allegra.WrongNetworkWithdrawal Network
x Set RewardAccount
y -> Network -> Set RewardAccount -> AlonzoUtxoPredFailure era
forall era.
Network -> Set RewardAccount -> AlonzoUtxoPredFailure era
WrongNetworkWithdrawal Network
x Set RewardAccount
y
  Allegra.OutputTooSmallUTxO [TxOut era]
x -> [TxOut era] -> AlonzoUtxoPredFailure era
forall era. [TxOut era] -> AlonzoUtxoPredFailure era
OutputTooSmallUTxO [TxOut era]
x
  Allegra.UpdateFailure EraRuleFailure "PPUP" era
x -> PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
forall era.
PredicateFailure (EraRule "UTXOS" era) -> AlonzoUtxoPredFailure era
UtxosFailure (forall (rule :: Symbol) (t :: * -> *) era.
InjectRuleFailure rule t era =>
t era -> EraRuleFailure rule era
injectFailure @"UTXOS" @t t era
EraRuleFailure "PPUP" era
x)
  Allegra.OutputBootAddrAttrsTooBig [TxOut era]
xs -> [(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
forall era.
[(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
OutputTooBigUTxO ((TxOut era -> (Integer, Integer, TxOut era))
-> [TxOut era] -> [(Integer, Integer, TxOut era)]
forall a b. (a -> b) -> [a] -> [b]
map (Integer
0,Integer
0,) [TxOut era]
xs)
  AllegraUtxoPredFailure era
Allegra.TriesToForgeADA -> AlonzoUtxoPredFailure era
forall era. AlonzoUtxoPredFailure era
TriesToForgeADA
  Allegra.OutputTooBigUTxO [TxOut era]
xs -> [(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
forall era.
[(Integer, Integer, TxOut era)] -> AlonzoUtxoPredFailure era
OutputTooBigUTxO ((TxOut era -> (Integer, Integer, TxOut era))
-> [TxOut era] -> [(Integer, Integer, TxOut era)]
forall a b. (a -> b) -> [a] -> [b]
map (Integer
0,Integer
0,) [TxOut era]
xs)