{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}

-- | Shelley CLI command types
module Cardano.CLI.Shelley.Commands
  ( -- * CLI command types
    ShelleyCommand (..)
  , AddressCmd (..)
  , StakeAddressCmd (..)
  , KeyCmd (..)
  , TransactionCmd (..)
  , NodeCmd (..)
  , PoolCmd (..)
  , QueryCmd (..)
  , GovernanceCmd (..)
  , GenesisCmd (..)
  , TextViewCmd (..)
  , renderShelleyCommand

    -- * CLI flag types
  , AddressKeyType (..)
  , ByronKeyType (..)
  , ByronKeyFormat (..)
  , CardanoAddressKeyType (..)
  , GenesisDir (..)
  , TxInCount (..)
  , TxOutCount (..)
  , TxShelleyWitnessCount (..)
  , TxByronWitnessCount (..)
  , SomeKeyFile (..)
  , OpCertCounterFile (..)
  , OutputFile (..)
  , ProtocolParamsFile (..)
  , ProtocolParamsSourceSpec (..)
  , WitnessFile (..)
  , TxFile (..)
  , InputTxBodyOrTxFile (..)
  , VerificationKeyBase64 (..)
  , GenesisKeyFile (..)
  , MetadataFile (..)
  , PoolMetadataFile (..)
  , PrivKeyFile (..)
  , BlockId (..)
  , WitnessSigningData (..)
  , ColdVerificationKeyOrFile (..)
  ) where

import           Prelude

import           Cardano.Api.Shelley

import           Data.Text (Text)

import           Cardano.CLI.Shelley.Key (PaymentVerifier, StakeVerifier, VerificationKeyOrFile,
                   VerificationKeyOrHashOrFile, VerificationKeyTextOrFile)
import           Cardano.CLI.Types

import           Cardano.Chain.Common (BlockCount)
import           Cardano.Ledger.Shelley.TxBody (MIRPot)
--
-- Shelley CLI command data types
--

-- | All the CLI subcommands under \"shelley\".
--
data ShelleyCommand
  = AddressCmd      AddressCmd
  | StakeAddressCmd StakeAddressCmd
  | KeyCmd          KeyCmd
  | TransactionCmd  TransactionCmd
  | NodeCmd         NodeCmd
  | PoolCmd         PoolCmd
  | QueryCmd        QueryCmd
  | GovernanceCmd   GovernanceCmd
  | GenesisCmd      GenesisCmd
  | TextViewCmd     TextViewCmd

renderShelleyCommand :: ShelleyCommand -> Text
renderShelleyCommand :: ShelleyCommand -> Text
renderShelleyCommand ShelleyCommand
sc =
  case ShelleyCommand
sc of
    AddressCmd AddressCmd
cmd -> AddressCmd -> Text
renderAddressCmd AddressCmd
cmd
    StakeAddressCmd StakeAddressCmd
cmd -> StakeAddressCmd -> Text
renderStakeAddressCmd StakeAddressCmd
cmd
    KeyCmd KeyCmd
cmd -> KeyCmd -> Text
renderKeyCmd KeyCmd
cmd
    TransactionCmd TransactionCmd
cmd -> TransactionCmd -> Text
renderTransactionCmd TransactionCmd
cmd
    NodeCmd NodeCmd
cmd -> NodeCmd -> Text
renderNodeCmd NodeCmd
cmd
    PoolCmd PoolCmd
cmd -> PoolCmd -> Text
renderPoolCmd PoolCmd
cmd
    QueryCmd QueryCmd
cmd -> QueryCmd -> Text
renderQueryCmd QueryCmd
cmd
    GovernanceCmd GovernanceCmd
cmd -> GovernanceCmd -> Text
renderGovernanceCmd GovernanceCmd
cmd
    GenesisCmd GenesisCmd
cmd -> GenesisCmd -> Text
renderGenesisCmd GenesisCmd
cmd
    TextViewCmd TextViewCmd
cmd -> TextViewCmd -> Text
renderTextViewCmd TextViewCmd
cmd

data AddressCmd
  = AddressKeyGen AddressKeyType VerificationKeyFile SigningKeyFile
  | AddressKeyHash VerificationKeyTextOrFile (Maybe OutputFile)
  | AddressBuild
      PaymentVerifier
      (Maybe StakeVerifier)
      NetworkId
      (Maybe OutputFile)
  | AddressInfo Text (Maybe OutputFile)
  deriving Int -> AddressCmd -> ShowS
[AddressCmd] -> ShowS
AddressCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddressCmd] -> ShowS
$cshowList :: [AddressCmd] -> ShowS
show :: AddressCmd -> String
$cshow :: AddressCmd -> String
showsPrec :: Int -> AddressCmd -> ShowS
$cshowsPrec :: Int -> AddressCmd -> ShowS
Show


renderAddressCmd :: AddressCmd -> Text
renderAddressCmd :: AddressCmd -> Text
renderAddressCmd AddressCmd
cmd =
  case AddressCmd
cmd of
    AddressKeyGen {} -> Text
"address key-gen"
    AddressKeyHash {} -> Text
"address key-hash"
    AddressBuild {} -> Text
"address build"
    AddressInfo {} -> Text
"address info"

