2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
(* Tezos Command line interface - Main Program *)
|
|
|
|
|
2017-11-07 20:38:11 +04:00
|
|
|
let cctxt ~base_dir ~block rpc_config =
|
|
|
|
Client_commands.make_context ~base_dir ~block ~rpc_config (Client_commands.default_log ~base_dir)
|
2016-11-22 17:23:40 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Main (lwt) entry *)
|
|
|
|
let main () =
|
|
|
|
Random.self_init () ;
|
|
|
|
Sodium.Random.stir () ;
|
2017-03-13 20:40:51 +04:00
|
|
|
Lwt.catch begin fun () ->
|
2017-09-27 11:55:20 +04:00
|
|
|
let original_args = List.tl (Array.to_list Sys.argv) in
|
2017-04-05 01:35:41 +04:00
|
|
|
begin
|
2017-09-27 11:55:20 +04:00
|
|
|
Client_config.parse_config_args
|
2017-11-07 20:38:11 +04:00
|
|
|
(cctxt ~base_dir:Client_commands.default_base_dir
|
|
|
|
~block:Client_commands.default_block
|
|
|
|
Client_rpcs.default_config)
|
2017-09-27 11:55:20 +04:00
|
|
|
original_args
|
2017-09-19 13:31:35 +04:00
|
|
|
>>=? fun (parsed_config_file, parsed_args, remaining) ->
|
|
|
|
let rpc_config : Client_rpcs.config = {
|
|
|
|
Client_rpcs.default_config with
|
|
|
|
host = parsed_config_file.node_addr ;
|
|
|
|
port = parsed_config_file.node_port ;
|
|
|
|
tls = parsed_config_file.tls ;
|
|
|
|
} in
|
2017-12-09 06:51:58 +04:00
|
|
|
let ctxt = new Client_rpcs.rpc rpc_config in
|
2017-09-19 13:31:35 +04:00
|
|
|
begin
|
2017-12-09 06:51:58 +04:00
|
|
|
Client_node_rpcs.Blocks.protocol ctxt parsed_args.block >>= function
|
2017-11-23 18:57:27 +04:00
|
|
|
| Ok version -> begin
|
|
|
|
match parsed_args.protocol with
|
|
|
|
| None ->
|
|
|
|
return (Some version, Client_commands.commands_for_version version)
|
|
|
|
| Some given_version -> begin
|
2017-11-27 09:13:12 +04:00
|
|
|
if not (Protocol_hash.equal version given_version) then
|
2017-11-23 18:57:27 +04:00
|
|
|
Format.eprintf
|
|
|
|
"@[<v 2>Warning:@,\
|
|
|
|
The protocol provided via `-protocol` (%a)@,\
|
|
|
|
is not the one retrieved from the node (%a).@."
|
2017-11-27 09:13:12 +04:00
|
|
|
Protocol_hash.pp_short given_version
|
|
|
|
Protocol_hash.pp_short version ;
|
2017-11-23 18:57:27 +04:00
|
|
|
return (Some version, Client_commands.commands_for_version given_version)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
| Error errs -> begin
|
|
|
|
match parsed_args.protocol with
|
|
|
|
| None -> begin
|
|
|
|
Format.eprintf
|
|
|
|
"@[<v 2>Ignored error:@,Failed to acquire the protocol version from the node@,%a@."
|
|
|
|
(Format.pp_print_list pp) errs ;
|
|
|
|
return (None, [])
|
|
|
|
end
|
|
|
|
| Some version ->
|
|
|
|
return (Some version, Client_commands.commands_for_version version)
|
|
|
|
end
|
2017-09-19 13:31:35 +04:00
|
|
|
end >>=? fun (_version, commands_for_version) ->
|
|
|
|
let commands =
|
|
|
|
Client_generic_rpcs.commands @
|
|
|
|
Client_network.commands () @
|
|
|
|
Client_keys.commands () @
|
|
|
|
Client_protocols.commands () @
|
|
|
|
Client_helpers.commands () @
|
2017-11-27 01:22:19 +04:00
|
|
|
Client_debug.commands () @
|
2017-09-19 13:31:35 +04:00
|
|
|
commands_for_version in
|
|
|
|
let rpc_config =
|
|
|
|
if parsed_args.print_timings then
|
|
|
|
{ rpc_config with
|
|
|
|
logger = Client_rpcs.timings_logger Format.err_formatter }
|
|
|
|
else if parsed_args.log_requests
|
2017-11-07 20:38:11 +04:00
|
|
|
then { rpc_config with logger = Client_rpcs.full_logger Format.err_formatter }
|
2017-09-19 13:31:35 +04:00
|
|
|
else rpc_config
|
|
|
|
in
|
2017-11-07 20:38:11 +04:00
|
|
|
let client_config =
|
|
|
|
cctxt ~block:parsed_args.block ~base_dir:parsed_config_file.base_dir rpc_config in
|
2017-09-19 13:31:35 +04:00
|
|
|
(Cli_entries.dispatch
|
2017-09-27 11:55:20 +04:00
|
|
|
~global_options:Client_config.global_options
|
2017-09-19 13:31:35 +04:00
|
|
|
commands
|
|
|
|
client_config
|
|
|
|
remaining) end >>=
|
|
|
|
Cli_entries.handle_cli_errors
|
2017-11-07 20:38:11 +04:00
|
|
|
~stdout:Format.std_formatter
|
|
|
|
~stderr:Format.err_formatter
|
2017-09-19 13:31:35 +04:00
|
|
|
~global_options:Client_config.global_options
|
|
|
|
>>= function
|
|
|
|
| Ok i ->
|
|
|
|
Lwt.return i
|
2017-04-07 23:21:20 +04:00
|
|
|
| Error errs ->
|
2017-09-19 13:31:35 +04:00
|
|
|
Format.eprintf "@[<v 2>Fatal error:@,%a@."
|
2017-04-07 23:21:20 +04:00
|
|
|
(Format.pp_print_list Error_monad.pp) errs ;
|
2017-04-05 01:35:41 +04:00
|
|
|
Lwt.return 1
|
2017-03-13 20:40:51 +04:00
|
|
|
end begin function
|
|
|
|
| Arg.Help help ->
|
|
|
|
Format.printf "%s%!" help ;
|
|
|
|
Lwt.return 0
|
2017-04-05 12:22:41 +04:00
|
|
|
| Client_commands.Version_not_found ->
|
2017-09-19 13:31:35 +04:00
|
|
|
Format.eprintf "Unknown protocol version.@." ;
|
2017-03-13 20:40:51 +04:00
|
|
|
Lwt.return 1
|
|
|
|
| Failure message ->
|
2017-04-07 23:21:20 +04:00
|
|
|
Format.eprintf
|
2017-09-19 13:31:35 +04:00
|
|
|
"Fatal error: %s@." message ;
|
2017-03-13 20:40:51 +04:00
|
|
|
Lwt.return 1
|
|
|
|
| exn ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Format.printf "Fatal internal error: %s@."
|
2017-03-13 20:40:51 +04:00
|
|
|
(Printexc.to_string exn) ;
|
|
|
|
Lwt.return 1
|
|
|
|
end
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
(* Where all the user friendliness starts *)
|
2016-12-02 02:20:23 +04:00
|
|
|
let () = Pervasives.exit (Lwt_main.run (main ()))
|