Skip to content

Commit 1d87e5a

Browse files
committed
Move Vote to core BaseTypes
1 parent 87f061a commit 1d87e5a

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

eras/conway/impl/src/Cardano/Ledger/Conway/Governance/Procedures.hs

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import Cardano.Ledger.BaseTypes (
9090
ProtVer,
9191
ToKeyValuePairs (..),
9292
UnitInterval,
93+
Vote (..),
9394
maybeToStrictMaybe,
9495
)
9596
import Cardano.Ledger.Binary (
@@ -100,12 +101,10 @@ import Cardano.Ledger.Binary (
100101
Interns,
101102
ToCBOR (toCBOR),
102103
decNoShareCBOR,
103-
decodeEnumBounded,
104104
decodeMapByKey,
105105
decodeNullStrictMaybe,
106106
decodeRecordNamed,
107107
decodeRecordNamedT,
108-
encodeEnum,
109108
encodeListLen,
110109
encodeNullStrictMaybe,
111110
encodeWord8,
@@ -373,24 +372,6 @@ instance NoThunks Voter
373372

374373
instance NFData Voter
375374

376-
data Vote
377-
= VoteNo
378-
| VoteYes
379-
| Abstain
380-
deriving (Ord, Generic, Eq, Show, Enum, Bounded)
381-
382-
instance ToJSON Vote
383-
384-
instance NoThunks Vote
385-
386-
instance NFData Vote
387-
388-
instance DecCBOR Vote where
389-
decCBOR = decodeEnumBounded
390-
391-
instance EncCBOR Vote where
392-
encCBOR = encodeEnum
393-
394375
newtype VotingProcedures era = VotingProcedures
395376
{ unVotingProcedures :: Map Voter (Map GovActionId (VotingProcedure era))
396377
}

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/Arbitrary.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,10 +562,6 @@ instance Arbitrary Voter where
562562
]
563563
shrink = genericShrink
564564

565-
instance Arbitrary Vote where
566-
arbitrary = arbitraryBoundedEnum
567-
shrink = shrinkBoundedEnum
568-
569565
instance Arbitrary (TxBody ConwayEra) where
570566
arbitrary =
571567
ConwayTxBody

eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/TreeDiff.hs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ instance ToExpr (PParamsHKD StrictMaybe era) => ToExpr (GovActionState era)
7171

7272
instance ToExpr Voter
7373

74-
instance ToExpr Vote
75-
7674
instance Era era => ToExpr (VotingProcedures era)
7775

7876
instance ToExpr (VotingProcedure era)

libs/cardano-ledger-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## 1.19.0.0
44

5+
* Add `FromJSON` instance to `Vote`
6+
* Move `Vote` to `BaseTypes` module
57
* Add `poolParamsCount`, `decCBORGroupPoolParams`, `encCBORGroupPoolParams` to `StakePool` module
68
* Remove `DecCBORGroup` and `EncCBORGroup` instances for `PoolParams`
79
* Remove the `UMap` module and the `umap` benchmarks cabal target.

libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes.hs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ module Cardano.Ledger.BaseTypes (
5757
module Data.Maybe.Strict,
5858
BlocksMade (..),
5959
kindObject,
60+
Vote (..),
6061

6162
-- * Indices
6263
TxIx (..),
@@ -106,6 +107,8 @@ import Cardano.Ledger.Binary (
106107
FromCBOR,
107108
ToCBOR,
108109
cborError,
110+
decodeEnumBounded,
111+
encodeEnum,
109112
ifDecoderVersionAtLeast,
110113
)
111114
import Cardano.Ledger.Binary.Coders (
@@ -970,3 +973,23 @@ newtype KeyValuePairs a = KeyValuePairs {unKeyValuePairs :: a}
970973
instance ToKeyValuePairs a => ToJSON (KeyValuePairs a) where
971974
toJSON = object . toKeyValuePairs . unKeyValuePairs
972975
toEncoding = pairs . mconcat . toKeyValuePairs . unKeyValuePairs
976+
977+
data Vote
978+
= VoteNo
979+
| VoteYes
980+
| Abstain
981+
deriving (Ord, Generic, Eq, Show, Enum, Bounded)
982+
983+
instance ToJSON Vote
984+
985+
instance FromJSON Vote
986+
987+
instance NoThunks Vote
988+
989+
instance NFData Vote
990+
991+
instance DecCBOR Vote where
992+
decCBOR = decodeEnumBounded
993+
994+
instance EncCBOR Vote where
995+
encCBOR = encodeEnum

libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/Core/Arbitrary.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,10 @@ deriving instance (Era era, Arbitrary (PParamsHKD Identity era)) => Arbitrary (P
517517

518518
deriving instance (Era era, Arbitrary (PParamsHKD StrictMaybe era)) => Arbitrary (PParamsUpdate era)
519519

520+
instance Arbitrary BaseTypes.Vote where
521+
arbitrary = arbitraryBoundedEnum
522+
shrink = shrinkBoundedEnum
523+
520524
------------------------------------------------------------------------------------------
521525
-- Cardano.Ledger.DRep -------------------------------------------------------------------
522526
------------------------------------------------------------------------------------------

libs/cardano-ledger-core/testlib/Test/Cardano/Ledger/TreeDiff.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ instance ToExpr TxId
179179

180180
instance ToExpr ChainAccountState
181181

182+
instance ToExpr Vote
183+
182184
-- CertState
183185
instance ToExpr DRep
184186

0 commit comments

Comments
 (0)