Skip to content

Commit 492d54c

Browse files
authored
Merge pull request #4627 from IntersectMBO/td/fix-reg-txcert-pattern
Fix Conway implementation of RegTxCert and UnRegTxCert
2 parents db39c75 + 85aee1a commit 492d54c

File tree

16 files changed

+189
-66
lines changed

16 files changed

+189
-66
lines changed

eras/alonzo/impl/CHANGELOG.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
# Version history for `cardano-ledger-alonzo`
22

3-
## 1.10.2.1
4-
5-
*
3+
## 1.11.0.0
4+
5+
* Add `ProtVer` argument to functions in `EraPlutusTxInfo` class:
6+
* `toPlutusTxCert` of
7+
* `toPlutusScriptPurpose`
8+
* `toPlutusArgs`
9+
* Add `ProtVer` argument to `TxInfo` functions:
10+
* `transTxBodyCerts`
11+
* `transPlutusPurpose`
12+
* `toPlutusV1Args`
13+
* `toLegacyPlutusArgs`
614

715
## 1.10.2.0
816

eras/alonzo/impl/cardano-ledger-alonzo.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: cardano-ledger-alonzo
3-
version: 1.10.2.1
3+
version: 1.11.0.0
44
license: Apache-2.0
55
maintainer: [email protected]
66
author: IOHK

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/Context.hs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ data LedgerTxInfo era = LedgerTxInfo
7171
}
7272

7373
class (PlutusLanguage l, EraPlutusContext era) => EraPlutusTxInfo (l :: Language) era where
74-
toPlutusTxCert :: proxy l -> TxCert era -> Either (ContextError era) (PlutusTxCert l)
74+
toPlutusTxCert ::
75+
proxy l ->
76+
ProtVer ->
77+
TxCert era ->
78+
Either (ContextError era) (PlutusTxCert l)
7579

7680
toPlutusScriptPurpose ::
7781
proxy l ->
82+
ProtVer ->
7883
PlutusPurpose AsIxItem era ->
7984
Either (ContextError era) (PlutusScriptPurpose l)
8085

