Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump CHaP index in preparation for 8.3.0 pre #174

Merged
merged 6 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2023-08-08T19:56:09Z
, cardano-haskell-packages 2023-08-15T15:38:21Z
, cardano-haskell-packages 2023-08-23T09:29:34Z

packages:
cardano-cli
Expand Down Expand Up @@ -43,3 +43,4 @@ write-ghc-environment-files: always
-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.

12 changes: 6 additions & 6 deletions cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.14
, cardano-api ^>= 8.16
, cardano-binary
, cardano-crypto
, cardano-crypto-class >= 2.1.1
, cardano-crypto-class ^>= 2.1.2
, cardano-crypto-wrapper ^>= 1.5
, cardano-data >= 1.0
, cardano-git-rev
Expand Down Expand Up @@ -200,7 +200,7 @@ library
, network
, optparse-applicative-fork
, ouroboros-consensus >= 0.9
, ouroboros-consensus-cardano >= 0.7
, ouroboros-consensus-cardano >= 0.8
, ouroboros-consensus-protocol >= 0.5.0.4
, ouroboros-network-api
, ouroboros-network-protocols
Expand All @@ -226,7 +226,7 @@ executable cardano-cli
ghc-options: -threaded -rtsopts "-with-rtsopts=-T"

build-depends: cardano-cli
, cardano-crypto-class ^>= 2.1
, cardano-crypto-class ^>= 2.1.2
, optparse-applicative-fork
, transformers-except

Expand Down Expand Up @@ -258,7 +258,7 @@ test-suite cardano-cli-test
, base16-bytestring
, bech32 >= 1.1.0
, bytestring
, cardano-api:{cardano-api, internal} ^>= 8.14
, cardano-api:{cardano-api, internal} ^>= 8.16
, cardano-api-gen ^>= 8.1.1.0
, cardano-cli
, cardano-cli:cardano-cli-test-lib
Expand Down Expand Up @@ -302,7 +302,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.16
, cardano-binary
, cardano-cli
, cardano-cli:cardano-cli-test-lib
Expand Down
79 changes: 57 additions & 22 deletions cardano-cli/src/Cardano/CLI/Commands/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module Cardano.CLI.Commands.Governance where

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.Types.Common
Expand All @@ -16,74 +17,108 @@ import Control.Monad.Trans.Except (ExceptT)
import Control.Monad.Trans.Except.Extra (firstExceptT, hoistEither, newExceptT)
import Data.Bifunctor
import qualified Data.ByteString as BS
import Data.Text (Text)
import qualified Data.Text.Encoding as Text
import Data.Word

runGovernanceCreateVoteCmd
:: AnyShelleyBasedEra
-> Vote
-> VType
-> TxIn
-> (TxId, Word32)
-> VerificationKeyOrFile StakePoolKey
-> VoteFile Out
-> ExceptT GovernanceCmdError IO ()
runGovernanceCreateVoteCmd anyEra vChoice vType govActionTxIn votingStakeCred oFp = do
runGovernanceCreateVoteCmd anyEra vChoice vType (govActionTxId, govActionIndex) votingStakeCred oFp = do
AnyShelleyBasedEra sbe <- pure anyEra
vStakePoolKey <- firstExceptT ReadFileError . newExceptT $ readVerificationKeyOrFile AsStakePoolKey votingStakeCred
let stakePoolKeyHash = verificationKeyHash vStakePoolKey
vStakeCred = StakeCredentialByKey . (verificationKeyHash . castVerificationKey) $ vStakePoolKey
case vType of
VCC -> do
votingCred <- hoistEither $ first VotingCredentialDecodeGovCmdEror $ toVotingCredential sbe vStakeCred
let govActIdentifier = makeGoveranceActionId sbe govActionTxIn
voteProcedure = createVotingProcedure sbe vChoice (VoterCommittee votingCred) govActIdentifier
firstExceptT WriteFileError . newExceptT $ shelleyBasedEraConstraints sbe $ writeFileTextEnvelope oFp Nothing voteProcedure
let voter = VoterCommittee votingCred
govActIdentifier = shelleyBasedEraConstraints sbe $ createGovernanceActionId govActionTxId govActionIndex
voteProcedure = createVotingProcedure sbe vChoice Nothing
votingEntry = VotingEntry { votingEntryVoter = voter
, votingEntryGovActionId = GovernanceActionId govActIdentifier
, votingEntryVotingProcedure = voteProcedure
}
firstExceptT WriteFileError . newExceptT $ shelleyBasedEraConstraints sbe $ writeFileTextEnvelope oFp Nothing votingEntry

