Skip to content

Commit

Permalink
more more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Jul 15, 2024
1 parent 470c77e commit 2a2da4f
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 87 deletions.
17 changes: 1 addition & 16 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ module Cardano.CLI.EraBased.Run.Genesis
, runGenesisKeyHashCmd
, runGenesisTxInCmd
, runGenesisVerKeyCmd

-- * Protocol Parameters
, readProtocolParameters
) where

import Cardano.Api
Expand Down Expand Up @@ -409,7 +406,7 @@ runGenesisCreateCardanoCmd
, sgSlotLength = L.secondsToNominalDiffTimeMicro $ MkFixed (fromIntegral slotLength) * 1_000
}
shelleyGenesisTemplate' <- overrideShelleyGenesis <$> decodeShelleyGenesisFile shelleyGenesisTemplate
alonzoGenesis <- decodeAlonzoGenesisFile (Just era) alonzoGenesisTemplate -- FIXME!!!
alonzoGenesis <- decodeAlonzoGenesisFile (Just era) alonzoGenesisTemplate
conwayGenesis <- decodeConwayGenesisFile conwayGenesisTemplate
(delegateMap, vrfKeys, kesKeys, opCerts) <- liftIO $ generateShelleyNodeSecrets shelleyDelegateKeys shelleyGenesisvkeys
let
Expand Down Expand Up @@ -1157,15 +1154,3 @@ runGenesisHashFileCmd (GenesisFile fpath) = do
gh = Crypto.hashWith id content
liftIO $ Text.putStrLn (Crypto.hashToTextAsHex gh)

-- Protocol Parameters

--TODO: eliminate this and get only the necessary params, and get them in a more
-- helpful way rather than requiring them as a local file.
readProtocolParameters :: ()
=> ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (L.PParams (ShelleyLedgerEra era))
readProtocolParameters sbe (ProtocolParamsFile fpath) = do
pparams <- handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $ LBS.readFile fpath
firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $
shelleyBasedEraConstraints sbe $ Aeson.eitherDecode' pparams
72 changes: 23 additions & 49 deletions cardano-cli/src/Cardano/CLI/EraBased/Run/Genesis/Common.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}


module Cardano.CLI.EraBased.Run.Genesis.Common
( decodeShelleyGenesisFile
Expand All @@ -20,68 +16,34 @@ module Cardano.CLI.EraBased.Run.Genesis.Common
, genStuffedAddress
, getCurrentTimePlus30
, readRelays

-- * Protocol Parameters
, readProtocolParameters
) where

import Cardano.Api hiding (ConwayEra)
import Cardano.Api.Ledger (AlonzoGenesis, ConwayGenesis, StandardCrypto,
StrictMaybe (SNothing))
import Cardano.Api.Ledger (AlonzoGenesis, ConwayGenesis, StandardCrypto)
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (Address (ShelleyAddress),
Hash (DRepKeyHash, GenesisDelegateKeyHash, GenesisKeyHash, StakeKeyHash, VrfKeyHash),
KESPeriod (KESPeriod),
OperationalCertificateIssueCounter (OperationalCertificateIssueCounter),
ShelleyGenesis (ShelleyGenesis, sgGenDelegs, sgInitialFunds, sgMaxLovelaceSupply, sgNetworkMagic, sgProtocolParams, sgStaking, sgSystemStart),
StakeCredential (StakeCredentialByKey), VerificationKey (VrfVerificationKey),
VrfKey, alonzoGenesisDefaults, conwayGenesisDefaults, decodeAlonzoGenesis,
shelleyGenesisDefaults, toShelleyAddr, toShelleyNetwork, toShelleyStakeAddr)

import Cardano.CLI.EraBased.Commands.Genesis as Cmd
import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep
import qualified Cardano.CLI.EraBased.Commands.Node as Cmd
import Cardano.CLI.EraBased.Run.Address (generateAndWriteKeyFiles)
import qualified Cardano.CLI.EraBased.Run.Governance.DRep as DRep
import qualified Cardano.CLI.EraBased.Run.Key as Key
import Cardano.CLI.EraBased.Run.Node (runNodeIssueOpCertCmd, runNodeKeyGenColdCmd,
runNodeKeyGenKesCmd, runNodeKeyGenVrfCmd)
import Cardano.CLI.EraBased.Run.StakeAddress (runStakeAddressKeyGenCmd)
import qualified Cardano.CLI.IO.Lazy as Lazy
import Cardano.Api.Shelley (Address (ShelleyAddress), ShelleyGenesis, ShelleyLedgerEra,
decodeAlonzoGenesis)

