Skip to content

Commit

Permalink
Include newest api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Aug 22, 2023
1 parent 763b3e5 commit 1ee1a2e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
8 changes: 4 additions & 4 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.14
, cardano-api ^>= 8.15
, cardano-binary
, cardano-crypto
, cardano-crypto-class ^>= 2.1.2
Expand Down Expand Up @@ -224,8 +224,8 @@ test-suite cardano-cli-test
, base16-bytestring
, bech32 >= 1.1.0
, bytestring
, cardano-api:{cardano-api, internal} ^>= 8.14
, cardano-api-gen ^>= 8.1.1.0
, cardano-api:{cardano-api, internal} ^>= 8.15
, cardano-api-gen ^>= 8.2.0.0
, cardano-cli
, cardano-cli:cardano-cli-test-lib
, cardano-slotting ^>= 0.1
Expand Down Expand Up @@ -268,7 +268,7 @@ test-suite cardano-cli-golden
build-depends: aeson >= 1.5.6.0
, base16-bytestring
, bytestring
, cardano-api:{cardano-api, gen} ^>= 8.14
, cardano-api:{cardano-api, gen} ^>= 8.15
, cardano-binary
, cardano-cli
, cardano-cli:cardano-cli-test-lib
Expand Down
9 changes: 7 additions & 2 deletions cardano-cli/src/Cardano/CLI/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

module Cardano.CLI.Commands.Governance where

import Cardano.Api
import Cardano.Api hiding (Constitution)
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley
import Cardano.Api.Shelley hiding (Constitution)

import Cardano.Binary (DecoderError)
import Cardano.CLI.Legacy.Run.StakeAddress
Expand All @@ -15,6 +15,7 @@ import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Governance
import Cardano.CLI.Types.Key
import Cardano.Prelude (intercalate, toS)
import Ouroboros.Consensus.Cardano.Block (EraMismatch)

import Control.Monad.IO.Class
import Control.Monad.Trans.Except (ExceptT)
Expand Down Expand Up @@ -60,6 +61,10 @@ data GovernanceCmdError
| GovernanceCmdDecoderError !DecoderError
| GovernanceCmdVerifyPollError !GovernancePollError
| GovernanceCmdWriteFileError !(FileError ())
| GovernanceCmdAcqireFailureError !AcquiringFailure
| GovernanceCmdEraConsensusModeMismatch !AnyConsensusMode !AnyCardanoEra
| GovernanceCmdUnsupportedNtcVersion !UnsupportedNtcVersionError
| GovernanceCmdEraMismatch !EraMismatch
-- Legacy - remove me after cardano-cli transitions to new era based structure
| GovernanceCmdMIRCertNotSupportedInConway
| GovernanceCmdGenesisDelegationNotSupportedInConway
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions
, renderGovernanceActionCmds
) where

import Cardano.Api
import Cardano.Api hiding (Constitution)
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley
import Cardano.Api.Shelley hiding (Constitution)

import Cardano.CLI.Types.Common (Constitution, VerificationKeyFile)
import Cardano.CLI.Types.Key
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

module Cardano.CLI.EraBased.Options.Common where

import Cardano.Api
import Cardano.Api hiding (Constitution)
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley
import Cardano.Api.Shelley hiding (Constitution)

import Cardano.CLI.Environment (EnvCli (..), envCliAnyShelleyBasedEra,
envCliAnyShelleyToBabbageEra)
Expand Down
37 changes: 36 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Cardano.CLI.EraBased.Run.Governance
( runGovernanceMIRCertificatePayStakeAddrs
Expand All @@ -15,10 +20,12 @@ import Cardano.CLI.Types.Common
import qualified Cardano.Ledger.Shelley.TxBody as Shelley

import Control.Monad

import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Function
import qualified Data.Map.Strict as Map

runGovernanceMIRCertificatePayStakeAddrs
Expand Down Expand Up @@ -91,3 +98,31 @@ runGovernanceDRepKeyGen _w vkeyPath skeyPath = firstExceptT GovernanceCmdWriteFi
skeyDesc = "Delegate Representative Signing Key"
vkeyDesc :: TextEnvelopeDescr
vkeyDesc = "Delegate Representative Verification Key"

runGovernanceQueryGovState
:: ConwayEraOnwards era
-> SocketPath
-> AnyConsensusModeParams
-> NetworkId
-> Maybe (File () Out)
-> ExceptT GovernanceCmdError IO ()
runGovernanceQueryGovState w socketPath (AnyConsensusModeParams cModeParams) network mFile = conwayEraOnwardsConstraints w $ do
let localNodeConnInfo = LocalNodeConnectInfo cModeParams network socketPath
sbe = conwayEraOnwardsToShelleyBasedEra w
cEra = conwayEraOnwardsToCardanoEra w
cMode = consensusModeOnly cModeParams

eraInMode <- toEraInMode cEra cMode
& hoistMaybe (GovernanceCmdEraConsensusModeMismatch (AnyConsensusMode cMode) (AnyCardanoEra cEra))

govState <- firstExceptT GovernanceCmdAcqireFailureError
( newExceptT $ executeLocalStateQueryExpr localNodeConnInfo Nothing $ queryGovState eraInMode sbe)
& onLeft (left . GovernanceCmdUnsupportedNtcVersion)
& onLeft (left . GovernanceCmdEraMismatch)
let serializedGovState = encodePretty govState

case mFile of
Nothing -> liftIO $ LBS.putStrLn serializedGovState
Just (File f) ->
handleIOExceptT (WriteFileError . FileIOError f) $
LBS.writeFile f serializedGovState
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Types/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module Cardano.CLI.Types.Common
, WitnessSigningData(..)
) where

import Cardano.Api
import Cardano.Api hiding (Constitution)
import qualified Cardano.Api.Ledger as Ledger

import qualified Cardano.Chain.Slotting as Byron
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/Types/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

module Cardano.CLI.Types.Governance where

import Cardano.Api
import Cardano.Api hiding (Constitution)
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley
import Cardano.Api.Shelley hiding (Constitution)

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key (VerificationKeyOrFile, VerificationKeyOrHashOrFile)
Expand Down

0 comments on commit 1ee1a2e

Please sign in to comment.