From 70324647f7dad1f67577e2faeb41bf4d71505c4a Mon Sep 17 00:00:00 2001 From: John Ky Date: Thu, 2 Nov 2023 21:21:36 +1100 Subject: [PATCH 1/3] Move runGovernance command to Governance module --- cardano-cli/src/Cardano/CLI/EraBased/Run.hs | 43 ---------------- .../Cardano/CLI/EraBased/Run/Governance.hs | 49 ++++++++++++++++++- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs index f4b02b55f0..1907e0c9a6 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs @@ -10,17 +10,9 @@ module Cardano.CLI.EraBased.Run import Cardano.Api import Cardano.CLI.EraBased.Commands -import Cardano.CLI.EraBased.Options.Governance import Cardano.CLI.EraBased.Run.Address import Cardano.CLI.EraBased.Run.Genesis import Cardano.CLI.EraBased.Run.Governance -import Cardano.CLI.EraBased.Run.Governance.Actions -import Cardano.CLI.EraBased.Run.Governance.Committee -import Cardano.CLI.EraBased.Run.Governance.DRep -import Cardano.CLI.EraBased.Run.Governance.GenesisKeyDelegationCertificate - (runGovernanceGenesisKeyDelegationCertificate) -import Cardano.CLI.EraBased.Run.Governance.Poll (runGovernancePollCmds) -import Cardano.CLI.EraBased.Run.Governance.Vote import Cardano.CLI.EraBased.Run.Key import Cardano.CLI.EraBased.Run.Node import Cardano.CLI.EraBased.Run.Query @@ -73,38 +65,3 @@ runCmds = \case TransactionCmds cmd -> runTransactionCmds cmd & firstExceptT CmdTransactionError - -runGovernanceCmds :: () - => GovernanceCmds era - -> ExceptT CmdError IO () -runGovernanceCmds = \case - GovernanceMIRPayStakeAddressesCertificate w mirpot vKeys rewards out -> - runGovernanceMIRCertificatePayStakeAddrs w mirpot vKeys rewards out - & firstExceptT CmdGovernanceCmdError - - GovernanceMIRTransfer w ll oFp direction -> - runGovernanceMIRCertificateTransfer w ll oFp direction - & firstExceptT CmdGovernanceCmdError - - GovernanceGenesisKeyDelegationCertificate sta genVk genDelegVk vrfVk out -> - let stb = shelleyToAlonzoEraToShelleyToBabbageEra sta in - runGovernanceGenesisKeyDelegationCertificate stb genVk genDelegVk vrfVk out - & firstExceptT CmdGovernanceCmdError - - GovernanceCommitteeCmds cmds -> - runGovernanceCommitteeCmds cmds - & firstExceptT CmdGovernanceCommitteeError - - GovernanceActionCmds cmds -> - runGovernanceActionCmds cmds - & firstExceptT CmdGovernanceActionError - - GovernanceDRepCmds cmds -> - runGovernanceDRepCmds cmds - - GovernancePollCmds cmds -> - runGovernancePollCmds cmds - & firstExceptT CmdGovernanceCmdError - - GovernanceVoteCmds cmds -> - runGovernanceVoteCmds cmds diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs index 00cee1f273..8be2c0e322 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs @@ -3,11 +3,14 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} module Cardano.CLI.EraBased.Run.Governance - ( runGovernanceMIRCertificatePayStakeAddrs + ( runGovernanceCmds + + , runGovernanceMIRCertificatePayStakeAddrs , runGovernanceMIRCertificateTransfer ) where @@ -15,15 +18,59 @@ import Cardano.Api import qualified Cardano.Api.Ledger as Ledger import Cardano.Api.Shelley +import qualified Cardano.CLI.EraBased.Commands.Governance as Cmd +import Cardano.CLI.EraBased.Run.Governance.Actions +import Cardano.CLI.EraBased.Run.Governance.Committee +import Cardano.CLI.EraBased.Run.Governance.DRep +import Cardano.CLI.EraBased.Run.Governance.GenesisKeyDelegationCertificate +import Cardano.CLI.EraBased.Run.Governance.Poll +import Cardano.CLI.EraBased.Run.Governance.Vote import Cardano.CLI.Types.Common +import Cardano.CLI.Types.Errors.CmdError import Cardano.CLI.Types.Errors.GovernanceCmdError import qualified Cardano.Ledger.Shelley.TxBody as Shelley import Control.Monad import Control.Monad.Trans.Except (ExceptT) import Control.Monad.Trans.Except.Extra +import Data.Function import qualified Data.Map.Strict as Map +runGovernanceCmds :: () + => Cmd.GovernanceCmds era + -> ExceptT CmdError IO () +runGovernanceCmds = \case + Cmd.GovernanceMIRPayStakeAddressesCertificate w mirpot vKeys rewards out -> + runGovernanceMIRCertificatePayStakeAddrs w mirpot vKeys rewards out + & firstExceptT CmdGovernanceCmdError + + Cmd.GovernanceMIRTransfer w ll oFp direction -> + runGovernanceMIRCertificateTransfer w ll oFp direction + & firstExceptT CmdGovernanceCmdError + + Cmd.GovernanceGenesisKeyDelegationCertificate sta genVk genDelegVk vrfVk out -> + let stb = shelleyToAlonzoEraToShelleyToBabbageEra sta in + runGovernanceGenesisKeyDelegationCertificate stb genVk genDelegVk vrfVk out + & firstExceptT CmdGovernanceCmdError + + Cmd.GovernanceCommitteeCmds cmds -> + runGovernanceCommitteeCmds cmds + & firstExceptT CmdGovernanceCommitteeError + + Cmd.GovernanceActionCmds cmds -> + runGovernanceActionCmds cmds + & firstExceptT CmdGovernanceActionError + + Cmd.GovernanceDRepCmds cmds -> + runGovernanceDRepCmds cmds + + Cmd.GovernancePollCmds cmds -> + runGovernancePollCmds cmds + & firstExceptT CmdGovernanceCmdError + + Cmd.GovernanceVoteCmds cmds -> + runGovernanceVoteCmds cmds + runGovernanceMIRCertificatePayStakeAddrs :: ShelleyToBabbageEra era -> Shelley.MIRPot From 7e9fde64939a62a7fc0325ea4516d89f87f77739 Mon Sep 17 00:00:00 2001 From: John Ky Date: Thu, 2 Nov 2023 21:25:05 +1100 Subject: [PATCH 2/3] Add create-genesis-key-delegation-certificate command to babbage era --- .../CLI/EraBased/Commands/Governance.hs | 2 +- .../Cardano/CLI/EraBased/Run/Governance.hs | 3 +- .../cardano-cli-golden/files/golden/help.cli | 36 ++++++++++++++++++ .../files/golden/help/babbage_governance.cli | 3 ++ ...ate-genesis-key-delegation-certificate.cli | 38 +++++++++++++++++++ .../files/golden/help/latest_governance.cli | 3 ++ ...ate-genesis-key-delegation-certificate.cli | 38 +++++++++++++++++++ 7 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_create-genesis-key-delegation-certificate.cli create mode 100644 cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_create-genesis-key-delegation-certificate.cli diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs index 37df119947..5fbee54fe7 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs @@ -33,7 +33,7 @@ data GovernanceCmds era (File () Out) TransferDirection | GovernanceGenesisKeyDelegationCertificate - (ShelleyToAlonzoEra era) + (ShelleyToBabbageEra era) (VerificationKeyOrHashOrFile GenesisKey) (VerificationKeyOrHashOrFile GenesisDelegateKey) (VerificationKeyOrHashOrFile VrfKey) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs index 8be2c0e322..cb02d9695a 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs @@ -49,8 +49,7 @@ runGovernanceCmds = \case & firstExceptT CmdGovernanceCmdError Cmd.GovernanceGenesisKeyDelegationCertificate sta genVk genDelegVk vrfVk out -> - let stb = shelleyToAlonzoEraToShelleyToBabbageEra sta in - runGovernanceGenesisKeyDelegationCertificate stb genVk genDelegVk vrfVk out + runGovernanceGenesisKeyDelegationCertificate sta genVk genDelegVk vrfVk out & firstExceptT CmdGovernanceCmdError Cmd.GovernanceCommitteeCmds cmds -> diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli index 4a2b464750..a763e0f662 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -4748,6 +4748,7 @@ Usage: cardano-cli babbage genesis hash --genesis FILE Usage: cardano-cli babbage governance ( create-mir-certificate + | create-genesis-key-delegation-certificate | action | create-poll | answer-poll @@ -4792,6 +4793,23 @@ Usage: cardano-cli babbage governance create-mir-certificate transfer-to-rewards Create an MIR certificate to transfer from the treasury pot to the reserves pot +Usage: cardano-cli babbage governance create-genesis-key-delegation-certificate + ( --genesis-verification-key STRING + | --genesis-verification-key-file FILE + | --genesis-verification-key-hash STRING + ) + ( --genesis-delegate-verification-key STRING + | --genesis-delegate-verification-key-file FILE + | --genesis-delegate-verification-key-hash STRING + ) + ( --vrf-verification-key STRING + | --vrf-verification-key-file FILE + | --vrf-verification-key-hash STRING + ) + --out-file FILE + + Create a genesis key delegation certificate + Usage: cardano-cli babbage governance action create-protocol-parameters-update Governance action commands. @@ -7384,6 +7402,7 @@ Usage: cardano-cli latest genesis hash --genesis FILE Usage: cardano-cli latest governance ( create-mir-certificate + | create-genesis-key-delegation-certificate | action | create-poll | answer-poll @@ -7428,6 +7447,23 @@ Usage: cardano-cli latest governance create-mir-certificate transfer-to-rewards Create an MIR certificate to transfer from the treasury pot to the reserves pot +Usage: cardano-cli latest governance create-genesis-key-delegation-certificate + ( --genesis-verification-key STRING + | --genesis-verification-key-file FILE + | --genesis-verification-key-hash STRING + ) + ( --genesis-delegate-verification-key STRING + | --genesis-delegate-verification-key-file FILE + | --genesis-delegate-verification-key-hash STRING + ) + ( --vrf-verification-key STRING + | --vrf-verification-key-file FILE + | --vrf-verification-key-hash STRING + ) + --out-file FILE + + Create a genesis key delegation certificate + Usage: cardano-cli latest governance action create-protocol-parameters-update Governance action commands. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli index 1ca4e1eec5..12e6574c2e 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance.cli @@ -1,5 +1,6 @@ Usage: cardano-cli babbage governance ( create-mir-certificate + | create-genesis-key-delegation-certificate | action | create-poll | answer-poll @@ -14,6 +15,8 @@ Available options: Available commands: create-mir-certificate Create an MIR (Move Instantaneous Rewards) certificate + create-genesis-key-delegation-certificate + Create a genesis key delegation certificate action Governance action commands. create-poll Create an SPO poll answer-poll Answer an SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_create-genesis-key-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_create-genesis-key-delegation-certificate.cli new file mode 100644 index 0000000000..803171426b --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/babbage_governance_create-genesis-key-delegation-certificate.cli @@ -0,0 +1,38 @@ +Usage: cardano-cli babbage governance create-genesis-key-delegation-certificate + ( --genesis-verification-key STRING + | --genesis-verification-key-file FILE + | --genesis-verification-key-hash STRING + ) + ( --genesis-delegate-verification-key STRING + | --genesis-delegate-verification-key-file FILE + | --genesis-delegate-verification-key-hash STRING + ) + ( --vrf-verification-key STRING + | --vrf-verification-key-file FILE + | --vrf-verification-key-hash STRING + ) + --out-file FILE + + Create a genesis key delegation certificate + +Available options: + --genesis-verification-key STRING + Genesis verification key (hex-encoded). + --genesis-verification-key-file FILE + Filepath of the genesis verification key. + --genesis-verification-key-hash STRING + Genesis verification key hash (hex-encoded). + --genesis-delegate-verification-key STRING + Genesis delegate verification key (hex-encoded). + --genesis-delegate-verification-key-file FILE + Filepath of the genesis delegate verification key. + --genesis-delegate-verification-key-hash STRING + Genesis delegate verification key hash (hex-encoded). + --vrf-verification-key STRING + VRF verification key (Bech32 or hex-encoded). + --vrf-verification-key-file FILE + Filepath of the VRF verification key. + --vrf-verification-key-hash STRING + VRF verification key hash (hex-encoded). + --out-file FILE The output file. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli index 9833a1a374..823ba48e81 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance.cli @@ -1,5 +1,6 @@ Usage: cardano-cli latest governance ( create-mir-certificate + | create-genesis-key-delegation-certificate | action | create-poll | answer-poll @@ -14,6 +15,8 @@ Available options: Available commands: create-mir-certificate Create an MIR (Move Instantaneous Rewards) certificate + create-genesis-key-delegation-certificate + Create a genesis key delegation certificate action Governance action commands. create-poll Create an SPO poll answer-poll Answer an SPO poll diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_create-genesis-key-delegation-certificate.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_create-genesis-key-delegation-certificate.cli new file mode 100644 index 0000000000..da70f14105 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/latest_governance_create-genesis-key-delegation-certificate.cli @@ -0,0 +1,38 @@ +Usage: cardano-cli latest governance create-genesis-key-delegation-certificate + ( --genesis-verification-key STRING + | --genesis-verification-key-file FILE + | --genesis-verification-key-hash STRING + ) + ( --genesis-delegate-verification-key STRING + | --genesis-delegate-verification-key-file FILE + | --genesis-delegate-verification-key-hash STRING + ) + ( --vrf-verification-key STRING + | --vrf-verification-key-file FILE + | --vrf-verification-key-hash STRING + ) + --out-file FILE + + Create a genesis key delegation certificate + +Available options: + --genesis-verification-key STRING + Genesis verification key (hex-encoded). + --genesis-verification-key-file FILE + Filepath of the genesis verification key. + --genesis-verification-key-hash STRING + Genesis verification key hash (hex-encoded). + --genesis-delegate-verification-key STRING + Genesis delegate verification key (hex-encoded). + --genesis-delegate-verification-key-file FILE + Filepath of the genesis delegate verification key. + --genesis-delegate-verification-key-hash STRING + Genesis delegate verification key hash (hex-encoded). + --vrf-verification-key STRING + VRF verification key (Bech32 or hex-encoded). + --vrf-verification-key-file FILE + Filepath of the VRF verification key. + --vrf-verification-key-hash STRING + VRF verification key hash (hex-encoded). + --out-file FILE The output file. + -h,--help Show this help text From e8956ac799b9afd6126b06a09e751e0588bd093b Mon Sep 17 00:00:00 2001 From: John Ky Date: Thu, 2 Nov 2023 21:53:21 +1100 Subject: [PATCH 3/3] Split GovernanceMIRTransfer command constructor to two command constructors --- .../CLI/EraBased/Commands/Governance.hs | 16 +++--- .../CLI/EraBased/Options/Governance.hs | 21 ++++---- .../Cardano/CLI/EraBased/Run/Governance.hs | 53 ++++++++++++------- .../Cardano/CLI/Legacy/Commands/Governance.hs | 15 +++--- cardano-cli/src/Cardano/CLI/Legacy/Options.hs | 8 ++- .../src/Cardano/CLI/Legacy/Run/Governance.hs | 23 +++++--- 6 files changed, 81 insertions(+), 55 deletions(-) diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs index 5fbee54fe7..7452918f85 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs @@ -15,23 +15,25 @@ import Cardano.CLI.EraBased.Commands.Governance.Committee import Cardano.CLI.EraBased.Commands.Governance.DRep import Cardano.CLI.EraBased.Commands.Governance.Poll import Cardano.CLI.EraBased.Commands.Governance.Vote -import Cardano.CLI.Types.Common import Cardano.CLI.Types.Key (VerificationKeyOrHashOrFile) import Data.Text (Text) data GovernanceCmds era - = GovernanceMIRPayStakeAddressesCertificate + = GovernanceCreateMirCertificateStakeAddressesCmd (ShelleyToBabbageEra era) MIRPot [StakeAddress] [Lovelace] (File () Out) - | GovernanceMIRTransfer + | GovernanceCreateMirCertificateTransferToTreasuryCmd + (ShelleyToBabbageEra era) + Lovelace + (File () Out) + | GovernanceCreateMirCertificateTransferToReservesCmd (ShelleyToBabbageEra era) Lovelace (File () Out) - TransferDirection | GovernanceGenesisKeyDelegationCertificate (ShelleyToBabbageEra era) (VerificationKeyOrHashOrFile GenesisKey) @@ -51,11 +53,11 @@ data GovernanceCmds era renderGovernanceCmds :: GovernanceCmds era -> Text renderGovernanceCmds = \case - GovernanceMIRPayStakeAddressesCertificate {} -> + GovernanceCreateMirCertificateStakeAddressesCmd {} -> "governance create-mir-certificate stake-addresses" - GovernanceMIRTransfer _ _ _ TransferToTreasury -> + GovernanceCreateMirCertificateTransferToTreasuryCmd {} -> "governance create-mir-certificate transfer-to-treasury" - GovernanceMIRTransfer _ _ _ TransferToReserves -> + GovernanceCreateMirCertificateTransferToReservesCmd {} -> "governance create-mir-certificate transfer-to-reserves" GovernanceGenesisKeyDelegationCertificate {} -> "governance create-genesis-key-delegation-certificate" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs index 54e6d224e4..9ede4ecc02 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs @@ -16,7 +16,6 @@ import Cardano.CLI.EraBased.Options.Governance.Committee import Cardano.CLI.EraBased.Options.Governance.DRep import Cardano.CLI.EraBased.Options.Governance.Poll import Cardano.CLI.EraBased.Options.Governance.Vote -import Cardano.CLI.Types.Common import Data.Foldable import Options.Applicative @@ -58,10 +57,10 @@ mirCertParsers w = $ Opt.info (pMIRPayStakeAddresses w) $ Opt.progDesc "Create an MIR certificate to pay stake addresses" , subParser "transfer-to-treasury" - $ Opt.info (pMIRTransferToTreasury w) + $ Opt.info (pGovernanceCreateMirCertificateTransferToTreasuryCmd w) $ Opt.progDesc "Create an MIR certificate to transfer from the reserves pot to the treasury pot" , subParser "transfer-to-rewards" - $ Opt.info (pMIRTransferToReserves w) + $ Opt.info (pGovernanceCreateMirCertificateTransferToReservesCmd w) $ Opt.progDesc "Create an MIR certificate to transfer from the treasury pot to the reserves pot" ] @@ -69,29 +68,27 @@ pMIRPayStakeAddresses :: () => ShelleyToBabbageEra era -> Parser (GovernanceCmds era) pMIRPayStakeAddresses w = - GovernanceMIRPayStakeAddressesCertificate w + GovernanceCreateMirCertificateStakeAddressesCmd w <$> pMIRPot <*> some pStakeAddress <*> some pRewardAmt <*> pOutputFile -pMIRTransferToTreasury :: () +pGovernanceCreateMirCertificateTransferToTreasuryCmd :: () => ShelleyToBabbageEra era -> Parser (GovernanceCmds era) -pMIRTransferToTreasury w = - GovernanceMIRTransfer w +pGovernanceCreateMirCertificateTransferToTreasuryCmd w = + GovernanceCreateMirCertificateTransferToTreasuryCmd w <$> pTransferAmt <*> pOutputFile - <*> pure TransferToTreasury -pMIRTransferToReserves :: () +pGovernanceCreateMirCertificateTransferToReservesCmd :: () => ShelleyToBabbageEra era -> Parser (GovernanceCmds era) -pMIRTransferToReserves w = - GovernanceMIRTransfer w +pGovernanceCreateMirCertificateTransferToReservesCmd w = + GovernanceCreateMirCertificateTransferToReservesCmd w <$> pTransferAmt <*> pOutputFile - <*> pure TransferToReserves pGovernanceGenesisKeyDelegationCertificate :: () => CardanoEra era diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs index cb02d9695a..07ebf622ef 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs @@ -11,7 +11,8 @@ module Cardano.CLI.EraBased.Run.Governance ( runGovernanceCmds , runGovernanceMIRCertificatePayStakeAddrs - , runGovernanceMIRCertificateTransfer + , runGovernanceCreateMirCertificateTransferToTreasuryCmd + , runGovernanceCreateMirCertificateTransferToReservesCmd ) where import Cardano.Api @@ -25,7 +26,6 @@ import Cardano.CLI.EraBased.Run.Governance.DRep import Cardano.CLI.EraBased.Run.Governance.GenesisKeyDelegationCertificate import Cardano.CLI.EraBased.Run.Governance.Poll import Cardano.CLI.EraBased.Run.Governance.Vote -import Cardano.CLI.Types.Common import Cardano.CLI.Types.Errors.CmdError import Cardano.CLI.Types.Errors.GovernanceCmdError import qualified Cardano.Ledger.Shelley.TxBody as Shelley @@ -40,12 +40,16 @@ runGovernanceCmds :: () => Cmd.GovernanceCmds era -> ExceptT CmdError IO () runGovernanceCmds = \case - Cmd.GovernanceMIRPayStakeAddressesCertificate w mirpot vKeys rewards out -> + Cmd.GovernanceCreateMirCertificateStakeAddressesCmd w mirpot vKeys rewards out -> runGovernanceMIRCertificatePayStakeAddrs w mirpot vKeys rewards out & firstExceptT CmdGovernanceCmdError - Cmd.GovernanceMIRTransfer w ll oFp direction -> - runGovernanceMIRCertificateTransfer w ll oFp direction + Cmd.GovernanceCreateMirCertificateTransferToTreasuryCmd w ll oFp -> + runGovernanceCreateMirCertificateTransferToTreasuryCmd w ll oFp + & firstExceptT CmdGovernanceCmdError + + Cmd.GovernanceCreateMirCertificateTransferToReservesCmd w ll oFp -> + runGovernanceCreateMirCertificateTransferToReservesCmd w ll oFp & firstExceptT CmdGovernanceCmdError Cmd.GovernanceGenesisKeyDelegationCertificate sta genVk genDelegVk vrfVk out -> @@ -100,27 +104,40 @@ runGovernanceMIRCertificatePayStakeAddrs w mirPot sAddrs rwdAmts oFp = do mirCertDesc :: TextEnvelopeDescr mirCertDesc = "Move Instantaneous Rewards Certificate" -runGovernanceMIRCertificateTransfer - :: ShelleyToBabbageEra era +runGovernanceCreateMirCertificateTransferToTreasuryCmd :: () + => ShelleyToBabbageEra era -> Lovelace -> File () Out - -> TransferDirection -> ExceptT GovernanceCmdError IO () -runGovernanceMIRCertificateTransfer w ll oFp direction = do +runGovernanceCreateMirCertificateTransferToTreasuryCmd w ll oFp = do let mirTarget = Ledger.SendToOppositePotMIR (toShelleyLovelace ll) - let mirCert = - makeMIRCertificate $ - case direction of - TransferToReserves -> MirCertificateRequirements w Ledger.TreasuryMIR mirTarget - TransferToTreasury -> MirCertificateRequirements w Ledger.ReservesMIR mirTarget + let mirCert = makeMIRCertificate $ MirCertificateRequirements w Ledger.ReservesMIR mirTarget firstExceptT GovernanceCmdTextEnvWriteError . newExceptT $ shelleyBasedEraConstraints (shelleyToBabbageEraToShelleyBasedEra w) $ writeLazyByteStringFile oFp - $ textEnvelopeToJSON (Just $ mirCertDesc direction) mirCert + $ textEnvelopeToJSON (Just mirCertDesc) mirCert where - mirCertDesc :: TransferDirection -> TextEnvelopeDescr - mirCertDesc TransferToTreasury = "MIR Certificate Send To Treasury" - mirCertDesc TransferToReserves = "MIR Certificate Send To Reserves" + mirCertDesc :: TextEnvelopeDescr + mirCertDesc = "MIR Certificate Send To Treasury" + +runGovernanceCreateMirCertificateTransferToReservesCmd :: () + => ShelleyToBabbageEra era + -> Lovelace + -> File () Out + -> ExceptT GovernanceCmdError IO () +runGovernanceCreateMirCertificateTransferToReservesCmd w ll oFp = do + let mirTarget = Ledger.SendToOppositePotMIR (toShelleyLovelace ll) + + let mirCert = makeMIRCertificate $ MirCertificateRequirements w Ledger.TreasuryMIR mirTarget + + firstExceptT GovernanceCmdTextEnvWriteError + . newExceptT + $ shelleyBasedEraConstraints (shelleyToBabbageEraToShelleyBasedEra w) + $ writeLazyByteStringFile oFp + $ textEnvelopeToJSON (Just mirCertDesc) mirCert + where + mirCertDesc :: TextEnvelopeDescr + mirCertDesc = "MIR Certificate Send To Reserves" diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs index 8d7b512971..0268cdb1e7 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs @@ -13,17 +13,20 @@ import Cardano.CLI.Types.Key import Data.Text (Text) data LegacyGovernanceCmds - = GovernanceMIRPayStakeAddressesCertificate + = GovernanceCreateMirCertificateStakeAddressesCmd (EraInEon ShelleyToBabbageEra) MIRPot [StakeAddress] [Lovelace] (File () Out) - | GovernanceMIRTransfer + | GovernanceCreateMirCertificateTransferToTreasuryCmd + (EraInEon ShelleyToBabbageEra) + Lovelace + (File () Out) + | GovernanceCreateMirCertificateTransferToReservesCmd (EraInEon ShelleyToBabbageEra) Lovelace (File () Out) - TransferDirection | GovernanceGenesisKeyDelegationCertificate (EraInEon ShelleyToBabbageEra) (VerificationKeyOrHashOrFile GenesisKey) @@ -53,9 +56,9 @@ data LegacyGovernanceCmds renderLegacyGovernanceCmds :: LegacyGovernanceCmds -> Text renderLegacyGovernanceCmds = \case GovernanceGenesisKeyDelegationCertificate {} -> "governance create-genesis-key-delegation-certificate" - GovernanceMIRPayStakeAddressesCertificate {} -> "governance create-mir-certificate stake-addresses" - GovernanceMIRTransfer _ _ _ TransferToTreasury -> "governance create-mir-certificate transfer-to-treasury" - GovernanceMIRTransfer _ _ _ TransferToReserves -> "governance create-mir-certificate transfer-to-reserves" + GovernanceCreateMirCertificateStakeAddressesCmd {} -> "governance create-mir-certificate stake-addresses" + GovernanceCreateMirCertificateTransferToTreasuryCmd {} -> "governance create-mir-certificate transfer-to-treasury" + GovernanceCreateMirCertificateTransferToReservesCmd {} -> "governance create-mir-certificate transfer-to-reserves" GovernanceUpdateProposal {} -> "governance create-update-proposal" GovernanceCreatePoll{} -> "governance create-poll" GovernanceAnswerPoll{} -> "governance answer-poll" diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs index 95bf1f8eb2..6552ce06f1 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Options.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Options.hs @@ -829,7 +829,7 @@ pGovernanceCmds envCli = pLegacyMIRPayStakeAddresses :: Parser LegacyGovernanceCmds pLegacyMIRPayStakeAddresses = - GovernanceMIRPayStakeAddressesCertificate + GovernanceCreateMirCertificateStakeAddressesCmd <$> pAnyShelleyToBabbageEra envCli <*> pMIRPot <*> some pStakeAddress @@ -838,19 +838,17 @@ pGovernanceCmds envCli = pLegacyMIRTransferToTreasury :: Parser LegacyGovernanceCmds pLegacyMIRTransferToTreasury = - GovernanceMIRTransfer + GovernanceCreateMirCertificateTransferToTreasuryCmd <$> pAnyShelleyToBabbageEra envCli <*> pTransferAmt <*> pOutputFile - <*> pure TransferToTreasury pLegacyMIRTransferToReserves :: Parser LegacyGovernanceCmds pLegacyMIRTransferToReserves = - GovernanceMIRTransfer + GovernanceCreateMirCertificateTransferToReservesCmd <$> pAnyShelleyToBabbageEra envCli <*> pTransferAmt <*> pOutputFile - <*> pure TransferToReserves pGovernanceGenesisKeyDelegationCertificate :: Parser LegacyGovernanceCmds pGovernanceGenesisKeyDelegationCertificate = diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs index 845827954a..9a1c5ea27d 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Run/Governance.hs @@ -33,10 +33,12 @@ import qualified Data.Text as Text runLegacyGovernanceCmds :: LegacyGovernanceCmds -> ExceptT GovernanceCmdError IO () runLegacyGovernanceCmds = \case - GovernanceMIRPayStakeAddressesCertificate anyEra mirpot vKeys rewards out -> + GovernanceCreateMirCertificateStakeAddressesCmd anyEra mirpot vKeys rewards out -> runLegacyGovernanceMIRCertificatePayStakeAddrs anyEra mirpot vKeys rewards out - GovernanceMIRTransfer anyEra amt out direction -> do - runLegacyGovernanceMIRCertificateTransfer anyEra amt out direction + GovernanceCreateMirCertificateTransferToTreasuryCmd anyEra amt out -> do + runLegacyGovernanceCreateMirCertificateTransferToTreasuryCmd anyEra amt out + GovernanceCreateMirCertificateTransferToReservesCmd anyEra amt out -> do + runLegacyGovernanceCreateMirCertificateTransferToReservesCmd anyEra amt out GovernanceGenesisKeyDelegationCertificate (EraInEon sbe) genVk genDelegVk vrfVk out -> runGovernanceGenesisKeyDelegationCertificate sbe genVk genDelegVk vrfVk out GovernanceUpdateProposal out eNo genVKeys ppUp mCostModelFp -> @@ -102,14 +104,21 @@ runLegacyGovernanceMIRCertificatePayStakeAddrs runLegacyGovernanceMIRCertificatePayStakeAddrs (EraInEon w) = runGovernanceMIRCertificatePayStakeAddrs w -runLegacyGovernanceMIRCertificateTransfer +runLegacyGovernanceCreateMirCertificateTransferToTreasuryCmd :: EraInEon ShelleyToBabbageEra -> Lovelace -> File () Out - -> TransferDirection -> ExceptT GovernanceCmdError IO () -runLegacyGovernanceMIRCertificateTransfer (EraInEon w) = - runGovernanceMIRCertificateTransfer w +runLegacyGovernanceCreateMirCertificateTransferToTreasuryCmd (EraInEon w) = + runGovernanceCreateMirCertificateTransferToTreasuryCmd w + +runLegacyGovernanceCreateMirCertificateTransferToReservesCmd + :: EraInEon ShelleyToBabbageEra + -> Lovelace + -> File () Out + -> ExceptT GovernanceCmdError IO () +runLegacyGovernanceCreateMirCertificateTransferToReservesCmd (EraInEon w) = + runGovernanceCreateMirCertificateTransferToReservesCmd w runLegacyGovernanceUpdateProposal :: File () Out