Skip to content

Commit

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

Expand All @@ -25,9 +26,7 @@ data GenesisCmds era
| GenesisCreateStaked !GenesisCreateStakedCmdArgs
| GenesisKeyGenGenesis !GenesisKeyGenGenesisCmdArgs
| GenesisKeyGenDelegate !GenesisKeyGenDelegateCmdArgs
| GenesisKeyGenUTxO
(VerificationKeyFile Out)
(SigningKeyFile Out)
| GenesisKeyGenUTxO !GenesisKeyGenUTxOCmdArgs
| GenesisCmdKeyHash
(VerificationKeyFile In)
| GenesisVerKey
Expand Down Expand Up @@ -100,6 +99,12 @@ data GenesisKeyGenDelegateCmdArgs = GenesisKeyGenDelegateCmdArgs
, opCertCounterPath :: !(OpCertCounterFile Out)
} deriving Show

data GenesisKeyGenUTxOCmdArgs = GenesisKeyGenUTxOCmdArgs
{ verificationKeyPath :: !(VerificationKeyFile Out)
, signingKeyPath :: !(SigningKeyFile 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 @@ -107,7 +107,7 @@ pGenesisDelegateKeyGen =

pGenesisUTxOKeyGen :: Parser (GenesisCmds era)
pGenesisUTxOKeyGen =
GenesisKeyGenUTxO
fmap GenesisKeyGenUTxO $ GenesisKeyGenUTxOCmdArgs
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut

Expand Down
25 changes: 15 additions & 10 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ runGenesisCmds = \case
runGenesisKeyGenGenesisCmd args
GenesisKeyGenDelegate args ->
runGenesisKeyGenDelegateCmd args
GenesisKeyGenUTxO vk sk ->
runGenesisKeyGenUTxOCmd vk sk
GenesisKeyGenUTxO args ->
runGenesisKeyGenUTxOCmd args
GenesisCmdKeyHash vk ->
runGenesisKeyHashCmd vk
GenesisVerKey vk sk ->
Expand Down Expand Up @@ -248,20 +248,23 @@ runGenesisKeyGenDelegateVRF vkeyPath skeyPath = do
vkeyDesc = "VRF Verification Key"


runGenesisKeyGenUTxOCmd ::
VerificationKeyFile Out
-> SigningKeyFile Out
runGenesisKeyGenUTxOCmd
:: GenesisKeyGenUTxOCmdArgs
-> ExceptT GenesisCmdError IO ()
runGenesisKeyGenUTxOCmd vkeyPath skeyPath = do
runGenesisKeyGenUTxOCmd
Cmd.GenesisKeyGenUTxOCmdArgs
{ Cmd.verificationKeyPath
, Cmd.signingKeyPath
} = do
skey <- liftIO $ generateSigningKey AsGenesisUTxOKey
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
where
skeyDesc, vkeyDesc :: TextEnvelopeDescr
Expand Down Expand Up @@ -834,8 +837,10 @@ createUtxoKeys dir index = do
liftIO $ createDirectoryIfMissing False dir
let strIndex = show index
runGenesisKeyGenUTxOCmd
(File @(VerificationKey ()) $ dir </> "utxo" ++ strIndex ++ ".vkey")
(File @(SigningKey ()) $ dir </> "utxo" ++ strIndex ++ ".skey")
Cmd.GenesisKeyGenUTxOCmdArgs
{ Cmd.verificationKeyPath = File @(VerificationKey ()) $ dir </> "utxo" ++ strIndex ++ ".vkey"
, Cmd.signingKeyPath = File @(SigningKey ()) $ dir </> "utxo" ++ strIndex ++ ".skey"
}

createPoolCredentials :: KeyOutputFormat -> FilePath -> Word -> ExceptT GenesisCmdError IO ()
createPoolCredentials fmt dir index = do
Expand Down
7 changes: 6 additions & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ runLegacyGenesisKeyGenUTxOCmd :: ()
=> VerificationKeyFile Out
-> SigningKeyFile Out
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenUTxOCmd = runGenesisKeyGenUTxOCmd
runLegacyGenesisKeyGenUTxOCmd vk sk =
runGenesisKeyGenUTxOCmd
Cmd.GenesisKeyGenUTxOCmdArgs
{ Cmd.verificationKeyPath = vk
, Cmd.signingKeyPath = sk
}

runLegacyGenesisKeyHashCmd :: VerificationKeyFile In -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyHashCmd = runGenesisKeyHashCmd
Expand Down

0 comments on commit 2d337cf

Please sign in to comment.