diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs index bb7aed140b..4714a149bb 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance/Actions.hs @@ -8,7 +8,7 @@ module Cardano.CLI.EraBased.Commands.Governance.Actions ( GovernanceActionCmds(..) - , GoveranceActionUpdateCommitteeCmdArgs(..) + , GovernanceActionUpdateCommitteeCmdArgs(..) , GovernanceActionCreateConstitutionCmdArgs(..) , GovernanceActionCreateNoConfidenceCmdArgs(..) , GovernanceActionInfoCmdArgs(..) @@ -33,7 +33,7 @@ import Data.Word data GovernanceActionCmds era = GovernanceActionCreateConstitutionCmd !(GovernanceActionCreateConstitutionCmdArgs era) - | GoveranceActionUpdateCommitteeCmd !(GoveranceActionUpdateCommitteeCmdArgs era) + | GovernanceActionUpdateCommitteeCmd !(GovernanceActionUpdateCommitteeCmdArgs era) | GovernanceActionCreateNoConfidenceCmd !(GovernanceActionCreateNoConfidenceCmdArgs era) | GovernanceActionProtocolParametersUpdateCmd !(GovernanceActionProtocolParametersUpdateCmdArgs era) | GovernanceActionTreasuryWithdrawalCmd !(GovernanceActionTreasuryWithdrawalCmdArgs era) @@ -41,16 +41,16 @@ data GovernanceActionCmds 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 :: ![VerificationKeyOrHashOrFileOrScript CommitteeColdKey] - , newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFileOrScript CommitteeColdKey, EpochNo)] + , oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey] + , newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey, EpochNo)] , requiredQuorum :: !Rational , mPrevGovernanceActionId :: !(Maybe (TxId, Word32)) , outFile :: !(File () Out) @@ -175,7 +175,7 @@ renderGovernanceActionCmds = ("governance action " <>) . \case GovernanceActionTreasuryWithdrawalCmd {} -> "create-treasury-withdrawal" - GoveranceActionUpdateCommitteeCmd {} -> + GovernanceActionUpdateCommitteeCmd {} -> "update-committee" GovernanceActionCreateNoConfidenceCmd {} -> diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs index 80bcdafd05..bca138da79 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs @@ -634,12 +634,15 @@ pOperatorCertIssueCounterFile = --- -pAddCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFileOrScript CommitteeColdKey) +pAddCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey) pAddCommitteeColdVerificationKeyOrHashOrFile = asum - [ VkhfsKeyHashFile . VerificationKeyOrFile <$> pAddCommitteeColdVerificationKeyOrFile - , VkhfsKeyHashFile . VerificationKeyHash <$> pAddCommitteeColdVerificationKeyHash - , VkhfsScript <$> pScriptFor "add-cc-cold-script-file" Nothing "Cold Native or Plutus script file" + [ 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) @@ -687,12 +690,26 @@ pAddCommitteeColdVerificationKeyFile = ] --- -pRemoveCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFileOrScript CommitteeColdKey) +pRemoveCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFileOrScriptHash CommitteeColdKey) pRemoveCommitteeColdVerificationKeyOrHashOrFile = asum - [ VkhfsKeyHashFile . VerificationKeyOrFile <$> pRemoveCommitteeColdVerificationKeyOrFile - , VkhfsKeyHashFile . VerificationKeyHash <$> pRemoveCommitteeColdVerificationKeyHash - , VkhfsScript <$> pScriptFor "remove-cc-cold-script-file" Nothing "Cold Native or Plutus script file" + [ 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) @@ -3162,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) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs index 751f983bad..581dc212f4 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance/Actions.hs @@ -105,16 +105,16 @@ 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") diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs index 7c3f4782d3..e25d1c6294 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs @@ -40,7 +40,7 @@ runGovernanceActionCmds = \case GovernanceActionTreasuryWithdrawalCmd args -> runGovernanceActionTreasuryWithdrawalCmd args - GoveranceActionUpdateCommitteeCmd args -> + GovernanceActionUpdateCommitteeCmd args -> runGovernanceActionUpdateCommitteeCmd args GovernanceActionCreateNoConfidenceCmd args -> @@ -189,10 +189,10 @@ runGovernanceActionCreateConstitutionCmd -- TODO: Conway era - After ledger bump update this function -- with the new ledger types runGovernanceActionUpdateCommitteeCmd :: () - => GoveranceActionUpdateCommitteeCmdArgs era + => GovernanceActionUpdateCommitteeCmdArgs era -> ExceptT GovernanceActionsError IO () runGovernanceActionUpdateCommitteeCmd - Cmd.GoveranceActionUpdateCommitteeCmdArgs + Cmd.GovernanceActionUpdateCommitteeCmdArgs { Cmd.eon , Cmd.networkId , Cmd.deposit @@ -215,15 +215,14 @@ runGovernanceActionUpdateCommitteeCmd { L.anchorUrl = unProposalUrl proposalUrl , L.anchorDataHash = proposalHash } - mapError' = modifyError $ either GovernanceActionsCmdScriptReadError GovernanceActionsCmdReadFileError oldCommitteeKeyHashes <- forM oldCommitteeVkeySource $ \vkeyOrHashOrTextFile -> - mapError' $ - readVerificationKeyOrHashOrFileOrScript AsCommitteeColdKey unCommitteeColdKeyHash vkeyOrHashOrTextFile + modifyError GovernanceActionsCmdReadFileError $ + readVerificaitonKeyOrHashOrFileOrScriptHash AsCommitteeColdKey unCommitteeColdKeyHash vkeyOrHashOrTextFile newCommitteeKeyHashes <- forM newCommitteeVkeySource $ \(vkeyOrHashOrTextFile, expEpoch) -> do - kh <- mapError' $ - readVerificationKeyOrHashOrFileOrScript AsCommitteeColdKey unCommitteeColdKeyHash vkeyOrHashOrTextFile + kh <- modifyError GovernanceActionsCmdReadFileError $ + readVerificaitonKeyOrHashOrFileOrScriptHash AsCommitteeColdKey unCommitteeColdKeyHash vkeyOrHashOrTextFile pure (kh, expEpoch) depositStakeCredential diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs index 4892d829dd..87f74d08dc 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceActionsError.hs @@ -14,7 +14,6 @@ data GovernanceActionsError | GovernanceActionsCmdProposalError ProposalError | GovernanceActionsCmdCostModelsError CostModelsError | GovernanceActionsCmdReadFileError (FileError InputDecodeError) - | GovernanceActionsCmdScriptReadError (FileError ScriptDecodeError) | GovernanceActionsReadStakeCredErrror StakeCredentialError | GovernanceActionsCmdReadTextEnvelopeFileError (FileError TextEnvelopeError) | GovernanceActionsCmdWriteFileError (FileError ()) @@ -31,8 +30,6 @@ instance Error GovernanceActionsError where "Cannot read constitution: " <> pshow e -- TODO Conway render this properly GovernanceActionsCmdReadFileError e -> "Cannot read file: " <> prettyError e - GovernanceActionsCmdScriptReadError e -> - "Cannot read script file: " <> prettyError e GovernanceActionsCmdReadTextEnvelopeFileError e -> "Cannot read text envelope file: " <> prettyError e GovernanceActionsCmdWriteFileError e -> diff --git a/cardano-cli/src/Cardano/CLI/Types/Key.hs b/cardano-cli/src/Cardano/CLI/Types/Key.hs index b345bee987..5c2b00688c 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Key.hs @@ -24,6 +24,8 @@ module Cardano.CLI.Types.Key , readVerificationKeyOrHashOrTextEnvFile , VerificationKeyOrHashOrFileOrScript(..) + , VerificationKeyOrHashOrFileOrScriptHash(..) + , readVerificaitonKeyOrHashOrFileOrScriptHash , PaymentVerifier(..) , StakeIdentifier(..) @@ -335,9 +337,8 @@ readDRepCredential = \case DRepHashSourceScript (ScriptHash scriptHash) -> pure (L.ScriptHashObj scriptHash) DRepHashSourceVerificationKey drepVKeyOrHashOrFile -> do - DRepKeyHash drepKeyHash <- + L.KeyHashObj . unDRepKeyHash <$> readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile - pure $ L.KeyHashObj drepKeyHash data VerificationKeyOrHashOrFileOrScript keyrole = VkhfsKeyHashFile !(VerificationKeyOrHashOrFile keyrole) @@ -346,6 +347,27 @@ data VerificationKeyOrHashOrFileOrScript keyrole deriving instance (Eq (VerificationKeyOrHashOrFile c)) => Eq (VerificationKeyOrHashOrFileOrScript c) deriving instance (Show (VerificationKeyOrHashOrFile c)) => Show (VerificationKeyOrHashOrFileOrScript c) +data VerificationKeyOrHashOrFileOrScriptHash keyrole + = VkhfshKeyHashFile !(VerificationKeyOrHashOrFile keyrole) + | VkhfshScriptHash !ScriptHash + +deriving instance (Eq (VerificationKeyOrHashOrFile c)) => Eq (VerificationKeyOrHashOrFileOrScriptHash c) +deriving instance (Show (VerificationKeyOrHashOrFile c)) => Show (VerificationKeyOrHashOrFileOrScriptHash c) + +readVerificaitonKeyOrHashOrFileOrScriptHash + :: MonadIOTransError (FileError InputDecodeError) t m + => Key keyrole + => AsType keyrole + -> (Hash keyrole -> L.KeyHash kr L.StandardCrypto) + -> VerificationKeyOrHashOrFileOrScriptHash keyrole + -> t m (L.Credential kr L.StandardCrypto) +readVerificaitonKeyOrHashOrFileOrScriptHash asType extractHash = \case + VkhfshScriptHash (ScriptHash scriptHash) -> + pure (L.ScriptHashObj scriptHash) + VkhfshKeyHashFile vKeyOrHashOrFile -> do + L.KeyHashObj . extractHash <$> + readVerificationKeyOrHashOrTextEnvFile asType vKeyOrHashOrFile + data SomeSigningKey = AByronSigningKey (SigningKey ByronKey) | APaymentSigningKey (SigningKey PaymentKey) @@ -432,4 +454,4 @@ readSigningKeyFile skFile = , FromSomeType (AsSigningKey AsStakePoolKey) AStakePoolSigningKey , FromSomeType (AsSigningKey AsVrfKey) AVrfSigningKey , FromSomeType (AsSigningKey AsKesKey) AKesSigningKey - ] \ No newline at end of file + ] diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index ed4152fdbf..e21d3e043c 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -6211,13 +6211,13 @@ Usage: cardano-cli conway governance action update-committee [ --remove-cc-cold-verification-key STRING | --remove-cc-cold-verification-key-file FILE | --remove-cc-cold-verification-key-hash STRING - | --remove-cc-cold-script-file FILE + | --remove-cc-cold-script-hash HASH ] [ ( --add-cc-cold-verification-key STRING | --add-cc-cold-verification-key-file FILE | --add-cc-cold-verification-key-hash STRING - | --add-cc-cold-script-file FILE + | --add-cc-cold-script-hash HASH ) --epoch NATURAL] --quorum RATIONAL diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli index ca75d240af..048d5f7cfc 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_action_update-committee.cli @@ -14,13 +14,13 @@ Usage: cardano-cli conway governance action update-committee [ --remove-cc-cold-verification-key STRING | --remove-cc-cold-verification-key-file FILE | --remove-cc-cold-verification-key-hash STRING - | --remove-cc-cold-script-file FILE + | --remove-cc-cold-script-hash HASH ] [ ( --add-cc-cold-verification-key STRING | --add-cc-cold-verification-key-file FILE | --add-cc-cold-verification-key-hash STRING - | --add-cc-cold-script-file FILE + | --add-cc-cold-script-hash HASH ) --epoch NATURAL] --quorum RATIONAL @@ -54,16 +54,20 @@ Available options: Filepath of the Consitutional Committee cold key. --remove-cc-cold-verification-key-hash STRING Constitutional Committee key hash (hex-encoded). - --remove-cc-cold-script-file FILE - Cold Native or Plutus script file + --remove-cc-cold-script-hash HASH + Cold Native or Plutus script file hash (hex-encoded). + Obtain it with "cardano-cli conway governance hash + script ...". --add-cc-cold-verification-key STRING Constitutional Committee cold key (hex-encoded). --add-cc-cold-verification-key-file FILE Filepath of the Consitutional Committee cold key. --add-cc-cold-verification-key-hash STRING Constitutional Committee key hash (hex-encoded). - --add-cc-cold-script-file FILE - Cold Native or Plutus script file + --add-cc-cold-script-hash HASH + Cold Native or Plutus script file hash (hex-encoded). + Obtain it with "cardano-cli conway governance hash + script ...". --epoch NATURAL Committee member expiry epoch --quorum RATIONAL Quorum of the committee that is necessary for a successful vote.