Client: fix for issue #161.

Use proper parsing for `--delegate` argument.
This commit is contained in:
Grégoire Henry 2018-04-10 14:55:32 +02:00 committed by Benjamin Canou
parent 3d57055cca
commit 3765c39477
5 changed files with 68 additions and 42 deletions

View File

@ -79,6 +79,11 @@ module type Alias = sig
?desc:string -> ?desc:string ->
('a, (#Client_context.wallet as 'obj)) Clic.params -> ('a, (#Client_context.wallet as 'obj)) Clic.params ->
(t -> 'a, 'obj) Clic.params (t -> 'a, 'obj) Clic.params
val source_arg :
?long:string ->
?placeholder:string ->
?doc:string ->
unit -> (t option, (#Client_context.wallet as 'obj)) Clic.arg
val autocomplete: val autocomplete:
#Client_context.wallet -> string list tzresult Lwt.t #Client_context.wallet -> string list tzresult Lwt.t
end end
@ -218,19 +223,7 @@ module Alias = functor (Entity : Entity) -> struct
(parameter (fun (_ : < .. >) s -> return @@ Fresh s)) (parameter (fun (_ : < .. >) s -> return @@ Fresh s))
next next
let source_param ?(name = "src") ?(desc = "source " ^ Entity.name) next = let parse_source_string cctxt s =
let desc =
Format.asprintf
"%s\n\
Can be a %s name, a file or a raw %s literal. If the \
parameter is not the name of an existing %s, the client will \
look for a file containing a %s, and if it does not exist, \
the argument will be read as a raw %s.\n\
Use 'alias:name', 'file:path' or 'text:literal' to disable \
autodetect."
desc Entity.name Entity.name Entity.name Entity.name Entity.name in
param ~name ~desc
(parameter (fun cctxt s ->
let read path = let read path =
Lwt.catch Lwt.catch
(fun () -> (fun () ->
@ -262,9 +255,43 @@ module Alias = functor (Entity : Entity) -> struct
let all_errs = let all_errs =
List.flatten [ a_errs ; r_errs ; s_errs ] in List.flatten [ a_errs ; r_errs ; s_errs ] in
Lwt.return (Error all_errs) Lwt.return (Error all_errs)
end)) end
let source_param ?(name = "src") ?(desc = "source " ^ Entity.name) next =
let desc =
Format.asprintf
"%s\n\
Can be a %s name, a file or a raw %s literal. If the \
parameter is not the name of an existing %s, the client will \
look for a file containing a %s, and if it does not exist, \
the argument will be read as a raw %s.\n\
Use 'alias:name', 'file:path' or 'text:literal' to disable \
autodetect."
desc Entity.name Entity.name Entity.name Entity.name Entity.name in
param ~name ~desc
(parameter parse_source_string)
next next
let source_arg
?(long = "source " ^ Entity.name)
?(placeholder = "src")
?(doc = "") () =
let doc =
Format.asprintf
"%s\n\
Can be a %s name, a file or a raw %s literal. If the \
parameter is not the name of an existing %s, the client will \
look for a file containing a %s, and if it does not exist, \
the argument will be read as a raw %s.\n\
Use 'alias:name', 'file:path' or 'text:literal' to disable \
autodetect."
doc Entity.name Entity.name Entity.name Entity.name Entity.name in
arg
~long
~placeholder
~doc
(parameter parse_source_string)
let force_switch () = let force_switch () =
Clic.switch Clic.switch
~long:"force" ~short:'f' ~long:"force" ~short:'f'

View File

@ -75,6 +75,11 @@ module type Alias = sig
?desc:string -> ?desc:string ->
('a, (#Client_context.wallet as 'obj)) Clic.params -> ('a, (#Client_context.wallet as 'obj)) Clic.params ->
(t -> 'a, 'obj) Clic.params (t -> 'a, 'obj) Clic.params
val source_arg :
?long:string ->
?placeholder:string ->
?doc:string ->
unit -> (t option, (#Client_context.wallet as 'obj)) Clic.arg
val autocomplete: val autocomplete:
#Client_context.wallet -> string list tzresult Lwt.t #Client_context.wallet -> string list tzresult Lwt.t
end end

View File

@ -75,12 +75,12 @@ let arg_arg =
string_parameter string_parameter
let delegate_arg = let delegate_arg =
arg Client_keys.Public_key_hash.source_arg
~long:"delegate" ~long:"delegate"
~placeholder:"identity" ~placeholder:"identity"
~doc:"delegate of the contract\n\ ~doc:"delegate of the contract\n\
Must be a known identity." Must be a known identity."
string_parameter ()
let source_arg = let source_arg =
arg arg

View File

@ -17,7 +17,7 @@ val fee_arg: (Tez.t, Proto_alpha.full) Clic.arg
val arg_arg: (string, Proto_alpha.full) Clic.arg val arg_arg: (string, Proto_alpha.full) Clic.arg
val source_arg: (string option, Proto_alpha.full) Clic.arg val source_arg: (string option, Proto_alpha.full) Clic.arg
val delegate_arg: (string option, Proto_alpha.full) Clic.arg val delegate_arg: (Ed25519.Public_key_hash.t option, Proto_alpha.full) Clic.arg
val delegatable_switch: (bool, Proto_alpha.full) Clic.arg val delegatable_switch: (bool, Proto_alpha.full) Clic.arg
val spendable_switch: (bool, Proto_alpha.full) Clic.arg val spendable_switch: (bool, Proto_alpha.full) Clic.arg
val max_priority_arg: (int option, Proto_alpha.full) Clic.arg val max_priority_arg: (int option, Proto_alpha.full) Clic.arg

View File

@ -16,10 +16,6 @@ open Client_proto_programs
open Client_keys open Client_keys
open Client_proto_args open Client_proto_args
let get_pkh cctxt = function
| None -> return None
| Some x -> Public_key_hash.find_opt cctxt x
let report_michelson_errors ?(no_print_source=false) ~msg (cctxt : #Client_context.printer) = function let report_michelson_errors ?(no_print_source=false) ~msg (cctxt : #Client_context.printer) = function
| Error errs -> | Error errs ->
cctxt#warning "%a" cctxt#warning "%a"
@ -204,7 +200,6 @@ let commands () =
new_contract (_, manager_pkh) balance (_, source) (cctxt : Proto_alpha.full) -> new_contract (_, manager_pkh) balance (_, source) (cctxt : Proto_alpha.full) ->
RawContractAlias.of_fresh cctxt force new_contract >>=? fun alias_name -> RawContractAlias.of_fresh cctxt force new_contract >>=? fun alias_name ->
source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) -> source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) ->
get_pkh cctxt delegate >>=? fun delegate ->
originate_account originate_account
~fee ~fee
?delegate ?delegate
@ -247,7 +242,6 @@ let commands () =
RawContractAlias.of_fresh cctxt force alias_name >>=? fun alias_name -> RawContractAlias.of_fresh cctxt force alias_name >>=? fun alias_name ->
Lwt.return (Micheline_parser.no_parsing_error program) >>=? fun { expanded = code } -> Lwt.return (Micheline_parser.no_parsing_error program) >>=? fun { expanded = code } ->
source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) -> source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) ->
get_pkh cctxt delegate >>=? fun delegate ->
originate_contract ~fee ~delegate ~delegatable ~spendable ~initial_storage originate_contract ~fee ~delegate ~delegatable ~spendable ~initial_storage
~manager ~balance ~source ~src_pk ~src_sk ~code cctxt >>= fun errors -> ~manager ~balance ~source ~src_pk ~src_sk ~code cctxt >>= fun errors ->
report_michelson_errors ~no_print_source ~msg:"origination simulation failed" cctxt errors >>= function report_michelson_errors ~no_print_source ~msg:"origination simulation failed" cctxt errors >>= function