Skip to content
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

Add Plutus script hash support in update-committee, overnance committee create-cold-key-resignation-certificate and query committee-state commands. #658

Merged
merged 8 commits into from
Mar 20, 2024
8 changes: 7 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository cardano-haskell-packages
-- you need to run if you change them
index-state:
, hackage.haskell.org 2024-03-15T22:05:53Z
, cardano-haskell-packages 2024-03-15T18:07:40Z
, cardano-haskell-packages 2024-03-20T14:04:39Z

packages:
cardano-cli
Expand All @@ -40,6 +40,12 @@ test-show-details: direct
-- Always write GHC env files, because they are needed for ghci.
write-ghc-environment-files: always

-- FIXME: remove this when bumping ouroboros-consensus
-- this is required to build with ouroboros-consensus-cardano-0.14.0.1
allow-newer:
cardano-git-rev

-- IMPORTANT
-- Do NOT add more source-repository-package stanzas here unless they are strictly
-- temporary! Please read the section in CONTRIBUTING about updating dependencies.

2 changes: 1 addition & 1 deletion cardano-cli/cardano-cli.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ library
, binary
, bytestring
, canonical-json
, cardano-api ^>= 8.41.0.0
, cardano-api ^>= 8.42.0.0
, cardano-binary
, cardano-crypto
, cardano-crypto-class ^>= 2.1.2
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/Byron/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ runPrintSigningKeyAddress bKeyFormat networkid skF = do

runKeygen :: NewSigningKeyFile -> ExceptT ByronClientCmdError IO ()
runKeygen (NewSigningKeyFile skF) = do
sK <- liftIO $ generateSigningKey AsByronKey
sK <- generateSigningKey AsByronKey
firstExceptT ByronCmdHelpersError . ensureNewFileLBS skF $ serialiseToRawBytes sK

runToVerification :: ByronKeyFormat -> SigningKeyFile In -> NewVerificationKeyFile -> ExceptT ByronClientCmdError IO ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

module Cardano.CLI.EraBased.Commands.Governance.Actions
( GovernanceActionCmds(..)
, GoveranceActionUpdateCommitteeCmdArgs(..)
, GovernanceActionUpdateCommitteeCmdArgs(..)
, GovernanceActionCreateConstitutionCmdArgs(..)
, GovernanceActionCreateNoConfidenceCmdArgs(..)
, GovernanceActionInfoCmdArgs(..)
Expand All @@ -33,24 +33,24 @@ import Data.Word

data GovernanceActionCmds era
= GovernanceActionCreateConstitutionCmd !(GovernanceActionCreateConstitutionCmdArgs era)
| GoveranceActionUpdateCommitteeCmd !(GoveranceActionUpdateCommitteeCmdArgs era)
| GovernanceActionUpdateCommitteeCmd !(GovernanceActionUpdateCommitteeCmdArgs era)
| GovernanceActionCreateNoConfidenceCmd !(GovernanceActionCreateNoConfidenceCmdArgs era)
| GovernanceActionProtocolParametersUpdateCmd !(GovernanceActionProtocolParametersUpdateCmdArgs era)
| GovernanceActionTreasuryWithdrawalCmd !(GovernanceActionTreasuryWithdrawalCmdArgs era)
| GovernanceActionInfoCmd !(GovernanceActionInfoCmdArgs era)
| GovernanceActionViewCmd !(GovernanceActionViewCmdArgs era)
deriving Show

data GoveranceActionUpdateCommitteeCmdArgs era
= GoveranceActionUpdateCommitteeCmdArgs
data GovernanceActionUpdateCommitteeCmdArgs era
= GovernanceActionUpdateCommitteeCmdArgs
{ eon :: !(ConwayEraOnwards era)
, networkId :: !L.Network
, deposit :: !L.Coin
, returnAddress :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFile CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFile CommitteeColdKey, EpochNo)]
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey, EpochNo)]
, requiredQuorum :: !Rational
, mPrevGovernanceActionId :: !(Maybe (TxId, Word32))
, outFile :: !(File () Out)
Expand Down Expand Up @@ -175,7 +175,7 @@ renderGovernanceActionCmds = ("governance action " <>) . \case
GovernanceActionTreasuryWithdrawalCmd {} ->
"create-treasury-withdrawal"

