ligo/src/proto_alpha/lib_client/client_proto_args.ml

233 lines
6.7 KiB
OCaml
Raw Normal View History

2016-09-08 21:13:10 +04:00
(**************************************************************************)
(* *)
2018-02-06 00:17:03 +04:00
(* Copyright (c) 2014 - 2018. *)
2016-09-08 21:13:10 +04:00
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
open Proto_alpha
open Alpha_context
2018-04-03 13:39:09 +04:00
open Clic
type error += Bad_tez_arg of string * string (* Arg_name * value *)
type error += Bad_max_priority of string
type error += Bad_endorsement_delay of string
let () =
register_error_kind
`Permanent
~id:"badTezArg"
~title:"Bad Tez Arg"
~description:("Invalid \xEA\x9C\xA9 notation in parameter.")
~pp:(fun ppf (arg_name, literal) ->
Format.fprintf ppf
"Invalid \xEA\x9C\xA9 notation in parameter %s: '%s'"
arg_name literal)
Data_encoding.(obj2
(req "parameter" string)
(req "literal" string))
(function Bad_tez_arg (parameter, literal) -> Some (parameter, literal) | _ -> None)
(fun (parameter, literal) -> Bad_tez_arg (parameter, literal)) ;
register_error_kind
`Permanent
~id:"badMaxPriorityArg"
~title:"Bad -max-priority arg"
~description:("invalid priority in -max-priority")
~pp:(fun ppf literal ->
Format.fprintf ppf "invalid priority '%s'in -max-priority" literal)
Data_encoding.(obj1 (req "parameter" string))
(function Bad_max_priority parameter -> Some parameter | _ -> None)
(fun parameter -> Bad_max_priority parameter) ;
register_error_kind
`Permanent
~id:"badEndorsementDelayArg"
~title:"Bad -endorsement-delay arg"
~description:("invalid priority in -endorsement-delay")
~pp:(fun ppf literal ->
Format.fprintf ppf "Bad argument value for -endorsement-delay. Expected an integer, but given '%s'" literal)
Data_encoding.(obj1 (req "parameter" string))
(function Bad_endorsement_delay parameter -> Some parameter | _ -> None)
(fun parameter -> Bad_endorsement_delay parameter)
2016-09-08 21:13:10 +04:00
let tez_sym =
"\xEA\x9C\xA9"
2017-09-27 11:55:20 +04:00
let string_parameter =
2018-02-11 22:17:39 +04:00
parameter (fun _ x -> return x)
2017-09-27 11:55:20 +04:00
2016-09-08 21:13:10 +04:00
let init_arg =
default_arg
~long:"init"
~placeholder:"data"
~doc:"initial value of the contract's storage"
~default:"Unit"
2017-09-27 11:55:20 +04:00
string_parameter
2016-09-08 21:13:10 +04:00
let arg_arg =
default_arg
~long:"arg"
~placeholder:"data"
~doc:"argument passed to the contract's script, if needed"
~default:"Unit"
2017-09-27 11:55:20 +04:00
string_parameter
2016-09-08 21:13:10 +04:00
let delegate_arg =
Client_keys.Public_key_hash.source_arg
~long:"delegate"
~placeholder:"identity"
~doc:"delegate of the contract\n\
Must be a known identity."
()
2016-09-08 21:13:10 +04:00
let source_arg =
arg
~long:"source"
~placeholder:"identity"
2018-03-15 18:21:21 +04:00
~doc:"source of the deposits to be paid\n\
Must be a known identity."
2017-09-27 11:55:20 +04:00
string_parameter
let spendable_switch =
switch
~long:"spendable"
~doc:"allow the manager to spend the contract's tokens"
()
let force_switch =
switch
~long:"force"
~short:'f'
~doc:"disables the node's injection checks\n\
Force the injection of branch-invalid operation or force \
\ the injection of block without a fitness greater than the \
\ current head."
()
let minimal_timestamp_switch =
switch
~long:"minimal-timestamp"
~doc:"Use the minimal timestamp instead of the current date \
as timestamp of the baked block."
()
let delegatable_switch =
switch
~long:"delegatable"
~doc:"allow future delegate change"
()
2016-09-08 21:13:10 +04:00
let tez_format =
"Text format: `DDDDDDD.DDDDDD`.\n\
Tez and mutez and separated by a period sign. Trailing and pending \
zeroes are allowed."
2017-09-27 11:55:20 +04:00
let tez_parameter param =
parameter
(fun _ s ->
match Tez.of_string s with
| Some tez -> return tez
2017-09-27 11:55:20 +04:00
| None -> fail (Bad_tez_arg (param, s)))
let tez_arg ~default ~parameter ~doc =
default_arg ~long:parameter ~placeholder:"amount" ~doc ~default
(tez_parameter ("--" ^ parameter))
let tez_param ~name ~desc next =
2018-04-03 13:39:09 +04:00
Clic.param
2017-11-13 17:29:28 +04:00
~name
~desc:(desc ^ " in \xEA\x9C\xA9\n" ^ tez_format)
2017-09-27 11:55:20 +04:00
(tez_parameter name)
2016-09-08 21:13:10 +04:00
next
let fee_arg =
tez_arg
~default:"0.05"
~parameter:"fee"
~doc:"fee in \xEA\x9C\xA9 to pay to the baker"
let gas_limit_arg =
arg
~long:"gas-limit"
~short:'G'
~placeholder:"amount"
~doc:"Set the gas limit of the transaction instead \
of letting the client decide based on a simulation"
(parameter (fun _ s ->
try
let v = Z.of_string s in
assert Compare.Z.(v >= Z.zero) ;
return v
with _ -> failwith "invalid gas limit (must be a positive number)"))
2018-04-22 21:57:49 +04:00
let storage_limit_arg =
arg
~long:"storage-limit"
~short:'S'
~placeholder:"amount"
~doc:"Set the storage limit of the transaction instead \
of letting the client decide based on a simulation"
(parameter (fun _ s ->
try
let v = Z.of_string s in
assert Compare.Z.(v >= Z.zero) ;
2018-04-22 21:57:49 +04:00
return v
with _ -> failwith "invalid storage limit (must be a positive number of bytes)"))
2016-09-08 21:13:10 +04:00
let max_priority_arg =
arg
~long:"max-priority"
~placeholder:"slot"
~doc:"maximum allowed baking slot"
2017-09-27 11:55:20 +04:00
(parameter (fun _ s ->
try return (int_of_string s)
with _ -> fail (Bad_max_priority s)))
2016-09-08 21:13:10 +04:00
let endorsement_delay_arg =
default_arg
~long:"endorsement-delay"
~placeholder:"seconds"
~doc:"delay before endorsing blocks\n\
Delay between notifications of new blocks from the node and \
production of endorsements for these blocks."
~default:"15"
2017-09-27 11:55:20 +04:00
(parameter (fun _ s ->
try return (int_of_string s)
with _ -> fail (Bad_endorsement_delay s)))
2016-09-08 21:13:10 +04:00
let no_print_source_flag =
switch
~long:"no-print-source"
~short:'q'
~doc:"don't print the source code\n\
If an error is encountered, the client will print the \
contract's source code by default.\n\
This option disables this behaviour."
()
let no_confirmation =
switch
~long:"no-confirmation"
~doc:"don't print wait for the operation to be confirmed."
()
2016-09-08 21:13:10 +04:00
module Daemon = struct
2017-11-01 15:07:33 +04:00
let baking_switch =
switch
~long:"baking"
~short:'B'
~doc:"run the baking daemon" ()
let endorsement_switch =
switch
~long:"endorsement"
~short:'E'
~doc:"run the endorsement daemon" ()
let denunciation_switch =
switch
~long:"denunciation"
~short:'D'
~doc:"run the denunciation daemon" ()
2016-09-08 21:13:10 +04:00
end