From e8395ceb7ae8cac36bb30bb6609445d722e5bb49 Mon Sep 17 00:00:00 2001 From: Alexey Kuleshevich Date: Mon, 13 Mar 2023 23:19:34 +0300 Subject: [PATCH] Add `Cardano.Ledger.Api.Governance` to the Api --- eras/conway/impl/CHANGELOG.md | 1 - .../src/Cardano/Ledger/Shelley/Governance.hs | 3 + libs/cardano-ledger-api/CHANGELOG.md | 4 + .../cardano-ledger-api.cabal | 2 + .../src/Cardano/Ledger/Api.hs | 3 + .../src/Cardano/Ledger/Api/Governance.hs | 84 +++++++++++++++++++ 6 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 libs/cardano-ledger-api/src/Cardano/Ledger/Api/Governance.hs diff --git a/eras/conway/impl/CHANGELOG.md b/eras/conway/impl/CHANGELOG.md index d1394648bc2..6b8e039bb4f 100644 --- a/eras/conway/impl/CHANGELOG.md +++ b/eras/conway/impl/CHANGELOG.md @@ -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 diff --git a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Governance.hs b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Governance.hs index 346b880a50f..50591ec0dd0 100644 --- a/eras/shelley/impl/src/Cardano/Ledger/Shelley/Governance.hs +++ b/eras/shelley/impl/src/Cardano/Ledger/Shelley/Governance.hs @@ -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 diff --git a/libs/cardano-ledger-api/CHANGELOG.md b/libs/cardano-ledger-api/CHANGELOG.md index abc52a1f381..d37492935a8 100644 --- a/libs/cardano-ledger-api/CHANGELOG.md +++ b/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 diff --git a/libs/cardano-ledger-api/cardano-ledger-api.cabal b/libs/cardano-ledger-api/cardano-ledger-api.cabal index d7f57a13bbf..be76031852d 100644 --- a/libs/cardano-ledger-api/cardano-ledger-api.cabal +++ b/libs/cardano-ledger-api/cardano-ledger-api.cabal @@ -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 @@ -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, diff --git a/libs/cardano-ledger-api/src/Cardano/Ledger/Api.hs b/libs/cardano-ledger-api/src/Cardano/Ledger/Api.hs index 8f98de86523..e34e7bc6785 100644 --- a/libs/cardano-ledger-api/src/Cardano/Ledger/Api.hs +++ b/libs/cardano-ledger-api/src/Cardano/Ledger/Api.hs @@ -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 diff --git a/libs/cardano-ledger-api/src/Cardano/Ledger/Api/Governance.hs b/libs/cardano-ledger-api/src/Cardano/Ledger/Api/Governance.hs new file mode 100644 index 00000000000..9661a1c45e5 --- /dev/null +++ b/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