Skip to content

Commit 0d54248

Browse files
committed
Implement Enc/DecCBOR for PoolParams explicitly
rather than via `Enc/DecCBORGroup`
1 parent f776625 commit 0d54248

File tree

2 files changed

+43
-42
lines changed

2 files changed

+43
-42
lines changed

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.19.0.0
44

5+
* Remove `DecCBORGroup` and `EncCBORGroup` instances for `PoolParams`
56
* Remove the `UMap` module and the `umap` benchmarks cabal target.
67
* Export `dRepToText`
78
* Deprecated `bheader` and `bbody`

libs/cardano-ledger-core/src/Cardano/Ledger/State/StakePool.hs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE FlexibleContexts #-}
66
{-# LANGUAGE LambdaCase #-}
77
{-# LANGUAGE OverloadedStrings #-}
8+
{-# LANGUAGE RecordWildCards #-}
89
{-# LANGUAGE StandaloneDeriving #-}
910
{-# LANGUAGE TypeApplications #-}
1011
{-# LANGUAGE TypeFamilies #-}
@@ -68,12 +69,9 @@ import Cardano.Ledger.BaseTypes (
6869
strictMaybeToMaybe,
6970
)
7071
import Cardano.Ledger.Binary (
71-
CBORGroup (..),
7272
DecCBOR (..),
73-
DecCBORGroup (..),
7473
DecShareCBOR (..),
7574
EncCBOR (..),
76-
EncCBORGroup (..),
7775
decodeNullMaybe,
7876
decodeRecordNamed,
7977
decodeRecordSum,
@@ -381,8 +379,6 @@ data PoolParams = PoolParams
381379
, ppMetadata :: !(StrictMaybe PoolMetadata)
382380
}
383381
deriving (Show, Generic, Eq, Ord)
384-
deriving (EncCBOR) via CBORGroup PoolParams
385-
deriving (DecCBOR) via CBORGroup PoolParams
386382

387383
ppVrfL :: Lens' PoolParams (VRFVerKeyHash 'StakePoolVRF)
388384
ppVrfL = lens ppVrf (\pp u -> pp {ppVrf = u})
@@ -452,40 +448,44 @@ data SizeOfPoolRelays = SizeOfPoolRelays
452448
instance EncCBOR SizeOfPoolRelays where
453449
encCBOR = error "The `SizeOfPoolRelays` type cannot be encoded!"
454450

455-
instance EncCBORGroup PoolParams where
456-
encCBORGroup poolParams =
457-
encCBOR (ppId poolParams)
458-
<> encCBOR (ppVrf poolParams)
459-
<> encCBOR (ppPledge poolParams)
460-
<> encCBOR (ppCost poolParams)
461-
<> encCBOR (ppMargin poolParams)
462-
<> encCBOR (ppRewardAccount poolParams)
463-
<> encCBOR (ppOwners poolParams)
464-
<> encCBOR (ppRelays poolParams)
465-
<> encodeNullMaybe encCBOR (strictMaybeToMaybe (ppMetadata poolParams))
466-
listLen _ = 9
467-
listLenBound _ = 9
468-
469-
instance DecCBORGroup PoolParams where
470-
decCBORGroup = do
471-
hk <- decCBOR
472-
vrf <- decCBOR
473-
pledge <- decCBOR
474-
cost <- decCBOR
475-
margin <- decCBOR
476-
ra <- decCBOR
477-
owners <- decCBOR
478-
relays <- decCBOR
479-
md <- decodeNullMaybe decCBOR
480-
pure $
481-
PoolParams
482-
{ ppId = hk
483-
, ppVrf = vrf
484-
, ppPledge = pledge
485-
, ppCost = cost
486-
, ppMargin = margin
487-
, ppRewardAccount = ra
488-
, ppOwners = owners
489-
, ppRelays = relays
490-
, ppMetadata = maybeToStrictMaybe md
491-
}
451+
instance EncCBOR PoolParams where
452+
encCBOR PoolParams {..} =
453+
encodeListLen 9
454+
<> encCBOR ppId
455+
<> encCBOR ppVrf
456+
<> encCBOR ppPledge
457+
<> encCBOR ppCost
458+
<> encCBOR ppMargin
459+
<> encCBOR ppRewardAccount
460+
<> encCBOR ppOwners
461+
<> encCBOR ppRelays
462+
<> encodeNullMaybe encCBOR (strictMaybeToMaybe ppMetadata)
463+
464+
instance DecCBOR PoolParams where
465+
decCBOR =
466+
decodeRecordNamed
467+
"CBORGroup"
468+
(const 9)
469+
( do
470+
hk <- decCBOR
471+
vrf <- decCBOR
472+
pledge <- decCBOR
473+
cost <- decCBOR
474+
margin <- decCBOR
475+
ra <- decCBOR
476+
owners <- decCBOR
477+
relays <- decCBOR
478+
md <- decodeNullMaybe decCBOR
479+
pure $
480+
PoolParams
481+
{ ppId = hk
482+
, ppVrf = vrf
483+
, ppPledge = pledge
484+
, ppCost = cost
485+
, ppMargin = margin
486+
, ppRewardAccount = ra
487+
, ppOwners = owners
488+
, ppRelays = relays
489+
, ppMetadata = maybeToStrictMaybe md
490+
}
491+
)

0 commit comments

Comments
 (0)