Skip to content

Commit f6d8f4c

Browse files
committed
Remove listLenBound from EncCBORGroup class
1 parent 294247f commit f6d8f4c

File tree

19 files changed

+38
-34
lines changed

19 files changed

+38
-34
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: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE BlockArguments #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE DeriveGeneric #-}
45
{-# LANGUAGE DerivingVia #-}
@@ -7,7 +8,6 @@
78
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
89
{-# LANGUAGE LambdaCase #-}
910
{-# LANGUAGE MultiParamTypeClasses #-}
10-
{-# LANGUAGE NamedFieldPuns #-}
1111
{-# LANGUAGE OverloadedStrings #-}
1212
{-# LANGUAGE PatternSynonyms #-}
1313
{-# LANGUAGE RankNTypes #-}
@@ -85,6 +85,7 @@ import Cardano.Ledger.Binary (
8585
encodeTag,
8686
ifDecoderVersionAtLeast,
8787
ifEncodingVersionAtLeast,
88+
listLenInt,
8889
natVersion,
8990
peekTokenType,
9091
setTag,
@@ -152,8 +153,9 @@ instance AlonzoEraScript era => EncCBOR (RedeemersRaw era) where
152153
(encCBOR rs)
153154
(encodeFoldableEncoder keyValueEncoder $ Map.toAscList rs)
154155
where
156+
keyValueEncoder :: (PlutusPurpose AsIx era, (Data era, ExUnits)) -> Encoding
155157
keyValueEncoder (ptr, (dats, exs)) =
156-
encodeListLen (listLen ptr + 2)
158+
encodeListLen (listLen (toProxy ptr) + 2)
157159
<> encCBORGroup ptr
158160
<> encCBOR dats
159161
<> encCBOR exs
@@ -556,7 +558,8 @@ instance AlonzoEraScript era => DecCBOR (Annotator (RedeemersRaw era)) where
556558
decodeElement ::
557559
forall s. Decoder s (PlutusPurpose AsIx era, Annotator (Data era), ExUnits)
558560
decodeElement = do
559-
decodeRecordNamed "Redeemer" (\(rdmrPtr, _, _) -> fromIntegral (listLen rdmrPtr) + 2) $ do
561+
let redeemerLen (redeemerPtr, _, _) = listLenInt redeemerPtr + 2
562+
decodeRecordNamed "Redeemer" redeemerLen do
560563
!redeemerPtr <- decCBORGroup
561564
!redeemerData <- decCBOR
562565
!redeemerExUnits <- decCBOR

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE BangPatterns #-}
2+
{-# LANGUAGE BlockArguments #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE DerivingVia #-}
45
{-# LANGUAGE FlexibleContexts #-}
@@ -235,7 +236,8 @@ instance AlonzoEraScript era => DecCBOR (RedeemersRaw era) where
235236
{-# INLINE decodeListRedeemers #-}
236237
decodeElement :: Decoder s (PlutusPurpose AsIx era, (Data era, ExUnits))
237238
decodeElement = do
238-
decodeRecordNamed "Redeemer" (\(redeemerPtr, _) -> fromIntegral (listLen redeemerPtr) + 2) $ do
239+
let redeemerLen (redeemerPtr, _) = listLenInt redeemerPtr + 2
240+
decodeRecordNamed "Redeemer" redeemerLen do
239241
!redeemerPtr <- decCBORGroup
240242
!redeemerData <- decCBOR
241243
!redeemerExUnits <- decCBOR

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ encodeShelleyDelegCert = \case
435435
encodePoolCert :: PoolCert -> Encoding
436436
encodePoolCert = \case
437437
RegPool poolParams ->
438-
encodeListLen (1 + listLen poolParams)
438+
encodeListLen (1 + listLen (toProxy poolParams))
439439
<> encodeWord8 3
440440
<> encCBORGroup poolParams
441441
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
* Change `Density` type to only be available at the type level
68
* Change `Wrapped` type to only be available at the type level
79
* Make `decodeAnnSet` fail when there are duplicates, starting with protocol version `12`.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ import Data.Maybe.Strict (StrictMaybe (..))
7777
import Data.Set (Set, insert, member)
7878
import qualified Data.Set as Set
7979
import qualified Data.Text as Text
80-
import Data.Typeable (Proxy (..), Typeable, typeOf)
80+
import Data.Typeable (Proxy (Proxy), Typeable, typeOf)
8181
import Data.Void (Void)
8282

8383
-- ====================================================================
@@ -426,7 +426,7 @@ hsize (SumD _) = 0
426426
hsize (RecD _) = 0
427427
hsize (KeyedD _) = 0
428428
hsize From = 1
429-
hsize FromGroup = fromIntegral $ listLenBound $ Proxy @t
429+
hsize FromGroup = fromIntegral $ listLen $ Proxy @t
430430
hsize (D _) = 1
431431
hsize (ApplyD f x) = hsize f + hsize x
432432
hsize (Invalid _) = 0

0 commit comments

Comments
 (0)