-- SPDX-FileCopyrightText: 2021 Oxhead Alpha
-- SPDX-License-Identifier: LicenseRef-MIT-OA

module Morley.Client.Parser
  ( ClientArgs (..)
  , ClientArgsRaw (..)
  , OriginateArgs (..)
  , TransferArgs (..)
  , GetScriptSizeArgs (..)
  , TicketBalanceArgs (..)
  , TransferTicketArgs (..)
  , addressOrAliasOption
  , clientConfigParser
  , morleyClientInfo
  , parserInfo

  , originateArgsOption
  , mbContractFileOption
  , contractNameOption

    -- * Parser utilities
  , baseUrlReader
  ) where

import Options.Applicative
  (ReadM, eitherReader, help, long, metavar, option, short, strOption, subparser, value)
import Options.Applicative qualified as Opt
import Options.Applicative.Help.Pretty (Doc, linebreak)
import Servant.Client (BaseUrl(..), parseBaseUrl)

import Morley.CLI
  (addressOrAliasOption, keyHashOption, mutezOption, parserInfo, someAddressOrAliasOption,
  valueOption)
import Morley.Client.Init
import Morley.Client.RPC.Types (BlockId(HeadId))
import Morley.Michelson.Untyped qualified as U
import Morley.Tezos.Address
import Morley.Tezos.Address.Alias
import Morley.Tezos.Address.Kinds
import Morley.Tezos.Core
import Morley.Tezos.Crypto
import Morley.Util.CLI (mkCLOptionParser, mkCommandParser)
import Morley.Util.Named

data ClientArgs
  = ClientArgs MorleyClientConfig ClientArgsRaw

data ClientArgsRaw where
  Originate :: OriginateArgs -> ClientArgsRaw
  GetScriptSize :: GetScriptSizeArgs -> ClientArgsRaw
  Transfer :: TransferArgs -> ClientArgsRaw
  TransferTicket :: TransferTicketArgs -> ClientArgsRaw
  GetBalance :: L1AddressKind kind => AddressOrAlias kind -> ClientArgsRaw
  GetBlockHeader :: BlockId -> ClientArgsRaw
  GetBlockOperations :: BlockId -> ClientArgsRaw
  TicketBalance :: SomeAddressOrAlias -> TicketBalanceArgs -> ClientArgsRaw
  AllTicketBalances :: ContractAddressOrAlias -> ClientArgsRaw

data OriginateArgs = OriginateArgs
  { OriginateArgs -> Maybe FilePath
oaMbContractFile :: Maybe FilePath
  , OriginateArgs -> ContractAlias
oaContractName   :: ContractAlias
  , OriginateArgs -> Mutez
oaInitialBalance :: Mutez
  , OriginateArgs -> Value
oaInitialStorage :: U.Value
  , OriginateArgs -> AddressOrAlias 'AddressKindImplicit
oaOriginateFrom  :: ImplicitAddressOrAlias
  , OriginateArgs -> Maybe Mutez
oaMbFee :: Maybe Mutez
  , OriginateArgs -> Maybe KeyHash
oaDelegate :: Maybe KeyHash
  }

data GetScriptSizeArgs = GetScriptSizeArgs
  { GetScriptSizeArgs -> FilePath
ssScriptFile :: FilePath
  , GetScriptSizeArgs -> Value
ssStorage    :: U.Value
  }

data TransferArgs = TransferArgs
  { TransferArgs -> AddressOrAlias 'AddressKindImplicit
taSender      :: ImplicitAddressOrAlias
  , TransferArgs -> SomeAddressOrAlias
taDestination :: SomeAddressOrAlias
  , TransferArgs -> Mutez
taAmount      :: Mutez
  , TransferArgs -> Value
taParameter   :: U.Value
  , TransferArgs -> Maybe Mutez
taMbFee :: Maybe Mutez
  }

data TransferTicketArgs = TransferTicketArgs
  { TransferTicketArgs -> AddressOrAlias 'AddressKindImplicit
ttaSender         :: ImplicitAddressOrAlias
  , TransferTicketArgs -> Value
ttaTicketContents :: U.Value
  , TransferTicketArgs -> Ty
ttaTicketType     :: U.Ty
  , TransferTicketArgs -> ContractAddressOrAlias
ttaTicketTicketer :: ContractAddressOrAlias
  , TransferTicketArgs -> Natural
ttaTicketAmount   :: Natural
  , TransferTicketArgs -> SomeAddressOrAlias
ttaDestination    :: SomeAddressOrAlias
  , TransferTicketArgs -> Maybe Mutez
ttaMbFee          :: Maybe Mutez
  }

morleyClientInfo :: Opt.ParserInfo ClientArgs
morleyClientInfo :: ParserInfo ClientArgs
morleyClientInfo =
  ("usage" :! Doc)
