Skip to content

Commit 193bf38

Browse files
committed
Remove listLenBound from EncCBORGroup class
1 parent c20fece commit 193bf38

File tree

19 files changed

+41
-35
lines changed

19 files changed

+41
-35
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
* 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)