Skip to content

Commit 0067de6

Browse files
authored
Merge pull request #982 from IntersectMBO/move-genesis-hash-to-hash-group
Move `genesis hash` to `hash genesis-file`
2 parents 7963292 + 5a31b7e commit 0067de6

25 files changed

+138
-31
lines changed

cardano-cli/src/Cardano/CLI/Commands/Hash.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE DerivingStrategies #-}
23
{-# LANGUAGE DuplicateRecordFields #-}
34
{-# LANGUAGE LambdaCase #-}
45

@@ -22,6 +23,7 @@ import Data.Text (Text)
2223
data HashCmds
2324
= HashAnchorDataCmd !HashAnchorDataCmdArgs
2425
| HashScriptCmd !HashScriptCmdArgs
26+
| HashGenesisFile !GenesisFile
2527

2628
data HashGoal hash
2729
= -- | The hash is written to stdout
@@ -58,3 +60,4 @@ renderHashCmds :: HashCmds -> Text
5860
renderHashCmds = \case
5961
HashAnchorDataCmd{} -> "hash anchor-data"
6062
HashScriptCmd{} -> "hash script"
63+
HashGenesisFile{} -> "hash genesis-file"

cardano-cli/src/Cardano/CLI/EraBased/Options/Genesis.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,13 @@ pGenesisCmds era envCli =
103103
, Just $
104104
subParser "hash" $
105105
Opt.info pGenesisHash $
106-
Opt.progDesc "Compute the hash of a genesis file"
106+
Opt.progDesc $
107+
mconcat
108+
[ "DEPRECATION WARNING! This command is deprecated and will be "
109+
, "removed in a future release. Please use hash genesis-file "
110+
, "instead. "
111+
, "Compute the hash of a genesis file."
112+
]
107113
]
108114

109115
pGenesisKeyGen :: Parser (GenesisCmds era)

cardano-cli/src/Cardano/CLI/Legacy/Options.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,13 @@ pGenesisCmds envCli =
173173
]
174174
, subParser "hash" $
175175
Opt.info pGenesisHash $
176-
Opt.progDesc "Compute the hash of a genesis file"
176+
Opt.progDesc $
177+
unlines
178+
[ "DEPRECATION WARNING! This command is deprecated and will be "
179+
, "removed in a future release. Please use hash genesis-file "
180+
, "instead. "
181+
, "Compute the hash of a genesis file."
182+
]
177183
]
178184
where
179185
pGenesisKeyGen :: Parser LegacyGenesisCmds

cardano-cli/src/Cardano/CLI/Options/Hash.hs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pHashCmds :: Parser Cmd.HashCmds
2020
pHashCmds =
2121
subParser "hash" $
2222
Opt.info
23-
(asum [pHashAnchorDataCmd, pHashScriptCmd])
23+
(asum [pHashAnchorDataCmd, pHashScriptCmd, pHashGenesisHashCmd])
2424
( Opt.progDesc $
2525
mconcat
2626
[ "Compute the hash to pass to the various --*-hash arguments of commands."
@@ -79,3 +79,13 @@ pHashScriptCmd = do
7979
)
8080
)
8181
$ Opt.progDesc "Compute the hash of a script (to then pass it to other commands)."
82+
83+
pHashGenesisHashCmd :: Parser Cmd.HashCmds
84+
pHashGenesisHashCmd =
85+
subParser "genesis-file" $
86+
Opt.info pGenesisHash $
87+
Opt.progDesc "Compute the hash of a genesis file."
88+
89+
pGenesisHash :: Parser Cmd.HashCmds
90+
pGenesisHash =
91+
Cmd.HashGenesisFile <$> pGenesisFile "The genesis file."

