|
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 | + decCBORGroupPoolParams, |
| 31 | + encCBORGroupPoolParams, |
| 32 | + poolParamsCount, |
29 | 33 |
|
30 | 34 | -- * Lenses |
31 | 35 | spsVrfL, |
@@ -68,12 +72,11 @@ import Cardano.Ledger.BaseTypes ( |
68 | 72 | strictMaybeToMaybe, |
69 | 73 | ) |
70 | 74 | import Cardano.Ledger.Binary ( |
71 | | - CBORGroup (..), |
72 | 75 | DecCBOR (..), |
73 | | - DecCBORGroup (..), |
74 | 76 | DecShareCBOR (..), |
| 77 | + Decoder, |
75 | 78 | EncCBOR (..), |
76 | | - EncCBORGroup (..), |
| 79 | + Encoding, |
77 | 80 | decodeNullMaybe, |
78 | 81 | decodeRecordNamed, |
79 | 82 | decodeRecordSum, |
@@ -381,8 +384,6 @@ data PoolParams = PoolParams |
381 | 384 | , ppMetadata :: !(StrictMaybe PoolMetadata) |
382 | 385 | } |
383 | 386 | deriving (Show, Generic, Eq, Ord) |
384 | | - deriving (EncCBOR) via CBORGroup PoolParams |
385 | | - deriving (DecCBOR) via CBORGroup PoolParams |
386 | 387 |
|
387 | 388 | ppVrfL :: Lens' PoolParams (VRFVerKeyHash 'StakePoolVRF) |
388 | 389 | ppVrfL = lens ppVrf (\pp u -> pp {ppVrf = u}) |
@@ -452,40 +453,53 @@ data SizeOfPoolRelays = SizeOfPoolRelays |
452 | 453 | instance EncCBOR SizeOfPoolRelays where |
453 | 454 | encCBOR = error "The `SizeOfPoolRelays` type cannot be encoded!" |
454 | 455 |
|
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 | | - } |
| 456 | +instance EncCBOR PoolParams where |
| 457 | + encCBOR poolParams = |
| 458 | + encodeListLen poolParamsCount |
| 459 | + <> encCBORGroupPoolParams poolParams |
| 460 | + |
| 461 | +instance DecCBOR PoolParams where |
| 462 | + decCBOR = |
| 463 | + decodeRecordNamed |
| 464 | + "CBORGroup" |
| 465 | + (const (fromIntegral poolParamsCount)) |
| 466 | + decCBORGroupPoolParams |
| 467 | + |
| 468 | +poolParamsCount :: Word |
| 469 | +poolParamsCount = 9 |
| 470 | + |
| 471 | +encCBORGroupPoolParams :: PoolParams -> Encoding |
| 472 | +encCBORGroupPoolParams PoolParams {..} = |
| 473 | + encCBOR ppId |
| 474 | + <> encCBOR ppVrf |
| 475 | + <> encCBOR ppPledge |
| 476 | + <> encCBOR ppCost |
| 477 | + <> encCBOR ppMargin |
| 478 | + <> encCBOR ppRewardAccount |
| 479 | + <> encCBOR ppOwners |
| 480 | + <> encCBOR ppRelays |
| 481 | + <> encodeNullMaybe encCBOR (strictMaybeToMaybe ppMetadata) |
| 482 | + |
| 483 | +decCBORGroupPoolParams :: Decoder s PoolParams |
| 484 | +decCBORGroupPoolParams = do |
| 485 | + hk <- decCBOR |
| 486 | + vrf <- decCBOR |
| 487 | + pledge <- decCBOR |
| 488 | + cost <- decCBOR |
| 489 | + margin <- decCBOR |
| 490 | + ra <- decCBOR |
| 491 | + owners <- decCBOR |
| 492 | + relays <- decCBOR |
| 493 | + md <- decodeNullMaybe decCBOR |
| 494 | + pure $ |
| 495 | + PoolParams |
| 496 | + { ppId = hk |
| 497 | + , ppVrf = vrf |
| 498 | + , ppPledge = pledge |
| 499 | + , ppCost = cost |
| 500 | + , ppMargin = margin |
| 501 | + , ppRewardAccount = ra |
| 502 | + , ppOwners = owners |
| 503 | + , ppRelays = relays |
| 504 | + , ppMetadata = maybeToStrictMaybe md |
| 505 | + } |
0 commit comments