Verified Commit da083f5f authored by Raphaël Proust's avatar Raphaël Proust Committed by Thomas Letan
Browse files

Everywhere: autoformat

parent 782ef0ee
......@@ -40,11 +40,13 @@ let default_section_title = "Miscellaneous"
bottom of the document. Unprefixed ids or unreferenced prefixes
will default to `Miscellaneous` *)
let section_titles =
[ (["proto.alpha"], "Protocol Alpha");
[
(["proto.alpha"], "Protocol Alpha");
(["distributed_db"; "node"; "raw_store"; "validator"; "worker"], "Shell");
(["micheline"; "michelson"], "Michelson parsing/macros");
(["rpc_client"], "Client");
(["cli"; "utils"; default_section_id], default_section_title) ]
(["cli"; "utils"; default_section_id], default_section_title);
]
let pp_rst_title ~char ppf title =
let sub = String.map (fun _ -> char) title in
......@@ -58,16 +60,15 @@ let pp_rst_h2 = pp_rst_title ~char:'*'
* let pp_rst_h4 = pp_rst_title ~char:'`' *)
let string_of_err_category = function
| `Branch ->
"branch"
| `Temporary ->
"temporary"
| `Permanent ->
"permanent"
| `Branch -> "branch"
| `Temporary -> "temporary"
| `Permanent -> "permanent"
let make_counter () =
let i = ref 1 in
fun () -> incr i ; !i
fun () ->
incr i ;
!i
let count = make_counter ()
......@@ -75,8 +76,7 @@ let unique_label () =
let label = sprintf "ref%d" (count ()) in
label
let pp_print_html_tab_button fmt ?(default = false) ~shortlabel ~content idref
=
let pp_print_html_tab_button fmt ?(default = false) ~shortlabel ~content idref =
fprintf
fmt
"<button class=\"tablinks%s\" onclick=\"showTab(this, '%s', \
......@@ -126,6 +126,7 @@ let pp_print_html_tabs fmt {Error_monad.id; category; description; schema; _} =
idref ;
fprintf fmt "%s@ " description_content ;
fprintf fmt "</div>@]" ;
(* Print schema *)
(* Hack: negative offset in order to reduce the <pre>'s content left-margin *)
......@@ -163,12 +164,9 @@ module ErrorPartition = struct
let compare s s' =
let idx s =
let rec loop acc = function
| [] ->
assert false
| h :: _ when h = s ->
acc
| _ :: t ->
loop (acc + 1) t
| [] -> assert false
| h :: _ when h = s -> acc
| _ :: t -> loop (acc + 1) t
in
loop 0 titles
in
......@@ -197,8 +195,7 @@ let pp_error_map ppf (map : ErrorSet.t ErrorPartition.t) : unit =
(fun section_title set ->
fprintf ppf "%a" pp_rst_h2 section_title ;
ErrorSet.iter
(fun error_repr ->
fprintf ppf "@[%a@]@\n@\n" pp_info_to_rst error_repr)
(fun error_repr -> fprintf ppf "@[%a@]@\n@\n" pp_info_to_rst error_repr)
set)
map
......@@ -209,8 +206,8 @@ let script =
elt.parentNode.children;for (i = 0; i < tablinks.length; i++) \
{tablinks[i].className = tablinks[i].className.replace(' active', \
'');}document.getElementById(tab).style.display = 'block';elt.className += \
' active';}document.addEventListener('DOMContentLoaded', function(){var a \
= document.getElementsByClassName('defaultOpen');for (i = 0; i < a.length; \
' active';}document.addEventListener('DOMContentLoaded', function(){var a = \
document.getElementsByClassName('defaultOpen');for (i = 0; i < a.length; \
i++) { a[i].click() }})</script>"
let style =
......@@ -236,8 +233,8 @@ let () =
print_script ppf ;
fprintf
ppf
"This document references possible errors that can come from RPC calls. \
It is generated from the OCaml source code (master branch).@\n\
"This document references possible errors that can come from RPC calls. It \
is generated from the OCaml source code (master branch).@\n\
@\n" ;
(* Body *)
let map =
......
......@@ -64,12 +64,11 @@ let with_node f =
Node.default_prevalidator_limits
Node.default_chain_validator_limits
None
>>=? fun node -> f node >>=? fun () -> return ()
>>=? fun node ->
f node >>=? fun () -> return ()
in
Lwt_utils_unix.with_tempdir "tezos_rpcdoc_" run
>>= function
| Ok () ->
Lwt.return_unit
Lwt_utils_unix.with_tempdir "tezos_rpcdoc_" run >>= function
| Ok () -> Lwt.return_unit
| Error err ->
Format.eprintf "%a@." pp_print_error err ;
Stdlib.exit 1
......@@ -36,7 +36,8 @@ let main _node =
(* include/copy usage.rst from input *)
let rec loop () =
let s = read_line () in
Format.printf "%s@\n" s ; loop ()
Format.printf "%s@\n" s ;
loop ()
in
(try loop () with End_of_file -> ()) ;
Format.printf "@\n" ;
......@@ -58,10 +59,8 @@ let main _node =
let hash = Protocol_hash.of_b58check_exn hash in
let (module Proto) =
match Registered_protocol.get hash with
| None ->
assert false
| Some proto ->
proto
| None -> assert false
| Some proto -> proto
in
Format.printf
"%a@\n@\n%a@\n@."
......
......@@ -27,7 +27,8 @@ let protocols =
(* version, title that appears in the doc, an optional path to an introduction, protocol hash *)
(* the optional introduction is inserted between the title "RPCs index"
and the generated directory description *)
[ ( "alpha",
[
( "alpha",
"Alpha",
Some "/include/rpc_introduction.rst.inc",
"ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK" );
......@@ -39,13 +40,12 @@ let protocols =
( "",
"009 Florence",
Some "/include/rpc_introduction.rst.inc",
"PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i" ) ]
"PsFLorenaUUuikDWvMDr6fGBRG8kt3e3D3fHoXK1j1BFRxeSH4i" );
]
let pp_name ppf = function
| [] | [""] ->
Format.pp_print_string ppf "/"
| prefix ->
Format.pp_print_string ppf (String.concat "/" prefix)
| [] | [""] -> Format.pp_print_string ppf "/"
| prefix -> Format.pp_print_string ppf (String.concat "/" prefix)
let ref_of_service (prefix, meth) =
Format.asprintf
......@@ -60,10 +60,8 @@ module Index = struct
let rec pp prefix ppf dir =
let open Resto.Description in
match dir with
| Empty ->
Format.fprintf ppf "Empty"
| Static {services; subdirs = None} ->
pp_services prefix ppf services
| Empty -> Format.fprintf ppf "Empty"
| Static {services; subdirs = None} -> pp_services prefix ppf services
| Static {services; subdirs = Some (Suffixes map)} ->
Format.fprintf
ppf
......@@ -83,15 +81,13 @@ module Index = struct
services
(pp_suffixes prefix)
(name, dir)
| Dynamic _ ->
Format.fprintf ppf "* %a (<dyn>)" pp_name prefix
| Dynamic _ -> Format.fprintf ppf "* %a (<dyn>)" pp_name prefix
and pp_suffixes prefix ppf (name, dir) = pp (prefix @ [name]) ppf dir
and pp_services prefix ppf services =
match Resto.MethMap.bindings services with
| [] ->
Format.fprintf ppf "* %a" pp_name prefix
| [] -> Format.fprintf ppf "* %a" pp_name prefix
| _ :: _ as services ->
Format.fprintf
ppf
......@@ -121,13 +117,11 @@ module Description = struct
let open RPC_description in
function
| {name; kind; _} -> (
match kind with
| Single arg | Optional arg ->
Format.fprintf ppf "[%s=%a]" name pp_arg arg
| Flag ->
Format.fprintf ppf "[%s]" name
| Multi arg ->
Format.fprintf ppf "(%s=%a)\\*" name pp_arg arg )
match kind with
| Single arg | Optional arg ->
Format.fprintf ppf "[%s=%a]" name pp_arg arg
| Flag -> Format.fprintf ppf "[%s]" name
| Multi arg -> Format.fprintf ppf "(%s=%a)\\*" name pp_arg arg)
let pp_title ppf query =
Format.fprintf
......@@ -147,7 +141,7 @@ module Description = struct
let open RPC_description in
function
| {name; description; kind} -> (
( match kind with
(match kind with
| Single arg | Optional arg | Multi arg ->
Format.fprintf
ppf
......@@ -155,18 +149,14 @@ module Description = struct
name
pp_html_arg
arg
| Flag ->
Format.fprintf ppf "<span class=\"query\">%s</span>" name ) ;
| Flag -> Format.fprintf ppf "<span class=\"query\">%s</span>" name) ;
match description with
| None ->
()
| Some descr ->
Format.fprintf ppf " : %s" descr )
| None -> ()
| Some descr -> Format.fprintf ppf " : %s" descr)
let pp ppf query =
match query with
| [] ->
()
| [] -> ()
| _ :: _ as query ->
Format.fprintf
ppf
......@@ -305,10 +295,8 @@ module Description = struct
let rec pp prefix ppf dir =
let open Resto.Description in
match dir with
| Empty ->
()
| Static {services; subdirs = None} ->
pp_services prefix ppf services
| Empty -> ()
| Static {services; subdirs = None} -> pp_services prefix ppf services
| Static {services; subdirs = Some (Suffixes map)} ->
pp_services prefix ppf services ;
Format.pp_print_list
......@@ -319,8 +307,7 @@ module Description = struct
let name = Format.asprintf "<%s>" arg.name in
pp_services prefix ppf services ;
pp_suffixes prefix ppf (name, dir)
| Dynamic _ ->
()
| Dynamic _ -> ()
and pp_suffixes prefix ppf (name, dir) = pp (prefix @ [name]) ppf dir
......@@ -384,8 +371,7 @@ let main node =
this repository *)
Format.eprintf "Hash not found: %a" Protocol_hash.pp hash ;
assert false
| Some proto ->
proto
| Some proto -> proto
in
( version,
"Protocol " ^ name,
......@@ -410,8 +396,7 @@ let main node =
version = required_version)
dirs
in
RPC_directory.describe_directory ~recurse:true ~arg:() dir
>>= fun dir ->
RPC_directory.describe_directory ~recurse:true ~arg:() dir >>= fun dir ->
let ppf = Format.std_formatter in
pp_document ppf [(name, intro, path, dir)] required_version ;
return ()
......
......@@ -55,8 +55,10 @@ let signed_wrong = Ed25519.append_signature wrong_account.secret_key
(* forge a block from a list of operations *)
let block_forged ?prev ops =
let from_int64 x =
[ Bytes.of_string Proto.Constants_repr.version_number;
Proto.Fitness_repr.int64_to_bytes x ]
[
Bytes.of_string Proto.Constants_repr.version_number;
Proto.Fitness_repr.int64_to_bytes x;
]
in
let pred = match prev with None -> genesis_block_hashed | Some x -> x in
let block ops =
......@@ -78,10 +80,8 @@ let block_forged ?prev ops =
Proto.Nonce_storage.of_bytes
@@ Rand.generate Proto.Alpha_context.Constants.nonce_length
with
| Error _ ->
assert false
| Ok nonce ->
nonce
| Error _ -> assert false
| Ok nonce -> nonce
in
Block_repr.forge_header
(block ops)
......@@ -151,8 +151,7 @@ let try_action addr port action =
let socket = Lwt_unix.socket PF_INET6 SOCK_STREAM 0 in
Lwt_unix.set_close_on_exec socket ;
let uaddr = Ipaddr_unix.V6.to_inet_addr addr in
Lwt_unix.connect socket (Lwt_unix.ADDR_INET (uaddr, port))
>>= fun () ->
Lwt_unix.connect socket (Lwt_unix.ADDR_INET (uaddr, port)) >>= fun () ->
let io_sched = P2p_io_scheduler.create ~read_buffer_size:(1 lsl 14) () in
let conn = P2p_io_scheduler.register io_sched socket in
P2p_connection.authenticate
......@@ -163,13 +162,11 @@ let try_action addr port action =
identity
Distributed_db.Raw.supported_versions
>>=? fun (_, auth_fd) ->
P2p_connection.accept auth_fd Distributed_db.Raw.encoding
>>= function
| Error _ ->
failwith "Connection rejected by peer."
P2p_connection.accept auth_fd Distributed_db.Raw.encoding >>= function
| Error _ -> failwith "Connection rejected by peer."
| Ok conn ->
action conn
>>=? fun () -> P2p_connection.close conn >>= fun () -> return_unit
action conn >>=? fun () ->
P2p_connection.close conn >>= fun () -> return_unit
let replicate n x =
let rec replicate_acc acc n x =
......@@ -190,10 +187,8 @@ let request_block_times block_hash n conn =
let request_op_times op_signed n conn =
let open Operation_hash in
let op_hash = hash_bytes [op_signed] in
lwt_log_notice "sending %a transaction" pp_short op_hash
>>= fun () ->
send conn (Operation op_signed)
>>=? fun () ->
lwt_log_notice "sending %a transaction" pp_short op_hash >>= fun () ->
send conn (Operation op_signed) >>=? fun () ->
lwt_log_notice "requesting %a transaction %d times" pp_short op_hash n
>>= fun () ->
let op_hashes = replicate n op_hash in
......@@ -228,8 +223,7 @@ let send_operation_size n conn =
Operation_hash.pp_short
op_hashed
>>= fun () ->
send conn (Operation op_faked)
>>=? fun () ->
send conn (Operation op_faked) >>=? fun () ->
let block = signed (block_forged [op_hashed]) in
let block_hashed = Block_hash.hash_bytes [block] in
lwt_log_notice
......@@ -247,8 +241,7 @@ let send_operation_bad_signature () conn =
pp_short
hashed_wrong_op
>>= fun () ->
send conn (Operation signed_wrong_op)
>>=? fun () ->
send conn (Operation signed_wrong_op) >>=? fun () ->
let block = signed (block_forged [hashed_wrong_op]) in
let block_hashed = Block_hash.hash_bytes [block] in
lwt_log_notice
......@@ -274,16 +267,14 @@ let double_spend () conn =
let block_hashed = Block_hash.hash_bytes [block_signed] in
lwt_log_notice "propagating operation %a" Operation_hash.pp_short op_hashed
>>= fun () ->
send conn (Operation op_signed)
>>=? fun () ->
send conn (Operation op_signed) >>=? fun () ->
lwt_log_notice "propagating block %a" Block_hash.pp_short block_hashed
>>= fun () -> send conn (Block block_signed)
in
spend destination_account >>=? fun () -> spend another_account
let long_chain n conn =
lwt_log_notice "propagating %d blocks" n
>>= fun () ->
lwt_log_notice "propagating %d blocks" n >>= fun () ->
let prev_ref = ref genesis_block_hashed in
let rec loop k =
if k < 1 then return_unit
......@@ -302,10 +293,8 @@ let lots_transactions amount fee n conn =
in
let ops = replicate n (Operation_hash.hash_bytes [signed_op]) in
let signed_block = signed (block_forged ops) in
lwt_log_notice "propagating %d transactions" n
>>= fun () ->
loop n
>>=? fun () ->
lwt_log_notice "propagating %d transactions" n >>= fun () ->
loop n >>=? fun () ->
lwt_log_notice
"propagating block %a with wrong signature"
Block_hash.pp_short
......@@ -320,13 +309,11 @@ let main () =
Arg.Unit
(fun () ->
Lwt_main.run
( lwt ()
>>= function
| Ok () ->
Lwt.return_unit
| Error err ->
lwt_log_error "Error: %a" pp_print_error err
>>= fun () -> Lwt.return_unit ))
(lwt () >>= function
| Ok () -> Lwt.return_unit
| Error err ->
lwt_log_error "Error: %a" pp_print_error err >>= fun () ->
Lwt.return_unit))
in
let run_cmd_int_suffix lwt =
Arg.String
......@@ -335,23 +322,20 @@ let main () =
let init = String.sub str 0 (String.length str - 1) in
let n =
if last == 'k' || last == 'K' then int_of_string init * (1 lsl 10)
else if last == 'm' || last == 'M' then
int_of_string init * (1 lsl 20)
else if last == 'g' || last == 'G' then
int_of_string init * (1 lsl 30)
else if last == 'm' || last == 'M' then int_of_string init * (1 lsl 20)
else if last == 'g' || last == 'G' then int_of_string init * (1 lsl 30)
else int_of_string str
in
Lwt_main.run
( lwt n
>>= function
| Ok () ->
Lwt.return_unit
| Error err ->
lwt_log_error "Error: %a" pp_print_error err
>>= fun () -> Lwt.return_unit ))
(lwt n >>= function
| Ok () -> Lwt.return_unit
| Error err ->
lwt_log_error "Error: %a" pp_print_error err >>= fun () ->
Lwt.return_unit))
in
let cmds =
[ ( "-1",
[
( "-1",
run_cmd_int_suffix
(run_action << request_block_times genesis_block_hashed),
"[N {,K,M,G}] Attempt to request to download N {,kilo,mega,giga}blocks."
......@@ -359,8 +343,7 @@ let main () =
( "-2",
run_cmd_int_suffix
(run_action << request_op_times (signed (tx_forged 5L 1L))),
"[N {,K,M,G}] Attempt to request to download N {,kilo,mega,giga}ops."
);
"[N {,K,M,G}] Attempt to request to download N {,kilo,mega,giga}ops." );
( "-3",
run_cmd_int_suffix (run_action << send_block_size),
"[N {,K,M,G}] Attempt to propagate an N {,kilo,mega,giga}byte fake \
......@@ -387,6 +370,7 @@ let main () =
"[N {,K,M,G}] Attempt to send a chain of N {,kilo,mega,giga}blocks" );
( "-10",
run_cmd_int_suffix (run_action << lots_transactions 0L 0L),
"[N {,K,M,G}] Attempt to send N {,kilo,mega,giga}ops" ) ]
"[N {,K,M,G}] Attempt to send N {,kilo,mega,giga}ops" );
]
in
Arg.parse cmds print_endline "Tezos Evil Client"
......@@ -23,8 +23,7 @@
(* *)
(*****************************************************************************)
let group =
{Clic.name = "protocols"; title = "Commands for managing protocols"}
let group = {Clic.name = "protocols"; title = "Commands for managing protocols"}
let proto_param ~name ~desc t =
Clic.param
......@@ -40,33 +39,32 @@ let commands () =
else failwith "%s is not a directory" dn
in
let check_dir_parameter = parameter check_dir in
[ command
[
command
~group
~desc:"List protocols known by the node."
no_options
(prefixes ["list"; "protocols"] stop)
(fun () (cctxt : #Client_context.full) ->
Shell_services.Protocol.list cctxt
>>=? fun protos ->
Shell_services.Protocol.list cctxt >>=? fun protos ->
List.iter_s (fun ph -> cctxt#message "%a" Protocol_hash.pp ph) protos
>>= fun () -> return_unit);
command
~group
~desc:"Inject a new protocol into the node."
no_options
( prefixes ["inject"; "protocol"]
(prefixes ["inject"; "protocol"]
@@ param
~name:"dir"
~desc:"directory containing the sources of a protocol"
check_dir_parameter
@@ stop )
@@ stop)
(fun () dirname (cctxt : #Client_context.full) ->
Lwt.catch
(fun () ->
Tezos_base_unix.Protocol_files.read_dir dirname
>>=? fun (_hash, proto) ->
Shell_services.Injection.protocol cctxt proto
>>= function
Shell_services.Injection.protocol cctxt proto >>= function
| Ok hash ->
cctxt#message
"Injected protocol %a successfully"
......@@ -91,12 +89,11 @@ let commands () =
~group
~desc:"Dump a protocol from the node's record of protocol."
no_options
( prefixes ["dump"; "protocol"]
(prefixes ["dump"; "protocol"]
@@ proto_param ~name:"protocol hash" ~desc:""
@@ stop )
@@ stop)
(fun () ph (cctxt : #Client_context.full) ->
Shell_services.Protocol.contents cctxt ph
>>=? fun proto ->
Shell_services.Protocol.contents cctxt ph >>=? fun proto ->
Tezos_base_unix.Protocol_files.write_dir
(Protocol_hash.to_short_b58check ph)
~hash:ph
......@@ -108,12 +105,11 @@ let commands () =
~group
~desc:"Show the environment version used by a protocol."
no_options
( prefixes ["protocol"; "environment"]
(prefixes ["protocol"; "environment"]
@@ proto_param ~name:"protocol hash" ~desc:""
@@ stop )
@@ stop)
(fun () protocol_hash (cctxt : #Client_context.full) ->
Shell_services.Protocol.environment cctxt protocol_hash
>>=? fun env ->
Shell_services.Protocol.environment cctxt protocol_hash >>=? fun env ->
cctxt#message
"Protocol %a uses environment %s"
Protocol_hash.pp
......@@ -124,12 +120,11 @@ let commands () =
~group
~desc:"Fetch a protocol from the network."
no_options
( prefixes ["fetch"; "protocol"]
(prefixes ["fetch"; "protocol"]
@@ proto_param ~name:"protocol hash" ~desc:""
@@ stop )
@@ stop)
(fun () hash (cctxt : #Client_context.full) ->
Shell_services.Protocol.fetch cctxt hash
>>= function
Shell_services.Protocol.fetch cctxt hash >>= function
| Ok () ->
cctxt#message
"Protocol %a successfully fetched."
......@@ -141,4 +136,5 @@ let commands () =
"Error while fetching protocol: %a"
Error_monad.pp_print_error
err
>>= fun () -> return_unit) ]
>>= fun () -> return_unit);
]
This diff is collapsed.
......@@ -27,11 +27,13 @@
let select_commands _ _ =
return
(List.flatten
[ Client_report_commands.commands ();
[
Client_report_commands.commands ();
Client_admin_commands.commands ();
Client_p2p_commands.commands ();
Client_protocols_commands.commands ();
Client_rpc_commands.commands;
Client_event_logging_commands.commands () ])
Client_event_logging_commands.commands ();
])
let () = Client_main_run.run (module Client_config) ~select_commands
......@@ -28,10 +28,8 @@ open Client_config
let disable_disclaimer =
match Sys.getenv_opt "TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER" with
| Some ("yes" | "y" | "YES" | "Y") ->
true
| _ ->
false
| Some ("yes" | "y" | "YES" | "Y") -> true
| _ -> false
let testnet_disclaimer () =