import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Errors.GenesisCmdError
import Cardano.CLI.Types.Errors.NodeCmdError
import Cardano.CLI.Types.Errors.StakePoolCmdError
import Cardano.CLI.Types.Key
import Cardano.CLI.Types.Errors.ProtocolParamsError
import Cardano.Crypto.Hash (HashAlgorithm)
import qualified Cardano.Crypto.Hash as Hash
import qualified Cardano.Crypto.Random as Crypto
import Ouroboros.Consensus.Shelley.Node (ShelleyGenesisStaking (..))

import Control.DeepSeq (NFData, deepseq)
import Control.Monad (forM, forM_, unless, void, when)
import qualified Data.Aeson as A
import Data.Bifunctor (Bifunctor (..))
import qualified Data.Binary.Get as Bin
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Coerce (coerce)
import Data.Data (Proxy (..))
import Data.ListMap (ListMap (..))
import qualified Data.ListMap as ListMap
import Data.Map.Strict (Map, fromList, toList)
import qualified Data.Map.Strict as Map
import Data.Maybe (fromMaybe)
import qualified Data.Sequence.Strict as Seq
import Data.String (fromString)
import Data.Map.Strict (Map)
import qualified Data.Text as Text
import Data.Time (NominalDiffTime, UTCTime, addUTCTime, getCurrentTime)
import Data.Tuple (swap)
import Data.Word (Word64)
import GHC.Generics (Generic)
import GHC.Num (Natural)
import Lens.Micro ((^.))
import System.Directory (createDirectoryIfMissing)
import System.FilePath ((</>))
import qualified System.Random as Random
import System.Random (StdGen)

import Crypto.Random (getRandomBytes)

Expand All @@ -92,9 +54,10 @@ decodeShelleyGenesisFile
-> t m (ShelleyGenesis StandardCrypto)
decodeShelleyGenesisFile = readAndDecodeGenesisFileWith A.eitherDecode

-- | Decode Alonzo Genesis file. See 'Cardano.Api.Genesis.decodeAlonzoGenesis' haddocks for details.
decodeAlonzoGenesisFile
:: MonadIOTransError GenesisCmdError t m
=> Maybe (CardanoEra era)
=> Maybe (CardanoEra era) -- ^ Optional era in which we're decoding alonzo genesis.
-> FilePath
-> t m AlonzoGenesis
decodeAlonzoGenesisFile mEra = readAndDecodeGenesisFileWith (runExcept . decodeAlonzoGenesis mEra)
Expand Down Expand Up @@ -150,3 +113,14 @@ readRelays fp = do
handleIOExceptT (GenesisCmdStakePoolRelayFileError fp) (LBS.readFile fp)
firstExceptT (GenesisCmdStakePoolRelayJsonDecodeError fp)
. hoistEither $ A.eitherDecode relaySpecJsonBs