-> ("description" :! FilePath)
-> ("header" :! FilePath)
-> ("parser" :! Parser ClientArgs)
-> ParserInfo ClientArgs
forall s.
("usage" :! Doc)
-> ("description" :! FilePath)
-> ("header" :! FilePath)
-> ("parser" :! Parser s)
-> ParserInfo s
parserInfo
    (IsLabel "usage" (Name "usage")
Name "usage"
#usage Name "usage" -> Doc -> "usage" :! Doc
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! Doc
usageDoc)
    (IsLabel "description" (Name "description")
Name "description"
#description Name "description" -> FilePath -> "description" :! FilePath
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Morley Client: RPC client for interaction with tezos node")
    (IsLabel "header" (Name "header")
Name "header"
#header Name "header" -> FilePath -> "header" :! FilePath
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Morley Client")
    (IsLabel "parser" (Name "parser")
Name "parser"
#parser Name "parser" -> Parser ClientArgs -> "parser" :! Parser ClientArgs
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! Parser ClientArgs
clientParser)

-- | Parser for the @morley-client@ executable.
clientParser :: Opt.Parser ClientArgs
clientParser :: Parser ClientArgs
clientParser = MorleyClientConfig -> ClientArgsRaw -> ClientArgs
ClientArgs (MorleyClientConfig -> ClientArgsRaw -> ClientArgs)
-> Parser MorleyClientConfig
-> Parser (ClientArgsRaw -> ClientArgs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser MorleyClientConfig
clientConfigParser Parser (ClientArgsRaw -> ClientArgs)
-> Parser ClientArgsRaw -> Parser ClientArgs
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser ClientArgsRaw
argsRawParser

clientConfigParser :: Opt.Parser MorleyClientConfig
clientConfigParser :: Parser MorleyClientConfig
clientConfigParser = do
  let mccSecretKey :: Maybe a
mccSecretKey = Maybe a
forall a. Maybe a
Nothing
  Maybe BaseUrl
mccEndpointUrl <- Parser (Maybe BaseUrl)
endpointOption
  FilePath
mccTezosClientPath <- Parser FilePath
pathOption
  Maybe FilePath
mccMbTezosClientDataDir <- Parser (Maybe FilePath)
dataDirOption
  Word
mccVerbosity <- [()] -> Word
forall i a. Num i => [a] -> i
genericLength ([()] -> Word) -> Parser [()] -> Parser Word
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser () -> Parser [()]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser ()
verboseSwitch
  pure MorleyClientConfig :: Maybe BaseUrl
-> FilePath
-> Maybe FilePath
-> Word
-> Maybe SecretKey
-> MorleyClientConfig
MorleyClientConfig{FilePath
Maybe FilePath
Maybe BaseUrl
Maybe SecretKey
Word
mccSecretKey :: Maybe SecretKey
mccVerbosity :: Word
mccMbTezosClientDataDir :: Maybe FilePath
mccTezosClientPath :: FilePath
mccEndpointUrl :: Maybe BaseUrl
mccVerbosity :: Word
mccMbTezosClientDataDir :: Maybe FilePath
mccTezosClientPath :: FilePath
mccEndpointUrl :: Maybe BaseUrl
mccSecretKey :: Maybe SecretKey
..}
  where
    verboseSwitch :: Opt.Parser ()
    verboseSwitch :: Parser ()
verboseSwitch = () -> Mod FlagFields () -> Parser ()
forall a. a -> Mod FlagFields a -> Parser a
Opt.flag' () (Mod FlagFields () -> Parser ())
-> ([Mod FlagFields ()] -> Mod FlagFields ())
-> [Mod FlagFields ()]
-> Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Mod FlagFields ()] -> Mod FlagFields ()
forall a. Monoid a => [a] -> a
mconcat ([Mod FlagFields ()] -> Parser ())
-> [Mod FlagFields ()] -> Parser ()
forall a b. (a -> b) -> a -> b
$
      [ Char -> Mod FlagFields ()
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'V'
      , FilePath -> Mod FlagFields ()
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Increase verbosity (pass several times to increase further)."
      ]

-- | Parses URL of the Tezos node.
endpointOption :: Opt.Parser (Maybe BaseUrl)
endpointOption :: Parser (Maybe BaseUrl)
endpointOption = Parser BaseUrl -> Parser (Maybe BaseUrl)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser BaseUrl -> Parser (Maybe BaseUrl))
-> (Mod OptionFields BaseUrl -> Parser BaseUrl)
-> Mod OptionFields BaseUrl
-> Parser (Maybe BaseUrl)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReadM BaseUrl -> Mod OptionFields BaseUrl -> Parser BaseUrl
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ReadM BaseUrl
baseUrlReader (Mod OptionFields BaseUrl -> Parser (Maybe BaseUrl))
-> Mod OptionFields BaseUrl -> Parser (Maybe BaseUrl)
forall a b. (a -> b) -> a -> b
$
  FilePath -> Mod OptionFields BaseUrl
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"endpoint"
  Mod OptionFields BaseUrl
-> Mod OptionFields BaseUrl -> Mod OptionFields BaseUrl
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields BaseUrl
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'E'
  Mod OptionFields BaseUrl
-> Mod OptionFields BaseUrl -> Mod OptionFields BaseUrl
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields BaseUrl
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"URL of the remote Tezos node."
  Mod OptionFields BaseUrl
-> Mod OptionFields BaseUrl -> Mod OptionFields BaseUrl
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields BaseUrl
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"URL"

pathOption :: Opt.Parser FilePath
pathOption :: Parser FilePath
pathOption = Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption (Mod OptionFields FilePath -> Parser FilePath)
-> Mod OptionFields FilePath -> Parser FilePath
forall a b. (a -> b) -> a -> b
$
  [Mod OptionFields FilePath] -> Mod OptionFields FilePath
forall a. Monoid a => [a] -> a
mconcat [ Char -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'I', FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"client-path", FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"PATH"
          , FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Path to `octez-client` binary."
          , FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value FilePath
"octez-client"
          , Mod OptionFields FilePath
forall a (f :: * -> *). Show a => Mod f a
Opt.showDefault
          ]

dataDirOption :: Opt.Parser (Maybe FilePath)
dataDirOption :: Parser (Maybe FilePath)
dataDirOption = Parser FilePath -> Parser (Maybe FilePath)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser FilePath -> Parser (Maybe FilePath))
-> Parser FilePath -> Parser (Maybe FilePath)
forall a b. (a -> b) -> a -> b
$ Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption (Mod OptionFields FilePath -> Parser FilePath)
-> Mod OptionFields FilePath -> Parser FilePath
forall a b. (a -> b) -> a -> b
$
  [Mod OptionFields FilePath] -> Mod OptionFields FilePath
