Skip to content

Commit cb5da85

Browse files
committed
Remove listLenBound from EncCBORGroup class
1 parent 28b57e0 commit cb5da85

File tree

18 files changed

+51
-45
lines changed

18 files changed

+51
-45
lines changed

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/BlockBody/Internal.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ instance Era era => EncCBORGroup (AlonzoBlockBody era) where
177177
BSL.toStrict $
178178
bodyBytes <> witsBytes <> metadataBytes <> invalidBytes
179179
listLen _ = 4
180-
listLenBound _ = 4
181180

182181
hashAlonzoSegWits ::
183182
BSL.ByteString ->

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ instance
336336
EncCBORGroup (AlonzoPlutusPurpose f era)
337337
where
338338
listLen _ = 2
339-
listLenBound _ = 2
340339
encCBORGroup = \case
341340
AlonzoSpending p -> encodeWord8 0 <> encCBOR p
342341
AlonzoMinting p -> encodeWord8 1 <> encCBOR p

eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxWits.hs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
88
{-# LANGUAGE LambdaCase #-}
99
{-# LANGUAGE MultiParamTypeClasses #-}
10-
{-# LANGUAGE NamedFieldPuns #-}
1110
{-# LANGUAGE OverloadedStrings #-}
1211
{-# LANGUAGE PatternSynonyms #-}
1312
{-# LANGUAGE RankNTypes #-}
@@ -126,6 +125,7 @@ import qualified Data.MapExtras as Map (fromElems)
126125
import Data.Maybe (mapMaybe)
127126
import Data.Set (Set)
128127
import qualified Data.Set as Set
128+
import Data.Typeable (Proxy (Proxy))
129129
import GHC.Generics (Generic)
130130
import Lens.Micro
131131
import NoThunks.Class (NoThunks)
@@ -152,8 +152,9 @@ instance AlonzoEraScript era => EncCBOR (RedeemersRaw era) where
152152
(encCBOR rs)
153153
(encodeFoldableEncoder keyValueEncoder $ Map.toAscList rs)
154154
where
155+
keyValueEncoder :: (PlutusPurpose AsIx era, (Data era, ExUnits)) -> Encoding
155156
keyValueEncoder (ptr, (dats, exs)) =
156-
encodeListLen (listLen ptr + 2)
157+
encodeListLen (listLen (Proxy @(PlutusPurpose AsIx era)) + 2)
157158
<> encCBORGroup ptr
158159
<> encCBOR dats
159160
<> encCBOR exs
@@ -556,11 +557,14 @@ instance AlonzoEraScript era => DecCBOR (Annotator (RedeemersRaw era)) where
556557
decodeElement ::
557558
forall s. Decoder s (PlutusPurpose AsIx era, Annotator (Data era), ExUnits)
558559
decodeElement = do
559-
decodeRecordNamed "Redeemer" (\(rdmrPtr, _, _) -> fromIntegral (listLen rdmrPtr) + 2) $ do
560-
!redeemerPtr <- decCBORGroup
561-
!redeemerData <- decCBOR
562-
!redeemerExUnits <- decCBOR
563-
pure (redeemerPtr, redeemerData, redeemerExUnits)
560+
decodeRecordNamed
561+
"Redeemer"
562+
(\(_, _, _) -> fromIntegral (listLen (Proxy @(PlutusPurpose AsIx era))) + 2)
563+
$ do
564+
!redeemerPtr <- decCBORGroup
565+
!redeemerData <- decCBOR
566+
!redeemerExUnits <- decCBOR
567+
pure (redeemerPtr, redeemerData, redeemerExUnits)
564568
{-# INLINE decodeElement #-}
565569
{-# INLINE decCBOR #-}
566570

eras/alonzo/impl/testlib/Test/Cardano/Ledger/Alonzo/Binary/Annotator.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Data.Maybe.Strict (maybeToStrictMaybe)
3737
import qualified Data.Sequence as Seq
3838
import qualified Data.Sequence.Strict as StrictSeq
3939
import qualified Data.Set as Set
40-
import Data.Typeable (Typeable)
40+
import Data.Typeable (Proxy (Proxy), Typeable)
4141
import Lens.Micro
4242
import Test.Cardano.Ledger.Common
4343
import Test.Cardano.Ledger.Mary.Binary.Annotator
@@ -235,11 +235,14 @@ instance AlonzoEraScript era => DecCBOR (RedeemersRaw era) where
235235
{-# INLINE decodeListRedeemers #-}
236236
decodeElement :: Decoder s (PlutusPurpose AsIx era, (Data era, ExUnits))
237237
decodeElement = do
238-
decodeRecordNamed "Redeemer" (\(redeemerPtr, _) -> fromIntegral (listLen redeemerPtr) + 2) $ do
239-
!redeemerPtr <- decCBORGroup
240-
!redeemerData <- decCBOR
241-
!redeemerExUnits <- decCBOR
242-
pure (redeemerPtr, (redeemerData, redeemerExUnits))
238+
decodeRecordNamed
239+
"Redeemer"
240+
(\(_, _) -> fromIntegral (listLen (Proxy @(PlutusPurpose AsIx era))) + 2)
241+
$ do
242+
!redeemerPtr <- decCBORGroup
243+
!redeemerData <- decCBOR
244+
!redeemerExUnits <- decCBOR
245+
pure (redeemerPtr, (redeemerData, redeemerExUnits))
243246
{-# INLINE decodeElement #-}
244247
{-# INLINE decCBOR #-}
245248

eras/conway/impl/src/Cardano/Ledger/Conway/Scripts.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ instance
270270
EncCBORGroup (ConwayPlutusPurpose f era)
271271
where
272272
listLen _ = 2
273-
listLenBound _ = 2
274273
encCBORGroup = \case
275274
ConwaySpending p -> encodeWord8 0 <> encCBOR p
276275
ConwayMinting p -> encodeWord8 1 <> encCBOR p

eras/dijkstra/impl/src/Cardano/Ledger/Dijkstra/Scripts.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ instance
157157
EncCBORGroup (DijkstraPlutusPurpose f era)
158158
where
159159
listLen _ = 2
160-
listLenBound _ = 2
161160
encCBORGroup = \case
162161
DijkstraSpending p -> encodeWord8 0 <> encCBOR p
163162
DijkstraMinting p -> encodeWord8 1 <> encCBOR p

eras/shelley/impl/src/Cardano/Ledger/Shelley/BlockBody/Internal.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ instance Era era => EncCBORGroup (ShelleyBlockBody era) where
198198
BSL.toStrict $
199199
bodyBytes <> witsBytes <> metadataBytes
200200
listLen _ = 3
201-
listLenBound _ = 3
202201

203202
hashShelleySegWits ::
204203
BSL.ByteString ->

eras/shelley/impl/src/Cardano/Ledger/Shelley/TxCert.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ import Data.Map.Strict (Map)
114114
import Data.Maybe (isJust)
115115
import Data.Monoid (Sum (..))
116116
import qualified Data.Set as Set
117+
import Data.Typeable (Proxy (Proxy))
117118
import GHC.Generics (Generic)
118119
import Lens.Micro
119120
import NoThunks.Class (NoThunks (..))
@@ -435,7 +436,7 @@ encodeShelleyDelegCert = \case
435436
encodePoolCert :: PoolCert -> Encoding
436437
encodePoolCert = \case
437438
RegPool poolParams ->
438-
encodeListLen (1 + listLen poolParams)
439+
encodeListLen (1 + listLen (Proxy @StakePoolParams))
439440
<> encodeWord8 3
440441
<> encCBORGroup poolParams
441442
RetirePool vk epoch ->

libs/cardano-ledger-binary/CHANGELOG.md

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

33
## 1.8.0.0
44

5+
* Remove `listLenBound` from `EncCBORGroup`
6+
* Change type of `listLen` in `EncCBORGroup` to accept a `Proxy` instead of a concrete value
57
* Make `decodeAnnSet` fail when there are duplicates, starting with protocol version `12`.
68
* Provide ability for `Annotator` to fail, by changing its type signature to return `Either` and adding `MonadFail` instance.
79
* Remove `encodedSizeExpr` and `encodedListSizeExpr` from `EncCBOR`

libs/cardano-ledger-binary/src/Cardano/Ledger/Binary/Decoding/Coders.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import Data.Maybe.Strict (StrictMaybe (..))
7676
import Data.Set (Set, insert, member)
7777
import qualified Data.Set as Set
7878
import qualified Data.Text as Text
79-
import Data.Typeable (Proxy (..), Typeable, typeOf)
79+
import Data.Typeable (Proxy (Proxy), Typeable, typeOf)
8080
import Data.Void (Void)
8181

8282
-- ====================================================================
@@ -410,7 +410,9 @@ x <! y = ApplyD x y
410410
-- | Infix form of @ApplyAnn@ with the same infixity and precedence as @($)@.
411411
(<*!) ::
412412
(Typeable a, Typeable t) =>
413-
Decode w1 (Annotator (a -> t)) -> Decode ('Closed d) (Annotator a) -> Decode w1 (Annotator t)
413+
Decode w1 (Annotator (a -> t)) ->
414+
Decode ('Closed d) (Annotator a) ->
415+
Decode w1 (Annotator t)
414416
x <*! y = ApplyAnn x y
415417
{-# INLINE (<*!) #-}
416418

@@ -425,7 +427,7 @@ hsize (SumD _) = 0
425427
hsize (RecD _) = 0
426428
hsize (KeyedD _) = 0
427429
hsize From = 1
428-
hsize FromGroup = fromIntegral $ listLenBound $ Proxy @t
430+
hsize FromGroup = fromIntegral $ listLen $ Proxy @t
429431
hsize (D _) = 1
430432
hsize (ApplyD f x) = hsize f + hsize x
431433
hsize (Invalid _) = 0

0 commit comments

Comments
 (0)