data StakeAddressCmd
  = StakeAddressKeyGen VerificationKeyFile SigningKeyFile
  | StakeAddressKeyHash (VerificationKeyOrFile StakeKey) (Maybe OutputFile)
  | StakeAddressBuild StakeVerifier NetworkId (Maybe OutputFile)
  | StakeRegistrationCert StakeVerifier OutputFile
  | StakeCredentialDelegationCert
      StakeVerifier
      (VerificationKeyOrHashOrFile StakePoolKey)
      OutputFile
  | StakeCredentialDeRegistrationCert StakeVerifier OutputFile
  deriving Int -> StakeAddressCmd -> ShowS
[StakeAddressCmd] -> ShowS
StakeAddressCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [StakeAddressCmd] -> ShowS
$cshowList :: [StakeAddressCmd] -> ShowS
show :: StakeAddressCmd -> String
$cshow :: StakeAddressCmd -> String
showsPrec :: Int -> StakeAddressCmd -> ShowS
$cshowsPrec :: Int -> StakeAddressCmd -> ShowS
Show

renderStakeAddressCmd :: StakeAddressCmd -> Text
renderStakeAddressCmd :: StakeAddressCmd -> Text
renderStakeAddressCmd StakeAddressCmd
cmd =
  case StakeAddressCmd
cmd of
    StakeAddressKeyGen {} -> Text
"stake-address key-gen"
    StakeAddressKeyHash {} -> Text
"stake-address key-hash"
    StakeAddressBuild {} -> Text
"stake-address build"
    StakeRegistrationCert {} -> Text
"stake-address registration-certificate"
    StakeCredentialDelegationCert {} -> Text
"stake-address delegation-certificate"
    StakeCredentialDeRegistrationCert {} -> Text
"stake-address deregistration-certificate"

data KeyCmd
  = KeyGetVerificationKey SigningKeyFile VerificationKeyFile
  | KeyNonExtendedKey  VerificationKeyFile VerificationKeyFile
  | KeyConvertByronKey (Maybe Text) ByronKeyType SomeKeyFile OutputFile
  | KeyConvertByronGenesisVKey VerificationKeyBase64 OutputFile
  | KeyConvertITNStakeKey SomeKeyFile OutputFile
  | KeyConvertITNExtendedToStakeKey SomeKeyFile OutputFile
  | KeyConvertITNBip32ToStakeKey SomeKeyFile OutputFile
  | KeyConvertCardanoAddressSigningKey CardanoAddressKeyType SigningKeyFile OutputFile
  deriving Int -> KeyCmd -> ShowS
[KeyCmd] -> ShowS
KeyCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [KeyCmd] -> ShowS
$cshowList :: [KeyCmd] -> ShowS
show :: KeyCmd -> String
$cshow :: KeyCmd -> String
showsPrec :: Int -> KeyCmd -> ShowS
$cshowsPrec :: Int -> KeyCmd -> ShowS
Show

renderKeyCmd :: KeyCmd -> Text
renderKeyCmd :: KeyCmd -> Text
renderKeyCmd KeyCmd
cmd =
  case KeyCmd
cmd of
    KeyGetVerificationKey {} -> Text
"key verification-key"
    KeyNonExtendedKey {} -> Text
"key non-extended-key"
    KeyConvertByronKey {} -> Text
"key convert-byron-key"
    KeyConvertByronGenesisVKey {} -> Text
"key convert-byron-genesis-key"
    KeyConvertITNStakeKey {} -> Text
"key convert-itn-key"
    KeyConvertITNExtendedToStakeKey {} -> Text
"key convert-itn-extended-key"
    KeyConvertITNBip32ToStakeKey {} -> Text
"key convert-itn-bip32-key"
    KeyConvertCardanoAddressSigningKey {} -> Text
"key convert-cardano-address-signing-key"

