2016-12-03 16:05:02 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2018-02-06 00:17:03 +04:00
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
2016-12-03 16:05:02 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
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
|
2017-04-05 12:22:41 +04:00
|
|
|
return dn
|
2016-12-03 16:05:02 +04:00
|
|
|
else
|
2017-04-05 12:22:41 +04:00
|
|
|
failwith "%s is not a directory" dn in
|
2017-09-27 11:55:20 +04:00
|
|
|
let check_dir_parameter = parameter check_dir in
|
2016-10-25 21:00:03 +04:00
|
|
|
[
|
2017-04-05 12:22:41 +04:00
|
|
|
|
2018-01-29 13:43:07 +04:00
|
|
|
command ~group ~desc: "List protocols known by the node."
|
2017-09-19 13:31:35 +04:00
|
|
|
no_options
|
2016-10-25 21:00:03 +04:00
|
|
|
(prefixes [ "list" ; "protocols" ] stop)
|
2018-02-14 18:20:03 +04:00
|
|
|
(fun () (cctxt : #Client_context.full_context) ->
|
2018-02-08 13:51:02 +04:00
|
|
|
Protocol_services.list ~contents:false cctxt >>=? fun protos ->
|
2017-11-07 20:38:11 +04:00
|
|
|
Lwt_list.iter_s (fun (ph, _p) -> cctxt#message "%a" Protocol_hash.pp ph) protos >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
return ()
|
2016-10-25 21:00:03 +04:00
|
|
|
);
|
2017-04-05 12:22:41 +04:00
|
|
|
|
2018-01-29 13:43:07 +04:00
|
|
|
command ~group ~desc: "Inject a new protocol into the node."
|
2017-09-19 13:31:35 +04:00
|
|
|
no_options
|
2016-10-25 21:00:03 +04:00
|
|
|
(prefixes [ "inject" ; "protocol" ]
|
2017-09-27 11:55:20 +04:00
|
|
|
@@ param ~name:"dir" ~desc:"directory containing a protocol" check_dir_parameter
|
2016-10-25 21:00:03 +04:00
|
|
|
@@ stop)
|
2018-02-14 18:20:03 +04:00
|
|
|
(fun () dirname (cctxt : #Client_context.full_context) ->
|
2016-10-25 21:00:03 +04:00
|
|
|
Lwt.catch
|
|
|
|
(fun () ->
|
2018-02-08 13:51:01 +04:00
|
|
|
Lwt_utils_unix.Protocol.read_dir dirname >>=? fun (_hash, proto) ->
|
2018-02-08 13:51:02 +04:00
|
|
|
Shell_services.inject_protocol cctxt proto >>= function
|
2016-10-25 21:00:03 +04:00
|
|
|
| Ok hash ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message "Injected protocol %a successfully" Protocol_hash.pp_short hash >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
return ()
|
2016-10-25 21:00:03 +04:00
|
|
|
| Error err ->
|
2017-11-07 20:38:11 +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 ->
|
2017-11-07 20:38:11 +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
|
|
|
);
|
2017-04-05 12:22:41 +04:00
|
|
|
|
2018-01-29 13:43:07 +04:00
|
|
|
command ~group ~desc: "Dump a protocol from the node's record of protocol."
|
2017-09-19 13:31:35 +04:00
|
|
|
no_options
|
2016-10-25 21:00:03 +04:00
|
|
|
(prefixes [ "dump" ; "protocol" ]
|
2017-04-05 12:22:41 +04:00
|
|
|
@@ Protocol_hash.param ~name:"protocol hash" ~desc:""
|
2016-10-25 21:00:03 +04:00
|
|
|
@@ stop)
|
2018-02-14 18:20:03 +04:00
|
|
|
(fun () ph (cctxt : #Client_context.full_context) ->
|
2018-02-08 13:51:02 +04:00
|
|
|
Protocol_services.contents cctxt ph >>=? fun proto ->
|
2018-02-08 13:51:01 +04:00
|
|
|
Lwt_utils_unix.Protocol.write_dir (Protocol_hash.to_short_b58check ph) ~hash:ph proto >>=? fun () ->
|
2017-11-07 20:38:11 +04:00
|
|
|
cctxt#message "Extracted protocol %a" Protocol_hash.pp_short ph >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
return ()
|
2017-11-13 19:34:00 +04:00
|
|
|
) ;
|
2016-10-25 21:00:03 +04:00
|
|
|
]
|