VDR -> do
votingCred <- hoistEither $ first VotingCredentialDecodeGovCmdEror $ toVotingCredential sbe vStakeCred
let govActIdentifier = makeGoveranceActionId sbe govActionTxIn
voteProcedure = createVotingProcedure sbe vChoice (VoterDRep votingCred) govActIdentifier
firstExceptT WriteFileError . newExceptT $ shelleyBasedEraConstraints sbe $ writeFileTextEnvelope oFp Nothing voteProcedure
let voter = VoterDRep votingCred
govActIdentifier = shelleyBasedEraConstraints sbe $ createGovernanceActionId govActionTxId govActionIndex
voteProcedure = createVotingProcedure sbe vChoice Nothing
votingEntry = VotingEntry { votingEntryVoter = voter
, votingEntryGovActionId = GovernanceActionId govActIdentifier
, votingEntryVotingProcedure = voteProcedure
}
firstExceptT WriteFileError . newExceptT $ shelleyBasedEraConstraints sbe $ writeFileTextEnvelope oFp Nothing votingEntry

VSP -> do
let govActIdentifier = makeGoveranceActionId sbe govActionTxIn
voteProcedure = createVotingProcedure sbe vChoice (VoterSpo stakePoolKeyHash) govActIdentifier
firstExceptT WriteFileError . newExceptT $ shelleyBasedEraConstraints sbe $ writeFileTextEnvelope oFp Nothing voteProcedure
let voter = VoterSpo stakePoolKeyHash
govActIdentifier = shelleyBasedEraConstraints sbe $ createGovernanceActionId govActionTxId govActionIndex
voteProcedure = createVotingProcedure sbe vChoice Nothing
votingEntry = VotingEntry { votingEntryVoter = voter
, votingEntryGovActionId = GovernanceActionId govActIdentifier
, votingEntryVotingProcedure = voteProcedure
}
firstExceptT WriteFileError . newExceptT $ shelleyBasedEraConstraints sbe $ writeFileTextEnvelope oFp Nothing votingEntry


runGovernanceNewConstitutionCmd
:: AnyShelleyBasedEra
:: Ledger.Network
-> AnyShelleyBasedEra
-> Lovelace
-> VerificationKeyOrFile StakePoolKey
-> Maybe (TxId, Word32)
-> (Ledger.Url, Text)
-> Constitution
-> NewConstitutionFile Out
-> ExceptT GovernanceCmdError IO ()
runGovernanceNewConstitutionCmd sbe deposit stakeVoteCred constitution oFp = do
runGovernanceNewConstitutionCmd network sbe deposit stakeVoteCred mPrevGovAct propAnchor constitution oFp = do
vStakePoolKeyHash
<- fmap (verificationKeyHash . castVerificationKey)
<$> firstExceptT ReadFileError . newExceptT
$ readVerificationKeyOrFile AsStakePoolKey stakeVoteCred
case constitution of
ConstitutionFromFile fp -> do
ConstitutionFromFile url fp -> do
cBs <- liftIO $ BS.readFile $ unFile fp
_utf8EncodedText <- firstExceptT NonUtf8EncodedConstitution . hoistEither $ Text.decodeUtf8' cBs
let govAct = ProposeNewConstitution cBs
runGovernanceCreateActionCmd sbe deposit vStakePoolKeyHash govAct oFp
let prevGovActId = Ledger.maybeToStrictMaybe $ uncurry createPreviousGovernanceActionId <$> mPrevGovAct
govAct = ProposeNewConstitution
prevGovActId
(createAnchor url cBs) -- TODO: Conway era - this is wrong, create `AnchorData` then hash that with hashAnchorData
runGovernanceCreateActionCmd network sbe deposit vStakePoolKeyHash propAnchor govAct oFp