--TODO: eliminate this and get only the necessary params, and get them in a more
-- helpful way rather than requiring them as a local file.
readProtocolParameters :: ()
=> ShelleyBasedEra era
-> ProtocolParamsFile
-> ExceptT ProtocolParamsError IO (L.PParams (ShelleyLedgerEra era))
readProtocolParameters sbe (ProtocolParamsFile fpath) = do
pparams <- handleIOExceptT (ProtocolParamsErrorFile . FileIOError fpath) $ LBS.readFile fpath
firstExceptT (ProtocolParamsErrorJSON fpath . Text.pack) . hoistEither $
shelleyBasedEraConstraints sbe $ A.eitherDecode' pparams
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ module Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData
import Cardano.Api hiding (ConwayEra)
import Cardano.Api.Ledger (StrictMaybe (SNothing))
import qualified Cardano.Api.Ledger as L
import Cardano.Api.Shelley (Address (ShelleyAddress),
Hash (DRepKeyHash, GenesisDelegateKeyHash, GenesisKeyHash, StakeKeyHash, VrfKeyHash),
import Cardano.Api.Shelley
(Hash (DRepKeyHash, GenesisDelegateKeyHash, GenesisKeyHash, StakeKeyHash, VrfKeyHash),
KESPeriod (KESPeriod),
OperationalCertificateIssueCounter (OperationalCertificateIssueCounter),
ShelleyGenesis (ShelleyGenesis, sgGenDelegs, sgInitialFunds, sgMaxLovelaceSupply, sgNetworkMagic, sgProtocolParams, sgStaking, sgSystemStart),
StakeCredential (StakeCredentialByKey), VerificationKey (VrfVerificationKey),
VrfKey, alonzoGenesisDefaults, conwayGenesisDefaults, decodeAlonzoGenesis,
shelleyGenesisDefaults, toShelleyAddr, toShelleyNetwork, toShelleyStakeAddr)
VrfKey, alonzoGenesisDefaults, conwayGenesisDefaults, shelleyGenesisDefaults,
toShelleyAddr, toShelleyNetwork, toShelleyStakeAddr)

import Cardano.CLI.EraBased.Commands.Genesis as Cmd
import qualified Cardano.CLI.EraBased.Commands.Governance.DRep as DRep
Expand All @@ -48,20 +48,13 @@ import Cardano.CLI.Types.Errors.GenesisCmdError
import Cardano.CLI.Types.Errors.NodeCmdError
import Cardano.CLI.Types.Errors.StakePoolCmdError
import Cardano.CLI.Types.Key
import Cardano.Crypto.Hash (HashAlgorithm)
import qualified Cardano.Crypto.Hash as Hash
import qualified Cardano.Crypto.Random as Crypto
import Ouroboros.Consensus.Shelley.Node (ShelleyGenesisStaking (..))

import Control.DeepSeq (NFData, deepseq)
import Control.Monad (forM, forM_, unless, void, when)
import qualified Data.Aeson as Aeson
import Data.Bifunctor (Bifunctor (..))
import qualified Data.Binary.Get as Bin
import Data.ByteString (ByteString)
import qualified Data.ByteString.Lazy.Char8 as LBS
import Data.Coerce (coerce)
import Data.Data (Proxy (..))
import Data.ListMap (ListMap (..))
import qualified Data.ListMap as ListMap
import Data.Map.Strict (Map, fromList, toList)
Expand All @@ -70,7 +63,6 @@ import Data.Maybe (fromMaybe)
import qualified Data.Sequence.Strict as Seq
import Data.String (fromString)
import qualified Data.Text as Text
import Data.Time (NominalDiffTime, UTCTime, addUTCTime, getCurrentTime)
import Data.Tuple (swap)
import Data.Word (Word64)
import GHC.Generics (Generic)
Expand All @@ -81,7 +73,6 @@ import System.FilePath ((</>))
import qualified System.Random as Random
import System.Random (StdGen)

import Crypto.Random (getRandomBytes)

runGenesisKeyGenGenesisCmd
:: GenesisKeyGenGenesisCmdArgs
Expand Down
2 changes: 1 addition & 1 deletion cardano-cli/src/Cardano/CLI/EraBased/Run/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import Cardano.Api.Shelley
import qualified Cardano.Binary as CBOR
import qualified Cardano.Chain.Common as Byron
import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd
import Cardano.CLI.EraBased.Run.Genesis
import Cardano.CLI.EraBased.Run.Genesis.Common (readProtocolParameters)
import Cardano.CLI.EraBased.Run.Query
import Cardano.CLI.Json.Friendly (FriendlyFormat (..), friendlyTx, friendlyTxBody)
import Cardano.CLI.Read
Expand Down
40 changes: 36 additions & 4 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -9828,7 +9828,15 @@ Usage: cardano-cli legacy genesis initial-txin --verification-key-file FILE

Get the TxIn for an initial UTxO based on the verification key

Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR
Usage: cardano-cli legacy genesis create-cardano
[ --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
| --babbage-era
| --conway-era
]
--genesis-dir DIR
[--gen-genesis-keys INT]
[--gen-utxo-keys INT]
[--start-time UTC-TIME]
Expand All @@ -9848,7 +9856,15 @@ Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR
Create a Byron and Shelley genesis file from a genesis template and
genesis/delegation/spending keys.

