module Bcc.CLI.Cole.Parsers
  ( ColeCommand(..)
  , NodeCmd(..)
  , backwardsCompatibilityCommands
  , parseColeCommands
  , parseHeavyDelThd
  , parseInstallerHash
  , parseMaxBlockSize
  , parseMaxHeaderSize
  , parseMaxTxSize
  , parseMaxProposalSize
  , parseMpcThd
  , parseScriptVersion
  , parseSlotDuration
  , parseSoftforkRule
  , parseSystemTag
  , parseTxFeePolicy
  , parseUpdateProposalThd
  , parseUpdateProposalTTL
  , parseUnlockStakeEpoch
  , parseUpdateVoteThd
  ) where

import           Bcc.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           Bcc.Binary (Annotated (..))

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

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

import           Bcc.Api hiding (UpdateProposal, GenesisParameters)
import           Bcc.Api.Cole (Address (..), ColeProtocolParametersUpdate (..), Entropic (..),
                   toColeEntropic)

import           Bcc.CLI.Cole.Commands
import           Bcc.CLI.Cole.Genesis
import           Bcc.CLI.Cole.Key
import           Bcc.CLI.Cole.Tx
import           Bcc.CLI.Run (ClientCommand (ColeCommand))
import           Bcc.CLI.Sophie.Commands (ColeKeyFormat (..))
import           Bcc.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
  convertToColeCommand :: Mod CommandFields ColeCommand -> Parser ClientCommand
  convertToColeCommand :: Mod CommandFields ColeCommand -> Parser ClientCommand
convertToColeCommand Mod CommandFields ColeCommand
p = ColeCommand -> ClientCommand
ColeCommand (ColeCommand -> ClientCommand)
-> Parser ColeCommand -> Parser ClientCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Mod CommandFields ColeCommand -> Parser ColeCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser (Mod CommandFields ColeCommand
p Mod CommandFields ColeCommand
-> Mod CommandFields ColeCommand -> Mod CommandFields ColeCommand
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields ColeCommand
forall (f :: * -> *) a. Mod f a
Opt.internal)

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

