Skip to content

Commit

Permalink
Merge pull request #665 from IntersectMBO/smelc/voting-script-cc-dreps
Browse files Browse the repository at this point in the history
vote create: support DRep and CC script hash
  • Loading branch information
smelc authored Mar 21, 2024
2 parents 372aa48 + 921db76 commit 8def78a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 30 deletions.
33 changes: 24 additions & 9 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ pRemoveCommitteeColdVerificationKeyHash =
where
deserialiseFromHex :: String -> Either String (Hash CommitteeColdKey)
deserialiseFromHex =
first (\e -> docToString $ "Invalid Consitutional Committee cold key hash: " <> prettyError e)
first (\e -> docToString $ "Invalid Constitutional Committee cold key hash: " <> prettyError e)
. deserialiseFromRawBytesHex (AsHash AsCommitteeColdKey)
. BSC.pack

Expand Down Expand Up @@ -897,17 +897,11 @@ pCommitteeHotKeyHash prefix =
. deserialiseFromRawBytesHex (AsHash AsCommitteeHotKey)
. BSC.pack

pCommitteeHotKeyOrFile :: Parser (VerificationKeyOrFile CommitteeHotKey)
pCommitteeHotKeyOrFile =
asum
[ VerificationKeyValue <$> pCommitteeHotKey
, VerificationKeyFilePath <$> pCommitteeHotKeyFile
]

pCommitteeHotKeyOrHashOrFile :: Parser (VerificationKeyOrHashOrFile CommitteeHotKey)
pCommitteeHotKeyOrHashOrFile =
asum
[ VerificationKeyOrFile <$> pCommitteeHotKeyOrFile
[ VerificationKeyOrFile . VerificationKeyValue <$> pCommitteeHotKey
, VerificationKeyOrFile . VerificationKeyFilePath <$> pCommitteeHotKeyFile
, VerificationKeyHash <$> pCommitteeHotKeyHash Nothing
]

Expand All @@ -919,6 +913,16 @@ pCommitteeHotVerificationKeyOrHashOrVerificationFile =
VerificationKeyHash <$> pCommitteeHotKeyHash (Just "cc")
]

pCommitteeHotVerificationKeyOrHashOrVerificationFileOrScriptHash :: Parser (VerificationKeyOrHashOrFileOrScriptHash CommitteeHotKey)
pCommitteeHotVerificationKeyOrHashOrVerificationFileOrScriptHash =
asum
[ VkhfshKeyHashFile <$> pCommitteeHotVerificationKeyOrHashOrVerificationFile
, VkhfshScriptHash <$>
pScriptHash
"cc-hot-script-hash"
"Cold Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

catCommands :: [Parser a] -> Maybe (Parser a)
catCommands = \case
[] -> Nothing
Expand Down Expand Up @@ -3197,6 +3201,17 @@ pDRepVerificationKeyOrHashOrFile =
, VerificationKeyHash <$> pDRepVerificationKeyHash
]

pDRepVerificationKeyOrHashOrFileOrScriptHash :: Parser (VerificationKeyOrHashOrFileOrScriptHash DRepKey)
pDRepVerificationKeyOrHashOrFileOrScriptHash =
asum
[ VkhfshKeyHashFile . VerificationKeyOrFile <$> pDRepVerificationKeyOrFile
, VkhfshKeyHashFile . VerificationKeyHash <$> pDRepVerificationKeyHash
, VkhfshScriptHash <$>
pScriptHash
"drep-script-hash"
"Cold Native or Plutus script file hash (hex-encoded). Obtain it with \"cardano-cli conway governance hash script ...\"."
]

pAllOrOnlyDRepVerificationKeyOrHashOrFile
:: Parser (AllOrOnly (VerificationKeyOrHashOrFile DRepKey))
pAllOrOnlyDRepVerificationKeyOrHashOrFile = pAll <|> pOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ pGovernanceVoteCreateCmdArgs cOnwards =

