module Cardano.CLI.Byron.Parsers
  ( ByronCommand(..)
  , NodeCmd(..)
  , backwardsCompatibilityCommands
  , parseByronCommands
  , parseHeavyDelThd
  , parseInstallerHash
  , parseMaxBlockSize
  , parseMaxHeaderSize
  , parseMaxTxSize
  , parseMaxProposalSize
  , parseMpcThd
  , parseScriptVersion
  , parseSlotDuration
  , parseSoftforkRule
  , parseSystemTag
  , parseTxFeePolicy
  , parseUpdateProposalThd
  , parseUpdateProposalTTL
  , parseUnlockStakeEpoch
  , parseUpdateVoteThd
  ) where

import           Cardano.Prelude hiding (option)
import           Prelude (String)

import           Control.Monad (fail)
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import           Data.Attoparsec.Combinator ((<?>))
import qualified Data.ByteString.Char8 as BSC
import qualified Data.ByteString.Lazy.Char8 as C8
import qualified Data.Char as Char
import qualified Data.Text as Text
import           Data.Time (UTCTime)
import           Data.Time.Clock.POSIX (posixSecondsToUTCTime)
import           Formatting (build, sformat)

import           Options.Applicative
import qualified Options.Applicative as Opt

import           Cardano.Binary (Annotated (..))

import           Cardano.Crypto (RequiresNetworkMagic (..))
import           Cardano.Crypto.Hashing (hashRaw)
import           Cardano.Crypto.ProtocolMagic (AProtocolMagic (..), ProtocolMagic,
                   ProtocolMagicId (..))

import           Cardano.Chain.Common (BlockCount (..), TxFeePolicy (..), TxSizeLinear (..),
                   decodeAddressBase58, rationalToLovelacePortion)
import qualified Cardano.Chain.Common as Byron
import           Cardano.Chain.Genesis (FakeAvvmOptions (..), TestnetBalanceOptions (..))
import           Cardano.Chain.Slotting (EpochNumber (..), SlotNumber (..))
import           Cardano.Chain.Update (ApplicationName (..), InstallerHash (..), NumSoftwareVersion,
                   ProtocolVersion (..), SoftforkRule (..), SoftwareVersion (..), SystemTag (..),
                   checkApplicationName, checkSystemTag)

import           Cardano.Api hiding (UpdateProposal, GenesisParameters)
import           Cardano.Api.Byron (Address (..), ByronProtocolParametersUpdate (..), Lovelace (..),
                   toByronLovelace)

import           Cardano.CLI.Byron.Commands
import           Cardano.CLI.Byron.Genesis
import           Cardano.CLI.Byron.Key
import           Cardano.CLI.Byron.Tx
import           Cardano.CLI.Run (ClientCommand (ByronCommand))
import           Cardano.CLI.Shelley.Commands (ByronKeyFormat (..))
import           Cardano.CLI.Types

command' :: String -> String -> Parser a -> Mod CommandFields a
command' :: String -> String -> Parser a -> Mod CommandFields a
command' String
c String
descr Parser a
p =
    String -> ParserInfo a -> Mod CommandFields a
forall a. String -> ParserInfo a -> Mod CommandFields a
command String
c (ParserInfo a -> Mod CommandFields a)
-> ParserInfo a -> Mod CommandFields a
forall a b. (a -> b) -> a -> b
$ Parser a -> InfoMod a -> ParserInfo a
forall a. Parser a -> InfoMod a -> ParserInfo a
info (Parser a
p Parser a -> Parser (a -> a) -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f (a -> b) -> f b
<**> Parser (a -> a)
forall a. Parser (a -> a)
helper)
              (InfoMod a -> ParserInfo a) -> InfoMod a -> ParserInfo a
forall a b. (a -> b) -> a -> b
$ [InfoMod a] -> InfoMod a
forall a. Monoid a => [a] -> a
mconcat [ String -> InfoMod a
forall a. String -> InfoMod a
progDesc String
descr ]

backwardsCompatibilityCommands :: Parser ClientCommand
backwardsCompatibilityCommands :: Parser ClientCommand
backwardsCompatibilityCommands =
  [Parser ClientCommand] -> Parser ClientCommand
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum [Parser ClientCommand]
hiddenCmds
 where
  convertToByronCommand :: Mod CommandFields ByronCommand -> Parser ClientCommand
  convertToByronCommand :: Mod CommandFields ByronCommand -> Parser ClientCommand
convertToByronCommand Mod CommandFields ByronCommand
p = ByronCommand -> ClientCommand
ByronCommand (ByronCommand -> ClientCommand)
-> Parser ByronCommand -> Parser ClientCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod CommandFields ByronCommand -> Parser ByronCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser (Mod CommandFields ByronCommand
p Mod CommandFields ByronCommand
-> Mod CommandFields ByronCommand -> Mod CommandFields ByronCommand
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields ByronCommand
forall (f :: * -> *) a. Mod f a
Opt.internal)

  hiddenCmds :: [Parser ClientCommand]
  hiddenCmds :: [Parser ClientCommand]
hiddenCmds = (Mod CommandFields ByronCommand -> Parser ClientCommand)
-> [Mod CommandFields ByronCommand] -> [Parser ClientCommand]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
map Mod CommandFields ByronCommand -> Parser ClientCommand
convertToByronCommand [ Mod CommandFields ByronCommand
parseGenesisRelatedValues
                                         , Mod CommandFields ByronCommand
parseKeyRelatedValues
                                         , Mod CommandFields ByronCommand
parseTxRelatedValues
                                         , Mod CommandFields ByronCommand
parseLocalNodeQueryValues
                                         , Mod CommandFields ByronCommand
parseMiscellaneous
                                         ]