data TransactionCmd
  = TxBuildRaw
      AnyCardanoEra
      (Maybe ScriptValidity) -- ^ Mark script as expected to pass or fail validation
      [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
      -- ^ Transaction inputs with optional spending scripts
      [TxIn]
      -- ^ Read only reference inputs
      [TxIn]
      -- ^ Transaction inputs for collateral, only key witnesses, no scripts.
      (Maybe TxOutAnyEra)
      -- ^ Return collateral
      (Maybe Lovelace)
      -- ^ Total collateral
      [RequiredSigner]
      -- ^ Required signers
      [TxOutAnyEra]
      (Maybe (Value, [ScriptWitnessFiles WitCtxMint]))
      -- ^ Multi-Asset value with script witness
      (Maybe SlotNo)
      -- ^ Transaction lower bound
      (Maybe SlotNo)
      -- ^ Transaction upper bound
      (Maybe Lovelace)
      -- ^ Tx fee
      [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
      -- ^ Certificates with potential script witness
      [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
      TxMetadataJsonSchema
      [ScriptFile]
      -- ^ Auxiliary scripts
      [MetadataFile]
      (Maybe ProtocolParamsSourceSpec)
      (Maybe UpdateProposalFile)
      TxBodyFile

    -- | Like 'TxBuildRaw' but without the fee, and with a change output.
  | TxBuild
      AnyCardanoEra
      AnyConsensusModeParams
      NetworkId
      (Maybe ScriptValidity) -- ^ Mark script as expected to pass or fail validation
      (Maybe Word)
      -- ^ Override the required number of tx witnesses
      [(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
      -- ^ Transaction inputs with optional spending scripts
      [TxIn]
      -- ^ Read only reference inputs
      [RequiredSigner]
      -- ^ Required signers
      [TxIn]
      -- ^ Transaction inputs for collateral, only key witnesses, no scripts.
      (Maybe TxOutAnyEra)
      -- ^ Return collateral
      (Maybe Lovelace)
      -- ^ Total collateral
      [TxOutAnyEra]
      -- ^ Normal outputs
      TxOutChangeAddress
      -- ^ A change output
      (Maybe (Value, [ScriptWitnessFiles WitCtxMint]))
      -- ^ Multi-Asset value with script witness
      (Maybe SlotNo)
      -- ^ Transaction lower bound
      (Maybe SlotNo)
      -- ^ Transaction upper bound
      [(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
      -- ^ Certificates with potential script witness
      [(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
      -- ^ Withdrawals with potential script witness
      TxMetadataJsonSchema
      [ScriptFile]
      -- ^ Auxiliary scripts
      [MetadataFile]
      (Maybe ProtocolParamsSourceSpec)
      (Maybe UpdateProposalFile)
      TxBuildOutputOptions
  | TxSign InputTxBodyOrTxFile [WitnessSigningData] (Maybe NetworkId) TxFile
  | TxCreateWitness TxBodyFile WitnessSigningData (Maybe NetworkId) OutputFile
  | TxAssembleTxBodyWitness TxBodyFile [WitnessFile] OutputFile
  | TxSubmit AnyConsensusModeParams NetworkId FilePath
  | TxMintedPolicyId ScriptFile
  | TxCalculateMinFee
      TxBodyFile
      (Maybe NetworkId)
      ProtocolParamsSourceSpec
      TxInCount
      TxOutCount
      TxShelleyWitnessCount
      TxByronWitnessCount
  | TxCalculateMinRequiredUTxO
      AnyCardanoEra
      ProtocolParamsSourceSpec
      TxOutAnyEra
  | TxHashScriptData
      ScriptDataOrFile
  | TxGetTxId InputTxBodyOrTxFile
  | TxView InputTxBodyOrTxFile

data InputTxBodyOrTxFile = InputTxBodyFile TxBodyFile | InputTxFile TxFile
  deriving Int -> InputTxBodyOrTxFile -> ShowS
[InputTxBodyOrTxFile] -> ShowS
InputTxBodyOrTxFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [InputTxBodyOrTxFile] -> ShowS
$cshowList :: [InputTxBodyOrTxFile] -> ShowS
show :: InputTxBodyOrTxFile -> String
$cshow :: InputTxBodyOrTxFile -> String
showsPrec :: Int -> InputTxBodyOrTxFile -> ShowS
$cshowsPrec :: Int -> InputTxBodyOrTxFile -> ShowS
Show

data ProtocolParamsSourceSpec
  = ParamsFromGenesis !GenesisFile
    -- ^ We allow an appropriately forewarned user to obtain protocol params
    --   directly from the genesis file, which allows them to avoid running
    --   the node in case they would like to estimate the fee using the
    --   blockchain's initial protocol parameters.
  | ParamsFromFile !ProtocolParamsFile
    -- ^ Obtain protocol parameters from a file structured by the
    --   'cardano-api' 'ProtocolParameters' data type.
  deriving Int -> ProtocolParamsSourceSpec -> ShowS
[ProtocolParamsSourceSpec] -> ShowS
ProtocolParamsSourceSpec -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProtocolParamsSourceSpec] -> ShowS
$cshowList :: [ProtocolParamsSourceSpec] -> ShowS
show :: ProtocolParamsSourceSpec -> String
$cshow :: ProtocolParamsSourceSpec -> String
showsPrec :: Int -> ProtocolParamsSourceSpec -> ShowS
$cshowsPrec :: Int -> ProtocolParamsSourceSpec -> ShowS
Show

renderTransactionCmd :: TransactionCmd -> Text
renderTransactionCmd :: TransactionCmd -> Text
renderTransactionCmd TransactionCmd
cmd =
  case TransactionCmd
cmd of
    TxBuild {} -> Text
"transaction build"
    TxBuildRaw {} -> Text
"transaction build-raw"
    TxSign {} -> Text
"transaction sign"
    TxCreateWitness {} -> Text
"transaction witness"
    TxAssembleTxBodyWitness {} -> Text
"transaction sign-witness"
    TxSubmit {} -> Text
"transaction submit"
    TxMintedPolicyId {} -> Text
"transaction policyid"
    TxCalculateMinFee {} -> Text
"transaction calculate-min-fee"
    TxCalculateMinRequiredUTxO {} -> Text
"transaction calculate-min-value"
    TxHashScriptData {} -> Text
"transaction hash-script-data"
    TxGetTxId {} -> Text
"transaction txid"
    TxView {} -> Text
"transaction view"

data NodeCmd
  = NodeKeyGenCold VerificationKeyFile SigningKeyFile OpCertCounterFile
  | NodeKeyGenKES  VerificationKeyFile SigningKeyFile
  | NodeKeyGenVRF  VerificationKeyFile SigningKeyFile
  | NodeKeyHashVRF  (VerificationKeyOrFile VrfKey) (Maybe OutputFile)
  | NodeNewCounter ColdVerificationKeyOrFile Word OpCertCounterFile
  | NodeIssueOpCert (VerificationKeyOrFile KesKey) SigningKeyFile OpCertCounterFile
                    KESPeriod OutputFile
  deriving Int -> NodeCmd -> ShowS
[NodeCmd] -> ShowS
NodeCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NodeCmd] -> ShowS
$cshowList :: [NodeCmd] -> ShowS
show :: NodeCmd -> String
$cshow :: NodeCmd -> String
showsPrec :: Int -> NodeCmd -> ShowS
$cshowsPrec :: Int -> NodeCmd -> ShowS
Show

renderNodeCmd :: NodeCmd -> Text
renderNodeCmd :: NodeCmd -> Text
renderNodeCmd NodeCmd
cmd = do
  case NodeCmd
cmd of
    NodeKeyGenCold {} -> Text
"node key-gen"
    NodeKeyGenKES {} -> Text
"node key-gen-KES"
    NodeKeyGenVRF {} -> Text
"node key-gen-VRF"
    NodeKeyHashVRF {} -> Text
"node key-hash-VRF"
    NodeNewCounter {} -> Text
"node new-counter"
    NodeIssueOpCert{} -> Text
"node issue-op-cert"


data PoolCmd
  = PoolRegistrationCert
      (VerificationKeyOrFile StakePoolKey)
      -- ^ Stake pool verification key.
      (VerificationKeyOrFile VrfKey)
      -- ^ VRF Verification key.
      Lovelace
      -- ^ Pool pledge.
      Lovelace
      -- ^ Pool cost.
      Rational
      -- ^ Pool margin.
      (VerificationKeyOrFile StakeKey)
      -- ^ Reward account verification staking key.
      [VerificationKeyOrFile StakeKey]
      -- ^ Pool owner verification staking key(s).
      [StakePoolRelay]
      -- ^ Stake pool relays.
      (Maybe StakePoolMetadataReference)
      -- ^ Stake pool metadata.
      NetworkId
      OutputFile
  | PoolRetirementCert
      (VerificationKeyOrFile StakePoolKey)
      -- ^ Stake pool verification key.
      EpochNo
      -- ^ Epoch in which to retire the stake pool.
      OutputFile
  | PoolGetId (VerificationKeyOrFile StakePoolKey) OutputFormat
  | PoolMetadataHash PoolMetadataFile (Maybe OutputFile)
  deriving Int -> PoolCmd -> ShowS
[PoolCmd] -> ShowS
PoolCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PoolCmd] -> ShowS
$cshowList :: [PoolCmd] -> ShowS
show :: PoolCmd -> String
$cshow :: PoolCmd -> String
showsPrec :: Int -> PoolCmd -> ShowS
$cshowsPrec :: Int -> PoolCmd -> ShowS
Show

renderPoolCmd :: PoolCmd -> Text
renderPoolCmd :: PoolCmd -> Text
renderPoolCmd PoolCmd
cmd =
  case PoolCmd
cmd of
    PoolRegistrationCert {} -> Text
"stake-pool registration-certificate"
    PoolRetirementCert {} -> Text
"stake-pool deregistration-certificate"
    PoolGetId {} -> Text
"stake-pool id"
    PoolMetadataHash {} -> Text
"stake-pool metadata-hash"

data QueryCmd =
    QueryLeadershipSchedule
      AnyConsensusModeParams
      NetworkId
      GenesisFile
      (VerificationKeyOrHashOrFile StakePoolKey)
      SigningKeyFile
      EpochLeadershipSchedule
      (Maybe OutputFile)
  | QueryProtocolParameters' AnyConsensusModeParams NetworkId (Maybe OutputFile)
  | QueryTip AnyConsensusModeParams NetworkId (Maybe OutputFile)
  | QueryStakePools' AnyConsensusModeParams NetworkId (Maybe OutputFile)
  | QueryStakeDistribution' AnyConsensusModeParams NetworkId (Maybe OutputFile)
  | QueryStakeAddressInfo AnyConsensusModeParams StakeAddress NetworkId (Maybe OutputFile)
  | QueryUTxO' AnyConsensusModeParams QueryUTxOFilter NetworkId (Maybe OutputFile)
  | QueryDebugLedgerState' AnyConsensusModeParams NetworkId (Maybe OutputFile)
  | QueryProtocolState' AnyConsensusModeParams NetworkId (Maybe OutputFile)
  | QueryStakeSnapshot'
      AnyConsensusModeParams
      NetworkId
      (AllOrOnly [Hash StakePoolKey])
      (Maybe OutputFile)
  | QueryKesPeriodInfo
      AnyConsensusModeParams
      NetworkId
      FilePath
      -- ^ Node operational certificate
      (Maybe OutputFile)
  | QueryPoolState' AnyConsensusModeParams NetworkId [Hash StakePoolKey]
  | QueryTxMempool AnyConsensusModeParams NetworkId TxMempoolQuery (Maybe OutputFile)
  deriving Int -> QueryCmd -> ShowS
[QueryCmd] -> ShowS
QueryCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QueryCmd] -> ShowS
$cshowList :: [QueryCmd] -> ShowS
show :: QueryCmd -> String
$cshow :: QueryCmd -> String
showsPrec :: Int -> QueryCmd -> ShowS
$cshowsPrec :: Int -> QueryCmd -> ShowS
Show

renderQueryCmd :: QueryCmd -> Text
renderQueryCmd :: QueryCmd -> Text
renderQueryCmd QueryCmd
cmd =
  case QueryCmd
cmd of
    QueryLeadershipSchedule {} -> Text
"query leadership-schedule"
    QueryProtocolParameters' {} -> Text
"query protocol-parameters "
    QueryTip {} -> Text
"query tip"
    QueryStakePools' {} -> Text
"query stake-pools"
    QueryStakeDistribution' {} -> Text
"query stake-distribution"
    QueryStakeAddressInfo {} -> Text
"query stake-address-info"
    QueryUTxO' {} -> Text
"query utxo"
    QueryDebugLedgerState' {} -> Text
"query ledger-state"
    QueryProtocolState' {} -> Text
"query protocol-state"
    QueryStakeSnapshot' {} -> Text
"query stake-snapshot"
    QueryKesPeriodInfo {} -> Text
"query kes-period-info"
    QueryPoolState' {} -> Text
"query pool-state"
    QueryTxMempool AnyConsensusModeParams
_ NetworkId
_ TxMempoolQuery
query Maybe OutputFile
_ -> Text
"query tx-mempool" forall a. Semigroup a => a -> a -> a
<> TxMempoolQuery -> Text
renderTxMempoolQuery TxMempoolQuery
query
  where
    renderTxMempoolQuery :: TxMempoolQuery -> Text
renderTxMempoolQuery TxMempoolQuery
query =
      case TxMempoolQuery
query of
        TxMempoolQueryTxExists TxId
tx -> Text
"tx-exists " forall a. Semigroup a => a -> a -> a
<> forall a. SerialiseAsRawBytes a => a -> Text
serialiseToRawBytesHexText TxId
tx
        TxMempoolQuery
TxMempoolQueryNextTx -> Text
"next-tx"
        TxMempoolQuery
TxMempoolQueryInfo -> Text
"info"


data GovernanceCmd
  = GovernanceMIRPayStakeAddressesCertificate
      MIRPot
      [StakeAddress]
      [Lovelace]
      OutputFile
  | GovernanceMIRTransfer Lovelace OutputFile TransferDirection
  | GovernanceGenesisKeyDelegationCertificate
      (VerificationKeyOrHashOrFile GenesisKey)
      (VerificationKeyOrHashOrFile GenesisDelegateKey)
      (VerificationKeyOrHashOrFile VrfKey)
      OutputFile
  | GovernanceUpdateProposal OutputFile EpochNo
                             [VerificationKeyFile]
                             ProtocolParametersUpdate
                             (Maybe FilePath)
  deriving Int -> GovernanceCmd -> ShowS
[GovernanceCmd] -> ShowS
GovernanceCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GovernanceCmd] -> ShowS
$cshowList :: [GovernanceCmd] -> ShowS
show :: GovernanceCmd -> String
$cshow :: GovernanceCmd -> String
showsPrec :: Int -> GovernanceCmd -> ShowS
$cshowsPrec :: Int -> GovernanceCmd -> ShowS
Show

renderGovernanceCmd :: GovernanceCmd -> Text
renderGovernanceCmd :: GovernanceCmd -> Text
renderGovernanceCmd GovernanceCmd
cmd =
  case GovernanceCmd
cmd of
    GovernanceGenesisKeyDelegationCertificate {} -> Text
"governance create-genesis-key-delegation-certificate"
    GovernanceMIRPayStakeAddressesCertificate {} -> Text
"governance create-mir-certificate stake-addresses"
    GovernanceMIRTransfer Lovelace
_ OutputFile
_ TransferDirection
TransferToTreasury -> Text
"governance create-mir-certificate transfer-to-treasury"
    GovernanceMIRTransfer Lovelace
_ OutputFile
_ TransferDirection
TransferToReserves -> Text
"governance create-mir-certificate transfer-to-reserves"
    GovernanceUpdateProposal {} -> Text
"governance create-update-proposal"

data TextViewCmd
  = TextViewInfo !FilePath (Maybe OutputFile)
  deriving Int -> TextViewCmd -> ShowS
[TextViewCmd] -> ShowS
TextViewCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TextViewCmd] -> ShowS
$cshowList :: [TextViewCmd] -> ShowS
show :: TextViewCmd -> String
$cshow :: TextViewCmd -> String
showsPrec :: Int -> TextViewCmd -> ShowS
$cshowsPrec :: Int -> TextViewCmd -> ShowS
Show


renderTextViewCmd :: TextViewCmd -> Text
renderTextViewCmd :: TextViewCmd -> Text
renderTextViewCmd (TextViewInfo String
_ Maybe OutputFile
_) = Text
"text-view decode-cbor"

data GenesisCmd
  = GenesisCreate GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) NetworkId
  | GenesisCreateCardano GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) BlockCount Word Rational NetworkId FilePath FilePath FilePath FilePath (Maybe FilePath)
  | GenesisCreateStaked
      GenesisDir
      Word
      Word
      Word
      Word
      (Maybe SystemStart)
      (Maybe Lovelace)
      Lovelace
      NetworkId
      Word
      Word
      Word
      (Maybe FilePath) -- ^ Relay specification filepath
  | GenesisKeyGenGenesis VerificationKeyFile SigningKeyFile
  | GenesisKeyGenDelegate VerificationKeyFile SigningKeyFile OpCertCounterFile
  | GenesisKeyGenUTxO VerificationKeyFile SigningKeyFile
  | GenesisCmdKeyHash VerificationKeyFile
  | GenesisVerKey VerificationKeyFile SigningKeyFile
  | GenesisTxIn VerificationKeyFile NetworkId (Maybe OutputFile)
  | GenesisAddr VerificationKeyFile NetworkId (Maybe OutputFile)
  | GenesisHashFile GenesisFile
  deriving Int -> GenesisCmd -> ShowS
[GenesisCmd] -> ShowS
GenesisCmd -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenesisCmd] -> ShowS
$cshowList :: [GenesisCmd] -> ShowS
show :: GenesisCmd -> String
$cshow :: GenesisCmd -> String
showsPrec :: Int -> GenesisCmd -> ShowS
$cshowsPrec :: Int -> GenesisCmd -> ShowS
Show

