Skip to content

Commit

Permalink
Merge pull request #921 from IntersectMBO/add-hash-validation2.5
Browse files Browse the repository at this point in the history
Hide free instances of `HashCheckParamInfo` into functions
  • Loading branch information
palas authored Oct 3, 2024
2 parents 89a8819 + 31212c8 commit 685c5fd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 65 deletions.
87 changes: 30 additions & 57 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3569,64 +3569,37 @@ pAnchorDataHash =
, Opt.help "Proposal anchor data hash (obtain it with \"cardano-cli hash anchor-data ...\")"
]

data HashCheckParamInfo anchorData
= HashCheckParamInfo
{ flagSuffix :: String
, dataName :: String
, hashParamName :: String
, urlParamName :: String
}

pMustCheckHash :: HashCheckParamInfo anchorData -> Parser (MustCheckHash anchorData)
pMustCheckHash
( HashCheckParamInfo
{ flagSuffix = flagSuffix'
, dataName = dataName'
, hashParamName = hashParamName'
, urlParamName = urlParamName'
}
) =
asum
[ Opt.flag' CheckHash $
mconcat
[ Opt.long ("check-" ++ flagSuffix')
, Opt.help
( "Check the "
++ dataName'
++ " hash (from "
++ hashParamName'
++ ") by downloading "
++ dataName'
++ " data (from "
++ urlParamName'
++ ")."
)
]
, Opt.flag' TrustHash $
mconcat
[ Opt.long ("trust-" ++ flagSuffix')
, Opt.help
("Do not check the " ++ dataName' ++ " hash (from " ++ hashParamName' ++ ") and trust it is correct.")
]
]
pMustCheckHash :: String -> String -> String -> String -> Parser (MustCheckHash anchorData)
pMustCheckHash flagSuffix' dataName' hashParamName' urlParamName' =
asum
[ Opt.flag' CheckHash $
mconcat
[ Opt.long ("check-" ++ flagSuffix')
, Opt.help
( "Check the "
++ dataName'
++ " hash (from "
++ hashParamName'
++ ") by downloading "
++ dataName'
++ " data (from "
++ urlParamName'
++ ")."
)
]
, Opt.flag' TrustHash $
mconcat
[ Opt.long ("trust-" ++ flagSuffix')
, Opt.help
("Do not check the " ++ dataName' ++ " hash (from " ++ hashParamName' ++ ") and trust it is correct.")
]
]

pMustCheckProposalHash :: Parser (MustCheckHash ProposalUrl)
pMustCheckProposalHash = pMustCheckHash "anchor-data" "proposal" "--anchor-data-hash" "--anchor-url"

proposalHashCheckInfo :: HashCheckParamInfo ProposalUrl
proposalHashCheckInfo =
HashCheckParamInfo
{ flagSuffix = "anchor-data"
, dataName = "proposal"
, hashParamName = "--anchor-data-hash"
, urlParamName = "--anchor-url"
}

constitutionHashCheckInfo :: HashCheckParamInfo ConstitutionUrl
constitutionHashCheckInfo =
HashCheckParamInfo
{ flagSuffix = "constitution-hash"
, dataName = "constitution"
, hashParamName = "--constitution-hash"
, urlParamName = "--constitution-url"
}
pMustCheckConstitutionHash :: Parser (MustCheckHash ConstitutionUrl)
pMustCheckConstitutionHash = pMustCheckHash "constitution-hash" "constitution" "--constitution-hash" "--constitution-url"

pPreviousGovernanceAction :: Parser (Maybe (TxId, Word16))
pPreviousGovernanceAction =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pGovernanceActionNewInfoCmd era = do
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pMustCheckProposalHash
<*> pFileOutDirection "out-file" "Path to action file to be used later on with build or build-raw "
)
$ Opt.progDesc "Create an info action."
Expand All @@ -95,10 +95,10 @@ pGovernanceActionNewConstitutionCmd era = do
<*> pPreviousGovernanceAction
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pMustCheckProposalHash
<*> pConstitutionUrl
<*> pConstitutionHash
<*> pMustCheckHash constitutionHashCheckInfo
<*> pMustCheckConstitutionHash
<*> optional pConstitutionScriptHash
<*> pFileOutDirection "out-file" "Output filepath of the constitution."
)
Expand Down Expand Up @@ -128,7 +128,7 @@ pUpdateCommitteeCmd eon =
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pMustCheckProposalHash
<*> many pRemoveCommitteeColdVerificationKeySource
<*> many
( (,)
Expand All @@ -154,7 +154,7 @@ pGovernanceActionNoConfidenceCmd era = do
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pMustCheckProposalHash
<*> pPreviousGovernanceAction
<*> pFileOutDirection "out-file" "Output filepath of the no confidence proposal."
)
Expand All @@ -176,7 +176,7 @@ pUpdateProtocolParametersPostConway conwayOnwards =
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pMustCheckProposalHash
<*> pPreviousGovernanceAction
<*> optional pConstitutionScriptHash

Expand Down Expand Up @@ -384,7 +384,7 @@ pGovernanceActionTreasuryWithdrawalCmd era = do
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pMustCheckProposalHash
<*> some ((,) <$> pStakeIdentifier (Just "funds-receiving") <*> pTreasuryWithdrawalAmt)
<*> optional pConstitutionScriptHash
<*> pFileOutDirection "out-file" "Output filepath of the treasury withdrawal."
Expand Down Expand Up @@ -428,7 +428,7 @@ pGovernanceActionHardforkInitCmd era = do
<*> pPreviousGovernanceAction
<*> pAnchorUrl
<*> pAnchorDataHash
<*> pMustCheckHash proposalHashCheckInfo
<*> pMustCheckProposalHash
<*> pPV
<*> pFileOutDirection "out-file" "Output filepath of the hardfork proposal."
)
Expand Down

0 comments on commit 685c5fd

Please sign in to comment.