Skip to content

Commit

Permalink
Add Cardano.Ledger.Api.Governance to the Api
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins authored and TimSheard committed Mar 21, 2023
1 parent 39bd9c2 commit e8395ce
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
1 change: 0 additions & 1 deletion eras/conway/impl/CHANGELOG.md
Expand Up @@ -21,7 +21,6 @@
* `GovernanceActionIx`
* `GovernanceActionId`
* Add `ToJSONKey` instance for `GovernanceActionId` #3323
* Reinstate `Vote` type #3326
* Fix `EncCBOR`/`DecCBOR` and `ToCBOR`/`FromCBOR` for `ConwayTallyState` #3323
* Add `Anchor` and `AnchorDataHash` types. #3323

Expand Down
3 changes: 3 additions & 0 deletions eras/shelley/impl/src/Cardano/Ledger/Shelley/Governance.hs
Expand Up @@ -48,9 +48,12 @@ class
where
type GovernanceState era = (r :: Type) | r -> era

-- | Construct empty governance state
emptyGovernanceState :: GovernanceState era
emptyGovernanceState = def

-- | Returns `Nothing` for all eras starting with Conway, otherwise returns proposed
-- pparams updates
getProposedPPUpdates :: GovernanceState era -> Maybe (ProposedPPUpdates era)
getProposedPPUpdates _ = Nothing

Expand Down
4 changes: 4 additions & 0 deletions libs/cardano-ledger-api/CHANGELOG.md
@@ -1,5 +1,9 @@
# Version history for `cardano-ledger-api`

## 1.0.1.0

* Add `Cardano.Ledger.Api.Governance` that exposes all of the governance related types.

## 1.0.0.0

* Initial release
2 changes: 2 additions & 0 deletions libs/cardano-ledger-api/cardano-ledger-api.cabal
Expand Up @@ -23,6 +23,7 @@ library
exposed-modules:
Cardano.Ledger.Api
Cardano.Ledger.Api.Era
Cardano.Ledger.Api.Governance
Cardano.Ledger.Api.PParams
Cardano.Ledger.Api.Scripts
Cardano.Ledger.Api.Scripts.Data
Expand All @@ -42,6 +43,7 @@ library

build-depends:
base >=4.14 && <4.17,
bytestring,
cardano-ledger-allegra >=1.1,
cardano-ledger-alonzo >=1.1,
cardano-ledger-babbage >=1.1,
Expand Down
3 changes: 3 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api.hs
Expand Up @@ -17,10 +17,13 @@ module Cardano.Ledger.Api (
module Cardano.Ledger.Api.PParams,
-- | Scripts
module Cardano.Ledger.Api.Scripts,
-- | Governance
module Cardano.Ledger.Api.Governance,
)
where

import Cardano.Ledger.Api.Era
import Cardano.Ledger.Api.Governance
import Cardano.Ledger.Api.PParams
import Cardano.Ledger.Api.Scripts
import Cardano.Ledger.Api.Tx
84 changes: 84 additions & 0 deletions libs/cardano-ledger-api/src/Cardano/Ledger/Api/Governance.hs
@@ -0,0 +1,84 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}

module Cardano.Ledger.Api.Governance (
EraGovernance (GovernanceState),
emptyGovernanceState,
getProposedPPUpdates,

-- * Shelley
ShelleyPPUPState (..),
ProposedPPUpdates (..),
emptyPPPUpdates,

-- * Conway

-- ** Conway Governance
ConwayGovernance (..),
cgRatifyL,
cgTallyL,
cgVoterRolesL,
ConwayTallyState (..),
RatifyState (..),
EnactState (..),
VoterRole (..),

-- ** Governance Action
GovernanceAction (..),
GovernanceActionId (..),
GovernanceActionIx (..),
GovernanceActionState (..),

-- ** Vote
Vote (..),
VoteDecision (..),

-- *** Anchor
Anchor (..),
AnchorData (..),
AnchorDataHash,
hashAnchorData,
) where

import Cardano.Ledger.Api.Era ()
import Cardano.Ledger.Conway.Governance (
Anchor (..),
AnchorDataHash,
ConwayGovernance (..),
ConwayTallyState (..),
EnactState (..),
GovernanceAction (..),
GovernanceActionId (..),
GovernanceActionIx (..),
GovernanceActionState (..),
RatifyState (..),
Vote (..),
VoteDecision (..),
VoterRole (..),
-- Lenses

cgRatifyL,
cgTallyL,
cgVoterRolesL,
)
import Cardano.Ledger.Crypto (Crypto)
import Cardano.Ledger.SafeHash (HashAnnotated, SafeHash, SafeToHash, hashAnnotated)
import Cardano.Ledger.Shelley.Governance (
EraGovernance (GovernanceState),
ShelleyPPUPState (..),
emptyGovernanceState,
getProposedPPUpdates,
)
import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates (..), emptyPPPUpdates)
import Data.ByteString (ByteString)

newtype AnchorData c = AnchorData ByteString
deriving (Eq, SafeToHash)

instance HashAnnotated (AnchorData c) AnchorDataHash c

-- | Hash `AnchorData`
hashAnchorData :: Crypto c => AnchorData c -> SafeHash c AnchorDataHash
hashAnchorData = hashAnnotated

0 comments on commit e8395ce

Please sign in to comment.