renderGenesisCmd :: GenesisCmd -> Text
renderGenesisCmd :: GenesisCmd -> Text
renderGenesisCmd GenesisCmd
cmd =
  case GenesisCmd
cmd of
    GenesisCreate {} -> Text
"genesis create"
    GenesisCreateCardano {} -> Text
"genesis create-cardano"
    GenesisCreateStaked {} -> Text
"genesis create-staked"
    GenesisKeyGenGenesis {} -> Text
"genesis key-gen-genesis"
    GenesisKeyGenDelegate {} -> Text
"genesis key-gen-delegate"
    GenesisKeyGenUTxO {} -> Text
"genesis key-gen-utxo"
    GenesisCmdKeyHash {} -> Text
"genesis key-hash"
    GenesisVerKey {} -> Text
"genesis get-ver-key"
    GenesisTxIn {} -> Text
"genesis initial-txin"
    GenesisAddr {} -> Text
"genesis initial-addr"
    GenesisHashFile {} -> Text
"genesis hash"

--
-- Shelley CLI flag/option data types
--

newtype ProtocolParamsFile
  = ProtocolParamsFile FilePath
  deriving (Int -> ProtocolParamsFile -> ShowS
[ProtocolParamsFile] -> ShowS
ProtocolParamsFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ProtocolParamsFile] -> ShowS
$cshowList :: [ProtocolParamsFile] -> ShowS
show :: ProtocolParamsFile -> String
$cshow :: ProtocolParamsFile -> String
showsPrec :: Int -> ProtocolParamsFile -> ShowS
$cshowsPrec :: Int -> ProtocolParamsFile -> ShowS
Show, ProtocolParamsFile -> ProtocolParamsFile -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ProtocolParamsFile -> ProtocolParamsFile -> Bool
$c/= :: ProtocolParamsFile -> ProtocolParamsFile -> Bool
== :: ProtocolParamsFile -> ProtocolParamsFile -> Bool
$c== :: ProtocolParamsFile -> ProtocolParamsFile -> Bool
Eq)

