Skip to content

Commit 7ecb8c9

Browse files
committed
Switch to eraProtVerHigh
1 parent 5a05426 commit 7ecb8c9

File tree

9 files changed

+43
-28
lines changed

9 files changed

+43
-28
lines changed

cardano-api/gen/Test/Hedgehog/Roundtrip/CBOR.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import Cardano.Api.Experimental qualified as Exp
1616
import Cardano.Api.Experimental.Plutus qualified as Exp
1717
import Cardano.Api.Ledger qualified as L
1818

19-
import Cardano.Binary
2019
import Cardano.Ledger.Core qualified as Ledger
2120
import Cardano.Ledger.Plutus.Language qualified as Plutus
2221

cardano-api/src/Cardano/Api/Era/Internal/Eon/ShelleyBasedEra.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module Cardano.Api.Era.Internal.Eon.ShelleyBasedEra
3030

3131
-- ** Mapping to era types from the Shelley ledger library
3232
, ShelleyLedgerEra
33-
, eraProtVerLow
33+
, eraProtVerHigh
3434
, ShelleyBasedEraConstraints
3535
, shelleyBasedEraConstraints
3636
)
@@ -357,15 +357,15 @@ type family ShelleyLedgerEra era = ledgerera | ledgerera -> era where
357357

358358
-- | Lookup the lower major protocol version for the shelley based era. In other words
359359
-- this is the major protocol version that the era has started in.
360-
eraProtVerLow :: ShelleyBasedEra era -> L.Version
361-
eraProtVerLow = \case
362-
ShelleyBasedEraShelley -> L.eraProtVerLow @L.ShelleyEra
363-
ShelleyBasedEraAllegra -> L.eraProtVerLow @L.AllegraEra
364-
ShelleyBasedEraMary -> L.eraProtVerLow @L.MaryEra
365-
ShelleyBasedEraAlonzo -> L.eraProtVerLow @L.AlonzoEra
366-
ShelleyBasedEraBabbage -> L.eraProtVerLow @L.BabbageEra
367-
ShelleyBasedEraConway -> L.eraProtVerLow @L.ConwayEra
368-
ShelleyBasedEraDijkstra -> L.eraProtVerLow @L.DijkstraEra
360+
eraProtVerHigh :: ShelleyBasedEra era -> L.Version
361+
eraProtVerHigh = \case
362+
ShelleyBasedEraShelley -> L.eraProtVerHigh @L.ShelleyEra
363+
ShelleyBasedEraAllegra -> L.eraProtVerHigh @L.AllegraEra
364+
ShelleyBasedEraMary -> L.eraProtVerHigh @L.MaryEra
365+
ShelleyBasedEraAlonzo -> L.eraProtVerHigh @L.AlonzoEra
366+
ShelleyBasedEraBabbage -> L.eraProtVerHigh @L.BabbageEra
367+
ShelleyBasedEraConway -> L.eraProtVerHigh @L.ConwayEra
368+
ShelleyBasedEraDijkstra -> L.eraProtVerHigh @L.DijkstraEra
369369

370370
requireShelleyBasedEra
371371
:: ()

cardano-api/src/Cardano/Api/Experimental/Plutus/Internal/Script.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ instance
119119
L.serialize' (L.eraProtVerHigh @era) s
120120

121121
deserialiseFromCBOR _ bs = do
122-
let v = L.eraProtVerLow @era
122+
let v = L.eraProtVerHigh @era
123123
scriptShortBs = SBS.toShort $ removePlutusScriptDoubleEncoding $ LBS.fromStrict bs
124124
let plutusScript :: Plutus.Plutus lang
125125
plutusScript = L.Plutus $ L.PlutusBinary scriptShortBs

cardano-api/src/Cardano/Api/Plutus/Internal/Script.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ instance IsScriptLanguage lang => SerialiseAsCBOR (Script lang) where
467467
deserialiseFromCBOR _ bs =
468468
case scriptLanguage :: ScriptLanguage lang of
469469
SimpleScriptLanguage ->
470-
let version = Ledger.eraProtVerLow @(ShelleyLedgerEra AllegraEra)
470+
let version = Ledger.eraProtVerHigh @(ShelleyLedgerEra AllegraEra)
471471
in SimpleScript . fromAllegraTimelock @(ShelleyLedgerEra AllegraEra)
472472
<$> Binary.decodeFullAnnotator version "Script" Binary.decCBOR (LBS.fromStrict bs)
473473
PlutusScriptLanguage PlutusScriptV1 ->
@@ -1494,7 +1494,7 @@ instance
14941494
serialiseToCBOR (PlutusScriptInEra (PlutusScriptSerialised s)) =
14951495
SBS.fromShort s
14961496
deserialiseFromCBOR _ bs = do
1497-
let v = Ledger.eraProtVerLow @(ShelleyLedgerEra era)
1497+
let v = Ledger.eraProtVerHigh @(ShelleyLedgerEra era)
14981498
scriptShortBs = SBS.toShort $ removePlutusScriptDoubleEncoding $ LBS.fromStrict bs
14991499
let plutusScript :: Plutus.Plutus (ToLedgerPlutusLanguage lang)
15001500
plutusScript = PlutusScriptBinary scriptShortBs

cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ decodePoolState
398398
-> Either DecoderError (PoolState era)
399399
decodePoolState sbe (SerialisedPoolState (Serialised ls)) =
400400
shelleyBasedEraConstraints sbe $
401-
PoolState <$> decodeFull (Core.eraProtVerLow @(ShelleyLedgerEra era)) ls
401+
PoolState <$> decodeFull (Core.eraProtVerHigh @(ShelleyLedgerEra era)) ls
402402

403403
newtype PoolDistribution era = PoolDistribution
404404
{ unPoolDistr :: Shelley.PoolDistr
@@ -410,7 +410,7 @@ decodePoolDistribution
410410
-> Serialised (PoolDistribution era)
411411
-> Either DecoderError (PoolDistribution era)
412412
decodePoolDistribution sbe (Serialised ls) =
413-
PoolDistribution <$> decodeFull (eraProtVerLow sbe) ls
413+
PoolDistribution <$> decodeFull (eraProtVerHigh sbe) ls
414414

415415
newtype SerialisedStakeSnapshots era
416416
= SerialisedStakeSnapshots

cardano-api/src/Cardano/Api/Serialise/TextEnvelope/Internal/Cddl.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ deserialiseWitnessLedgerCddl sbe te =
186186
w <-
187187
first TextEnvelopeCddlErrCBORDecodingError $
188188
CBOR.decodeFullAnnotator
189-
(eraProtVerLow sbe)
189+
(eraProtVerHigh sbe)
190190
"Shelley Witness"
191191
CBOR.decCBOR
192192
(LBS.fromStrict teRawCBOR)
@@ -195,7 +195,7 @@ deserialiseWitnessLedgerCddl sbe te =
195195
w <-
196196
first TextEnvelopeCddlErrCBORDecodingError $
197197
CBOR.decodeFullAnnotator
198-
(eraProtVerLow sbe)
198+
(eraProtVerHigh sbe)
199199
"Shelley Witness"
200200
CBOR.decCBOR
201201
(LBS.fromStrict teRawCBOR)

cardano-api/src/Cardano/Api/Tx/Internal/Serialise.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ deserialiseWitnessLedger sbe te =
8888
w <-
8989
first TextEnvelopeDecodeError $
9090
CBOR.decodeFullAnnotator
91-
(eraProtVerLow sbe)
91+
(eraProtVerHigh sbe)
9292
"Shelley Witness"
9393
CBOR.decCBOR
9494
(LBS.fromStrict teRawCBOR)
@@ -97,7 +97,7 @@ deserialiseWitnessLedger sbe te =
9797
w <-
9898
first TextEnvelopeDecodeError $
9999
CBOR.decodeFullAnnotator
100-
(eraProtVerLow sbe)
100+
(eraProtVerHigh sbe)
101101
"Shelley Witness"
102102
CBOR.decCBOR
103103
(LBS.fromStrict teRawCBOR)

cardano-api/src/Cardano/Api/Tx/Internal/Sign.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ deserialiseShelleyBasedTx
237237
deserialiseShelleyBasedTx mkTx bs =
238238
mkTx
239239
<$> CBOR.decodeFullAnnotator
240-
(L.eraProtVerLow @ledgerera)
240+
(L.eraProtVerHigh @ledgerera)
241241
"Shelley Tx"
242242
CBOR.decCBOR
243243
(LBS.fromStrict bs)
@@ -729,9 +729,9 @@ instance IsCardanoEra era => SerialiseAsCBOR (KeyWitness era) where
729729
serialiseToCBOR (ByronKeyWitness wit) =
730730
Plain.serialize' wit
731731
serialiseToCBOR (ShelleyKeyWitness sbe wit) =
732-
CBOR.serialize' (eraProtVerLow sbe) wit
732+
CBOR.serialize' (eraProtVerHigh sbe) wit
733733
serialiseToCBOR (ShelleyBootstrapWitness sbe wit) =
734-
CBOR.serialize' (eraProtVerLow sbe) wit
734+
CBOR.serialize' (eraProtVerHigh sbe) wit
735735

736736
deserialiseFromCBOR _ bs =
737737
case cardanoEra :: CardanoEra era of
@@ -752,12 +752,12 @@ instance IsCardanoEra era => SerialiseAsCBOR (KeyWitness era) where
752752
-- provides a convenient way to try multiple decoders until one succeeds.
753753
legacyKeyWitnessEncode :: KeyWitness era -> ByteString
754754
legacyKeyWitnessEncode (ShelleyKeyWitness sbe wit) =
755-
CBOR.serialize' (eraProtVerLow sbe) $
755+
CBOR.serialize' (eraProtVerHigh sbe) $
756756
CBOR.encodeListLen 2
757757
<> CBOR.encodeWord 0
758758
<> CBOR.encCBOR wit
759759
legacyKeyWitnessEncode (ShelleyBootstrapWitness sbe wit) =
760-
CBOR.serialize' (eraProtVerLow sbe) $
760+
CBOR.serialize' (eraProtVerHigh sbe) $
761761
CBOR.encodeListLen 2
762762
<> CBOR.encodeWord 1
763763
<> CBOR.encCBOR wit
@@ -789,22 +789,22 @@ decodeShelleyBasedWitness sbe bs =
789789
shelleyKeyWitnessDecoder b =
790790
ShelleyKeyWitness sbe
791791
<$> CBOR.decodeFullAnnotator
792-
(L.eraProtVerLow @(ShelleyLedgerEra era))
792+
(L.eraProtVerHigh @(ShelleyLedgerEra era))
793793
"Shelley Witness"
794794
CBOR.decCBOR
795795
(LBS.fromStrict b)
796796

797797
bootstrapWitnessDecoder b =
798798
ShelleyBootstrapWitness sbe
799799
<$> CBOR.decodeFullAnnotator
800-
(L.eraProtVerLow @(ShelleyLedgerEra era))
800+
(L.eraProtVerHigh @(ShelleyLedgerEra era))
801801
"Shelley Witness"
802802
CBOR.decCBOR
803803
(LBS.fromStrict b)
804804

805805
legacyKeyWitnessDecoder b =
806806
CBOR.decodeFullAnnotator
807-
(L.eraProtVerLow @(ShelleyLedgerEra era))
807+
(L.eraProtVerHigh @(ShelleyLedgerEra era))
808808
"Shelley Witness"
809809
decodeLegacy
810810
(LBS.fromStrict b)

cardano-api/test/cardano-api-test/Test/Cardano/Api/CBOR.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,19 @@ prop_decode_only_wrapped_plutus_script_V2_CBOR = H.property $ do
346346
(SBS.fromShort shortBs)
347347
Ledger.SPlutusV2
348348

349+
prop_decode_only_wrapped_plutus_script_V2_ByteStringToInteger_CBOR :: Property
350+
prop_decode_only_wrapped_plutus_script_V2_ByteStringToInteger_CBOR = H.property $ do
351+
let v2Special = Base16.decodeLenient "5822582001000022325333573466e1ccde5251333792945200000100111200116375a005"
352+
H.decodeOnlyPlutusScriptBytes
353+
ShelleyBasedEraConway
354+
PlutusScriptV2
355+
v2Special
356+
(AsScript AsPlutusScriptV2)
357+
H.assertValidPlutusScriptBytesExperimental
358+
Exp.ConwayEra
359+
v2Special
360+
Ledger.SPlutusV2
361+
349362
prop_decode_only_wrapped_plutus_script_V3_CBOR :: Property
350363
prop_decode_only_wrapped_plutus_script_V3_CBOR = H.property $ do
351364
PlutusScriptSerialised shortBs <- H.forAll $ genPlutusScript PlutusScriptV3
@@ -569,6 +582,9 @@ tests =
569582
, testProperty
570583
"decode only wrapped plutus script V2 CBOR"
571584
prop_decode_only_wrapped_plutus_script_V2_CBOR
585+
, testProperty
586+
"decode only wrapped plutus script V2 special CBOR"
587+
prop_decode_only_wrapped_plutus_script_V2_ByteStringToInteger_CBOR
572588
, testProperty
573589
"decode only wrapped plutus script V3 CBOR"
574590
prop_decode_only_wrapped_plutus_script_V3_CBOR

0 commit comments

Comments
 (0)