Skip to content

Commit

Permalink
vote create: support DRep and CC script hash
Browse files Browse the repository at this point in the history
  • Loading branch information
smelc committed Mar 21, 2024
1 parent 372aa48 commit 08612cf
Show file tree
Hide file tree
Showing 4 changed files with 38 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

0 comments on commit 08612cf

Please sign in to comment.