2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
type ('a, 'b) lwt_format =
|
|
|
|
('a, Format.formatter, unit, 'b Lwt.t) format4
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-03-15 04:17:20 +04:00
|
|
|
type cfg = {
|
|
|
|
|
2017-03-31 02:42:13 +04:00
|
|
|
(* network options. *)
|
|
|
|
node_addr : string ;
|
|
|
|
node_port : int ;
|
2017-03-15 04:17:20 +04:00
|
|
|
tls : bool ;
|
|
|
|
|
|
|
|
(* webclient options *)
|
|
|
|
web_port : int ;
|
2017-03-31 02:42:13 +04:00
|
|
|
|
|
|
|
(* misc options *)
|
|
|
|
base_dir : string ;
|
|
|
|
print_timings : bool ;
|
|
|
|
force : bool ;
|
|
|
|
block : Node_rpc_services.Blocks.block ;
|
|
|
|
|
2017-03-15 04:17:20 +04:00
|
|
|
}
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
type context =
|
2017-03-15 04:17:20 +04:00
|
|
|
{ config : cfg ;
|
|
|
|
error : 'a 'b. ('a, 'b) lwt_format -> 'a ;
|
2016-12-03 16:05:02 +04:00
|
|
|
warning : 'a. ('a, unit) lwt_format -> 'a ;
|
|
|
|
message : 'a. ('a, unit) lwt_format -> 'a ;
|
|
|
|
answer : 'a. ('a, unit) lwt_format -> 'a ;
|
|
|
|
log : 'a. string -> ('a, unit) lwt_format -> 'a }
|
|
|
|
|
|
|
|
type command = (context, unit) Cli_entries.command
|
|
|
|
|
2017-03-15 04:17:20 +04:00
|
|
|
(* Default config *)
|
|
|
|
|
|
|
|
let (//) = Filename.concat
|
|
|
|
|
|
|
|
let default_cfg_of_base_dir base_dir = {
|
|
|
|
base_dir ;
|
|
|
|
print_timings = false ;
|
|
|
|
force = false ;
|
|
|
|
block = `Prevalidation ;
|
|
|
|
|
2017-03-31 02:42:13 +04:00
|
|
|
node_addr = "127.0.0.1" ;
|
|
|
|
node_port = 8732 ;
|
2017-03-15 04:17:20 +04:00
|
|
|
tls = false ;
|
|
|
|
|
|
|
|
web_port = 8080 ;
|
|
|
|
}
|
|
|
|
|
2017-03-31 02:42:13 +04:00
|
|
|
let home =
|
|
|
|
try Sys.getenv "HOME"
|
|
|
|
with Not_found -> "/root"
|
|
|
|
|
|
|
|
let default_base_dir = home // ".tezos-client"
|
|
|
|
|
2017-03-15 04:17:20 +04:00
|
|
|
let default_cfg = default_cfg_of_base_dir default_base_dir
|
|
|
|
|
|
|
|
let make_context ?(config = default_cfg) log =
|
2016-12-03 16:05:02 +04:00
|
|
|
let error fmt =
|
|
|
|
Format.kasprintf
|
|
|
|
(fun msg ->
|
|
|
|
Lwt.fail (Failure msg))
|
|
|
|
fmt in
|
|
|
|
let warning fmt =
|
|
|
|
Format.kasprintf
|
|
|
|
(fun msg -> log "stderr" msg)
|
|
|
|
fmt in
|
|
|
|
let message fmt =
|
|
|
|
Format.kasprintf
|
|
|
|
(fun msg -> log "stdout" msg)
|
|
|
|
fmt in
|
|
|
|
let answer =
|
|
|
|
message in
|
|
|
|
let log name fmt =
|
|
|
|
Format.kasprintf
|
|
|
|
(fun msg -> log name msg)
|
|
|
|
fmt in
|
2017-03-15 04:17:20 +04:00
|
|
|
{ config ; error ; warning ; message ; answer ; log }
|
2016-12-03 16:05:02 +04:00
|
|
|
|
|
|
|
let ignore_context =
|
|
|
|
make_context (fun _ _ -> Lwt.return ())
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
exception Version_not_found
|
|
|
|
|
2017-02-24 20:17:53 +04:00
|
|
|
let versions = Protocol_hash.Table.create 7
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let get_versions () =
|
2017-02-24 20:17:53 +04:00
|
|
|
Protocol_hash.Table.fold
|
2016-09-08 21:13:10 +04:00
|
|
|
(fun k c acc -> (k, c) :: acc)
|
|
|
|
versions
|
|
|
|
[]
|
|
|
|
|
|
|
|
let register name commands =
|
|
|
|
let previous =
|
2017-02-24 20:17:53 +04:00
|
|
|
try Protocol_hash.Table.find versions name
|
2016-09-08 21:13:10 +04:00
|
|
|
with Not_found -> [] in
|
2017-02-24 20:17:53 +04:00
|
|
|
Protocol_hash.Table.add versions name (commands @ previous)
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let commands_for_version version =
|
2017-02-24 20:17:53 +04:00
|
|
|
try Protocol_hash.Table.find versions version
|
2016-09-08 21:13:10 +04:00
|
|
|
with Not_found -> raise Version_not_found
|