33module Cardano.Ledger.Plutus.Preprocessor.Source.V3 where
44
55import Language.Haskell.TH
6- import qualified PlutusLedgerApi.V3 as PV3
6+ import qualified PlutusLedgerApi.Data. V3 as PV3D
77import PlutusTx (fromBuiltinData , unsafeFromBuiltinData )
8- import qualified PlutusTx.AssocMap as PAM
98import qualified PlutusTx.Builtins as P
9+ import qualified PlutusTx.Data.AssocMap as PAMD
10+ import qualified PlutusTx.Data.List as PLD
1011import qualified PlutusTx.Prelude as P
1112
1213alwaysSucceedsNoDatumQ :: Q [Dec ]
1314alwaysSucceedsNoDatumQ =
1415 [d |
1516 alwaysSucceedsNoDatum :: P.BuiltinData -> P.BuiltinUnit
1617 alwaysSucceedsNoDatum arg =
17- P.check $
18- case unsafeFromBuiltinData arg of
19- PV3.ScriptContext _txInfo (PV3.Redeemer _redeemer) scriptInfo ->
18+ let PV3D.ScriptContext _txInfo (PV3D.Redeemer _redeemer) scriptInfo =
19+ P. unsafeFromBuiltinData arg
20+ in P.check $
2021 case scriptInfo of
2122 -- We fail if this is a spending script with a Datum
22- PV3 .SpendingScript _ (Just _) -> False
23+ PV3D .SpendingScript _ (Just _) -> False
2324 _ -> True
2425 |]
2526
@@ -28,11 +29,13 @@ alwaysSucceedsWithDatumQ =
2829 [d |
2930 alwaysSucceedsWithDatum :: P.BuiltinData -> P.BuiltinUnit
3031 alwaysSucceedsWithDatum arg =
31- P.check $
32- case unsafeFromBuiltinData arg of
33- -- Expecting a spending script with a Datum, thus failing when it is not
34- PV3.ScriptContext _txInfo (PV3.Redeemer _redeemer) (PV3.SpendingScript _ (Just _)) -> True
35- _ -> False
32+ let PV3D.ScriptContext _txInfo (PV3D.Redeemer _redeemer) scriptPurpose =
33+ P.unsafeFromBuiltinData arg
34+ in P.check $
35+ case scriptPurpose of
36+ PV3D.SpendingScript _ (Just _) -> True
37+ -- Expecting a spending script with a Datum, thus failing when it is not
38+ _ -> False
3639 |]
3740
3841alwaysFailsNoDatumQ :: Q [Dec ]
@@ -42,10 +45,10 @@ alwaysFailsNoDatumQ =
4245 alwaysFailsNoDatum arg =
4346 P.check $
4447 case fromBuiltinData arg of
45- Just (PV3 .ScriptContext _txInfo (PV3 .Redeemer _redeemer) scriptInfo) ->
48+ Just (PV3D .ScriptContext _txInfo (PV3D .Redeemer _redeemer) scriptInfo) ->
4649 case scriptInfo of
4750 -- We fail only if this is not a spending script with a Datum
48- PV3 .SpendingScript _ (Just _) -> True
51+ PV3D .SpendingScript _ (Just _) -> True
4952 _ -> False
5053 Nothing -> True
5154 |]
@@ -57,10 +60,10 @@ alwaysFailsWithDatumQ =
5760 alwaysFailsWithDatum arg =
5861 P.check $
5962 case fromBuiltinData arg of
60- Just (PV3 .ScriptContext _txInfo (PV3 .Redeemer _redeemer) scriptInfo) ->
63+ Just (PV3D .ScriptContext _txInfo (PV3D .Redeemer _redeemer) scriptInfo) ->
6164 case scriptInfo of
6265 -- We fail only if this is a spending script with a Datum
63- PV3 .SpendingScript _ (Just _) -> False
66+ PV3D .SpendingScript _ (Just _) -> False
6467 _ -> True
6568 Nothing -> True
6669 |]
@@ -72,9 +75,12 @@ redeemerSameAsDatumQ =
7275 redeemerSameAsDatum arg =
7376 P.check $
7477 case unsafeFromBuiltinData arg of
75- PV3.ScriptContext _txInfo (PV3.Redeemer redeemer) (PV3.SpendingScript _ (Just (PV3.Datum datum))) ->
76- -- Expecting a spending script with a Datum, thus failing when it is not
77- datum P.== redeemer
78+ PV3D.ScriptContext
79+ _txInfo
80+ (PV3D.Redeemer redeemer)
81+ (PV3D.SpendingScript _ (Just (PV3D.Datum datum))) ->
82+ -- Expecting a spending script with a Datum, thus failing when it is not
83+ datum P.== redeemer
7884 _ -> False
7985 |]
8086
@@ -85,7 +91,7 @@ evenDatumQ =
8591 evenDatum arg =
8692 P.check $
8793 case unsafeFromBuiltinData arg of
88- PV3 .ScriptContext _txInfo _redeemer (PV3 .SpendingScript _ (Just (PV3 .Datum datum))) ->
94+ PV3D .ScriptContext _txInfo _redeemer (PV3D .SpendingScript _ (Just (PV3D .Datum datum))) ->
8995 -- Expecting a spending script with a Datum, thus failing when it is not
9096 P.modulo (P.unsafeDataAsI datum) 2 P.== 0
9197 |]
@@ -97,10 +103,10 @@ evenRedeemerNoDatumQ =
97103 evenRedeemerNoDatum arg =
98104 P.check $
99105 case unsafeFromBuiltinData arg of
100- PV3 .ScriptContext _txInfo (PV3 .Redeemer redeemer) scriptInfo ->
106+ PV3D .ScriptContext _txInfo (PV3D .Redeemer redeemer) scriptInfo ->
101107 case scriptInfo of
102108 -- Expecting No Datum, therefore should fail when it is supplied
103- PV3 .SpendingScript _ (Just _) -> False
109+ PV3D .SpendingScript _ (Just _) -> False
104110 _ -> P.modulo (P.unsafeDataAsI redeemer) 2 P.== 0
105111 |]
106112
@@ -111,7 +117,7 @@ evenRedeemerWithDatumQ =
111117 evenRedeemerWithDatum arg =
112118 P.check $
113119 case unsafeFromBuiltinData arg of
114- PV3 .ScriptContext _txInfo (PV3 .Redeemer redeemer) (PV3 .SpendingScript _ (Just _)) ->
120+ PV3D .ScriptContext _txInfo (PV3D .Redeemer redeemer) (PV3D .SpendingScript _ (Just _)) ->
115121 -- Expecting a spending script with a Datum, thus failing when it is not
116122 P.modulo (P.unsafeDataAsI redeemer) 2 P.== 0
117123 _ -> False
@@ -124,23 +130,31 @@ purposeIsWellformedNoDatumQ =
124130 purposeIsWellformedNoDatum arg =
125131 P.check $
126132 case unsafeFromBuiltinData arg of
127- PV3.ScriptContext txInfo _redeemer scriptInfo ->
128- case scriptInfo of
129- PV3.MintingScript cs ->
130- PAM.member cs $ PV3.getValue . PV3.mintValueMinted $ PV3.txInfoMint txInfo
133+ PV3D.ScriptContext
134+ PV3D.TxInfo
135+ { PV3D.txInfoMint = infoMint
136+ , PV3D.txInfoInputs = infoInputs
137+ , PV3D.txInfoWdrl = infoWdrl
138+ , PV3D.txInfoTxCerts = infoTxCerts
139+ , PV3D.txInfoVotes = infoVotes
140+ }
141+ _redeemer
142+ scriptInfo -> case scriptInfo of
143+ PV3D.MintingScript cs ->
144+ PAMD.member cs $ PV3D.getValue $ PV3D.mintValueMinted infoMint
131145 -- Expecting No Datum, therefore should fail when it is supplied
132- PV3 .SpendingScript txOutRef mDatum ->
146+ PV3D .SpendingScript txOutRef mDatum ->
133147 case mDatum of
134148 Just _ -> False
135149 Nothing ->
136- null $ P .filter ((txOutRef P.==) . PV3 .txInInfoOutRef) $ PV3.txInfoInputs txInfo
137- PV3 .RewardingScript stakingCredential ->
138- PAM .member stakingCredential $ PV3.txInfoWdrl txInfo
139- PV3 .CertifyingScript _idx txCert ->
140- null $ P .filter (txCert P.==) $ PV3.txInfoTxCerts txInfo
141- PV3 .VotingScript voter ->
142- PAM .member voter $ PV3.txInfoVotes txInfo
143- PV3 .ProposingScript _idx _propProc -> True
150+ PLD. null $ PLD .filter ((txOutRef P.==) . PV3D .txInInfoOutRef) infoInputs
151+ PV3D .RewardingScript cred ->
152+ PAMD .member cred infoWdrl
153+ PV3D .CertifyingScript _idx txCert ->
154+ PLD. null $ PLD .filter (txCert P.==) infoTxCerts
155+ PV3D .VotingScript voter ->
156+ PAMD .member voter infoVotes
157+ PV3D .ProposingScript _idx _propProc -> True
144158 -- Eq instance for proposals have been removed. I am not sure if this is a
145159 -- good idea, but it only affects ledger test script, so we'll deal with
146160 -- this later:
@@ -155,8 +169,8 @@ purposeIsWellformedWithDatumQ =
155169 purposeIsWellformedWithDatum arg =
156170 P.check $
157171 case unsafeFromBuiltinData arg of
158- PV3 .ScriptContext txInfo _redeemer (PV3 .SpendingScript txOutRef (Just _)) ->
159- not $ null $ P .filter ((txOutRef P.==) . PV3 .txInInfoOutRef) $ PV3 .txInfoInputs txInfo
172+ PV3D .ScriptContext txInfo _redeemer (PV3D .SpendingScript txOutRef (Just _)) ->
173+ not $ PLD. null $ PLD .filter ((txOutRef P.==) . PV3D .txInInfoOutRef) $ PV3D .txInfoInputs txInfo
160174 _ -> False
161175 |]
162176
@@ -167,8 +181,8 @@ datumIsWellformedQ =
167181 datumIsWellformed arg =
168182 P.check $
169183 case unsafeFromBuiltinData arg of
170- PV3 .ScriptContext txInfo _redeemer (PV3 .SpendingScript _txOutRef (Just datum)) ->
171- not $ null $ P .filter (datum P.==) $ PAM .elems $ PV3 .txInfoData txInfo
184+ PV3D .ScriptContext txInfo _redeemer (PV3D .SpendingScript _txOutRef (Just datum)) ->
185+ not $ PLD. null $ PLD .filter (datum P.==) $ PAMD .elems $ PV3D .txInfoData txInfo
172186 _ -> False
173187 |]
174188
@@ -180,9 +194,9 @@ inputsOutputsAreNotEmptyNoDatumQ =
180194 P.check $
181195 case unsafeFromBuiltinData arg of
182196 -- When there is a datum supplied, we need to fail.
183- PV3 .ScriptContext _txInfo _redeemer (PV3 .SpendingScript _txOutRef (Just _)) -> False
184- PV3 .ScriptContext txInfo _redeemer _scriptPurpose ->
185- not $ null (PV3 .txInfoInputs txInfo) || null (PV3 .txInfoOutputs txInfo)
197+ PV3D .ScriptContext _txInfo _redeemer (PV3D .SpendingScript _txOutRef (Just _)) -> False
198+ PV3D .ScriptContext txInfo _redeemer _scriptPurpose ->
199+ not $ PLD. null (PV3D .txInfoInputs txInfo) || PLD. null (PV3D .txInfoOutputs txInfo)
186200 |]
187201
188202inputsOutputsAreNotEmptyWithDatumQ :: Q [Dec ]
@@ -192,7 +206,7 @@ inputsOutputsAreNotEmptyWithDatumQ =
192206 inputsOutputsAreNotEmptyWithDatum arg =
193207 P.check $
194208 case unsafeFromBuiltinData arg of
195- PV3 .ScriptContext _txInfo _redeemer (PV3 .SpendingScript _txOutRef Nothing) -> False
196- PV3 .ScriptContext txInfo _redeemer _scriptPurpose ->
197- not $ null (PV3 .txInfoInputs txInfo) || null (PV3 .txInfoOutputs txInfo)
209+ PV3D .ScriptContext _txInfo _redeemer (PV3D .SpendingScript _txOutRef Nothing) -> False
210+ PV3D .ScriptContext txInfo _redeemer _scriptPurpose ->
211+ not $ PLD. null (PV3D .txInfoInputs txInfo) || PLD. null (PV3D .txInfoOutputs txInfo)
198212 |]
0 commit comments