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 all 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"
8 changes: 7 additions & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ pGenesisCmds era envCli =
, Just $
subParser "hash" $
Opt.info pGenesisHash $
Opt.progDesc "Compute the hash of a genesis file"
Opt.progDesc $
mconcat
[ "DEPRECATION WARNING! This command is deprecated and will be "
, "removed in a future release. Please use hash genesis-file "
, "instead. "
, "Compute the hash of a genesis file."
]
]

pGenesisKeyGen :: Parser (GenesisCmds era)
Expand Down
8 changes: 7 additions & 1 deletion cardano-cli/src/Cardano/CLI/Legacy/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ pGenesisCmds envCli =
]
, subParser "hash" $
Opt.info pGenesisHash $
Opt.progDesc "Compute the hash of a genesis file"
Opt.progDesc $
unlines
[ "DEPRECATION WARNING! This command is deprecated and will be "
, "removed in a future release. Please use hash genesis-file "
, "instead. "
, "Compute the hash of a genesis file."
]
]
where
pGenesisKeyGen :: Parser LegacyGenesisCmds
Expand Down
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
38 changes: 29 additions & 9 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,9 @@ Usage: cardano-cli legacy genesis create-staked

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Usage: cardano-cli byron
( key
Expand Down Expand Up @@ -1219,7 +1221,9 @@ Usage: cardano-cli shelley genesis create-testnet-data [--spec-shelley FILEPATH]

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Usage: cardano-cli shelley governance
( create-mir-certificate
Expand Down Expand Up @@ -2292,7 +2296,9 @@ Usage: cardano-cli allegra genesis create-testnet-data [--spec-shelley FILEPATH]

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Usage: cardano-cli allegra governance
( create-mir-certificate
Expand Down Expand Up @@ -3363,7 +3369,9 @@ Usage: cardano-cli mary genesis create-testnet-data [--spec-shelley FILEPATH]

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Usage: cardano-cli mary governance
( create-mir-certificate
Expand Down Expand Up @@ -4426,7 +4434,9 @@ Usage: cardano-cli alonzo genesis create-testnet-data [--spec-shelley FILEPATH]

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Usage: cardano-cli alonzo governance
( create-mir-certificate
Expand Down Expand Up @@ -5506,7 +5516,9 @@ Usage: cardano-cli babbage genesis create-testnet-data [--spec-shelley FILEPATH]

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Usage: cardano-cli babbage governance
( create-mir-certificate
Expand Down Expand Up @@ -6862,7 +6874,9 @@ Usage: cardano-cli conway genesis create-testnet-data [--spec-shelley FILEPATH]

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

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

Expand Down Expand Up @@ -8862,7 +8876,9 @@ Usage: cardano-cli latest genesis create-testnet-data [--spec-shelley FILEPATH]

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

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

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

Expand Down Expand Up @@ -10589,7 +10605,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 +10625,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
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Available commands:
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Usage: cardano-cli allegra genesis hash --genesis FILEPATH

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Available options:
--genesis FILEPATH The genesis file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Available commands:
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Usage: cardano-cli alonzo genesis hash --genesis FILEPATH

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Available options:
--genesis FILEPATH The genesis file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Available commands:
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Usage: cardano-cli babbage genesis hash --genesis FILEPATH

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Available options:
--genesis FILEPATH The genesis file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Available commands:
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Usage: cardano-cli conway genesis hash --genesis FILEPATH

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Available options:
--genesis FILEPATH The genesis file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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 @@ -10,3 +10,4 @@ Available commands:
to other commands).
script Compute the hash of a script (to then pass it to
other commands).
genesis-file Compute the hash of a genesis file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Usage: cardano-cli hash genesis-file --genesis FILEPATH

Compute the hash of a genesis file.

Available options:
--genesis FILEPATH The genesis file.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Available commands:
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Usage: cardano-cli latest genesis hash --genesis FILEPATH

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Available options:
--genesis FILEPATH The genesis file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ Available commands:
and genesis/delegation/spending keys.
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Usage: cardano-cli legacy genesis hash --genesis FILEPATH

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Available options:
--genesis FILEPATH The genesis file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Available commands:
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Usage: cardano-cli mary genesis hash --genesis FILEPATH

Compute the hash of a genesis file
DEPRECATION WARNING! This command is deprecated and will be removed in a
future release. Please use hash genesis-file instead. Compute the hash of a
genesis file.

Available options:
--genesis FILEPATH The genesis file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@ Available commands:
create-staked Create a staked Shelley genesis file from a genesis
template and genesis/delegation/spending keys.
create-testnet-data Create data to use for starting a testnet.
hash Compute the hash of a genesis file
hash DEPRECATION WARNING! This command is deprecated and
will be removed in a future release. Please use hash
genesis-file instead. Compute the hash of a genesis
file.
Loading
Loading