@@ -85,6 +90,7 @@ class (PlutusLanguage l, EraPlutusContext era) => EraPlutusTxInfo (l :: Language
8590

8691
toPlutusArgs ::
8792
proxy l ->
93+
ProtVer ->
8894
PlutusTxInfo l ->
8995
PlutusPurpose AsIxItem era ->
9096
Maybe (Data era) ->
@@ -129,7 +135,8 @@ toPlutusWithContext script scriptHash plutusPurpose lti (redeemerData, exUnits)
129135
maybeSpendingDatum =
130136
getSpendingDatum (ltiUTxO lti) (ltiTx lti) (hoistPlutusPurpose toAsItem plutusPurpose)
131137
txInfo <- toPlutusTxInfo proxy lti
132-
plutusArgs <- toPlutusArgs proxy txInfo plutusPurpose maybeSpendingDatum redeemerData
138+
plutusArgs <-
139+
toPlutusArgs proxy (ltiProtVer lti) txInfo plutusPurpose maybeSpendingDatum redeemerData
133140
pure $
134141
PlutusWithContext
135142
{ pwcProtocolVersion = pvMajor (ltiProtVer lti)

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Plutus/TxInfo.hs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ import NoThunks.Class (NoThunks)
101101
import qualified PlutusLedgerApi.V1 as PV1
102102

103103
instance Crypto c => EraPlutusTxInfo 'PlutusV1 (AlonzoEra c) where
104-
toPlutusTxCert _ = pure . transTxCert
104+
toPlutusTxCert _ _ = pure . transTxCert
105105

106-
toPlutusScriptPurpose proxy = transPlutusPurpose proxy . hoistPlutusPurpose toAsItem
106+
toPlutusScriptPurpose proxy pv = transPlutusPurpose proxy pv . hoistPlutusPurpose toAsItem
107107

108108
toPlutusTxInfo proxy LedgerTxInfo {ltiProtVer, ltiEpochInfo, ltiSystemStart, ltiUTxO, ltiTx} = do
109109
timeRange <-
110110
transValidityInterval ltiTx ltiProtVer ltiEpochInfo ltiSystemStart (txBody ^. vldtTxBodyL)
111111
txInsMaybes <- forM (Set.toList (txBody ^. inputsTxBodyL)) $ \txIn -> do
112112
txOut <- transLookupTxOut ltiUTxO txIn
113113
pure $ PV1.TxInInfo (transTxIn txIn) <$> transTxOut txOut
114-
txCerts <- transTxBodyCerts proxy txBody
114+
txCerts <- transTxBodyCerts proxy ltiProtVer txBody
115115
Right $
116116
PV1.TxInfo
117117
{ -- A mistake was made in Alonzo of filtering out Byron addresses, so we need to
@@ -135,25 +135,27 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV1 (AlonzoEra c) where
135135
toPlutusV1Args ::
136136
EraPlutusTxInfo 'PlutusV1 era =>
137137
proxy 'PlutusV1 ->
138+
ProtVer ->
138139
PV1.TxInfo ->
139140
PlutusPurpose AsIxItem era ->
140141
Maybe (Data era) ->
141142
Data era ->
142143
Either (ContextError era) (PlutusArgs 'PlutusV1)
143-
toPlutusV1Args proxy txInfo scriptPurpose maybeSpendingData redeemerData =
144+
toPlutusV1Args proxy pv txInfo scriptPurpose maybeSpendingData redeemerData =
144145
PlutusV1Args
145-
<$> toLegacyPlutusArgs proxy (PV1.ScriptContext txInfo) scriptPurpose maybeSpendingData redeemerData
146+
<$> toLegacyPlutusArgs proxy pv (PV1.ScriptContext txInfo) scriptPurpose maybeSpendingData redeemerData
146147

147148
toLegacyPlutusArgs ::
148149
EraPlutusTxInfo l era =>
149150
proxy l ->
151+
ProtVer ->
150152
(PlutusScriptPurpose l -> PlutusScriptContext l) ->
151153
PlutusPurpose AsIxItem era ->
152154
Maybe (Data era) ->
153155
Data era ->
154156
Either (ContextError era) (LegacyPlutusArgs l)
155-
toLegacyPlutusArgs proxy mkScriptContext scriptPurpose maybeSpendingData redeemerData = do
156-
scriptContext <- mkScriptContext <$> toPlutusScriptPurpose proxy scriptPurpose
157+
toLegacyPlutusArgs proxy pv mkScriptContext scriptPurpose maybeSpendingData redeemerData = do
158+
scriptContext <- mkScriptContext <$> toPlutusScriptPurpose proxy pv scriptPurpose
157159
let redeemer = getPlutusData redeemerData
158160
pure $ case maybeSpendingData of
159161
Nothing -> LegacyPlutusArgs2 redeemer scriptContext
@@ -257,10 +259,11 @@ transTxBodyId txBody = PV1.TxId (transSafeHash (hashAnnotated txBody))
257259
transTxBodyCerts ::
258260
(EraPlutusTxInfo l era, EraTxBody era) =>
259261
proxy l ->
262+
ProtVer ->
260263
TxBody era ->
261264
Either (ContextError era) [PlutusTxCert l]
262-
transTxBodyCerts proxy txBody =
263-
mapM (toPlutusTxCert proxy) $ F.toList (txBody ^. certsTxBodyL)
265+
transTxBodyCerts proxy pv txBody =
266+
mapM (toPlutusTxCert proxy pv) $ F.toList (txBody ^. certsTxBodyL)
264267

265268
transWithdrawals :: Withdrawals c -> Map.Map PV1.StakingCredential Integer
266269
transWithdrawals (Withdrawals mp) = Map.foldlWithKey' accum Map.empty mp
@@ -348,11 +351,12 @@ transTxCertCommon = \case
348351
transPlutusPurpose ::
349352
(EraPlutusTxInfo l era, PlutusTxCert l ~ PV1.DCert) =>
350353
proxy l ->
354+
ProtVer ->
351355
AlonzoPlutusPurpose AsItem era ->
352356
Either (ContextError era) PV1.ScriptPurpose
353-
transPlutusPurpose proxy = \case
357+
transPlutusPurpose proxy pv = \case
354358
AlonzoSpending (AsItem txIn) -> pure $ PV1.Spending (transTxIn txIn)
355359
AlonzoMinting (AsItem policyId) -> pure $ PV1.Minting (transPolicyID policyId)
356-
AlonzoCertifying (AsItem txCert) -> PV1.Certifying <$> toPlutusTxCert proxy txCert
360+
AlonzoCertifying (AsItem txCert) -> PV1.Certifying <$> toPlutusTxCert proxy pv txCert
357361
AlonzoRewarding (AsItem rewardAccount) ->
358362
pure $ PV1.Rewarding (PV1.StakingHash (transRewardAccount rewardAccount))

eras/babbage/impl/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Version history for `cardano-ledger-babbage`
22

3-
## 1.9.0.1
3+
## 1.10.0.0
44

5-
*
5+
* Add `ProtVer` argument to `TxInfo` functions:
6+
* `transTxRedeemers`
7+
* `toPlutusV2Args`
68

79
## 1.9.0.0
810

eras/babbage/impl/cardano-ledger-babbage.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: cardano-ledger-babbage
3-
version: 1.9.0.1
3+
version: 1.10.0.0
44
license: Apache-2.0
55
maintainer: [email protected]
66
author: IOHK
@@ -73,7 +73,7 @@ library
7373
cardano-crypto-class,
7474
cardano-data >=1.2,
7575
cardano-ledger-allegra ^>=1.6,
76-
cardano-ledger-alonzo >=1.9 && <1.11,
76+
cardano-ledger-alonzo >=1.11 && <1.12,
7777
cardano-ledger-binary >=1.3,
7878
cardano-ledger-core ^>=1.15,
7979
cardano-ledger-mary ^>=1.7,

eras/babbage/impl/src/Cardano/Ledger/Babbage/TxInfo.hs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ import Cardano.Ledger.Babbage.Core
4646
import Cardano.Ledger.Babbage.Era (BabbageEra)
4747
import Cardano.Ledger.Babbage.Scripts (PlutusScript (..))
4848
import Cardano.Ledger.Babbage.UTxO ()
49-
import Cardano.Ledger.BaseTypes (Inject (..), StrictMaybe (..), isSJust, kindObject)
49+
import Cardano.Ledger.BaseTypes (
50+
Inject (..),
51+
ProtVer,
52+
StrictMaybe (..),
53+
isSJust,
54+
kindObject,
55+
)
5056
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR (..))
5157
import Cardano.Ledger.Binary.Coders (
5258
Decode (..),
@@ -184,14 +190,15 @@ transRedeemerPtr ::
184190
, Inject (BabbageContextError era) (ContextError era)
185191
) =>
186192
proxy l ->
193+
ProtVer ->
187194
TxBody era ->
188195
(PlutusPurpose AsIx era, (Data era, ExUnits)) ->
189196
Either (ContextError era) (PlutusScriptPurpose l, PV2.Redeemer)
190-
transRedeemerPtr proxy txBody (ptr, (d, _)) =
197+
transRedeemerPtr proxy pv txBody (ptr, (d, _)) =
191198
case redeemerPointerInverse txBody ptr of
192199
SNothing -> Left $ inject $ RedeemerPointerPointsToNothing ptr
193200
SJust sp -> do
194-
plutusScriptPurpose <- toPlutusScriptPurpose proxy sp
201+
plutusScriptPurpose <- toPlutusScriptPurpose proxy pv sp
195202
Right (plutusScriptPurpose, transRedeemer d)
196203

197204
-- | Translate all `Redeemers` from within a `Tx` into a Map from a `PlutusScriptPurpose`
@@ -204,12 +211,13 @@ transTxRedeemers ::
204211
, Inject (BabbageContextError era) (ContextError era)
205212
) =>
206213
proxy l ->
214+
ProtVer ->
207215
Tx era ->
208216
Either (ContextError era) (PV2.Map (PlutusScriptPurpose l) PV2.Redeemer)
209-
transTxRedeemers proxy tx =
217+
transTxRedeemers proxy pv tx =
210218
PV2.unsafeFromList
211219
<$> mapM
212-
(transRedeemerPtr proxy (tx ^. bodyTxL))
220+
(transRedeemerPtr proxy pv (tx ^. bodyTxL))
213221
(Map.toList (unRedeemers $ tx ^. witsTxL . rdmrsTxWitsL))
214222

215223
instance Crypto c => EraPlutusContext (BabbageEra c) where
@@ -288,9 +296,9 @@ instance ToJSON (PlutusPurpose AsIx era) => ToJSON (BabbageContextError era) whe
288296
<> T.intercalate ", " (map txInToText (Set.toList txIns))
289297

290298
instance Crypto c => EraPlutusTxInfo 'PlutusV1 (BabbageEra c) where
291-
toPlutusTxCert _ = pure . Alonzo.transTxCert
299+
toPlutusTxCert _ _ = pure . Alonzo.transTxCert
292300

293-
toPlutusScriptPurpose proxy = Alonzo.transPlutusPurpose proxy . hoistPlutusPurpose toAsItem
301+
toPlutusScriptPurpose proxy pv = Alonzo.transPlutusPurpose proxy pv . hoistPlutusPurpose toAsItem
294302

295303
toPlutusTxInfo proxy LedgerTxInfo {ltiProtVer, ltiEpochInfo, ltiSystemStart, ltiUTxO, ltiTx} = do
296304
let refInputs = txBody ^. referenceInputsTxBodyL
@@ -304,7 +312,7 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV1 (BabbageEra c) where
304312
(transTxOutV1 . TxOutFromOutput)
305313
[minBound ..]
306314
(F.toList (txBody ^. outputsTxBodyL))
307-
txCerts <- Alonzo.transTxBodyCerts proxy txBody
315+
txCerts <- Alonzo.transTxBodyCerts proxy ltiProtVer txBody
308316
pure
309317
PV1.TxInfo
310318
{ PV1.txInfoInputs = inputs
@@ -324,9 +332,9 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV1 (BabbageEra c) where
324332
toPlutusArgs = Alonzo.toPlutusV1Args
325333

326334
instance Crypto c => EraPlutusTxInfo 'PlutusV2 (BabbageEra c) where
327-
toPlutusTxCert _ = pure . Alonzo.transTxCert
335+
toPlutusTxCert _ _ = pure . Alonzo.transTxCert
328336

329-
toPlutusScriptPurpose proxy = Alonzo.transPlutusPurpose proxy . hoistPlutusPurpose toAsItem
337+
toPlutusScriptPurpose proxy pv = Alonzo.transPlutusPurpose proxy pv . hoistPlutusPurpose toAsItem
330338

331339
toPlutusTxInfo proxy LedgerTxInfo {ltiProtVer, ltiEpochInfo, ltiSystemStart, ltiUTxO, ltiTx} = do
332340
timeRange <-
@@ -338,8 +346,8 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV2 (BabbageEra c) where
338346
(transTxOutV2 . TxOutFromOutput)
339347
[minBound ..]
340348
(F.toList (txBody ^. outputsTxBodyL))
341-
txCerts <- Alonzo.transTxBodyCerts proxy txBody
342-
plutusRedeemers <- transTxRedeemers proxy ltiTx
349+
txCerts <- Alonzo.transTxBodyCerts proxy ltiProtVer txBody
350+
plutusRedeemers <- transTxRedeemers proxy ltiProtVer ltiTx
343351
pure
344352
PV2.TxInfo
345353
{ PV2.txInfoInputs = inputs
@@ -363,11 +371,12 @@ instance Crypto c => EraPlutusTxInfo 'PlutusV2 (BabbageEra c) where
363371
toPlutusV2Args ::
364372
EraPlutusTxInfo 'PlutusV2 era =>
365373
proxy 'PlutusV2 ->
374+
ProtVer ->
366375
PV2.TxInfo ->
367376
PlutusPurpose AsIxItem era ->
368377
Maybe (Data era) ->
369378
Data era ->
370379
Either (ContextError era) (PlutusArgs 'PlutusV2)
371-
toPlutusV2Args proxy txInfo scriptPurpose maybeSpendingData redeemerData =
380+
toPlutusV2Args proxy pv txInfo scriptPurpose maybeSpendingData redeemerData =
372381
PlutusV2Args
373-
<$> toLegacyPlutusArgs proxy (PV2.ScriptContext txInfo) scriptPurpose maybeSpendingData redeemerData
382+
<$> toLegacyPlutusArgs proxy pv (PV2.ScriptContext txInfo) scriptPurpose maybeSpendingData redeemerData

eras/babbage/test-suite/cardano-ledger-babbage-test.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.0
22
name: cardano-ledger-babbage-test
3-
version: 1.2.0.4
3+
version: 1.2.0.5
44
license: Apache-2.0
55
maintainer: [email protected]
66
author: IOHK
@@ -35,7 +35,7 @@ library
3535
cardano-ledger-binary:{cardano-ledger-binary, testlib} >=1.0,
3636
cardano-ledger-alonzo:{cardano-ledger-alonzo, testlib} >=1.9,
3737
cardano-ledger-alonzo-test >=1.1,
38-
cardano-ledger-babbage:{cardano-ledger-babbage, testlib} >=1.9 && <1.10,
38+
cardano-ledger-babbage:{cardano-ledger-babbage, testlib} >=1.9 && <1.11,
3939
cardano-ledger-core:{cardano-ledger-core, testlib} >=1.11,
4040
cardano-ledger-shelley-ma-test >=1.1,
4141
cardano-ledger-mary >=1.4,

eras/conway/impl/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## 1.17.0.0
44

5+
* Add `ProtVer` argument to `TxInfo` functions:
6+
* `transTxCert`
7+
* `transScriptPurpose`
8+
* `transPlutusPurposeV1V2`
9+
* `toPlutusV3Args`
510
* Changed `ConwayWdrlNotDelegatedToDRep` to wrap `NonEmpty KeyHash`
611
* Removed `DRepAlreadyRegisteredForStakeKeyDELEG`
712
* Add `showGovActionType`, `acceptedByEveryone`

eras/conway/impl/cardano-ledger-conway.cabal

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ library
8686
cardano-data >=1.2.3,
8787
cardano-ledger-binary ^>=1.4,
8888
cardano-ledger-allegra ^>=1.6,
89-
cardano-ledger-alonzo ^>=1.10,
90-
cardano-ledger-babbage ^>=1.9,
89+
cardano-ledger-alonzo ^>=1.11,
90+
cardano-ledger-babbage ^>=1.10,
9191
cardano-ledger-core ^>=1.15,
9292
cardano-ledger-mary ^>=1.7,
9393
cardano-ledger-shelley ^>=1.14,
@@ -195,6 +195,7 @@ test-suite tests
195195
Test.Cardano.Ledger.Conway.GenesisSpec
196196
Test.Cardano.Ledger.Conway.GovActionReorderSpec
197197
Test.Cardano.Ledger.Conway.Plutus.PlutusSpec
198+
Test.Cardano.Ledger.Conway.TxInfoSpec
198199
Paths_cardano_ledger_conway
199200

200201
default-language: Haskell2010
@@ -221,4 +222,5 @@ test-suite tests
221222
containers,
222223
data-default-class,
223224
microlens,
225+
plutus-ledger-api,
224226
testlib

0 commit comments

Comments
 (0)