Skip to content

Commit

Permalink
Wire newly introduce governance commands in the CLI
Browse files Browse the repository at this point in the history
  Mostly plumbing and parser implementation following what already exists.
  • Loading branch information
KtorZ committed Apr 6, 2023
1 parent 8c67896 commit de92fb6
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cardano-cli/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

- Remove cardano-cli address build-script ([PR 4700](https://github.com/input-output-hk/cardano-node/pull/4700))

- New commands for on-chain SPOs polls under `shelley governance`:
- `create-poll`:
For the current governing entities, as a means to create new polls.

- `answer-poll`:
For participants who want to answer a given poll.

- `verify-poll`:
For anyone who seek to verify a poll entry (e.g. explorers)

The commands are built to fit and play nicely within the cardano-cli.
The poll and answers structures are based on transaction metadata and
require to be embedded in an actual transaction. The added commands
however only works from metadata and raw "GovernancePoll" envelopes.

See [CIP proposal](https://github.com/cardano-foundation/CIPs/pull/496) for details.

### Features

- Default to the ledger's CDDL format for transaction body creation by removing flags `--cddl-format` and `--cli-format` from `build` and `build-raw` ([PR 4303](https://github.com/input-output-hk/cardano-node/pull/4303))
Expand Down
15 changes: 15 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,18 @@ data GovernanceCmd
[VerificationKeyFile]
ProtocolParametersUpdate
(Maybe FilePath)
| GovernanceCreatePoll
Text -- Prompt
[Text] -- Choices
(Maybe Word) -- Nonce
OutputFile
| GovernanceAnswerPoll
FilePath -- Poll file
SigningKeyFile
(Maybe Word) -- Answer index
| GovernanceVerifyPoll
FilePath -- Poll file
FilePath -- Metadata JSON file
deriving Show

renderGovernanceCmd :: GovernanceCmd -> Text
Expand All @@ -426,6 +438,9 @@ renderGovernanceCmd cmd =
GovernanceMIRTransfer _ _ TransferToTreasury -> "governance create-mir-certificate transfer-to-treasury"
GovernanceMIRTransfer _ _ TransferToReserves -> "governance create-mir-certificate transfer-to-reserves"
GovernanceUpdateProposal {} -> "governance create-update-proposal"
GovernanceCreatePoll{} -> "governance create-poll"
GovernanceAnswerPoll{} -> "governance answer-poll"
GovernanceVerifyPoll{} -> "governance verify-poll"

data TextViewCmd
= TextViewInfo !FilePath (Maybe OutputFile)
Expand Down
81 changes: 81 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,15 @@ pGovernanceCmd =
, subParser "create-update-proposal"
$ Opt.info pUpdateProposal
$ Opt.progDesc "Create an update proposal"
, subParser "create-poll"
$ Opt.info pGovernanceCreatePoll
$ Opt.progDesc "Create an SPO poll"
, subParser "answer-poll"
$ Opt.info pGovernanceAnswerPoll
$ Opt.progDesc "Answer an SPO poll"
, subParser "verify-poll"
$ Opt.info pGovernanceVerifyPoll
$ Opt.progDesc "Verify an answer to a given SPO poll"
]
where
mirCertParsers :: Parser GovernanceCmd
Expand Down Expand Up @@ -1151,6 +1160,78 @@ pGovernanceCmd =
<*> pProtocolParametersUpdate
<*> optional pCostModels

pGovernanceCreatePoll :: Parser GovernanceCmd
pGovernanceCreatePoll =
GovernanceCreatePoll
<$> pPollQuestion
<*> some pPollAnswer
<*> optional pPollNonce
<*> pOutputFile

pGovernanceAnswerPoll :: Parser GovernanceCmd
pGovernanceAnswerPoll =
GovernanceAnswerPoll
<$> pPollFile
<*> pSigningKeyFile Input
<*> optional pPollAnswerIndex

pGovernanceVerifyPoll :: Parser GovernanceCmd
pGovernanceVerifyPoll =
GovernanceVerifyPoll
<$> pPollFile
<*> pPollMetadataFile


pPollQuestion :: Parser Text
pPollQuestion =
Opt.strOption
( Opt.long "question"
<> Opt.metavar "STRING"
<> Opt.help "The question for the poll."
)

pPollAnswer :: Parser Text
pPollAnswer =
Opt.strOption
( Opt.long "answer"
<> Opt.metavar "STRING"
<> Opt.help "A possible choice for the poll. The option is repeatable."
)

pPollAnswerIndex :: Parser Word
pPollAnswerIndex =
Opt.option auto
( Opt.long "answer"
<> Opt.metavar "INT"
<> Opt.help "The index of the chosen answer in the poll. Optional. Asked interactively if omitted."
)

pPollFile :: Parser FilePath
pPollFile =
Opt.strOption
( Opt.long "poll-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath to the ongoing poll."
<> Opt.completer (Opt.bashCompleter "file")
)

pPollNonce :: Parser Word
pPollNonce =
Opt.option auto
( Opt.long "nonce"
<> Opt.metavar "UINT"
<> Opt.help "An (optional) nonce for non-replayability."
)

pPollMetadataFile :: Parser FilePath
pPollMetadataFile =
Opt.strOption
( Opt.long "metadata-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the metadata file, in (detailed) JSON format."
<> Opt.completer (Opt.bashCompleter "file")
)

pTransferAmt :: Parser Lovelace
pTransferAmt =
Opt.option (readerFromParsecParser parseLovelace)
Expand Down
6 changes: 6 additions & 0 deletions cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ runGovernanceCmd (GovernanceGenesisKeyDelegationCertificate genVk genDelegVk vrf
runGovernanceGenesisKeyDelegationCertificate genVk genDelegVk vrfVk out
runGovernanceCmd (GovernanceUpdateProposal out eNo genVKeys ppUp mCostModelFp) =
runGovernanceUpdateProposal out eNo genVKeys ppUp mCostModelFp
runGovernanceCmd (GovernanceCreatePoll prompt choices nonce out) =
runGovernanceCreatePoll prompt choices nonce out
runGovernanceCmd (GovernanceAnswerPoll poll sk ix) =
runGovernanceAnswerPoll poll sk ix
runGovernanceCmd (GovernanceVerifyPoll poll metadata) =
runGovernanceVerifyPoll poll metadata

runGovernanceMIRCertificatePayStakeAddrs
:: Shelley.MIRPot
Expand Down

0 comments on commit de92fb6

Please sign in to comment.