forall a. Monoid a => [a] -> a
mconcat [ Char -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'd', FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"data-dir", FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"PATH"
          , FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Path to `octez-client` data directory."
          ]

feeOption :: Opt.Parser (Maybe Mutez)
feeOption :: Parser (Maybe Mutez)
feeOption = Parser Mutez -> Parser (Maybe Mutez)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser Mutez -> Parser (Maybe Mutez))
-> Parser Mutez -> Parser (Maybe Mutez)
forall a b. (a -> b) -> a -> b
$ Maybe Mutez
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Mutez
mutezOption
            Maybe Mutez
forall a. Maybe a
Nothing
            (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"fee")
            (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Fee that is going to be used for the transaction. \
                      \By default fee will be computed automatically."
            )

data TicketBalanceArgs = TicketBalanceArgs
  { TicketBalanceArgs -> ContractAddress
tbaTicketer :: ContractAddress
  , TicketBalanceArgs -> Value
tbaContent :: U.Value
  , TicketBalanceArgs -> Ty
tbaContentType :: U.Ty
  }

getTicketBalanceOption :: Opt.Parser TicketBalanceArgs
getTicketBalanceOption :: Parser TicketBalanceArgs
getTicketBalanceOption = do
  ContractAddress
tbaTicketer <- Maybe ContractAddress
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser ContractAddress
forall a.
(Buildable a, HasCLReader a) =>
Maybe a
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser a
mkCLOptionParser Maybe ContractAddress
forall a. Maybe a
Nothing
    (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"ticketer")
    (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"The contract that issued the ticket.")
  Ty
tbaContentType <- Maybe Ty
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Ty
forall a.
(Buildable a, HasCLReader a) =>
Maybe a
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser a
mkCLOptionParser Maybe Ty
forall a. Maybe a
Nothing
    (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"content-type")
    (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Content type.")
  Value
tbaContent <- Maybe Value
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Value
valueOption Maybe Value
forall a. Maybe a
Nothing
    (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"content")
    (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Ticket content.")
  pure TicketBalanceArgs :: ContractAddress -> Value -> Ty -> TicketBalanceArgs
TicketBalanceArgs{ContractAddress
Ty
Value
tbaContent :: Value
tbaContentType :: Ty
tbaTicketer :: ContractAddress
tbaContentType :: Ty
tbaContent :: Value
tbaTicketer :: ContractAddress
..}

-- | Generic parser to read an option of 'BlockId' type.
blockIdOption
  :: Maybe BlockId
  -> "name" :! String
  -> "help" :! String
  -> Opt.Parser BlockId
blockIdOption :: Maybe BlockId
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser BlockId
blockIdOption = Maybe BlockId
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser BlockId
forall a.
(Buildable a, HasCLReader a) =>
Maybe a
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser a
mkCLOptionParser

argsRawParser :: Opt.Parser ClientArgsRaw
argsRawParser :: Parser ClientArgsRaw
argsRawParser = Mod CommandFields ClientArgsRaw -> Parser ClientArgsRaw
forall a. Mod CommandFields a -> Parser a
subparser (Mod CommandFields ClientArgsRaw -> Parser ClientArgsRaw)
-> Mod CommandFields ClientArgsRaw -> Parser ClientArgsRaw
forall a b. (a -> b) -> a -> b
$ [Mod CommandFields ClientArgsRaw]
-> Mod CommandFields ClientArgsRaw
forall a. Monoid a => [a] -> a
mconcat
  [ Mod CommandFields ClientArgsRaw
originateCmd
  , Mod CommandFields ClientArgsRaw
transferCmd
  , Mod CommandFields ClientArgsRaw
transferTicketCmd
  , Mod CommandFields ClientArgsRaw
getBalanceCmd
  , Mod CommandFields ClientArgsRaw
getScriptSizeCmd
  , Mod CommandFields ClientArgsRaw
getBlockHeaderCmd
  , Mod CommandFields ClientArgsRaw
getBlockOperationsCmd
  , Mod CommandFields ClientArgsRaw
getTicketBalanceCmd
  , Mod CommandFields ClientArgsRaw
getAllTicketBalancesCmd
  ]
  where
    ownerOption :: (Maybe a
 -> NamedF Identity a "name" -> NamedF Identity a "help" -> t)
-> t
ownerOption Maybe a
-> NamedF Identity a "name" -> NamedF Identity a "help" -> t
f = Maybe a
-> NamedF Identity a "name" -> NamedF Identity a "help" -> t
f
      Maybe a
forall a. Maybe a
Nothing
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> a -> NamedF Identity a "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! a
"owner")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> a -> NamedF Identity a "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! a
"Ticket owner")
    getTicketBalanceCmd :: Mod CommandFields ClientArgsRaw
getTicketBalanceCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"ticket-balance"
      (SomeAddressOrAlias -> TicketBalanceArgs -> ClientArgsRaw
TicketBalance (SomeAddressOrAlias -> TicketBalanceArgs -> ClientArgsRaw)
-> Parser SomeAddressOrAlias
-> Parser (TicketBalanceArgs -> ClientArgsRaw)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe SomeAddressOrAlias
 -> NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help"
 -> Parser SomeAddressOrAlias)
-> Parser SomeAddressOrAlias
forall {a} {a} {a} {t}.
(IsString a, IsString a) =>
(Maybe a
 -> NamedF Identity a "name" -> NamedF Identity a "help" -> t)
-> t
ownerOption Maybe SomeAddressOrAlias
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser SomeAddressOrAlias
someAddressOrAliasOption Parser (TicketBalanceArgs -> ClientArgsRaw)
-> Parser TicketBalanceArgs -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser TicketBalanceArgs
getTicketBalanceOption)
      FilePath
"Get ticket balance for specific tickets"
    getAllTicketBalancesCmd :: Mod CommandFields ClientArgsRaw
getAllTicketBalancesCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"all-ticket-balances"
      (ContractAddressOrAlias -> ClientArgsRaw
AllTicketBalances (ContractAddressOrAlias -> ClientArgsRaw)
-> Parser ContractAddressOrAlias -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Maybe ContractAddressOrAlias
 -> NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help"
 -> Parser ContractAddressOrAlias)
-> Parser ContractAddressOrAlias
forall {a} {a} {a} {t}.
(IsString a, IsString a) =>
(Maybe a
 -> NamedF Identity a "name" -> NamedF Identity a "help" -> t)
-> t
ownerOption Maybe ContractAddressOrAlias
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser ContractAddressOrAlias
forall (kind :: AddressKind).
(SingI kind, L1AddressKind kind) =>
Maybe (AddressOrAlias kind)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias kind)
addressOrAliasOption)
      FilePath
"Get all ticket balances"
    originateCmd :: Mod CommandFields ClientArgsRaw
originateCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"originate"
      (OriginateArgs -> ClientArgsRaw
Originate (OriginateArgs -> ClientArgsRaw)
-> Parser OriginateArgs -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser OriginateArgs
originateArgsOption)
      FilePath
"Originate passed contract on real network."
    transferCmd :: Mod CommandFields ClientArgsRaw
transferCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"transfer"
      (TransferArgs -> ClientArgsRaw
Transfer (TransferArgs -> ClientArgsRaw)
-> Parser TransferArgs -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TransferArgs
transferArgsOption)
      FilePath
"Perform a transfer to the given contract with given amount and parameter."
    transferTicketCmd :: Mod CommandFields ClientArgsRaw
transferTicketCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"transfer-ticket"
      (TransferTicketArgs -> ClientArgsRaw
TransferTicket (TransferTicketArgs -> ClientArgsRaw)
-> Parser TransferTicketArgs -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser TransferTicketArgs
transferTicketArgsOption)
      FilePath
"Perform a ticket transfer to the given contract with given amount and parameter."
    getBalanceCmd :: Mod CommandFields ClientArgsRaw
getBalanceCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"get-balance"
      ((ContractAddressOrAlias -> ClientArgsRaw
forall (kind :: AddressKind).
L1AddressKind kind =>
AddressOrAlias kind -> ClientArgsRaw
GetBalance (ContractAddressOrAlias -> ClientArgsRaw)
-> Parser ContractAddressOrAlias -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        forall (kind :: AddressKind).
(SingI kind, L1AddressKind kind) =>
Maybe (AddressOrAlias kind)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias kind)
addressOrAliasOption @'AddressKindContract
          Maybe ContractAddressOrAlias
forall a. Maybe a
Nothing
          (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"contract-addr")
          (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Contract address or alias to get balance for."))
      Parser ClientArgsRaw
-> Parser ClientArgsRaw -> Parser ClientArgsRaw
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> (AddressOrAlias 'AddressKindImplicit -> ClientArgsRaw
forall (kind :: AddressKind).
L1AddressKind kind =>
AddressOrAlias kind -> ClientArgsRaw
GetBalance (AddressOrAlias 'AddressKindImplicit -> ClientArgsRaw)
-> Parser (AddressOrAlias 'AddressKindImplicit)
-> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (kind :: AddressKind).
(SingI kind, L1AddressKind kind) =>
Maybe (AddressOrAlias kind)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias kind)
addressOrAliasOption @'AddressKindImplicit
          Maybe (AddressOrAlias 'AddressKindImplicit)
forall a. Maybe a
Nothing
          (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"implicit-addr")
          (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Implicit address or alias to get balance for."))
      )
      FilePath
"Get balance for given address"
    getBlockHeaderCmd :: Mod CommandFields ClientArgsRaw
getBlockHeaderCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"get-block-header"
      (BlockId -> ClientArgsRaw
GetBlockHeader (BlockId -> ClientArgsRaw)
-> Parser BlockId -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe BlockId
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser BlockId
blockIdOption
        (BlockId -> Maybe BlockId
forall a. a -> Maybe a
Just BlockId
HeadId)
        (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"block-id")
        (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Id of the block whose header will be queried.")
      )
      FilePath
"Get header of a block"
    getBlockOperationsCmd :: Mod CommandFields ClientArgsRaw
getBlockOperationsCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"get-block-operations"
      (BlockId -> ClientArgsRaw
GetBlockOperations (BlockId -> ClientArgsRaw)
-> Parser BlockId -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe BlockId
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser BlockId
blockIdOption
        (BlockId -> Maybe BlockId
forall a. a -> Maybe a
Just BlockId
HeadId)
        (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"block-id")
        (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Id of the block whose operations will be queried.")
      )
      FilePath
"Get operations contained in a block"
    getScriptSizeCmd :: Mod CommandFields ClientArgsRaw
getScriptSizeCmd =
      FilePath
-> Parser ClientArgsRaw
-> FilePath
-> Mod CommandFields ClientArgsRaw
forall a. FilePath -> Parser a -> FilePath -> Mod CommandFields a
mkCommandParser FilePath
"compute-script-size"
      (GetScriptSizeArgs -> ClientArgsRaw
GetScriptSize (GetScriptSizeArgs -> ClientArgsRaw)
-> Parser GetScriptSizeArgs -> Parser ClientArgsRaw
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser GetScriptSizeArgs
getScriptSizeArgsOption)
      FilePath
"Compute script size"

originateArgsOption :: Opt.Parser OriginateArgs
originateArgsOption :: Parser OriginateArgs
originateArgsOption = do
  Maybe FilePath
oaMbContractFile <- Parser (Maybe FilePath)
mbContractFileOption
  ContractAlias
oaContractName <- Parser ContractAlias
contractNameOption
  Mutez
oaInitialBalance <-
    Maybe Mutez
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Mutez
mutezOption
      (Mutez -> Maybe Mutez
forall a. a -> Maybe a
Just Mutez
zeroMutez)
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"initial-balance")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Inital balance of the contract.")
  Value
oaInitialStorage <-
    Maybe Value
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Value
valueOption
      Maybe Value
forall a. Maybe a
Nothing
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"initial-storage")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Initial contract storage value.")
  AddressOrAlias 'AddressKindImplicit
oaOriginateFrom <-
    Maybe (AddressOrAlias 'AddressKindImplicit)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias 'AddressKindImplicit)
forall (kind :: AddressKind).
(SingI kind, L1AddressKind kind) =>
Maybe (AddressOrAlias kind)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias kind)
addressOrAliasOption
      Maybe (AddressOrAlias 'AddressKindImplicit)
forall a. Maybe a
Nothing
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"from")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Address or alias of address from which origination is performed.")
  Maybe Mutez
oaMbFee <- Parser (Maybe Mutez)
feeOption
  Maybe KeyHash
oaDelegate <- Parser KeyHash -> Parser (Maybe KeyHash)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser KeyHash -> Parser (Maybe KeyHash))
-> Parser KeyHash -> Parser (Maybe KeyHash)
forall a b. (a -> b) -> a -> b
$
    Maybe KeyHash
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser KeyHash
keyHashOption
      Maybe KeyHash
forall a. Maybe a
Nothing
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"delegate")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Key hash of the contract's delegate")
  pure $ OriginateArgs :: Maybe FilePath
-> ContractAlias
-> Mutez
-> Value
-> AddressOrAlias 'AddressKindImplicit
-> Maybe Mutez
-> Maybe KeyHash
-> OriginateArgs
OriginateArgs {Maybe FilePath
Maybe Mutez
Maybe KeyHash
Mutez
AddressOrAlias 'AddressKindImplicit
ContractAlias
Value
oaDelegate :: Maybe KeyHash
oaMbFee :: Maybe Mutez
oaOriginateFrom :: AddressOrAlias 'AddressKindImplicit
oaInitialStorage :: Value
oaInitialBalance :: Mutez
oaContractName :: ContractAlias
oaMbContractFile :: Maybe FilePath
oaDelegate :: Maybe KeyHash
oaMbFee :: Maybe Mutez
oaOriginateFrom :: AddressOrAlias 'AddressKindImplicit
oaInitialStorage :: Value
oaInitialBalance :: Mutez
oaContractName :: ContractAlias
oaMbContractFile :: Maybe FilePath
..}

getScriptSizeArgsOption :: Opt.Parser GetScriptSizeArgs
getScriptSizeArgsOption :: Parser GetScriptSizeArgs
getScriptSizeArgsOption = FilePath -> Value -> GetScriptSizeArgs
GetScriptSizeArgs (FilePath -> Value -> GetScriptSizeArgs)
-> Parser FilePath -> Parser (Value -> GetScriptSizeArgs)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FilePath
scriptFileOption
  Parser (Value -> GetScriptSizeArgs)
-> Parser Value -> Parser GetScriptSizeArgs
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Value
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Value
valueOption Maybe Value
forall a. Maybe a
Nothing (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"storage")
                          (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Contract storage value.")

mbContractFileOption :: Opt.Parser (Maybe FilePath)
mbContractFileOption :: Parser (Maybe FilePath)
mbContractFileOption = Parser FilePath -> Parser (Maybe FilePath)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser FilePath -> Parser (Maybe FilePath))
-> (Mod OptionFields FilePath -> Parser FilePath)
-> Mod OptionFields FilePath
-> Parser (Maybe FilePath)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption (Mod OptionFields FilePath -> Parser (Maybe FilePath))
-> Mod OptionFields FilePath -> Parser (Maybe FilePath)
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields FilePath] -> Mod OptionFields FilePath
forall a. Monoid a => [a] -> a
mconcat
  [ FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"contract", FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILEPATH"
  , FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Path to contract file."
  ]

scriptFileOption :: Opt.Parser FilePath
scriptFileOption :: Parser FilePath
scriptFileOption = Mod OptionFields FilePath -> Parser FilePath
forall s. IsString s => Mod OptionFields s -> Parser s
strOption (Mod OptionFields FilePath -> Parser FilePath)
-> Mod OptionFields FilePath -> Parser FilePath
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields FilePath] -> Mod OptionFields FilePath
forall a. Monoid a => [a] -> a
mconcat
  [ FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"script", FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"FILEPATH"
  , FilePath -> Mod OptionFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Path to script file."
  ]

