From 0896afdd20deae69805e66d9c021777b116f3940 Mon Sep 17 00:00:00 2001 From: Mateusz Galazyn Date: Fri, 8 Mar 2024 17:07:48 +0100 Subject: [PATCH] Extend committee `create-hot-key-authorization-certificate` to support scripts --- .../CLI/EraBased/Run/Governance/Committee.hs | 19 ++++++++++++++++++- .../CLI/EraBased/Run/Governance/DRep.hs | 11 +---------- cardano-cli/src/Cardano/CLI/Read.hs | 13 +++---------- .../Types/Errors/GovernanceCommitteeError.hs | 3 +++ cardano-cli/src/Cardano/CLI/Types/Key.hs | 8 ++++---- 5 files changed, 29 insertions(+), 25 deletions(-) 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 9295fa78ee..8399055958 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs @@ -9,10 +9,12 @@ module Cardano.CLI.EraBased.Run.Governance.Committee ) where import Cardano.Api +import qualified Cardano.Api.Ledger as L import Cardano.Api.Shelley import Cardano.CLI.EraBased.Commands.Governance.Committee import qualified Cardano.CLI.EraBased.Commands.Governance.Committee as Cmd +import Cardano.CLI.Read (readFileScriptInAnyLang) import Cardano.CLI.Types.Errors.GovernanceCommitteeError import Cardano.CLI.Types.Key import Cardano.CLI.Types.Key.VerificationKey @@ -142,6 +144,21 @@ runGovernanceCommitteeCreateHotKeyAuthorizationCertificate , Cmd.outFile = oFp } = conwayEraOnwardsConstraints eon $ do + --- + let fp = undefined :: FilePath + ScriptInAnyLang _lang hotScript <- + modifyError GovernanceCommitteeCmdScriptReadError $ + readFileScriptInAnyLang fp + + let hotCred = L.ScriptHashObj . toShelleyScriptHash $ hashScript hotScript + + ScriptInAnyLang _lang coldScript <- + modifyError GovernanceCommitteeCmdScriptReadError $ + readFileScriptInAnyLang fp + + let coldCred = L.ScriptHashObj . toShelleyScriptHash $ hashScript coldScript + + --- CommitteeColdKeyHash coldVKHash <- lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey coldVkOrHashOrFp) & onLeft (left . GovernanceCommitteeCmdKeyReadError) @@ -150,7 +167,7 @@ runGovernanceCommitteeCreateHotKeyAuthorizationCertificate lift (readVerificationKeyOrHashOrTextEnvFile AsCommitteeHotKey hotVkOrHashOrFp) & onLeft (left . GovernanceCommitteeCmdKeyReadError) - makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequirements eon coldVKHash hotVkHash) + makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequirements eon coldCred hotCred) & textEnvelopeToJSON (Just genKeyDelegCertDesc) & writeLazyByteStringFile oFp & firstExceptT GovernanceCommitteeCmdTextEnvWriteError . newExceptT diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs index 8265dde3e6..1641bfeb60 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs @@ -111,16 +111,7 @@ runGovernanceDRepRegistrationCertificateCmd , outFile } = conwayEraOnwardsConstraints w $ do - drepCred <- - case drepHashSource of - DRepHashSourceScript (ScriptHash scriptHash) -> - return $ L.ScriptHashObj scriptHash - DRepHashSourceVerificationKey drepVkeyHashSource -> do - DRepKeyHash drepKeyHash <- - firstExceptT RegistrationReadError - . newExceptT - $ readVerificationKeyOrHashOrFile AsDRepKey drepVkeyHashSource - return $ L.KeyHashObj $ conwayEraOnwardsConstraints w drepKeyHash + drepCred <- modifyError RegistrationReadError $ readDRepCredential drepHashSource let req = DRepRegistrationRequirements w drepCred deposit registrationCert = makeDrepRegistrationCertificate req mAnchor description = Just @TextEnvelopeDescr "DRep Key Registration Certificate" diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index 889a44015c..fbd2b045ba 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -1128,16 +1128,9 @@ readVoteDelegationTarget :: () -> ExceptT DelegationError IO (L.DRep L.StandardCrypto) readVoteDelegationTarget voteDelegationTarget = case voteDelegationTarget of - VoteDelegationTargetOfDRep drepHashSource -> do - drepHash <- case drepHashSource of - DRepHashSourceScript (ScriptHash scriptHash) -> - pure $ L.ScriptHashObj scriptHash - DRepHashSourceVerificationKey drepVKeyOrHashOrFile -> do - DRepKeyHash drepKeyHash <- - lift (readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile) - & onLeft (left . DelegationDRepReadError) - pure $ L.KeyHashObj drepKeyHash - pure $ L.DRepCredential drepHash + VoteDelegationTargetOfDRep drepHashSource -> + modifyError DelegationDRepReadError $ + L.DRepCredential <$> readDRepCredential drepHashSource VoteDelegationTargetOfAbstain -> pure L.DRepAlwaysAbstain VoteDelegationTargetOfNoConfidence -> diff --git a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceCommitteeError.hs b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceCommitteeError.hs index d2a1b0b2f9..ed761c12c0 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceCommitteeError.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Errors/GovernanceCommitteeError.hs @@ -6,9 +6,12 @@ module Cardano.CLI.Types.Errors.GovernanceCommitteeError import Cardano.Api +import Cardano.CLI.Types.Errors.ScriptDecodeError + data GovernanceCommitteeError = GovernanceCommitteeCmdKeyDecodeError InputDecodeError | GovernanceCommitteeCmdKeyReadError (FileError InputDecodeError) + | GovernanceCommitteeCmdScriptReadError (FileError ScriptDecodeError) | GovernanceCommitteeCmdTextEnvReadFileError (FileError TextEnvelopeError) | GovernanceCommitteeCmdTextEnvWriteError (FileError ()) | GovernanceCommitteeCmdWriteFileError (FileError ()) diff --git a/cardano-cli/src/Cardano/CLI/Types/Key.hs b/cardano-cli/src/Cardano/CLI/Types/Key.hs index f635958638..f5aabd68cd 100644 --- a/cardano-cli/src/Cardano/CLI/Types/Key.hs +++ b/cardano-cli/src/Cardano/CLI/Types/Key.hs @@ -323,16 +323,16 @@ data DRepHashSource (VerificationKeyOrHashOrFile DRepKey) deriving (Eq, Show) -readDRepCredential :: () +readDRepCredential + :: MonadIOTransError (FileError InputDecodeError) t m => DRepHashSource - -> ExceptT DelegationError IO (L.Credential 'L.DRepRole L.StandardCrypto) + -> t m (L.Credential L.DRepRole L.StandardCrypto) readDRepCredential = \case DRepHashSourceScript (ScriptHash scriptHash) -> pure (L.ScriptHashObj scriptHash) DRepHashSourceVerificationKey drepVKeyOrHashOrFile -> do DRepKeyHash drepKeyHash <- - lift (readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile) - & onLeft (left . DelegationDRepReadError) + hoistIOEither $ readVerificationKeyOrHashOrTextEnvFile AsDRepKey drepVKeyOrHashOrFile pure $ L.KeyHashObj drepKeyHash