Skip to content

Commit

Permalink
Command argument types: 'genesis key-gen-delegate'
Browse files Browse the repository at this point in the history
  • Loading branch information
carlhammann committed Oct 23, 2023
1 parent b9379df commit 4fd1580
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
12 changes: 8 additions & 4 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Cardano.CLI.EraBased.Commands.Genesis
, GenesisCreateCardanoCmdArgs (..)
, GenesisCreateStakedCmdArgs (..)
, GenesisKeyGenGenesisCmdArgs (..)
, GenesisKeyGenDelegateCmdArgs (..)
, renderGenesisCmds
) where

Expand All @@ -23,10 +24,7 @@ data GenesisCmds era
| GenesisCreateCardano !GenesisCreateCardanoCmdArgs
| GenesisCreateStaked !GenesisCreateStakedCmdArgs
| GenesisKeyGenGenesis !GenesisKeyGenGenesisCmdArgs
| GenesisKeyGenDelegate
(VerificationKeyFile Out)
(SigningKeyFile Out)
(OpCertCounterFile Out)
| GenesisKeyGenDelegate !GenesisKeyGenDelegateCmdArgs
| GenesisKeyGenUTxO
(VerificationKeyFile Out)
(SigningKeyFile Out)
Expand Down Expand Up @@ -96,6 +94,12 @@ data GenesisKeyGenGenesisCmdArgs = GenesisKeyGenGenesisCmdArgs
, signingKeyPath :: !(SigningKeyFile Out)
} deriving Show

data GenesisKeyGenDelegateCmdArgs = GenesisKeyGenDelegateCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile Out)
, opCertCounterPath :: !(OpCertCounterFile Out)
} deriving Show

renderGenesisCmds :: GenesisCmds era -> Text
renderGenesisCmds = \case
GenesisCreate {} ->
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pGenesisKeyGen =

pGenesisDelegateKeyGen :: Parser (GenesisCmds era)
pGenesisDelegateKeyGen =
GenesisKeyGenDelegate
fmap GenesisKeyGenDelegate $ GenesisKeyGenDelegateCmdArgs
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut
<*> pOperatorCertIssueCounterFile
Expand Down
31 changes: 18 additions & 13 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ runGenesisCmds :: GenesisCmds era -> ExceptT GenesisCmdError IO ()
runGenesisCmds = \case
GenesisKeyGenGenesis args ->
runGenesisKeyGenGenesisCmd args
GenesisKeyGenDelegate vk sk ctr ->
runGenesisKeyGenDelegateCmd vk sk ctr
GenesisKeyGenDelegate args ->
runGenesisKeyGenDelegateCmd args
GenesisKeyGenUTxO vk sk ->
runGenesisKeyGenUTxOCmd vk sk
GenesisCmdKeyHash vk ->
Expand Down Expand Up @@ -190,25 +190,28 @@ runGenesisKeyGenGenesisCmd
vkeyDesc = "Genesis Verification Key"


runGenesisKeyGenDelegateCmd ::
VerificationKeyFile Out
-> SigningKeyFile Out
-> OpCertCounterFile Out
runGenesisKeyGenDelegateCmd
:: GenesisKeyGenDelegateCmdArgs
-> ExceptT GenesisCmdError IO ()
runGenesisKeyGenDelegateCmd vkeyPath skeyPath ocertCtrPath = do
runGenesisKeyGenDelegateCmd
Cmd.GenesisKeyGenDelegateCmdArgs
{ Cmd.verificationKeyPath
, Cmd.signingKeyPath
, Cmd.opCertCounterPath
} = do
skey <- liftIO $ generateSigningKey AsGenesisDelegateKey
let vkey = getVerificationKey skey
firstExceptT GenesisCmdGenesisFileError
. newExceptT
$ writeLazyByteStringFile skeyPath
$ writeLazyByteStringFile signingKeyPath
$ textEnvelopeToJSON (Just skeyDesc) skey
firstExceptT GenesisCmdGenesisFileError
. newExceptT
$ writeLazyByteStringFile vkeyPath
$ writeLazyByteStringFile verificationKeyPath
$ textEnvelopeToJSON (Just vkeyDesc) vkey
firstExceptT GenesisCmdGenesisFileError
. newExceptT
$ writeLazyByteStringFile ocertCtrPath
$ writeLazyByteStringFile opCertCounterPath
$ textEnvelopeToJSON (Just certCtrDesc)
$ OperationalCertificateIssueCounter
initialCounter
Expand Down Expand Up @@ -791,9 +794,11 @@ createDelegateKeys :: KeyOutputFormat -> FilePath -> Word -> ExceptT GenesisCmdE
createDelegateKeys fmt dir index = do
liftIO $ createDirectoryIfMissing False dir
runGenesisKeyGenDelegateCmd
(File @(VerificationKey ()) $ dir </> "delegate" ++ strIndex ++ ".vkey")
(onlyOut coldSK)
(onlyOut opCertCtr)
Cmd.GenesisKeyGenDelegateCmdArgs
{ Cmd.verificationKeyPath = File @(VerificationKey ()) $ dir </> "delegate" ++ strIndex ++ ".vkey"
, Cmd.signingKeyPath = onlyOut coldSK
, Cmd.opCertCounterPath = onlyOut opCertCtr
}
runGenesisKeyGenDelegateVRF
(File @(VerificationKey ()) $ dir </> "delegate" ++ strIndex ++ ".vrf.vkey")
(File @(SigningKey ()) $ dir </> "delegate" ++ strIndex ++ ".vrf.skey")
Expand Down
8 changes: 7 additions & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ runLegacyGenesisKeyGenDelegateCmd :: ()
-> SigningKeyFile Out
-> OpCertCounterFile Out
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenDelegateCmd = runGenesisKeyGenDelegateCmd
runLegacyGenesisKeyGenDelegateCmd vkf skf okf =
runGenesisKeyGenDelegateCmd
Cmd.GenesisKeyGenDelegateCmdArgs
{ Cmd.verificationKeyPath = vkf
, Cmd.signingKeyPath = skf
, Cmd.opCertCounterPath = okf
}

runLegacyGenesisKeyGenUTxOCmd :: ()
=> VerificationKeyFile Out
Expand Down

0 comments on commit 4fd1580

Please sign in to comment.