-
Notifications
You must be signed in to change notification settings - Fork 15
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
Share code in parsers of committee commands #816
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -526,13 +526,18 @@ | |||||
, Opt.help "The amount to transfer." | ||||||
] | ||||||
|
||||||
pHexHash | ||||||
:: SerialiseAsRawBytes (Hash a) => AsType a -> ReadM (Hash a) | ||||||
pHexHash a = | ||||||
pHexHash :: () | ||||||
=> SerialiseAsRawBytes (Hash a) | ||||||
=> AsType a | ||||||
-> Maybe String -- | Optional prefix to the error message | ||||||
-> ReadM (Hash a) | ||||||
pHexHash a mErrPrefix = | ||||||
Opt.eitherReader $ | ||||||
first (docToString . prettyError) | ||||||
first (\e -> errPrefix <> (docToString $ prettyError e)) | ||||||
. deserialiseFromRawBytesHex (AsHash a) | ||||||
. BSC.pack | ||||||
where | ||||||
errPrefix = maybe "" ((<>) ": ") mErrPrefix | ||||||
Check notice Code scanning / HLint Use section Note
cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs:540:26-36: Suggestion: Use section
Found: ((<>) ": ") Perhaps: (": " <>) |
||||||
|
||||||
pBech32KeyHash :: SerialiseAsBech32 (Hash a) => AsType a -> ReadM (Hash a) | ||||||
pBech32KeyHash a = | ||||||
|
@@ -714,17 +719,11 @@ | |||||
|
||||||
pRemoveCommitteeColdVerificationKeyHash :: Parser (Hash CommitteeColdKey) | ||||||
pRemoveCommitteeColdVerificationKeyHash = | ||||||
Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat | ||||||
Opt.option deserialiseColdCCKeyHashFromHex $ mconcat | ||||||
[ Opt.long "remove-cc-cold-verification-key-hash" | ||||||
, Opt.metavar "STRING" | ||||||
, Opt.help "Constitutional Committee key hash (hex-encoded)." | ||||||
] | ||||||
where | ||||||
deserialiseFromHex :: String -> Either String (Hash CommitteeColdKey) | ||||||
deserialiseFromHex = | ||||||
first (\e -> docToString $ "Invalid Constitutional Committee cold key hash: " <> prettyError e) | ||||||
. deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey) | ||||||
. BSC.pack | ||||||
|
||||||
pRemoveCommitteeColdVerificationKeyOrFile :: Parser (VerificationKeyOrFile CommitteeColdKey) | ||||||
pRemoveCommitteeColdVerificationKeyOrFile = | ||||||
|
@@ -735,17 +734,21 @@ | |||||
|
||||||
pRemoveCommitteeColdVerificationKey :: Parser (VerificationKey CommitteeColdKey) | ||||||
pRemoveCommitteeColdVerificationKey = | ||||||
Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat | ||||||
Opt.option (Opt.eitherReader deserialiseColdCCKeyFromHex) $ mconcat | ||||||
[ Opt.long "remove-cc-cold-verification-key" | ||||||
, Opt.metavar "STRING" | ||||||
, Opt.help "Constitutional Committee cold key (hex-encoded)." | ||||||
] | ||||||
where | ||||||
deserialiseFromHex :: String -> Either String (VerificationKey CommitteeColdKey) | ||||||
deserialiseFromHex = | ||||||
first (\e -> docToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) | ||||||
. deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeColdKey) | ||||||
. BSC.pack | ||||||
|
||||||
deserialiseColdCCKeyFromHex :: String -> Either String (VerificationKey CommitteeColdKey) | ||||||
deserialiseColdCCKeyFromHex = | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would also be nice to have also something like |
||||||
first (\e -> docToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) | ||||||
. deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeColdKey) | ||||||
. BSC.pack | ||||||
|
||||||
deserialiseColdCCKeyHashFromHex :: ReadM (Hash CommitteeColdKey) | ||||||
deserialiseColdCCKeyHashFromHex = | ||||||
pHexHash AsCommitteeColdKey (Just "Invalid Constitutional Committee cold key hash") | ||||||
|
||||||
pRemoveCommitteeColdVerificationKeyFile :: Parser (File (VerificationKey keyrole) In) | ||||||
pRemoveCommitteeColdVerificationKeyFile = | ||||||
|
@@ -774,31 +777,19 @@ | |||||
|
||||||
pCommitteeColdVerificationKey :: Parser (VerificationKey CommitteeColdKey) | ||||||
pCommitteeColdVerificationKey = | ||||||
Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat | ||||||
Opt.option (Opt.eitherReader deserialiseColdCCKeyFromHex) $ mconcat | ||||||
[ Opt.long "cold-verification-key" | ||||||
, Opt.metavar "STRING" | ||||||
, Opt.help "Constitutional Committee cold key (hex-encoded)." | ||||||
] | ||||||
where | ||||||
deserialiseFromHex :: String -> Either String (VerificationKey CommitteeColdKey) | ||||||
deserialiseFromHex = | ||||||
first (\e -> docToString $ "Invalid Constitutional Committee cold key: " <> prettyError e) | ||||||
. deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeColdKey) | ||||||
. BSC.pack | ||||||
|
||||||
pCommitteeColdVerificationKeyHash :: Parser (Hash CommitteeColdKey) | ||||||
pCommitteeColdVerificationKeyHash = | ||||||
Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat | ||||||
Opt.option deserialiseColdCCKeyHashFromHex $ mconcat | ||||||
[ Opt.long "cold-verification-key-hash" | ||||||
, Opt.metavar "STRING" | ||||||
, Opt.help "Constitutional Committee key hash (hex-encoded)." | ||||||
] | ||||||
where | ||||||
deserialiseFromHex :: String -> Either String (Hash CommitteeColdKey) | ||||||
deserialiseFromHex = | ||||||
first (\e -> docToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e) | ||||||
. deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey) | ||||||
. BSC.pack | ||||||
|
||||||
pCommitteeColdVerificationKeyFile :: Parser (File (VerificationKey keyrole) In) | ||||||
pCommitteeColdVerificationKeyFile = | ||||||
|
@@ -843,12 +834,7 @@ | |||||
] | ||||||
|
||||||
pCommitteeHotKey :: Parser (VerificationKey CommitteeHotKey) | ||||||
pCommitteeHotKey = | ||||||
Opt.option (Opt.eitherReader deserialiseHotCCKeyFromHex) $ mconcat | ||||||
[ Opt.long "hot-key" | ||||||
, Opt.metavar "STRING" | ||||||
, Opt.help "Constitutional Committee hot key (hex-encoded)." | ||||||
] | ||||||
pCommitteeHotKey = pCommitteeHotVerificationKey "hot-key" | ||||||
|
||||||
pCommitteeHotVerificationKeyOrFile :: Parser (VerificationKeyOrFile CommitteeHotKey) | ||||||
pCommitteeHotVerificationKeyOrFile = | ||||||
|
@@ -859,17 +845,11 @@ | |||||
|
||||||
pCommitteeHotVerificationKeyHash :: Parser (Hash CommitteeHotKey) | ||||||
pCommitteeHotVerificationKeyHash = | ||||||
Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat | ||||||
Opt.option deserialiseHotCCKeyHashFromHex $ 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 = | ||||||
|
@@ -885,14 +865,9 @@ | |||||
. deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeHotKey) | ||||||
. BSC.pack | ||||||
|
||||||
pCommitteeHotKeyFile :: Parser (VerificationKeyFile In) | ||||||
pCommitteeHotKeyFile = | ||||||
fmap File $ Opt.strOption $ mconcat | ||||||
[ Opt.long "hot-key-file" | ||||||
, Opt.metavar "FILE" | ||||||
, Opt.help "Filepath of the Consitutional Committee hot key." | ||||||
, Opt.completer (Opt.bashCompleter "file") | ||||||
] | ||||||
deserialiseHotCCKeyHashFromHex :: ReadM (Hash CommitteeHotKey) | ||||||
deserialiseHotCCKeyHashFromHex = | ||||||
pHexHash AsCommitteeHotKey (Just "Invalid Consitutional Committee hot key hash") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Consitutional -> Constitutional The typo was already there before the PR, but it would be good to do a search and replace since you are at it |
||||||
|
||||||
pCommitteeHotVerificationKeyFile :: String -> Parser (VerificationKeyFile In) | ||||||
pCommitteeHotVerificationKeyFile longFlag = | ||||||
|
@@ -906,23 +881,17 @@ | |||||
-- | The first argument is the optional prefix. | ||||||
pCommitteeHotKeyHash :: Maybe String -> Parser (Hash CommitteeHotKey) | ||||||
pCommitteeHotKeyHash prefix = | ||||||
Opt.option (Opt.eitherReader deserialiseFromHex) $ mconcat | ||||||
Opt.option deserialiseHotCCKeyHashFromHex $ mconcat | ||||||
[ Opt.long $ prefixFlag prefix "hot-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 | ||||||
|
||||||
pCommitteeHotKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile CommitteeHotKey) | ||||||
pCommitteeHotKeyOrHashOrFile = | ||||||
asum | ||||||
[ VerificationKeyOrFile . VerificationKeyValue <$> pCommitteeHotKey | ||||||
, VerificationKeyOrFile . VerificationKeyFilePath <$> pCommitteeHotKeyFile | ||||||
, VerificationKeyOrFile . VerificationKeyFilePath <$> pCommitteeHotVerificationKeyFile "hot-key-file" | ||||||
, VerificationKeyHash <$> pCommitteeHotKeyHash Nothing | ||||||
] | ||||||
|
||||||
|
@@ -998,7 +967,7 @@ | |||||
-- | First argument is the optional prefix | ||||||
pStakeVerificationKeyHash :: Maybe String -> Parser (Hash StakeKey) | ||||||
pStakeVerificationKeyHash prefix = | ||||||
Opt.option (pHexHash AsStakeKey) $ mconcat | ||||||
Opt.option (pHexHash AsStakeKey Nothing) $ mconcat | ||||||
[ Opt.long $ prefixFlag prefix "stake-key-hash" | ||||||
, Opt.metavar "HASH" | ||||||
, Opt.help "Stake verification key hash (hex-encoded)." | ||||||
|
@@ -2416,10 +2385,10 @@ | |||||
, Opt.help "A Cardano address" | ||||||
] | ||||||
|
||||||
-- | First argument is the prefix to use | ||||||
-- | First argument is the prefix for the option's flag to use | ||||||
pStakePoolVerificationKeyHash :: Maybe String -> Parser (Hash StakePoolKey) | ||||||
pStakePoolVerificationKeyHash prefix = | ||||||
Opt.option (pBech32KeyHash AsStakePoolKey <|> pHexHash AsStakePoolKey) $ mconcat | ||||||
Opt.option (pBech32KeyHash AsStakePoolKey <|> pHexHash AsStakePoolKey Nothing) $ mconcat | ||||||
[ Opt.long $ prefixFlag prefix "stake-pool-id" | ||||||
, Opt.metavar "STAKE_POOL_ID" | ||||||
, Opt.help | ||||||
|
@@ -3292,7 +3261,7 @@ | |||||
|
||||||
pDRepVerificationKeyHash :: Parser (Hash DRepKey) | ||||||
pDRepVerificationKeyHash = | ||||||
Opt.option (pBech32KeyHash AsDRepKey <|> pHexHash AsDRepKey) $ mconcat | ||||||
Opt.option (pBech32KeyHash AsDRepKey <|> pHexHash AsDRepKey Nothing) $ mconcat | ||||||
[ Opt.long "drep-key-hash" | ||||||
, Opt.metavar "HASH" | ||||||
, Opt.help "DRep verification key hash (either Bech32-encoded or hex-encoded)." | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, you could also use this function in:
pAddCommitteeColdVerificationKeyHash
,pGenesisVerificationKeyHash
,pGenesisDelegateVerificationKeyHash
,pVrfVerificationKeyHash
, andpStakePoolMetadataHash
, I think.