|
5 | 5 | {-# LANGUAGE FlexibleContexts #-} |
6 | 6 | {-# LANGUAGE LambdaCase #-} |
7 | 7 | {-# LANGUAGE OverloadedStrings #-} |
| 8 | +{-# LANGUAGE RecordWildCards #-} |
8 | 9 | {-# LANGUAGE StandaloneDeriving #-} |
9 | 10 | {-# LANGUAGE TypeApplications #-} |
10 | 11 | {-# LANGUAGE TypeFamilies #-} |
|
26 | 27 | module Cardano.Ledger.State.StakePool ( |
27 | 28 | -- * Stake Pool State |
28 | 29 | StakePoolState (..), |
| 30 | + poolParamsCount, |
29 | 31 |
|
30 | 32 | -- * Lenses |
31 | 33 | spsVrfL, |
@@ -68,12 +70,9 @@ import Cardano.Ledger.BaseTypes ( |
68 | 70 | strictMaybeToMaybe, |
69 | 71 | ) |
70 | 72 | import Cardano.Ledger.Binary ( |
71 | | - CBORGroup (..), |
72 | 73 | DecCBOR (..), |
73 | | - DecCBORGroup (..), |
74 | 74 | DecShareCBOR (..), |
75 | 75 | EncCBOR (..), |
76 | | - EncCBORGroup (..), |
77 | 76 | decodeNullMaybe, |
78 | 77 | decodeRecordNamed, |
79 | 78 | decodeRecordSum, |
@@ -381,8 +380,6 @@ data PoolParams = PoolParams |
381 | 380 | , ppMetadata :: !(StrictMaybe PoolMetadata) |
382 | 381 | } |
383 | 382 | deriving (Show, Generic, Eq, Ord) |
384 | | - deriving (EncCBOR) via CBORGroup PoolParams |
385 | | - deriving (DecCBOR) via CBORGroup PoolParams |
386 | 383 |
|
387 | 384 | ppVrfL :: Lens' PoolParams (VRFVerKeyHash 'StakePoolVRF) |
388 | 385 | ppVrfL = lens ppVrf (\pp u -> pp {ppVrf = u}) |
@@ -452,40 +449,47 @@ data SizeOfPoolRelays = SizeOfPoolRelays |
452 | 449 | instance EncCBOR SizeOfPoolRelays where |
453 | 450 | encCBOR = error "The `SizeOfPoolRelays` type cannot be encoded!" |
454 | 451 |
|
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 | | - } |
| 452 | +poolParamsCount :: Word |
| 453 | +poolParamsCount = 9 |
| 454 | + |
| 455 | +instance EncCBOR PoolParams where |
| 456 | + encCBOR PoolParams {..} = |
| 457 | + encodeListLen poolParamsCount |
| 458 | + <> encCBOR ppId |
| 459 | + <> encCBOR ppVrf |
| 460 | + <> encCBOR ppPledge |
| 461 | + <> encCBOR ppCost |
| 462 | + <> encCBOR ppMargin |
| 463 | + <> encCBOR ppRewardAccount |
| 464 | + <> encCBOR ppOwners |
| 465 | + <> encCBOR ppRelays |
| 466 | + <> encodeNullMaybe encCBOR (strictMaybeToMaybe ppMetadata) |
| 467 | + |
| 468 | +instance DecCBOR PoolParams where |
| 469 | + decCBOR = |
| 470 | + decodeRecordNamed |
| 471 | + "CBORGroup" |
| 472 | + (const (fromIntegral poolParamsCount)) |
| 473 | + ( do |
| 474 | + hk <- decCBOR |
| 475 | + vrf <- decCBOR |
| 476 | + pledge <- decCBOR |
| 477 | + cost <- decCBOR |
| 478 | + margin <- decCBOR |
| 479 | + ra <- decCBOR |
| 480 | + owners <- decCBOR |
| 481 | + relays <- decCBOR |
| 482 | + md <- decodeNullMaybe decCBOR |
| 483 | + pure $ |
| 484 | + PoolParams |
| 485 | + { ppId = hk |
| 486 | + , ppVrf = vrf |
| 487 | + , ppPledge = pledge |
| 488 | + , ppCost = cost |
| 489 | + , ppMargin = margin |
| 490 | + , ppRewardAccount = ra |
| 491 | + , ppOwners = owners |
| 492 | + , ppRelays = relays |
| 493 | + , ppMetadata = maybeToStrictMaybe md |
| 494 | + } |
| 495 | + ) |
0 commit comments