{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}

module Cardano.CLI.Legacy.Run.Genesis
  ( runLegacyGenesisCmds
  )
where

import           Cardano.Api
import qualified Cardano.Api.Byron as Byron
import           Cardano.Api.Ledger (Coin (..))

import           Cardano.CLI.EraBased.Commands.Genesis
                   (GenesisKeyGenGenesisCmdArgs (GenesisKeyGenGenesisCmdArgs))
import qualified Cardano.CLI.EraBased.Commands.Genesis as Cmd
import           Cardano.CLI.EraBased.Run.Genesis
import qualified Cardano.CLI.EraBased.Run.Genesis.CreateTestnetData as CreateTestnetData
import           Cardano.CLI.Legacy.Commands.Genesis
import           Cardano.CLI.Types.Common
import           Cardano.CLI.Types.Errors.GenesisCmdError

runLegacyGenesisCmds :: LegacyGenesisCmds -> ExceptT GenesisCmdError IO ()
runLegacyGenesisCmds :: LegacyGenesisCmds -> ExceptT GenesisCmdError IO ()
runLegacyGenesisCmds = \case
  GenesisKeyGenGenesis VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk ->
    VerificationKeyFile 'Out
-> SigningKeyFile 'Out -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenGenesisCmd VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk
  GenesisKeyGenDelegate VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk OpCertCounterFile 'Out
ctr ->
    VerificationKeyFile 'Out
-> SigningKeyFile 'Out
-> OpCertCounterFile 'Out
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenDelegateCmd VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk OpCertCounterFile 'Out
ctr
  GenesisKeyGenUTxO VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk ->
    VerificationKeyFile 'Out
-> SigningKeyFile 'Out -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenUTxOCmd VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk
  GenesisCmdKeyHash VerificationKeyFile 'In
vk ->
    VerificationKeyFile 'In -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyHashCmd VerificationKeyFile 'In
vk
  GenesisVerKey VerificationKeyFile 'Out
vk SigningKeyFile 'In
sk ->
    VerificationKeyFile 'Out
-> SigningKeyFile 'In -> ExceptT GenesisCmdError IO ()
runLegacyGenesisVerKeyCmd VerificationKeyFile 'Out
vk SigningKeyFile 'In
sk
  GenesisTxIn VerificationKeyFile 'In