GoveranceActionUpdateCommitteeCmd {} ->
GovernanceActionUpdateCommitteeCmd {} ->
"update-committee"

GovernanceActionCreateNoConfidenceCmd {} ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ data GovernanceCommitteeCreateHotKeyAuthorizationCertificateCmdArgs era =
data GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs era =
GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs
{ eon :: !(ConwayEraOnwards era)
, vkeyColdKeySource :: !(VerificationKeyOrHashOrFile CommitteeColdKey)
, vkeyColdKeySource :: !(VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey)
, anchor :: !(Maybe (L.Anchor (L.EraCrypto (ShelleyLedgerEra era))))
, outFile :: !(File () Out)
} deriving Show
Expand Down
4 changes: 2 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ data QueryCommitteeMembersStateCmdArgs era = QueryCommitteeMembersStateCmdArgs
, nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, networkId :: !NetworkId
, committeeColdKeys :: ![VerificationKeyOrHashOrFile CommitteeColdKey]
, committeeHotKeys :: ![VerificationKeyOrHashOrFile CommitteeHotKey]
, committeeColdKeys :: ![VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey]
, committeeHotKeys :: ![VerificationKeyOrHashOrFileOrScriptHash CommitteeHotKey]
, memberStatuses :: ![MemberStatus]
, target :: !(Consensus.Target ChainPoint)
, mOutFile :: !(Maybe (File () Out))
Expand Down
51 changes: 33 additions & 18 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -634,11 +634,15 @@ pOperatorCertIssueCounterFile =

---

pAddCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile CommitteeColdKey)
pAddCommitteeColdVerificationKeyOrHashOrFile =
pAddCommitteeColdVerificationKeySource :: Parser (VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey)
pAddCommitteeColdVerificationKeySource =
asum
[ VerificationKeyOrFile <$> pAddCommitteeColdVerificationKeyOrFile
, VerificationKeyHash <$> pAddCommitteeColdVerificationKeyHash
[ VkhfshKeyHashFile . VerificationKeyOrFile <$> pAddCommitteeColdVerificationKeyOrFile
, VkhfshKeyHashFile . VerificationKeyHash <$> pAddCommitteeColdVerificationKeyHash
, VkhfshScriptHash <$>
pScriptHash
"add-cc-cold-script-hash"
"Cold Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

pAddCommitteeColdVerificationKeyHash :: Parser (Hash CommitteeColdKey)
Expand Down Expand Up @@ -686,11 +690,26 @@ pAddCommitteeColdVerificationKeyFile =
]

---
pRemoveCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile CommitteeColdKey)
pRemoveCommitteeColdVerificationKeyOrHashOrFile =
pRemoveCommitteeColdVerificationKeySource :: Parser (VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey)
pRemoveCommitteeColdVerificationKeySource =
asum
[ VerificationKeyOrFile <$> pRemoveCommitteeColdVerificationKeyOrFile
, VerificationKeyHash <$> pRemoveCommitteeColdVerificationKeyHash
[ VkhfshKeyHashFile . VerificationKeyOrFile <$> pRemoveCommitteeColdVerificationKeyOrFile
, VkhfshKeyHashFile . VerificationKeyHash <$> pRemoveCommitteeColdVerificationKeyHash
, VkhfshScriptHash <$>
pScriptHash
"remove-cc-cold-script-hash"
"Cold Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

pScriptHash
:: String -- ^ long option name
-> String -- ^ help text
-> Parser ScriptHash
pScriptHash longOptionName helpText =
Opt.option scriptHashReader $ mconcat
[ Opt.long longOptionName
, Opt.metavar "HASH"
, Opt.help helpText
]

pRemoveCommitteeColdVerificationKeyHash :: Parser (Hash CommitteeColdKey)
Expand Down Expand Up @@ -3160,19 +3179,15 @@ pDRepHashSource =

pDRepScriptHash :: Parser ScriptHash
pDRepScriptHash =
Opt.option scriptHashReader $ mconcat
[ Opt.long "drep-script-hash"
, Opt.metavar "HASH"
, Opt.help "DRep script hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]
pScriptHash
"drep-script-hash"
"DRep script hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."

pConstitutionScriptHash :: Parser ScriptHash
pConstitutionScriptHash =
Opt.option scriptHashReader $ mconcat
[ Opt.long "constitution-script-hash"
, Opt.metavar "HASH"
, Opt.help "Constitution script hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]
pScriptHash
"constitution-script-hash"
"Constitution script hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."

pDRepVerificationKeyOrHashOrFile
:: Parser (VerificationKeyOrHashOrFile DRepKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,25 @@ pGovernanceActionUpdateCommitteeCmd era = do
pure
$ subParser "update-committee"
$ Opt.info
( Cmd.GoveranceActionUpdateCommitteeCmd
( Cmd.GovernanceActionUpdateCommitteeCmd
<$> pUpdateCommitteeCmd eon
)
$ Opt.progDesc "Create or update a new committee proposal."

pUpdateCommitteeCmd :: ()
=> ConwayEraOnwards era
-> Parser (Cmd.GoveranceActionUpdateCommitteeCmdArgs era)
-> Parser (Cmd.GovernanceActionUpdateCommitteeCmdArgs era)
pUpdateCommitteeCmd eon =
Cmd.GoveranceActionUpdateCommitteeCmdArgs eon
Cmd.GovernanceActionUpdateCommitteeCmdArgs eon
<$> pNetwork
<*> pGovActionDeposit
<*> pStakeIdentifier (Just "deposit-return")
<*> pAnchorUrl
<*> pAnchorDataHash
<*> many pRemoveCommitteeColdVerificationKeyOrHashOrFile
<*> many pRemoveCommitteeColdVerificationKeySource
<*> many
( (,)
<$> pAddCommitteeColdVerificationKeyOrHashOrFile
<$> pAddCommitteeColdVerificationKeySource
<*> pEpochNo "Committee member expiry epoch")
<*> pRational "quorum" "Quorum of the committee that is necessary for a successful vote."
<*> pPreviousGovernanceAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,19 @@ pGovernanceCommitteeCreateColdKeyResignationCertificateCmd era = do
[ "Create cold key resignation certificate for a Constitutional Committee Member"
]
where
mkParser w = GovernanceCommitteeCreateColdKeyResignationCertificateCmd <$>
(
GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs w <$>
pCommitteeColdVerificationKeyOrHashOrFile <*>
pAnchor <*>
pOutputFile
)
mkParser w =
GovernanceCommitteeCreateColdKeyResignationCertificateCmd <$>
(GovernanceCommitteeCreateColdKeyResignationCertificateCmdArgs w <$>
coldVKeyOrFileOrScriptHash <*> pAnchor <*> pOutputFile)
coldVKeyOrFileOrScriptHash =
asum
[ VkhfshKeyHashFile . VerificationKeyOrFile <$> pCommitteeColdVerificationKeyOrFile
, VkhfshKeyHashFile . VerificationKeyHash <$> pCommitteeColdVerificationKeyHash
, VkhfshScriptHash <$>
pScriptHash
"cold-script-hash"
"Cold Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

pAnchor :: Parser (Maybe (L.Anchor L.StandardCrypto))
pAnchor =
Expand Down
25 changes: 23 additions & 2 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.EraBased.Commands.Query
import Cardano.CLI.EraBased.Options.Common
import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key

import Data.Foldable
import Options.Applicative hiding (help, str)
Expand Down Expand Up @@ -388,12 +389,32 @@ pQueryGetCommitteeStateCmd era envCli = do
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> many pCommitteeColdVerificationKeyOrHashOrFile
<*> many pCommitteeHotKeyOrHashOrFile
<*> many pCommitteeColdVerificationKeyOrHashOrFileOrScriptHash
<*> many pCommitteeHotKeyOrHashOrFileOrScriptHash
<*> many pMemberStatus
<*> pTarget era
<*> optional pOutputFile

pCommitteeColdVerificationKeyOrHashOrFileOrScriptHash :: Parser (VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey)
pCommitteeColdVerificationKeyOrHashOrFileOrScriptHash =
asum
[ VkhfshKeyHashFile <$> pCommitteeColdVerificationKeyOrHashOrFile
, VkhfshScriptHash <$>
pScriptHash
"cold-script-hash"
"Cold Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

pCommitteeHotKeyOrHashOrFileOrScriptHash :: Parser (VerificationKeyOrHashOrFileOrScriptHash CommitteeHotKey)
pCommitteeHotKeyOrHashOrFileOrScriptHash =
asum
[ VkhfshKeyHashFile <$> pCommitteeHotKeyOrHashOrFile
, VkhfshScriptHash <$>
pScriptHash
"hot-script-hash"
"Hot Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

pMemberStatus :: Parser MemberStatus
pMemberStatus =
asum
Expand Down
5 changes: 2 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Address.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ makeStakeAddressRef stakeIdentifier =
StakeIdentifierVerifier stakeVerifier ->
case stakeVerifier of
StakeVerifierKey stkVkeyOrFile -> do
stakeVKeyHash <- firstExceptT AddressCmdReadKeyFileError $
newExceptT $ readVerificationKeyOrHashOrFile AsStakeKey stkVkeyOrFile

stakeVKeyHash <- modifyError AddressCmdReadKeyFileError $
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍 I've always found those firstExcepT _ $ newExceptT a bit clunky.

readVerificationKeyOrHashOrFile AsStakeKey stkVkeyOrFile
return . StakeAddressByValue $ StakeCredentialByKey stakeVKeyHash

StakeVerifierScriptFile (File fp) -> do
Expand Down
10 changes: 5 additions & 5 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/CreateTestnetData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ runGenesisKeyGenGenesisCmd
{ Cmd.verificationKeyPath
, Cmd.signingKeyPath
} = do
skey <- liftIO $ generateSigningKey AsGenesisKey
skey <- generateSigningKey AsGenesisKey
let vkey = getVerificationKey skey
firstExceptT GenesisCmdGenesisFileError . newExceptT $ do
void $ writeLazyByteStringFile signingKeyPath $ textEnvelopeToJSON (Just skeyDesc) skey
Expand All @@ -116,7 +116,7 @@ runGenesisKeyGenDelegateCmd
, Cmd.signingKeyPath
, Cmd.opCertCounterPath
} = do
skey <- liftIO $ generateSigningKey AsGenesisDelegateKey
skey <- generateSigningKey AsGenesisDelegateKey
let vkey = getVerificationKey skey
firstExceptT GenesisCmdGenesisFileError . newExceptT $ do
void $ writeLazyByteStringFile signingKeyPath
Expand All @@ -143,7 +143,7 @@ runGenesisKeyGenDelegateVRF ::
-> SigningKeyFile Out
-> ExceptT GenesisCmdError IO ()
runGenesisKeyGenDelegateVRF vkeyPath skeyPath = do
skey <- liftIO $ generateSigningKey AsVrfKey
skey <- generateSigningKey AsVrfKey
let vkey = getVerificationKey skey
firstExceptT GenesisCmdGenesisFileError . newExceptT $ do
void $ writeLazyByteStringFile skeyPath
Expand All @@ -163,7 +163,7 @@ runGenesisKeyGenUTxOCmd
{ Cmd.verificationKeyPath
, Cmd.signingKeyPath
} = do
skey <- liftIO $ generateSigningKey AsGenesisUTxOKey
skey <- generateSigningKey AsGenesisUTxOKey
let vkey = getVerificationKey skey
firstExceptT GenesisCmdGenesisFileError . newExceptT $ do
void $ writeLazyByteStringFile signingKeyPath
Expand Down Expand Up @@ -334,7 +334,7 @@ runGenesisCreateTestNetDataCmd Cmd.GenesisCreateTestNetDataCmdArgs

initialDReps :: L.Coin -> [VerificationKey DRepKey] -> ListMap (L.Credential L.DRepRole L.StandardCrypto) (L.DRepState L.StandardCrypto)
initialDReps minDeposit = ListMap.fromList . map (\c -> ( verificationKeyToDRepCredential c
, L.DRepState { L.drepExpiry = EpochNo 1000
, L.DRepState { L.drepExpiry = EpochNo 1_000
, L.drepAnchor = SNothing
, L.drepDeposit = max (L.Coin 1_000_000) minDeposit
}))
Expand Down
Loading
Loading