From 949c71750d49231e59a59d2963a1f3cf3d62e8cf Mon Sep 17 00:00:00 2001 From: teodanciu Date: Wed, 18 Oct 2023 23:39:26 +0100 Subject: [PATCH] Adapt to new anchor parameter in `ConwayResignCommitteeColdKey` --- .../EraBased/Commands/Governance/Committee.hs | 3 ++ .../EraBased/Options/Governance/Committee.hs | 40 ++++++++++++++++--- .../CLI/EraBased/Run/Governance/Committee.hs | 3 +- cardano-cli/src/Cardano/CLI/Json/Friendly.hs | 6 ++- .../CLI/Types/Errors/TxValidationError.hs | 2 +- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs index 141a3d77f8..9746c3f9ef 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Committee.hs @@ -13,6 +13,8 @@ module Cardano.CLI.EraBased.Commands.Governance.Committee ) where import Cardano.Api +import qualified Cardano.Api.Ledger as Ledger +import Cardano.Api.Shelley import Cardano.CLI.Types.Key import Cardano.CLI.Types.Key.VerificationKey @@ -59,6 +61,7 @@ data GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era = GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs { eon :: !(ConwayEraOnwards era) , vkeyColdKeySource :: !(VerificationKeyOrHashOrFile CommitteeColdKey) + , anchor :: !(Maybe (Ledger.Anchor (Ledger.EraCrypto (ShelleyLedgerEra era)))) , outFile :: !(File () Out) } deriving Show diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs index f6548bd323..72159ba55b 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Committee.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeFamilies #-} module Cardano.CLI.EraBased.Options.Governance.Committee ( pGovernanceCommitteeCmds @@ -8,6 +9,10 @@ import Cardano.Api import Cardano.CLI.EraBased.Commands.Governance.Committee import Cardano.CLI.EraBased.Options.Common +import Cardano.CLI.Read +import qualified Cardano.Ledger.BaseTypes as L +import qualified Cardano.Ledger.Crypto as Crypto +import qualified Cardano.Ledger.SafeHash as L import Options.Applicative (Parser) import qualified Options.Applicative as Opt @@ -116,13 +121,36 @@ pGovernanceCommitteeCreateColdKeyResignationCertificateCmd era = do w <- forEraMaybeEon era pure $ subParser "create-cold-key-resignation-certificate" - $ Opt.info - ( fmap GovernanceCommitteeCreateColdKeyResignationCertificateCmd $ - GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs w - <$> pCommitteeColdVerificationKeyOrHashOrFile - <*> pOutputFile - ) + $ Opt.info (conwayEraOnwardsConstraints w $ mkParser w) $ Opt.progDesc $ mconcat [ "Create cold key resignation certificate for a Constitutional Committee Member" ] + where + mkParser w = GovernanceCommitteeCreateColdKeyResignationCertificateCmd <$> + ( + GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs w <$> + pCommitteeColdVerificationKeyOrHashOrFile <*> + pAnchor <*> + pOutputFile + ) + +pAnchor :: Parser (Maybe (L.Anchor Crypto.StandardCrypto)) +pAnchor = + Opt.optional $ + L.Anchor + <$> fmap unAnchorUrl pAnchorUrl + <*> pSafeHash + +pAnchorUrl :: Parser AnchorUrl +pAnchorUrl = + AnchorUrl + <$> pUrl "committee-cold-key-resignation-certificate-metadata-url" "Committee cold key resignation certificate URL" + +pSafeHash :: Parser (L.SafeHash Crypto.StandardCrypto L.AnchorData) +pSafeHash = + Opt.option readSafeHash $ mconcat + [ Opt.long "committee-cold-key-resignation-certificate-metadata-hash" + , Opt.metavar "HASH" + , Opt.help "Committee cold key resignation certificate metadata hash." + ] diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs index e0056f2286..e1b8db68ec 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs @@ -172,6 +172,7 @@ runGovernanceCommitteeColdKeyResignationCertificate Cmd.GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs { Cmd.eon = w , Cmd.vkeyColdKeySource = coldVkOrHashOrFp + , Cmd.anchor = anchor , Cmd.outFile = oFp } = conwayEraOnwardsConstraints w $ do @@ -179,7 +180,7 @@ runGovernanceCommitteeColdKeyResignationCertificate lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey coldVkOrHashOrFp) & onLeft (left . GovernanceCommitteeCmdKeyReadError) - makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequirements w coldVKHash) + makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequirements w coldVKHash anchor) & textEnvelopeToJSON (Just genKeyDelegCertDesc) & writeLazyByteStringFile oFp & firstExceptT GovernanceCommitteeCmdTextEnvWriteError . newExceptT diff --git a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs index e19412ca8b..ddec08e325 100644 --- a/cardano-cli/src/Cardano/CLI/Json/Friendly.hs +++ b/cardano-cli/src/Cardano/CLI/Json/Friendly.hs @@ -429,10 +429,12 @@ renderCertificate sbe = \case [ "cold key hash" .= ck , "hot key hash" .= hk ] - Ledger.ResignCommitteeColdTxCert cred -> case cred of + Ledger.ResignCommitteeColdTxCert cred anchor -> case cred of Shelley.ScriptHashObj sh -> "Cold committee resignation" .= object - [ "script hash" .= sh ] + [ "script hash" .= sh + , "achor" .= anchor + ] Shelley.KeyHashObj ck@Shelley.KeyHash{} -> "Constitutional committee cold key resignation" .= object [ "cold key hash" .= ck diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs index ad14c7b7de..f4b5f027b4 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/TxValidationError.hs @@ -274,7 +274,7 @@ validateTxCertificates era certsAndScriptWitnesses = cardanoEraConstraints era $ L.DelegTxCert sCred _ -> Just sCred L.RegDepositDelegTxCert sCred _ _ -> Just sCred L.AuthCommitteeHotKeyTxCert{} -> Nothing - L.ResignCommitteeColdTxCert _ -> Nothing + L.ResignCommitteeColdTxCert _ _ -> Nothing L.RegDRepTxCert{} -> Nothing L.UnRegDRepTxCert{} -> Nothing L.UpdateDRepTxCert{} -> Nothing