-- Implemented with asum so all commands don't get hidden when trying to hide
-- the 'pNodeCmdBackwardCompatible' parser.
parseColeCommands :: Parser ColeCommand
parseColeCommands :: Parser ColeCommand
parseColeCommands = [Parser ColeCommand] -> Parser ColeCommand
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
  [ String -> ParserInfo ColeCommand -> Parser ColeCommand
subParser String
"key" (Parser ColeCommand -> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ColeCommand -> Parser ColeCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ColeCommand
parseKeyRelatedValues)
      (InfoMod ColeCommand -> ParserInfo ColeCommand)
-> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ColeCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Cole key utility commands")
  , String -> ParserInfo ColeCommand -> Parser ColeCommand
subParser String
"transaction" (Parser ColeCommand -> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ColeCommand -> Parser ColeCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ColeCommand
parseTxRelatedValues)
      (InfoMod ColeCommand -> ParserInfo ColeCommand)
-> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ColeCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Cole transaction commands")
  , String -> ParserInfo ColeCommand -> Parser ColeCommand
subParser String
"query" (Parser ColeCommand -> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ColeCommand -> Parser ColeCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ColeCommand
parseLocalNodeQueryValues)
      (InfoMod ColeCommand -> ParserInfo ColeCommand)
-> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ColeCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Cole node query commands.")
  , String -> ParserInfo ColeCommand -> Parser ColeCommand
subParser String
"genesis" (Parser ColeCommand -> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ColeCommand -> Parser ColeCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ColeCommand
parseGenesisRelatedValues)
      (InfoMod ColeCommand -> ParserInfo ColeCommand)
-> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ColeCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Cole genesis block commands")
  , String -> ParserInfo ColeCommand -> Parser ColeCommand
subParser String
"governance" (Parser ColeCommand -> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (NodeCmd -> ColeCommand
NodeCmd (NodeCmd -> ColeCommand) -> Parser NodeCmd -> Parser ColeCommand
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 ColeCommand -> ParserInfo ColeCommand)
-> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ColeCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Cole governance commands")
  , String -> ParserInfo ColeCommand -> Parser ColeCommand
subParser String
"miscellaneous" (Parser ColeCommand -> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a. Parser a -> InfoMod a -> ParserInfo a
Opt.info (Mod CommandFields ColeCommand -> Parser ColeCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser Mod CommandFields ColeCommand
parseMiscellaneous)
      (InfoMod ColeCommand -> ParserInfo ColeCommand)
-> InfoMod ColeCommand -> ParserInfo ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> InfoMod ColeCommand
forall a. String -> InfoMod a
Opt.progDesc String
"Cole miscellaneous commands")
  , NodeCmd -> ColeCommand
NodeCmd (NodeCmd -> ColeCommand) -> Parser NodeCmd -> Parser ColeCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NodeCmd
pNodeCmdBackwardCompatible
  ]
 where
   subParser :: String -> ParserInfo ColeCommand -> Parser ColeCommand
   subParser :: String -> ParserInfo ColeCommand -> Parser ColeCommand
subParser String
name ParserInfo ColeCommand
pInfo = Mod CommandFields ColeCommand -> Parser ColeCommand
forall a. Mod CommandFields a -> Parser a
Opt.subparser (Mod CommandFields ColeCommand -> Parser ColeCommand)
-> Mod CommandFields ColeCommand -> Parser ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> ParserInfo ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> ParserInfo a -> Mod CommandFields a
Opt.command String
name ParserInfo ColeCommand
pInfo Mod CommandFields ColeCommand
-> Mod CommandFields ColeCommand -> Mod CommandFields ColeCommand
forall a. Semigroup a => a -> a -> a
<> String -> Mod CommandFields ColeCommand
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
CBORBlockCole (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
"cole-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 cole 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
CBORDelegationCertificateCole (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
"cole-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 cole era delegation certificate"

  , CBORObject -> Mod FlagFields CBORObject -> Parser CBORObject
forall a. a -> Mod FlagFields a -> Parser a
flag' CBORObject
CBORTxCole (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
"cole-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 cole era tx"

  , CBORObject -> Mod FlagFields CBORObject -> Parser CBORObject
forall a. a -> Mod FlagFields a -> Parser a
flag' CBORObject
CBORUpdateProposalCole (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
"cole-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 cole era update proposal"
  , CBORObject -> Mod FlagFields CBORObject -> Parser CBORObject
forall a. a -> Mod FlagFields a -> Parser a
flag' CBORObject
CBORVoteCole (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
"cole-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 cole era vote"
  ]

-- | Values required to create genesis.
parseGenesisParameters :: Parser GenesisParameters
parseGenesisParameters :: Parser GenesisParameters
parseGenesisParameters =
  UTCTime
-> String
-> BlockCount
-> ProtocolMagic
-> TestnetBalanceOptions
-> FakeAvvmOptions
-> EntropicPortion
-> Maybe Integer
-> GenesisParameters
GenesisParameters
    (UTCTime
 -> String
 -> BlockCount
 -> ProtocolMagic
 -> TestnetBalanceOptions
 -> FakeAvvmOptions
 -> EntropicPortion
 -> Maybe Integer
 -> GenesisParameters)
-> Parser UTCTime
-> Parser
     (String
      -> BlockCount
      -> ProtocolMagic
      -> TestnetBalanceOptions
      -> FakeAvvmOptions
      -> EntropicPortion
      -> 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
   -> EntropicPortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser String
-> Parser
     (BlockCount
      -> ProtocolMagic
      -> TestnetBalanceOptions
      -> FakeAvvmOptions
      -> EntropicPortion
      -> 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
   -> EntropicPortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser BlockCount
-> Parser
     (ProtocolMagic
      -> TestnetBalanceOptions
      -> FakeAvvmOptions
      -> EntropicPortion
      -> Maybe Integer
      -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser BlockCount
parseK
    Parser
  (ProtocolMagic
   -> TestnetBalanceOptions
   -> FakeAvvmOptions
   -> EntropicPortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser ProtocolMagic
-> Parser
     (TestnetBalanceOptions
      -> FakeAvvmOptions
      -> EntropicPortion
      -> Maybe Integer
      -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ProtocolMagic
parseProtocolMagic
    Parser
  (TestnetBalanceOptions
   -> FakeAvvmOptions
   -> EntropicPortion
   -> Maybe Integer
   -> GenesisParameters)
-> Parser TestnetBalanceOptions
-> Parser
     (FakeAvvmOptions
      -> EntropicPortion -> Maybe Integer -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TestnetBalanceOptions
parseTestnetBalanceOptions
    Parser
  (FakeAvvmOptions
   -> EntropicPortion -> Maybe Integer -> GenesisParameters)
-> Parser FakeAvvmOptions
-> Parser (EntropicPortion -> Maybe Integer -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FakeAvvmOptions
parseFakeAvvmOptions
    Parser (EntropicPortion -> Maybe Integer -> GenesisParameters)
-> Parser EntropicPortion
-> Parser (Maybe Integer -> GenesisParameters)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> EntropicPortion
rationalToEntropicPortion (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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 ColeCommand
parseGenesisRelatedValues :: Mod CommandFields ColeCommand
parseGenesisRelatedValues =
  [Mod CommandFields ColeCommand] -> Mod CommandFields ColeCommand
forall a. Monoid a => [a] -> a
mconcat
    [ String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command' String
"genesis" String
"Create genesis."
      (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ NewDirectory -> GenesisParameters -> ColeCommand
Genesis
          (NewDirectory -> GenesisParameters -> ColeCommand)
-> Parser NewDirectory -> Parser (GenesisParameters -> ColeCommand)
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 -> ColeCommand)
-> Parser GenesisParameters -> Parser ColeCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser GenesisParameters
parseGenesisParameters
    , String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command' String
"print-genesis-hash" String
"Compute hash of a genesis file."
        (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ GenesisFile -> ColeCommand
PrintGenesisHash
            (GenesisFile -> ColeCommand)
-> Parser GenesisFile -> Parser ColeCommand
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 ColeCommand
parseKeyRelatedValues :: Mod CommandFields ColeCommand
parseKeyRelatedValues =
    [Mod CommandFields ColeCommand] -> Mod CommandFields ColeCommand
forall a. Monoid a => [a] -> a
mconcat
        [ String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command' String
"keygen" String
"Generate a signing key."
            (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ NewSigningKeyFile -> ColeCommand
Keygen
                (NewSigningKeyFile -> ColeCommand)
-> Parser NewSigningKeyFile -> Parser ColeCommand
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser NewSigningKeyFile
parseNewSigningKeyFile String
"secret"
        , String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
            String
"to-verification"
            String
"Extract a verification key in its base64 form."
            (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ ColeKeyFormat
-> SigningKeyFile -> NewVerificationKeyFile -> ColeCommand
ToVerification
                (ColeKeyFormat
 -> SigningKeyFile -> NewVerificationKeyFile -> ColeCommand)
-> Parser ColeKeyFormat
-> Parser (SigningKeyFile -> NewVerificationKeyFile -> ColeCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ColeKeyFormat
parseColeKeyFormat
                Parser (SigningKeyFile -> NewVerificationKeyFile -> ColeCommand)
-> Parser SigningKeyFile
-> Parser (NewVerificationKeyFile -> ColeCommand)
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 -> ColeCommand)
-> Parser NewVerificationKeyFile -> Parser ColeCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewVerificationKeyFile
parseNewVerificationKeyFile String
"to"
        , String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ ColeKeyFormat -> SigningKeyFile -> ColeCommand
PrettySigningKeyPublic
                (ColeKeyFormat -> SigningKeyFile -> ColeCommand)
-> Parser ColeKeyFormat -> Parser (SigningKeyFile -> ColeCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ColeKeyFormat
parseColeKeyFormat
                Parser (SigningKeyFile -> ColeCommand)
-> Parser SigningKeyFile -> Parser ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
            String
"signing-key-address"
            String
"Print address of a signing key."
            (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ ColeKeyFormat -> NetworkId -> SigningKeyFile -> ColeCommand
PrintSigningKeyAddress
                (ColeKeyFormat -> NetworkId -> SigningKeyFile -> ColeCommand)
-> Parser ColeKeyFormat
-> Parser (NetworkId -> SigningKeyFile -> ColeCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser ColeKeyFormat
parseColeKeyFormat
                Parser (NetworkId -> SigningKeyFile -> ColeCommand)
-> Parser NetworkId -> Parser (SigningKeyFile -> ColeCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser NetworkId
pNetworkId
                Parser (SigningKeyFile -> ColeCommand)
-> Parser SigningKeyFile -> Parser ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ SigningKeyFile -> NewSigningKeyFile -> ColeCommand
MigrateDelegateKeyFrom
                (SigningKeyFile -> NewSigningKeyFile -> ColeCommand)
-> Parser SigningKeyFile
-> Parser (NewSigningKeyFile -> ColeCommand)
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 -> ColeCommand)
-> Parser NewSigningKeyFile -> Parser ColeCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewSigningKeyFile
parseNewSigningKeyFile String
"to"
        ]

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

parseMiscellaneous :: Mod CommandFields ColeCommand
parseMiscellaneous :: Mod CommandFields ColeCommand
parseMiscellaneous = [Mod CommandFields ColeCommand] -> Mod CommandFields ColeCommand
forall a. Monoid a => [a] -> a
mconcat
  [ String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
      String
"validate-cbor"
      String
"Validate a CBOR blockchain object."
      (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ CBORObject -> String -> ColeCommand
ValidateCBOR
          (CBORObject -> String -> ColeCommand)
-> Parser CBORObject -> Parser (String -> ColeCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser CBORObject
parseCBORObject
          Parser (String -> ColeCommand)
-> Parser String -> Parser ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
      String
"pretty-print-cbor"
      String
"Pretty print a CBOR file."
      (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ String -> ColeCommand
PrettyPrintCBOR
          (String -> ColeCommand) -> Parser String -> Parser ColeCommand
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 -> Entropic -> Rational -> TestnetBalanceOptions
TestnetBalanceOptions
    (Word -> Word -> Entropic -> Rational -> TestnetBalanceOptions)
-> Parser Word
-> Parser (Word -> Entropic -> 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 -> Entropic -> Rational -> TestnetBalanceOptions)
-> Parser Word
-> Parser (Entropic -> 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 (Entropic -> Rational -> TestnetBalanceOptions)
-> Parser Entropic -> Parser (Rational -> TestnetBalanceOptions)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser Entropic
parseEntropic
          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 ColeEra)
parseTxOut :: Parser (TxOut ColeEra)
parseTxOut =
  ReadM (TxOut ColeEra)
-> Mod OptionFields (TxOut ColeEra) -> Parser (TxOut ColeEra)
forall a. ReadM a -> Mod OptionFields a -> Parser a
option
    ( (\(Text
addr, Word64
entropic) -> AddressInEra ColeEra
-> TxOutValue ColeEra -> TxOutDatumHash ColeEra -> TxOut ColeEra
forall era.
AddressInEra era
-> TxOutValue era -> TxOutDatumHash era -> TxOut era
TxOut (Text -> AddressInEra ColeEra
pAddressInEra Text
addr)
                                  (Word64 -> TxOutValue ColeEra
pEntropicTxOut Word64
entropic)
                                  TxOutDatumHash ColeEra
forall era. TxOutDatumHash era
TxOutDatumHashNone)
      ((Text, Word64) -> TxOut ColeEra)
-> ReadM (Text, Word64) -> ReadM (TxOut ColeEra)
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 ColeEra) -> Parser (TxOut ColeEra))
-> Mod OptionFields (TxOut ColeEra) -> Parser (TxOut ColeEra)
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields (TxOut ColeEra)
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"txout"
      Mod OptionFields (TxOut ColeEra)
-> Mod OptionFields (TxOut ColeEra)
-> Mod OptionFields (TxOut ColeEra)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (TxOut ColeEra)
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"'(\"ADDR\", ENTROPIC)'"
      Mod OptionFields (TxOut ColeEra)
-> Mod OptionFields (TxOut ColeEra)
-> Mod OptionFields (TxOut ColeEra)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (TxOut ColeEra)
forall (f :: * -> *) a. String -> Mod f a
help String
"Specify a transaction output, as a pair of an address and entropic."
 where
  pAddressInEra :: Text -> AddressInEra ColeEra
  pAddressInEra :: Text -> AddressInEra ColeEra
pAddressInEra Text
t =
    case Text -> Either DecoderError Address
decodeAddressBase58 Text
t of
      Left DecoderError
err -> Text -> AddressInEra ColeEra
forall a. HasCallStack => Text -> a
panic (Text -> AddressInEra ColeEra) -> Text -> AddressInEra ColeEra
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
coleAddress -> AddressTypeInEra ColeAddr ColeEra
-> Address ColeAddr -> AddressInEra ColeEra
forall addrtype era.
AddressTypeInEra addrtype era
-> Address addrtype -> AddressInEra era
AddressInEra AddressTypeInEra ColeAddr ColeEra
forall era. AddressTypeInEra ColeAddr era
ColeAddressInAnyEra (Address ColeAddr -> AddressInEra ColeEra)
-> Address ColeAddr -> AddressInEra ColeEra
forall a b. (a -> b) -> a -> b
$ Address -> Address ColeAddr
ColeAddress Address
coleAddress

  pEntropicTxOut :: Word64 -> TxOutValue ColeEra
  pEntropicTxOut :: Word64 -> TxOutValue ColeEra
pEntropicTxOut 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 ColeEra
forall a. HasCallStack => Text -> a
panic (Text -> TxOutValue ColeEra) -> Text -> TxOutValue ColeEra
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
" entropic exceeds the Word64 upper bound"
    else OnlyBccSupportedInEra ColeEra -> Entropic -> TxOutValue ColeEra
forall era. OnlyBccSupportedInEra era -> Entropic -> TxOutValue era
TxOutBccOnly OnlyBccSupportedInEra ColeEra
BccOnlyInColeEra (Entropic -> TxOutValue ColeEra)
-> (Integer -> Entropic) -> Integer -> TxOutValue ColeEra
forall k (cat :: k -> k -> *) (b :: k) (c :: k) (a :: k).
Category cat =>
cat b c -> cat a b -> cat a c
. Integer -> Entropic
Entropic (Integer -> TxOutValue ColeEra) -> Integer -> TxOutValue ColeEra
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 ColeCommand
parseTxRelatedValues :: Mod CommandFields ColeCommand
parseTxRelatedValues =
  [Mod CommandFields ColeCommand] -> Mod CommandFields ColeCommand
forall a. Monoid a => [a] -> a
mconcat
    [ String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ NetworkId -> TxFile -> ColeCommand
SubmitTx
            (NetworkId -> TxFile -> ColeCommand)
-> Parser NetworkId -> Parser (TxFile -> ColeCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
            Parser (TxFile -> ColeCommand)
-> Parser TxFile -> Parser ColeCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser TxFile
parseTxFile String
"tx"
    , String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ GenesisFile
-> NetworkId
-> ColeKeyFormat
-> NewTxFile
-> SigningKeyFile
-> Address ColeAddr
-> [TxOut ColeEra]
-> ColeCommand
SpendGenesisUTxO
            (GenesisFile
 -> NetworkId
 -> ColeKeyFormat
 -> NewTxFile
 -> SigningKeyFile
 -> Address ColeAddr
 -> [TxOut ColeEra]
 -> ColeCommand)
-> Parser GenesisFile
-> Parser
     (NetworkId
      -> ColeKeyFormat
      -> NewTxFile
      -> SigningKeyFile
      -> Address ColeAddr
      -> [TxOut ColeEra]
      -> ColeCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> Parser GenesisFile
parseGenesisFile String
"genesis-json"
            Parser
  (NetworkId
   -> ColeKeyFormat
   -> NewTxFile
   -> SigningKeyFile
   -> Address ColeAddr
   -> [TxOut ColeEra]
   -> ColeCommand)
-> Parser NetworkId
-> Parser
     (ColeKeyFormat
      -> NewTxFile
      -> SigningKeyFile
      -> Address ColeAddr
      -> [TxOut ColeEra]
      -> ColeCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser NetworkId
pNetworkId
            Parser
  (ColeKeyFormat
   -> NewTxFile
   -> SigningKeyFile
   -> Address ColeAddr
   -> [TxOut ColeEra]
   -> ColeCommand)
-> Parser ColeKeyFormat
-> Parser
     (NewTxFile
      -> SigningKeyFile
      -> Address ColeAddr
      -> [TxOut ColeEra]
      -> ColeCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ColeKeyFormat
parseColeKeyFormat
            Parser
  (NewTxFile
   -> SigningKeyFile
   -> Address ColeAddr
   -> [TxOut ColeEra]
   -> ColeCommand)
-> Parser NewTxFile
-> Parser
     (SigningKeyFile
      -> Address ColeAddr -> [TxOut ColeEra] -> ColeCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewTxFile
parseNewTxFile String
"tx"
            Parser
  (SigningKeyFile
   -> Address ColeAddr -> [TxOut ColeEra] -> ColeCommand)
-> Parser SigningKeyFile
-> Parser (Address ColeAddr -> [TxOut ColeEra] -> ColeCommand)
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 ColeAddr -> [TxOut ColeEra] -> ColeCommand)
-> Parser (Address ColeAddr)
-> Parser ([TxOut ColeEra] -> ColeCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser (Address ColeAddr)
parseAddress
                  String
"rich-addr-from"
                  String
"Tx source: genesis UTxO richman address (non-HD)."
            Parser ([TxOut ColeEra] -> ColeCommand)
-> Parser [TxOut ColeEra] -> Parser ColeCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (TxOut ColeEra) -> Parser [TxOut ColeEra]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser (TxOut ColeEra)
parseTxOut

    , String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
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 ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ NetworkId
-> ColeKeyFormat
-> NewTxFile
-> SigningKeyFile
-> [TxIn]
-> [TxOut ColeEra]
-> ColeCommand
SpendUTxO
            (NetworkId
 -> ColeKeyFormat
 -> NewTxFile
 -> SigningKeyFile
 -> [TxIn]
 -> [TxOut ColeEra]
 -> ColeCommand)
-> Parser NetworkId
-> Parser
     (ColeKeyFormat
      -> NewTxFile
      -> SigningKeyFile
      -> [TxIn]
      -> [TxOut ColeEra]
      -> ColeCommand)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
            Parser
  (ColeKeyFormat
   -> NewTxFile
   -> SigningKeyFile
   -> [TxIn]
   -> [TxOut ColeEra]
   -> ColeCommand)
-> Parser ColeKeyFormat
-> Parser
     (NewTxFile
      -> SigningKeyFile -> [TxIn] -> [TxOut ColeEra] -> ColeCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ColeKeyFormat
parseColeKeyFormat
            Parser
  (NewTxFile
   -> SigningKeyFile -> [TxIn] -> [TxOut ColeEra] -> ColeCommand)
-> Parser NewTxFile
-> Parser
     (SigningKeyFile -> [TxIn] -> [TxOut ColeEra] -> ColeCommand)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> Parser NewTxFile
parseNewTxFile String
"tx"
            Parser (SigningKeyFile -> [TxIn] -> [TxOut ColeEra] -> ColeCommand)
-> Parser SigningKeyFile
-> Parser ([TxIn] -> [TxOut ColeEra] -> ColeCommand)
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 ColeEra] -> ColeCommand)
-> Parser [TxIn] -> Parser ([TxOut ColeEra] -> ColeCommand)
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 ColeEra] -> ColeCommand)
-> Parser [TxOut ColeEra] -> Parser ColeCommand
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser (TxOut ColeEra) -> Parser [TxOut ColeEra]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some Parser (TxOut ColeEra)
parseTxOut

    , String
-> String -> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a. String -> String -> Parser a -> Mod CommandFields a
command'
        String
"txid"
        String
"Print the txid of a raw, signed transaction."
        (Parser ColeCommand -> Mod CommandFields ColeCommand)
-> Parser ColeCommand -> Mod CommandFields ColeCommand
forall a b. (a -> b) -> a -> b
$ TxFile -> ColeCommand
GetTxId
            (TxFile -> ColeCommand) -> Parser TxFile -> Parser ColeCommand
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
parseColeUpdateProposal (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
parseColeVote (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
parseColeUpdateProposalSubmission (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
parseColeVoteSubmission (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.")
      ]

parseColeUpdateProposal :: Parser NodeCmd
parseColeUpdateProposal :: Parser NodeCmd
parseColeUpdateProposal = do
  NetworkId
-> SigningKeyFile
-> ProtocolVersion
-> SoftwareVersion
-> SystemTag
-> InstallerHash
-> String
-> ColeProtocolParametersUpdate
-> NodeCmd
UpdateProposal
    (NetworkId
 -> SigningKeyFile
 -> ProtocolVersion
 -> SoftwareVersion
 -> SystemTag
 -> InstallerHash
 -> String
 -> ColeProtocolParametersUpdate
 -> NodeCmd)
-> Parser NetworkId
-> Parser
     (SigningKeyFile
      -> ProtocolVersion
      -> SoftwareVersion
      -> SystemTag
      -> InstallerHash
      -> String
      -> ColeProtocolParametersUpdate
      -> NodeCmd)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NetworkId
pNetworkId
    Parser
  (SigningKeyFile
   -> ProtocolVersion
   -> SoftwareVersion
   -> SystemTag
   -> InstallerHash
   -> String
   -> ColeProtocolParametersUpdate
   -> NodeCmd)
-> Parser SigningKeyFile
-> Parser
     (ProtocolVersion
      -> SoftwareVersion
      -> SystemTag
      -> InstallerHash
      -> String
      -> ColeProtocolParametersUpdate
      -> 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
   -> ColeProtocolParametersUpdate
   -> NodeCmd)
-> Parser ProtocolVersion
-> Parser
     (SoftwareVersion
      -> SystemTag
      -> InstallerHash
      -> String
      -> ColeProtocolParametersUpdate
      -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ProtocolVersion
parseProtocolVersion
    Parser
  (SoftwareVersion
   -> SystemTag
   -> InstallerHash
   -> String
   -> ColeProtocolParametersUpdate
   -> NodeCmd)
-> Parser SoftwareVersion
-> Parser
     (SystemTag
      -> InstallerHash
      -> String
      -> ColeProtocolParametersUpdate
      -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SoftwareVersion
parseSoftwareVersion
    Parser
  (SystemTag
   -> InstallerHash
   -> String
   -> ColeProtocolParametersUpdate
   -> NodeCmd)
-> Parser SystemTag
-> Parser
     (InstallerHash
      -> String -> ColeProtocolParametersUpdate -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SystemTag
parseSystemTag
    Parser
  (InstallerHash
   -> String -> ColeProtocolParametersUpdate -> NodeCmd)
-> Parser InstallerHash
-> Parser (String -> ColeProtocolParametersUpdate -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser InstallerHash
parseInstallerHash
    Parser (String -> ColeProtocolParametersUpdate -> NodeCmd)
-> Parser String
-> Parser (ColeProtocolParametersUpdate -> NodeCmd)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser String
parseFilePath String
"filepath" String
"Cole proposal output filepath."
    Parser (ColeProtocolParametersUpdate -> NodeCmd)
-> Parser ColeProtocolParametersUpdate -> Parser NodeCmd
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ColeProtocolParametersUpdate
pColeProtocolParametersUpdate

parseColeVoteSubmission :: Parser NodeCmd
parseColeVoteSubmission :: Parser NodeCmd
parseColeVoteSubmission = 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 Cole update proposal vote."


pColeProtocolParametersUpdate :: Parser ColeProtocolParametersUpdate
pColeProtocolParametersUpdate :: Parser ColeProtocolParametersUpdate
pColeProtocolParametersUpdate =
  Maybe Word16
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe Natural
-> Maybe EntropicPortion
-> Maybe EntropicPortion
-> Maybe EntropicPortion
-> Maybe EntropicPortion
-> Maybe SlotNumber
-> Maybe SoftforkRule
-> Maybe TxFeePolicy
-> Maybe EpochNumber
-> ColeProtocolParametersUpdate
ColeProtocolParametersUpdate
    (Maybe Word16
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe Natural
 -> Maybe EntropicPortion
 -> Maybe EntropicPortion
 -> Maybe EntropicPortion
 -> Maybe EntropicPortion
 -> Maybe SlotNumber
 -> Maybe SoftforkRule
 -> Maybe TxFeePolicy
 -> Maybe EpochNumber
 -> ColeProtocolParametersUpdate)
-> Parser (Maybe Word16)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
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 EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
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 EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe Natural
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
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 EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe Natural
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
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 EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe Natural
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
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 EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe Natural)
-> Parser
     (Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
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 EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe EntropicPortion)
-> Parser
     (Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser EntropicPortion -> Parser (Maybe EntropicPortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser EntropicPortion
parseMpcThd
    Parser
  (Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe EntropicPortion)
-> Parser
     (Maybe EntropicPortion
      -> Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser EntropicPortion -> Parser (Maybe EntropicPortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser EntropicPortion
parseHeavyDelThd
    Parser
  (Maybe EntropicPortion
   -> Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe EntropicPortion)
-> Parser
     (Maybe EntropicPortion
      -> Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser EntropicPortion -> Parser (Maybe EntropicPortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser EntropicPortion
parseUpdateVoteThd
    Parser
  (Maybe EntropicPortion
   -> Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe EntropicPortion)
-> Parser
     (Maybe SlotNumber
      -> Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser EntropicPortion -> Parser (Maybe EntropicPortion)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser EntropicPortion
parseUpdateProposalThd
    Parser
  (Maybe SlotNumber
   -> Maybe SoftforkRule
   -> Maybe TxFeePolicy
   -> Maybe EpochNumber
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe SlotNumber)
-> Parser
     (Maybe SoftforkRule
      -> Maybe TxFeePolicy
      -> Maybe EpochNumber
      -> ColeProtocolParametersUpdate)
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
   -> ColeProtocolParametersUpdate)
-> Parser (Maybe SoftforkRule)
-> Parser
     (Maybe TxFeePolicy
      -> Maybe EpochNumber -> ColeProtocolParametersUpdate)
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 -> ColeProtocolParametersUpdate)
-> Parser (Maybe TxFeePolicy)
-> Parser (Maybe EpochNumber -> ColeProtocolParametersUpdate)
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 -> ColeProtocolParametersUpdate)
-> Parser (Maybe EpochNumber)
-> Parser ColeProtocolParametersUpdate
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

parseColeUpdateProposalSubmission :: Parser NodeCmd
parseColeUpdateProposalSubmission :: Parser NodeCmd
parseColeUpdateProposalSubmission =
  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 Cole update proposal."


parseColeVote :: Parser NodeCmd
parseColeVote :: Parser NodeCmd
parseColeVote =
  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 Cole 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
"Cole 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 Cole.EntropicPortion
parseMpcThd :: Parser EntropicPortion
parseMpcThd =
  Rational -> EntropicPortion
rationalToEntropicPortion
    (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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 -> ProtocolVersion
ProtocolVersion (Word16 -> Word16 -> ProtocolVersion)
-> Parser Word16 -> Parser (Word16 -> 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 -> ProtocolVersion)
-> Parser Word16 -> Parser 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 sentry." String
"WORD16" :: Parser Word16)

parseHeavyDelThd :: Parser Cole.EntropicPortion
parseHeavyDelThd :: Parser EntropicPortion
parseHeavyDelThd =
  Rational -> EntropicPortion
rationalToEntropicPortion
    (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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 Cole.EntropicPortion
parseUpdateVoteThd :: Parser EntropicPortion
parseUpdateVoteThd =
  Rational -> EntropicPortion
rationalToEntropicPortion
    (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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 Cole.EntropicPortion
parseUpdateProposalThd :: Parser EntropicPortion
parseUpdateProposalThd =
  Rational -> EntropicPortion
rationalToEntropicPortion
    (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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 =
  EntropicPortion
-> EntropicPortion -> EntropicPortion -> SoftforkRule
SoftforkRule
    (EntropicPortion
 -> EntropicPortion -> EntropicPortion -> SoftforkRule)
-> Parser EntropicPortion
-> Parser (EntropicPortion -> EntropicPortion -> SoftforkRule)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Rational -> EntropicPortion
rationalToEntropicPortion (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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 (EntropicPortion -> EntropicPortion -> SoftforkRule)
-> Parser EntropicPortion
-> Parser (EntropicPortion -> SoftforkRule)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> EntropicPortion
rationalToEntropicPortion (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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 (EntropicPortion -> SoftforkRule)
-> Parser EntropicPortion -> Parser SoftforkRule
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Rational -> EntropicPortion
rationalToEntropicPortion (Rational -> EntropicPortion)
-> Parser Rational -> Parser EntropicPortion
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
<$> ( Entropic -> Rational -> TxSizeLinear
TxSizeLinear (Entropic -> Rational -> TxSizeLinear)
-> Parser Entropic -> Parser (Rational -> TxSizeLinear)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> String -> Parser Entropic
parseEntropic 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 ColeAddr)
parseAddress :: String -> String -> Parser (Address ColeAddr)
parseAddress String
opt String
desc =
  ReadM (Address ColeAddr)
-> Mod OptionFields (Address ColeAddr) -> Parser (Address ColeAddr)
forall a. ReadM a -> Mod OptionFields a -> Parser a
option (Text -> Address ColeAddr
cliParseBase58Address (Text -> Address ColeAddr)
-> ReadM Text -> ReadM (Address ColeAddr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ReadM Text
forall s. IsString s => ReadM s
str)
    (Mod OptionFields (Address ColeAddr) -> Parser (Address ColeAddr))
-> Mod OptionFields (Address ColeAddr) -> Parser (Address ColeAddr)
forall a b. (a -> b) -> a -> b
$ String -> Mod OptionFields (Address ColeAddr)
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
opt Mod OptionFields (Address ColeAddr)
-> Mod OptionFields (Address ColeAddr)
-> Mod OptionFields (Address ColeAddr)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (Address ColeAddr)
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"ADDR" Mod OptionFields (Address ColeAddr)
-> Mod OptionFields (Address ColeAddr)
-> Mod OptionFields (Address ColeAddr)
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields (Address ColeAddr)
forall (f :: * -> *) a. String -> Mod f a
help String
desc

parseColeKeyFormat :: Parser ColeKeyFormat
parseColeKeyFormat :: Parser ColeKeyFormat
parseColeKeyFormat = [Parser ColeKeyFormat] -> Parser ColeKeyFormat
forall (t :: * -> *) (f :: * -> *) a.
(Foldable t, Alternative f) =>
t (f a) -> f a
asum
  [ ColeKeyFormat
-> Mod FlagFields ColeKeyFormat -> Parser ColeKeyFormat
forall a. a -> Mod FlagFields a -> Parser a
flag' ColeKeyFormat
LegacyColeKeyFormat (Mod FlagFields ColeKeyFormat -> Parser ColeKeyFormat)
-> Mod FlagFields ColeKeyFormat -> Parser ColeKeyFormat
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields ColeKeyFormat
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"cole-legacy-formats"
     Mod FlagFields ColeKeyFormat
-> Mod FlagFields ColeKeyFormat -> Mod FlagFields ColeKeyFormat
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ColeKeyFormat
forall (f :: * -> *) a. String -> Mod f a
help String
"Cole/bcc-sl formats and compatibility"

  , ColeKeyFormat
-> Mod FlagFields ColeKeyFormat -> Parser ColeKeyFormat
forall a. a -> Mod FlagFields a -> Parser a
flag' ColeKeyFormat
NonLegacyColeKeyFormat (Mod FlagFields ColeKeyFormat -> Parser ColeKeyFormat)
-> Mod FlagFields ColeKeyFormat -> Parser ColeKeyFormat
forall a b. (a -> b) -> a -> b
$
        String -> Mod FlagFields ColeKeyFormat
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
"cole-formats"
     Mod FlagFields ColeKeyFormat
-> Mod FlagFields ColeKeyFormat -> Mod FlagFields ColeKeyFormat
forall a. Semigroup a => a -> a -> a
<> String -> Mod FlagFields ColeKeyFormat
forall (f :: * -> *) a. String -> Mod f a
help String
"Cole era formats and compatibility"

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

  -- Default Cole key format
  , ColeKeyFormat -> Parser ColeKeyFormat
forall (f :: * -> *) a. Applicative f => a -> f a
pure ColeKeyFormat
NonLegacyColeKeyFormat
  ]


parseFakeAvvmOptions :: Parser FakeAvvmOptions
parseFakeAvvmOptions :: Parser FakeAvvmOptions
parseFakeAvvmOptions =
  Word -> Entropic -> FakeAvvmOptions
FakeAvvmOptions
    (Word -> Entropic -> FakeAvvmOptions)
-> Parser Word -> Parser (Entropic -> 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 (Entropic -> FakeAvvmOptions)
-> Parser Entropic -> Parser FakeAvvmOptions
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> String -> String -> Parser Entropic
parseEntropic 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 Shardagnostic 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 Bcc."

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 ColeAddr
cliParseBase58Address :: Text -> Address ColeAddr
cliParseBase58Address Text
t =
  case Text -> Either DecoderError Address
decodeAddressBase58 Text
t of
    Left DecoderError
err -> Text -> Address ColeAddr
forall a. HasCallStack => Text -> a
panic (Text -> Address ColeAddr) -> Text -> Address ColeAddr
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
coleAddress -> Address -> Address ColeAddr
ColeAddress Address
coleAddress

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

parseEntropic :: String -> String -> Parser Cole.Entropic
parseEntropic :: String -> String -> Parser Entropic
parseEntropic String
optname String
desc =
  ReadM Entropic -> Mod OptionFields Entropic -> Parser Entropic
forall a. ReadM a -> Mod OptionFields a -> Parser a
Opt.option (Parser Entropic -> ReadM Entropic
forall a. Parser a -> ReadM a
readerFromAttoParser Parser Entropic
parseEntropicAtto)
    (  String -> Mod OptionFields Entropic
forall (f :: * -> *) a. HasName f => String -> Mod f a
long String
optname
    Mod OptionFields Entropic
-> Mod OptionFields Entropic -> Mod OptionFields Entropic
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Entropic
forall (f :: * -> *) a. HasMetavar f => String -> Mod f a
metavar String
"INT"
    Mod OptionFields Entropic
-> Mod OptionFields Entropic -> Mod OptionFields Entropic
forall a. Semigroup a => a -> a -> a
<> String -> Mod OptionFields Entropic
forall (f :: * -> *) a. String -> Mod f a
help String
desc
    )
 where
  parseEntropicAtto :: Atto.Parser Cole.Entropic
  parseEntropicAtto :: Parser Entropic
parseEntropicAtto = 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 Entropic
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Parser Entropic) -> String -> Parser Entropic
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
" entropic exceeds the Word64 upper bound"
    else case Entropic -> Maybe Entropic
toColeEntropic (Integer -> Entropic
Entropic Integer
i) of
           Just Entropic
coleEntropic -> Entropic -> Parser Entropic
forall (m :: * -> *) a. Monad m => a -> m a
return Entropic
coleEntropic
           Maybe Entropic
Nothing -> Text -> Parser Entropic
forall a. HasCallStack => Text -> a
panic (Text -> Parser Entropic) -> Text -> Parser Entropic
forall a b. (a -> b) -> a -> b
$ Text
"Error converting entropic: " 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."