newtype TxInCount
  = TxInCount Int
  deriving Int -> TxInCount -> ShowS
[TxInCount] -> ShowS
TxInCount -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxInCount] -> ShowS
$cshowList :: [TxInCount] -> ShowS
show :: TxInCount -> String
$cshow :: TxInCount -> String
showsPrec :: Int -> TxInCount -> ShowS
$cshowsPrec :: Int -> TxInCount -> ShowS
Show

newtype TxOutCount
  = TxOutCount Int
  deriving Int -> TxOutCount -> ShowS
[TxOutCount] -> ShowS
TxOutCount -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxOutCount] -> ShowS
$cshowList :: [TxOutCount] -> ShowS
show :: TxOutCount -> String
$cshow :: TxOutCount -> String
showsPrec :: Int -> TxOutCount -> ShowS
$cshowsPrec :: Int -> TxOutCount -> ShowS
Show

newtype TxShelleyWitnessCount
  = TxShelleyWitnessCount Int
  deriving Int -> TxShelleyWitnessCount -> ShowS
[TxShelleyWitnessCount] -> ShowS
TxShelleyWitnessCount -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxShelleyWitnessCount] -> ShowS
$cshowList :: [TxShelleyWitnessCount] -> ShowS
show :: TxShelleyWitnessCount -> String
$cshow :: TxShelleyWitnessCount -> String
showsPrec :: Int -> TxShelleyWitnessCount -> ShowS
$cshowsPrec :: Int -> TxShelleyWitnessCount -> ShowS
Show