pAnyVotingStakeVerificationKeyOrHashOrFile :: Parser AnyVotingStakeVerificationKeyOrHashOrFile
pAnyVotingStakeVerificationKeyOrHashOrFile =
asum [ AnyDRepVerificationKeyOrHashOrFile <$> pDRepVerificationKeyOrHashOrFile
asum [ AnyDRepVerificationKeyOrHashOrFileOrScriptHash <$> pDRepVerificationKeyOrHashOrFileOrScriptHash
, AnyStakePoolVerificationKeyOrHashOrFile <$> pStakePoolVerificationKeyOrHashOrFile Nothing
, AnyCommitteeHotVerificationKeyOrHashOrFile <$> pCommitteeHotVerificationKeyOrHashOrVerificationFile
, AnyCommitteeHotVerificationKeyOrHashOrFileOrScriptHash <$> pCommitteeHotVerificationKeyOrHashOrVerificationFileOrScriptHash
]

pGovernanceVoteViewCmd :: ()
Expand Down
12 changes: 6 additions & 6 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Governance/Vote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ runGovernanceVoteCreateCmd

shelleyBasedEraConstraints sbe $ do
voter <- firstExceptT GovernanceVoteCmdReadVerificationKeyError $ case votingStakeCredentialSource of
AnyDRepVerificationKeyOrHashOrFile stake -> do
DRepKeyHash h <- readVerificationKeyOrHashOrTextEnvFile AsDRepKey stake
pure $ L.DRepVoter $ L.KeyHashObj h
AnyDRepVerificationKeyOrHashOrFileOrScriptHash stake -> do
drepCred <- readVerificationKeyOrHashOrFileOrScriptHash AsDRepKey unDRepKeyHash stake
pure $ L.DRepVoter drepCred

AnyStakePoolVerificationKeyOrHashOrFile stake -> do
StakePoolKeyHash h <- readVerificationKeyOrHashOrTextEnvFile AsStakePoolKey stake
pure $ L.StakePoolVoter h

AnyCommitteeHotVerificationKeyOrHashOrFile stake -> do
CommitteeHotKeyHash h <- readVerificationKeyOrHashOrTextEnvFile AsCommitteeHotKey stake
pure $ L.CommitteeVoter $ L.KeyHashObj h
AnyCommitteeHotVerificationKeyOrHashOrFileOrScriptHash stake -> do
hotCred <- readVerificationKeyOrHashOrFileOrScriptHash AsCommitteeHotKey unCommitteeHotKeyHash stake
pure $ L.CommitteeVoter hotCred

let govActIdentifier = createGovernanceActionId govActionTxId govActionIndex
votingProcedures = singletonVotingProcedures eon voter govActIdentifier (unVotingProcedure voteProcedure)
Expand Down
19 changes: 6 additions & 13 deletions cardano-cli/src/Cardano/CLI/Types/Governance.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Cardano.Api
import Cardano.Api.Shelley

import Cardano.CLI.Types.Key (DRepHashSource, VerificationKeyOrFile,
VerificationKeyOrHashOrFile)
VerificationKeyOrHashOrFile, VerificationKeyOrHashOrFileOrScriptHash)

import Data.Word

Expand All @@ -29,18 +29,11 @@ data VType = VCC -- committee
| VSP -- spo
deriving Show

data AnyVotingStakeVerificationKeyOrHashOrFile where
AnyDRepVerificationKeyOrHashOrFile
:: VerificationKeyOrHashOrFile DRepKey
-> AnyVotingStakeVerificationKeyOrHashOrFile

AnyStakePoolVerificationKeyOrHashOrFile
:: VerificationKeyOrHashOrFile StakePoolKey
-> AnyVotingStakeVerificationKeyOrHashOrFile

AnyCommitteeHotVerificationKeyOrHashOrFile
:: VerificationKeyOrHashOrFile CommitteeHotKey
-> AnyVotingStakeVerificationKeyOrHashOrFile
-- | Possible credentials for creating a vote
data AnyVotingStakeVerificationKeyOrHashOrFile =
AnyDRepVerificationKeyOrHashOrFileOrScriptHash (VerificationKeyOrHashOrFileOrScriptHash DRepKey)
| AnyStakePoolVerificationKeyOrHashOrFile (VerificationKeyOrHashOrFile StakePoolKey)
| AnyCommitteeHotVerificationKeyOrHashOrFileOrScriptHash (VerificationKeyOrHashOrFileOrScriptHash CommitteeHotKey)

data VoteDelegationTarget
= VoteDelegationTargetOfDRep DRepHashSource
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 @@ -6504,12 +6504,14 @@ Usage: cardano-cli conway governance vote create (--yes | --no | --abstain)
( --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
| --drep-script-hash HASH
| --stake-pool-verification-key STRING
| --cold-verification-key-file FILE
| --stake-pool-id STAKE_POOL_ID
| --cc-hot-verification-key STRING
| --cc-hot-verification-key-file FILE
| --cc-hot-key-hash STRING
| --cc-hot-script-hash HASH
)
[--anchor-url TEXT
--anchor-data-hash HASH]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ Usage: cardano-cli conway governance vote create (--yes | --no | --abstain)
( --drep-verification-key STRING
| --drep-verification-key-file FILE
| --drep-key-hash HASH
| --drep-script-hash HASH
| --stake-pool-verification-key STRING
| --cold-verification-key-file FILE
| --stake-pool-id STAKE_POOL_ID
| --cc-hot-verification-key STRING
| --cc-hot-verification-key-file FILE
| --cc-hot-key-hash STRING
| --cc-hot-script-hash HASH
)
[--anchor-url TEXT
--anchor-data-hash HASH]
Expand All @@ -28,6 +30,9 @@ Available options:
Filepath of the DRep verification key.
--drep-key-hash HASH DRep verification key hash (either Bech32-encoded or
hex-encoded).
--drep-script-hash HASH Cold Native or Plutus script file hash (hex-encoded).
Obtain it with "cardano-cli conway governance hash
script ...".
--stake-pool-verification-key STRING
Stake pool verification key (Bech32 or hex-encoded).
--cold-verification-key-file FILE
Expand All @@ -40,6 +45,10 @@ Available options:
--cc-hot-verification-key-file FILE
Filepath of the Consitutional Committee hot key.
--cc-hot-key-hash STRING Constitutional Committee key hash (hex-encoded).
--cc-hot-script-hash HASH
Cold Native or Plutus script file hash (hex-encoded).
Obtain it with "cardano-cli conway governance hash
script ...".
--anchor-url TEXT Vote anchor URL
--anchor-data-hash HASH Hash of the vote anchor data (obtain it with
"cardano-cli conway governance hash anchor-data
Expand Down

0 comments on commit 8def78a

Please sign in to comment.