Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move genesis hash to hash genesis-file #982

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/Commands/Hash.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE LambdaCase #-}

Expand All @@ -22,6 +23,7 @@ import Data.Text (Text)
data HashCmds
= HashAnchorDataCmd !HashAnchorDataCmdArgs
| HashScriptCmd !HashScriptCmdArgs
| HashGenesisFile !GenesisFile

data HashGoal hash
= -- | The hash is written to stdout
Expand Down Expand Up @@ -58,3 +60,4 @@ renderHashCmds :: HashCmds -> Text
renderHashCmds = \case
HashAnchorDataCmd{} -> "hash anchor-data"
HashScriptCmd{} -> "hash script"
HashGenesisFile{} -> "hash genesis-file"
3 changes: 0 additions & 3 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ data GenesisCmds era
| GenesisVerKey !GenesisVerKeyCmdArgs
| GenesisTxIn !GenesisTxInCmdArgs
| GenesisAddr !GenesisAddrCmdArgs
| GenesisHashFile !GenesisFile
deriving Show

data GenesisCreateCmdArgs era = GenesisCreateCmdArgs
Expand Down Expand Up @@ -192,5 +191,3 @@ renderGenesisCmds = \case
"genesis initial-txin"
GenesisAddr{} ->
"genesis initial-addr"
GenesisHashFile{} ->
"genesis hash"
8 changes: 0 additions & 8 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ pGenesisCmds era envCli =
mconcat
[ "Create data to use for starting a testnet."
]
, Just $
subParser "hash" $
Opt.info pGenesisHash $
Opt.progDesc "Compute the hash of a genesis file"
]

pGenesisKeyGen :: Parser (GenesisCmds era)
Expand Down Expand Up @@ -360,10 +356,6 @@ pGenesisCreateTestNetData sbe envCli =
, Opt.help "The directory where to generate the data. Created if not existing."
]

pGenesisHash :: Parser (GenesisCmds era)
pGenesisHash =
GenesisHashFile <$> pGenesisFile "The genesis file."

pGenesisDir :: Parser GenesisDir
pGenesisDir =
fmap GenesisDir $
Expand Down
12 changes: 0 additions & 12 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module Cardano.CLI.EraBased.Run.Genesis
, runGenesisCreateCardanoCmd
, runGenesisCreateCmd
, runGenesisCreateStakedCmd
, runGenesisHashFileCmd
, runGenesisKeyHashCmd
, runGenesisTxInCmd
, runGenesisVerKeyCmd
Expand Down Expand Up @@ -108,7 +107,6 @@ runGenesisCmds = \case
GenesisCreateCardano args -> runGenesisCreateCardanoCmd args
GenesisCreateStaked args -> runGenesisCreateStakedCmd args
GenesisCreateTestNetData args -> TN.runGenesisCreateTestNetDataCmd args
GenesisHashFile gf -> runGenesisHashFileCmd gf

runGenesisKeyHashCmd :: VerificationKeyFile In -> ExceptT GenesisCmdError IO ()
runGenesisKeyHashCmd vkeyPath = do
Expand Down Expand Up @@ -1341,13 +1339,3 @@ readInitialFundAddresses utxodir nw = do
(PaymentCredentialByKey vkh)
NoStakeAddress
]

-- | Hash a genesis file
runGenesisHashFileCmd :: GenesisFile -> ExceptT GenesisCmdError IO ()
runGenesisHashFileCmd (GenesisFile fpath) = do
content <-
handleIOExceptT (GenesisCmdGenesisFileError . FileIOError fpath) $
BS.readFile fpath
let gh :: Crypto.Hash Crypto.Blake2b_256 ByteString
gh = Crypto.hashWith id content
liftIO $ Text.putStrLn (Crypto.hashToTextAsHex gh)
3 changes: 0 additions & 3 deletions cardano-cli/src/Cardano/CLI/Legacy/Commands/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ data LegacyGenesisCmds
(VerificationKeyFile In)
NetworkId
(Maybe (File () Out))
| GenesisHashFile
GenesisFile
deriving Show

renderLegacyGenesisCmds :: LegacyGenesisCmds -> Text
Expand All @@ -97,4 +95,3 @@ renderLegacyGenesisCmds = \case
GenesisVerKey{} -> "genesis get-ver-key"
GenesisTxIn{} -> "genesis initial-txin"
GenesisAddr{} -> "genesis initial-addr"
GenesisHashFile{} -> "genesis hash"
7 changes: 0 additions & 7 deletions cardano-cli/src/Cardano/CLI/Legacy/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ pGenesisCmds envCli =
[ "Create a staked Shelley genesis file from a genesis "
, "template and genesis/delegation/spending keys."
]
, subParser "hash" $
Opt.info pGenesisHash $
Opt.progDesc "Compute the hash of a genesis file"
]
where
pGenesisKeyGen :: Parser LegacyGenesisCmds
Expand Down Expand Up @@ -278,10 +275,6 @@ pGenesisCmds envCli =
<*> pStuffedUtxoCount
<*> Opt.optional pRelayJsonFp

