Skip to content

Commit

Permalink
Reduce duplication by using pHexHash more
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Jul 3, 2024
1 parent 1bcfba9 commit e8e94d3
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ pScriptHash longOptionName helpText =

pRemoveCommitteeColdVerificationKeyHash :: Parser (Hash CommitteeColdKey)
pRemoveCommitteeColdVerificationKeyHash =
Opt.option (Opt.eitherReader deserialiseColdCCKeyHashFromHex) $ mconcat
Opt.option deserialiseColdCCKeyHashFromHex $ mconcat
[ Opt.long "remove-cc-cold-verification-key-hash"
, Opt.metavar "STRING"
, Opt.help "Constitutional Committee key hash (hex-encoded)."
Expand All @@ -745,11 +745,9 @@ deserialiseColdCCKeyFromHex =
. deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeColdKey)
. BSC.pack

deserialiseColdCCKeyHashFromHex :: String -> Either String (Hash CommitteeColdKey)
deserialiseColdCCKeyHashFromHex :: ReadM (Hash CommitteeColdKey)
deserialiseColdCCKeyHashFromHex =
first (\e -> docToString $ "Invalid Constitutional Committee cold key hash: " <> prettyError e)
. deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey)
. BSC.pack
pHexHash AsCommitteeColdKey (Just "Invalid Constitutional Committee cold key hash")

pRemoveCommitteeColdVerificationKeyFile :: Parser (File (VerificationKey keyrole) In)
pRemoveCommitteeColdVerificationKeyFile =
Expand Down Expand Up @@ -786,7 +784,7 @@ pCommitteeColdVerificationKey =

pCommitteeColdVerificationKeyHash :: Parser (Hash CommitteeColdKey)
pCommitteeColdVerificationKeyHash =
Opt.option (Opt.eitherReader deserialiseColdCCKeyHashFromHex) $ mconcat
Opt.option deserialiseColdCCKeyHashFromHex $ mconcat
[ Opt.long "cold-verification-key-hash"
, Opt.metavar "STRING"
, Opt.help "Constitutional Committee key hash (hex-encoded)."
Expand Down Expand Up @@ -846,7 +844,7 @@ pCommitteeHotVerificationKeyOrFile =

pCommitteeHotVerificationKeyHash :: Parser (Hash CommitteeHotKey)
pCommitteeHotVerificationKeyHash =
Opt.option (Opt.eitherReader deserialiseHotCCKeyHashFromHex) $ mconcat
Opt.option deserialiseHotCCKeyHashFromHex $ mconcat
[ Opt.long "hot-verification-key-hash"
, Opt.metavar "STRING"
, Opt.help "Constitutional Committee key hash (hex-encoded)."
Expand All @@ -866,11 +864,9 @@ deserialiseHotCCKeyFromHex =
. deserialiseFromRawBytesHex (AsVerificationKey AsCommitteeHotKey)
. BSC.pack

deserialiseHotCCKeyHashFromHex :: String -> Either String (Hash CommitteeHotKey)
deserialiseHotCCKeyHashFromHex :: ReadM (Hash CommitteeHotKey)
deserialiseHotCCKeyHashFromHex =
first (\e -> docToString $ "Invalid Consitutional Committee hot key hash: " <> prettyError e)
. deserialiseFromRawBytesHex (AsHash AsCommitteeHotKey)
. BSC.pack
pHexHash AsCommitteeHotKey (Just "Invalid Consitutional Committee hot key hash")

pCommitteeHotVerificationKeyFile :: String -> Parser (VerificationKeyFile In)
pCommitteeHotVerificationKeyFile longFlag =
Expand All @@ -884,7 +880,7 @@ pCommitteeHotVerificationKeyFile longFlag =
-- | The first argument is the optional prefix.
pCommitteeHotKeyHash :: Maybe String -> Parser (Hash CommitteeHotKey)
pCommitteeHotKeyHash prefix =
Opt.option (Opt.eitherReader deserialiseHotCCKeyHashFromHex) $ mconcat
Opt.option deserialiseHotCCKeyHashFromHex $ mconcat
[ Opt.long $ prefixFlag prefix "hot-key-hash"
, Opt.metavar "STRING"
, Opt.help "Constitutional Committee key hash (hex-encoded)."
Expand Down

0 comments on commit e8e94d3

Please sign in to comment.