-
Notifications
You must be signed in to change notification settings - Fork 158
/
Body.hs
114 lines (105 loc) · 3.88 KB
/
Body.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
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Cardano.Ledger.Api.Tx.Body (
-- | Building and inspecting transaction outputs
module Cardano.Ledger.Api.Tx.Out,
-- | Working with Timelock scripts and Plutus scripts
module Cardano.Ledger.Api.Scripts,
EraTxBody (TxBody),
mkBasicTxBody,
inputsTxBodyL,
outputsTxBodyL,
feeTxBodyL,
withdrawalsTxBodyL,
Withdrawals (..),
auxDataHashTxBodyL,
AuxiliaryDataHash,
allInputsTxBodyF,
evalBalanceTxBody,
-- * Shelley Era
ShelleyEraTxBody,
ttlTxBodyL,
updateTxBodyL,
updateTxBodyG,
certsTxBodyL,
certsTxBodyG,
-- * Allegra Era
AllegraEraTxBody,
vldtTxBodyL,
ValidityInterval (..),
-- * Mary Era
MaryEraTxBody,
mintTxBodyL,
mintValueTxBodyF,
mintedTxBodyF,
-- * Alonzo Era
AlonzoEraTxBody,
collateralInputsTxBodyL,
reqSignerHashesTxBodyL,
scriptIntegrityHashTxBodyL,
networkIdTxBodyL,
-- * Babbage Era
BabbageEraTxBody,
sizedOutputsTxBodyL,
referenceInputsTxBodyL,
totalCollateralTxBodyL,
collateralReturnTxBodyL,
sizedCollateralReturnTxBodyL,
allSizedOutputsTxBodyF,
-- * Conway Era
ConwayEraTxBody,
votingProceduresTxBodyL,
proposalProceduresTxBodyL,
conwayCertsTxBodyL,
)
where
import Cardano.Ledger.Address (Withdrawals (..))
import Cardano.Ledger.Allegra.Core (AllegraEraTxBody (..))
import Cardano.Ledger.Alonzo.TxBody (AlonzoEraTxBody (..))
import Cardano.Ledger.Api.Era ()
import Cardano.Ledger.Api.Scripts
import Cardano.Ledger.Api.Tx.Out
import Cardano.Ledger.AuxiliaryData (AuxiliaryDataHash)
import Cardano.Ledger.Babbage.TxBody (BabbageEraTxBody (..))
import Cardano.Ledger.Coin (Coin)
import Cardano.Ledger.Conway.Core (ConwayEraTxBody (..))
import Cardano.Ledger.Core (Era (EraCrypto), EraTxBody (..), PParams, Value)
import Cardano.Ledger.Credential (StakeCredential)
import Cardano.Ledger.Keys (KeyHash (..), KeyRole (..))
import Cardano.Ledger.Mary.Core (MaryEraTxBody (..))
import Cardano.Ledger.Shelley.Core (ShelleyEraTxBody (..))
import Cardano.Ledger.Shelley.UTxO (getProducedValue)
import Cardano.Ledger.UTxO (EraUTxO (getConsumedValue), UTxO)
import Cardano.Ledger.Val ((<->))
-- | Evaluate the difference between the value currently being consumed by a transaction
-- and the total value being produced. This value will be zero for a valid transaction.
--
-- In case when full `Cardano.Ledger.DPState` is available then this can be simplified to:
--
-- > let lookupRefund = lookupDepositDState (dpsDState dpState)
-- > let isRegPoolId = (`Map.member` psStakePoolParams (dpsPState dpState))
-- > evalBalanceTxBody pp lookupRefund isRegPoolId utxo txBody
evalBalanceTxBody ::
(EraUTxO era, ShelleyEraTxBody era) =>
-- | Current protocol parameters
PParams era ->
-- | Lookup current deposit amount for a registered stake credential delegation. This
-- function must produce valid answer for all of the stake credentials present in any of
-- the `DeRegKey` delegation certificates in the supplied `TxBody`. In other words,
-- there is no requirement to know about all of the delegation certificates in the
-- ledger state, just the ones this transaction cares about.
(StakeCredential (EraCrypto era) -> Maybe Coin) ->
-- | Check whether a pool with a supplied PoolStakeId is already registered. There is no
-- requirement to answer this question for all stake pool credentials, just for the ones
-- that have the registration certificates included in the supplied `TxBody`
(KeyHash 'StakePool (EraCrypto era) -> Bool) ->
-- | The UTxO relevant to the transaction.
UTxO era ->
-- | The transaction being evaluated for balance.
TxBody era ->
-- | The difference between what the transaction consumes and what it produces.
Value era
evalBalanceTxBody pp lookupRefund isRegPoolId utxo txBody =
getConsumedValue pp lookupRefund utxo txBody <-> getProducedValue pp isRegPoolId txBody