pGenesisHash :: Parser LegacyGenesisCmds
pGenesisHash =
GenesisHashFile <$> pGenesisFile "The genesis file."

pGenesisDir :: Parser GenesisDir
pGenesisDir =
fmap GenesisDir $
Expand Down
9 changes: 0 additions & 9 deletions cardano-cli/src/Cardano/CLI/Legacy/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ runLegacyGenesisCmds = \case
runLegacyGenesisCreateCardanoCmd eSbe gd gn un ms am k slotLength sc nw bg sg ag cg mNodeCfg
GenesisCreateStaked eSbe fmt gd gn gp gl un ms am ds nw bf bp su relayJsonFp ->
runLegacyGenesisCreateStakedCmd eSbe fmt gd gn gp gl un ms am ds nw bf bp su relayJsonFp
GenesisHashFile gf ->
runLegacyGenesisHashFileCmd gf

runLegacyGenesisKeyGenGenesisCmd
:: ()
Expand Down Expand Up @@ -271,10 +269,3 @@ runLegacyGenesisCreateStakedCmd
, Cmd.numStuffedUtxo = numStuffedUtxo
, Cmd.mStakePoolRelaySpecFile = mStakePoolRelaySpecFile
}

-- | Hash a genesis file
runLegacyGenesisHashFileCmd
:: ()
=> GenesisFile
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisHashFileCmd = runGenesisHashFileCmd
12 changes: 11 additions & 1 deletion cardano-cli/src/Cardano/CLI/Options/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pHashCmds :: Parser Cmd.HashCmds
pHashCmds =
subParser "hash" $
Opt.info
(asum [pHashAnchorDataCmd, pHashScriptCmd])
(asum [pHashAnchorDataCmd, pHashScriptCmd, pHashGenesisHashCmd])
( Opt.progDesc $
mconcat
[ "Compute the hash to pass to the various --*-hash arguments of commands."
Expand Down Expand Up @@ -79,3 +79,13 @@ pHashScriptCmd = do
)
)
$ Opt.progDesc "Compute the hash of a script (to then pass it to other commands)."

pHashGenesisHashCmd :: Parser Cmd.HashCmds
pHashGenesisHashCmd =
subParser "genesis-file" $
Opt.info pGenesisHash $
Opt.progDesc "Compute the hash of a genesis file."

pGenesisHash :: Parser Cmd.HashCmds
pGenesisHash =
Cmd.HashGenesisFile <$> pGenesisFile "The genesis file."
15 changes: 13 additions & 2 deletions cardano-cli/src/Cardano/CLI/Run/Hash.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import qualified Cardano.Api.Ledger as L
import qualified Cardano.CLI.Commands.Hash as Cmd
import Cardano.CLI.Parser (stringToAnchorScheme)
import Cardano.CLI.Read
import Cardano.CLI.Types.Common (AnchorScheme (..), MustCheckHash (..),
import Cardano.CLI.Types.Common (AnchorScheme (..), GenesisFile (..), MustCheckHash (..),
PotentiallyCheckedAnchor (..), SupportedSchemes)
import Cardano.CLI.Types.Errors.HashCmdError
import Cardano.Crypto.Hash (hashToTextAsHex)
import Cardano.Prelude (first)
import qualified Cardano.Crypto.Hash as Crypto
import Cardano.Prelude (ByteString, first)

import Control.Exception (throw)
import Control.Monad (when)
Expand Down Expand Up @@ -55,6 +56,7 @@ runHashCmds
runHashCmds = \case
Cmd.HashAnchorDataCmd args -> runHashAnchorDataCmd args
Cmd.HashScriptCmd args -> runHashScriptCmd args
Cmd.HashGenesisFile args -> runHashGenesisFile args

runHashAnchorDataCmd
:: ()
Expand Down Expand Up @@ -217,3 +219,12 @@ carryHashChecks potentiallyCheckedAnchor =
TrustHash -> pure ()
where
anchor = pcaAnchor potentiallyCheckedAnchor

runHashGenesisFile :: GenesisFile -> ExceptT HashCmdError IO ()
runHashGenesisFile (GenesisFile fpath) = do
content <-
handleIOExceptT (HashGenesisCmdGenesisFileError . FileIOError fpath) $
BS.readFile fpath
let gh :: Crypto.Hash Crypto.Blake2b_256 ByteString
gh = Crypto.hashWith id content
liftIO $ Text.putStrLn (Crypto.hashToTextAsHex gh)
3 changes: 3 additions & 0 deletions cardano-cli/src/Cardano/CLI/Types/Errors/HashCmdError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data HashCmdError
| HashWriteFileError !(FileError ())
| HashReadScriptError !FilePath !(FileError ScriptDecodeError)
| HashFetchURLError !FetchURLError
| HashGenesisCmdGenesisFileError !(FileError ())
deriving Show

instance Error HashCmdError where
Expand All @@ -45,6 +46,8 @@ instance Error HashCmdError where
"Cannot read script at" <+> pretty filepath <> ":" <+> prettyError err
HashFetchURLError fetchErr ->
pretty (displayException fetchErr)
HashGenesisCmdGenesisFileError fe ->
prettyError fe

data FetchURLError
= FetchURLInvalidURLError !String
Expand Down
46 changes: 5 additions & 41 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ Usage: cardano-cli legacy genesis
| create-cardano
| create
| create-staked
| hash
palas marked this conversation as resolved.
Show resolved Hide resolved
)

