Skip to content

Commit

Permalink
Merge pull request #806 from IntersectMBO/smelc/add-hot-script-hash-o…
Browse files Browse the repository at this point in the history
…ption-to-gov-committee-create-hot-key-authorization-cert

Add --hot-script-hash option to committee create-hot-key-authorization-certificate subcommand
  • Loading branch information
smelc authored Jul 2, 2024
2 parents 2006e3b + 3c23953 commit 32ece3b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era =
GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeyColdKeySource :: !(VerificationKeySource CommitteeColdKey)
, vkeyHotKeySource :: !(VerificationKeyOrHashOrFileOrScript CommitteeHotKey)
, vkeyHotKeySource :: !(VerificationKeySource CommitteeHotKey)
, outFile :: !(File () Out)
} deriving Show

Expand Down
37 changes: 29 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,31 @@ pCommitteeHotKey =
, Opt.help "Constitutional Committee hot key (hex-encoded)."
]

pCommitteeHotVerificationKey :: Parser (VerificationKey CommitteeHotKey)
pCommitteeHotVerificationKey =
pCommitteeHotVerificationKeyOrFile :: Parser (VerificationKeyOrFile CommitteeHotKey)
pCommitteeHotVerificationKeyOrFile =
asum
[ VerificationKeyValue <$> pCommitteeHotVerificationKey "hot-verification-key"
, VerificationKeyFilePath <$> pCommitteeHotVerificationKeyFile "hot-verification-key-file"
]

pCommitteeHotVerificationKeyHash :: Parser (Hash CommitteeHotKey)
pCommitteeHotVerificationKeyHash =
Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat
[ Opt.long "hot-verification-key-hash"
, Opt.metavar "STRING"
, Opt.help "Constitutional Committee key hash (hex-encoded)."
]
where
deserialiseFromHex :: String -> Either String (Hash CommitteeHotKey)
deserialiseFromHex =
first (\e -> docToString $ "Invalid Consitutional Committee hot key hash: " <> prettyError e)
. deserialiseFromRawBytesHex (AsHash AsCommitteeHotKey)
. BSC.pack

pCommitteeHotVerificationKey :: String -> Parser (VerificationKey CommitteeHotKey)
pCommitteeHotVerificationKey longFlag =
Opt.option (Opt.eitherReader deserialiseHotCCKeyFromHex) $ mconcat
[ Opt.long "cc-hot-verification-key"
[ Opt.long longFlag
, Opt.metavar "STRING"
, Opt.help "Constitutional Committee hot key (hex-encoded)."
]
Expand All @@ -873,10 +894,10 @@ pCommitteeHotKeyFile =
, Opt.completer (Opt.bashCompleter "file")
]

