diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 734834136b..b1f695e6b4 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -20,7 +20,7 @@ jobs: env: # Modify this value to "invalidate" the cabal cache. - CABAL_CACHE_VERSION: "2023-07-28" + CABAL_CACHE_VERSION: "2023-08-14" concurrency: group: > diff --git a/Setup.hs b/Setup.hs deleted file mode 100644 index 44671092b2..0000000000 --- a/Setup.hs +++ /dev/null @@ -1,2 +0,0 @@ -import Distribution.Simple -main = defaultMain diff --git a/cardano-cli/cardano-cli.cabal b/cardano-cli/cardano-cli.cabal index 3dcfce5511..a5edd549b9 100644 --- a/cardano-cli/cardano-cli.cabal +++ b/cardano-cli/cardano-cli.cabal @@ -298,6 +298,7 @@ test-suite cardano-cli-golden Test.Golden.Byron.Witness Test.Golden.ErrorsSpec Test.Golden.Governance.Committee + Test.Golden.Governance.DRep Test.Golden.Help Test.Golden.Key.NonExtendedKey Test.Golden.Shelley.Address.Build diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs index 7c3d51cd80..989d6d4d5d 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Commands/Governance.hs @@ -46,6 +46,10 @@ data EraBasedGovernanceCmds era (GovernanceCommitteeCmds era) | EraBasedGovernanceActionCmds (GovernanceActionCmds era) + | EraBasedGovernanceDRepGenerateKey + (ConwayEraOnwards era) + (File (VerificationKey ()) Out) + (File (SigningKey ()) Out) renderEraBasedGovernanceCmds :: EraBasedGovernanceCmds era -> Text renderEraBasedGovernanceCmds = \case @@ -69,3 +73,4 @@ renderEraBasedGovernanceCmds = \case renderGovernanceCommitteeCmds cmds EraBasedGovernanceActionCmds cmds -> renderGovernanceActionCmds cmds + EraBasedGovernanceDRepGenerateKey{} -> "governance drep key-gen" diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs index 62cb1cbd64..52201df6ae 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Options/Governance.hs @@ -36,6 +36,7 @@ pEraBasedGovernanceCmds envCli era = , pCreateMirCertificatesCmds era , pGovernanceCommitteeCmds era <&> fmap EraBasedGovernanceCommitteeCmds , fmap EraBasedGovernanceActionCmds <$> pGovernanceActionCmds era + , pDRepCommands era ] @@ -297,3 +298,18 @@ pMIRTransferToReserves w = <*> pure TransferToReserves -------------------------------------------------------------------------------- + +pDRepCommands :: () + => CardanoEra era + -> Maybe (Parser (EraBasedGovernanceCmds era)) +pDRepCommands era = do + w <- maybeFeatureInEra era + pure $ + subParser "drep" + $ Opt.info (pKeyGen w) + $ Opt.progDesc "Delegate Representative commands." + where + pKeyGen w = + subParser "key-gen" + $ Opt.info (EraBasedGovernanceDRepGenerateKey w <$> pVerificationKeyFileOut <*> pSigningKeyFileOut) + $ Opt.progDesc "Generate Delegate Representative verification and signing keys." diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs index b64bfb28af..f3e05a3688 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run.hs @@ -77,6 +77,11 @@ runEraBasedGovernanceCmds = \case EraBasedGovernanceActionCmds cmds -> firstExceptT (const ()) -- TODO: Conway era - fix error handling $ runGovernanceActionCmds cmds + + EraBasedGovernanceDRepGenerateKey w vrf sgn -> + firstExceptT (const ()) -- TODO: Conway era - fix error handling + $ runGovernanceDRepKeyGen w vrf sgn + runEraBasedGovernancePreConwayCmd :: ShelleyToBabbageEra era -> ExceptT () IO () diff --git a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs index 0178c39939..09324cae64 100644 --- a/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/EraBased/Run/Governance.hs @@ -3,6 +3,7 @@ module Cardano.CLI.EraBased.Run.Governance ( runGovernanceMIRCertificatePayStakeAddrs , runGovernanceMIRCertificateTransfer + , runGovernanceDRepKeyGen ) where import Cardano.Api @@ -14,6 +15,8 @@ import Cardano.CLI.Types.Common import qualified Cardano.Ledger.Shelley.TxBody as Shelley import Control.Monad + +import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans.Except (ExceptT) import Control.Monad.Trans.Except.Extra import qualified Data.Map.Strict as Map @@ -72,3 +75,19 @@ runGovernanceMIRCertificateTransfer w ll oFp direction = do mirCertDesc :: TransferDirection -> TextEnvelopeDescr mirCertDesc TransferToTreasury = "MIR Certificate Send To Treasury" mirCertDesc TransferToReserves = "MIR Certificate Send To Reserves" + +runGovernanceDRepKeyGen + :: ConwayEraOnwards era + -> VerificationKeyFile Out + -> SigningKeyFile Out + -> ExceptT GovernanceCmdError IO () +runGovernanceDRepKeyGen _w vkeyPath skeyPath = firstExceptT GovernanceCmdWriteFileError $ do + skey <- liftIO $ generateSigningKey AsDRepKey + let vkey = getVerificationKey skey + newExceptT $ writeLazyByteStringFile skeyPath (textEnvelopeToJSON (Just skeyDesc) skey) + newExceptT $ writeLazyByteStringFile vkeyPath (textEnvelopeToJSON (Just vkeyDesc) vkey) + where + skeyDesc :: TextEnvelopeDescr + skeyDesc = "Delegate Representative Signing Key" + vkeyDesc :: TextEnvelopeDescr + vkeyDesc = "Delegate Representative Verification Key" diff --git a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs index 6211419b6d..90e2f96f5d 100644 --- a/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs +++ b/cardano-cli/src/Cardano/CLI/Legacy/Commands/Governance.hs @@ -130,3 +130,4 @@ pCreateConstitution envCli = <*> pVotingCredential <*> pConstitution <*> pFileOutDirection "out-file" "Output filepath of the governance action." + diff --git a/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs new file mode 100644 index 0000000000..6d9929ce52 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/Test/Golden/Governance/DRep.hs @@ -0,0 +1,30 @@ +{- HLINT ignore "Use camelCase" -} + +module Test.Golden.Governance.DRep where + +import Control.Monad (void) + +import Test.Cardano.CLI.Util + +import Hedgehog (Property) +import qualified Hedgehog.Extras.Test.Base as H +import qualified Hedgehog.Extras.Test.File as H + +hprop_golden_governanceDRepKeyGen :: Property +hprop_golden_governanceDRepKeyGen = + propertyOnce . H.moduleWorkspace "tmp" $ \tempDir -> do + verificationKeyFile <- noteTempFile tempDir "key-gen.vkey" + signingKeyFile <- noteTempFile tempDir "key-gen.skey" + + void $ execCardanoCLI + [ "conway", "governance", "drep", "key-gen" + , "--verification-key-file", verificationKeyFile + , "--signing-key-file", signingKeyFile + ] + + H.assertFileOccurences 1 "DRepVerificationKey_ed25519" verificationKeyFile + H.assertFileOccurences 1 "DRepSigningKey_ed25519" signingKeyFile + + H.assertFileOccurences 1 "Delegate Representative Verification Key" verificationKeyFile + H.assertFileOccurences 1 "Delegate Representative Signing Key" signingKeyFile + 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 3c7c58a798..5716f8befb 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help.cli @@ -519,6 +519,7 @@ Usage: cardano-cli conway governance | vote | committee | action + | drep ) Era-based governance commands @@ -649,6 +650,15 @@ Usage: cardano-cli conway governance action create-constitution --governance-act Create a constitution. +Usage: cardano-cli conway governance drep key-gen + + Delegate Representative commands. + +Usage: cardano-cli conway governance drep key-gen --verification-key-file FILE + --signing-key-file FILE + + Generate Delegate Representative verification and signing keys. + Usage: cardano-cli latest governance Latest era commands (Babbage) @@ -758,6 +768,7 @@ Usage: cardano-cli experimental governance | vote | committee | action + | drep ) Era-based governance commands @@ -888,6 +899,15 @@ Usage: cardano-cli experimental governance action create-constitution --governan Create a constitution. +Usage: cardano-cli experimental governance drep key-gen + + Delegate Representative commands. + +Usage: cardano-cli experimental governance drep key-gen --verification-key-file FILE + --signing-key-file FILE + + Generate Delegate Representative verification and signing keys. + Usage: cardano-cli legacy Legacy commands Legacy commands diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance.cli index 1ea2cc1b2f..575ef298f3 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance.cli @@ -4,6 +4,7 @@ Usage: cardano-cli conway governance | vote | committee | action + | drep ) Era-based governance commands @@ -17,3 +18,4 @@ Available commands: vote Vote creation. committee Committee member commands. action Governance action commands. + drep Delegate Representative commands. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_key-gen.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_key-gen.cli new file mode 100644 index 0000000000..0c38618472 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/conway_governance_drep_key-gen.cli @@ -0,0 +1,10 @@ +Usage: cardano-cli conway governance drep key-gen --verification-key-file FILE + --signing-key-file FILE + + Generate Delegate Representative verification and signing keys. + +Available options: + --verification-key-file FILE + Output filepath of the verification key. + --signing-key-file FILE Output filepath of the signing key. + -h,--help Show this help text diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/experimental_governance.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/experimental_governance.cli index db6f3d7503..cd59c41f44 100644 --- a/cardano-cli/test/cardano-cli-golden/files/golden/help/experimental_governance.cli +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/experimental_governance.cli @@ -4,6 +4,7 @@ Usage: cardano-cli experimental governance | vote | committee | action + | drep ) Era-based governance commands @@ -17,3 +18,4 @@ Available commands: vote Vote creation. committee Committee member commands. action Governance action commands. + drep Delegate Representative commands. diff --git a/cardano-cli/test/cardano-cli-golden/files/golden/help/experimental_governance_drep_key-gen.cli b/cardano-cli/test/cardano-cli-golden/files/golden/help/experimental_governance_drep_key-gen.cli new file mode 100644 index 0000000000..cd96c7fa30 --- /dev/null +++ b/cardano-cli/test/cardano-cli-golden/files/golden/help/experimental_governance_drep_key-gen.cli @@ -0,0 +1,10 @@ +Usage: cardano-cli experimental governance drep key-gen --verification-key-file FILE + --signing-key-file FILE + + Generate Delegate Representative verification and signing keys. + +Available options: + --verification-key-file FILE + Output filepath of the verification key. + --signing-key-file FILE Output filepath of the signing key. + -h,--help Show this help text