ConstitutionFromText c -> do
ConstitutionFromText url c -> do
let constitBs = Text.encodeUtf8 c
govAct = ProposeNewConstitution constitBs
runGovernanceCreateActionCmd sbe deposit vStakePoolKeyHash govAct oFp
prevGovActId = Ledger.maybeToStrictMaybe $ uncurry createPreviousGovernanceActionId <$> mPrevGovAct
govAct = ProposeNewConstitution
prevGovActId
(createAnchor url constitBs)
runGovernanceCreateActionCmd network sbe deposit vStakePoolKeyHash propAnchor govAct oFp

runGovernanceCreateActionCmd
:: AnyShelleyBasedEra
:: Ledger.Network
-> AnyShelleyBasedEra
-> Lovelace
-> Hash StakeKey
-> (Ledger.Url, Text)
-> GovernanceAction
-> File a Out
-> ExceptT GovernanceCmdError IO ()
runGovernanceCreateActionCmd anyEra deposit depositReturnAddr govAction oFp = do
runGovernanceCreateActionCmd network anyEra deposit depositReturnAddr propAnchor govAction oFp = do
AnyShelleyBasedEra sbe <- pure anyEra
let proposal = createProposalProcedure sbe deposit depositReturnAddr govAction
let proposal = createProposalProcedure
sbe
network
deposit
depositReturnAddr
govAction
(uncurry createAnchor (fmap Text.encodeUtf8 propAnchor))

firstExceptT WriteFileError . newExceptT
$ shelleyBasedEraConstraints sbe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions
) where

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Common (Constitution, VerificationKeyFile)
import Cardano.CLI.Types.Key

import Data.Text (Text)
Expand Down Expand Up @@ -49,36 +50,45 @@ data GovernanceActionCmds era

