Skip to content

Commit

Permalink
Merge pull request #322 from input-output-hk/jordan/parameterize-gove…
Browse files Browse the repository at this point in the history
…rnance-actions

Parameterize GovernanceAction on era
  • Loading branch information
newhoggy authored Oct 18, 2023
2 parents 7e54356 + 0145c48 commit bb08052
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2023-09-21"
CABAL_CACHE_VERSION: "2023-10-17"

concurrency:
group: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Cardano.Api.Eras.Constraints
import Cardano.Api.HasTypeProxy
import Cardano.Api.Keys.Shelley
import Cardano.Api.ProtocolParameters
import qualified Cardano.Api.ReexposeLedger as Ledger
import Cardano.Api.SerialiseCBOR
import Cardano.Api.SerialiseTextEnvelope
import Cardano.Api.TxIn
Expand Down Expand Up @@ -45,7 +46,7 @@ import Data.Word
data AnyGovernanceAction = forall era. AnyGovernanceAction (Gov.GovAction era)

-- TODO: Conway - Transitiion to Ledger.GovAction
data GovernanceAction
data GovernanceAction era
= MotionOfNoConfidence
(StrictMaybe (Ledger.PrevGovActionId Ledger.CommitteePurpose StandardCrypto))
| ProposeNewConstitution
Expand All @@ -63,13 +64,11 @@ data GovernanceAction
ProtVer
| UpdatePParams
(StrictMaybe (Ledger.PrevGovActionId Ledger.PParamUpdatePurpose StandardCrypto))
ProtocolParametersUpdate
deriving (Eq, Show)

(Ledger.PParamsUpdate (ShelleyLedgerEra era))

toGovernanceAction :: ()
=> ShelleyBasedEra era
-> GovernanceAction
-> GovernanceAction era
-> Gov.GovAction (ShelleyLedgerEra era)
toGovernanceAction sbe =
shelleyBasedEraConstraints sbe $ \case
Expand Down Expand Up @@ -98,22 +97,19 @@ toGovernanceAction sbe =
InitiateHardfork prevGovId pVer ->
Gov.HardForkInitiation prevGovId pVer
UpdatePParams preGovId ppup ->
case toLedgerPParamsUpdate sbe ppup of
Left e -> error $ "toGovernanceAction: " <> show e
Right ppup' -> Gov.ParameterChange preGovId ppup'
Gov.ParameterChange preGovId ppup

fromGovernanceAction
:: EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto
=> ShelleyBasedEra era
-> Gov.GovAction (ShelleyLedgerEra era)
-> GovernanceAction
fromGovernanceAction sbe = \case
=> Gov.GovAction (ShelleyLedgerEra era)
-> GovernanceAction era
fromGovernanceAction = \case
Gov.NoConfidence prevGovId ->
MotionOfNoConfidence prevGovId
Gov.NewConstitution prevGovId constitution ->
ProposeNewConstitution prevGovId $ Gov.constitutionAnchor constitution
Gov.ParameterChange prevGovId pparams ->
UpdatePParams prevGovId $ fromLedgerPParamsUpdate sbe pparams
UpdatePParams prevGovId pparams
Gov.HardForkInitiation prevGovId pVer ->
InitiateHardfork prevGovId pVer
Gov.TreasuryWithdrawals withdrawlMap ->
Expand Down Expand Up @@ -163,7 +159,7 @@ createProposalProcedure
-> Network
-> Lovelace -- ^ Deposit
-> Hash StakeKey -- ^ Return address
-> GovernanceAction
-> GovernanceAction era
-> Ledger.Anchor StandardCrypto
-> Proposal era
createProposalProcedure sbe nw dep (StakeKeyHash retAddrh) govAct anchor =
Expand All @@ -178,15 +174,15 @@ createProposalProcedure sbe nw dep (StakeKeyHash retAddrh) govAct anchor =
fromProposalProcedure
:: ShelleyBasedEra era
-> Proposal era
-> (Lovelace, Hash StakeKey, GovernanceAction)
-> (Lovelace, Hash StakeKey, GovernanceAction era)
fromProposalProcedure sbe (Proposal pp) =
shelleyBasedEraConstraints sbe
( fromShelleyLovelace $ Gov.pProcDeposit pp
, case fromShelleyStakeCredential (L.getRwdCred (Gov.pProcReturnAddr pp)) of
StakeCredentialByKey keyhash -> keyhash
StakeCredentialByScript _scripthash ->
error "fromProposalProcedure TODO: Conway era script reward addresses not yet supported"
, fromGovernanceAction sbe (Gov.pProcGovAction pp)
, fromGovernanceAction (Gov.pProcGovAction pp)
)


Expand Down
3 changes: 2 additions & 1 deletion cardano-api/internal/Cardano/Api/ReexposeLedger.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Cardano.Api.ReexposeLedger
, Network(..)
, PoolCert(..)
, PParams(..)
, PParamsUpdate
, addDeltaCoin
, toDeltaCoin
, toEraCBOR
Expand Down Expand Up @@ -102,7 +103,7 @@ module Cardano.Api.ReexposeLedger
) where

import Cardano.Crypto.Hash.Class (hashFromBytes, hashToBytes)
import Cardano.Ledger.Alonzo.Core (CoinPerWord (..))
import Cardano.Ledger.Alonzo.Core (CoinPerWord (..), PParamsUpdate (..))
import Cardano.Ledger.Alonzo.Scripts (Prices (..))
import Cardano.Ledger.Api.Tx.Cert (pattern AuthCommitteeHotKeyTxCert,
pattern DelegStakeTxCert, pattern DelegTxCert, pattern GenesisDelegTxCert,
Expand Down

0 comments on commit bb08052

Please sign in to comment.