newtype TxByronWitnessCount
  = TxByronWitnessCount Int
  deriving Int -> TxByronWitnessCount -> ShowS
[TxByronWitnessCount] -> ShowS
TxByronWitnessCount -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TxByronWitnessCount] -> ShowS
$cshowList :: [TxByronWitnessCount] -> ShowS
show :: TxByronWitnessCount -> String
$cshow :: TxByronWitnessCount -> String
showsPrec :: Int -> TxByronWitnessCount -> ShowS
$cshowsPrec :: Int -> TxByronWitnessCount -> ShowS
Show

newtype BlockId
  = BlockId String -- Probably not a String
  deriving Int -> BlockId -> ShowS
[BlockId] -> ShowS
BlockId -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlockId] -> ShowS
$cshowList :: [BlockId] -> ShowS
show :: BlockId -> String
$cshow :: BlockId -> String
showsPrec :: Int -> BlockId -> ShowS
$cshowsPrec :: Int -> BlockId -> ShowS
Show

newtype GenesisKeyFile
  = GenesisKeyFile FilePath
  deriving Int -> GenesisKeyFile -> ShowS
[GenesisKeyFile] -> ShowS
GenesisKeyFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenesisKeyFile] -> ShowS
$cshowList :: [GenesisKeyFile] -> ShowS
show :: GenesisKeyFile -> String
$cshow :: GenesisKeyFile -> String
showsPrec :: Int -> GenesisKeyFile -> ShowS
$cshowsPrec :: Int -> GenesisKeyFile -> ShowS
Show