data EraBasedNewCommittee
= EraBasedNewCommittee
{ ebDeposit :: Lovelace
{ ebNetwork :: Ledger.Network
, ebDeposit :: Lovelace
, ebReturnAddress :: AnyStakeIdentifier
, ebPropAnchor :: (Ledger.Url, Text)
, ebOldCommittee :: [AnyStakeIdentifier]
, ebNewCommittee :: [(AnyStakeIdentifier, EpochNo)]
, ebRequiredQuorum :: Rational
, ebPreviousGovActionId :: TxIn
, ebPreviousGovActionId :: Maybe (TxId, Word32)
, ebFilePath :: File () Out
} deriving Show

data EraBasedNewConstitution
= EraBasedNewConstitution
{ encDeposit :: Lovelace
{ encNetwork :: Ledger.Network
, encDeposit :: Lovelace
, encStakeCredential :: AnyStakeIdentifier
, encPrevGovActId :: Maybe (TxId, Word32)
, encPropAnchor :: (Ledger.Url, Text)
, encConstitution :: Constitution
, encFilePath :: File () Out
} deriving Show

data EraBasedNoConfidence
= EraBasedNoConfidence
{ ncDeposit :: Lovelace
{ ncNetwork :: Ledger.Network
, ncDeposit :: Lovelace
, ncStakeCredential :: AnyStakeIdentifier
, ncProposalAnchor :: (Ledger.Url, Text)
, ncGovAct :: TxId
, ncGovActIndex :: Word32
, ncFilePath :: File () Out
} deriving Show

data EraBasedTreasuryWithdrawal where
EraBasedTreasuryWithdrawal
:: Lovelace -- ^ Deposit
:: Ledger.Network
-> Lovelace -- ^ Deposit
-> AnyStakeIdentifier -- ^ Return address
-> (Ledger.Url, Text) -- ^ Proposal anchor
-> [(AnyStakeIdentifier, Lovelace)]
-> File () Out
-> EraBasedTreasuryWithdrawal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ module Cardano.CLI.EraBased.Commands.Governance.Vote
, renderGovernanceVoteCmds
) where

import Cardano.Api

import Cardano.CLI.Types.Governance

import Data.Text (Text)

data GovernanceVoteCmds era
newtype GovernanceVoteCmds era
= GovernanceVoteCreateCmd
AnyVote
(File () Out)

renderGovernanceVoteCmds :: ()
=> GovernanceVoteCmds era
Expand Down
73 changes: 58 additions & 15 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
module Cardano.CLI.EraBased.Options.Common where

import Cardano.Api
import qualified Cardano.Api.Ledger as Ledger
import Cardano.Api.Shelley

import Cardano.CLI.Environment (EnvCli (..), envCliAnyShelleyBasedEra,
Expand Down Expand Up @@ -41,7 +42,7 @@ import Data.Text (Text)
import qualified Data.Text as Text
import Data.Time.Clock (UTCTime)
import Data.Time.Format (defaultTimeLocale, parseTimeOrError)
import Data.Word (Word64)
import Data.Word
import GHC.Natural (Natural)
import Network.Socket (PortNumber)
import Options.Applicative hiding (help, str)
Expand Down Expand Up @@ -780,15 +781,27 @@ catCommands = \case
pConstitution :: Parser Constitution
pConstitution =
asum
[ fmap ConstitutionFromText $ Opt.strOption $ mconcat
[ Opt.long "constitution"
, Opt.metavar "TEXT"
, Opt.help "Input constitution as UTF-8 encoded text."
]
[ ConstitutionFromText
<$> pUrl "constitution-url" "Constitution URL."
<*> Opt.strOption (mconcat
[ Opt.long "constitution"
, Opt.metavar "TEXT"
, Opt.help "Input constitution as UTF-8 encoded text."
])
, ConstitutionFromFile
<$> pFileInDirection "constitution-file" "Input constitution as a text file."
<$> pUrl "constitution-url" "Constitution URL."
<*> pFileInDirection "constitution-file" "Input constitution as a text file."
]

pUrl :: String -> String -> Parser Ledger.Url
pUrl l h = fromMaybe (error "Url longer than 64 bytes")
. Ledger.textToUrl <$>
Opt.strOption (mconcat
[ Opt.long l
, Opt.metavar "TEXT"
, Opt.help h
])

pGovActionDeposit :: Parser Lovelace
pGovActionDeposit =
Opt.option (readerFromParsecParser parseLovelace) $ mconcat
Expand Down Expand Up @@ -2657,14 +2670,6 @@ pVoterType =
, flag' VSP $ mconcat [long "spo", Opt.help "Stake pool operator"]
]

pGoveranceActionIdentifier :: String -> Parser TxIn
pGoveranceActionIdentifier h =
Opt.option (readerFromParsecParser parseTxIn) $ mconcat
[ Opt.long "tx-in"
, Opt.metavar "TX-IN"
, Opt.help h
]

-- TODO: Conway era include "normal" stake keys
pVotingCredential :: Parser (VerificationKeyOrFile StakePoolKey)
pVotingCredential = pStakePoolVerificationKeyOrFile
Expand Down Expand Up @@ -2711,6 +2716,44 @@ pDRepVerificationKeyFile =
, Opt.help "Filepath of the DRep verification key."
, Opt.completer (Opt.bashCompleter "file")
]
pProposalAnchor :: Parser (Ledger.Url, Text)
pProposalAnchor = (,) <$> pUrl "proposal-url" "Proposal anchor URL"
<*> pAnchorHash

pAnchorHash :: Parser Text
pAnchorHash =
Opt.strOption $ mconcat
[ Opt.long "anchor-data-hash"
, Opt.metavar "TEXT"
, Opt.help "Hash of anchor data."
]

pPreviousGovernanceAction :: Parser (Maybe (TxId, Word32))
pPreviousGovernanceAction = optional $
(,) <$> pTxId "governance-action-tx-id" "Previous txid of the governance action."
<*> pWord32 "governance-action-index" "Previous tx's governance action index."

pGovernanceActionId :: Parser (TxId, Word32)
pGovernanceActionId =
(,) <$> pTxId "governance-action-tx-id" "Txid of the governance action."
<*> pWord32 "governance-action-index" "Tx's governance action index."

pWord32 :: String -> String -> Parser Word32
pWord32 l h =
Opt.option auto $ mconcat
[ Opt.long l
, Opt.metavar "WORD32"
, Opt.help h
]

pTxId :: String -> String -> Parser TxId
pTxId l h =
Opt.option (readerFromParsecParser parseTxId) $ mconcat
[ Opt.long l
, Opt.metavar "TXID"
, Opt.help h
]


--------------------------------------------------------------------------------
-- Helpers
Expand Down
Loading