contractNameOption :: Opt.Parser ContractAlias
contractNameOption :: Parser ContractAlias
contractNameOption = (Text -> ContractAlias) -> Parser Text -> Parser ContractAlias
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Text -> ContractAlias
ContractAlias (Parser Text -> Parser ContractAlias)
-> (Mod OptionFields Text -> Parser Text)
-> Mod OptionFields Text
-> Parser ContractAlias
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mod OptionFields Text -> Parser Text
forall s. IsString s => Mod OptionFields s -> Parser s
strOption (Mod OptionFields Text -> Parser ContractAlias)
-> Mod OptionFields Text -> Parser ContractAlias
forall a b. (a -> b) -> a -> b
$ [Mod OptionFields Text] -> Mod OptionFields Text
forall a. Monoid a => [a] -> a
mconcat
  [ FilePath -> Mod OptionFields Text
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"contract-name"
  , Text -> Mod OptionFields Text
forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Text
"stdin"
  , FilePath -> Mod OptionFields Text
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Alias of originated contract."
  ]

transferArgsOption :: Opt.Parser TransferArgs
transferArgsOption :: Parser TransferArgs
transferArgsOption = do
  AddressOrAlias 'AddressKindImplicit
taSender <-
    Maybe (AddressOrAlias 'AddressKindImplicit)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias 'AddressKindImplicit)
forall (kind :: AddressKind).
(SingI kind, L1AddressKind kind) =>
Maybe (AddressOrAlias kind)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias kind)
addressOrAliasOption
      Maybe (AddressOrAlias 'AddressKindImplicit)
forall a. Maybe a
Nothing
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"from")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Address or alias from which transfer is performed.")
  SomeAddressOrAlias
taDestination <-
    Maybe SomeAddressOrAlias
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser SomeAddressOrAlias
someAddressOrAliasOption
      Maybe SomeAddressOrAlias
forall a. Maybe a
Nothing
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"to")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Address or alias of the transfer's destination.")
  Mutez
taAmount <-
    Maybe Mutez
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Mutez
mutezOption
      (Mutez -> Maybe Mutez
forall a. a -> Maybe a
Just Mutez
zeroMutez)
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"amount")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Transfer amount.")
  Value
taParameter <-
    Maybe Value
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Value
valueOption
      Maybe Value