-- Implemented with asum so all commands don't get hidden when trying to hide
-- the 'pNodeCmdBackwardCompatible' parser.
parseByronCommands :: Parser ByronCommand
parseByronCommands :: Parser ByronCommand
parseByronCommands = [Parser ByronCommand] -> Parser ByronCommand
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
  [ String -> ParserInfo ByronCommand -> Parser ByronCommand
subParser String
"key" (Parser ByronCommand
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ByronCommand -> Parser ByronCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ByronCommand
parseKeyRelatedValues)
      (InfoMod ByronCommand -> ParserInfo ByronCommand)
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ByronCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Byron key utility commands")
  , String -> ParserInfo ByronCommand -> Parser ByronCommand
subParser String
"transaction" (Parser ByronCommand
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ByronCommand -> Parser ByronCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ByronCommand
parseTxRelatedValues)
      (InfoMod ByronCommand -> ParserInfo ByronCommand)
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ByronCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Byron transaction commands")
  , String -> ParserInfo ByronCommand -> Parser ByronCommand
subParser String
"query" (Parser ByronCommand
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ByronCommand -> Parser ByronCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ByronCommand
parseLocalNodeQueryValues)
      (InfoMod ByronCommand -> ParserInfo ByronCommand)
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ByronCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Byron node query commands.")
  , String -> ParserInfo ByronCommand -> Parser ByronCommand
subParser String
"genesis" (Parser ByronCommand
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ByronCommand -> Parser ByronCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ByronCommand
parseGenesisRelatedValues)
      (InfoMod ByronCommand -> ParserInfo ByronCommand)
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ByronCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Byron genesis block commands")
  , String -> ParserInfo ByronCommand -> Parser ByronCommand
subParser String
"governance" (Parser ByronCommand
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (NodeCmd -> ByronCommand
NodeCmd (NodeCmd -> ByronCommand) -> Parser NodeCmd -> Parser ByronCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod CommandFields NodeCmd -> Parser NodeCmd
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields NodeCmd
pNodeCmd)
      (InfoMod ByronCommand -> ParserInfo ByronCommand)
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ByronCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Byron governance commands")
  , String -> ParserInfo ByronCommand -> Parser ByronCommand
subParser String
"miscellaneous" (Parser ByronCommand
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ByronCommand -> Parser ByronCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ByronCommand
parseMiscellaneous)
      (InfoMod ByronCommand -> ParserInfo ByronCommand)
-> InfoMod ByronCommand -> ParserInfo ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ByronCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Byron miscellaneous commands")
  , NodeCmd -> ByronCommand
NodeCmd (NodeCmd -> ByronCommand) -> Parser NodeCmd -> Parser ByronCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NodeCmd
pNodeCmdBackwardCompatible
  ]
 where
   subParser :: String -> ParserInfo ByronCommand -> Parser ByronCommand
   subParser :: String -> ParserInfo ByronCommand -> Parser ByronCommand
subParser String
name ParserInfo ByronCommand
pInfo = Mod CommandFields ByronCommand -> Parser ByronCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser (Mod CommandFields ByronCommand -> Parser ByronCommand)
-> Mod CommandFields ByronCommand -> Parser ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> ParserInfo ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
name ParserInfo ByronCommand
pInfo Mod CommandFields ByronCommand
-> Mod CommandFields ByronCommand -> Mod CommandFields ByronCommand
forall a. Semigroup a => a -> a -> a
<> String -> Mod CommandFields ByronCommand
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
name

pNodeCmdBackwardCompatible :: Parser NodeCmd
pNodeCmdBackwardCompatible :: Parser NodeCmd
pNodeCmdBackwardCompatible = Mod CommandFields NodeCmd -> Parser NodeCmd
forall a. Mod CommandFields a -> Parser a
Opt.subparser (Mod CommandFields NodeCmd -> Parser NodeCmd)
-> Mod CommandFields NodeCmd -> Parser NodeCmd
forall a b. (a -> b) -> a -> b
$ Mod CommandFields NodeCmd
pNodeCmd Mod CommandFields NodeCmd
-> Mod CommandFields NodeCmd -> Mod CommandFields NodeCmd
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields NodeCmd
forall (f :: * -> *) a. Mod f a
Opt.internal

parseCBORObject :: Parser CBORObject
parseCBORObject :: Parser CBORObject
parseCBORObject = [Parser CBORObject] -> Parser CBORObject
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
  [ EpochSlots -> CBORObject
CBORBlockByron (EpochSlots -> CBORObject)
-> Parser EpochSlots -> Parser CBORObject
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM EpochSlots
-> Mod OptionFields EpochSlots -> Parser EpochSlots
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM EpochSlots
forall a. Read a => ReadM a
auto
      (  String -> Mod OptionFields EpochSlots
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-block"
      Mod OptionFields EpochSlots
-> Mod OptionFields EpochSlots -> Mod OptionFields EpochSlots
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields EpochSlots
forall (f :: * -> *) a. String -> Mod f a
help
          (   String
"The CBOR file is a byron era block."
          String -> String -> String
forall a. Semigroup a => a -> a -> a
<>  String
" Enter the number of slots in an epoch. The default value is 21600")
      Mod OptionFields EpochSlots
-> Mod OptionFields EpochSlots -> Mod OptionFields EpochSlots
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields EpochSlots
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"INT"
      Mod OptionFields EpochSlots
-> Mod OptionFields EpochSlots -> Mod OptionFields EpochSlots
forall a. Semigroup a => a -> a -> a
<> EpochSlots -> Mod OptionFields EpochSlots
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value (Word64 -> EpochSlots
EpochSlots Word64
21600)
      )

  , CBORObject -> Mod FlagFields CBORObject -> Parser CBORObject
forall a. a -> Mod FlagFields a -> Parser a
flag' CBORObject
CBORDelegationCertificateByron (Mod FlagFields CBORObject -> Parser CBORObject)
-> Mod FlagFields CBORObject -> Parser CBORObject
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-delegation-certificate"
     Mod FlagFields CBORObject
-> Mod FlagFields CBORObject -> Mod FlagFields CBORObject
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. String -> Mod f a
help String
"The CBOR file is a byron era delegation certificate"

  , CBORObject -> Mod FlagFields CBORObject -> Parser CBORObject
forall a. a -> Mod FlagFields a -> Parser a
flag' CBORObject
CBORTxByron (Mod FlagFields CBORObject -> Parser CBORObject)
-> Mod FlagFields CBORObject -> Parser CBORObject
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-tx"
     Mod FlagFields CBORObject
-> Mod FlagFields CBORObject -> Mod FlagFields CBORObject
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. String -> Mod f a
help String
"The CBOR file is a byron era tx"

  , CBORObject -> Mod FlagFields CBORObject -> Parser CBORObject
forall a. a -> Mod FlagFields a -> Parser a
flag' CBORObject
CBORUpdateProposalByron (Mod FlagFields CBORObject -> Parser CBORObject)
-> Mod FlagFields CBORObject -> Parser CBORObject
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-update-proposal"
     Mod FlagFields CBORObject
-> Mod FlagFields CBORObject -> Mod FlagFields CBORObject
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. String -> Mod f a
help String
"The CBOR file is a byron era update proposal"
  , CBORObject -> Mod FlagFields CBORObject -> Parser CBORObject
forall a. a -> Mod FlagFields a -> Parser a
flag' CBORObject
CBORVoteByron (Mod FlagFields CBORObject -> Parser CBORObject)
-> Mod FlagFields CBORObject -> Parser CBORObject
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-vote"
     Mod FlagFields CBORObject
-> Mod FlagFields CBORObject -> Mod FlagFields CBORObject
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields CBORObject
forall (f :: * -> *) a. String -> Mod f a
help String
"The CBOR file is a byron era vote"
  ]

-- | Values required to create genesis.
parseGenesisParameters :: Parser GenesisParameters
parseGenesisParameters :: Parser GenesisParameters
parseGenesisParameters =
  UTCTime
-> String
-> BlockCount
-> ProtocolMagic
-> TestnetBalanceOptions
-> FakeAvvmOptions
-> LovelacePortion
-> Maybe Integer
-> GenesisParameters
GenesisParameters
    (UTCTime
 -> String
 -> BlockCount
 -> ProtocolMagic
 -> TestnetBalanceOptions
 -> FakeAvvmOptions
 -> LovelacePortion
 -> Maybe Integer
 -> GenesisParameters)
-> Parser UTCTime
-> Parser
     (String
      -> BlockCount
      -> ProtocolMagic
      -> TestnetBalanceOptions
      -> FakeAvvmOptions
      -> LovelacePortion
      -> Maybe Integer
      -> GenesisParameters)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser UTCTime
parseUTCTime
          String
"start-time"
          String
"Start time of the new cluster to be enshrined in the new genesis."
    Parser
  (String
   -> BlockCount
   -> ProtocolMagic
   -> TestnetBalanceOptions
   -> FakeAvvmOptions
   -> LovelacePortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser String
-> Parser
     (BlockCount
      -> ProtocolMagic
      -> TestnetBalanceOptions
      -> FakeAvvmOptions
      -> LovelacePortion
      -> Maybe Integer
      -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath
          String
"protocol-parameters-file"
          String
"JSON file with protocol parameters."
    Parser
  (BlockCount
   -> ProtocolMagic
   -> TestnetBalanceOptions
   -> FakeAvvmOptions
   -> LovelacePortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser BlockCount
-> Parser
     (ProtocolMagic
      -> TestnetBalanceOptions
      -> FakeAvvmOptions
      -> LovelacePortion
      -> Maybe Integer
      -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser BlockCount
parseK
    Parser
  (ProtocolMagic
   -> TestnetBalanceOptions
   -> FakeAvvmOptions
   -> LovelacePortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser ProtocolMagic
-> Parser
     (TestnetBalanceOptions
      -> FakeAvvmOptions
      -> LovelacePortion
      -> Maybe Integer
      -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ProtocolMagic
parseProtocolMagic
    Parser
  (TestnetBalanceOptions
   -> FakeAvvmOptions
   -> LovelacePortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser TestnetBalanceOptions
-> Parser
     (FakeAvvmOptions
      -> LovelacePortion -> Maybe Integer -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TestnetBalanceOptions
parseTestnetBalanceOptions
    Parser
  (FakeAvvmOptions
   -> LovelacePortion -> Maybe Integer -> GenesisParameters)
-> Parser FakeAvvmOptions
-> Parser (LovelacePortion -> Maybe Integer -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FakeAvvmOptions
parseFakeAvvmOptions
    Parser (LovelacePortion -> Maybe Integer -> GenesisParameters)
-> Parser LovelacePortion
-> Parser (Maybe Integer -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> LovelacePortion
rationalToLovelacePortion (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
         String -> String -> Double -> Parser Rational
parseFractionWithDefault
          String
"avvm-balance-factor"
          String
"AVVM balances will be multiplied by this factor (defaults to 1)."
          Double
1)
    Parser (Maybe Integer -> GenesisParameters)
-> Parser (Maybe Integer) -> Parser GenesisParameters
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Integer -> Parser (Maybe Integer)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional
        ( String -> String -> Parser Integer
forall a. Integral a => String -> String -> Parser a
parseIntegral
            String
"secret-seed"
            String
"Optionally specify the seed of generation."
        )

parseGenesisRelatedValues :: Mod CommandFields ByronCommand
parseGenesisRelatedValues :: Mod CommandFields ByronCommand
parseGenesisRelatedValues =
  [Mod CommandFields ByronCommand] -> Mod CommandFields ByronCommand
forall a. Monoid a => [a] -> a
mconcat
    [ String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command' String
"genesis" String
"Create genesis."
      (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ NewDirectory -> GenesisParameters -> ByronCommand
Genesis
          (NewDirectory -> GenesisParameters -> ByronCommand)
-> Parser NewDirectory
-> Parser (GenesisParameters -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser NewDirectory
parseNewDirectory
              String
"genesis-output-dir"
              String
"Non-existent directory where genesis JSON file and secrets shall be placed."
          Parser (GenesisParameters -> ByronCommand)
-> Parser GenesisParameters -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser GenesisParameters
parseGenesisParameters
    , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command' String
"print-genesis-hash" String
"Compute hash of a genesis file."
        (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ GenesisFile -> ByronCommand
PrintGenesisHash
            (GenesisFile -> ByronCommand)
-> Parser GenesisFile -> Parser ByronCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser GenesisFile
parseGenesisFile String
"genesis-json"
    ]

-- | Values required to create keys and perform
-- transformation on keys.
parseKeyRelatedValues :: Mod CommandFields ByronCommand
parseKeyRelatedValues :: Mod CommandFields ByronCommand
parseKeyRelatedValues =
    [Mod CommandFields ByronCommand] -> Mod CommandFields ByronCommand
forall a. Monoid a => [a] -> a
mconcat
        [ String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command' String
"keygen" String
"Generate a signing key."
            (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ NewSigningKeyFile -> ByronCommand
Keygen
                (NewSigningKeyFile -> ByronCommand)
-> Parser NewSigningKeyFile -> Parser ByronCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser NewSigningKeyFile
parseNewSigningKeyFile String
"secret"
        , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
            String
"to-verification"
            String
"Extract a verification key in its base64 form."
            (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat
-> SigningKeyFile -> NewVerificationKeyFile -> ByronCommand
ToVerification
                (ByronKeyFormat
 -> SigningKeyFile -> NewVerificationKeyFile -> ByronCommand)
-> Parser ByronKeyFormat
-> Parser
     (SigningKeyFile -> NewVerificationKeyFile -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByronKeyFormat
parseByronKeyFormat
                Parser (SigningKeyFile -> NewVerificationKeyFile -> ByronCommand)
-> Parser SigningKeyFile
-> Parser (NewVerificationKeyFile -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser SigningKeyFile
parseSigningKeyFile
                      String
"secret"
                      String
"Signing key file to extract the verification part from."
                Parser (NewVerificationKeyFile -> ByronCommand)
-> Parser NewVerificationKeyFile -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewVerificationKeyFile
parseNewVerificationKeyFile String
"to"
        , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
            String
"signing-key-public"
            String
"Pretty-print a signing key's verification key (not a secret)."
            (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat -> SigningKeyFile -> ByronCommand
PrettySigningKeyPublic
                (ByronKeyFormat -> SigningKeyFile -> ByronCommand)
-> Parser ByronKeyFormat -> Parser (SigningKeyFile -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByronKeyFormat
parseByronKeyFormat
                Parser (SigningKeyFile -> ByronCommand)
-> Parser SigningKeyFile -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser SigningKeyFile
parseSigningKeyFile
                      String
"secret"
                      String
"Signing key to pretty-print."
        , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
            String
"signing-key-address"
            String
"Print address of a signing key."
            (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ ByronKeyFormat -> NetworkId -> SigningKeyFile -> ByronCommand
PrintSigningKeyAddress
                (ByronKeyFormat -> NetworkId -> SigningKeyFile -> ByronCommand)
-> Parser ByronKeyFormat
-> Parser (NetworkId -> SigningKeyFile -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByronKeyFormat
parseByronKeyFormat
                Parser (NetworkId -> SigningKeyFile -> ByronCommand)
-> Parser NetworkId -> Parser (SigningKeyFile -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser NetworkId
pNetworkId
                Parser (SigningKeyFile -> ByronCommand)
-> Parser SigningKeyFile -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser SigningKeyFile
parseSigningKeyFile
                      String
"secret"
                      String
"Signing key, whose address is to be printed."
        , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
            String
"migrate-delegate-key-from"
            String
"Migrate a delegate key from an older version."
            (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ SigningKeyFile -> NewSigningKeyFile -> ByronCommand
MigrateDelegateKeyFrom
                (SigningKeyFile -> NewSigningKeyFile -> ByronCommand)
-> Parser SigningKeyFile
-> Parser (NewSigningKeyFile -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser SigningKeyFile
parseSigningKeyFile String
"from" String
"Legacy signing key file to migrate."
                Parser (NewSigningKeyFile -> ByronCommand)
-> Parser NewSigningKeyFile -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewSigningKeyFile
parseNewSigningKeyFile String
"to"
        ]

parseLocalNodeQueryValues :: Mod CommandFields ByronCommand
parseLocalNodeQueryValues :: Mod CommandFields ByronCommand
parseLocalNodeQueryValues =
    [Mod CommandFields ByronCommand] -> Mod CommandFields ByronCommand
forall a. Monoid a => [a] -> a
mconcat
        [ String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command' String
"get-tip" String
"Get the tip of your local node's blockchain"
            (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ NetworkId -> ByronCommand
GetLocalNodeTip
                (NetworkId -> ByronCommand)
-> Parser NetworkId -> Parser ByronCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
        ]

parseMiscellaneous :: Mod CommandFields ByronCommand
parseMiscellaneous :: Mod CommandFields ByronCommand
parseMiscellaneous = [Mod CommandFields ByronCommand] -> Mod CommandFields ByronCommand
forall a. Monoid a => [a] -> a
mconcat
  [ String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
      String
"validate-cbor"
      String
"Validate a CBOR blockchain object."
      (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ CBORObject -> String -> ByronCommand
ValidateCBOR
          (CBORObject -> String -> ByronCommand)
-> Parser CBORObject -> Parser (String -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser CBORObject
parseCBORObject
          Parser (String -> ByronCommand)
-> Parser String -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath String
"filepath" String
"Filepath of CBOR file."
  , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
      String
"pretty-print-cbor"
      String
"Pretty print a CBOR file."
      (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ String -> ByronCommand
PrettyPrintCBOR
          (String -> ByronCommand) -> Parser String -> Parser ByronCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
"filepath" String
"Filepath of CBOR file."
  ]



parseTestnetBalanceOptions :: Parser TestnetBalanceOptions
parseTestnetBalanceOptions :: Parser TestnetBalanceOptions
parseTestnetBalanceOptions =
  Word -> Word -> Lovelace -> Rational -> TestnetBalanceOptions
TestnetBalanceOptions
    (Word -> Word -> Lovelace -> Rational -> TestnetBalanceOptions)
-> Parser Word
-> Parser (Word -> Lovelace -> Rational -> TestnetBalanceOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Word
forall a. Integral a => String -> String -> Parser a
parseIntegral
          String
"n-poor-addresses"
          String
"Number of poor nodes (with small balance)."
    Parser (Word -> Lovelace -> Rational -> TestnetBalanceOptions)
-> Parser Word
-> Parser (Lovelace -> Rational -> TestnetBalanceOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser Word
forall a. Integral a => String -> String -> Parser a
parseIntegral
          String
"n-delegate-addresses"
          String
"Number of delegate nodes (with huge balance)."
    Parser (Lovelace -> Rational -> TestnetBalanceOptions)
-> Parser Lovelace -> Parser (Rational -> TestnetBalanceOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser Lovelace
parseLovelace
          String
"total-balance"
          String
"Total balance owned by these nodes."
    Parser (Rational -> TestnetBalanceOptions)
-> Parser Rational -> Parser TestnetBalanceOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser Rational
parseFraction
          String
"delegate-share"
          String
"Portion of stake owned by all delegates together."

parseTxIn :: Parser TxIn
parseTxIn :: Parser TxIn
parseTxIn =
  ReadM TxIn -> Mod OptionFields TxIn -> Parser TxIn
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
  (Parser TxIn -> ReadM TxIn
forall a. Parser a -> ReadM a
readerFromAttoParser Parser TxIn
parseTxInAtto)
  (Mod OptionFields TxIn -> Parser TxIn)
-> Mod OptionFields TxIn -> Parser TxIn
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields TxIn
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"txin"
    Mod OptionFields TxIn
-> Mod OptionFields TxIn -> Mod OptionFields TxIn
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields TxIn
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"(TXID,INDEX)"
    Mod OptionFields TxIn
-> Mod OptionFields TxIn -> Mod OptionFields TxIn
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields TxIn
forall (f :: * -> *) a. String -> Mod f a
help String
"Transaction input is a pair of an UTxO TxId and a zero-based output index."

parseTxInAtto :: Atto.Parser TxIn
parseTxInAtto :: Parser TxIn
parseTxInAtto =
  TxId -> TxIx -> TxIn
TxIn (TxId -> TxIx -> TxIn)
-> Parser ByteString TxId -> Parser ByteString (TxIx -> TxIn)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Char -> Parser Char
Atto.char Char
'(' Parser Char -> Parser ByteString TxId -> Parser ByteString TxId
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser ByteString TxId
parseTxIdAtto Parser ByteString TxId -> Parser Char -> Parser ByteString TxId
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> Parser Char
Atto.char Char
',')
       Parser ByteString (TxIx -> TxIn)
-> Parser ByteString TxIx -> Parser TxIn
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Parser ByteString TxIx
parseTxIxAtto Parser ByteString TxIx -> Parser Char -> Parser ByteString TxIx
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> Parser Char
Atto.char Char
')')


parseTxIdAtto :: Atto.Parser TxId
parseTxIdAtto :: Parser ByteString TxId
parseTxIdAtto = (Parser ByteString TxId -> String -> Parser ByteString TxId
forall i a. Parser i a -> String -> Parser i a
<?> String
"Transaction ID (hexadecimal)") (Parser ByteString TxId -> Parser ByteString TxId)
-> Parser ByteString TxId -> Parser ByteString TxId
forall a b. (a -> b) -> a -> b
$ do
  ByteString
bstr <- (Char -> Bool) -> Parser ByteString
Atto.takeWhile1 Char -> Bool
Char.isHexDigit
  case AsType TxId -> ByteString -> Maybe TxId
forall a.
SerialiseAsRawBytes a =>
AsType a -> ByteString -> Maybe a
deserialiseFromRawBytesHex AsType TxId
AsTxId ByteString
bstr of
    Just TxId
addr -> TxId -> Parser ByteString TxId
forall (m :: * -> *) a. Monad m => a -> m a
return TxId
addr
    Maybe TxId
Nothing -> String -> Parser ByteString TxId
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser ByteString TxId)
-> String -> Parser ByteString TxId
forall a b. (a -> b) -> a -> b
$ String
"Incorrect transaction id format:: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ ByteString -> String
forall a b. (Show a, ConvertText String b) => a -> b
show ByteString
bstr

parseTxIxAtto :: Atto.Parser TxIx
parseTxIxAtto :: Parser ByteString TxIx
parseTxIxAtto = Int -> TxIx
forall a. Enum a => Int -> a
toEnum (Int -> TxIx) -> Parser ByteString Int -> Parser ByteString TxIx
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ByteString Int
forall a. Integral a => Parser a
Atto.decimal

parseTxOut :: Parser (TxOut ByronEra)
parseTxOut :: Parser (TxOut ByronEra)
parseTxOut =
  ReadM (TxOut ByronEra)
-> Mod OptionFields (TxOut ByronEra) -> Parser (TxOut ByronEra)
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ( (\(Text
addr, Word64
lovelace) -> AddressInEra ByronEra
-> TxOutValue ByronEra -> TxOutDatumHash ByronEra -> TxOut ByronEra
forall era.
AddressInEra era
-> TxOutValue era -> TxOutDatumHash era -> TxOut era
TxOut (Text -> AddressInEra ByronEra
pAddressInEra Text
addr)
                                  (Word64 -> TxOutValue ByronEra
pLovelaceTxOut Word64
lovelace)
                                  TxOutDatumHash ByronEra
forall era. TxOutDatumHash era
TxOutDatumHashNone)
      ((Text, Word64) -> TxOut ByronEra)
-> ReadM (Text, Word64) -> ReadM (TxOut ByronEra)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM (Text, Word64)
forall a. Read a => ReadM a
auto
    )
    (Mod OptionFields (TxOut ByronEra) -> Parser (TxOut ByronEra))
-> Mod OptionFields (TxOut ByronEra) -> Parser (TxOut ByronEra)
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields (TxOut ByronEra)
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"txout"
      Mod OptionFields (TxOut ByronEra)
-> Mod OptionFields (TxOut ByronEra)
-> Mod OptionFields (TxOut ByronEra)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (TxOut ByronEra)
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"'(\"ADDR\", LOVELACE)'"
      Mod OptionFields (TxOut ByronEra)
-> Mod OptionFields (TxOut ByronEra)
-> Mod OptionFields (TxOut ByronEra)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (TxOut ByronEra)
forall (f :: * -> *) a. String -> Mod f a
help String
"Specify a transaction output, as a pair of an address and lovelace."
 where
  pAddressInEra :: Text -> AddressInEra ByronEra
  pAddressInEra :: Text -> AddressInEra ByronEra
pAddressInEra Text
t =
    case Text -> Either DecoderError Address
decodeAddressBase58 Text
t of
      Left DecoderError
err -> Text -> AddressInEra ByronEra
forall a. HasCallStack => Text -> a
panic (Text -> AddressInEra ByronEra) -> Text -> AddressInEra ByronEra
forall a b. (a -> b) -> a -> b
$ Text
"Bad Base58 address: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (DecoderError -> String
forall a b. (Show a, ConvertText String b) => a -> b
show DecoderError
err)
      Right Address
byronAddress -> AddressTypeInEra ByronAddr ByronEra
-> Address ByronAddr -> AddressInEra ByronEra
forall addrtype era.
AddressTypeInEra addrtype era
-> Address addrtype -> AddressInEra era
AddressInEra AddressTypeInEra ByronAddr ByronEra
forall era. AddressTypeInEra ByronAddr era
ByronAddressInAnyEra (Address ByronAddr -> AddressInEra ByronEra)
-> Address ByronAddr -> AddressInEra ByronEra
forall a b. (a -> b) -> a -> b
$ Address -> Address ByronAddr
ByronAddress Address
byronAddress

  pLovelaceTxOut :: Word64 -> TxOutValue ByronEra
  pLovelaceTxOut :: Word64 -> TxOutValue ByronEra
pLovelaceTxOut Word64
l =
    if Word64
l Word64 -> Word64 -> Bool
forall a. Ord a => a -> a -> Bool
> (Word64
forall a. Bounded a => a
maxBound :: Word64)
    then Text -> TxOutValue ByronEra
forall a. HasCallStack => Text -> a
panic (Text -> TxOutValue ByronEra) -> Text -> TxOutValue ByronEra
forall a b. (a -> b) -> a -> b
$ Word64 -> Text
forall a b. (Show a, ConvertText String b) => a -> b
show Word64
l Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" lovelace exceeds the Word64 upper bound"
    else OnlyAdaSupportedInEra ByronEra -> Lovelace -> TxOutValue ByronEra
forall era. OnlyAdaSupportedInEra era -> Lovelace -> TxOutValue era
TxOutAdaOnly OnlyAdaSupportedInEra ByronEra
AdaOnlyInByronEra (Lovelace -> TxOutValue ByronEra)
-> (Integer -> Lovelace) -> Integer -> TxOutValue ByronEra
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Integer -> Lovelace
Lovelace (Integer -> TxOutValue ByronEra) -> Integer -> TxOutValue ByronEra
forall a b. (a -> b) -> a -> b
$ Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger Word64
l

readerFromAttoParser :: Atto.Parser a -> Opt.ReadM a
readerFromAttoParser :: Parser a -> ReadM a
readerFromAttoParser Parser a
p =
  (String -> Either String a) -> ReadM a
forall a. (String -> Either String a) -> ReadM a
Opt.eitherReader (Parser a -> ByteString -> Either String a
forall a. Parser a -> ByteString -> Either String a
Atto.parseOnly (Parser a
p Parser a -> Parser ByteString () -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ByteString ()
forall t. Chunk t => Parser t ()
Atto.endOfInput) (ByteString -> Either String a)
-> (String -> ByteString) -> String -> Either String a
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> ByteString
BSC.pack)

parseTxRelatedValues :: Mod CommandFields ByronCommand
parseTxRelatedValues :: Mod CommandFields ByronCommand
parseTxRelatedValues =
  [Mod CommandFields ByronCommand] -> Mod CommandFields ByronCommand
forall a. Monoid a => [a] -> a
mconcat
    [ String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
        String
"submit-tx"
        String
"Submit a raw, signed transaction, in its on-wire representation."
        (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ NetworkId -> TxFile -> ByronCommand
SubmitTx
            (NetworkId -> TxFile -> ByronCommand)
-> Parser NetworkId -> Parser (TxFile -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
            Parser (TxFile -> ByronCommand)
-> Parser TxFile -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser TxFile
parseTxFile String
"tx"
    , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
        String
"issue-genesis-utxo-expenditure"
        String
"Write a file with a signed transaction, spending genesis UTxO."
        (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ GenesisFile
-> NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile
-> Address ByronAddr
-> [TxOut ByronEra]
-> ByronCommand
SpendGenesisUTxO
            (GenesisFile
 -> NetworkId
 -> ByronKeyFormat
 -> NewTxFile
 -> SigningKeyFile
 -> Address ByronAddr
 -> [TxOut ByronEra]
 -> ByronCommand)
-> Parser GenesisFile
-> Parser
     (NetworkId
      -> ByronKeyFormat
      -> NewTxFile
      -> SigningKeyFile
      -> Address ByronAddr
      -> [TxOut ByronEra]
      -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser GenesisFile
parseGenesisFile String
"genesis-json"
            Parser
  (NetworkId
   -> ByronKeyFormat
   -> NewTxFile
   -> SigningKeyFile
   -> Address ByronAddr
   -> [TxOut ByronEra]
   -> ByronCommand)
-> Parser NetworkId
-> Parser
     (ByronKeyFormat
      -> NewTxFile
      -> SigningKeyFile
      -> Address ByronAddr
      -> [TxOut ByronEra]
      -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser NetworkId
pNetworkId
            Parser
  (ByronKeyFormat
   -> NewTxFile
   -> SigningKeyFile
   -> Address ByronAddr
   -> [TxOut ByronEra]
   -> ByronCommand)
-> Parser ByronKeyFormat
-> Parser
     (NewTxFile
      -> SigningKeyFile
      -> Address ByronAddr
      -> [TxOut ByronEra]
      -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByronKeyFormat
parseByronKeyFormat
            Parser
  (NewTxFile
   -> SigningKeyFile
   -> Address ByronAddr
   -> [TxOut ByronEra]
   -> ByronCommand)
-> Parser NewTxFile
-> Parser
     (SigningKeyFile
      -> Address ByronAddr -> [TxOut ByronEra] -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewTxFile
parseNewTxFile String
"tx"
            Parser
  (SigningKeyFile
   -> Address ByronAddr -> [TxOut ByronEra] -> ByronCommand)
-> Parser SigningKeyFile
-> Parser (Address ByronAddr -> [TxOut ByronEra] -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser SigningKeyFile
parseSigningKeyFile
                  String
"wallet-key"
                  String
"Key that has access to all mentioned genesis UTxO inputs."
            Parser (Address ByronAddr -> [TxOut ByronEra] -> ByronCommand)
-> Parser (Address ByronAddr)
-> Parser ([TxOut ByronEra] -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser (Address ByronAddr)
parseAddress
                  String
"rich-addr-from"
                  String
"Tx source: genesis UTxO richman address (non-HD)."
            Parser ([TxOut ByronEra] -> ByronCommand)
-> Parser [TxOut ByronEra] -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (TxOut ByronEra) -> Parser [TxOut ByronEra]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser (TxOut ByronEra)
parseTxOut

    , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
        String
"issue-utxo-expenditure"
        String
"Write a file with a signed transaction, spending normal UTxO."
        (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ NetworkId
-> ByronKeyFormat
-> NewTxFile
-> SigningKeyFile
-> [TxIn]
-> [TxOut ByronEra]
-> ByronCommand
SpendUTxO
            (NetworkId
 -> ByronKeyFormat
 -> NewTxFile
 -> SigningKeyFile
 -> [TxIn]
 -> [TxOut ByronEra]
 -> ByronCommand)
-> Parser NetworkId
-> Parser
     (ByronKeyFormat
      -> NewTxFile
      -> SigningKeyFile
      -> [TxIn]
      -> [TxOut ByronEra]
      -> ByronCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
            Parser
  (ByronKeyFormat
   -> NewTxFile
   -> SigningKeyFile
   -> [TxIn]
   -> [TxOut ByronEra]
   -> ByronCommand)
-> Parser ByronKeyFormat
-> Parser
     (NewTxFile
      -> SigningKeyFile -> [TxIn] -> [TxOut ByronEra] -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByronKeyFormat
parseByronKeyFormat
            Parser
  (NewTxFile
   -> SigningKeyFile -> [TxIn] -> [TxOut ByronEra] -> ByronCommand)
-> Parser NewTxFile
-> Parser
     (SigningKeyFile -> [TxIn] -> [TxOut ByronEra] -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewTxFile
parseNewTxFile String
"tx"
            Parser
  (SigningKeyFile -> [TxIn] -> [TxOut ByronEra] -> ByronCommand)
-> Parser SigningKeyFile
-> Parser ([TxIn] -> [TxOut ByronEra] -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser SigningKeyFile
parseSigningKeyFile
                  String
"wallet-key"
                  String
"Key that has access to all mentioned genesis UTxO inputs."
            Parser ([TxIn] -> [TxOut ByronEra] -> ByronCommand)
-> Parser [TxIn] -> Parser ([TxOut ByronEra] -> ByronCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TxIn -> Parser [TxIn]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser TxIn
parseTxIn
            Parser ([TxOut ByronEra] -> ByronCommand)
-> Parser [TxOut ByronEra] -> Parser ByronCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (TxOut ByronEra) -> Parser [TxOut ByronEra]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser (TxOut ByronEra)
parseTxOut

    , String
-> String -> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
        String
"txid"
        String
"Print the txid of a raw, signed transaction."
        (Parser ByronCommand -> Mod CommandFields ByronCommand)
-> Parser ByronCommand -> Mod CommandFields ByronCommand
forall a b. (a -> b) -> a -> b
$ TxFile -> ByronCommand
GetTxId
            (TxFile -> ByronCommand) -> Parser TxFile -> Parser ByronCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser TxFile
parseTxFile String
"tx"
    ]

pNodeCmd :: Mod CommandFields NodeCmd
pNodeCmd :: Mod CommandFields NodeCmd
pNodeCmd =
    [Mod CommandFields NodeCmd] -> Mod CommandFields NodeCmd
forall a. Monoid a => [a] -> a
mconcat
      [ String -> ParserInfo NodeCmd -> Mod CommandFields NodeCmd
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
"create-update-proposal"
          (Parser NodeCmd -> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info Parser NodeCmd
parseByronUpdateProposal (InfoMod NodeCmd -> ParserInfo NodeCmd)
-> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a b. (a -> b) -> a -> b
$ String -> InfoMod NodeCmd
forall a. String -> InfoMod a
Opt.progDesc  String
"Create an update proposal.")

      , String -> ParserInfo NodeCmd -> Mod CommandFields NodeCmd
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
"create-proposal-vote"
          (Parser NodeCmd -> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info Parser NodeCmd
parseByronVote (InfoMod NodeCmd -> ParserInfo NodeCmd)
-> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a b. (a -> b) -> a -> b
$ String -> InfoMod NodeCmd
forall a. String -> InfoMod a
Opt.progDesc String
"Create an update proposal vote.")

      , String -> ParserInfo NodeCmd -> Mod CommandFields NodeCmd
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
"submit-update-proposal"
          (Parser NodeCmd -> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info Parser NodeCmd
parseByronUpdateProposalSubmission (InfoMod NodeCmd -> ParserInfo NodeCmd)
-> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a b. (a -> b) -> a -> b
$ String -> InfoMod NodeCmd
forall a. String -> InfoMod a
Opt.progDesc String
"Submit an update proposal.")

      , String -> ParserInfo NodeCmd -> Mod CommandFields NodeCmd
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
"submit-proposal-vote"
          (Parser NodeCmd -> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info Parser NodeCmd
parseByronVoteSubmission (InfoMod NodeCmd -> ParserInfo NodeCmd)
-> InfoMod NodeCmd -> ParserInfo NodeCmd
forall a b. (a -> b) -> a -> b
$ String -> InfoMod NodeCmd
forall a. String -> InfoMod a
Opt.progDesc String
"Submit a proposal vote.")
      ]

parseByronUpdateProposal :: Parser NodeCmd
parseByronUpdateProposal :: Parser NodeCmd
parseByronUpdateProposal = do
  NetworkId
-> SigningKeyFile
-> ProtocolVersion
-> SoftwareVersion
-> SystemTag
-> InstallerHash
-> String
-> ByronProtocolParametersUpdate
-> NodeCmd
UpdateProposal
    (NetworkId
 -> SigningKeyFile
 -> ProtocolVersion
 -> SoftwareVersion
 -> SystemTag
 -> InstallerHash
 -> String
 -> ByronProtocolParametersUpdate
 -> NodeCmd)
-> Parser NetworkId
-> Parser
     (SigningKeyFile
      -> ProtocolVersion
      -> SoftwareVersion
      -> SystemTag
      -> InstallerHash
      -> String
      -> ByronProtocolParametersUpdate
      -> NodeCmd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
    Parser
  (SigningKeyFile
   -> ProtocolVersion
   -> SoftwareVersion
   -> SystemTag
   -> InstallerHash
   -> String
   -> ByronProtocolParametersUpdate
   -> NodeCmd)
-> Parser SigningKeyFile
-> Parser
     (ProtocolVersion
      -> SoftwareVersion
      -> SystemTag
      -> InstallerHash
      -> String
      -> ByronProtocolParametersUpdate
      -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser SigningKeyFile
parseSigningKeyFile String
"signing-key" String
"Path to signing key."
    Parser
  (ProtocolVersion
   -> SoftwareVersion
   -> SystemTag
   -> InstallerHash
   -> String
   -> ByronProtocolParametersUpdate
   -> NodeCmd)
-> Parser ProtocolVersion
-> Parser
     (SoftwareVersion
      -> SystemTag
      -> InstallerHash
      -> String
      -> ByronProtocolParametersUpdate
      -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ProtocolVersion
parseProtocolVersion
    Parser
  (SoftwareVersion
   -> SystemTag
   -> InstallerHash
   -> String
   -> ByronProtocolParametersUpdate
   -> NodeCmd)
-> Parser SoftwareVersion
-> Parser
     (SystemTag
      -> InstallerHash
      -> String
      -> ByronProtocolParametersUpdate
      -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SoftwareVersion
parseSoftwareVersion
    Parser
  (SystemTag
   -> InstallerHash
   -> String
   -> ByronProtocolParametersUpdate
   -> NodeCmd)
-> Parser SystemTag
-> Parser
     (InstallerHash
      -> String -> ByronProtocolParametersUpdate -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SystemTag
parseSystemTag
    Parser
  (InstallerHash
   -> String -> ByronProtocolParametersUpdate -> NodeCmd)
-> Parser InstallerHash
-> Parser (String -> ByronProtocolParametersUpdate -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser InstallerHash
parseInstallerHash
    Parser (String -> ByronProtocolParametersUpdate -> NodeCmd)
-> Parser String
-> Parser (ByronProtocolParametersUpdate -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath String
"filepath" String
"Byron proposal output filepath."
    Parser (ByronProtocolParametersUpdate -> NodeCmd)
-> Parser ByronProtocolParametersUpdate -> Parser NodeCmd
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ByronProtocolParametersUpdate
pByronProtocolParametersUpdate

parseByronVoteSubmission :: Parser NodeCmd
parseByronVoteSubmission :: Parser NodeCmd
parseByronVoteSubmission = do
  NetworkId -> String -> NodeCmd
SubmitVote
    (NetworkId -> String -> NodeCmd)
-> Parser NetworkId -> Parser (String -> NodeCmd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
    Parser (String -> NodeCmd) -> Parser String -> Parser NodeCmd
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath String
"filepath" String
"Filepath of Byron update proposal vote."


pByronProtocolParametersUpdate :: Parser ByronProtocolParametersUpdate
pByronProtocolParametersUpdate :: Parser ByronProtocolParametersUpdate
pByronProtocolParametersUpdate =
  Maybe Word16
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe LovelacePortion
-> Maybe LovelacePortion
-> Maybe LovelacePortion
-> Maybe LovelacePortion
-> Maybe SlotNumber
-> Maybe SoftforkRule
-> Maybe TxFeePolicy
-> Maybe EpochNumber
-> ByronProtocolParametersUpdate
ByronProtocolParametersUpdate
    (Maybe Word16
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe LovelacePortion
 -> Maybe LovelacePortion
 -> Maybe LovelacePortion
 -> Maybe LovelacePortion
 -> Maybe SlotNumber
 -> Maybe SoftforkRule
 -> Maybe TxFeePolicy
 -> Maybe EpochNumber
 -> ByronProtocolParametersUpdate)
-> Parser (Maybe Word16)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Word16 -> Parser (Maybe Word16)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Word16
parseScriptVersion
    Parser
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Natural -> Parser (Maybe Natural)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Natural
parseSlotDuration
    Parser
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Natural -> Parser (Maybe Natural)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Natural
parseMaxBlockSize
    Parser
  (Maybe Natural
   -> Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Natural -> Parser (Maybe Natural)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Natural
parseMaxHeaderSize
    Parser
  (Maybe Natural
   -> Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Natural -> Parser (Maybe Natural)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Natural
parseMaxTxSize
    Parser
  (Maybe Natural
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Natural -> Parser (Maybe Natural)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser Natural
parseMaxProposalSize
    Parser
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe LovelacePortion)
-> Parser
     (Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser LovelacePortion -> Parser (Maybe LovelacePortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser LovelacePortion
parseMpcThd
    Parser
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe LovelacePortion)
-> Parser
     (Maybe LovelacePortion
      -> Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser LovelacePortion -> Parser (Maybe LovelacePortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser LovelacePortion
parseHeavyDelThd
    Parser
  (Maybe LovelacePortion
   -> Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe LovelacePortion)
-> Parser
     (Maybe LovelacePortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser LovelacePortion -> Parser (Maybe LovelacePortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser LovelacePortion
parseUpdateVoteThd
    Parser
  (Maybe LovelacePortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe LovelacePortion)
-> Parser
     (Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser LovelacePortion -> Parser (Maybe LovelacePortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser LovelacePortion
parseUpdateProposalThd
    Parser
  (Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe SlotNumber)
-> Parser
     (Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SlotNumber -> Parser (Maybe SlotNumber)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser SlotNumber
parseUpdateProposalTTL
    Parser
  (Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ByronProtocolParametersUpdate)
-> Parser (Maybe SoftforkRule)
-> Parser
     (Maybe TxFeePolicy
      -> Maybe EpochNumber -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SoftforkRule -> Parser (Maybe SoftforkRule)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser SoftforkRule
parseSoftforkRule
    Parser
  (Maybe TxFeePolicy
   -> Maybe EpochNumber -> ByronProtocolParametersUpdate)
-> Parser (Maybe TxFeePolicy)
-> Parser (Maybe EpochNumber -> ByronProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TxFeePolicy -> Parser (Maybe TxFeePolicy)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser TxFeePolicy
parseTxFeePolicy
    Parser (Maybe EpochNumber -> ByronProtocolParametersUpdate)
-> Parser (Maybe EpochNumber)
-> Parser ByronProtocolParametersUpdate
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser EpochNumber -> Parser (Maybe EpochNumber)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser EpochNumber
parseUnlockStakeEpoch

parseByronUpdateProposalSubmission :: Parser NodeCmd
parseByronUpdateProposalSubmission :: Parser NodeCmd
parseByronUpdateProposalSubmission =
  NetworkId -> String -> NodeCmd
SubmitUpdateProposal
    (NetworkId -> String -> NodeCmd)
-> Parser NetworkId -> Parser (String -> NodeCmd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
    Parser (String -> NodeCmd) -> Parser String -> Parser NodeCmd
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath String
"filepath" String
"Filepath of Byron update proposal."


parseByronVote :: Parser NodeCmd
parseByronVote :: Parser NodeCmd
parseByronVote =
  NetworkId -> SigningKeyFile -> String -> Bool -> String -> NodeCmd
CreateVote
    (NetworkId
 -> SigningKeyFile -> String -> Bool -> String -> NodeCmd)
-> Parser NetworkId
-> Parser (SigningKeyFile -> String -> Bool -> String -> NodeCmd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
    Parser (SigningKeyFile -> String -> Bool -> String -> NodeCmd)
-> Parser SigningKeyFile
-> Parser (String -> Bool -> String -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> SigningKeyFile
SigningKeyFile (String -> SigningKeyFile)
-> Parser String -> Parser SigningKeyFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
"signing-key" String
"Filepath of signing key.")
    Parser (String -> Bool -> String -> NodeCmd)
-> Parser String -> Parser (Bool -> String -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath String
"proposal-filepath" String
"Filepath of Byron update proposal."
    Parser (Bool -> String -> NodeCmd)
-> Parser Bool -> Parser (String -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser Bool
parseVoteBool
    Parser (String -> NodeCmd) -> Parser String -> Parser NodeCmd
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath String
"output-filepath" String
"Byron vote output filepath."

--------------------------------------------------------------------------------
-- CLI Parsers
--------------------------------------------------------------------------------

parseScriptVersion :: Parser Word16
parseScriptVersion :: Parser Word16
parseScriptVersion =
  ReadM Word16 -> Mod OptionFields Word16 -> Parser Word16
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Word16
forall a. Read a => ReadM a
auto
    ( String -> Mod OptionFields Word16
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"script-version"
    Mod OptionFields Word16
-> Mod OptionFields Word16 -> Mod OptionFields Word16
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Word16
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"WORD16"
    Mod OptionFields Word16
-> Mod OptionFields Word16 -> Mod OptionFields Word16
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Word16
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed script version."
    )

parseSlotDuration :: Parser Natural
parseSlotDuration :: Parser Natural
parseSlotDuration =
  ReadM Natural -> Mod OptionFields Natural -> Parser Natural
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Natural
forall a. Read a => ReadM a
auto
    ( String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"slot-duration"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NATURAL"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed slot duration."
    )

parseSystemTag :: Parser SystemTag
parseSystemTag :: Parser SystemTag
parseSystemTag = ReadM SystemTag -> Mod OptionFields SystemTag -> Parser SystemTag
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ((String -> Either String SystemTag) -> ReadM SystemTag
forall a. (String -> Either String a) -> ReadM a
eitherReader String -> Either String SystemTag
checkSysTag)
                   ( String -> Mod OptionFields SystemTag
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"system-tag"
                   Mod OptionFields SystemTag
-> Mod OptionFields SystemTag -> Mod OptionFields SystemTag
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields SystemTag
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"STRING"
                   Mod OptionFields SystemTag
-> Mod OptionFields SystemTag -> Mod OptionFields SystemTag
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields SystemTag
forall (f :: * -> *) a. String -> Mod f a
help String
"Identify which system (linux, win64, etc) the update proposal is for."
                   )
 where
  checkSysTag :: String -> Either String SystemTag
  checkSysTag :: String -> Either String SystemTag
checkSysTag String
name =
    let tag :: SystemTag
tag = Text -> SystemTag
SystemTag (Text -> SystemTag) -> Text -> SystemTag
forall a b. (a -> b) -> a -> b
$ String -> Text
forall a b. ConvertText a b => a -> b
toS String
name
    in case SystemTag -> Either SystemTagError ()
forall (m :: * -> *).
MonadError SystemTagError m =>
SystemTag -> m ()
checkSystemTag SystemTag
tag of
         Left SystemTagError
err -> String -> Either String SystemTag
forall a b. a -> Either a b
Left (String -> Either String SystemTag)
-> (Text -> String) -> Text -> Either String SystemTag
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> String
forall a b. ConvertText a b => a -> b
toS (Text -> Either String SystemTag)
-> Text -> Either String SystemTag
forall a b. (a -> b) -> a -> b
$ Format Text (SystemTagError -> Text) -> SystemTagError -> Text
forall a. Format Text a -> a
sformat Format Text (SystemTagError -> Text)
forall a r. Buildable a => Format r (a -> r)
build SystemTagError
err
         Right () -> SystemTag -> Either String SystemTag
forall a b. b -> Either a b
Right SystemTag
tag

parseInstallerHash :: Parser InstallerHash
parseInstallerHash :: Parser InstallerHash
parseInstallerHash =
  Hash Raw -> InstallerHash
InstallerHash (Hash Raw -> InstallerHash)
-> (String -> Hash Raw) -> String -> InstallerHash
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
.  ByteString -> Hash Raw
hashRaw (ByteString -> Hash Raw)
-> (String -> ByteString) -> String -> Hash Raw
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. String -> ByteString
C8.pack
    (String -> InstallerHash) -> Parser String -> Parser InstallerHash
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption ( String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"installer-hash"
                  Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"HASH"
                  Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
"Software hash."
                  )

parseMaxBlockSize :: Parser Natural
parseMaxBlockSize :: Parser Natural
parseMaxBlockSize =
  ReadM Natural -> Mod OptionFields Natural -> Parser Natural
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Natural
forall a. Read a => ReadM a
auto
    ( String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"max-block-size"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NATURAL"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed max block size."
    )

parseMaxHeaderSize :: Parser Natural
parseMaxHeaderSize :: Parser Natural
parseMaxHeaderSize =
  ReadM Natural -> Mod OptionFields Natural -> Parser Natural
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Natural
forall a. Read a => ReadM a
auto
    ( String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"max-header-size"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NATURAL"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed max block header size."
    )

parseMaxTxSize :: Parser Natural
parseMaxTxSize :: Parser Natural
parseMaxTxSize =
  ReadM Natural -> Mod OptionFields Natural -> Parser Natural
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Natural
forall a. Read a => ReadM a
auto
    ( String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"max-tx-size"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NATURAL"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed max transaction size."
    )

parseMaxProposalSize :: Parser  Natural
parseMaxProposalSize :: Parser Natural
parseMaxProposalSize =
  ReadM Natural -> Mod OptionFields Natural -> Parser Natural
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Natural
forall a. Read a => ReadM a
auto
    ( String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"max-proposal-size"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"NATURAL"
    Mod OptionFields Natural
-> Mod OptionFields Natural -> Mod OptionFields Natural
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Natural
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed max update proposal size."
    )

parseMpcThd :: Parser Byron.LovelacePortion
parseMpcThd :: Parser LovelacePortion
parseMpcThd =
  Rational -> LovelacePortion
rationalToLovelacePortion
    (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Rational
parseFraction String
"max-mpc-thd" String
"Proposed max mpc threshold."

parseProtocolVersion :: Parser ProtocolVersion
parseProtocolVersion :: Parser ProtocolVersion
parseProtocolVersion =
  Word16 -> Word16 -> Word8 -> ProtocolVersion
ProtocolVersion (Word16 -> Word16 -> Word8 -> ProtocolVersion)
-> Parser Word16 -> Parser (Word16 -> Word8 -> ProtocolVersion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (String -> String -> String -> Parser Word16
forall a. Integral a => String -> String -> String -> Parser a
parseWord String
"protocol-version-major" String
"Protocol verson major." String
"WORD16" :: Parser Word16)
                  Parser (Word16 -> Word8 -> ProtocolVersion)
-> Parser Word16 -> Parser (Word8 -> ProtocolVersion)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> String -> String -> Parser Word16
forall a. Integral a => String -> String -> String -> Parser a
parseWord String
"protocol-version-minor" String
"Protocol verson minor." String
"WORD16" :: Parser Word16)
                  Parser (Word8 -> ProtocolVersion)
-> Parser Word8 -> Parser ProtocolVersion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (String -> String -> String -> Parser Word8
forall a. Integral a => String -> String -> String -> Parser a
parseWord String
"protocol-version-alt" String
"Protocol verson alt." String
"WORD8" :: Parser Word8)

parseHeavyDelThd :: Parser Byron.LovelacePortion
parseHeavyDelThd :: Parser LovelacePortion
parseHeavyDelThd =
  Rational -> LovelacePortion
rationalToLovelacePortion
    (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Rational
parseFraction String
"heavy-del-thd" String
"Proposed heavy delegation threshold."

parseUpdateVoteThd :: Parser Byron.LovelacePortion
parseUpdateVoteThd :: Parser LovelacePortion
parseUpdateVoteThd =
  Rational -> LovelacePortion
rationalToLovelacePortion
    (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Rational
parseFraction String
"update-vote-thd" String
"Propose update vote threshold."

parseUpdateProposalThd :: Parser Byron.LovelacePortion
parseUpdateProposalThd :: Parser LovelacePortion
parseUpdateProposalThd =
  Rational -> LovelacePortion
rationalToLovelacePortion
    (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Rational
parseFraction String
"update-proposal-thd" String
"Propose update proposal threshold."

parseUpdateProposalTTL :: Parser SlotNumber
parseUpdateProposalTTL :: Parser SlotNumber
parseUpdateProposalTTL =
  Word64 -> SlotNumber
SlotNumber
    (Word64 -> SlotNumber) -> Parser Word64 -> Parser SlotNumber
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Word64 -> Mod OptionFields Word64 -> Parser Word64
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Word64
forall a. Read a => ReadM a
auto
          ( String -> Mod OptionFields Word64
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"time-to-live"
          Mod OptionFields Word64
-> Mod OptionFields Word64 -> Mod OptionFields Word64
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Word64
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"WORD64"
          Mod OptionFields Word64
-> Mod OptionFields Word64 -> Mod OptionFields Word64
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Word64
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed time for an update proposal to live."
          )

parseSoftforkRule :: Parser SoftforkRule
parseSoftforkRule :: Parser SoftforkRule
parseSoftforkRule =
  LovelacePortion
-> LovelacePortion -> LovelacePortion -> SoftforkRule
SoftforkRule
    (LovelacePortion
 -> LovelacePortion -> LovelacePortion -> SoftforkRule)
-> Parser LovelacePortion
-> Parser (LovelacePortion -> LovelacePortion -> SoftforkRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Rational -> LovelacePortion
rationalToLovelacePortion (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Rational
parseFraction String
"softfork-init-thd" String
"Propose initial threshold (right after proposal is confirmed).")
    Parser (LovelacePortion -> LovelacePortion -> SoftforkRule)
-> Parser LovelacePortion
-> Parser (LovelacePortion -> SoftforkRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> LovelacePortion
rationalToLovelacePortion (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Rational
parseFraction String
"softfork-min-thd" String
"Propose minimum threshold (threshold can't be less than this).")
    Parser (LovelacePortion -> SoftforkRule)
-> Parser LovelacePortion -> Parser SoftforkRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> LovelacePortion
rationalToLovelacePortion (Rational -> LovelacePortion)
-> Parser Rational -> Parser LovelacePortion
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Rational
parseFraction String
"softfork-thd-dec" String
"Propose threshold decrement (threshold will decrease by this amount after each epoch).")


parseSoftwareVersion :: Parser SoftwareVersion
parseSoftwareVersion :: Parser SoftwareVersion
parseSoftwareVersion =
  ApplicationName -> NumSoftwareVersion -> SoftwareVersion
SoftwareVersion (ApplicationName -> NumSoftwareVersion -> SoftwareVersion)
-> Parser ApplicationName
-> Parser (NumSoftwareVersion -> SoftwareVersion)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ApplicationName
parseApplicationName Parser (NumSoftwareVersion -> SoftwareVersion)
-> Parser NumSoftwareVersion -> Parser SoftwareVersion
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser NumSoftwareVersion
parseNumSoftwareVersion

parseApplicationName :: Parser ApplicationName
parseApplicationName :: Parser ApplicationName
parseApplicationName = ReadM ApplicationName
-> Mod OptionFields ApplicationName -> Parser ApplicationName
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ((String -> Either String ApplicationName) -> ReadM ApplicationName
forall a. (String -> Either String a) -> ReadM a
eitherReader String -> Either String ApplicationName
checkAppNameLength)
       (  String -> Mod OptionFields ApplicationName
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"application-name"
       Mod OptionFields ApplicationName
-> Mod OptionFields ApplicationName
-> Mod OptionFields ApplicationName
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields ApplicationName
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"STRING"
       Mod OptionFields ApplicationName
-> Mod OptionFields ApplicationName
-> Mod OptionFields ApplicationName
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields ApplicationName
forall (f :: * -> *) a. String -> Mod f a
help String
"The name of the application."
       )
 where
  checkAppNameLength :: String -> Either String ApplicationName
  checkAppNameLength :: String -> Either String ApplicationName
checkAppNameLength String
name =
    let appName :: ApplicationName
appName = Text -> ApplicationName
ApplicationName (Text -> ApplicationName) -> Text -> ApplicationName
forall a b. (a -> b) -> a -> b
$ String -> Text
forall a b. ConvertText a b => a -> b
toS String
name
    in case ApplicationName -> Either ApplicationNameError ()
forall (m :: * -> *).
MonadError ApplicationNameError m =>
ApplicationName -> m ()
checkApplicationName ApplicationName
appName of
         Left ApplicationNameError
err -> String -> Either String ApplicationName
forall a b. a -> Either a b
Left (String -> Either String ApplicationName)
-> (Text -> String) -> Text -> Either String ApplicationName
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Text -> String
forall a b. ConvertText a b => a -> b
toS (Text -> Either String ApplicationName)
-> Text -> Either String ApplicationName
forall a b. (a -> b) -> a -> b
$ Format Text (ApplicationNameError -> Text)
-> ApplicationNameError -> Text
forall a. Format Text a -> a
sformat Format Text (ApplicationNameError -> Text)
forall a r. Buildable a => Format r (a -> r)
build ApplicationNameError
err
         Right () -> ApplicationName -> Either String ApplicationName
forall a b. b -> Either a b
Right ApplicationName
appName

parseNumSoftwareVersion :: Parser NumSoftwareVersion
parseNumSoftwareVersion :: Parser NumSoftwareVersion
parseNumSoftwareVersion =
  String -> String -> String -> Parser NumSoftwareVersion
forall a. Integral a => String -> String -> String -> Parser a
parseWord
    String
"software-version-num"
    String
"Numeric software version associated with application name."
    String
"WORD32"

parseTxFeePolicy :: Parser TxFeePolicy
parseTxFeePolicy :: Parser TxFeePolicy
parseTxFeePolicy =
  TxSizeLinear -> TxFeePolicy
TxFeePolicyTxSizeLinear
    (TxSizeLinear -> TxFeePolicy)
-> Parser TxSizeLinear -> Parser TxFeePolicy
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ( Lovelace -> Rational -> TxSizeLinear
TxSizeLinear (Lovelace -> Rational -> TxSizeLinear)
-> Parser Lovelace -> Parser (Rational -> TxSizeLinear)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Lovelace
parseLovelace String
"tx-fee-a-constant" String
"Propose the constant a for txfee = a + b*s where s is the size."
                       Parser (Rational -> TxSizeLinear)
-> Parser Rational -> Parser TxSizeLinear
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser Rational
parseFraction String
"tx-fee-b-constant" String
"Propose the constant b for txfee = a + b*s where s is the size."
        )

parseVoteBool :: Parser Bool
parseVoteBool :: Parser Bool
parseVoteBool = Bool -> Mod FlagFields Bool -> Parser Bool
forall a. a -> Mod FlagFields a -> Parser a
flag' Bool
True (String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"vote-yes" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Vote yes with respect to an update proposal.")
            Parser Bool -> Parser Bool -> Parser Bool
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Bool -> Mod FlagFields Bool -> Parser Bool
forall a. a -> Mod FlagFields a -> Parser a
flag' Bool
False (String -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"vote-no" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields Bool
forall (f :: * -> *) a. String -> Mod f a
help String
"Vote no with respect to an update proposal.")

parseUnlockStakeEpoch :: Parser EpochNumber
parseUnlockStakeEpoch :: Parser EpochNumber
parseUnlockStakeEpoch =
  Word64 -> EpochNumber
EpochNumber
    (Word64 -> EpochNumber) -> Parser Word64 -> Parser EpochNumber
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Word64 -> Mod OptionFields Word64 -> Parser Word64
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Word64
forall a. Read a => ReadM a
auto
      ( String -> Mod OptionFields Word64
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"unlock-stake-epoch"
      Mod OptionFields Word64
-> Mod OptionFields Word64 -> Mod OptionFields Word64
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Word64
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"WORD64"
      Mod OptionFields Word64
-> Mod OptionFields Word64 -> Mod OptionFields Word64
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Word64
forall (f :: * -> *) a. String -> Mod f a
help String
"Proposed epoch to unlock all stake."
      )


parseWord :: Integral a => String -> String -> String -> Parser a
parseWord :: String -> String -> String -> Parser a
parseWord String
optname String
desc String
metvar = ReadM a -> Mod OptionFields a -> Parser a
forall a. ReadM a -> Mod OptionFields a -> Parser a
option (Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> ReadM Integer -> ReadM a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Integer
forall a. Read a => ReadM a
auto)
  (Mod OptionFields a -> Parser a) -> Mod OptionFields a -> Parser a
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields a
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname Mod OptionFields a -> Mod OptionFields a -> Mod OptionFields a
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields a
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
metvar Mod OptionFields a -> Mod OptionFields a -> Mod OptionFields a
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields a
forall (f :: * -> *) a. String -> Mod f a
help String
desc



parseAddress :: String -> String -> Parser (Address ByronAddr)
parseAddress :: String -> String -> Parser (Address ByronAddr)
parseAddress String
opt String
desc =
  ReadM (Address ByronAddr)
-> Mod OptionFields (Address ByronAddr)
-> Parser (Address ByronAddr)
forall a. ReadM a -> Mod OptionFields a -> Parser a
option (Text -> Address ByronAddr
cliParseBase58Address (Text -> Address ByronAddr)
-> ReadM Text -> ReadM (Address ByronAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Text
forall s. IsString s => ReadM s
str)
    (Mod OptionFields (Address ByronAddr)
 -> Parser (Address ByronAddr))
-> Mod OptionFields (Address ByronAddr)
-> Parser (Address ByronAddr)
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields (Address ByronAddr)
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
opt Mod OptionFields (Address ByronAddr)
-> Mod OptionFields (Address ByronAddr)
-> Mod OptionFields (Address ByronAddr)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (Address ByronAddr)
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"ADDR" Mod OptionFields (Address ByronAddr)
-> Mod OptionFields (Address ByronAddr)
-> Mod OptionFields (Address ByronAddr)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (Address ByronAddr)
forall (f :: * -> *) a. String -> Mod f a
help String
desc

parseByronKeyFormat :: Parser ByronKeyFormat
parseByronKeyFormat :: Parser ByronKeyFormat
parseByronKeyFormat = [Parser ByronKeyFormat] -> Parser ByronKeyFormat
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
  [ ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a. a -> Mod FlagFields a -> Parser a
flag' ByronKeyFormat
LegacyByronKeyFormat (Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat)
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-legacy-formats"
     Mod FlagFields ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Mod FlagFields ByronKeyFormat
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. String -> Mod f a
help String
"Byron/cardano-sl formats and compatibility"

  , ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a. a -> Mod FlagFields a -> Parser a
flag' ByronKeyFormat
NonLegacyByronKeyFormat (Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat)
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-formats"
     Mod FlagFields ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Mod FlagFields ByronKeyFormat
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. String -> Mod f a
help String
"Byron era formats and compatibility"

    -- And hidden compatibility flag aliases that should be deprecated:
  , ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a. a -> Mod FlagFields a -> Parser a
flag' ByronKeyFormat
LegacyByronKeyFormat (Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat)
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a b. (a -> b) -> a -> b
$ Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. Mod f a
hidden Mod FlagFields ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Mod FlagFields ByronKeyFormat
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"byron-legacy"
  , ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a. a -> Mod FlagFields a -> Parser a
flag' ByronKeyFormat
NonLegacyByronKeyFormat (Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat)
-> Mod FlagFields ByronKeyFormat -> Parser ByronKeyFormat
forall a b. (a -> b) -> a -> b
$ Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. Mod f a
hidden Mod FlagFields ByronKeyFormat
-> Mod FlagFields ByronKeyFormat -> Mod FlagFields ByronKeyFormat
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ByronKeyFormat
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"real-pbft"

  -- Default Byron key format
  , ByronKeyFormat -> Parser ByronKeyFormat
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByronKeyFormat
NonLegacyByronKeyFormat
  ]


parseFakeAvvmOptions :: Parser FakeAvvmOptions
parseFakeAvvmOptions :: Parser FakeAvvmOptions
parseFakeAvvmOptions =
  Word -> Lovelace -> FakeAvvmOptions
FakeAvvmOptions
    (Word -> Lovelace -> FakeAvvmOptions)
-> Parser Word -> Parser (Lovelace -> FakeAvvmOptions)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Word
forall a. Integral a => String -> String -> Parser a
parseIntegral String
"avvm-entry-count" String
"Number of AVVM addresses."
    Parser (Lovelace -> FakeAvvmOptions)
-> Parser Lovelace -> Parser FakeAvvmOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser Lovelace
parseLovelace String
"avvm-entry-balance" String
"AVVM address."

parseK :: Parser BlockCount
parseK :: Parser BlockCount
parseK =
  Word64 -> BlockCount
BlockCount
    (Word64 -> BlockCount) -> Parser Word64 -> Parser BlockCount
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Word64
forall a. Integral a => String -> String -> Parser a
parseIntegral String
"k" String
"The security parameter of the Ouroboros protocol."

parseNewDirectory :: String -> String -> Parser NewDirectory
parseNewDirectory :: String -> String -> Parser NewDirectory
parseNewDirectory String
opt String
desc = String -> NewDirectory
NewDirectory (String -> NewDirectory) -> Parser String -> Parser NewDirectory
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
opt String
desc

parseFractionWithDefault
  :: String
  -> String
  -> Double
  -> Parser Rational
parseFractionWithDefault :: String -> String -> Double -> Parser Rational
parseFractionWithDefault String
optname String
desc Double
w =
  Double -> Rational
forall a. Real a => a -> Rational
toRational (Double -> Rational) -> Parser Double -> Parser Rational
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Double -> Mod OptionFields Double -> Parser Double
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM Double
readDouble
    ( String -> Mod OptionFields Double
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname
    Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Double
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"DOUBLE"
    Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Double
forall (f :: * -> *) a. String -> Mod f a
help String
desc
    Mod OptionFields Double
-> Mod OptionFields Double -> Mod OptionFields Double
forall a. Semigroup a => a -> a -> a
<> Double -> Mod OptionFields Double
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Double
w
    )

pNetworkId :: Parser NetworkId
pNetworkId :: Parser NetworkId
pNetworkId =
  Parser NetworkId
pMainnet' Parser NetworkId -> Parser NetworkId -> Parser NetworkId
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (NetworkMagic -> NetworkId)
-> Parser NetworkMagic -> Parser NetworkId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NetworkMagic -> NetworkId
Testnet Parser NetworkMagic
pTestnetMagic
 where
   pMainnet' :: Parser NetworkId
   pMainnet' :: Parser NetworkId
pMainnet' =
    NetworkId -> Mod FlagFields NetworkId -> Parser NetworkId
forall a. a -> Mod FlagFields a -> Parser a
Opt.flag' NetworkId
Mainnet
      (  String -> Mod FlagFields NetworkId
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"mainnet"
      Mod FlagFields NetworkId
-> Mod FlagFields NetworkId -> Mod FlagFields NetworkId
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields NetworkId
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Use the mainnet magic id."
      )

pTestnetMagic :: Parser NetworkMagic
pTestnetMagic :: Parser NetworkMagic
pTestnetMagic =
  NumSoftwareVersion -> NetworkMagic
NetworkMagic (NumSoftwareVersion -> NetworkMagic)
-> Parser NumSoftwareVersion -> Parser NetworkMagic
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    ReadM NumSoftwareVersion
-> Mod OptionFields NumSoftwareVersion -> Parser NumSoftwareVersion
forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option ReadM NumSoftwareVersion
forall a. Read a => ReadM a
Opt.auto
      (  String -> Mod OptionFields NumSoftwareVersion
forall (f :: * -> *) a. HasName f => String -> Mod f a
Opt.long String
"testnet-magic"
      Mod OptionFields NumSoftwareVersion
-> Mod OptionFields NumSoftwareVersion
-> Mod OptionFields NumSoftwareVersion
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields NumSoftwareVersion
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
Opt.metavar String
"NATURAL"
      Mod OptionFields NumSoftwareVersion
-> Mod OptionFields NumSoftwareVersion
-> Mod OptionFields NumSoftwareVersion
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields NumSoftwareVersion
forall (f :: * -> *) a. String -> Mod f a
Opt.help String
"Specify a testnet magic id."
      )

parseNewSigningKeyFile :: String -> Parser NewSigningKeyFile
parseNewSigningKeyFile :: String -> Parser NewSigningKeyFile
parseNewSigningKeyFile String
opt =
  String -> NewSigningKeyFile
NewSigningKeyFile
    (String -> NewSigningKeyFile)
-> Parser String -> Parser NewSigningKeyFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
opt String
"Non-existent file to write the signing key to."

parseNewTxFile :: String -> Parser NewTxFile
parseNewTxFile :: String -> Parser NewTxFile
parseNewTxFile String
opt =
  String -> NewTxFile
NewTxFile
    (String -> NewTxFile) -> Parser String -> Parser NewTxFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
opt String
"Non-existent file to write the signed transaction to."

parseNewVerificationKeyFile :: String -> Parser NewVerificationKeyFile
parseNewVerificationKeyFile :: String -> Parser NewVerificationKeyFile
parseNewVerificationKeyFile String
opt =
  String -> NewVerificationKeyFile
NewVerificationKeyFile
    (String -> NewVerificationKeyFile)
-> Parser String -> Parser NewVerificationKeyFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
opt String
"Non-existent file to write the verification key to."

parseProtocolMagicId :: String -> Parser ProtocolMagicId
parseProtocolMagicId :: String -> Parser ProtocolMagicId
parseProtocolMagicId String
arg =
  NumSoftwareVersion -> ProtocolMagicId
ProtocolMagicId
    (NumSoftwareVersion -> ProtocolMagicId)
-> Parser NumSoftwareVersion -> Parser ProtocolMagicId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser NumSoftwareVersion
forall a. Integral a => String -> String -> Parser a
parseIntegral String
arg String
"The magic number unique to any instance of Cardano."

parseProtocolMagic :: Parser ProtocolMagic
parseProtocolMagic :: Parser ProtocolMagic
parseProtocolMagic =
  (Annotated ProtocolMagicId ()
 -> RequiresNetworkMagic -> ProtocolMagic)
-> RequiresNetworkMagic
-> Annotated ProtocolMagicId ()
-> ProtocolMagic
forall a b c. (a -> b -> c) -> b -> a -> c
flip Annotated ProtocolMagicId ()
-> RequiresNetworkMagic -> ProtocolMagic
forall a.
Annotated ProtocolMagicId a
-> RequiresNetworkMagic -> AProtocolMagic a
AProtocolMagic RequiresNetworkMagic
RequiresMagic (Annotated ProtocolMagicId () -> ProtocolMagic)
-> (ProtocolMagicId -> Annotated ProtocolMagicId ())
-> ProtocolMagicId
-> ProtocolMagic
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. (ProtocolMagicId -> () -> Annotated ProtocolMagicId ())
-> () -> ProtocolMagicId -> Annotated ProtocolMagicId ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip ProtocolMagicId -> () -> Annotated ProtocolMagicId ()
forall b a. b -> a -> Annotated b a
Annotated ()
    (ProtocolMagicId -> ProtocolMagic)
-> Parser ProtocolMagicId -> Parser ProtocolMagic
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser ProtocolMagicId
parseProtocolMagicId String
"protocol-magic"

parseTxFile :: String -> Parser TxFile
parseTxFile :: String -> Parser TxFile
parseTxFile String
opt =
  String -> TxFile
TxFile
    (String -> TxFile) -> Parser String -> Parser TxFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
opt String
"File containing the signed transaction."

parseUTCTime :: String -> String -> Parser UTCTime
parseUTCTime :: String -> String -> Parser UTCTime
parseUTCTime String
optname String
desc =
  ReadM UTCTime -> Mod OptionFields UTCTime -> Parser UTCTime
forall a. ReadM a -> Mod OptionFields a -> Parser a
option (POSIXTime -> UTCTime
posixSecondsToUTCTime (POSIXTime -> UTCTime)
-> (Integer -> POSIXTime) -> Integer -> UTCTime
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Integer -> POSIXTime
forall a. Num a => Integer -> a
fromInteger (Integer -> UTCTime) -> ReadM Integer -> ReadM UTCTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Integer
forall a. Read a => ReadM a
auto)
    (Mod OptionFields UTCTime -> Parser UTCTime)
-> Mod OptionFields UTCTime -> Parser UTCTime
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields UTCTime
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname Mod OptionFields UTCTime
-> Mod OptionFields UTCTime -> Mod OptionFields UTCTime
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields UTCTime
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"POSIXSECONDS" Mod OptionFields UTCTime
-> Mod OptionFields UTCTime -> Mod OptionFields UTCTime
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields UTCTime
forall (f :: * -> *) a. String -> Mod f a
help String
desc

cliParseBase58Address :: Text -> Address ByronAddr
cliParseBase58Address :: Text -> Address ByronAddr
cliParseBase58Address Text
t =
  case Text -> Either DecoderError Address
decodeAddressBase58 Text
t of
    Left DecoderError
err -> Text -> Address ByronAddr
forall a. HasCallStack => Text -> a
panic (Text -> Address ByronAddr) -> Text -> Address ByronAddr
forall a b. (a -> b) -> a -> b
$ Text
"Bad Base58 address: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (DecoderError -> String
forall a b. (Show a, ConvertText String b) => a -> b
show DecoderError
err)
    Right Address
byronAddress -> Address -> Address ByronAddr
ByronAddress Address
byronAddress

parseFraction :: String -> String -> Parser Rational
parseFraction :: String -> String -> Parser Rational
parseFraction String
optname String
desc =
  ReadM Rational -> Mod OptionFields Rational -> Parser Rational
forall a. ReadM a -> Mod OptionFields a -> Parser a
option (Double -> Rational
forall a. Real a => a -> Rational
toRational (Double -> Rational) -> ReadM Double -> ReadM Rational
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Double
readDouble) (Mod OptionFields Rational -> Parser Rational)
-> Mod OptionFields Rational -> Parser Rational
forall a b. (a -> b) -> a -> b
$
      String -> Mod OptionFields Rational
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname
   Mod OptionFields Rational
-> Mod OptionFields Rational -> Mod OptionFields Rational
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Rational
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"DOUBLE"
   Mod OptionFields Rational
-> Mod OptionFields Rational -> Mod OptionFields Rational
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Rational
forall (f :: * -> *) a. String -> Mod f a
help String
desc

parseIntegral :: Integral a => String -> String -> Parser a
parseIntegral :: String -> String -> Parser a
parseIntegral String
optname String
desc = ReadM a -> Mod OptionFields a -> Parser a
forall a. ReadM a -> Mod OptionFields a -> Parser a
option (Integer -> a
forall a. Num a => Integer -> a
fromInteger (Integer -> a) -> ReadM Integer -> ReadM a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Integer
forall a. Read a => ReadM a
auto)
  (Mod OptionFields a -> Parser a) -> Mod OptionFields a -> Parser a
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields a
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname Mod OptionFields a -> Mod OptionFields a -> Mod OptionFields a
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields a
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"INT" Mod OptionFields a -> Mod OptionFields a -> Mod OptionFields a
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields a
forall (f :: * -> *) a. String -> Mod f a
help String
desc

parseLovelace :: String -> String -> Parser Byron.Lovelace
parseLovelace :: String -> String -> Parser Lovelace
parseLovelace String
optname String
desc =
  ReadM Lovelace -> Mod OptionFields Lovelace -> Parser Lovelace
forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option (Parser Lovelace -> ReadM Lovelace
forall a. Parser a -> ReadM a
readerFromAttoParser Parser Lovelace
parseLovelaceAtto)
    (  String -> Mod OptionFields Lovelace
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname
    Mod OptionFields Lovelace
-> Mod OptionFields Lovelace -> Mod OptionFields Lovelace
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Lovelace
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"INT"
    Mod OptionFields Lovelace
-> Mod OptionFields Lovelace -> Mod OptionFields Lovelace
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Lovelace
forall (f :: * -> *) a. String -> Mod f a
help String
desc
    )
 where
  parseLovelaceAtto :: Atto.Parser Byron.Lovelace
  parseLovelaceAtto :: Parser Lovelace
parseLovelaceAtto = do
    Integer
i <- Parser Integer
forall a. Integral a => Parser a
Atto.decimal
    if Integer
i Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
> Word64 -> Integer
forall a. Integral a => a -> Integer
toInteger (Word64
forall a. Bounded a => a
maxBound :: Word64)
    then String -> Parser Lovelace
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Lovelace) -> String -> Parser Lovelace
forall a b. (a -> b) -> a -> b
$ Integer -> String
forall a b. (Show a, ConvertText String b) => a -> b
show Integer
i String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
" lovelace exceeds the Word64 upper bound"
    else case Lovelace -> Maybe Lovelace
toByronLovelace (Integer -> Lovelace
Lovelace Integer
i) of
           Just Lovelace
byronLovelace -> Lovelace -> Parser Lovelace
forall (m :: * -> *) a. Monad m => a -> m a
return Lovelace
byronLovelace
           Maybe Lovelace
Nothing -> Text -> Parser Lovelace
forall a. HasCallStack => Text -> a
panic (Text -> Parser Lovelace) -> Text -> Parser Lovelace
forall a b. (a -> b) -> a -> b
$ Text
"Error converting lovelace: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> String -> Text
Text.pack (Integer -> String
forall a b. (Show a, ConvertText String b) => a -> b
show Integer
i)

readDouble :: ReadM Double
readDouble :: ReadM Double
readDouble = do
  Double
f <- ReadM Double
forall a. Read a => ReadM a
auto
  Bool -> ReadM () -> ReadM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Double
f Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
< Double
0) (ReadM () -> ReadM ()) -> ReadM () -> ReadM ()
forall a b. (a -> b) -> a -> b
$ String -> ReadM ()
forall a. String -> ReadM a
readerError String
"fraction must be >= 0"
  Bool -> ReadM () -> ReadM ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Double
f Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
1) (ReadM () -> ReadM ()) -> ReadM () -> ReadM ()
forall a b. (a -> b) -> a -> b
$ String -> ReadM ()
forall a. String -> ReadM a
readerError String
"fraction must be <= 1"
  Double -> ReadM Double
forall (m :: * -> *) a. Monad m => a -> m a
return Double
f

parseFilePath :: String -> String -> Parser FilePath
parseFilePath :: String -> String -> Parser String
parseFilePath String
optname String
desc =
  Mod OptionFields String -> Parser String
forall s. IsString s => Mod OptionFields s -> Parser s
strOption
    ( String -> Mod OptionFields String
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname
    Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"FILEPATH"
    Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields String
forall (f :: * -> *) a. String -> Mod f a
help String
desc
    Mod OptionFields String
-> Mod OptionFields String -> Mod OptionFields String
forall a. Semigroup a => a -> a -> a
<> Completer -> Mod OptionFields String
forall (f :: * -> *) a. HasCompleter f => Completer -> Mod f a
completer (String -> Completer
bashCompleter String
"file")
    )

parseSigningKeyFile :: String -> String -> Parser SigningKeyFile
parseSigningKeyFile :: String -> String -> Parser SigningKeyFile
parseSigningKeyFile String
opt String
desc = String -> SigningKeyFile
SigningKeyFile (String -> SigningKeyFile)
-> Parser String -> Parser SigningKeyFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
opt String
desc


parseGenesisFile :: String -> Parser GenesisFile
parseGenesisFile :: String -> Parser GenesisFile
parseGenesisFile String
opt =
  String -> GenesisFile
GenesisFile (String -> GenesisFile) -> Parser String -> Parser GenesisFile
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser String
parseFilePath String
opt String
"Genesis JSON file."