Client: fix for issue #161.
Use proper parsing for `--delegate` argument.
This commit is contained in:
parent
3d57055cca
commit
3765c39477
@ -79,6 +79,11 @@ module type Alias = sig
|
||||
?desc:string ->
|
||||
('a, (#Client_context.wallet as '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:
|
||||
#Client_context.wallet -> string list tzresult Lwt.t
|
||||
end
|
||||
@ -218,6 +223,40 @@ module Alias = functor (Entity : Entity) -> struct
|
||||
(parameter (fun (_ : < .. >) s -> return @@ Fresh s))
|
||||
next
|
||||
|
||||
let parse_source_string cctxt s =
|
||||
let read path =
|
||||
Lwt.catch
|
||||
(fun () ->
|
||||
Lwt_io.(with_file ~mode:Input path read) >>= fun content ->
|
||||
return content)
|
||||
(fun exn ->
|
||||
failwith
|
||||
"cannot read file (%s)" (Printexc.to_string exn))
|
||||
>>=? fun content ->
|
||||
of_source content in
|
||||
begin
|
||||
match String.split ~limit:1 ':' s with
|
||||
| [ "alias" ; alias ]->
|
||||
find cctxt alias
|
||||
| [ "text" ; text ] ->
|
||||
of_source text
|
||||
| [ "file" ; path ] ->
|
||||
read path
|
||||
| _ ->
|
||||
find cctxt s >>= function
|
||||
| Ok v -> return v
|
||||
| Error a_errs ->
|
||||
read s >>= function
|
||||
| Ok v -> return v
|
||||
| Error r_errs ->
|
||||
of_source s >>= function
|
||||
| Ok v -> return v
|
||||
| Error s_errs ->
|
||||
let all_errs =
|
||||
List.flatten [ a_errs ; r_errs ; s_errs ] in
|
||||
Lwt.return (Error all_errs)
|
||||
end
|
||||
|
||||
let source_param ?(name = "src") ?(desc = "source " ^ Entity.name) next =
|
||||
let desc =
|
||||
Format.asprintf
|
||||
@ -230,41 +269,29 @@ module Alias = functor (Entity : Entity) -> struct
|
||||
autodetect."
|
||||
desc Entity.name Entity.name Entity.name Entity.name Entity.name in
|
||||
param ~name ~desc
|
||||
(parameter (fun cctxt s ->
|
||||
let read path =
|
||||
Lwt.catch
|
||||
(fun () ->
|
||||
Lwt_io.(with_file ~mode:Input path read) >>= fun content ->
|
||||
return content)
|
||||
(fun exn ->
|
||||
failwith
|
||||
"cannot read file (%s)" (Printexc.to_string exn))
|
||||
>>=? fun content ->
|
||||
of_source content in
|
||||
begin
|
||||
match String.split ~limit:1 ':' s with
|
||||
| [ "alias" ; alias ]->
|
||||
find cctxt alias
|
||||
| [ "text" ; text ] ->
|
||||
of_source text
|
||||
| [ "file" ; path ] ->
|
||||
read path
|
||||
| _ ->
|
||||
find cctxt s >>= function
|
||||
| Ok v -> return v
|
||||
| Error a_errs ->
|
||||
read s >>= function
|
||||
| Ok v -> return v
|
||||
| Error r_errs ->
|
||||
of_source s >>= function
|
||||
| Ok v -> return v
|
||||
| Error s_errs ->
|
||||
let all_errs =
|
||||
List.flatten [ a_errs ; r_errs ; s_errs ] in
|
||||
Lwt.return (Error all_errs)
|
||||
end))
|
||||
(parameter parse_source_string)
|
||||
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 () =
|
||||
Clic.switch
|
||||
~long:"force" ~short:'f'
|
||||
|
@ -75,6 +75,11 @@ module type Alias = sig
|
||||
?desc:string ->
|
||||
('a, (#Client_context.wallet as '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:
|
||||
#Client_context.wallet -> string list tzresult Lwt.t
|
||||
end
|
||||
|
@ -75,12 +75,12 @@ let arg_arg =
|
||||
string_parameter
|
||||
|
||||
let delegate_arg =
|
||||
arg
|
||||
Client_keys.Public_key_hash.source_arg
|
||||
~long:"delegate"
|
||||
~placeholder:"identity"
|
||||
~doc:"delegate of the contract\n\
|
||||
Must be a known identity."
|
||||
string_parameter
|
||||
()
|
||||
|
||||
let source_arg =
|
||||
arg
|
||||
|
@ -17,7 +17,7 @@ val fee_arg: (Tez.t, 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 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 spendable_switch: (bool, Proto_alpha.full) Clic.arg
|
||||
val max_priority_arg: (int option, Proto_alpha.full) Clic.arg
|
||||
|
@ -16,10 +16,6 @@ open Client_proto_programs
|
||||
open Client_keys
|
||||
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
|
||||
| Error errs ->
|
||||
cctxt#warning "%a"
|
||||
@ -204,7 +200,6 @@ let commands () =
|
||||
new_contract (_, manager_pkh) balance (_, source) (cctxt : Proto_alpha.full) ->
|
||||
RawContractAlias.of_fresh cctxt force new_contract >>=? fun alias_name ->
|
||||
source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) ->
|
||||
get_pkh cctxt delegate >>=? fun delegate ->
|
||||
originate_account
|
||||
~fee
|
||||
?delegate
|
||||
@ -247,7 +242,6 @@ let commands () =
|
||||
RawContractAlias.of_fresh cctxt force alias_name >>=? fun alias_name ->
|
||||
Lwt.return (Micheline_parser.no_parsing_error program) >>=? fun { expanded = code } ->
|
||||
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
|
||||
~manager ~balance ~source ~src_pk ~src_sk ~code cctxt >>= fun errors ->
|
||||
report_michelson_errors ~no_print_source ~msg:"origination simulation failed" cctxt errors >>= function
|
||||
|
Loading…
Reference in New Issue
Block a user