-
Notifications
You must be signed in to change notification settings - Fork 479
/
V3.hs
221 lines (194 loc) · 5.66 KB
/
V3.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
-- | The interface to Plutus V3 for the ledger.
module PlutusLedgerApi.V3 (
-- * Scripts
SerialisedScript,
ScriptForEvaluation,
serialisedScript,
deserialisedScript,
serialiseCompiledCode,
serialiseUPLC,
deserialiseScript,
uncheckedDeserialiseUPLC,
-- * Running scripts
evaluateScriptRestricting,
evaluateScriptCounting,
-- ** CIP-1694
ColdCommitteeCredential (..),
HotCommitteeCredential (..),
DRepCredential (..),
DRep (..),
Delegatee (..),
TxCert (..),
Voter (..),
Vote (..),
GovernanceActionId (..),
Committee (..),
Constitution (..),
ProtocolVersion (..),
GovernanceAction (..),
ChangedParameters (..),
ProposalProcedure (..),
-- ** Protocol version
MajorProtocolVersion (..),
-- ** Verbose mode and log output
VerboseMode (..),
LogOutput,
-- * Costing-related types
ExBudget (..),
V2.ExCPU (..),
V2.ExMemory (..),
V2.SatInt (V2.unSatInt),
V2.fromSatInt,
-- ** Cost model
EvaluationContext,
mkEvaluationContext,
ParamName (..),
CostModelApplyError (..),
CostModelParams,
assertWellFormedCostModelParams,
-- * Context types
ScriptContext (..),
ScriptPurpose (..),
-- ** Supporting types used in the context types
-- *** ByteStrings
V2.BuiltinByteString,
V2.toBuiltin,
V2.fromBuiltin,
-- *** Bytes
V2.LedgerBytes (..),
V2.fromBytes,
-- *** Credentials
V2.StakingCredential (..),
V2.Credential (..),
-- *** Value
V2.Value (..),
V2.CurrencySymbol (..),
V2.TokenName (..),
V2.singleton,
V2.unionWith,
V2.adaSymbol,
V2.adaToken,
V2.Lovelace (..),
-- *** Time
V2.POSIXTime (..),
V2.POSIXTimeRange,
-- *** Types for representing transactions
V2.Address (..),
V2.PubKeyHash (..),
TxId (..),
TxInfo (..),
V2.TxOut (..),
TxOutRef (..),
TxInInfo (..),
V2.OutputDatum (..),
-- *** Intervals
V2.Interval (..),
V2.Extended (..),
V2.Closure,
V2.UpperBound (..),
V2.LowerBound (..),
V2.always,
V2.from,
V2.to,
V2.lowerBound,
V2.upperBound,
V2.strictLowerBound,
V2.strictUpperBound,
-- *** Ratio
Ratio.Rational,
Ratio.ratio,
Ratio.fromGHC,
Ratio.toGHC,
-- *** Association maps
V2.Map,
V2.unsafeFromList,
-- *** Newtypes and hash types
V2.ScriptHash (..),
V2.Redeemer (..),
V2.RedeemerHash (..),
V2.Datum (..),
V2.DatumHash (..),
-- * Data
V2.Data (..),
V2.BuiltinData (..),
V2.ToData (..),
V2.FromData (..),
V2.UnsafeFromData (..),
V2.toData,
V2.fromData,
V2.dataToBuiltinData,
V2.builtinDataToData,
-- * Errors
V2.EvaluationError (..),
V2.ScriptDecodeError (..),
) where
import PlutusCore.Data qualified as PLC
import PlutusLedgerApi.Common as Common hiding (deserialiseScript, evaluateScriptCounting,
evaluateScriptRestricting)
import PlutusLedgerApi.Common qualified as Common (deserialiseScript, evaluateScriptCounting,
evaluateScriptRestricting)
import PlutusLedgerApi.V2 qualified as V2 hiding (ScriptContext (..), ScriptPurpose (..), TxId (..),
TxInfo (..), TxOutRef (..))
import PlutusLedgerApi.V3.Contexts
import PlutusLedgerApi.V3.EvaluationContext
import PlutusLedgerApi.V3.ParamName
import PlutusLedgerApi.V3.Tx
import PlutusTx.Ratio qualified as Ratio
import Control.Monad.Except (MonadError)
{- | An alias to the Plutus ledger language this module exposes at runtime.
MAYBE: Use CPP '__FILE__' + some TH to automate this.
-}
thisLedgerLanguage :: PlutusLedgerLanguage
thisLedgerLanguage = PlutusV3
{- | The deserialization from a serialised script into a `ScriptForEvaluation`,
ready to be evaluated on-chain.
Called inside phase-1 validation (i.e., deserialisation error is a phase-1 error).
-}
deserialiseScript ::
forall m.
(MonadError ScriptDecodeError m) =>
-- | which major protocol version the script was submitted in.
MajorProtocolVersion ->
-- | the script to deserialise.
SerialisedScript ->
m ScriptForEvaluation
deserialiseScript = Common.deserialiseScript thisLedgerLanguage
{- | Evaluates a script, returning the minimum budget that the script would need
to evaluate successfully. This will take as long as the script takes, if you need to
limit the execution time of the script also, you can use 'evaluateScriptRestricting', which
also returns the used budget.
-}
evaluateScriptCounting ::
-- | Which protocol version to run the operation in
MajorProtocolVersion ->
-- | Whether to produce log output
VerboseMode ->
-- | Includes the cost model to use for tallying up the execution costs
EvaluationContext ->
-- | The script to evaluate
ScriptForEvaluation ->
-- | The arguments to the script
[PLC.Data] ->
(LogOutput, Either EvaluationError ExBudget)
evaluateScriptCounting = Common.evaluateScriptCounting thisLedgerLanguage
{- | Evaluates a script, with a cost model and a budget that restricts how many
resources it can use according to the cost model. Also returns the budget that
was actually used.
Can be used to calculate budgets for scripts, but even in this case you must give
a limit to guard against scripts that run for a long time or loop.
-}
evaluateScriptRestricting ::
-- | Which protocol version to run the operation in
MajorProtocolVersion ->
-- | Whether to produce log output
VerboseMode ->
-- | Includes the cost model to use for tallying up the execution costs
EvaluationContext ->
-- | The resource budget which must not be exceeded during evaluation
ExBudget ->
-- | The script to evaluate
ScriptForEvaluation ->
-- | The arguments to the script
[PLC.Data] ->
(LogOutput, Either EvaluationError ExBudget)
evaluateScriptRestricting = Common.evaluateScriptRestricting thisLedgerLanguage