Skip to content

Commit

Permalink
Extend committee create-hot-key-authorization-certificate to suppor…
Browse files Browse the repository at this point in the history
…t scripts
  • Loading branch information
carbolymer committed Mar 13, 2024
1 parent 33599f2 commit 0896afd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
19 changes: 18 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Committee.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
11 changes: 1 addition & 10 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/DRep.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 3 additions & 10 deletions cardano-cli/src/Cardano/CLI/Read.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ())
Expand Down
8 changes: 4 additions & 4 deletions cardano-cli/src/Cardano/CLI/Types/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 0896afd

Please sign in to comment.