Skip to content

Commit

Permalink
Use plutus script hash instead of plutus script for update-committee
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Mar 19, 2024
1 parent 4f423d5 commit 7d65f7d
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 50 deletions.
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 :: ![VerificationKeyOrHashOrFileOrScript CommitteeColdKey]
, newCommitteeVkeySource :: ![(VerificationKeyOrHashOrFileOrScript 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
49 changes: 31 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,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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
15 changes: 7 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ runGovernanceActionCmds = \case
GovernanceActionTreasuryWithdrawalCmd args ->
runGovernanceActionTreasuryWithdrawalCmd args

GoveranceActionUpdateCommitteeCmd args ->
GovernanceActionUpdateCommitteeCmd args ->
runGovernanceActionUpdateCommitteeCmd args

GovernanceActionCreateNoConfidenceCmd args ->
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ data GovernanceActionsError
| GovernanceActionsCmdProposalError ProposalError
| GovernanceActionsCmdCostModelsError CostModelsError
| GovernanceActionsCmdReadFileError (FileError InputDecodeError)
| GovernanceActionsCmdScriptReadError (FileError ScriptDecodeError)
| GovernanceActionsReadStakeCredErrror StakeCredentialError
| GovernanceActionsCmdReadTextEnvelopeFileError (FileError TextEnvelopeError)
| GovernanceActionsCmdWriteFileError (FileError ())
Expand All @@ -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 ->
Expand Down
28 changes: 25 additions & 3 deletions cardano-cli/src/Cardano/CLI/Types/Key.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Cardano.CLI.Types.Key
, readVerificationKeyOrHashOrTextEnvFile

, VerificationKeyOrHashOrFileOrScript(..)
, VerificationKeyOrHashOrFileOrScriptHash(..)
, readVerificaitonKeyOrHashOrFileOrScriptHash

, PaymentVerifier(..)
, StakeIdentifier(..)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -432,4 +454,4 @@ readSigningKeyFile skFile =
, FromSomeType (AsSigningKey AsStakePoolKey) AStakePoolSigningKey
, FromSomeType (AsSigningKey AsVrfKey) AVrfSigningKey
, FromSomeType (AsSigningKey AsKesKey) AKesSigningKey
]
]
4 changes: 2 additions & 2 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7d65f7d

Please sign in to comment.