pCommitteeHotVerificationKeyFile :: Parser (VerificationKeyFile In)
pCommitteeHotVerificationKeyFile =
pCommitteeHotVerificationKeyFile :: String -> Parser (VerificationKeyFile In)
pCommitteeHotVerificationKeyFile longFlag =
fmap File $ Opt.strOption $ mconcat
[ Opt.long "cc-hot-verification-key-file"
[ Opt.long longFlag
, Opt.metavar "FILE"
, Opt.help "Filepath of the Consitutional Committee hot key."
, Opt.completer (Opt.bashCompleter "file")
Expand Down Expand Up @@ -908,8 +929,8 @@ pCommitteeHotKeyOrHashOrFile =
pCommitteeHotVerificationKeyOrHashOrVerificationFile :: Parser (VerificationKeyOrHashOrFile CommitteeHotKey)
pCommitteeHotVerificationKeyOrHashOrVerificationFile =
asum
[ VerificationKeyOrFile . VerificationKeyValue <$> pCommitteeHotVerificationKey,
VerificationKeyOrFile . VerificationKeyFilePath <$> pCommitteeHotVerificationKeyFile,
[ VerificationKeyOrFile . VerificationKeyValue <$> pCommitteeHotVerificationKey "cc-hot-verification-key",
VerificationKeyOrFile . VerificationKeyFilePath <$> pCommitteeHotVerificationKeyFile "cc-hot-verification-key-file",
VerificationKeyHash <$> pCommitteeHotKeyHash (Just "cc")
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,13 @@ pGovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd era = do
( fmap GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmd $
GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs w
<$> pColdCredential
<*> pHotVerificationKeyOrHashOrFileOrScript
<*> pHotCredential
<*> pOutputFile
)
$ Opt.progDesc
$ mconcat
[ "Create hot key authorization certificate for a Constitutional Committee Member"
]
where
pHotVerificationKeyOrHashOrFileOrScript = asum
[ VkhfsKeyHashFile <$> pCommitteeHotKeyOrHashOrFile
, VkhfsScript <$> pScriptFor "hot-script-file" Nothing "Hot Native or Plutus script file"
]

pGovernanceCommitteeCreateColdKeyResignationCertificateCmd :: ()
=> CardanoEra era
Expand Down Expand Up @@ -149,6 +144,18 @@ pColdCredential =
, VksScript <$> pScriptFor "cold-script-file" Nothing "Cold Native or Plutus script file"
]

pHotCredential :: Parser (VerificationKeySource CommitteeHotKey)
pHotCredential =
asum
[ VksKeyHashFile . VerificationKeyOrFile <$> pCommitteeHotVerificationKeyOrFile
, VksKeyHashFile . VerificationKeyHash <$> pCommitteeHotVerificationKeyHash
, VksScriptHash <$>
pScriptHash
"hot-script-hash"
"Committee hot Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli hash script ...\"."
, VksScript <$> pScriptFor "hot-script-file" Nothing "Hot Native or Plutus script file"
]

pAnchor :: Parser (Maybe (L.Anchor L.StandardCrypto))
pAnchor =
Opt.optional $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import Cardano.Api.Shelley
import Cardano.CLI.EraBased.Commands.Governance.Committee
import qualified Cardano.CLI.EraBased.Commands.Governance.Committee as Cmd
import qualified Cardano.CLI.EraBased.Run.Key as Key
import Cardano.CLI.Read (readVerificationKeyOrHashOrFileOrScript,
readVerificationKeySource)
import Cardano.CLI.Read (readVerificationKeySource)
import Cardano.CLI.Types.Errors.GovernanceCommitteeError
import Cardano.CLI.Types.Key.VerificationKey

Expand Down Expand Up @@ -141,7 +140,7 @@ runGovernanceCommitteeCreateHotKeyAuthorizationCertificate
let mapError' = modifyError $ either GovernanceCommitteeCmdScriptReadError GovernanceCommitteeCmdKeyReadError
hotCred <-
mapError' $
readVerificationKeyOrHashOrFileOrScript AsCommitteeHotKey unCommitteeHotKeyHash vkeyHotKeySource
readVerificationKeySource AsCommitteeHotKey unCommitteeHotKeyHash vkeyHotKeySource
coldCred <-
mapError' $
readVerificationKeySource AsCommitteeColdKey unCommitteeColdKeyHash vkeyColdKeySource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ hprop_golden_governance_CommitteeCreateHotKeyAuthorizationCertificate =
H.noteShowM_ $ execCardanoCLI
[ "conway", "governance", "committee", "create-hot-key-authorization-certificate"
, "--cold-verification-key-file", ccColdVKey
, "--hot-key-file", ccHotVKey
, "--hot-verification-key-file", ccHotVKey
, "--out-file", certFile
]

Expand Down
7 changes: 4 additions & 3 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -6930,9 +6930,10 @@ Usage: cardano-cli conway governance committee create-hot-key-authorization-cert
| --cold-script-hash HASH
| --cold-script-file FILE
)
( --hot-key STRING
| --hot-key-file FILE
| --hot-key-hash STRING
( --hot-verification-key STRING
| --hot-verification-key-file FILE
| --hot-verification-key-hash STRING
| --hot-script-hash HASH
| --hot-script-file FILE
)
--out-file FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ Usage: cardano-cli conway governance committee create-hot-key-authorization-cert
| --cold-script-hash HASH
| --cold-script-file FILE
)
( --hot-key STRING
| --hot-key-file FILE
| --hot-key-hash STRING
( --hot-verification-key STRING
| --hot-verification-key-file FILE
| --hot-verification-key-hash STRING
| --hot-script-hash HASH
| --hot-script-file FILE
)
--out-file FILE
Expand All @@ -25,9 +26,15 @@ Available options:
(hex-encoded). Obtain it with "cardano-cli hash
script ...".
--cold-script-file FILE Cold Native or Plutus script file
--hot-key STRING Constitutional Committee hot key (hex-encoded).
--hot-key-file FILE Filepath of the Consitutional Committee hot key.
--hot-key-hash STRING Constitutional Committee key hash (hex-encoded).
--hot-verification-key STRING
Constitutional Committee hot key (hex-encoded).
--hot-verification-key-file FILE
Filepath of the Consitutional Committee hot key.
--hot-verification-key-hash STRING
Constitutional Committee key hash (hex-encoded).
--hot-script-hash HASH Committee hot Native or Plutus script file hash
(hex-encoded). Obtain it with "cardano-cli hash
script ...".
--hot-script-file FILE Hot Native or Plutus script file
--out-file FILE The output file.
-h,--help Show this help text

0 comments on commit 32ece3b

Please sign in to comment.