forall a. Maybe a
Nothing
      (IsLabel "name" (Name "name")
Name "name"
#name Name "name" -> FilePath -> NamedF Identity FilePath "name"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"parameter")
      (IsLabel "help" (Name "help")
Name "help"
#help Name "help" -> FilePath -> NamedF Identity FilePath "help"
forall (name :: Symbol) a. Name name -> a -> NamedF Identity a name
:! FilePath
"Transfer parameter.")
  Maybe Mutez
taMbFee <- Parser (Maybe Mutez)
feeOption
  pure $ TransferArgs :: AddressOrAlias 'AddressKindImplicit
-> SomeAddressOrAlias
-> Mutez
-> Value
-> Maybe Mutez
-> TransferArgs
TransferArgs {Maybe Mutez
Mutez
AddressOrAlias 'AddressKindImplicit
SomeAddressOrAlias
Value
taMbFee :: Maybe Mutez
taParameter :: Value
taAmount :: Mutez
taDestination :: SomeAddressOrAlias
taSender :: AddressOrAlias 'AddressKindImplicit
taMbFee :: Maybe Mutez
taParameter :: Value
taAmount :: Mutez
taDestination :: SomeAddressOrAlias
taSender :: AddressOrAlias 'AddressKindImplicit
..}

transferTicketArgsOption :: Opt.Parser TransferTicketArgs
transferTicketArgsOption :: Parser TransferTicketArgs
transferTicketArgsOption = do
  AddressOrAlias 'AddressKindImplicit
ttaSender <- Maybe (AddressOrAlias 'AddressKindImplicit)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias 'AddressKindImplicit)
forall (kind :: AddressKind).
(SingI kind, L1AddressKind kind) =>
Maybe (AddressOrAlias kind)
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias kind)
addressOrAliasOption Maybe (AddressOrAlias 'AddressKindImplicit)
forall a. Maybe a
Nothing
    (NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help"
 -> Parser (AddressOrAlias 'AddressKindImplicit))
-> Param (NamedF Identity FilePath "name")
-> NamedF Identity FilePath "help"
-> Parser (AddressOrAlias 'AddressKindImplicit)
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "name" (FilePath -> Param (NamedF Identity FilePath "name"))
FilePath -> Param (NamedF Identity FilePath "name")
#name FilePath
"from"
    (NamedF Identity FilePath "help"
 -> Parser (AddressOrAlias 'AddressKindImplicit))
-> Param (NamedF Identity FilePath "help")
-> Parser (AddressOrAlias 'AddressKindImplicit)
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "help" (FilePath -> Param (NamedF Identity FilePath "help"))
FilePath -> Param (NamedF Identity FilePath "help")
#help FilePath
"Address or alias from which transfer is performed."
  Natural
ttaTicketAmount <- Maybe Natural
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Natural
forall a.
(Buildable a, HasCLReader a) =>
Maybe a
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser a
mkCLOptionParser Maybe Natural
forall a. Maybe a
Nothing
    (NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help" -> Parser Natural)
-> Param (NamedF Identity FilePath "name")
-> NamedF Identity FilePath "help"
-> Parser Natural
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "name" (FilePath -> Param (NamedF Identity FilePath "name"))
FilePath -> Param (NamedF Identity FilePath "name")
#name FilePath
"amount"
    (NamedF Identity FilePath "help" -> Parser Natural)
-> Param (NamedF Identity FilePath "help") -> Parser Natural
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "help" (FilePath -> Param (NamedF Identity FilePath "help"))
FilePath -> Param (NamedF Identity FilePath "help")
#help FilePath
"Ticket amount."
  Value
ttaTicketContents <- Maybe Value
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Value
forall a.
(Buildable a, HasCLReader a) =>
Maybe a
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser a
mkCLOptionParser Maybe Value
forall a. Maybe a
Nothing
    (NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help" -> Parser Value)
-> Param (NamedF Identity FilePath "name")
-> NamedF Identity FilePath "help"
-> Parser Value
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "name" (FilePath -> Param (NamedF Identity FilePath "name"))
FilePath -> Param (NamedF Identity FilePath "name")
#name FilePath
"value"
    (NamedF Identity FilePath "help" -> Parser Value)
-> Param (NamedF Identity FilePath "help") -> Parser Value
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "help" (FilePath -> Param (NamedF Identity FilePath "help"))
FilePath -> Param (NamedF Identity FilePath "help")
#help FilePath
"Ticket value."
  Ty
ttaTicketType <- Maybe Ty
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser Ty
forall a.
(Buildable a, HasCLReader a) =>
Maybe a
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser a
mkCLOptionParser Maybe Ty
forall a. Maybe a
Nothing
    (NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help" -> Parser Ty)
-> Param (NamedF Identity FilePath "name")
-> NamedF Identity FilePath "help"
-> Parser Ty
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "name" (FilePath -> Param (NamedF Identity FilePath "name"))
FilePath -> Param (NamedF Identity FilePath "name")
#name FilePath
"type"
    (NamedF Identity FilePath "help" -> Parser Ty)
-> Param (NamedF Identity FilePath "help") -> Parser Ty
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "help" (FilePath -> Param (NamedF Identity FilePath "help"))
FilePath -> Param (NamedF Identity FilePath "help")
#help FilePath
"Ticket type."
  ContractAddressOrAlias
ttaTicketTicketer <- Maybe ContractAddressOrAlias
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser ContractAddressOrAlias
forall a.
(Buildable a, HasCLReader a) =>
Maybe a
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser a
mkCLOptionParser Maybe ContractAddressOrAlias
forall a. Maybe a
Nothing
    (NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help"
 -> Parser ContractAddressOrAlias)
-> Param (NamedF Identity FilePath "name")
-> NamedF Identity FilePath "help"
-> Parser ContractAddressOrAlias
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "name" (FilePath -> Param (NamedF Identity FilePath "name"))
FilePath -> Param (NamedF Identity FilePath "name")
#name FilePath
"ticketer"
    (NamedF Identity FilePath "help" -> Parser ContractAddressOrAlias)
-> Param (NamedF Identity FilePath "help")
-> Parser ContractAddressOrAlias
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "help" (FilePath -> Param (NamedF Identity FilePath "help"))
FilePath -> Param (NamedF Identity FilePath "help")
#help FilePath
"Ticketer address or alias."
  SomeAddressOrAlias
ttaDestination <- Maybe SomeAddressOrAlias
-> NamedF Identity FilePath "name"
-> NamedF Identity FilePath "help"
-> Parser SomeAddressOrAlias
someAddressOrAliasOption Maybe SomeAddressOrAlias
forall a. Maybe a
Nothing
    (NamedF Identity FilePath "name"
 -> NamedF Identity FilePath "help" -> Parser SomeAddressOrAlias)
-> Param (NamedF Identity FilePath "name")
-> NamedF Identity FilePath "help"
-> Parser SomeAddressOrAlias
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "name" (FilePath -> Param (NamedF Identity FilePath "name"))
FilePath -> Param (NamedF Identity FilePath "name")
#name FilePath
"to"
    (NamedF Identity FilePath "help" -> Parser SomeAddressOrAlias)
-> Param (NamedF Identity FilePath "help")
-> Parser SomeAddressOrAlias
forall p fn fn'. WithParam p fn fn' => fn -> Param p -> fn'
! IsLabel
  "help" (FilePath -> Param (NamedF Identity FilePath "help"))
FilePath -> Param (NamedF Identity FilePath "help")
#help FilePath
"Address or alias of the transfer's destination."
  Maybe Mutez
ttaMbFee <- Parser (Maybe Mutez)
feeOption
  pure $ TransferTicketArgs :: AddressOrAlias 'AddressKindImplicit
-> Value
-> Ty
-> ContractAddressOrAlias
-> Natural
-> SomeAddressOrAlias
-> Maybe Mutez
-> TransferTicketArgs
TransferTicketArgs {Natural
Maybe Mutez
AddressOrAlias 'AddressKindImplicit
ContractAddressOrAlias
SomeAddressOrAlias
Ty
Value
ttaMbFee :: Maybe Mutez
ttaDestination :: SomeAddressOrAlias
ttaTicketTicketer :: ContractAddressOrAlias
ttaTicketType :: Ty
ttaTicketContents :: Value
ttaTicketAmount :: Natural
ttaSender :: AddressOrAlias 'AddressKindImplicit
ttaMbFee :: Maybe Mutez
ttaDestination :: SomeAddressOrAlias
ttaTicketAmount :: Natural
ttaTicketTicketer :: ContractAddressOrAlias
ttaTicketType :: Ty
ttaTicketContents :: Value
ttaSender :: AddressOrAlias 'AddressKindImplicit
..}

usageDoc :: Doc
usageDoc :: Doc
usageDoc = [Doc] -> Doc
forall a. Monoid a => [a] -> a
mconcat
  [ Doc
"You can use help for specific COMMAND", Doc
linebreak
  , Doc
"EXAMPLE:", Doc
linebreak
  , Doc
"morley-client originate --help"
  , Doc
"USAGE EXAMPLE:", Doc
linebreak
  , Doc
"morley-client -E florence.testnet.tezos.serokell.team:8732 originate \\", Doc
linebreak
  , Doc
"  --from tz1akcPmG1Kyz2jXpS4RvVJ8uWr7tsiT9i6A \\", Doc
linebreak
  , Doc
"  --contract ../contracts/tezos_examples/attic/add1.tz --initial-balance 1 --initial-storage 0", Doc
linebreak
  , Doc
linebreak
  , Doc
"  This command will originate contract with code stored in add1.tz", Doc
linebreak
  , Doc
"  on real network with initial balance 1 and initial storage set to 0", Doc
linebreak
  , Doc
"  and return info about operation: operation hash and originated contract address", Doc
linebreak
  , Doc
linebreak
  , Doc
"morley-client -E florence.testnet.tezos.serokell.team:8732 transfer \\", Doc
linebreak
  , Doc
"  --from tz1akcPmG1Kyz2jXpS4RvVJ8uWr7tsiT9i6A \\", Doc
linebreak
  , Doc
"  --to KT1USbmjj6P2oJ54UM6HxBZgpoPtdiRSVABW --amount 1 --parameter 0", Doc
linebreak
  , Doc
linebreak
  , Doc
"  This command will perform tranfer to contract with address on real network", Doc
linebreak
  , Doc
"  KT1USbmjj6P2oJ54UM6HxBZgpoPtdiRSVABW with amount 1 and parameter 0", Doc
linebreak
  , Doc
"  as a result it will return operation hash"
  ]

--------------------------------------------------------------------------------
-- Parser utilities
--------------------------------------------------------------------------------

-- | Utility reader to use in parsing 'BaseUrl'.
baseUrlReader :: ReadM BaseUrl
baseUrlReader :: ReadM BaseUrl
baseUrlReader = (FilePath -> Either FilePath BaseUrl) -> ReadM BaseUrl
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((FilePath -> Either FilePath BaseUrl) -> ReadM BaseUrl)
-> (FilePath -> Either FilePath BaseUrl) -> ReadM BaseUrl
forall a b. (a -> b) -> a -> b
$ (SomeException -> FilePath)
-> Either SomeException BaseUrl -> Either FilePath BaseUrl
forall (p :: * -> * -> *) a b c.
Bifunctor p =>
(a -> b) -> p a c -> p b c
first SomeException -> FilePath
forall e. Exception e => e -> FilePath
displayException (Either SomeException BaseUrl -> Either FilePath BaseUrl)
-> (FilePath -> Either SomeException BaseUrl)
-> FilePath
-> Either FilePath BaseUrl
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Either SomeException BaseUrl
forall (m :: * -> *). MonadThrow m => FilePath -> m BaseUrl
parseBaseUrl