data MetadataFile = MetadataFileJSON FilePath
                  | MetadataFileCBOR FilePath

  deriving Int -> MetadataFile -> ShowS
[MetadataFile] -> ShowS
MetadataFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MetadataFile] -> ShowS
$cshowList :: [MetadataFile] -> ShowS
show :: MetadataFile -> String
$cshow :: MetadataFile -> String
showsPrec :: Int -> MetadataFile -> ShowS
$cshowsPrec :: Int -> MetadataFile -> ShowS
Show

newtype OutputFile = OutputFile
  { OutputFile -> String
unOutputFile :: FilePath
  }
  deriving Int -> OutputFile -> ShowS
[OutputFile] -> ShowS
OutputFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OutputFile] -> ShowS
$cshowList :: [OutputFile] -> ShowS
show :: OutputFile -> String
$cshow :: OutputFile -> String
showsPrec :: Int -> OutputFile -> ShowS
$cshowsPrec :: Int -> OutputFile -> ShowS
Show

newtype PoolMetadataFile = PoolMetadataFile
  { PoolMetadataFile -> String
unPoolMetadataFile :: FilePath }
  deriving Int -> PoolMetadataFile -> ShowS
[PoolMetadataFile] -> ShowS
PoolMetadataFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PoolMetadataFile] -> ShowS
$cshowList :: [PoolMetadataFile] -> ShowS
show :: PoolMetadataFile -> String
$cshow :: PoolMetadataFile -> String
showsPrec :: Int -> PoolMetadataFile -> ShowS
$cshowsPrec :: Int -> PoolMetadataFile -> ShowS
Show

newtype GenesisDir
  = GenesisDir FilePath
  deriving Int -> GenesisDir -> ShowS
[GenesisDir] -> ShowS
GenesisDir -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenesisDir] -> ShowS
$cshowList :: [GenesisDir] -> ShowS
show :: GenesisDir -> String
$cshow :: GenesisDir -> String
showsPrec :: Int -> GenesisDir -> ShowS
$cshowsPrec :: Int -> GenesisDir -> ShowS
Show

-- | Either a verification or signing key, used for conversions and other
-- commands that make sense for both.
--
data SomeKeyFile
  = AVerificationKeyFile VerificationKeyFile
  | ASigningKeyFile SigningKeyFile
  deriving Int -> SomeKeyFile -> ShowS
[SomeKeyFile] -> ShowS
SomeKeyFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SomeKeyFile] -> ShowS
$cshowList :: [SomeKeyFile] -> ShowS
show :: SomeKeyFile -> String
$cshow :: SomeKeyFile -> String
showsPrec :: Int -> SomeKeyFile -> ShowS
$cshowsPrec :: Int -> SomeKeyFile -> ShowS
Show

data AddressKeyType
  = AddressKeyShelley
  | AddressKeyShelleyExtended
  | AddressKeyByron
  deriving Int -> AddressKeyType -> ShowS
[AddressKeyType] -> ShowS
AddressKeyType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [AddressKeyType] -> ShowS
$cshowList :: [AddressKeyType] -> ShowS
show :: AddressKeyType -> String
$cshow :: AddressKeyType -> String
showsPrec :: Int -> AddressKeyType -> ShowS
$cshowsPrec :: Int -> AddressKeyType -> ShowS
Show

data ByronKeyType
  = ByronPaymentKey  ByronKeyFormat
  | ByronGenesisKey  ByronKeyFormat
  | ByronDelegateKey ByronKeyFormat
  deriving Int -> ByronKeyType -> ShowS
[ByronKeyType] -> ShowS
ByronKeyType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ByronKeyType] -> ShowS
$cshowList :: [ByronKeyType] -> ShowS
show :: ByronKeyType -> String
$cshow :: ByronKeyType -> String
showsPrec :: Int -> ByronKeyType -> ShowS
$cshowsPrec :: Int -> ByronKeyType -> ShowS
Show

data ByronKeyFormat = NonLegacyByronKeyFormat
                    | LegacyByronKeyFormat
  deriving Int -> ByronKeyFormat -> ShowS
