-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathUtxo.hs
533 lines (482 loc) · 19.6 KB
/
Utxo.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-orphans #-}
module Cardano.Ledger.Babbage.Rules.Utxo (
BabbageUTXO,
BabbageUtxoPredFailure (..),
utxoTransition,
feesOK,
validateTotalCollateral,
validateCollateralEqBalance,
validateOutputTooSmallUTxO,
) where
import Cardano.Ledger.Allegra.Rules (AllegraUtxoPredFailure, shelleyToAllegraUtxoPredFailure)
import qualified Cardano.Ledger.Allegra.Rules as Allegra (
validateOutsideValidityIntervalUTxO,
)
import Cardano.Ledger.Alonzo.Rules (
AlonzoUtxoEvent (..),
AlonzoUtxoPredFailure (..),
AlonzoUtxosPredFailure (..),
allegraToAlonzoUtxoPredFailure,
)
import qualified Cardano.Ledger.Alonzo.Rules as Alonzo (
validateExUnitsTooBigUTxO,
validateInsufficientCollateral,
validateOutputTooBigUTxO,
validateOutsideForecast,
validateScriptsNotPaidUTxO,
validateTooManyCollateralInputs,
validateWrongNetworkInTxBody,
)
import Cardano.Ledger.Alonzo.Tx (AlonzoTx (..))
import Cardano.Ledger.Alonzo.TxWits (nullRedeemers)
import Cardano.Ledger.Babbage.Collateral (collAdaBalance)
import Cardano.Ledger.Babbage.Core
import Cardano.Ledger.Babbage.Era (BabbageEra, BabbageUTXO)
import Cardano.Ledger.Babbage.Rules.Ppup ()
import Cardano.Ledger.Babbage.Rules.Utxos (BabbageUTXOS)
import Cardano.Ledger.BaseTypes (
Mismatch (..),
ProtVer (..),
ShelleyBase,
epochInfo,
networkId,
systemStart,
)
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..), Sized (..))
import Cardano.Ledger.Binary.Coders
import Cardano.Ledger.Coin (Coin (..), DeltaCoin, toDeltaCoin)
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.TxIn (TxIn)
import Cardano.Ledger.UTxO (EraUTxO (..), UTxO (..), areAllAdaOnly, balance)
import Cardano.Ledger.Val ((<->))
import qualified Cardano.Ledger.Val as Val (inject, isAdaOnly, pointwise)
import Control.DeepSeq (NFData)
import Control.Monad (unless, when)
import Control.Monad.Trans.Reader (asks)
import Control.SetAlgebra (eval, (◁))
import Control.State.Transition.Extended (
Embed (..),
STS (..),
TRC (..),
TransitionRule,
failureOnNonEmpty,
judgmentContext,
liftSTS,
trans,
validate,
)
import Data.Bifunctor (first)
import Data.Coerce (coerce)
import Data.Foldable (sequenceA_, toList)
import Data.List.NonEmpty (NonEmpty)
import qualified Data.Map.Strict as Map
import Data.Maybe.Strict (StrictMaybe (..))
import Data.Set (Set)
import qualified Data.Set as Set
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
import Lens.Micro
import NoThunks.Class (InspectHeapNamed (..), NoThunks (..))
import Validation (Validation, failureIf, failureUnless)
-- ======================================================
-- | Predicate failure for the Babbage Era
data BabbageUtxoPredFailure era
= AlonzoInBabbageUtxoPredFailure !(AlonzoUtxoPredFailure era) -- Inherited from Alonzo
| -- | The collateral is not equivalent to the total collateral asserted by the transaction
IncorrectTotalCollateralField
-- | collateral provided
!DeltaCoin
-- | collateral amount declared in transaction body
!Coin
| -- | list of supplied transaction outputs that are too small,
-- together with the minimum value for the given output.
BabbageOutputTooSmallUTxO
![(TxOut era, Coin)]
| -- | TxIns that appear in both inputs and reference inputs
BabbageNonDisjointRefInputs
!(NonEmpty TxIn)
deriving (Generic)
type instance EraRuleFailure "UTXO" BabbageEra = BabbageUtxoPredFailure BabbageEra
instance InjectRuleFailure "UTXO" BabbageUtxoPredFailure BabbageEra
instance InjectRuleFailure "UTXO" AlonzoUtxoPredFailure BabbageEra where
injectFailure = AlonzoInBabbageUtxoPredFailure
instance InjectRuleFailure "UTXO" ShelleyPpupPredFailure BabbageEra where
injectFailure = AlonzoInBabbageUtxoPredFailure . UtxosFailure . injectFailure
instance InjectRuleFailure "UTXO" ShelleyUtxoPredFailure BabbageEra where
injectFailure =
AlonzoInBabbageUtxoPredFailure
. allegraToAlonzoUtxoPredFailure
. shelleyToAllegraUtxoPredFailure
instance InjectRuleFailure "UTXO" AllegraUtxoPredFailure BabbageEra where
injectFailure = AlonzoInBabbageUtxoPredFailure . allegraToAlonzoUtxoPredFailure
instance InjectRuleFailure "UTXO" AlonzoUtxosPredFailure BabbageEra where
injectFailure = AlonzoInBabbageUtxoPredFailure . UtxosFailure
deriving instance
( Era era
, Show (AlonzoUtxoPredFailure era)
, Show (PredicateFailure (EraRule "UTXO" era))
, Show (TxOut era)
, Show (Script era)
, Show TxIn
) =>
Show (BabbageUtxoPredFailure era)
deriving instance
( Era era
, Eq (AlonzoUtxoPredFailure era)
, Eq (PredicateFailure (EraRule "UTXO" era))
, Eq (TxOut era)
, Eq (Script era)
, Eq TxIn
) =>
Eq (BabbageUtxoPredFailure era)
instance
( Era era
, NFData (Value era)
, NFData (TxOut era)
, NFData (PredicateFailure (EraRule "UTXOS" era))
) =>
NFData (BabbageUtxoPredFailure era)
-- =======================================================
-- | 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 inputs do not contain any non-ADA part
-- 5) The collateral is sufficient to cover the appropriate percentage of the
-- fee marked in the transaction
-- 6) The collateral is equivalent to total collateral asserted by the transaction
-- 7) There is at least one collateral input
--
-- feesOK can differ from Era to Era, as new notions of fees arise. This is the Babbage version
-- See: Figure 2: Functions related to fees and collateral, in the Babbage specification
-- In the spec feesOK is a boolean function. Because wee need to handle predicate failures
-- in the implementaion, it is coded as a Test. Which is a validation.
-- This version is generic in that it can be lifted to any PredicateFailure type that
-- embeds BabbageUtxoPred era. This makes it possibly useful in future Eras.
feesOK ::
forall era rule.
( EraUTxO era
, BabbageEraTxBody era
, AlonzoEraTxWits era
, InjectRuleFailure rule AlonzoUtxoPredFailure era
, InjectRuleFailure rule BabbageUtxoPredFailure era
) =>
PParams era ->
Tx era ->
UTxO era ->
Test (EraRuleFailure rule era)
feesOK pp tx u@(UTxO utxo) =
let txBody = tx ^. bodyTxL
collateral' = txBody ^. collateralInputsTxBodyL -- Inputs allocated to pay txfee
-- restrict Utxo to those inputs we use to pay fees.
utxoCollateral = eval (collateral' ◁ utxo)
theFee = txBody ^. feeTxBodyL -- Coin supplied to pay fees
minFee = getMinFeeTxUtxo pp tx u
in sequenceA_
[ -- Part 1: minfee pp tx ≤ txfee txBody
failureUnless
(minFee <= theFee)
(injectFailure $ FeeTooSmallUTxO Mismatch {mismatchSupplied = theFee, mismatchExpected = minFee})
, -- Part 2: (txrdmrs tx ≠ ∅ ⇒ validateCollateral)
unless (nullRedeemers $ tx ^. witsTxL . rdmrsTxWitsL) $
validateTotalCollateral pp txBody utxoCollateral
]
-- | Test that inputs and refInpts are disjoint, in Conway and later Eras.
disjointRefInputs ::
forall era.
EraPParams era =>
PParams era ->
Set TxIn ->
Set TxIn ->
Test (BabbageUtxoPredFailure era)
disjointRefInputs pp inputs refInputs =
when
(pvMajor (pp ^. ppProtocolVersionL) > eraProtVerHigh @BabbageEra)
(failureOnNonEmpty common BabbageNonDisjointRefInputs)
where
common = inputs `Set.intersection` refInputs
validateTotalCollateral ::
forall era rule.
( BabbageEraTxBody era
, InjectRuleFailure rule AlonzoUtxoPredFailure era
, InjectRuleFailure rule BabbageUtxoPredFailure era
) =>
PParams era ->
TxBody era ->
Map.Map TxIn (TxOut era) ->
Test (EraRuleFailure rule era)
validateTotalCollateral pp txBody utxoCollateral =
sequenceA_
[ -- Part 3: (∀(a,_,_) ∈ range (collateral txb ◁ utxo), a ∈ Addrvkey)
fromAlonzoValidation $ Alonzo.validateScriptsNotPaidUTxO utxoCollateral
, -- Part 4: isAdaOnly balance
fromAlonzoValidation $
validateCollateralContainsNonADA txBody utxoCollateral
, -- Part 5: balance ≥ ⌈txfee txb ∗ (collateralPercent pp) / 100⌉
fromAlonzoValidation $ Alonzo.validateInsufficientCollateral pp txBody bal
, -- Part 6: (txcoll tx ≠ ◇) ⇒ balance = txcoll tx
first (fmap injectFailure) $ validateCollateralEqBalance bal (txBody ^. totalCollateralTxBodyL)
, -- Part 7: collInputs tx ≠ ∅
fromAlonzoValidation $ failureIf (null utxoCollateral) (NoCollateralInputs @era)
]
where
bal = collAdaBalance txBody utxoCollateral
fromAlonzoValidation = first (fmap injectFailure)
-- | This validation produces the same failure as in Alonzo, but is slightly different
-- then the corresponding one in Alonzo, due to addition of the collateral return output:
--
-- 1. Collateral amount can be specified exactly, thus protecting user against unnecessary
-- loss.
--
-- 2. Collateral inputs can contain multi-assets, as long all of them are returned to the
-- `collateralReturnTxBodyL`. This design decision was also intentional, in order to
-- simplify utxo selection for collateral.
validateCollateralContainsNonADA ::
forall era.
BabbageEraTxBody era =>
TxBody era ->
Map.Map TxIn (TxOut era) ->
Test (AlonzoUtxoPredFailure era)
validateCollateralContainsNonADA txBody utxoCollateral =
failureUnless onlyAdaInCollateral $ CollateralContainsNonADA valueWithNonAda
where
onlyAdaInCollateral =
utxoCollateralAndReturnHaveOnlyAda || allNonAdaIsConsumedByReturn
-- When we do not have any non-ada TxOuts we can short-circuit the more expensive
-- validation of NonAda being fully consumed by the return output, which requires
-- computation of the full balance on the Value, not just the Coin.
utxoCollateralAndReturnHaveOnlyAda =
utxoCollateralHasOnlyAda && areAllAdaOnly (txBody ^. collateralReturnTxBodyL)
utxoCollateralHasOnlyAda = areAllAdaOnly utxoCollateral
-- Whenever return TxOut consumes all of the NonAda value then the total collateral
-- balance is considered valid.
allNonAdaIsConsumedByReturn = Val.isAdaOnly totalCollateralBalance
-- When reporting failure the NonAda value can be present in either:
-- - Only in collateral inputs.
-- - Only in return output, thus we report the return output value, rather than utxo.
-- - Both inputs and return address, but does not balance out. In which case
-- we report utxo balance
valueWithNonAda =
case txBody ^. collateralReturnTxBodyL of
SNothing -> collateralBalance
SJust retTxOut ->
if utxoCollateralHasOnlyAda
then retTxOut ^. valueTxOutL
else collateralBalance
-- This is the balance that is provided by the collateral inputs
collateralBalance = balance $ UTxO utxoCollateral
-- This is the total amount that will be spent as collateral. This is where we account
-- for the fact that we can remove Non-Ada assets from collateral inputs, by directing
-- them to the return TxOut.
totalCollateralBalance = case txBody ^. collateralReturnTxBodyL of
SNothing -> collateralBalance
SJust retTxOut -> collateralBalance <-> (retTxOut ^. valueTxOutL @era)
-- > (txcoll tx ≠ ◇) => balance == txcoll tx
validateCollateralEqBalance ::
DeltaCoin -> StrictMaybe Coin -> Validation (NonEmpty (BabbageUtxoPredFailure era)) ()
validateCollateralEqBalance bal txcoll =
case txcoll of
SNothing -> pure ()
SJust tc -> failureUnless (bal == toDeltaCoin tc) (IncorrectTotalCollateralField bal tc)
-- > getValue txout ≥ inject ( serSize txout ∗ coinsPerUTxOByte pp )
validateOutputTooSmallUTxO ::
(EraTxOut era, Foldable f) =>
PParams era ->
f (Sized (TxOut era)) ->
Test (BabbageUtxoPredFailure era)
validateOutputTooSmallUTxO pp outs =
failureUnless (null outputsTooSmall) $ BabbageOutputTooSmallUTxO outputsTooSmall
where
outs' = map (\out -> (sizedValue out, getMinCoinSizedTxOut pp out)) (toList outs)
outputsTooSmall =
filter
( \(out, minSize) ->
let v = out ^. valueTxOutL
in -- pointwise is used because non-ada amounts must be >= 0 too
not $
Val.pointwise
(>=)
v
(Val.inject minSize)
)
outs'
-- | The UTxO transition rule for the Babbage eras.
utxoTransition ::
forall era.
( EraUTxO era
, BabbageEraTxBody era
, AlonzoEraTxWits era
, Tx era ~ AlonzoTx era
, InjectRuleFailure "UTXO" ShelleyUtxoPredFailure era
, InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
, InjectRuleFailure "UTXO" AlonzoUtxoPredFailure era
, InjectRuleFailure "UTXO" BabbageUtxoPredFailure era
, Environment (EraRule "UTXO" era) ~ UtxoEnv era
, State (EraRule "UTXO" era) ~ UTxOState era
, Signal (EraRule "UTXO" era) ~ AlonzoTx era
, BaseM (EraRule "UTXO" era) ~ ShelleyBase
, STS (EraRule "UTXO" era)
, -- In this function we we call the UTXOS rule, so we need some assumptions
Embed (EraRule "UTXOS" era) (EraRule "UTXO" era)
, Environment (EraRule "UTXOS" era) ~ UtxoEnv era
, State (EraRule "UTXOS" era) ~ UTxOState era
, Signal (EraRule "UTXOS" era) ~ Tx era
) =>
TransitionRule (EraRule "UTXO" era)
utxoTransition = do
TRC (Shelley.UtxoEnv slot pp certState, utxos, tx) <- judgmentContext
let utxo = utxosUtxo utxos
{- txb := txbody tx -}
let txBody = body tx
allInputs = txBody ^. allInputsTxBodyF
refInputs :: Set TxIn
refInputs = txBody ^. referenceInputsTxBodyL
inputs :: Set TxIn
inputs = txBody ^. inputsTxBodyL
{- inputs ∩ refInputs = ∅ -}
runTest $ disjointRefInputs pp inputs refInputs
{- ininterval slot (txvld txb) -}
runTest $ Allegra.validateOutsideValidityIntervalUTxO slot txBody
sysSt <- liftSTS $ asks systemStart
ei <- liftSTS $ asks epochInfo
{- epochInfoSlotToUTCTime epochInfo systemTime i_f ≠ ◇ -}
runTest $ Alonzo.validateOutsideForecast ei slot sysSt tx
{- txins txb ≠ ∅ -}
runTestOnSignal $ Shelley.validateInputSetEmptyUTxO txBody
{- feesOK pp tx utxo -}
validate $ feesOK pp tx utxo -- Generalizes the fee to small from earlier Era's
{- allInputs = spendInputs txb ∪ collInputs txb ∪ refInputs txb -}
{- (spendInputs txb ∪ collInputs txb ∪ refInputs txb) ⊆ dom utxo -}
runTest $ Shelley.validateBadInputsUTxO utxo allInputs
{- consumed pp utxo txb = produced pp poolParams txb -}
runTest $ Shelley.validateValueNotConservedUTxO pp utxo certState txBody
{- adaID ∉ supp mint tx - check not needed because mint field of type MultiAsset
cannot contain ada -}
{- ∀ txout ∈ allOuts txb, getValue txout ≥ inject (serSize txout ∗ coinsPerUTxOByte pp) -}
let allSizedOutputs = txBody ^. allSizedOutputsTxBodyF
runTest $ validateOutputTooSmallUTxO pp allSizedOutputs
let allOutputs = fmap sizedValue allSizedOutputs
{- ∀ txout ∈ allOuts txb, serSize (getValue txout) ≤ maxValSize pp -}
runTest $ Alonzo.validateOutputTooBigUTxO pp allOutputs
{- ∀ ( _ ↦ (a,_)) ∈ allOuts txb, a ∈ Addrbootstrap → bootstrapAttrsSize a ≤ 64 -}
runTestOnSignal $ Shelley.validateOutputBootAddrAttrsTooBig allOutputs
netId <- liftSTS $ asks networkId
{- ∀(_ → (a, _)) ∈ allOuts txb, netId a = NetworkId -}
runTestOnSignal $ Shelley.validateWrongNetwork netId allOutputs
{- ∀(a → ) ∈ txwdrls txb, netId a = NetworkId -}
runTestOnSignal $ Shelley.validateWrongNetworkWithdrawal netId txBody
{- (txnetworkid txb = NetworkId) ∨ (txnetworkid txb = ◇) -}
runTestOnSignal $ Alonzo.validateWrongNetworkInTxBody netId txBody
{- txsize tx ≤ maxTxSize pp -}
runTestOnSignal $ Shelley.validateMaxTxSizeUTxO pp tx
{- totExunits tx ≤ maxTxExUnits pp -}
runTest $ Alonzo.validateExUnitsTooBigUTxO pp tx
{- ‖collateral tx‖ ≤ maxCollInputs pp -}
runTest $ Alonzo.validateTooManyCollateralInputs pp txBody
trans @(EraRule "UTXOS" era) =<< coerce <$> judgmentContext
--------------------------------------------------------------------------------
-- BabbageUTXO STS
--------------------------------------------------------------------------------
instance
forall era.
( EraTx era
, EraUTxO era
, BabbageEraTxBody era
, AlonzoEraTxWits era
, Tx era ~ AlonzoTx era
, EraRule "UTXO" era ~ BabbageUTXO era
, InjectRuleFailure "UTXO" ShelleyUtxoPredFailure era
, InjectRuleFailure "UTXO" AllegraUtxoPredFailure era
, InjectRuleFailure "UTXO" AlonzoUtxoPredFailure era
, InjectRuleFailure "UTXO" BabbageUtxoPredFailure era
, -- instructions for calling UTXOS from BabbageUTXO
Embed (EraRule "UTXOS" era) (BabbageUTXO era)
, Environment (EraRule "UTXOS" era) ~ UtxoEnv era
, State (EraRule "UTXOS" era) ~ UTxOState era
, Signal (EraRule "UTXOS" era) ~ Tx era
) =>
STS (BabbageUTXO era)
where
type State (BabbageUTXO era) = UTxOState era
type Signal (BabbageUTXO era) = AlonzoTx era
type Environment (BabbageUTXO era) = UtxoEnv era
type BaseM (BabbageUTXO era) = ShelleyBase
type PredicateFailure (BabbageUTXO era) = BabbageUtxoPredFailure era
type Event (BabbageUTXO era) = AlonzoUtxoEvent era
initialRules = []
transitionRules = [utxoTransition @era]
instance
( Era era
, STS (BabbageUTXOS era)
, PredicateFailure (EraRule "UTXOS" era) ~ AlonzoUtxosPredFailure era
, Event (EraRule "UTXOS" era) ~ Event (BabbageUTXOS era)
) =>
Embed (BabbageUTXOS era) (BabbageUTXO era)
where
wrapFailed = AlonzoInBabbageUtxoPredFailure . UtxosFailure
wrapEvent = UtxosEvent
-- ============================================
-- CBOR for Predicate faiure type
instance
( Era era
, EncCBOR (TxOut era)
, EncCBOR (Value era)
, EncCBOR (PredicateFailure (EraRule "UTXOS" era))
, EncCBOR (PredicateFailure (EraRule "UTXO" era))
, EncCBOR (Script era)
, EncCBOR TxIn
, Typeable (TxAuxData era)
) =>
EncCBOR (BabbageUtxoPredFailure era)
where
encCBOR =
encode . \case
AlonzoInBabbageUtxoPredFailure x -> Sum AlonzoInBabbageUtxoPredFailure 1 !> To x
IncorrectTotalCollateralField c1 c2 -> Sum IncorrectTotalCollateralField 2 !> To c1 !> To c2
BabbageOutputTooSmallUTxO x -> Sum BabbageOutputTooSmallUTxO 3 !> To x
BabbageNonDisjointRefInputs x -> Sum BabbageNonDisjointRefInputs 4 !> To x
instance
( Era era
, DecCBOR (TxOut era)
, EncCBOR (Value era)
, DecCBOR (Value era)
, DecCBOR (PredicateFailure (EraRule "UTXOS" era))
, DecCBOR (PredicateFailure (EraRule "UTXO" era))
, Typeable (Script era)
, Typeable (TxAuxData era)
) =>
DecCBOR (BabbageUtxoPredFailure era)
where
decCBOR = decode $ Summands "BabbageUtxoPred" $ \case
1 -> SumD AlonzoInBabbageUtxoPredFailure <! From
2 -> SumD IncorrectTotalCollateralField <! From <! From
3 -> SumD BabbageOutputTooSmallUTxO <! From
4 -> SumD BabbageNonDisjointRefInputs <! From
n -> Invalid n
deriving via
InspectHeapNamed "BabbageUtxoPred" (BabbageUtxoPredFailure era)
instance
NoThunks (BabbageUtxoPredFailure era)