ligo/src/bin_client/main_client.ml
Grégoire Henry 632144b689 RPC: remove subfield accessors
This is painful to maintain and `jq` works well.
2018-06-06 10:54:33 +02:00

53 lines
2.2 KiB
OCaml

(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2018. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
open Client_config
let get_commands_for_version ctxt block protocol =
Shell_services.Blocks.protocols ctxt ~block () >>= function
| Ok { next_protocol = version } -> begin
match protocol with
| None ->
return (Some version, Client_commands.commands_for_version version)
| Some given_version -> begin
if not (Protocol_hash.equal version given_version) then
Format.eprintf
"@[<v 2>@{<warning>@{<title>Warning@}@}@,\
The protocol provided via `--protocol` (%a)@,\
is not the one retrieved from the node (%a).@]@\n@."
Protocol_hash.pp_short given_version
Protocol_hash.pp_short version ;
return (Some version, Client_commands.commands_for_version given_version)
end
end
| Error errs -> begin
match protocol with
| None -> begin
Format.eprintf
"@[<v 2>@{<warning>@{<title>Warning@}@}@,\
Failed to acquire the protocol version from the node@,%a@]@\n@."
(Format.pp_print_list pp) errs ;
return (None, [])
end
| Some version ->
return (Some version, Client_commands.commands_for_version version)
end
let select_commands ctxt { block ; protocol } =
get_commands_for_version ctxt block protocol >>|? fun (_, commands_for_version) ->
Client_rpc_commands.commands @
List.map
(Clic.map_command
(fun (o : Client_context.full) -> (o :> Client_context.io_wallet)))
(Client_keys_commands.commands ()) @
Client_helpers_commands.commands () @
commands_for_version
let () = Client_main_run.run select_commands