vk NetworkId
nw Maybe (File () 'Out)
mOutFile ->
    VerificationKeyFile 'In
-> NetworkId
-> Maybe (File () 'Out)
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisTxInCmd VerificationKeyFile 'In
vk NetworkId
nw Maybe (File () 'Out)
mOutFile
  GenesisAddr VerificationKeyFile 'In
vk NetworkId
nw Maybe (File () 'Out)
mOutFile ->
    VerificationKeyFile 'In
-> NetworkId
-> Maybe (File () 'Out)
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisAddrCmd VerificationKeyFile 'In
vk NetworkId
nw Maybe (File () 'Out)
mOutFile
  GenesisCreate EraInEon ShelleyBasedEra
eSbe KeyOutputFormat
fmt GenesisDir
gd Word
gn Word
un Maybe SystemStart
ms Maybe Coin
am NetworkId
nw ->
    EraInEon ShelleyBasedEra
-> KeyOutputFormat
-> GenesisDir
-> Word
-> Word
-> Maybe SystemStart
-> Maybe Coin
-> NetworkId
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateCmd EraInEon ShelleyBasedEra
eSbe KeyOutputFormat
fmt GenesisDir
gd Word
gn Word
un Maybe SystemStart
ms Maybe Coin
am NetworkId
nw
  GenesisCreateCardano EraInEon ShelleyBasedEra
eSbe GenesisDir
gd Word
gn Word
un Maybe SystemStart
ms Maybe Coin
am BlockCount
k Word
slotLength Rational
sc NetworkId
nw FilePath
bg FilePath
sg FilePath
ag FilePath
cg Maybe FilePath
mNodeCfg ->
    EraInEon ShelleyBasedEra
-> GenesisDir
-> Word
-> Word
-> Maybe SystemStart
-> Maybe Coin
-> BlockCount
-> Word
-> Rational
-> NetworkId
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> Maybe FilePath
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateCardanoCmd EraInEon ShelleyBasedEra
eSbe GenesisDir
gd Word
gn Word
un Maybe SystemStart
ms Maybe Coin
am BlockCount
k Word
slotLength Rational
sc NetworkId
nw FilePath
bg FilePath
sg FilePath
ag FilePath
cg Maybe FilePath
mNodeCfg
  GenesisCreateStaked EraInEon ShelleyBasedEra
eSbe KeyOutputFormat
fmt GenesisDir
gd Word
gn Word
gp Word
gl Word
un Maybe SystemStart
ms Maybe Coin
am Coin
ds NetworkId
nw Word
bf Word
bp Word
su Maybe FilePath
relayJsonFp ->
    EraInEon ShelleyBasedEra
-> KeyOutputFormat
-> GenesisDir
-> Word
-> Word
-> Word
-> Word
-> Maybe SystemStart
-> Maybe Coin
-> Coin
-> NetworkId
-> Word
-> Word
-> Word
-> Maybe FilePath
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateStakedCmd EraInEon ShelleyBasedEra
eSbe KeyOutputFormat
fmt GenesisDir
gd Word
gn Word
gp Word
gl Word
un Maybe SystemStart
ms Maybe Coin
am Coin
ds NetworkId
nw Word
bf Word
bp Word
su Maybe FilePath
relayJsonFp
  GenesisHashFile GenesisFile
gf ->
    GenesisFile -> ExceptT GenesisCmdError IO ()
runLegacyGenesisHashFileCmd GenesisFile
gf

runLegacyGenesisKeyGenGenesisCmd
  :: ()
  => VerificationKeyFile Out
  -> SigningKeyFile Out
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenGenesisCmd :: VerificationKeyFile 'Out
-> SigningKeyFile 'Out -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenGenesisCmd VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk = GenesisKeyGenGenesisCmdArgs -> ExceptT GenesisCmdError IO ()
CreateTestnetData.runGenesisKeyGenGenesisCmd (GenesisKeyGenGenesisCmdArgs -> ExceptT GenesisCmdError IO ())
-> GenesisKeyGenGenesisCmdArgs -> ExceptT GenesisCmdError IO ()
forall a b. (a -> b) -> a -> b
$ VerificationKeyFile 'Out
-> SigningKeyFile 'Out -> GenesisKeyGenGenesisCmdArgs
GenesisKeyGenGenesisCmdArgs VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk

runLegacyGenesisKeyGenDelegateCmd
  :: ()
  => VerificationKeyFile Out
  -> SigningKeyFile Out
  -> OpCertCounterFile Out
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenDelegateCmd :: VerificationKeyFile 'Out
-> SigningKeyFile 'Out
-> OpCertCounterFile 'Out
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenDelegateCmd VerificationKeyFile 'Out
vkf SigningKeyFile 'Out
skf OpCertCounterFile 'Out
okf =
  GenesisKeyGenDelegateCmdArgs -> ExceptT GenesisCmdError IO ()
CreateTestnetData.runGenesisKeyGenDelegateCmd
    Cmd.GenesisKeyGenDelegateCmdArgs
      { verificationKeyPath :: VerificationKeyFile 'Out
Cmd.verificationKeyPath = VerificationKeyFile 'Out
vkf
      , signingKeyPath :: SigningKeyFile 'Out
Cmd.signingKeyPath = SigningKeyFile 'Out
skf
      , opCertCounterPath :: OpCertCounterFile 'Out
Cmd.opCertCounterPath = OpCertCounterFile 'Out
okf
      }

runLegacyGenesisKeyGenUTxOCmd
  :: ()
  => VerificationKeyFile Out
  -> SigningKeyFile Out
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenUTxOCmd :: VerificationKeyFile 'Out
-> SigningKeyFile 'Out -> ExceptT GenesisCmdError IO ()
runLegacyGenesisKeyGenUTxOCmd VerificationKeyFile 'Out
vk SigningKeyFile 'Out
sk =
  GenesisKeyGenUTxOCmdArgs -> ExceptT GenesisCmdError IO ()
CreateTestnetData.runGenesisKeyGenUTxOCmd
    Cmd.GenesisKeyGenUTxOCmdArgs
      { verificationKeyPath :: VerificationKeyFile 'Out
Cmd.verificationKeyPath = VerificationKeyFile 'Out
vk
      , signingKeyPath :: SigningKeyFile 'Out
Cmd.signingKeyPath = SigningKeyFile 'Out
sk
      }

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

runLegacyGenesisVerKeyCmd
  :: VerificationKeyFile Out
  -> SigningKeyFile In
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisVerKeyCmd :: VerificationKeyFile 'Out
-> SigningKeyFile 'In -> ExceptT GenesisCmdError IO ()
runLegacyGenesisVerKeyCmd VerificationKeyFile 'Out
vk SigningKeyFile 'In
sk =
  GenesisVerKeyCmdArgs -> ExceptT GenesisCmdError IO ()
runGenesisVerKeyCmd
    Cmd.GenesisVerKeyCmdArgs
      { verificationKeyPath :: VerificationKeyFile 'Out
Cmd.verificationKeyPath = VerificationKeyFile 'Out
vk
      , signingKeyPath :: SigningKeyFile 'In
Cmd.signingKeyPath = SigningKeyFile 'In
sk
      }

runLegacyGenesisTxInCmd
  :: ()
  => VerificationKeyFile In
  -> NetworkId
  -> Maybe (File () Out)
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisTxInCmd :: VerificationKeyFile 'In
-> NetworkId
-> Maybe (File () 'Out)
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisTxInCmd VerificationKeyFile 'In
vkt NetworkId
nid Maybe (File () 'Out)
mOf =
  GenesisTxInCmdArgs -> ExceptT GenesisCmdError IO ()
runGenesisTxInCmd
    Cmd.GenesisTxInCmdArgs
      { verificationKeyPath :: VerificationKeyFile 'In
Cmd.verificationKeyPath = VerificationKeyFile 'In
vkt
      , network :: NetworkId
Cmd.network = NetworkId
nid
      , mOutFile :: Maybe (File () 'Out)
Cmd.mOutFile = Maybe (File () 'Out)
mOf
      }

runLegacyGenesisAddrCmd
  :: ()
  => VerificationKeyFile In
  -> NetworkId
  -> Maybe (File () Out)
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisAddrCmd :: VerificationKeyFile 'In
-> NetworkId
-> Maybe (File () 'Out)
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisAddrCmd VerificationKeyFile 'In
vkf NetworkId
nid Maybe (File () 'Out)
mOf =
  GenesisAddrCmdArgs -> ExceptT GenesisCmdError IO ()
runGenesisAddrCmd
    Cmd.GenesisAddrCmdArgs
      { verificationKeyPath :: VerificationKeyFile 'In
Cmd.verificationKeyPath = VerificationKeyFile 'In
vkf
      , network :: NetworkId
Cmd.network = NetworkId
nid
      , mOutFile :: Maybe (File () 'Out)
Cmd.mOutFile = Maybe (File () 'Out)
mOf
      }

runLegacyGenesisCreateCmd
  :: ()
  => EraInEon ShelleyBasedEra
  -> KeyOutputFormat
  -> GenesisDir
  -> Word
  -- ^ num genesis & delegate keys to make
  -> Word
  -- ^ num utxo keys to make
  -> Maybe SystemStart
  -> Maybe Coin
  -> NetworkId
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateCmd :: EraInEon ShelleyBasedEra
-> KeyOutputFormat
-> GenesisDir
-> Word
-> Word
-> Maybe SystemStart
-> Maybe Coin
-> NetworkId
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateCmd (EraInEon ShelleyBasedEra era
asbe) KeyOutputFormat
fmt GenesisDir
genDir Word
nGenKeys Word
nUTxOKeys Maybe SystemStart
mStart Maybe Coin
mSupply NetworkId
network =
  GenesisCreateCmdArgs era -> ExceptT GenesisCmdError IO ()
forall era.
GenesisCreateCmdArgs era -> ExceptT GenesisCmdError IO ()
runGenesisCreateCmd
    Cmd.GenesisCreateCmdArgs
      { eon :: ShelleyBasedEra era
Cmd.eon = ShelleyBasedEra era
asbe
      , keyOutputFormat :: KeyOutputFormat
Cmd.keyOutputFormat = KeyOutputFormat
fmt
      , genesisDir :: GenesisDir
Cmd.genesisDir = GenesisDir
genDir
      , numGenesisKeys :: Word
Cmd.numGenesisKeys = Word
nGenKeys
      , numUTxOKeys :: Word
Cmd.numUTxOKeys = Word
nUTxOKeys
      , mSystemStart :: Maybe SystemStart
Cmd.mSystemStart = Maybe SystemStart
mStart
      , mSupply :: Maybe Coin
Cmd.mSupply = Maybe Coin
mSupply
      , network :: NetworkId
Cmd.network = NetworkId
network
      }

runLegacyGenesisCreateCardanoCmd
  :: ()
  => EraInEon ShelleyBasedEra
  -> GenesisDir
  -> Word
  -- ^ num genesis & delegate keys to make
  -> Word
  -- ^ num utxo keys to make
  -> Maybe SystemStart
  -> Maybe Coin
  -> Byron.BlockCount
  -> Word
  -- ^ slot length in ms
  -> Rational
  -> NetworkId
  -> FilePath
  -- ^ Byron Genesis
  -> FilePath
  -- ^ Shelley Genesis
  -> FilePath
  -- ^ Alonzo Genesis
  -> FilePath
  -- ^ Conway Genesis
  -> Maybe FilePath
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateCardanoCmd :: EraInEon ShelleyBasedEra
-> GenesisDir
-> Word
-> Word
-> Maybe SystemStart
-> Maybe Coin
-> BlockCount
-> Word
-> Rational
-> NetworkId
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> Maybe FilePath
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateCardanoCmd
  (EraInEon ShelleyBasedEra era
sbe)
  GenesisDir
genDir
  Word
nGenKeys
  Word
nUTxOKeys
  Maybe SystemStart
mStart
  Maybe Coin
mSupply
  BlockCount
security
  Word
slotLength
  Rational
slotCoeff
  NetworkId
network
  FilePath
byronGenesis
  FilePath
shelleyGenesis
  FilePath
alonzoGenesis
  FilePath
conwayGenesis
  Maybe FilePath
mNodeCfg =
    GenesisCreateCardanoCmdArgs era -> ExceptT GenesisCmdError IO ()
forall era.
GenesisCreateCardanoCmdArgs era -> ExceptT GenesisCmdError IO ()
runGenesisCreateCardanoCmd
      Cmd.GenesisCreateCardanoCmdArgs
        { eon :: ShelleyBasedEra era
Cmd.eon = ShelleyBasedEra era
sbe
        , genesisDir :: GenesisDir
Cmd.genesisDir = GenesisDir
genDir
        , numGenesisKeys :: Word
Cmd.numGenesisKeys = Word
nGenKeys
        , numUTxOKeys :: Word
Cmd.numUTxOKeys = Word
nUTxOKeys
        , mSystemStart :: Maybe SystemStart
Cmd.mSystemStart = Maybe SystemStart
mStart
        , mSupply :: Maybe Coin
Cmd.mSupply = Maybe Coin
mSupply
        , security :: BlockCount
Cmd.security = BlockCount
security
        , slotLength :: Word
Cmd.slotLength = Word
slotLength
        , slotCoeff :: Rational
Cmd.slotCoeff = Rational
slotCoeff
        , network :: NetworkId
Cmd.network = NetworkId
network
        , byronGenesisTemplate :: FilePath
Cmd.byronGenesisTemplate = FilePath
byronGenesis
        , shelleyGenesisTemplate :: FilePath
Cmd.shelleyGenesisTemplate = FilePath
shelleyGenesis
        , alonzoGenesisTemplate :: FilePath
Cmd.alonzoGenesisTemplate = FilePath
alonzoGenesis
        , conwayGenesisTemplate :: FilePath
Cmd.conwayGenesisTemplate = FilePath
conwayGenesis
        , mNodeConfigTemplate :: Maybe FilePath
Cmd.mNodeConfigTemplate = Maybe FilePath
mNodeCfg
        }

runLegacyGenesisCreateStakedCmd
  :: ()
  => EraInEon ShelleyBasedEra
  -> KeyOutputFormat
  -- ^ key output format
  -> GenesisDir
  -> Word
  -- ^ num genesis & delegate keys to make
  -> Word
  -- ^ num utxo keys to make
  -> Word
  -- ^ num pools to make
  -> Word
  -- ^ num delegators to make
  -> Maybe SystemStart
  -> Maybe Coin
  -- ^ supply going to non-delegators
  -> Coin
  -- ^ supply going to delegators
  -> NetworkId
  -> Word
  -- ^ bulk credential files to write
  -> Word
  -- ^ pool credentials per bulk file
  -> Word
  -- ^ num stuffed UTxO entries
  -> Maybe FilePath
  -- ^ Specified stake pool relays
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateStakedCmd :: EraInEon ShelleyBasedEra
-> KeyOutputFormat
-> GenesisDir
-> Word
-> Word
-> Word
-> Word
-> Maybe SystemStart
-> Maybe Coin
-> Coin
-> NetworkId
-> Word
-> Word
-> Word
-> Maybe FilePath
-> ExceptT GenesisCmdError IO ()
runLegacyGenesisCreateStakedCmd
  (EraInEon ShelleyBasedEra era
sbe)
  KeyOutputFormat
keyOutputFormat
  GenesisDir
genesisDir
  Word
numGenesisKeys
  Word
numUTxOKeys
  Word
numPools
  Word
numStakeDelegators
  Maybe SystemStart
mSystemStart
  Maybe Coin
mNonDelegatedSupply
  Coin
delegatedSupply
  NetworkId
network
  Word
numBulkPoolCredFiles
  Word
numBulkPoolsPerFile
  Word
numStuffedUtxo
  Maybe FilePath
mStakePoolRelaySpecFile =
    GenesisCreateStakedCmdArgs era -> ExceptT GenesisCmdError IO ()
forall era.
GenesisCreateStakedCmdArgs era -> ExceptT GenesisCmdError IO ()
runGenesisCreateStakedCmd
      Cmd.GenesisCreateStakedCmdArgs
        { eon :: ShelleyBasedEra era
Cmd.eon = ShelleyBasedEra era
sbe
        , keyOutputFormat :: KeyOutputFormat
Cmd.keyOutputFormat = KeyOutputFormat
keyOutputFormat
        , genesisDir :: GenesisDir
Cmd.genesisDir = GenesisDir
genesisDir
        , numGenesisKeys :: Word
Cmd.numGenesisKeys = Word
numGenesisKeys
        , numUTxOKeys :: Word
Cmd.numUTxOKeys = Word
numUTxOKeys
        , numPools :: Word
Cmd.numPools = Word
numPools
        , numStakeDelegators :: Word
Cmd.numStakeDelegators = Word
numStakeDelegators
        , mSystemStart :: Maybe SystemStart
Cmd.mSystemStart = Maybe SystemStart
mSystemStart
        , mNonDelegatedSupply :: Maybe Coin
Cmd.mNonDelegatedSupply = Maybe Coin
mNonDelegatedSupply
        , delegatedSupply :: Coin
Cmd.delegatedSupply = Coin
delegatedSupply
        , network :: NetworkId
Cmd.network = NetworkId
network
        , numBulkPoolCredFiles :: Word
Cmd.numBulkPoolCredFiles = Word
numBulkPoolCredFiles
        , numBulkPoolsPerFile :: Word
Cmd.numBulkPoolsPerFile = Word
numBulkPoolsPerFile
        , numStuffedUtxo :: Word
Cmd.numStuffedUtxo = Word
numStuffedUtxo
        , mStakePoolRelaySpecFile :: Maybe FilePath
Cmd.mStakePoolRelaySpecFile = Maybe FilePath
mStakePoolRelaySpecFile
        }

-- | Hash a genesis file
runLegacyGenesisHashFileCmd
  :: ()
  => GenesisFile
  -> ExceptT GenesisCmdError IO ()
runLegacyGenesisHashFileCmd :: GenesisFile -> ExceptT GenesisCmdError IO ()
runLegacyGenesisHashFileCmd = GenesisFile -> ExceptT GenesisCmdError IO ()
runGenesisHashFileCmd