Skip to content

Commit

Permalink
Add CBOR instances for DefaultVote
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Jan 31, 2025
1 parent 4b2721c commit e59a601
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions eras/conway/impl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.19.0.0

* Added `ToCBOR` and `FromCBOR` instances for `DefaultVote`.
* Made the fields of predicate failures and environments lazy
* Add `MemPack` instance for `PlutusScript ConwayEra`
* Deprecate `Conway` type synonym
Expand Down
21 changes: 21 additions & 0 deletions eras/conway/impl/src/Cardano/Ledger/Conway/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ import Cardano.Ledger.Binary.Coders (
(!>),
(<!),
)
import Cardano.Ledger.Binary.Plain (
decodeWord8,
encodeWord8,
)
import Cardano.Ledger.CertState (
CommitteeAuthorization (..),
Obligations (..),
Expand Down Expand Up @@ -541,6 +545,23 @@ data DefaultVote
DefaultNoConfidence
deriving (Eq, Show)

instance FromCBOR DefaultVote where
fromCBOR = do
tag <- decodeWord8
case tag of
0 -> pure DefaultNo
1 -> pure DefaultAbstain
2 -> pure DefaultNoConfidence
_ -> fail $ "Invalid DefaultVote tag " ++ show tag

instance ToCBOR DefaultVote where
toCBOR DefaultNo = encodeWord8 0
toCBOR DefaultAbstain = encodeWord8 1
toCBOR DefaultNoConfidence = encodeWord8 2

instance EncCBOR DefaultVote
instance DecCBOR DefaultVote

defaultStakePoolVote ::
-- | Specify the key hash of the pool whose default vote should be returned.
KeyHash 'StakePool ->
Expand Down

0 comments on commit e59a601

Please sign in to comment.