diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs index 33ea404b727..6304d2907b9 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Commands.hs @@ -307,7 +307,7 @@ renderQueryCmd cmd = QueryProtocolState' {} -> "query protocol-state" data GovernanceCmd - = GovernanceMIRCertificate MIRPot [VerificationKeyFile] [Lovelace] OutputFile + = GovernanceMIRCertificate MIRPot [StakeAddress] [Lovelace] OutputFile | GovernanceGenesisKeyDelegationCertificate (VerificationKeyOrHashOrFile GenesisKey) (VerificationKeyOrHashOrFile GenesisDelegateKey) diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs index 939a09fe936..8c1c954d6c1 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Parsers.hs @@ -65,7 +65,7 @@ parseShelleyCommands = , Opt.command "address" (Opt.info (AddressCmd <$> pAddressCmd) $ Opt.progDesc "Payment address commands") , Opt.command "stake-address" - (Opt.info (StakeAddressCmd <$> pStakeAddress) $ Opt.progDesc "Stake address commands") + (Opt.info (StakeAddressCmd <$> pStakeAddressCmd) $ Opt.progDesc "Stake address commands") , Opt.command "key" (Opt.info (KeyCmd <$> pKeyCmd) $ Opt.progDesc "Key utility commands") , Opt.command "transaction" @@ -199,8 +199,8 @@ pScript = ScriptFile <$> Opt.strOption <> Opt.completer (Opt.bashCompleter "file") ) -pStakeAddress :: Parser StakeAddressCmd -pStakeAddress = +pStakeAddressCmd :: Parser StakeAddressCmd +pStakeAddressCmd = asum [ subParser "key-gen" (Opt.info pStakeAddressKeyGen $ Opt.progDesc "Create a stake address key pair") @@ -737,7 +737,7 @@ pGovernanceCmd = pMIRCertificate :: Parser GovernanceCmd pMIRCertificate = GovernanceMIRCertificate <$> pMIRPot - <*> some pStakeVerificationKeyFile + <*> some pStakeAddress <*> some pRewardAmt <*> pOutputFile @@ -1779,6 +1779,14 @@ pAddress = <> Opt.help "A Cardano address" ) +pStakeAddress :: Parser StakeAddress +pStakeAddress = + Opt.option (readerFromAttoParser parseStakeAddress) + ( Opt.long "stake-address" + <> Opt.metavar "ADDRESS" + <> Opt.help "Target stake address (bech32 format)." + ) + pStakeVerificationKeyOrFile :: Parser (VerificationKeyOrFile StakeKey) pStakeVerificationKeyOrFile = VerificationKeyValue <$> pStakeVerificationKey diff --git a/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs index b2aa51434b3..2490983f60a 100644 --- a/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Shelley/Run/Governance.hs @@ -8,7 +8,7 @@ import Cardano.Prelude import qualified Data.Text as Text -import Control.Monad.Trans.Except.Extra (firstExceptT, left, newExceptT, right) +import Control.Monad.Trans.Except.Extra (firstExceptT, left, newExceptT) import Cardano.Api import Cardano.Api.Shelley @@ -62,18 +62,18 @@ runGovernanceCmd (GovernanceUpdateProposal out eNo genVKeys ppUp) = runGovernanceMIRCertificate :: Shelley.MIRPot - -> [VerificationKeyFile] - -- ^ Stake verification keys - -> [Lovelace] - -- ^ Reward amounts + -> [StakeAddress] -- ^ Stake addresses + -> [Lovelace] -- ^ Corresponding reward amounts (same length) -> OutputFile -> ExceptT ShelleyGovernanceCmdError IO () -runGovernanceMIRCertificate mirPot vKeys rwdAmts (OutputFile oFp) = do - sCreds <- mapM readStakeKeyToCred vKeys +runGovernanceMIRCertificate mirPot sAddrs rwdAmts (OutputFile oFp) = do - checkEqualKeyRewards vKeys rwdAmts + unless (length sAddrs == length rwdAmts) $ + left $ ShelleyGovernanceCmdMIRCertificateKeyRewardMistmach + oFp (length sAddrs) (length rwdAmts) - let mirCert = makeMIRCertificate mirPot (zip sCreds rwdAmts) + let sCreds = map stakeAddrToStakeCredential sAddrs + mirCert = makeMIRCertificate mirPot (zip sCreds rwdAmts) firstExceptT ShelleyGovernanceCmdTextEnvWriteError . newExceptT @@ -82,19 +82,10 @@ runGovernanceMIRCertificate mirPot vKeys rwdAmts (OutputFile oFp) = do mirCertDesc :: TextEnvelopeDescr mirCertDesc = "Move Instantaneous Rewards Certificate" - checkEqualKeyRewards :: [VerificationKeyFile] -> [Lovelace] -> ExceptT ShelleyGovernanceCmdError IO () - checkEqualKeyRewards keys rwds = do - let numVKeys = length keys - numRwdAmts = length rwds - if numVKeys == numRwdAmts - then return () else left $ ShelleyGovernanceCmdMIRCertificateKeyRewardMistmach oFp numVKeys numRwdAmts - - readStakeKeyToCred :: VerificationKeyFile -> ExceptT ShelleyGovernanceCmdError IO StakeCredential - readStakeKeyToCred (VerificationKeyFile stVKey) = do - stakeVkey <- firstExceptT ShelleyGovernanceCmdTextEnvReadError - . newExceptT - $ readFileTextEnvelope (AsVerificationKey AsStakeKey) stVKey - right . StakeCredentialByKey $ verificationKeyHash stakeVkey + --TODO: expose a pattern for StakeAddress that give us the StakeCredential + stakeAddrToStakeCredential :: StakeAddress -> StakeCredential + stakeAddrToStakeCredential (StakeAddress _ scred) = + fromShelleyStakeCredential scred runGovernanceGenesisKeyDelegationCertificate :: VerificationKeyOrHashOrFile GenesisKey diff --git a/cardano-cli/test/Test/Golden/Shelley/TextEnvelope/Certificates/MIRCertificate.hs b/cardano-cli/test/Test/Golden/Shelley/TextEnvelope/Certificates/MIRCertificate.hs index 1f34e521402..15f531f76a3 100644 --- a/cardano-cli/test/Test/Golden/Shelley/TextEnvelope/Certificates/MIRCertificate.hs +++ b/cardano-cli/test/Test/Golden/Shelley/TextEnvelope/Certificates/MIRCertificate.hs @@ -36,11 +36,12 @@ golden_shelleyMIRCertificate = propertyOnce . H.moduleWorkspace "tmp" $ \tempDir H.assertFilesExist [verKey, signKey] + let testAddr = "stake1u9j6axhcpd0exvrthn5dqzqt54g85akqvkn4uqmccm70qsc5hpv9w" -- Create MIR certificate void $ execCardanoCLI [ "governance","create-mir-certificate" , "--reserves" --TODO: Should also do "--reserves" - , "--stake-verification-key-file", verKey + , "--stake-address", testAddr , "--reward", "1000" , "--out-file", mirCertificate ]