From 2e3dc3b0cb4b33a44f402266b186549fc0a0063b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 5 Oct 2023 12:02:06 +0200 Subject: [PATCH 1/2] vote create: allow cc hot keys as input --- .../Cardano/CLI/EraBased/Options/Common.hs | 48 ++++++++++++++----- .../CLI/EraBased/Options/Governance/Vote.hs | 1 + 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index b0277bbfa6..0c79031139 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -814,17 +814,25 @@ pAnyVerificationKeySource helpText = pCommitteeHotKey :: Parser (VerificationKey CommitteeHotKey) pCommitteeHotKey = - Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat + Opt.option (Opt.eitherReader deserialiseHotCCKeyFromHex) $ mconcat [ Opt.long "hot-key" , Opt.metavar "STRING" , Opt.help "Constitutional Committee hot key (hex-encoded)." ] - where - deserialiseFromHex :: String -> Either String (VerificationKey CommitteeHotKey) - deserialiseFromHex = - first (\e -> "Invalid Constitutional Committee hot key: " ++ displayError e) - . deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeHotKey) - . BSC.pack + +pCommitteeHotVerificationKey :: Parser (VerificationKey CommitteeHotKey) +pCommitteeHotVerificationKey = + Opt.option (Opt.eitherReader deserialiseHotCCKeyFromHex) $ mconcat + [ Opt.long "cc-hot-verification-key" + , Opt.metavar "STRING" + , Opt.help "Constitutional Committee hot key (hex-encoded)." + ] + +deserialiseHotCCKeyFromHex :: String -> Either String (VerificationKey CommitteeHotKey) +deserialiseHotCCKeyFromHex = + first (\e -> "Invalid Constitutional Committee hot key: " ++ displayError e) + . deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeHotKey) + . BSC.pack pCommitteeHotKeyFile :: Parser (VerificationKeyFile In) pCommitteeHotKeyFile = @@ -835,10 +843,20 @@ pCommitteeHotKeyFile = , Opt.completer (Opt.bashCompleter "file") ] -pCommitteeHotKeyHash :: Parser (Hash CommitteeHotKey) -pCommitteeHotKeyHash = +pCommitteeHotVerificationKeyFile :: Parser (VerificationKeyFile In) +pCommitteeHotVerificationKeyFile = + fmap File $ Opt.strOption $ mconcat + [ Opt.long "cc-hot-verification-key-file" + , Opt.metavar "FILE" + , Opt.help "Filepath of the Consitutional Committee hot key." + , Opt.completer (Opt.bashCompleter "file") + ] + +-- | The first argument is the optional prefix. +pCommitteeHotKeyHash :: Maybe String -> Parser (Hash CommitteeHotKey) +pCommitteeHotKeyHash prefix = Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat - [ Opt.long "hot-key-hash" + [ Opt.long $ prefixFlag prefix "hot-key-hash" , Opt.metavar "STRING" , Opt.help "Constitutional Committee key hash (hex-encoded)." ] @@ -860,7 +878,15 @@ pCommitteeHotKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile CommitteeHot pCommitteeHotKeyOrHashOrFile = asum [ VerificationKeyOrFile <$> pCommitteeHotKeyOrFile - , VerificationKeyHash <$> pCommitteeHotKeyHash + , VerificationKeyHash <$> pCommitteeHotKeyHash Nothing + ] + +pCommitteeHotVerificationKeyOrHashOrVerificationFile :: Parser (VerificationKeyOrHashOrFile CommitteeHotKey) +pCommitteeHotVerificationKeyOrHashOrVerificationFile = + asum + [ VerificationKeyOrFile . VerificationKeyValue <$> pCommitteeHotVerificationKey, + VerificationKeyOrFile . VerificationKeyFilePath <$> pCommitteeHotVerificationKeyFile, + VerificationKeyHash <$> pCommitteeHotKeyHash (Just "cc") ] catCommands :: [Parser a] -> Maybe (Parser a) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs index 4c286afbb4..6afe8e6654 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Vote.hs @@ -53,4 +53,5 @@ pAnyVotingStakeVerificationKeyOrHashOrFile :: Parser AnyVotingStakeVerificationK pAnyVotingStakeVerificationKeyOrHashOrFile = asum [ AnyDRepVerificationKeyOrHashOrFile <$> pDRepVerificationKeyOrHashOrFile , AnyStakePoolVerificationKeyOrHashOrFile <$> pStakePoolVerificationKeyOrHashOrFile Nothing + , AnyCommitteeHotVerificationKeyOrHashOrFile <$> pCommitteeHotVerificationKeyOrHashOrVerificationFile ] From 3244a925af30fb6784dbab6fff61f43a530e6d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Thu, 5 Oct 2023 15:20:04 +0200 Subject: [PATCH 2/2] vote create: adapt golden files --- cardano-cli/test/cardano-cli-golden/files/golden/help.cli | 3 +++ .../files/golden/help/conway_governance_vote_create.cli | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index c4ef0af43c..47285d39f7 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6563,6 +6563,9 @@ Usage: cardano-cli conway governance vote create (--yes | --no | --abstain) | --stake-pool-verification-key STRING | --cold-verification-key-file FILE | --stake-pool-id STAKE_POOL_ID + | --cc-hot-verification-key STRING + | --cc-hot-verification-key-file FILE + | --cc-hot-key-hash STRING ) --out-file FILE diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli index 0ef7ea6bbb..a1f7b7d026 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_vote_create.cli @@ -7,6 +7,9 @@ Usage: cardano-cli conway governance vote create (--yes | --no | --abstain) | --stake-pool-verification-key STRING | --cold-verification-key-file FILE | --stake-pool-id STAKE_POOL_ID + | --cc-hot-verification-key STRING + | --cc-hot-verification-key-file FILE + | --cc-hot-key-hash STRING ) --out-file FILE @@ -32,5 +35,10 @@ Available options: Stake pool ID/verification key hash (either Bech32-encoded or hex-encoded). Zero or more occurences of this option is allowed. + --cc-hot-verification-key STRING + Constitutional Committee hot key (hex-encoded). + --cc-hot-verification-key-file FILE + Filepath of the Consitutional Committee hot key. + --cc-hot-key-hash STRING Constitutional Committee key hash (hex-encoded). --out-file FILE Output filepath of the vote. -h,--help Show this help text