Skip to content

Commit

Permalink
Adapt to new anchor parameter in ConwayResignCommitteeColdKey
Browse files Browse the repository at this point in the history
  • Loading branch information
teodanciu committed Oct 19, 2023
1 parent 6524280 commit beb07ad
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}

module Cardano.CLI.EraBased.Options.Governance.Committee
( pGovernanceCommitteeCmds
Expand All @@ -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
Expand Down Expand Up @@ -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."
]
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,15 @@ runGovernanceCommitteeColdKeyResignationCertificate
Cmd.GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs
{ Cmd.eon = w
, Cmd.vkeyColdKeySource = coldVkOrHashOrFp
, Cmd.anchor = anchor
, Cmd.outFile = oFp
} =
conwayEraOnwardsConstraints w $ do
CommitteeColdKeyHash coldVKHash <-
lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey coldVkOrHashOrFp)
& onLeft (left . GovernanceCommitteeCmdKeyReadError)

makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequirements w coldVKHash)
makeCommitteeColdkeyResignationCertificate (CommitteeColdkeyResignationRequirements w coldVKHash anchor)
& textEnvelopeToJSON (Just genKeyDelegCertDesc)
& writeLazyByteStringFile oFp
& firstExceptT GovernanceCommitteeCmdTextEnvWriteError . newExceptT
Expand Down
6 changes: 4 additions & 2 deletions cardano-cli/src/Cardano/CLI/Json/Friendly.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit beb07ad

Please sign in to comment.