[ByronKeyFormat] -> ShowS
ByronKeyFormat -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ByronKeyFormat] -> ShowS
$cshowList :: [ByronKeyFormat] -> ShowS
show :: ByronKeyFormat -> String
$cshow :: ByronKeyFormat -> String
showsPrec :: Int -> ByronKeyFormat -> ShowS
$cshowsPrec :: Int -> ByronKeyFormat -> ShowS
Show

-- | The type of @cardano-address@ key.
data CardanoAddressKeyType
  = CardanoAddressShelleyPaymentKey
  | CardanoAddressShelleyStakeKey
  | CardanoAddressIcarusPaymentKey
  | CardanoAddressByronPaymentKey
  deriving Int -> CardanoAddressKeyType -> ShowS
[CardanoAddressKeyType] -> ShowS
CardanoAddressKeyType -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CardanoAddressKeyType] -> ShowS
$cshowList :: [CardanoAddressKeyType] -> ShowS
show :: CardanoAddressKeyType -> String
$cshow :: CardanoAddressKeyType -> String
showsPrec :: Int -> CardanoAddressKeyType -> ShowS
$cshowsPrec :: Int -> CardanoAddressKeyType -> ShowS
Show

newtype OpCertCounterFile
  = OpCertCounterFile FilePath
  deriving Int -> OpCertCounterFile -> ShowS
[OpCertCounterFile] -> ShowS
OpCertCounterFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OpCertCounterFile] -> ShowS
$cshowList :: [OpCertCounterFile] -> ShowS
show :: OpCertCounterFile -> String
$cshow :: OpCertCounterFile -> String
showsPrec :: Int -> OpCertCounterFile -> ShowS
$cshowsPrec :: Int -> OpCertCounterFile -> ShowS
Show

newtype PrivKeyFile
  = PrivKeyFile FilePath
  deriving Int -> PrivKeyFile -> ShowS
[PrivKeyFile] -> ShowS
PrivKeyFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrivKeyFile] -> ShowS
$cshowList :: [PrivKeyFile] -> ShowS
show :: PrivKeyFile -> String
$cshow :: PrivKeyFile -> String
showsPrec :: Int -> PrivKeyFile -> ShowS
$cshowsPrec :: Int -> PrivKeyFile -> ShowS
Show

newtype WitnessFile
  = WitnessFile FilePath
  deriving Int -> WitnessFile -> ShowS
[WitnessFile] -> ShowS
WitnessFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WitnessFile] -> ShowS
$cshowList :: [WitnessFile] -> ShowS
show :: WitnessFile -> String
$cshow :: WitnessFile -> String
showsPrec :: Int -> WitnessFile -> ShowS
$cshowsPrec :: Int -> WitnessFile -> ShowS
Show

-- | A raw verification key given in Base64, and decoded into a ByteString.
newtype VerificationKeyBase64
  = VerificationKeyBase64 String
  deriving Int -> VerificationKeyBase64 -> ShowS
[VerificationKeyBase64] -> ShowS
VerificationKeyBase64 -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VerificationKeyBase64] -> ShowS
$cshowList :: [VerificationKeyBase64] -> ShowS
show :: VerificationKeyBase64 -> String
$cshow :: VerificationKeyBase64 -> String
showsPrec :: Int -> VerificationKeyBase64 -> ShowS
$cshowsPrec :: Int -> VerificationKeyBase64 -> ShowS
Show

-- | Data required to construct a witness.
data WitnessSigningData
  = KeyWitnessSigningData
      !SigningKeyFile
      -- ^ Path to a file that should contain a signing key.
      !(Maybe (Address ByronAddr))
      -- ^ An optionally specified Byron address.
      --
      -- If specified, both the network ID and derivation path are extracted
      -- from the address and used in the construction of the Byron witness.
  deriving Int -> WitnessSigningData -> ShowS
[WitnessSigningData] -> ShowS
WitnessSigningData -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WitnessSigningData] -> ShowS
$cshowList :: [WitnessSigningData] -> ShowS
show :: WitnessSigningData -> String
$cshow :: WitnessSigningData -> String
showsPrec :: Int -> WitnessSigningData -> ShowS
$cshowsPrec :: Int -> WitnessSigningData -> ShowS
Show

-- | Either a stake pool verification key, genesis delegate verification key,
-- or a path to a cold verification key file.
--
-- Note that a "cold verification key" refers to either a stake pool or
-- genesis delegate verification key.
--
-- TODO: A genesis delegate extended key should also be valid here.
data ColdVerificationKeyOrFile
  = ColdStakePoolVerificationKey !(VerificationKey StakePoolKey)
  | ColdGenesisDelegateVerificationKey !(VerificationKey GenesisDelegateKey)
  | ColdVerificationKeyFile !VerificationKeyFile
  deriving Int -> ColdVerificationKeyOrFile -> ShowS
[ColdVerificationKeyOrFile] -> ShowS
ColdVerificationKeyOrFile -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ColdVerificationKeyOrFile] -> ShowS
$cshowList :: [ColdVerificationKeyOrFile] -> ShowS
show :: ColdVerificationKeyOrFile -> String
$cshow :: ColdVerificationKeyOrFile -> String
showsPrec :: Int -> ColdVerificationKeyOrFile -> ShowS
$cshowsPrec :: Int -> ColdVerificationKeyOrFile -> ShowS
Show