ligo/src/bin_client/client_protocols_commands.ml

84 lines
4.1 KiB
OCaml
Raw Normal View History

2018-06-29 16:08:08 +04:00
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)
(* *)
(*****************************************************************************)
let group =
2018-04-03 13:39:09 +04:00
{ Clic.name = "protocols" ;
title = "Commands for managing protocols" }
2016-10-25 21:00:03 +04:00
let commands () =
2018-04-03 13:39:09 +04:00
let open Clic in
let check_dir _ dn =
if Sys.is_directory dn then
return dn
else
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
[
command ~group ~desc: "List protocols known by the node."
no_options
2016-10-25 21:00:03 +04:00
(prefixes [ "list" ; "protocols" ] stop)
(fun () (cctxt : #Client_context.full) ->
Shell_services.Protocol.list cctxt >>=? fun protos ->
Lwt_list.iter_s (fun ph -> cctxt#message "%a" Protocol_hash.pp ph) protos >>= fun () ->
2018-06-26 13:07:12 +04:00
return_unit
2016-10-25 21:00:03 +04:00
);
command ~group ~desc: "Inject a new protocol into the node."
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)
(fun () dirname (cctxt : #Client_context.full) ->
2016-10-25 21:00:03 +04:00
Lwt.catch
(fun () ->
Lwt_utils_unix.Protocol.read_dir dirname >>=? fun (_hash, proto) ->
Shell_services.Injection.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 () ->
2018-06-26 13:07:12 +04:00
return_unit
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"
dirname Error_monad.pp_print_error err >>= fun () ->
2018-06-26 13:07:12 +04:00
return_unit)
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"
dirname Error_monad.pp_print_error [Error_monad.Exn exn] >>= fun () ->
2018-06-26 13:07:12 +04:00
return_unit)
2016-10-25 21:00:03 +04:00
);
command ~group ~desc: "Dump a protocol from the node's record of protocol."
no_options
2016-10-25 21:00:03 +04:00
(prefixes [ "dump" ; "protocol" ]
@@ Protocol_hash.param ~name:"protocol hash" ~desc:""
2016-10-25 21:00:03 +04:00
@@ stop)
(fun () ph (cctxt : #Client_context.full) ->
Shell_services.Protocol.contents cctxt ph >>=? fun proto ->
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 () ->
2018-06-26 13:07:12 +04:00
return_unit
) ;
2016-10-25 21:00:03 +04:00
]