2016-12-03 16:05:02 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-04-05 01:35:41 +04:00
|
|
|
open Client_commands
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let group =
|
|
|
|
{ Cli_entries.name = "protocols" ;
|
|
|
|
title = "Commands for managing protocols" }
|
|
|
|
|
2016-10-25 21:00:03 +04:00
|
|
|
let commands () =
|
|
|
|
let open Cli_entries in
|
2016-12-03 16:05:02 +04:00
|
|
|
let check_dir _ dn =
|
|
|
|
if Sys.is_directory dn then
|
|
|
|
Lwt.return dn
|
|
|
|
else
|
|
|
|
Lwt.fail_with (dn ^ " is not a directory") in
|
|
|
|
let check_hash _ ph =
|
2017-04-05 11:54:21 +04:00
|
|
|
Lwt.wrap1 Protocol_hash.of_b58check_exn ph in
|
2016-10-25 21:00:03 +04:00
|
|
|
[
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "list known protocols"
|
2016-10-25 21:00:03 +04:00
|
|
|
(prefixes [ "list" ; "protocols" ] stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Protocols.list cctxt.rpc_config ~contents:false () >>=? fun protos ->
|
|
|
|
Lwt_list.iter_s (fun (ph, _p) -> cctxt.message "%a" Protocol_hash.pp ph) protos >>= fun () ->
|
|
|
|
return ()
|
2016-10-25 21:00:03 +04:00
|
|
|
);
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "inject a new protocol to the shell database"
|
2016-10-25 21:00:03 +04:00
|
|
|
(prefixes [ "inject" ; "protocol" ]
|
2016-12-03 16:05:02 +04:00
|
|
|
@@ param ~name:"dir" ~desc:"directory containing a protocol" check_dir
|
2016-10-25 21:00:03 +04:00
|
|
|
@@ stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun dirname cctxt ->
|
2016-10-25 21:00:03 +04:00
|
|
|
Lwt.catch
|
|
|
|
(fun () ->
|
|
|
|
let proto = Tezos_compiler.Protocol.of_dir dirname in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.inject_protocol cctxt.rpc_config proto >>= function
|
2016-10-25 21:00:03 +04:00
|
|
|
| Ok hash ->
|
2017-04-05 01:35:41 +04:00
|
|
|
cctxt.message "Injected protocol %a successfully" Protocol_hash.pp_short hash >>= fun () ->
|
|
|
|
return ()
|
|
|
|
|
2016-10-25 21:00:03 +04:00
|
|
|
| Error err ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.error "Error while injecting protocol from %s: %a"
|
2017-04-05 01:35:41 +04:00
|
|
|
dirname Error_monad.pp_print_error err >>= fun () ->
|
|
|
|
return ())
|
2016-10-25 21:00:03 +04:00
|
|
|
(fun exn ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.error "Error while injecting protocol from %s: %a"
|
2017-04-05 01:35:41 +04:00
|
|
|
dirname Error_monad.pp_print_error [Error_monad.Exn exn] >>= fun () ->
|
|
|
|
return ())
|
2016-10-25 21:00:03 +04:00
|
|
|
);
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "dump a protocol from the shell database"
|
2016-10-25 21:00:03 +04:00
|
|
|
(prefixes [ "dump" ; "protocol" ]
|
|
|
|
@@ param ~name:"protocol hash" ~desc:"" check_hash
|
|
|
|
@@ stop)
|
2016-12-03 16:05:02 +04:00
|
|
|
(fun ph cctxt ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Protocols.contents cctxt.rpc_config ph >>=? fun proto ->
|
2017-02-24 20:17:53 +04:00
|
|
|
Updater.extract "" ph proto >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
cctxt.message "Extracted protocol %a" Protocol_hash.pp_short ph >>= fun () ->
|
|
|
|
return ()
|
|
|
|
) ;
|
2017-02-24 20:17:53 +04:00
|
|
|
(* | Error err -> *)
|
|
|
|
(* cctxt.error "Error while dumping protocol %a: %a" *)
|
|
|
|
(* Protocol_hash.pp_short ph Error_monad.pp_print_error err); *)
|
2016-10-25 21:00:03 +04:00
|
|
|
]
|