cardano-cli/src/Cardano/CLI/Run/Hash.hs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import qualified Cardano.Api.Ledger as L
2121
import qualified Cardano.CLI.Commands.Hash as Cmd
2222
import Cardano.CLI.Parser (stringToAnchorScheme)
2323
import Cardano.CLI.Read
24-
import Cardano.CLI.Types.Common (AnchorScheme (..), MustCheckHash (..),
24+
import Cardano.CLI.Types.Common (AnchorScheme (..), GenesisFile (..), MustCheckHash (..),
2525
PotentiallyCheckedAnchor (..), SupportedSchemes)
2626
import Cardano.CLI.Types.Errors.HashCmdError
2727
import Cardano.Crypto.Hash (hashToTextAsHex)
28-
import Cardano.Prelude (first)
28+
import qualified Cardano.Crypto.Hash as Crypto
29+
import Cardano.Prelude (ByteString, first)
2930

3031
import Control.Exception (throw)
3132
import Control.Monad (when)
@@ -55,6 +56,7 @@ runHashCmds
5556
runHashCmds = \case
5657
Cmd.HashAnchorDataCmd args -> runHashAnchorDataCmd args
5758
Cmd.HashScriptCmd args -> runHashScriptCmd args
59+
Cmd.HashGenesisFile args -> runHashGenesisFile args
5860

5961
runHashAnchorDataCmd
6062
:: ()
@@ -217,3 +219,12 @@ carryHashChecks potentiallyCheckedAnchor =
217219
TrustHash -> pure ()
218220
where
219221
anchor = pcaAnchor potentiallyCheckedAnchor
222+
223+
runHashGenesisFile :: GenesisFile -> ExceptT HashCmdError IO ()
224+
runHashGenesisFile (GenesisFile fpath) = do
225+
content <-
226+
handleIOExceptT (HashGenesisCmdGenesisFileError . FileIOError fpath) $
227+
BS.readFile fpath
228+
let gh :: Crypto.Hash Crypto.Blake2b_256 ByteString
229+
gh = Crypto.hashWith id content
230+
liftIO $ Text.putStrLn (Crypto.hashToTextAsHex gh)

cardano-cli/src/Cardano/CLI/Types/Errors/HashCmdError.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ data HashCmdError
2727
| HashWriteFileError !(FileError ())
2828
| HashReadScriptError !FilePath !(FileError ScriptDecodeError)
2929
| HashFetchURLError !FetchURLError
30+
| HashGenesisCmdGenesisFileError !(FileError ())
3031
deriving Show
3132

3233
instance Error HashCmdError where
@@ -45,6 +46,8 @@ instance Error HashCmdError where
4546
"Cannot read script at" <+> pretty filepath <> ":" <+> prettyError err
4647
HashFetchURLError fetchErr ->
4748
pretty (displayException fetchErr)
49+
HashGenesisCmdGenesisFileError fe ->
50+
prettyError fe
4851

4952
data FetchURLError
5053
= FetchURLInvalidURLError !String

cardano-cli/test/cardano-cli-golden/files/golden/help.cli

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,9 @@ Usage: cardano-cli legacy genesis create-staked
667667

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

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

672674
Usage: cardano-cli byron
673675
( key
@@ -1195,7 +1197,9 @@ Usage: cardano-cli shelley genesis create-staked [--key-output-format STRING]
11951197

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

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

12001204
Usage: cardano-cli shelley governance
12011205
( create-mir-certificate
@@ -2244,7 +2248,9 @@ Usage: cardano-cli allegra genesis create-staked [--key-output-format STRING]
22442248

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

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

22492255
Usage: cardano-cli allegra governance
22502256
( create-mir-certificate
@@ -3291,7 +3297,9 @@ Usage: cardano-cli mary genesis create-staked [--key-output-format STRING]
32913297

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

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

32963304
Usage: cardano-cli mary governance
32973305
( create-mir-certificate
@@ -4330,7 +4338,9 @@ Usage: cardano-cli alonzo genesis create-staked [--key-output-format STRING]
43304338

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

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

43354345
Usage: cardano-cli alonzo governance
43364346
( create-mir-certificate
@@ -5406,7 +5416,9 @@ Usage: cardano-cli babbage genesis create-testnet-data [--spec-shelley FILEPATH]
54065416

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

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

54115423
Usage: cardano-cli babbage governance
54125424
( create-mir-certificate
@@ -6762,7 +6774,9 @@ Usage: cardano-cli conway genesis create-testnet-data [--spec-shelley FILEPATH]
67626774

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

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

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

@@ -8780,7 +8794,9 @@ Usage: cardano-cli latest genesis create-testnet-data [--spec-shelley FILEPATH]
87808794

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

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

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

@@ -10525,7 +10541,7 @@ Usage: cardano-cli latest transaction txid
1052510541

1052610542
Print a transaction identifier.
1052710543

10528-
Usage: cardano-cli hash (anchor-data | script)
10544+
Usage: cardano-cli hash (anchor-data | script | genesis-file)
1052910545

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

@@ -10545,6 +10561,10 @@ Usage: cardano-cli hash script --script-file FILEPATH [--out-file FILEPATH]
1054510561

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

10564+
Usage: cardano-cli hash genesis-file --genesis FILEPATH
10565+
10566+
Compute the hash of a genesis file.
10567+
1054810568
Usage: cardano-cli ping [-c|--count COUNT]
1054910569
((-h|--host HOST) | (-u|--unixsock SOCKET))
1055010570
[-p|--port PORT]

cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_genesis.cli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ Available commands:
3434
and genesis/delegation/spending keys.
3535
create-staked Create a staked Shelley genesis file from a genesis
3636
template and genesis/delegation/spending keys.
37-
hash Compute the hash of a genesis file
37+
hash DEPRECATION WARNING! This command is deprecated and
38+
will be removed in a future release. Please use hash
39+
genesis-file instead. Compute the hash of a genesis
40+
file.

cardano-cli/test/cardano-cli-golden/files/golden/help/allegra_genesis_hash.cli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Usage: cardano-cli allegra genesis hash --genesis FILEPATH
22

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

57
Available options:
68
--genesis FILEPATH The genesis file.

cardano-cli/test/cardano-cli-golden/files/golden/help/alonzo_genesis.cli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,7 @@ Available commands:
3434
and genesis/delegation/spending keys.
3535
create-staked Create a staked Shelley genesis file from a genesis
3636
template and genesis/delegation/spending keys.
37-
hash Compute the hash of a genesis file
37+
hash DEPRECATION WARNING! This command is deprecated and
38+
will be removed in a future release. Please use hash
39+
genesis-file instead. Compute the hash of a genesis
40+
file.

0 commit comments

Comments
 (0)