Genesis block commands
Expand Down Expand Up @@ -665,10 +664,6 @@ Usage: cardano-cli legacy genesis create-staked
Create a staked Shelley genesis file from a genesis template and
genesis/delegation/spending keys.

Usage: cardano-cli legacy genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli byron
( key
| transaction
Expand Down Expand Up @@ -1095,7 +1090,6 @@ Usage: cardano-cli shelley genesis
| create
| create-staked
| create-testnet-data
| hash
)

Genesis block commands.
Expand Down Expand Up @@ -1217,10 +1211,6 @@ Usage: cardano-cli shelley genesis create-testnet-data [--spec-shelley FILEPATH]

Create data to use for starting a testnet.

Usage: cardano-cli shelley genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli shelley governance
( create-mir-certificate
| create-genesis-key-delegation-certificate
Expand Down Expand Up @@ -2168,7 +2158,6 @@ Usage: cardano-cli allegra genesis
| create
| create-staked
| create-testnet-data
| hash
)

Genesis block commands.
Expand Down Expand Up @@ -2290,10 +2279,6 @@ Usage: cardano-cli allegra genesis create-testnet-data [--spec-shelley FILEPATH]

Create data to use for starting a testnet.

Usage: cardano-cli allegra genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli allegra governance
( create-mir-certificate
| create-genesis-key-delegation-certificate
Expand Down Expand Up @@ -3241,7 +3226,6 @@ Usage: cardano-cli mary genesis
| create
| create-staked
| create-testnet-data
| hash
)

Genesis block commands.
Expand Down Expand Up @@ -3361,10 +3345,6 @@ Usage: cardano-cli mary genesis create-testnet-data [--spec-shelley FILEPATH]

Create data to use for starting a testnet.

Usage: cardano-cli mary genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli mary governance
( create-mir-certificate
| create-genesis-key-delegation-certificate
Expand Down Expand Up @@ -4304,7 +4284,6 @@ Usage: cardano-cli alonzo genesis
| create
| create-staked
| create-testnet-data
| hash
)

Genesis block commands.
Expand Down Expand Up @@ -4424,10 +4403,6 @@ Usage: cardano-cli alonzo genesis create-testnet-data [--spec-shelley FILEPATH]

Create data to use for starting a testnet.

Usage: cardano-cli alonzo genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli alonzo governance
( create-mir-certificate
| create-genesis-key-delegation-certificate
Expand Down Expand Up @@ -5382,7 +5357,6 @@ Usage: cardano-cli babbage genesis
| create
| create-staked
| create-testnet-data
| hash
)

Genesis block commands.
Expand Down Expand Up @@ -5504,10 +5478,6 @@ Usage: cardano-cli babbage genesis create-testnet-data [--spec-shelley FILEPATH]

Create data to use for starting a testnet.

Usage: cardano-cli babbage genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli babbage governance
( create-mir-certificate
| create-genesis-key-delegation-certificate
Expand Down Expand Up @@ -6740,7 +6710,6 @@ Usage: cardano-cli conway genesis
| create
| create-staked
| create-testnet-data
| hash
)

Genesis block commands.
Expand Down Expand Up @@ -6860,10 +6829,6 @@ Usage: cardano-cli conway genesis create-testnet-data [--spec-shelley FILEPATH]

Create data to use for starting a testnet.

Usage: cardano-cli conway genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli conway governance (action | committee | drep | vote)

Governance commands.
Expand Down Expand Up @@ -8740,7 +8705,6 @@ Usage: cardano-cli latest genesis
| create
| create-staked
| create-testnet-data
| hash
)

Genesis block commands.
Expand Down Expand Up @@ -8860,10 +8824,6 @@ Usage: cardano-cli latest genesis create-testnet-data [--spec-shelley FILEPATH]

Create data to use for starting a testnet.

Usage: cardano-cli latest genesis hash --genesis FILEPATH

Compute the hash of a genesis file

Usage: cardano-cli latest governance (action | committee | drep | vote)

Governance commands.
Expand Down Expand Up @@ -10589,7 +10549,7 @@ Usage: cardano-cli latest transaction txid

Print a transaction identifier.

Usage: cardano-cli hash (anchor-data | script)
Usage: cardano-cli hash (anchor-data | script | genesis-file)

Compute the hash to pass to the various --*-hash arguments of commands.

Expand All @@ -10609,6 +10569,10 @@ Usage: cardano-cli hash script --script-file FILEPATH [--out-file FILEPATH]

Compute the hash of a script (to then pass it to other commands).

Usage: cardano-cli hash genesis-file --genesis FILEPATH

Compute the hash of a genesis file.

Usage: cardano-cli ping [-c|--count COUNT]
((-h|--host HOST) | (-u|--unixsock SOCKET))
[-p|--port PORT]
Expand Down
Loading
Loading