Usage: cardano-cli legacy genesis create [--key-output-format STRING]
Usage: cardano-cli legacy genesis create
[ --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
| --babbage-era
| --conway-era
]
[--key-output-format STRING]
--genesis-dir DIR
[--gen-genesis-keys INT]
[--gen-utxo-keys INT]
Expand Down Expand Up @@ -11103,7 +11119,15 @@ Usage: cardano-cli genesis initial-txin --verification-key-file FILE

Get the TxIn for an initial UTxO based on the verification key

Usage: cardano-cli genesis create-cardano --genesis-dir DIR
Usage: cardano-cli genesis create-cardano
[ --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
| --babbage-era
| --conway-era
]
--genesis-dir DIR
[--gen-genesis-keys INT]
[--gen-utxo-keys INT]
[--start-time UTC-TIME]
Expand All @@ -11123,7 +11147,15 @@ Usage: cardano-cli genesis create-cardano --genesis-dir DIR
Create a Byron and Shelley genesis file from a genesis template and
genesis/delegation/spending keys.

Usage: cardano-cli genesis create [--key-output-format STRING]
Usage: cardano-cli genesis create
[ --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
| --babbage-era
| --conway-era
]
[--key-output-format STRING]
--genesis-dir DIR
[--gen-genesis-keys INT]
[--gen-utxo-keys INT]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Usage: cardano-cli genesis create-cardano --genesis-dir DIR
Usage: cardano-cli genesis create-cardano
[ --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
| --babbage-era
| --conway-era
]
--genesis-dir DIR
[--gen-genesis-keys INT]
[--gen-utxo-keys INT]
[--start-time UTC-TIME]
Expand All @@ -19,6 +27,12 @@ Usage: cardano-cli genesis create-cardano --genesis-dir DIR
genesis/delegation/spending keys.

Available options:
--shelley-era Specify the Shelley era
--allegra-era Specify the Allegra era
--mary-era Specify the Mary era
--alonzo-era Specify the Alonzo era
--babbage-era Specify the Babbage era (default)
--conway-era Specify the Conway era
--genesis-dir DIR The genesis directory containing the genesis template
and required genesis/delegation/spending keys.
--gen-genesis-keys INT The number of genesis keys to make [default is 3].
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Usage: cardano-cli genesis create [--key-output-format STRING]
Usage: cardano-cli genesis create
[ --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
| --babbage-era
| --conway-era
]
[--key-output-format STRING]
--genesis-dir DIR
[--gen-genesis-keys INT]
[--gen-utxo-keys INT]
Expand All @@ -10,6 +18,12 @@ Usage: cardano-cli genesis create [--key-output-format STRING]
genesis/delegation/spending keys.

Available options:
--shelley-era Specify the Shelley era
--allegra-era Specify the Allegra era
--mary-era Specify the Mary era
--alonzo-era Specify the Alonzo era
--babbage-era Specify the Babbage era (default)
--conway-era Specify the Conway era
--key-output-format STRING
Optional key output format. Accepted output formats
are "text-envelope" and "bech32" (default is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR
Usage: cardano-cli legacy genesis create-cardano
[ --shelley-era
| --allegra-era
| --mary-era
| --alonzo-era
| --babbage-era
| --conway-era
]
--genesis-dir DIR
[--gen-genesis-keys INT]
[--gen-utxo-keys INT]
[--start-time UTC-TIME]
Expand All @@ -19,6 +27,12 @@ Usage: cardano-cli legacy genesis create-cardano --genesis-dir DIR
genesis/delegation/spending keys.

Available options:
--shelley-era Specify the Shelley era
--allegra-era Specify the Allegra era
--mary-era Specify the Mary era
--alonzo-era Specify the Alonzo era
--babbage-era Specify the Babbage era (default)
--conway-era Specify the Conway era
--genesis-dir DIR The genesis directory containing the genesis template
and required genesis/delegation/spending keys.
--gen-genesis-keys INT The number of genesis keys to make [default is 3].
Expand Down
Loading

0 comments on commit 2a2da4f

Please sign in to comment.