Client: add global option --wait
This commit is contained in:
parent
72e31287d1
commit
ee5373d960
@ -411,7 +411,8 @@ let run ?(rpc_port=18731) () =
|
||||
let open Client_config in
|
||||
let {block; _} = default_cli_args in
|
||||
let (cctxt : #Tezos_client_base.Client_context.full) =
|
||||
new Client_context_unix.unix_full ~block ~base_dir: "/" ~rpc_config
|
||||
new Client_context_unix.unix_full
|
||||
~block ~confirmations:None ~base_dir: "/" ~rpc_config
|
||||
in
|
||||
|
||||
let print_header () =
|
||||
|
@ -8,6 +8,8 @@ source $test_dir/test_lib.inc.sh "$@"
|
||||
start_node 1
|
||||
activate_alpha
|
||||
|
||||
$client -w none config update
|
||||
|
||||
sleep 2
|
||||
|
||||
#tests for the rpc service raw_context
|
||||
@ -83,8 +85,8 @@ bake_after $client transfer 400,000 from bootstrap5 to bootstrap1 -fee 0
|
||||
bake_after $client transfer 400,000 from bootstrap1 to bootstrap5 -fee 0
|
||||
$client get balance for bootstrap5 | assert "4,000,000 ꜩ"
|
||||
|
||||
bake_after $client activate account $key4 with king_commitment.json --no-confirmation
|
||||
bake_after $client activate account $key5 with queen_commitment.json --no-confirmation
|
||||
bake_after $client activate account $key4 with king_commitment.json
|
||||
bake_after $client activate account $key5 with queen_commitment.json
|
||||
|
||||
$client get balance for $key4 | assert "23,932,454.669,343 ꜩ"
|
||||
$client get balance for $key5 | assert "72,954,577.464,032 ꜩ"
|
||||
|
@ -9,6 +9,8 @@ source $test_dir/test_lib.inc.sh "$@"
|
||||
start_node 1
|
||||
activate_alpha
|
||||
|
||||
$client -w none config update
|
||||
|
||||
bake
|
||||
|
||||
key1=foo
|
||||
|
@ -17,7 +17,7 @@ show_logs="no"
|
||||
|
||||
sleep 2
|
||||
|
||||
dictator_secret="edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
|
||||
dictator_secret="unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
|
||||
|
||||
# autogenerated from the demo source
|
||||
protocol_version="Ps1ZDZdgRP4PFDkzmFpiYtE7gJHioavCMxC96i9zJsK6URwSXSJ"
|
||||
|
@ -17,7 +17,7 @@ show_logs="no"
|
||||
|
||||
sleep 2
|
||||
|
||||
dictator_secret="edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
|
||||
dictator_secret="unencrypted:edsk31vznjHSSpGExDMHYASz45VZqXN4DPxvsa4hAyY8dHM28cZzp6"
|
||||
|
||||
# autogenerated from the demo source
|
||||
protocol_version="Ps1ZDZdgRP4PFDkzmFpiYtE7gJHioavCMxC96i9zJsK6URwSXSJ"
|
||||
|
@ -21,6 +21,7 @@ for client in "${client_instances[@]}"; do
|
||||
echo
|
||||
echo "### $client bootstrapped"
|
||||
echo
|
||||
$client -w none config update
|
||||
$client bootstrapped
|
||||
echo
|
||||
done
|
||||
|
@ -729,6 +729,11 @@ let args10 spec1 spec2 spec3 spec4 spec5 spec6 spec7 spec8 spec9 spec10 =
|
||||
{ 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 }
|
||||
|
||||
(* Some combinators for writing commands concisely. *)
|
||||
let param ~name ~desc kind next = Param (name, desc, kind, next)
|
||||
|
@ -168,6 +168,12 @@ val args10 : ('a, 'ctx) arg -> ('b, 'ctx) arg -> ('c, 'ctx) arg -> ('d, 'ctx) ar
|
||||
('i, 'ctx) arg -> ('j, 'ctx) arg ->
|
||||
('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j, 'ctx) options
|
||||
|
||||
(** Include 11 optional parameters *)
|
||||
val args11 : ('a, 'ctx) arg -> ('b, 'ctx) arg -> ('c, 'ctx) arg -> ('d, 'ctx) arg ->
|
||||
('e, 'ctx) arg -> ('f, 'ctx) arg -> ('g, 'ctx) arg -> ('h, 'ctx) arg ->
|
||||
('i, 'ctx) arg -> ('j, 'ctx) arg -> ('k, 'ctx) arg ->
|
||||
('a * 'b * 'c * 'd * 'e * 'f * 'g * 'h * 'i * 'j * 'k, 'ctx) options
|
||||
|
||||
(** {2 Parameter based command lines} *)
|
||||
|
||||
(** Type of parameters for a command *)
|
||||
|
@ -55,6 +55,7 @@ end
|
||||
|
||||
class type block = object
|
||||
method block : Block_services.block
|
||||
method confirmations : int option
|
||||
end
|
||||
|
||||
class type io_wallet = object
|
||||
@ -80,6 +81,7 @@ end
|
||||
class proxy_context (obj : full) = object
|
||||
method base = obj#base
|
||||
method block = obj#block
|
||||
method confirmations = obj#confirmations
|
||||
method answer : type a. (a, unit) lwt_format -> a = obj#answer
|
||||
method call_service :
|
||||
'm 'p 'q 'i 'o.
|
||||
|
@ -35,6 +35,7 @@ end
|
||||
|
||||
class type block = object
|
||||
method block : Block_services.block
|
||||
method confirmations : int option
|
||||
end
|
||||
|
||||
class type io_wallet = object
|
||||
|
@ -13,6 +13,7 @@ type error += Invalid_block_argument of string
|
||||
type error += Invalid_protocol_argument of string
|
||||
type error += Invalid_port_arg of string
|
||||
type error += Invalid_remote_signer_argument of string
|
||||
type error += Invalid_wait_arg of string
|
||||
let () =
|
||||
register_error_kind
|
||||
`Branch
|
||||
@ -57,7 +58,18 @@ let () =
|
||||
Format.fprintf ppf "Value '%s' is not a valid URI." s)
|
||||
Data_encoding.(obj1 (req "value" string))
|
||||
(function Invalid_remote_signer_argument s -> Some s | _ -> None)
|
||||
(fun s -> Invalid_remote_signer_argument s)
|
||||
(fun s -> Invalid_remote_signer_argument s) ;
|
||||
register_error_kind
|
||||
`Branch
|
||||
~id: "invalidWaitArgument"
|
||||
~title: "Bad Wait Argument"
|
||||
~description: "Wait argument could not be parsed"
|
||||
~pp:
|
||||
(fun ppf s ->
|
||||
Format.fprintf ppf "Value %s is not a valid number of confirmation, nor 'none'." s)
|
||||
Data_encoding.(obj1 (req "value" string))
|
||||
(function Invalid_wait_arg s -> Some s | _ -> None)
|
||||
(fun s -> Invalid_wait_arg s)
|
||||
|
||||
let home = try Sys.getenv "HOME" with Not_found -> "/root"
|
||||
|
||||
@ -77,6 +89,7 @@ module Cfg_file = struct
|
||||
tls: bool ;
|
||||
web_port: int ;
|
||||
remote_signer: Uri.t option ;
|
||||
confirmations: int option ;
|
||||
}
|
||||
|
||||
let default = {
|
||||
@ -86,28 +99,33 @@ module Cfg_file = struct
|
||||
tls = false ;
|
||||
web_port = 8080 ;
|
||||
remote_signer = None ;
|
||||
confirmations = Some 0 ;
|
||||
}
|
||||
|
||||
open Data_encoding
|
||||
|
||||
let encoding =
|
||||
conv
|
||||
(fun { base_dir ; node_addr ; node_port ; tls ; web_port ; remote_signer } ->
|
||||
(base_dir, Some node_addr, Some node_port,
|
||||
Some tls, Some web_port, remote_signer))
|
||||
(fun (base_dir, node_addr, node_port, tls, web_port, remote_signer) ->
|
||||
let node_addr = Option.unopt ~default:default.node_addr node_addr in
|
||||
let node_port = Option.unopt ~default:default.node_port node_port in
|
||||
let tls = Option.unopt ~default:default.tls tls in
|
||||
let web_port = Option.unopt ~default:default.web_port web_port in
|
||||
{ base_dir ; node_addr ; node_port ; tls ; web_port ; remote_signer })
|
||||
(obj6
|
||||
(fun { base_dir ; node_addr ; node_port ; tls ; web_port ;
|
||||
remote_signer ; confirmations } ->
|
||||
(base_dir, Some node_addr, Some node_port,
|
||||
Some tls, Some web_port, remote_signer, confirmations))
|
||||
(fun (base_dir, node_addr, node_port, tls, web_port,
|
||||
remote_signer, confirmations) ->
|
||||
let node_addr = Option.unopt ~default:default.node_addr node_addr in
|
||||
let node_port = Option.unopt ~default:default.node_port node_port in
|
||||
let tls = Option.unopt ~default:default.tls tls in
|
||||
let web_port = Option.unopt ~default:default.web_port web_port in
|
||||
{ base_dir ; node_addr ; node_port ; tls ; web_port ;
|
||||
remote_signer ; confirmations })
|
||||
(obj7
|
||||
(req "base_dir" string)
|
||||
(opt "node_addr" string)
|
||||
(opt "node_port" int16)
|
||||
(opt "tls" bool)
|
||||
(opt "web_port" int16)
|
||||
(opt "remote_signer" RPC_client.uri_encoding))
|
||||
(opt "remote_signer" RPC_client.uri_encoding)
|
||||
(opt "confirmations" int8))
|
||||
|
||||
let from_json json =
|
||||
Data_encoding.Json.destruct encoding json
|
||||
@ -124,6 +142,7 @@ end
|
||||
|
||||
type cli_args = {
|
||||
block: Block_services.block ;
|
||||
confirmations: int option ;
|
||||
protocol: Protocol_hash.t option ;
|
||||
print_timings: bool ;
|
||||
log_requests: bool ;
|
||||
@ -131,6 +150,7 @@ type cli_args = {
|
||||
|
||||
let default_cli_args = {
|
||||
block = default_block ;
|
||||
confirmations = Some 0 ;
|
||||
protocol = None ;
|
||||
print_timings = false ;
|
||||
log_requests = false ;
|
||||
@ -149,6 +169,20 @@ let block_parameter () =
|
||||
| Error _ -> fail (Invalid_block_argument block)
|
||||
| Ok block -> return block)
|
||||
|
||||
let wait_parameter () =
|
||||
parameter
|
||||
(fun _ wait ->
|
||||
match wait with
|
||||
| "no" | "none" -> return None
|
||||
| _ ->
|
||||
try
|
||||
let w = int_of_string wait in
|
||||
if 0 <= w then
|
||||
return (Some w)
|
||||
else
|
||||
fail (Invalid_wait_arg wait)
|
||||
with _ -> fail (Invalid_wait_arg wait))
|
||||
|
||||
let protocol_parameter () =
|
||||
parameter
|
||||
(fun _ arg ->
|
||||
@ -194,6 +228,13 @@ let block_arg () =
|
||||
~doc:"block on which to apply contextual commands"
|
||||
~default:(Block_services.to_string default_cli_args.block)
|
||||
(block_parameter ())
|
||||
let wait_arg () =
|
||||
arg
|
||||
~long:"wait"
|
||||
~short:'w'
|
||||
~placeholder:"none|<int>"
|
||||
~doc:"how many confirmation blocks before to consider an operation as included"
|
||||
(wait_parameter ())
|
||||
let protocol_arg () =
|
||||
arg
|
||||
~long:"protocol"
|
||||
@ -318,11 +359,12 @@ let commands config_file cfg =
|
||||
]
|
||||
|
||||
let global_options () =
|
||||
args10
|
||||
args11
|
||||
(base_dir_arg ())
|
||||
(config_file_arg ())
|
||||
(timings_switch ())
|
||||
(block_arg ())
|
||||
(wait_arg ())
|
||||
(protocol_arg ())
|
||||
(log_requests_switch ())
|
||||
(addr_arg ())
|
||||
@ -339,6 +381,7 @@ let parse_config_args (ctx : #Client_context.full) argv =
|
||||
config_file,
|
||||
timings,
|
||||
block,
|
||||
confirmations,
|
||||
protocol,
|
||||
log_requests,
|
||||
node_addr,
|
||||
@ -382,7 +425,9 @@ let parse_config_args (ctx : #Client_context.full) argv =
|
||||
let node_addr = Option.unopt ~default:cfg.node_addr node_addr in
|
||||
let node_port = Option.unopt ~default:cfg.node_port node_port in
|
||||
let remote_signer = Option.first_some remote_signer cfg.remote_signer in
|
||||
let cfg = { cfg with tls ; node_port ; node_addr ; remote_signer } in
|
||||
let confirmations = Option.unopt ~default:cfg.confirmations confirmations in
|
||||
let cfg = { cfg with tls ; node_port ; node_addr ;
|
||||
remote_signer ; confirmations } in
|
||||
if Sys.file_exists base_dir && not (Sys.is_directory base_dir) then begin
|
||||
Format.eprintf "%s is not a directory.@." base_dir ;
|
||||
exit 1 ;
|
||||
@ -394,5 +439,6 @@ let parse_config_args (ctx : #Client_context.full) argv =
|
||||
Lwt_utils_unix.create_dir config_dir >>= fun () ->
|
||||
return
|
||||
(cfg,
|
||||
{ block ; print_timings = timings ; log_requests ; protocol },
|
||||
{ block ; confirmations ;
|
||||
print_timings = timings ; log_requests ; protocol },
|
||||
commands config_file cfg, remaining)
|
||||
|
@ -83,11 +83,12 @@ class unix_logger ~base_dir =
|
||||
inherit Client_context.simple_printer log
|
||||
end
|
||||
|
||||
class unix_full ~base_dir ~block ~rpc_config : Client_context.full =
|
||||
class unix_full ~base_dir ~block ~confirmations ~rpc_config : Client_context.full =
|
||||
object
|
||||
inherit unix_logger ~base_dir
|
||||
inherit unix_prompter
|
||||
inherit unix_wallet ~base_dir
|
||||
inherit RPC_client.http_ctxt rpc_config Media_type.all_media_types
|
||||
method block = block
|
||||
method confirmations = confirmations
|
||||
end
|
||||
|
@ -18,5 +18,6 @@ class unix_logger :
|
||||
class unix_full :
|
||||
base_dir:string ->
|
||||
block:Block_services.block ->
|
||||
confirmations:int option ->
|
||||
rpc_config:RPC_client.config ->
|
||||
Client_context.full
|
||||
|
@ -90,6 +90,7 @@ let main select_commands =
|
||||
Client_config.parse_config_args
|
||||
(new unix_full
|
||||
~block:Client_config.default_block
|
||||
~confirmations:None
|
||||
~base_dir:Client_config.default_base_dir
|
||||
~rpc_config:RPC_client.default_config)
|
||||
original_args
|
||||
@ -120,6 +121,7 @@ let main select_commands =
|
||||
let client_config =
|
||||
new unix_full
|
||||
~block:parsed_args.block
|
||||
~confirmations:parsed_args.confirmations
|
||||
~base_dir:parsed_config_file.base_dir
|
||||
~rpc_config:rpc_config in
|
||||
Option.iter parsed_config_file.remote_signer ~f: begin fun signer ->
|
||||
|
@ -38,6 +38,7 @@ let no_write_context ?(block = `Head 0) config : #Client_context.full = object
|
||||
a Data_encoding.encoding -> unit Error_monad.tzresult Lwt.t =
|
||||
fun _ _ _ -> return ()
|
||||
method block = block
|
||||
method confirmations = None
|
||||
method prompt : type a. (a, string tzresult) Client_context.lwt_format -> a =
|
||||
Format.kasprintf (fun _ -> return "")
|
||||
method prompt_password : type a. (a, MBytes.t tzresult) Client_context.lwt_format -> a =
|
||||
|
@ -141,7 +141,9 @@ let commands () =
|
||||
@@ stop)
|
||||
begin fun fee (_, contract) (_, delegate) (cctxt : Proto_alpha.full) ->
|
||||
source_to_keys cctxt cctxt#block contract >>=? fun (src_pk, manager_sk) ->
|
||||
set_delegate cctxt cctxt#block contract (Some delegate) ~fee ~src_pk ~manager_sk >>=? fun _ ->
|
||||
set_delegate
|
||||
cctxt cctxt#block ?confirmations:cctxt#confirmations
|
||||
contract (Some delegate) ~fee ~src_pk ~manager_sk >>=? fun _ ->
|
||||
return ()
|
||||
end ;
|
||||
|
||||
@ -152,7 +154,9 @@ let commands () =
|
||||
@@ stop)
|
||||
begin fun fee (_, contract) (cctxt : Proto_alpha.full) ->
|
||||
source_to_keys cctxt cctxt#block contract >>=? fun (src_pk, manager_sk) ->
|
||||
set_delegate ~fee cctxt cctxt#block contract None ~src_pk ~manager_sk >>=? fun _ ->
|
||||
set_delegate
|
||||
cctxt cctxt#block ?confirmations:cctxt#confirmations
|
||||
contract None ~fee ~src_pk ~manager_sk >>=? fun _ ->
|
||||
return ()
|
||||
end ;
|
||||
|
||||
@ -178,6 +182,7 @@ let commands () =
|
||||
originate_account
|
||||
cctxt
|
||||
cctxt#block
|
||||
?confirmations:cctxt#confirmations
|
||||
~fee
|
||||
?delegate
|
||||
~delegatable
|
||||
@ -217,7 +222,7 @@ 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) ->
|
||||
originate_contract cctxt cctxt#block
|
||||
originate_contract cctxt cctxt#block ?confirmations:cctxt#confirmations
|
||||
~fee ?gas_limit ~delegate ~delegatable ~spendable ~initial_storage
|
||||
~manager ~balance ~source ~src_pk ~src_sk ~code () >>= fun errors ->
|
||||
report_michelson_errors ~no_print_source ~msg:"origination simulation failed" cctxt errors >>= function
|
||||
@ -241,8 +246,8 @@ let commands () =
|
||||
@@ stop)
|
||||
begin fun (fee, gas_limit, arg, no_print_source) amount (_, source) (_, destination) cctxt ->
|
||||
source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) ->
|
||||
transfer cctxt ~fee cctxt#block
|
||||
~source ~src_pk ~src_sk ~destination ~arg ~amount ?gas_limit () >>=
|
||||
transfer cctxt cctxt#block ?confirmations:cctxt#confirmations
|
||||
~source ~fee ~src_pk ~src_sk ~destination ~arg ~amount ?gas_limit () >>=
|
||||
report_michelson_errors ~no_print_source ~msg:"transfer simulation failed" cctxt >>= function
|
||||
| None -> return ()
|
||||
| Some (_res, _contracts) ->
|
||||
@ -257,8 +262,8 @@ let commands () =
|
||||
@@ stop)
|
||||
begin fun fee (_, source) cctxt ->
|
||||
source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) ->
|
||||
reveal cctxt ~fee cctxt#block
|
||||
~source ~src_pk ~src_sk () >>=? fun _res ->
|
||||
reveal cctxt cctxt#block ?confirmations:cctxt#confirmations
|
||||
~source ~fee ~src_pk ~src_sk () >>=? fun _res ->
|
||||
return ()
|
||||
end;
|
||||
|
||||
@ -271,15 +276,14 @@ let commands () =
|
||||
@@ stop)
|
||||
begin fun fee src_pkh cctxt ->
|
||||
Client_keys.get_key cctxt src_pkh >>=? fun (_, src_pk, src_sk) ->
|
||||
register_as_delegate cctxt
|
||||
register_as_delegate cctxt ?confirmations:cctxt#confirmations
|
||||
~fee cctxt#block ~manager_sk:src_sk src_pk >>=? fun _res ->
|
||||
return ()
|
||||
end;
|
||||
|
||||
command ~group ~desc:"Register and activate a predefined account using the provided activation key."
|
||||
(args3
|
||||
(args2
|
||||
(Secret_key.force_switch ())
|
||||
(Client_proto_args.no_confirmation)
|
||||
encrypted_switch)
|
||||
(prefixes [ "activate" ; "account" ]
|
||||
@@ Secret_key.fresh_alias_param
|
||||
@ -288,7 +292,7 @@ let commands () =
|
||||
~desc:"Activation key (as JSON file) obtained from the Tezos foundation (or the Alphanet faucet)."
|
||||
file_parameter
|
||||
@@ stop)
|
||||
(fun (force, no_confirmation, encrypted) name activation_key_file cctxt ->
|
||||
(fun (force, encrypted) name activation_key_file cctxt ->
|
||||
Secret_key.of_fresh cctxt force name >>=? fun name ->
|
||||
Lwt_utils_unix.Json.read_file activation_key_file >>=? fun json ->
|
||||
match Data_encoding.Json.destruct
|
||||
@ -300,9 +304,8 @@ let commands () =
|
||||
(fun ppf -> Data_encoding.Json.print_error ppf) exn
|
||||
Data_encoding.Json.pp json
|
||||
| key ->
|
||||
let confirmations =
|
||||
if no_confirmation then None else Some 0 in
|
||||
claim_commitment cctxt cctxt#block ?confirmations
|
||||
claim_commitment
|
||||
cctxt cctxt#block ?confirmations:cctxt#confirmations
|
||||
~encrypted ~force key name >>=? fun _res ->
|
||||
return ()
|
||||
);
|
||||
@ -358,7 +361,8 @@ let commands () =
|
||||
fail_when (predecessors < 0)
|
||||
(failure "check-previous cannot be negative") >>=? fun () ->
|
||||
Client_confirmations.wait_for_operation_inclusion ctxt
|
||||
~confirmations ~predecessors operation_hash
|
||||
~confirmations ~predecessors operation_hash >>=? fun _ ->
|
||||
return ()
|
||||
end ;
|
||||
|
||||
command ~group:alphanet ~desc: "Fork a test protocol (Alphanet dictator only)."
|
||||
|
Loading…
Reference in New Issue
Block a user