From 1f4732f51eb05518a92ea16a992853f6659a2ab7 Mon Sep 17 00:00:00 2001 From: "G.B. Fefe" Date: Sun, 1 May 2022 21:26:13 +0200 Subject: [PATCH 1/4] Clic: add `map_arg` and `aggregate` to merge options --- src/lib_clic/clic.ml | 1049 +++++++++++------------------------------ src/lib_clic/clic.mli | 7 + 2 files changed, 282 insertions(+), 774 deletions(-) diff --git a/src/lib_clic/clic.ml b/src/lib_clic/clic.ml index 7776593dea91..75569eb0ab8a 100644 --- a/src/lib_clic/clic.ml +++ b/src/lib_clic/clic.ml @@ -86,10 +86,12 @@ type ('a, 'ctx) arg = -> ('p, 'ctx) arg | Switch : {label : label; doc : string} -> (bool, 'ctx) arg | Constant : 'a -> ('a, 'ctx) arg - -type ('a, 'arg) args = - | NoArgs : (unit, 'args) args - | AddArg : ('a, 'args) arg * ('b, 'args) args -> ('a * 'b, 'args) args + | Map : { + spec : ('a, 'ctx) arg; + converter : 'ctx -> 'a -> 'b tzresult Lwt.t; + } + -> ('b, 'ctx) arg + | Pair : ('a, 'ctx) arg * ('b, 'ctx) arg -> ('a * 'b, 'ctx) arg (* A simple structure for command interpreters. This is more generic than the exported one, see end of file. *) @@ -110,12 +112,9 @@ type ('a, 'ctx) params = * ('a -> 'b, 'ctx) params -> ('p list -> 'a -> 'b, 'ctx) params -type (_, _) options = - | Argument : { - spec : ('a, 'arg) args; - converter : 'a -> 'b; - } - -> ('b, 'arg) options +type ('a, 'ctx) options = ('a, 'ctx) arg + +let aggregate spec = spec (* A command group *) type group = {name : string; title : string} @@ -174,62 +173,64 @@ let print_label ppf = function | {long; short = None} -> Format.fprintf ppf "--%s" long | {long; short = Some short} -> Format.fprintf ppf "-%c --%s" short long -let print_options_detailed (type ctx) = - let help_option : type a. Format.formatter -> (a, ctx) arg -> unit = - fun ppf -> function - | Arg {label; placeholder; doc; _} -> - Format.fprintf - ppf - "@{%a <%s>@}: %a" - print_label - label - placeholder - print_desc - doc - | DefArg {label; placeholder; doc; default; _} -> - Format.fprintf - ppf - "@{%a <%s>@}: %a" - print_label - label - placeholder - print_desc - (doc ^ "\nDefaults to `" ^ default ^ "`.") - | Switch {label; doc} -> - Format.fprintf ppf "@{%a@}: %a" print_label label print_desc doc - | Constant _ -> () - in - let rec help : type b. Format.formatter -> (b, ctx) args -> unit = - fun ppf -> function - | NoArgs -> () - | AddArg (arg, NoArgs) -> Format.fprintf ppf "%a" help_option arg - | AddArg (arg, rest) -> - Format.fprintf ppf "%a@,%a" help_option arg help rest - in - help - -let has_args : type a ctx. (a, ctx) args -> bool = function - | NoArgs -> false - | AddArg (_, _) -> true - -let print_options_brief (type ctx) = - let help_option : type a. Format.formatter -> (a, ctx) arg -> unit = - fun ppf -> function - | DefArg {label; placeholder; _} -> - Format.fprintf ppf "[@{%a <%s>@}]" print_label label placeholder - | Arg {label; placeholder; _} -> - Format.fprintf ppf "[@{%a <%s>@}]" print_label label placeholder - | Switch {label; _} -> Format.fprintf ppf "[@{%a@}]" print_label label - | Constant _ -> () - in - let rec help : type b. Format.formatter -> (b, ctx) args -> unit = - fun ppf -> function - | NoArgs -> () - | AddArg (arg, NoArgs) -> Format.fprintf ppf "%a" help_option arg - | AddArg (arg, rest) -> - Format.fprintf ppf "%a@ %a" help_option arg help rest - in - help +let rec print_options_detailed : + type ctx a. Format.formatter -> (a, ctx) options -> unit = + fun ppf -> function + | Arg {label; placeholder; doc; _} -> + Format.fprintf + ppf + "@{%a <%s>@}: %a" + print_label + label + placeholder + print_desc + doc + | DefArg {label; placeholder; doc; default; _} -> + Format.fprintf + ppf + "@{%a <%s>@}: %a" + print_label + label + placeholder + print_desc + (doc ^ "\nDefaults to `" ^ default ^ "`.") + | Switch {label; doc} -> + Format.fprintf ppf "@{%a@}: %a" print_label label print_desc doc + | Constant _ -> () + | Pair (speca, specb) -> + Format.fprintf + ppf + "%a@,%a" + print_options_detailed + speca + print_options_detailed + specb + | Map {spec; converter = _} -> print_options_detailed ppf spec + +let rec has_args : type a ctx. (a, ctx) arg -> bool = function + | Constant _ -> false + | Arg _ | DefArg _ | Switch _ -> true + | Pair (speca, specb) -> has_args speca || has_args specb + | Map {spec; _} -> has_args spec + +let rec print_options_brief : + type ctx a. Format.formatter -> (a, ctx) arg -> unit = + fun ppf -> function + | DefArg {label; placeholder; _} -> + Format.fprintf ppf "[@{%a <%s>@}]" print_label label placeholder + | Arg {label; placeholder; _} -> + Format.fprintf ppf "[@{%a <%s>@}]" print_label label placeholder + | Switch {label; _} -> Format.fprintf ppf "[@{%a@}]" print_label label + | Constant _ -> () + | Pair (speca, specb) -> + Format.fprintf + ppf + "%a@ %a" + print_options_brief + speca + print_options_brief + specb + | Map {spec; converter = _} -> print_options_brief ppf spec let print_highlight highlight_strings formatter str = let rec print_string = function @@ -288,25 +289,22 @@ let print_commandline ppf (highlights, options, args) = Format.fprintf ppf "@{%a@}" print args let rec print_params_detailed : - type a b ctx. (b, ctx) args -> Format.formatter -> (a, ctx) params -> unit = + type a b ctx. (b, ctx) arg -> Format.formatter -> (a, ctx) params -> unit = fun spec ppf -> function | Stop -> print_options_detailed ppf spec - | Seq (n, desc, _) -> ( + | Seq (n, desc, _) -> Format.fprintf ppf "@{%s@}: %a" n print_desc (trim desc) ; - match spec with - | NoArgs -> () - | _ -> Format.fprintf ppf "@,%a" print_options_detailed spec) - | NonTerminalSeq (n, desc, _, _, next) -> ( + if has_args spec then + Format.fprintf ppf "@,%a" print_options_detailed spec + | NonTerminalSeq (n, desc, _, _, next) -> Format.fprintf ppf "@{%s@}: %a" n print_desc (trim desc) ; - match spec with - | NoArgs -> () - | _ -> Format.fprintf ppf "@,%a" (print_params_detailed spec) next) + if has_args spec then + Format.fprintf ppf "@,%a" (print_params_detailed spec) next | Prefix (_, next) -> print_params_detailed spec ppf next - | Param (n, desc, _, Stop) -> ( + | Param (n, desc, _, Stop) -> Format.fprintf ppf "@{%s@}: %a" n print_desc (trim desc) ; - match spec with - | NoArgs -> () - | _ -> Format.fprintf ppf "@,%a" print_options_detailed spec) + if has_args spec then + Format.fprintf ppf "@,%a" print_options_detailed spec | Param (n, desc, _, next) -> Format.fprintf ppf @@ -317,10 +315,9 @@ let rec print_params_detailed : (print_params_detailed spec) next -let contains_params_args : - type arg ctx. (arg, ctx) params -> (_, ctx) args -> bool = +let contains_params_args : type a ctx. (a, ctx) params -> (_, ctx) arg -> bool = fun params args -> - let rec help : (arg, ctx) params -> bool = function + let rec help : (a, ctx) params -> bool = function | Stop -> has_args args | Seq (_, _, _) -> true | NonTerminalSeq (_, _, _, _, _) -> true @@ -339,18 +336,18 @@ let print_command : fun ?(prefix = fun _ () -> ()) ?(highlights = []) ppf - (Command {params; desc; options = Argument {spec; _}; _}) -> - if contains_params_args params spec then + (Command {params; desc; options; _}) -> + if contains_params_args params options then Format.fprintf ppf "@{%a%a@{@,@{%a@,%a@}@}@}" prefix () print_commandline - (highlights, spec, params) + (highlights, options, params) print_desc desc - (print_params_detailed spec) + (print_params_detailed options) params else Format.fprintf @@ -359,7 +356,7 @@ let print_command : prefix () print_commandline - (highlights, spec, params) + (highlights, options, params) print_desc desc @@ -708,7 +705,6 @@ let restore_formatter ppf (out_functions, tag_functions, tags) = let usage_internal ppf ~executable_name ~global_options ?(highlights = []) commands = let by_group = group_commands commands in - let (Argument {spec; _}) = global_options in let print_groups = Format.pp_print_list ~pp_sep:(fun ppf () -> Format.fprintf ppf "@,@,") @@ -741,7 +737,7 @@ let usage_internal ppf ~executable_name ~global_options ?(highlights = []) executable_name executable_name print_options_detailed - spec + global_options (fun ppf () -> if by_group <> [] then Format.fprintf ppf "@,@,") () print_groups @@ -755,9 +751,118 @@ let arg ~doc ?short ~long ~placeholder kind = let default_arg ~doc ?short ~long ~placeholder ~default kind = DefArg {doc; placeholder; label = {long; short}; kind; default} +let map_arg ~f:converter spec = Map {spec; converter} + +let args1 a = a + +let args2 a b = Pair (a, b) + +let args3 a b c = + map_arg + ~f:(fun _ ((a, b), c) -> Lwt_result_syntax.return (a, b, c)) + (args2 (args2 a b) c) + +let args4 a b c d = + map_arg + ~f:(fun _ ((a, b), (c, d)) -> Lwt_result_syntax.return (a, b, c, d)) + (args2 (args2 a b) (args2 c d)) + +let args5 a b c d e = + map_arg + ~f:(fun _ ((a, b, c, d), e) -> Lwt_result_syntax.return (a, b, c, d, e)) + (args2 (args4 a b c d) e) + +let args6 a b c d e f = + map_arg + ~f:(fun _ ((a, b, c, d), (e, f)) -> + Lwt_result_syntax.return (a, b, c, d, e, f)) + (args2 (args4 a b c d) (args2 e f)) + +let args7 a b c d e f g = + map_arg + ~f:(fun _ ((a, b, c, d), (e, f, g)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g)) + (args2 (args4 a b c d) (args3 e f g)) + +let args8 a b c d e f g h = + map_arg + ~f:(fun _ ((a, b, c, d), (e, f, g, h)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h)) + (args2 (args4 a b c d) (args4 e f g h)) + +let args9 a b c d e f g h i = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), i) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i)) + (args2 (args8 a b c d e f g h) i) + +let args10 a b c d e f g h i j = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), (i, j)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i, j)) + (args2 (args8 a b c d e f g h) (args2 i j)) + +let args11 a b c d e f g h i j k = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), (i, j, k)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i, j, k)) + (args2 (args8 a b c d e f g h) (args3 i j k)) + +let args12 a b c d e f g h i j k l = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), (i, j, k, l)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i, j, k, l)) + (args2 (args8 a b c d e f g h) (args4 i j k l)) + +let args13 a b c d e f g h i j k l m = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), (i, j, k, l, m)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i, j, k, l, m)) + (args2 (args8 a b c d e f g h) (args5 i j k l m)) + +let args14 a b c d e f g h i j k l m n = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), (i, j, k, l, m, n)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i, j, k, l, m, n)) + (args2 (args8 a b c d e f g h) (args6 i j k l m n)) + +let args15 a b c d e f g h i j k l m n o = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), (i, j, k, l, m, n, o)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)) + (args2 (args8 a b c d e f g h) (args7 i j k l m n o)) + +let args16 a b c d e f g h i j k l m n o p = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h), (i, j, k, l, m, n, o, p)) -> + Lwt_result_syntax.return (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)) + (args2 (args8 a b c d e f g h) (args8 i j k l m n o p)) + +let args17 a b c d e f g h i j k l m n o p q = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p), q) -> + Lwt_result_syntax.return + (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q)) + (args2 (args16 a b c d e f g h i j k l m n o p) q) + +let args18 a b c d e f g h i j k l m n o p q r = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p), (q, r)) -> + Lwt_result_syntax.return + (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r)) + (args2 (args16 a b c d e f g h i j k l m n o p) (args2 q r)) + +let args19 a b c d e f g h i j k l m n o p q r s = + map_arg + ~f:(fun _ ((a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p), (q, r, s)) -> + Lwt_result_syntax.return + (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)) + (args2 (args16 a b c d e f g h i j k l m n o p) (args3 q r s)) + let switch ~doc ?short ~long () = Switch {doc; label = {long; short}} -let parse_arg : +(* Argument parsing *) +let rec parse_arg : type a ctx. ?command:_ command -> (a, ctx) arg -> @@ -798,46 +903,37 @@ let parse_arg : | Some [_] -> return_true | Some (_ :: _) -> tzfail (Multiple_occurrences (long, command))) | Constant c -> return c - -(* Argument parsing *) -let rec parse_args : - type a ctx. - ?command:_ command -> - (a, ctx) args -> - string list StringMap.t -> - ctx -> - a tzresult Lwt.t = - fun ?command spec args_dict ctx -> - let open Lwt_result_syntax in - match spec with - | NoArgs -> return_unit - | AddArg (arg, rest) -> - let* arg = parse_arg ?command arg args_dict ctx in - let+ rest = parse_args ?command rest args_dict ctx in - (arg, rest) + | Pair (speca, specb) -> + let* arga = parse_arg ?command speca args_dict ctx in + let* argb = parse_arg ?command specb args_dict ctx in + return (arga, argb) + | Map {spec; converter} -> + let* arg = parse_arg ?command spec args_dict ctx in + converter ctx arg let empty_args_dict = StringMap.empty let rec make_arities_dict : type a b. - (a, b) args -> (int * string) StringMap.t -> (int * string) StringMap.t = - fun args acc -> - match args with - | NoArgs -> acc - | AddArg (arg, rest) -> ( - let recur {long; short} num = - (match short with - | None -> acc - | Some c -> StringMap.add ("-" ^ String.make 1 c) (num, long) acc) - |> StringMap.add ("-" ^ long) (num, long) - |> StringMap.add ("--" ^ long) (num, long) - |> make_arities_dict rest - in - match arg with - | Arg {label; _} -> recur label 1 - | DefArg {label; _} -> recur label 1 - | Switch {label; _} -> recur label 0 - | Constant _c -> make_arities_dict rest acc) + (a, b) arg -> (int * string) StringMap.t -> (int * string) StringMap.t = + fun arg acc -> + let add {long; short} num = + (match short with + | None -> acc + | Some c -> StringMap.add ("-" ^ String.make 1 c) (num, long) acc) + |> StringMap.add ("-" ^ long) (num, long) + |> StringMap.add ("--" ^ long) (num, long) + in + match arg with + | Arg {label; _} -> add label 1 + | DefArg {label; _} -> add label 1 + | Switch {label; _} -> add label 0 + | Constant _c -> acc + | Pair (speca, specb) -> + let acc = make_arities_dict speca acc in + let acc = make_arities_dict specb acc in + acc + | Map {spec; _} -> make_arities_dict spec acc type error += Version : error @@ -935,574 +1031,6 @@ let make_args_dict_filter ?command spec args = in (dict, List.rev remaining) -let ( >> ) arg1 arg2 = AddArg (arg1, arg2) - -let args1 spec = - Argument {spec = spec >> NoArgs; converter = (fun (arg, ()) -> arg)} - -let args2 spec1 spec2 = - Argument - { - spec = spec1 >> (spec2 >> NoArgs); - converter = (fun (arg1, (arg2, ())) -> (arg1, arg2)); - } - -let args3 spec1 spec2 spec3 = - Argument - { - spec = spec1 >> (spec2 >> (spec3 >> NoArgs)); - converter = (fun (arg1, (arg2, (arg3, ()))) -> (arg1, arg2, arg3)); - } - -let args4 spec1 spec2 spec3 spec4 = - Argument - { - spec = spec1 >> (spec2 >> (spec3 >> (spec4 >> NoArgs))); - converter = - (fun (arg1, (arg2, (arg3, (arg4, ())))) -> (arg1, arg2, arg3, arg4)); - } - -let args5 spec1 spec2 spec3 spec4 spec5 = - Argument - { - spec = spec1 >> (spec2 >> (spec3 >> (spec4 >> (spec5 >> NoArgs)))); - converter = - (fun (arg1, (arg2, (arg3, (arg4, (arg5, ()))))) -> - (arg1, arg2, arg3, arg4, arg5)); - } - -let args6 spec1 spec2 spec3 spec4 spec5 spec6 = - Argument - { - spec = - spec1 >> (spec2 >> (spec3 >> (spec4 >> (spec5 >> (spec6 >> NoArgs))))); - converter = - (fun (arg1, (arg2, (arg3, (arg4, (arg5, (spec6, ())))))) -> - (arg1, arg2, arg3, arg4, arg5, spec6)); - } - -let args7 spec1 spec2 spec3 spec4 spec5 spec6 spec7 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 >> (spec4 >> (spec5 >> (spec6 >> (spec7 >> NoArgs)))))); - converter = - (fun (arg1, (arg2, (arg3, (arg4, (arg5, (spec6, (spec7, ()))))))) -> - (arg1, arg2, arg3, arg4, arg5, spec6, spec7)); - } - -let args8 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 >> (spec5 >> (spec6 >> (spec7 >> (spec8 >> NoArgs)))))) - ); - converter = - (fun ( arg1, - (arg2, (arg3, (arg4, (arg5, (spec6, (spec7, (spec8, ()))))))) ) -> - (arg1, arg2, arg3, arg4, arg5, spec6, spec7, spec8)); - } - -let args9 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 >> (spec6 >> (spec7 >> (spec8 >> (spec9 >> NoArgs))))) - ))); - converter = - (fun ( arg1, - ( arg2, - (arg3, (arg4, (arg5, (spec6, (spec7, (spec8, (spec9, ()))))))) - ) ) -> - (arg1, arg2, arg3, arg4, arg5, spec6, spec7, spec8, spec9)); - } - -let args10 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 >> (spec8 >> (spec9 >> (spec10 >> NoArgs)))))) - ))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - (arg5, (spec6, (spec7, (spec8, (spec9, (spec10, ())))))) ) - ) ) ) -> - (arg1, arg2, arg3, arg4, arg5, spec6, spec7, spec8, spec9, spec10)); - } - -let args11 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 >> (spec9 >> (spec10 >> (spec11 >> NoArgs)))) - )))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - (spec6, (spec7, (spec8, (spec9, (spec10, (spec11, ())))))) - ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11 )); - } - -let args12 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 >> (spec11 >> (spec12 >> NoArgs))))) - )))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - (spec8, (spec9, (spec10, (spec11, (spec12, ()))))) ) - ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12 )); - } - -let args13 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 spec13 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 - >> (spec11 >> (spec12 >> (spec13 >> NoArgs))) - ))))))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - ( spec8, - (spec9, (spec10, (spec11, (spec12, (spec13, ()))))) - ) ) ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12, - spec13 )); - } - -let args14 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 spec13 spec14 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 - >> (spec11 - >> (spec12 - >> (spec13 >> (spec14 >> NoArgs))))))) - )))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - ( spec8, - ( spec9, - ( spec10, - (spec11, (spec12, (spec13, (spec14, ())))) ) ) - ) ) ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12, - spec13, - spec14 )); - } - -let args15 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 spec13 spec14 spec15 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 - >> (spec11 - >> (spec12 - >> (spec13 - >> (spec14 >> (spec15 >> NoArgs)))) - )))))))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - ( spec8, - ( spec9, - ( spec10, - ( spec11, - (spec12, (spec13, (spec14, (spec15, ())))) ) - ) ) ) ) ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12, - spec13, - spec14, - spec15 )); - } - -let args16 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 spec13 spec14 spec15 spec16 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 - >> (spec11 - >> (spec12 - >> (spec13 - >> (spec14 - >> (spec15 >> (spec16 >> NoArgs)) - ))))))))))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - ( spec8, - ( spec9, - ( spec10, - ( spec11, - ( spec12, - (spec13, (spec14, (spec15, (spec16, ())))) - ) ) ) ) ) ) ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12, - spec13, - spec14, - spec15, - spec16 )); - } - -let args17 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 spec13 spec14 spec15 spec16 spec17 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 - >> (spec11 - >> (spec12 - >> (spec13 - >> (spec14 - >> (spec15 - >> (spec16 - >> (spec17 >> NoArgs))))))) - ))))))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - ( spec8, - ( spec9, - ( spec10, - ( spec11, - ( spec12, - ( spec13, - (spec14, (spec15, (spec16, (spec17, ())))) - ) ) ) ) ) ) ) ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12, - spec13, - spec14, - spec15, - spec16, - spec17 )); - } - -let args18 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 spec13 spec14 spec15 spec16 spec17 spec18 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 - >> (spec11 - >> (spec12 - >> (spec13 - >> (spec14 - >> (spec15 - >> (spec16 - >> (spec17 - >> (spec18 >> NoArgs)))) - ))))))))))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - ( spec8, - ( spec9, - ( spec10, - ( spec11, - ( spec12, - ( spec13, - ( spec14, - ( spec15, - (spec16, (spec17, (spec18, ()))) ) ) - ) ) ) ) ) ) ) ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12, - spec13, - spec14, - spec15, - spec16, - spec17, - spec18 )); - } - -let args19 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 spec11 - spec12 spec13 spec14 spec15 spec16 spec17 spec18 spec19 = - Argument - { - spec = - spec1 - >> (spec2 - >> (spec3 - >> (spec4 - >> (spec5 - >> (spec6 - >> (spec7 - >> (spec8 - >> (spec9 - >> (spec10 - >> (spec11 - >> (spec12 - >> (spec13 - >> (spec14 - >> (spec15 - >> (spec16 - >> (spec17 - >> (spec18 - >> (spec19 >> NoArgs) - ))))))))))))))))); - converter = - (fun ( arg1, - ( arg2, - ( arg3, - ( arg4, - ( arg5, - ( spec6, - ( spec7, - ( spec8, - ( spec9, - ( spec10, - ( spec11, - ( spec12, - ( spec13, - ( spec14, - ( spec15, - ( spec16, - (spec17, (spec18, (spec19, ()))) ) - ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) -> - ( arg1, - arg2, - arg3, - arg4, - arg5, - spec6, - spec7, - spec8, - spec9, - spec10, - spec11, - spec12, - spec13, - spec14, - spec15, - spec16, - spec17, - spec18, - spec19 )); - } - (* Some combinators for writing commands concisely. *) let param ~name ~desc kind next = Param (name, desc, kind, next) @@ -1527,7 +1055,7 @@ let rec prefixes p next = let stop = Stop -let no_options = Argument {spec = NoArgs; converter = (fun () -> ())} +let no_options = Constant () let command ?group ~desc options params handler = Command {params; options; handler; desc; group; conv = (fun x -> x)} @@ -1568,14 +1096,8 @@ let search_command keyword (Command {params; _}) = (* Command execution *) let exec (type ctx) - (Command - { - options = Argument {converter; spec = options_spec}; - params = spec; - handler; - conv; - _; - } as command) (ctx : ctx) params args_dict = + (Command {options = options_spec; params = spec; handler; conv; _} as + command) (ctx : ctx) params args_dict = let open Lwt_result_syntax in let rec exec : type ctx a. @@ -1628,8 +1150,8 @@ let exec (type ctx) | _ -> Stdlib.failwith "cli_entries internal error: exec no case matched" in let ctx = conv ctx in - let* parsed_options = parse_args ~command options_spec args_dict ctx in - exec 1 ctx spec (handler (converter parsed_options)) params + let* parsed_options = parse_arg ~command options_spec args_dict ctx in + exec 1 ctx spec (handler parsed_options) params [@@@ocaml.warning "-30"] @@ -1665,12 +1187,7 @@ and 'ctx tree = | TEmpty : 'ctx tree let has_options : type ctx. ctx command -> bool = - fun (Command {options = Argument {spec; _}; _}) -> - let args_help : type a ctx. (a, ctx) args -> bool = function - | NoArgs -> false - | AddArg (_, _) -> true - in - args_help spec + fun (Command {options; _}) -> has_args options let insert_in_dispatch_tree : type ctx. ctx tree -> ctx command -> ctx tree = fun root (Command {params; conv; _} as command) -> @@ -1743,8 +1260,8 @@ let insert_in_dispatch_tree : type ctx. ctx tree -> ctx command -> ctx tree = Stdlib.failwith (Format.asprintf "Clic.Command_tree.insert: conflicting commands \"%a\"" - (fun ppf (Command {params; options = Argument {spec; _}; _}) -> - print_commandline ppf ([], spec, params)) + (fun ppf (Command {params; options; _}) -> + print_commandline ppf ([], options, params)) command) in insert_tree conv root params @@ -1782,10 +1299,9 @@ let find_command tree initial_arguments = | [command] -> tzfail (Help (Some command)) | more -> tzfail (Unterminated_command (initial_arguments, more))) | (TStop c, []) -> return (c, empty_args_dict, initial_arguments) - | (TStop (Command {options = Argument {spec; _}; _} as command), remaining) - -> ( + | (TStop (Command {options; _} as command), remaining) -> ( let* (args_dict, unparsed) = - make_args_dict_filter ~command spec remaining + make_args_dict_filter ~command options remaining in match unparsed with | [] -> return (command, args_dict, initial_arguments) @@ -1793,8 +1309,7 @@ let find_command tree initial_arguments = if String.length hd > 0 && hd.[0] = '-' then tzfail (Unknown_option (hd, Some command)) else tzfail (Extra_arguments (unparsed, command))) - | ( TSeq ((Command {options = Argument {spec; _}; _} as command), _), - remaining ) -> + | (TSeq ((Command {options; _} as command), _), remaining) -> if List.exists (function "-h" | "--help" -> true | _ -> false) @@ -1802,7 +1317,7 @@ let find_command tree initial_arguments = then tzfail (Help (Some command)) else let+ (dict, remaining) = - make_args_dict_filter ~command spec remaining + make_args_dict_filter ~command options remaining in (command, dict, List.rev_append acc remaining) | (TNonTerminalSeq {stop = None; _}, ([] | ("-h" | "--help") :: _)) -> @@ -1845,23 +1360,15 @@ let find_command tree initial_arguments = in traverse tree initial_arguments [] -let get_arg_label (type a) (arg : (a, _) arg) = - match arg with - | Arg {label; _} -> label - | DefArg {label; _} -> label - | Switch {label; _} -> label - | Constant _ -> assert false - -let get_arg : type a ctx. (a, ctx) arg -> string list = - fun arg -> - let {long; short} = get_arg_label arg in +let get_arg {long; short} = ("--" ^ long) :: (match short with None -> [] | Some c -> ["-" ^ String.make 1 c]) -let rec list_args : type arg ctx. (arg, ctx) args -> string list = function - | NoArgs -> [] - | AddArg (Constant _, args) -> list_args args - | AddArg (arg, args) -> get_arg arg @ list_args args +let rec list_args : type a ctx. (a, ctx) arg -> string list = function + | Constant _ -> [] + | Arg {label; _} | DefArg {label; _} | Switch {label; _} -> get_arg label + | Pair (speca, specb) -> list_args speca @ list_args specb + | Map {spec; _} -> list_args spec let complete_func autocomplete cctxt = let open Lwt_result_syntax in @@ -1869,41 +1376,38 @@ let complete_func autocomplete cctxt = | None -> return_nil | Some autocomplete -> autocomplete cctxt -let list_command_args (Command {options = Argument {spec; _}; _}) = - list_args spec +let list_command_args (Command {options; _}) = list_args options -let complete_arg : type a ctx. ctx -> (a, ctx) arg -> string list tzresult Lwt.t - = - fun ctx -> - let open Lwt_result_syntax in - function - | Arg {kind = {autocomplete; _}; _} -> complete_func autocomplete ctx - | DefArg {kind = {autocomplete; _}; _} -> complete_func autocomplete ctx - | Switch _ -> return_nil - | Constant _ -> return_nil - -let rec remaining_spec : type a ctx. StringSet.t -> (a, ctx) args -> string list +let rec remaining_spec : type a ctx. StringSet.t -> (a, ctx) arg -> string list = fun seen -> function - | NoArgs -> [] - | AddArg (Constant _, rest) -> remaining_spec seen rest - | AddArg (arg, rest) -> - let {long; _} = get_arg_label arg in - if StringSet.mem long seen then remaining_spec seen rest - else get_arg arg @ remaining_spec seen rest + | Constant _ -> [] + | Arg {label; _} | DefArg {label; _} | Switch {label; _} -> + if StringSet.mem label.long seen then [] else get_arg label + | Pair (speca, specb) -> remaining_spec seen speca @ remaining_spec seen specb + | Map {spec; _} -> remaining_spec seen spec let complete_options (type ctx) continuation args args_spec ind (ctx : ctx) = let arities = make_arities_dict args_spec StringMap.empty in let rec complete_spec : - type a. string -> (a, ctx) args -> string list tzresult Lwt.t = + type a. string -> (a, ctx) arg -> string list option tzresult Lwt.t = fun name -> let open Lwt_result_syntax in function - | NoArgs -> return_nil - | AddArg (Constant _, rest) -> complete_spec name rest - | AddArg (arg, rest) -> - if (get_arg_label arg).long = name then complete_arg ctx arg - else complete_spec name rest + | Constant _ -> return_none + | DefArg {kind = {autocomplete; _}; label; _} + | Arg {kind = {autocomplete; _}; label; _} + when label.long = name -> + let* p = complete_func autocomplete ctx in + return_some p + | Switch {label; _} when label.long = name -> return_some [] + | Arg _ | DefArg _ | Switch _ -> return_none + | Pair (speca, specb) -> ( + let* resa = complete_spec name speca in + match resa with + | Some _ -> return resa + | None -> complete_spec name specb) + | Map {spec; _} -> complete_spec name spec in let rec help args ind seen = let open Lwt_result_syntax in @@ -1921,7 +1425,9 @@ let complete_options (type ctx) continuation args args_spec ind (ctx : ctx) = let+ cont_args = continuation args 0 in remaining_spec seen args_spec @ cont_args | (0, args) -> help args (ind - 1) seen - | (1, _) when ind = 1 -> complete_spec arg args_spec + | (1, _) when ind = 1 -> + let* res = complete_spec arg args_spec in + return (Option.value ~default:[] res) | (1, _ :: tl) -> help tl (ind - 2) seen | _ -> Stdlib.failwith "cli_entries internal error, invalid arity") | None -> continuation args ind) @@ -1988,8 +1494,8 @@ let complete_tree cctxt tree index args = | None -> return_nil | Some p -> help p tl (ind - 1)) | (TParam {tree; _}, _ :: tl) -> help tree tl (ind - 1) - | (TStop (Command {options = Argument {spec; _}; conv; _}), args) -> - complete_options (fun _ _ -> return_nil) args spec ind (conv cctxt) + | (TStop (Command {options; conv; _}), args) -> + complete_options (fun _ _ -> return_nil) args options ind (conv cctxt) | ((TParam _ | TPrefix _ | TNonTerminalSeq _), []) | (TEmpty, _) -> return_nil in @@ -2009,17 +1515,15 @@ let autocompletion ~script ~cur_arg ~prev_arg ~args ~global_options commands let+ completions = if prev_arg = script then let+ command_completions = complete_next_tree cctxt tree in - let (Argument {spec; _}) = global_options in - list_args spec @ command_completions + list_args global_options @ command_completions else match ind 0 args with | None -> return_nil | Some index -> - let (Argument {spec; _}) = global_options in complete_options (fun args ind -> complete_tree cctxt tree ind args) args - spec + global_options index cctxt in @@ -2030,10 +1534,9 @@ let autocompletion ~script ~cur_arg ~prev_arg ~args ~global_options commands let parse_global_options global_options ctx args = let open Lwt_result_syntax in - let (Argument {spec; converter}) = global_options in - let* (dict, remaining) = make_args_dict_consume spec args in - let* nested = parse_args spec dict ctx in - return (converter nested, remaining) + let* (dict, remaining) = make_args_dict_consume global_options args in + let* nested = parse_arg global_options dict ctx in + return (nested, remaining) let dispatch commands ctx args = let open Lwt_result_syntax in @@ -2202,9 +1705,8 @@ let pp_cli_errors ppf ~executable_name ~global_options ~default errs = Format.fprintf ppf "@[Unterminated command, here are possible completions.@,%a@]" - (Format.pp_print_list - (fun ppf (Command {params; options = Argument {spec; _}; _}) -> - print_commandline ppf ([], spec, params))) + (Format.pp_print_list (fun ppf (Command {params; options; _}) -> + print_commandline ppf ([], options, params))) commands ; Some (List.map (fun c -> Ex c) commands) | Command_not_found ([], _all_commands) -> @@ -2219,9 +1721,8 @@ let pp_cli_errors ppf ~executable_name ~global_options ~default errs = "@[Unrecognized command.@,\ Did you mean one of the following?@,\ \ @[%a@]@]" - (Format.pp_print_list - (fun ppf (Command {params; options = Argument {spec; _}; _}) -> - print_commandline ppf ([], spec, params))) + (Format.pp_print_list (fun ppf (Command {params; options; _}) -> + print_commandline ppf ([], options, params))) commands ; Some (List.map (fun c -> Ex c) commands) | err -> diff --git a/src/lib_clic/clic.mli b/src/lib_clic/clic.mli index 2ce38540bf98..3d91842c38dc 100644 --- a/src/lib_clic/clic.mli +++ b/src/lib_clic/clic.mli @@ -108,6 +108,10 @@ val default_arg : val switch : doc:string -> ?short:char -> long:string -> unit -> (bool, 'ctx) arg +(** Map a function over the result of a parsed argument. *) +val map_arg : + f:('ctx -> 'a -> 'b tzresult Lwt.t) -> ('a, 'ctx) arg -> ('b, 'ctx) arg + (** {2 Groups of Optional Arguments} *) (** Defines a group of options, either the global options or the @@ -443,6 +447,9 @@ val args19 : 'ctx ) options +(** Aggregate a set of options into a single value. *) +val aggregate : ('a, 'ctx) options -> ('a, 'ctx) arg + (** {2 Parameter based command lines} *) (** Type of parameters for a command *) -- GitLab From e920f14b8df1562aac402565042e86380e9bfab9 Mon Sep 17 00:00:00 2001 From: "G.B. Fefe" Date: Mon, 9 May 2022 10:50:59 +0200 Subject: [PATCH 2/4] Proto/Client: move `Client_proto_args.tez_sym` into `Operation_result` --- src/proto_alpha/lib_client/client_proto_args.ml | 2 -- src/proto_alpha/lib_client/client_proto_args.mli | 2 -- .../lib_client/client_proto_context.ml | 2 +- src/proto_alpha/lib_client/client_proto_fa12.ml | 2 +- src/proto_alpha/lib_client/injection.ml | 12 ++++++------ src/proto_alpha/lib_client/operation_result.ml | 14 +++++++------- src/proto_alpha/lib_client/operation_result.mli | 2 ++ .../client_proto_context_commands.ml | 16 ++++++++-------- .../client_sapling_commands.ml | 2 +- 9 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_args.ml b/src/proto_alpha/lib_client/client_proto_args.ml index 377851898fc6..0898130cedae 100644 --- a/src/proto_alpha/lib_client/client_proto_args.ml +++ b/src/proto_alpha/lib_client/client_proto_args.ml @@ -137,8 +137,6 @@ let () = (function Forbidden_Negative_int str -> Some str | _ -> None) (fun str -> Forbidden_Negative_int str) -let tez_sym = "\xEA\x9C\xA9" - let string_parameter = parameter (fun _ x -> return x) let int_parameter = diff --git a/src/proto_alpha/lib_client/client_proto_args.mli b/src/proto_alpha/lib_client/client_proto_args.mli index 8770d12681aa..1713e65cc0f7 100644 --- a/src/proto_alpha/lib_client/client_proto_args.mli +++ b/src/proto_alpha/lib_client/client_proto_args.mli @@ -28,8 +28,6 @@ open Protocol open Alpha_context open Protocol_client_context -val tez_sym : string - val entrypoint_parameter : (Entrypoint.t, full) Clic.parameter val init_arg : (string, full) Clic.arg diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 717321510f30..a0d44e0b42aa 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -578,7 +578,7 @@ let inject_activate_operation cctxt ~chain ~block ?confirmations ?dry_run alias alias Ed25519.Public_key_hash.pp pkh - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp balance >>= fun () -> return_unit) diff --git a/src/proto_alpha/lib_client/client_proto_fa12.ml b/src/proto_alpha/lib_client/client_proto_fa12.ml index 89983ce1935b..e9c046013c6a 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.ml +++ b/src/proto_alpha/lib_client/client_proto_fa12.ml @@ -860,7 +860,7 @@ let tez_of_string_exn index field s = | None -> error_with "Invalid %s notation at entry %i, field \"%s\": %s" - Client_proto_args.tez_sym + Operation_result.tez_sym index field s diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 15c34c2d8114..6567240c6f4e 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -117,10 +117,10 @@ let check_fees : "The proposed fee (%s%a) are higher than the configured fee cap \ (%s%a).@\n\ \ Use `--fee-cap %a` to emit this operation anyway." - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp fee - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp config.fee_cap Tez.pp @@ -164,10 +164,10 @@ let check_fees : "The proposed fee (%s%a) are lower than the fee that baker expect \ by default (%s%a).@\n\ \ Use `--force-low-fee` to emit this operation anyway." - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp fee - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp estimated_fees >>= fun () -> exit 1 @@ -914,10 +914,10 @@ let may_patch_limits (type kind) (cctxt : #Protocol_client_context.full) "The operation will burn %s%a which is higher than the configured \ burn cap (%s%a).@\n\ \ Use `--burn-cap %a` to emit this operation." - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp burn - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp fee_parameter.burn_cap Tez.pp diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index da71a64bf3ee..235beabdf9a9 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -27,6 +27,8 @@ open Protocol open Alpha_context open Apply_results +let tez_sym = "\xEA\x9C\xA9" + let pp_manager_operation_content (type kind) source internal pp_result ppf ((operation, result) : kind manager_operation * _) = Format.fprintf ppf "@[" ; @@ -36,7 +38,7 @@ let pp_manager_operation_content (type kind) source internal pp_result ppf ppf "@[%s:@,Amount: %s%a@,From: %a@,To: %a" (if internal then "Internal transaction" else "Transaction") - Client_proto_args.tez_sym + tez_sym Tez.pp amount Contract.pp @@ -65,7 +67,7 @@ let pp_manager_operation_content (type kind) source internal pp_result ppf (if internal then "Internal origination" else "Origination") Contract.pp source - Client_proto_args.tez_sym + tez_sym Tez.pp credit ; let code = @@ -395,10 +397,8 @@ let pp_balance_updates ppf = function balance_updates in let pp_update ppf = function - | Credited amount -> - Format.fprintf ppf "+%s%a" Client_proto_args.tez_sym Tez.pp amount - | Debited amount -> - Format.fprintf ppf "-%s%a" Client_proto_args.tez_sym Tez.pp amount + | Credited amount -> Format.fprintf ppf "+%s%a" tez_sym Tez.pp amount + | Debited amount -> Format.fprintf ppf "-%s%a" tez_sym Tez.pp amount in let pp_one ppf (balance, update) = let to_fill = column_size + 3 - String.length balance in @@ -888,7 +888,7 @@ let pp_manager_operation_contents_and_result ppf Storage limit: %s bytes" Signature.Public_key_hash.pp source - Client_proto_args.tez_sym + tez_sym Tez.pp fee (Z.to_string counter) diff --git a/src/proto_alpha/lib_client/operation_result.mli b/src/proto_alpha/lib_client/operation_result.mli index 404f36ef3b49..77298d3a03e1 100644 --- a/src/proto_alpha/lib_client/operation_result.mli +++ b/src/proto_alpha/lib_client/operation_result.mli @@ -26,6 +26,8 @@ open Protocol open Alpha_context +val tez_sym : string + val pp_internal_operation : Format.formatter -> Script_typed_ir.packed_internal_operation -> unit diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 9cd39bf97cc0..bd66706301fa 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -236,7 +236,7 @@ let commands_ro () = (fun () (_, contract) (cctxt : Protocol_client_context.full) -> get_balance cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? fun amount -> - cctxt#answer "%a %s" Tez.pp amount Client_proto_args.tez_sym + cctxt#answer "%a %s" Tez.pp amount Operation_result.tez_sym >>= fun () -> return_unit); command ~group @@ -513,7 +513,7 @@ let commands_ro () = p Tez.pp (Tez.of_mutez_exn w) - Client_proto_args.tez_sym + Operation_result.tez_sym (if List.mem ~equal:Protocol_hash.equal p known_protos then "" else "not ")) @@ -538,21 +538,21 @@ let commands_ro () = Current in favor %a %s, needed supermajority %a %s@]" Tez.pp (Tez.of_mutez_exn ballots_info.ballots.yay) - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp (Tez.of_mutez_exn ballots_info.ballots.nay) - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp (Tez.of_mutez_exn ballots_info.ballots.pass) - Client_proto_args.tez_sym + Operation_result.tez_sym (Int32.to_float ballots_info.participation /. 100.) (Int32.to_float ballots_info.current_quorum /. 100.) Tez.pp (Tez.of_mutez_exn ballots_info.ballots.yay) - Client_proto_args.tez_sym + Operation_result.tez_sym Tez.pp (Tez.of_mutez_exn ballots_info.supermajority) - Client_proto_args.tez_sym + Operation_result.tez_sym >>= fun () -> return_unit else cctxt#message "The ballots have already been cleared." @@ -609,7 +609,7 @@ let commands_ro () = >>=? function | None -> cctxt#answer "unlimited" >>= return | Some limit -> - cctxt#answer "%a %s" Tez.pp limit Client_proto_args.tez_sym + cctxt#answer "%a %s" Tez.pp limit Operation_result.tez_sym >>= return)); ] diff --git a/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml b/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml index 100ea07e6497..106efb3162a1 100644 --- a/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml +++ b/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml @@ -796,7 +796,7 @@ let commands () = "Total Sapling funds %a%s" Context.Shielded_tez.pp (Context.Account.balance account) - Client_proto_args.tez_sym + Operation_result.tez_sym >>= fun () -> return_unit)); command ~group -- GitLab From 352182d28edd89d822b40b0edc0fd31988df5521 Mon Sep 17 00:00:00 2001 From: "G.B. Fefe" Date: Sun, 1 May 2022 21:26:13 +0200 Subject: [PATCH 3/4] Proto/Client: use an aggregated argument for `fee_parameters` --- .../lib_client/client_proto_args.ml | 85 ++- .../lib_client/client_proto_args.mli | 9 +- .../client_proto_context_commands.ml | 662 +++--------------- .../client_proto_fa12_commands.ml | 138 +--- .../client_proto_multisig_commands.ml | 150 +--- .../client_sapling_commands.ml | 96 +-- 6 files changed, 192 insertions(+), 948 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_args.ml b/src/proto_alpha/lib_client/client_proto_args.ml index 0898130cedae..0dae91164860 100644 --- a/src/proto_alpha/lib_client/client_proto_args.ml +++ b/src/proto_alpha/lib_client/client_proto_args.ml @@ -484,34 +484,6 @@ let minimal_nanotez_per_byte_arg = (parameter (fun _ s -> try return (Q.of_string s) with _ -> fail (Bad_minimal_fees s))) -let force_low_fee_arg = - switch - ~long:"force-low-fee" - ~doc:"Don't check that the fee is lower than the estimated default value" - () - -let fee_cap_arg = - default_arg - ~long:"fee-cap" - ~placeholder:"amount" - ~default:"1.0" - ~doc:"Set the fee cap" - (parameter (fun _ s -> - match Tez.of_string s with - | Some t -> return t - | None -> failwith "Bad fee cap")) - -let burn_cap_arg = - default_arg - ~long:"burn-cap" - ~placeholder:"amount" - ~default:"0" - ~doc:"Set the burn cap" - (parameter (fun _ s -> - match Tez.of_string s with - | Some t -> return t - | None -> failwith "Bad burn cap")) - let replace_by_fees_arg = switch ~long:"replace" @@ -899,3 +871,60 @@ module Tx_rollup = struct inbox_root_hash_parameter next end + +let fee_parameter_args = + let open Clic in + let force_low_fee_arg = + switch + ~long:"force-low-fee" + ~doc:"Don't check that the fee is lower than the estimated default value" + () + in + let fee_cap_arg = + default_arg + ~long:"fee-cap" + ~placeholder:"amount" + ~default:"1.0" + ~doc:"Set the fee cap" + (parameter (fun _ s -> + match Tez.of_string s with + | Some t -> return t + | None -> failwith "Bad fee cap")) + in + let burn_cap_arg = + default_arg + ~long:"burn-cap" + ~placeholder:"amount" + ~default:"0" + ~doc:"Set the burn cap" + (parameter (fun _ s -> + match Tez.of_string s with + | Some t -> return t + | None -> failwith "Bad burn cap")) + in + Clic.map_arg + ~f: + (fun _cctxt + ( minimal_fees, + minimal_nanotez_per_byte, + minimal_nanotez_per_gas_unit, + force_low_fee, + fee_cap, + burn_cap ) -> + return + { + Injection.minimal_fees; + minimal_nanotez_per_byte; + minimal_nanotez_per_gas_unit; + force_low_fee; + fee_cap; + burn_cap; + }) + (Clic.aggregate + (Clic.args6 + minimal_fees_arg + minimal_nanotez_per_byte_arg + minimal_nanotez_per_gas_unit_arg + force_low_fee_arg + fee_cap_arg + burn_cap_arg)) diff --git a/src/proto_alpha/lib_client/client_proto_args.mli b/src/proto_alpha/lib_client/client_proto_args.mli index 1713e65cc0f7..519df20744ba 100644 --- a/src/proto_alpha/lib_client/client_proto_args.mli +++ b/src/proto_alpha/lib_client/client_proto_args.mli @@ -70,12 +70,6 @@ val minimal_nanotez_per_gas_unit_arg : (Q.t, full) Clic.arg val minimal_nanotez_per_byte_arg : (Q.t, full) Clic.arg -val force_low_fee_arg : (bool, full) Clic.arg - -val fee_cap_arg : (Tez.t, full) Clic.arg - -val burn_cap_arg : (Tez.t, full) Clic.arg - val replace_by_fees_arg : (bool, full) Clic.arg val successor_level_arg : (bool, full) Clic.arg @@ -242,3 +236,6 @@ module Tx_rollup : sig ('a, full) Clic.params -> (Tx_rollup_inbox.Merkle.root -> 'a, full) Clic.params end + +val fee_parameter_args : + (Injection.fee_parameter, Protocol_client_context.full) Clic.arg diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index bd66706301fa..0bc248862571 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -678,25 +678,10 @@ let transfer_command amount (source : Contract.t) destination counter, arg, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, entrypoint, replace_by_fees, successor_level ) = - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in (* When --force is used we want to inject the transfer even if it fails. In that case we cannot rely on simulation to compute limits and fees so we require the corresponding options to be set. *) @@ -901,17 +886,12 @@ let commands_rw () = command ~group ~desc:"Set the delegate of a contract." - (args10 + (args5 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args) (prefixes ["set"; "delegate"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ prefix "to" @@ -919,29 +899,10 @@ let commands_rw () = ~name:"dlgt" ~desc:"new delegate of the contract" @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + (fun (fee, dry_run, verbose_signing, simulation, fee_parameter) (_, contract) delegate (cctxt : Protocol_client_context.full) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in match contract with | Originated _ -> Managed_contract.get_contract_manager cctxt contract @@ -989,40 +950,13 @@ let commands_rw () = command ~group ~desc:"Withdraw the delegate from a contract." - (args9 - fee_arg - dry_run_switch - verbose_signing_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) (prefixes ["withdraw"; "delegate"; "from"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + (fun (fee, dry_run, verbose_signing, fee_parameter) (_, contract) (cctxt : Protocol_client_context.full) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in match contract with | Originated _ -> Managed_contract.get_contract_manager cctxt contract @@ -1068,7 +1002,7 @@ let commands_rw () = command ~group ~desc:"Launch a smart contract on the blockchain." - (args15 + (args10 fee_arg dry_run_switch verbose_signing_switch @@ -1078,12 +1012,7 @@ let commands_rw () = (Client_keys.force_switch ()) init_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args) (prefixes ["originate"; "contract"] @@ RawContractAlias.fresh_alias_param ~name:"new" @@ -1110,12 +1039,7 @@ let commands_rw () = force, initial_storage, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) alias_name balance (_, source) @@ -1130,16 +1054,6 @@ let commands_rw () = "only implicit accounts can be the source of an origination" | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in originate_contract cctxt ~chain:cctxt#chain @@ -1177,7 +1091,7 @@ let commands_rw () = ~desc: "Execute multiple transfers from a single source account.\n\ If one of the transfers fails, none of them get executed." - (args17 + (args12 default_fee_arg dry_run_switch verbose_signing_switch @@ -1187,12 +1101,7 @@ let commands_rw () = counter_arg default_arg_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args default_entrypoint_arg replace_by_fees_arg) (prefixes ["multiple"; "transfers"; "from"] @@ -1220,27 +1129,12 @@ let commands_rw () = counter, arg, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, entrypoint, replace_by_fees ) (_, source) operations_json cctxt -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in let prepare i = prepare_batch_operation cctxt @@ -1326,7 +1220,7 @@ let commands_rw () = command ~group ~desc:"Transfer tokens / call a smart contract." - (args19 + (args14 fee_arg dry_run_switch verbose_signing_switch @@ -1337,12 +1231,7 @@ let commands_rw () = counter_arg arg_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args entrypoint_arg replace_by_fees_arg successor_level_arg) @@ -1367,12 +1256,7 @@ let commands_rw () = counter, arg, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, entrypoint, replace_by_fees, successor_level ) @@ -1395,31 +1279,21 @@ let commands_rw () = counter, arg, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, entrypoint, replace_by_fees, successor_level )); command ~group ~desc:"Register a global constant" - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["register"; "global"; "constant"] @@ global_constant_param ~name:"expression" @@ -1435,14 +1309,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) global_constant_str (_, source) cctxt -> @@ -1451,16 +1320,6 @@ let commands_rw () = failwith "Only implicit accounts can register global constants" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in register_global_constant cctxt ~chain:cctxt#chain @@ -1488,7 +1347,7 @@ let commands_rw () = command ~group ~desc:"Call a smart contract (same as 'transfer 0')." - (args19 + (args14 fee_arg dry_run_switch verbose_signing_switch @@ -1499,12 +1358,7 @@ let commands_rw () = counter_arg arg_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args entrypoint_arg replace_by_fees_arg successor_level_arg) @@ -1527,12 +1381,7 @@ let commands_rw () = counter, arg, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, entrypoint, replace_by_fees, successor_level ) @@ -1555,58 +1404,24 @@ let commands_rw () = counter, arg, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, entrypoint, replace_by_fees, successor_level )); command ~group ~desc:"Reveal the public key of the contract manager." - (args9 - fee_arg - dry_run_switch - verbose_signing_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) (prefixes ["reveal"; "key"; "for"] @@ ContractAlias.alias_param ~name:"src" ~desc:"name of the source contract" @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) - (_, (source : Contract.t)) - cctxt -> + (fun (fee, dry_run, verbose_signing, fee_parameter) (_, source) cctxt -> match source with | Originated _ -> failwith "only implicit accounts can be revealed" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in reveal cctxt ~dry_run @@ -1624,42 +1439,13 @@ let commands_rw () = command ~group ~desc:"Register the public key hash as a delegate." - (args9 - fee_arg - dry_run_switch - verbose_signing_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + (args4 fee_arg dry_run_switch verbose_signing_switch fee_parameter_args) (prefixes ["register"; "key"] @@ Public_key_hash.source_param ~name:"mgr" ~desc:"the delegate key" @@ prefixes ["as"; "delegate"] @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) - src_pkh - cctxt -> + (fun (fee, dry_run, verbose_signing, fee_parameter) src_pkh cctxt -> Client_keys.get_key cctxt src_pkh >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in register_as_delegate cctxt ~chain:cctxt#chain @@ -2000,17 +1786,12 @@ let commands_rw () = command ~group ~desc:"Set the deposits limit of a registered delegate." - (args10 + (args5 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args) (prefixes ["set"; "deposits"; "limit"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ prefix "to" @@ -2018,29 +1799,10 @@ let commands_rw () = ~name:"deposits limit" ~desc:"the maximum amount of frozen deposits" @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + (fun (fee, dry_run, verbose_signing, simulation, fee_parameter) (_, contract) limit (cctxt : Protocol_client_context.full) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in match contract with | Originated _ -> cctxt#error @@ -2069,42 +1831,18 @@ let commands_rw () = command ~group ~desc:"Remove the deposits limit of a registered delegate." - (args10 + (args5 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args) (prefixes ["unset"; "deposits"; "limit"; "for"] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) - (fun ( fee, - dry_run, - verbose_signing, - simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + (fun (fee, dry_run, verbose_signing, simulation, fee_parameter) (_, contract) (cctxt : Protocol_client_context.full) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in match contract with | Originated _ -> cctxt#error @@ -2133,19 +1871,14 @@ let commands_rw () = command ~group ~desc:"Launch a new transaction rollup." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["originate"; "tx"; "rollup"] @@ prefix "from" @@ ContractAlias.destination_param @@ -2156,14 +1889,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) (_, source) cctxt -> match source with @@ -2171,16 +1899,6 @@ let commands_rw () = failwith "Only implicit accounts can originate transaction rollups" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in originate_tx_rollup cctxt ~chain:cctxt#chain @@ -2201,19 +1919,14 @@ let commands_rw () = command ~group ~desc:"Submit a batch of transaction rollup operations." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["submit"; "tx"; "rollup"; "batch"] @@ Clic.param ~name:"batch" @@ -2233,14 +1946,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) content tx_rollup (_, source) @@ -2251,16 +1959,6 @@ let commands_rw () = "Only implicit accounts can submit transaction rollup batches" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in submit_tx_rollup_batch cctxt ~chain:cctxt#chain @@ -2286,19 +1984,14 @@ let commands_rw () = "Commit to a transaction rollup for an inbox and level.\n\n\ The provided list of message result hash must be ordered in the same \ way the messages were ordered in the inbox." - (args13 + (args8 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg (Tx_rollup.commitment_hash_arg ~long:"predecessor-hash" ~usage: @@ -2325,14 +2018,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, counter, - force_low_fee, - fee_cap, - burn_cap, predecessor ) tx_rollup (_, source) @@ -2346,16 +2034,6 @@ let commands_rw () = "Only implicit accounts can submit transaction rollup commitments" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in submit_tx_rollup_commitment cctxt ~chain:cctxt#chain @@ -2381,19 +2059,14 @@ let commands_rw () = command ~group ~desc:"Finalize a commitment of an transaction rollup." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch - simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args + simulate_switch + counter_arg) (prefixes ["finalize"; "commitment"; "of"; "tx"; "rollup"] @@ Tx_rollup.tx_rollup_address_param ~usage:"Tx rollup that have his commitment finalized." @@ -2405,15 +2078,10 @@ let commands_rw () = (fun ( fee, dry_run, verbose_signing, - simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter, + simulation, + counter ) tx_rollup (_, source) cctxt -> @@ -2422,16 +2090,6 @@ let commands_rw () = failwith "Only implicit accounts can finalize commitments" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in submit_tx_rollup_finalize_commitment cctxt ~chain:cctxt#chain @@ -2453,19 +2111,14 @@ let commands_rw () = command ~group ~desc:"Recover commitment bond from an transaction rollup." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["recover"; "bond"; "of"] @@ ContractAlias.destination_param ~name:"src" @@ -2477,14 +2130,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) (_, source) tx_rollup cctxt -> @@ -2493,16 +2141,6 @@ let commands_rw () = failwith "Only implicit accounts can deposit/recover bonds" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in submit_tx_rollup_return_bond cctxt ~chain:cctxt#chain @@ -2524,19 +2162,14 @@ let commands_rw () = command ~group ~desc:"Remove a commitment from an transaction rollup." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["remove"; "commitment"; "of"; "tx"; "rollup"] @@ Tx_rollup.tx_rollup_address_param ~usage:"Tx rollup that have his commitment removed." @@ -2549,14 +2182,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) tx_rollup (_, source) cctxt -> @@ -2565,16 +2193,6 @@ let commands_rw () = failwith "Only implicit accounts can remove commitments." | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in submit_tx_rollup_remove_commitment cctxt ~chain:cctxt#chain @@ -2596,19 +2214,14 @@ let commands_rw () = command ~group ~desc:"Reject a commitment of an transaction rollup." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["reject"; "commitment"; "of"; "tx"; "rollup"] @@ Tx_rollup.tx_rollup_address_param ~usage:"Tx rollup that have one of his commitment rejected." @@ -2665,14 +2278,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) tx_rollup level rejected_message_result_hash @@ -2693,16 +2301,6 @@ let commands_rw () = commitments." | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in submit_tx_rollup_rejection cctxt ~chain:cctxt#chain @@ -2741,19 +2339,14 @@ let commands_rw () = See transaction rollups documentation for more information.\n\n\ The provided list of ticket information must be ordered as in \ withdrawal list computed by the application of the message." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["dispatch"; "tickets"; "of"; "tx"; "rollup"] @@ Tx_rollup.tx_rollup_address_param ~usage:"Tx rollup which have some tickets dispatched." @@ -2788,14 +2381,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) tx_rollup (_, source) level @@ -2811,16 +2399,6 @@ let commands_rw () = rollup." | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in tx_rollup_dispatch_tickets cctxt ~chain:cctxt#chain @@ -2847,19 +2425,14 @@ let commands_rw () = command ~group ~desc:"Transfer tickets from an implicit account to a contract." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefix "transfer" @@ non_negative_z_param ~name:"qty" ~desc:"Amount of tickets to transfer." @@ prefixes ["tickets"; "from"] @@ -2894,14 +2467,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) amount (_, source) (_, destination) @@ -2915,16 +2483,6 @@ let commands_rw () = failwith "Only implicit accounts can transfer tickets." | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in transfer_ticket cctxt ~chain:cctxt#chain @@ -2951,19 +2509,14 @@ let commands_rw () = command ~group ~desc:"Originate a new smart-contract rollup." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["originate"; "sc"; "rollup"; "from"] @@ ContractAlias.destination_param ~name:"src" @@ -2983,14 +2536,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) (_, source) pvm boot_sector @@ -3001,16 +2549,6 @@ let commands_rw () = "Only implicit accounts can originate smart-contract rollups" | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in let (module R : Sc_rollups.PVM.S) = pvm in boot_sector pvm >>=? fun boot_sector -> sc_rollup_originate @@ -3035,19 +2573,14 @@ let commands_rw () = command ~group ~desc:"Send one or more messages to a smart-contract rollup." - (args12 + (args7 fee_arg dry_run_switch verbose_signing_switch simulate_switch - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg + fee_parameter_args storage_limit_arg - counter_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + counter_arg) (prefixes ["send"; "sc"; "rollup"; "message"] @@ param ~name:"messages" @@ -3070,14 +2603,9 @@ let commands_rw () = dry_run, verbose_signing, simulation, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, + fee_parameter, storage_limit, - counter, - force_low_fee, - fee_cap, - burn_cap ) + counter ) messages (_, source) rollup @@ -3097,16 +2625,6 @@ let commands_rw () = | messages -> return messages)) >>=? fun messages -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in sc_rollup_add_messages cctxt ~chain:cctxt#chain diff --git a/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml index 912444dd68f2..624ef6f7d449 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml @@ -79,7 +79,7 @@ let callback_entrypoint_arg = string_parameter let contract_call_options = - Clic.args14 + Clic.args9 tez_amount_arg fee_arg Client_proto_context_commands.dry_run_switch @@ -88,15 +88,10 @@ let contract_call_options = storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args let contract_view_options = - Clic.args15 + Clic.args10 callback_entrypoint_arg tez_amount_arg fee_arg @@ -106,12 +101,7 @@ let contract_view_options = storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args let view_options = Clic.args3 @@ -275,12 +265,7 @@ let commands_ro () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, contract) (_, addr) (_, callback) @@ -290,16 +275,6 @@ let commands_ro () : #Protocol_client_context.full Clic.command list = let action = Client_proto_fa12.Get_balance (addr, (callback, callback_entrypoint)) in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_fa12.call_contract cctxt ~chain:cctxt#chain @@ -352,12 +327,7 @@ let commands_ro () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, contract) (_, src) (_, dst) @@ -369,16 +339,6 @@ let commands_ro () : #Protocol_client_context.full Clic.command list = Client_proto_fa12.Get_allowance (src, dst, (callback, callback_entrypoint)) in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_fa12.call_contract cctxt ~chain:cctxt#chain @@ -428,12 +388,7 @@ let commands_ro () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, contract) (_, addr) (_, callback) @@ -443,16 +398,6 @@ let commands_ro () : #Protocol_client_context.full Clic.command list = let action = Client_proto_fa12.Get_total_supply (callback, callback_entrypoint) in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_fa12.call_contract cctxt ~chain:cctxt#chain @@ -486,7 +431,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = command ~group ~desc:"Transfer tokens between two given accounts" - (Clic.args15 + (Clic.args10 as_arg tez_amount_arg fee_arg @@ -496,12 +441,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args) (prefixes ["from"; "fa1.2"; "contract"] @@ token_contract_param () @@ prefix "transfer" @@ amount_param () @@ prefix "from" @@ from_param () @@ prefix "to" @@ to_param () @@ stop @@ -515,12 +455,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, contract) amount src @@ -530,16 +465,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = get_contract_caller_keys cctxt caller >>=? fun (source, caller_pk, caller_sk) -> let action = Client_proto_fa12.Transfer (snd src, dst, amount) in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_fa12.call_contract cctxt ~chain:cctxt#chain @@ -584,12 +509,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, contract) (_, source) amount @@ -598,16 +518,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = get_contract_caller_keys cctxt source >>=? fun (source, src_pk, src_sk) -> let action = Client_proto_fa12.Approve (dst, amount) in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_fa12.call_contract cctxt ~chain:cctxt#chain @@ -637,7 +547,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc: "Execute multiple token transfers from a single source account. If \ one of the token transfers fails, none of them are executed." - (args14 + (args9 default_fee_arg as_arg Client_proto_context_commands.dry_run_switch @@ -646,12 +556,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = default_storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args) (prefixes ["multiple"; "fa1.2"; "transfers"; "from"] @@ alias_param ~name:"src" @@ -681,26 +586,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) src operations_json cctxt -> let (_, caller) = Option.value ~default:src as_address in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in match Data_encoding.Json.destruct (Data_encoding.list Client_proto_fa12.token_transfer_encoding) diff --git a/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml index 1a5e5922deaa..460ef742c905 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml @@ -74,7 +74,7 @@ let bytes_param ~name ~desc = Clic.param ~name ~desc Client_proto_args.bytes_parameter let transfer_options = - Clic.args15 + Clic.args10 Client_proto_args.fee_arg Client_proto_context_commands.dry_run_switch Client_proto_context_commands.verbose_signing_switch @@ -83,16 +83,11 @@ let transfer_options = Client_proto_args.counter_arg Client_proto_args.arg_arg Client_proto_args.no_print_source_flag - Client_proto_args.minimal_fees_arg - Client_proto_args.minimal_nanotez_per_byte_arg - Client_proto_args.minimal_nanotez_per_gas_unit_arg - Client_proto_args.force_low_fee_arg - Client_proto_args.fee_cap_arg - Client_proto_args.burn_cap_arg + Client_proto_args.fee_parameter_args Client_proto_args.entrypoint_arg let non_transfer_options = - Clic.args13 + Clic.args8 Client_proto_args.fee_arg Client_proto_context_commands.dry_run_switch Client_proto_context_commands.verbose_signing_switch @@ -100,12 +95,7 @@ let non_transfer_options = Client_proto_args.storage_limit_arg Client_proto_args.counter_arg Client_proto_args.no_print_source_flag - Client_proto_args.minimal_fees_arg - Client_proto_args.minimal_nanotez_per_byte_arg - Client_proto_args.minimal_nanotez_per_gas_unit_arg - Client_proto_args.force_low_fee_arg - Client_proto_args.fee_cap_arg - Client_proto_args.burn_cap_arg + Client_proto_args.fee_parameter_args let prepare_command_display prepared_command bytes_only = if bytes_only then @@ -198,7 +188,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = command ~group ~desc:"Originate a new multisig contract." - (args14 + (args9 Client_proto_args.fee_arg Client_proto_context_commands.dry_run_switch Client_proto_args.gas_limit_arg @@ -206,13 +196,8 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = Client_proto_args.delegate_arg (Client_keys.force_switch ()) Client_proto_args.no_print_source_flag - Client_proto_args.minimal_fees_arg - Client_proto_args.minimal_nanotez_per_byte_arg - Client_proto_args.minimal_nanotez_per_gas_unit_arg - Client_proto_args.force_low_fee_arg - Client_proto_args.fee_cap_arg - Client_proto_context_commands.verbose_signing_switch - Client_proto_args.burn_cap_arg) + Client_proto_args.fee_parameter_args + Client_proto_context_commands.verbose_signing_switch) (prefixes ["deploy"; "multisig"] @@ Client_proto_contracts.RawContractAlias.fresh_alias_param ~name:"new_multisig" @@ -236,13 +221,8 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = delegate, force, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - verbose_signing, - burn_cap ) + fee_parameter, + verbose_signing ) alias_name balance (_, source) @@ -260,16 +240,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = "only implicit accounts can be the source of an origination" | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in List.map_es (fun (pk_uri, _) -> Client_keys.public_key pk_uri) keys @@ -505,12 +475,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = counter, parameter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, entrypoint ) (_, multisig_contract) amount @@ -533,16 +498,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = "only implicit accounts can be the source of a contract call" | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_multisig.call_multisig cctxt ~chain:cctxt#chain @@ -601,12 +556,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, multisig_contract) lambda (_, source) @@ -618,16 +568,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = "only implicit accounts can be the source of a contract call" | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Lwt.return @@ Micheline_parser.no_parsing_error @@ Michelson_v1_parser.parse_expression lambda >>=? fun {expanded = lambda; _} -> @@ -683,12 +623,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, multisig_contract) delegate (_, source) @@ -700,16 +635,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = "only implicit accounts can be the source of a contract call" | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_multisig.call_multisig cctxt ~chain:cctxt#chain @@ -758,12 +683,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, multisig_contract) (_, source) signatures @@ -774,16 +694,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = "only implicit accounts can be the source of a contract call" | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_multisig.call_multisig cctxt ~chain:cctxt#chain @@ -835,12 +745,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) (_, multisig_contract) new_threshold new_keys @@ -857,16 +762,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = (fun (pk_uri, _) -> Client_keys.public_key pk_uri) new_keys >>=? fun keys -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_multisig.call_multisig cctxt ~chain:cctxt#chain @@ -928,12 +823,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) bytes (_, multisig_contract) (_, source) @@ -945,16 +835,6 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = "only implicit accounts can be the source of a contract call" | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_multisig.call_multisig_on_bytes cctxt ~chain:cctxt#chain diff --git a/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml b/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml index 106efb3162a1..33e2a97d7e09 100644 --- a/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml +++ b/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml @@ -145,7 +145,7 @@ let shield_cmd = command ~group ~desc:"Shield tokens from an implicit account to a Sapling address." - (args14 + (args9 fee_arg dry_run_switch verbose_signing_switch @@ -153,12 +153,7 @@ let shield_cmd = storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args message_arg) (prefixes ["sapling"; "shield"] @@ tez_param @@ -182,12 +177,7 @@ let shield_cmd = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, message ) amount (_, source) @@ -207,16 +197,6 @@ let shield_cmd = do_shield cctxt ?message contract_dst amount sapling_dst >>=? fun sapling_input -> let arg = sapling_transaction_as_arg sapling_input in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_context.transfer cctxt ~chain:cctxt#chain @@ -254,7 +234,7 @@ let unshield_cmd = command ~group ~desc:"Unshield tokens from a Sapling address to an implicit account." - (args13 + (args8 fee_arg dry_run_switch verbose_signing_switch @@ -262,12 +242,7 @@ let unshield_cmd = storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg) + fee_parameter_args) (prefixes ["sapling"; "unshield"] @@ tez_param ~name:"qty" @@ -292,12 +267,7 @@ let unshield_cmd = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap ) + fee_parameter ) amount (name, _sapling_uri) (_, tz_dst) @@ -316,24 +286,14 @@ let unshield_cmd = keys_of_implicit_account cctxt tz_dst >>=? fun (source, src_pk, src_sk) -> do_unshield cctxt contract_dst name stez source >>=? fun sapling_input -> let arg = sapling_transaction_as_arg sapling_input in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_context.transfer cctxt ~chain:cctxt#chain ~block:cctxt#block ~fee_parameter ~amount:Tez.zero - ~src_pk ~src_sk + ~src_pk ~destination:(Contract contract_dst) ~source ~arg @@ -375,7 +335,7 @@ let forge_shielded_cmd = command ~group ~desc:"Forge a sapling transaction and save it to a file." - (args16 + (args11 fee_arg dry_run_switch verbose_signing_switch @@ -383,12 +343,7 @@ let forge_shielded_cmd = storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args message_arg (file_arg sapling_transaction_file) json_switch) @@ -414,12 +369,7 @@ let forge_shielded_cmd = _storage_limit, _counter, _no_print_source, - _minimal_fees, - _minimal_nanotez_per_byte, - _minimal_nanotez_per_gas_unit, - _force_low_fee, - _fee_cap, - _burn_cap, + _fee_parameter, message, file, use_json_format ) @@ -457,7 +407,7 @@ let submit_shielded_cmd = command ~group ~desc:"Submit a forged sapling transaction." - (args14 + (args9 fee_arg dry_run_switch verbose_signing_switch @@ -465,12 +415,7 @@ let submit_shielded_cmd = storage_limit_arg counter_arg no_print_source_flag - minimal_fees_arg - minimal_nanotez_per_byte_arg - minimal_nanotez_per_gas_unit_arg - force_low_fee_arg - fee_cap_arg - burn_cap_arg + fee_parameter_args json_switch) (prefixes ["sapling"; "submit"] (* TODO: Add a dedicated abstracted Clic element to parse filenames, @@ -492,12 +437,7 @@ let submit_shielded_cmd = storage_limit, counter, no_print_source, - minimal_fees, - minimal_nanotez_per_byte, - minimal_nanotez_per_gas_unit, - force_low_fee, - fee_cap, - burn_cap, + fee_parameter, use_json_format ) filename (_, source) @@ -527,16 +467,6 @@ let submit_shielded_cmd = let chain = cctxt#chain and block = cctxt#block in keys_of_implicit_account cctxt source >>=? fun (source, src_pk, src_sk) -> let open Protocol.Alpha_context in - let fee_parameter = - { - Injection.minimal_fees; - minimal_nanotez_per_byte; - minimal_nanotez_per_gas_unit; - force_low_fee; - fee_cap; - burn_cap; - } - in Client_proto_context.transfer cctxt ~chain -- GitLab From 9158f49f94b27bfcd07822444ec8346411960b40 Mon Sep 17 00:00:00 2001 From: "G.B. Fefe" Date: Mon, 2 May 2022 11:16:51 +0200 Subject: [PATCH 4/4] Proto/Client: remove unrequired `Injection.dummy_fee_parameter` --- .../lib_client/client_proto_context.ml | 3 --- src/proto_alpha/lib_client/injection.ml | 18 ++++-------------- src/proto_alpha/lib_client/injection.mli | 4 +--- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index a0d44e0b42aa..ba34dc202c11 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -562,7 +562,6 @@ let inject_activate_operation cctxt ~chain ~block ?confirmations ?dry_run alias ?dry_run ~chain ~block - ~fee_parameter:Injection.dummy_fee_parameter contents >>=? fun (oph, op, result) -> (match confirmations with @@ -695,7 +694,6 @@ let submit_proposals ?dry_run ?verbose_signing (cctxt : #full) ~chain ~block ~chain ~block ?confirmations - ~fee_parameter:Injection.dummy_fee_parameter ?dry_run ~src_sk contents @@ -713,7 +711,6 @@ let submit_ballot ?dry_run ?verbose_signing (cctxt : #full) ~chain ~block ~chain ~block ?confirmations - ~fee_parameter:Injection.dummy_fee_parameter ?dry_run ~src_sk contents diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 6567240c6f4e..6606d7cf23d9 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -86,16 +86,6 @@ type fee_parameter = { burn_cap : Tez.t; } -let dummy_fee_parameter = - { - minimal_fees = Tez.zero; - minimal_nanotez_per_byte = Q.zero; - minimal_nanotez_per_gas_unit = Q.zero; - force_low_fee = false; - fee_cap = Tez.one; - burn_cap = Tez.zero; - } - (* Rounding up (see Z.cdiv) *) let z_mutez_of_q_nanotez (ntz : Q.t) = let q_mutez = Q.div ntz (Q.of_int 1000) in @@ -953,7 +943,7 @@ let tenderbake_adjust_confirmations (cctxt : #Client_context.full) = function *) let inject_operation_internal (type kind) cctxt ~chain ~block ?confirmations ?(dry_run = false) ?(simulation = false) ?(force = false) ?successor_level - ?branch ?src_sk ?verbose_signing ~fee_parameter + ?branch ?src_sk ?verbose_signing ?fee_parameter (contents : kind contents_list) = (if simulation then simulate cctxt ~chain ~block ?successor_level ?branch contents @@ -962,7 +952,7 @@ let inject_operation_internal (type kind) cctxt ~chain ~block ?confirmations cctxt ~chain ~block - ~fee_parameter + ?fee_parameter ?verbose_signing ?branch ?src_sk @@ -1083,7 +1073,7 @@ let inject_operation_internal (type kind) cctxt ~chain ~block ?confirmations let inject_operation (type kind) cctxt ~chain ~block ?confirmations ?(dry_run = false) ?(simulation = false) ?successor_level ?branch ?src_sk - ?verbose_signing ~fee_parameter (contents : kind contents_list) = + ?verbose_signing ?fee_parameter (contents : kind contents_list) = Tezos_client_base.Client_confirmations.wait_for_bootstrapped cctxt >>=? fun () -> inject_operation_internal @@ -1097,7 +1087,7 @@ let inject_operation (type kind) cctxt ~chain ~block ?confirmations ?branch ?src_sk ?verbose_signing - ~fee_parameter + ?fee_parameter (contents : kind contents_list) let prepare_manager_operation ~fee ~gas_limit ~storage_limit operation = diff --git a/src/proto_alpha/lib_client/injection.mli b/src/proto_alpha/lib_client/injection.mli index ae8067e96e32..fd1b1104a74b 100644 --- a/src/proto_alpha/lib_client/injection.mli +++ b/src/proto_alpha/lib_client/injection.mli @@ -39,8 +39,6 @@ type fee_parameter = { burn_cap : Tez.t; } -val dummy_fee_parameter : fee_parameter - val preapply : #Protocol_client_context.full -> chain:Shell_services.chain -> @@ -81,7 +79,7 @@ val inject_operation : ?branch:int -> ?src_sk:Client_keys.sk_uri -> ?verbose_signing:bool -> - fee_parameter:fee_parameter -> + ?fee_parameter:fee_parameter -> 'kind contents_list -> 'kind result_list tzresult Lwt.t -- GitLab