Skip to content

Commit

Permalink
Add plutus script hash support for update-committee
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Mar 18, 2024
1 parent c385dd2 commit 50f710a
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ data GoveranceActionUpdateCommitteeCmdArgs era
, returnAddress :: !StakeIdentifier
, proposalUrl :: !ProposalUrl
, proposalHash :: !(L.SafeHash L.StandardCrypto L.AnchorData)
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFile CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFile CommitteeColdKey, EpochNo)]
, oldCommitteeVkeySource :: ![VerificationKeyOrHashOrFileOrScript CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFileOrScript CommitteeColdKey, EpochNo)]
, requiredQuorum :: !Rational
, mPrevGovernanceActionId :: !(Maybe (TxId, Word32))
, outFile :: !(File () Out)
Expand Down
14 changes: 8 additions & 6 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,12 @@ pOperatorCertIssueCounterFile =

---

pAddCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile CommitteeColdKey)
pAddCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFileOrScript CommitteeColdKey)
pAddCommitteeColdVerificationKeyOrHashOrFile =
asum
[ VerificationKeyOrFile <$> pAddCommitteeColdVerificationKeyOrFile
, VerificationKeyHash <$> pAddCommitteeColdVerificationKeyHash
[ VkhfsKeyHashFile . VerificationKeyOrFile <$> pAddCommitteeColdVerificationKeyOrFile
, VkhfsKeyHashFile . VerificationKeyHash <$> pAddCommitteeColdVerificationKeyHash
, VkhfsScript <$> pScriptFor "add-cc-cold-script-file" Nothing "Cold Native or Plutus script file"
]

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

---
pRemoveCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile CommitteeColdKey)
pRemoveCommitteeColdVerificationKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFileOrScript CommitteeColdKey)
pRemoveCommitteeColdVerificationKeyOrHashOrFile =
asum
[ VerificationKeyOrFile <$> pRemoveCommitteeColdVerificationKeyOrFile
, VerificationKeyHash <$> pRemoveCommitteeColdVerificationKeyHash
[ VkhfsKeyHashFile . VerificationKeyOrFile <$> pRemoveCommitteeColdVerificationKeyOrFile
, VkhfsKeyHashFile . VerificationKeyHash <$> pRemoveCommitteeColdVerificationKeyHash
, VkhfsScript <$> pScriptFor "remove-cc-cold-script-file" Nothing "Cold Native or Plutus script file"
]

pRemoveCommitteeColdVerificationKeyHash :: Parser (Hash CommitteeColdKey)
Expand Down
12 changes: 6 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import Cardano.CLI.Types.Errors.GovernanceActionsError
import Cardano.CLI.Types.Key

import Control.Monad
import Data.Function
import GHC.IsList
import GHC.Exts (IsList (..))

runGovernanceActionCmds :: ()
=> GovernanceActionCmds era
Expand Down Expand Up @@ -216,14 +215,15 @@ runGovernanceActionUpdateCommitteeCmd
{ L.anchorUrl = unProposalUrl proposalUrl
, L.anchorDataHash = proposalHash
}
mapError' = modifyError $ either GovernanceActionsCmdScriptReadError GovernanceActionsCmdReadFileError

oldCommitteeKeyHashes <- forM oldCommitteeVkeySource $ \vkeyOrHashOrTextFile ->
modifyError GovernanceActionsCmdReadFileError $
readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey vkeyOrHashOrTextFile
mapError' $
readVerificationKeyOrHashOrFileOrScript AsCommitteeColdKey unCommitteeColdKeyHash vkeyOrHashOrTextFile

newCommitteeKeyHashes <- forM newCommitteeVkeySource $ \(vkeyOrHashOrTextFile, expEpoch) -> do
kh <- modifyError GovernanceActionsCmdReadFileError $
readVerificationKeyOrHashOrTextEnvFile AsCommitteeColdKey vkeyOrHashOrTextFile
kh <- mapError' $
readVerificationKeyOrHashOrFileOrScript AsCommitteeColdKey unCommitteeColdKeyHash vkeyOrHashOrTextFile
pure (kh, expEpoch)

depositStakeCredential
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ runGovernanceCommitteeCreateHotKeyAuthorizationCertificate
let mapError' = modifyError $ either GovernanceCommitteeCmdScriptReadError GovernanceCommitteeCmdKeyReadError
hotCred <-
mapError' $
readVerificationKeyOrHashOrFileOrScript AsCommitteeHotKey (\(CommitteeHotKeyHash kh) -> kh) vkeyHotKeySource
readVerificationKeyOrHashOrFileOrScript AsCommitteeHotKey unCommitteeHotKeyHash vkeyHotKeySource
coldCred <-
mapError' $
readVerificationKeyOrHashOrFileOrScript AsCommitteeColdKey (\(CommitteeColdKeyHash kh) -> kh) vkeyColdKeySource
readVerificationKeyOrHashOrFileOrScript AsCommitteeColdKey unCommitteeColdKeyHash vkeyColdKeySource

makeCommitteeHotKeyAuthorizationCertificate (CommitteeHotKeyAuthorizationRequirements eon coldCred hotCred)
& textEnvelopeToJSON (Just genKeyDelegCertDesc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data GovernanceActionsError
| GovernanceActionsCmdProposalError ProposalError
| GovernanceActionsCmdCostModelsError CostModelsError
| GovernanceActionsCmdReadFileError (FileError InputDecodeError)
| GovernanceActionsCmdScriptReadError (FileError ScriptDecodeError)
| GovernanceActionsReadStakeCredErrror StakeCredentialError
| GovernanceActionsCmdReadTextEnvelopeFileError (FileError TextEnvelopeError)
| GovernanceActionsCmdWriteFileError (FileError ())
Expand All @@ -30,14 +31,13 @@ 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 ->
"Cannot write file: " <> prettyError e
GovernanceActionsValueUpdateProtocolParametersNotFound (AnyShelleyBasedEra expectedShelleyEra) ->
mconcat
[ "Protocol parameters update value for " <> pshow (toCardanoEra expectedShelleyEra)
, " was not found."
]
"Protocol parameters update value for" <+> pretty expectedShelleyEra <+> "was not found."
GovernanceActionsReadStakeCredErrror e ->
prettyError e
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ hprop_golden_governanceVerifyPoll = propertyOnce $ do
, "--poll-file", pollFile
, "--tx-file", txFile
]

liftIO (readVerificationKeyOrTextEnvFile AsStakePoolKey goldenVkFile) >>= \case
Left e ->
H.failWith Nothing $ docToString $ prettyError e
H.evalIO (runExceptT $ readVerificationKeyOrTextEnvFile AsStakePoolKey goldenVkFile) >>= \case
Left e -> do
H.noteShow_ $ prettyError e
H.failure
Right vk -> do
let expected = prettyPrintJSON $ serialiseToRawBytesHexText <$> [verificationKeyHash vk]
H.assert $ expected `BSC.isInfixOf` stdout
Expand Down
2 changes: 2 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -6211,11 +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
]
[
( --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
)
--epoch NATURAL]
--quorum RATIONAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +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
]
[
( --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
)
--epoch NATURAL]
--quorum RATIONAL
Expand Down Expand Up @@ -52,12 +54,16 @@ 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
--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
--epoch NATURAL Committee member expiry epoch
--quorum RATIONAL Quorum of the committee that is necessary for a
successful vote.
Expand Down

0 comments on commit 50f710a

Please sign in to comment.