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. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
let protocol =
|
2017-04-05 11:54:21 +04:00
|
|
|
Protocol_hash.of_b58check_exn
|
2017-02-19 21:22:32 +04:00
|
|
|
"ProtoDemoDemoDemoDemoDemoDemoDemoDemoDemoDemoD3c8k9"
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let demo cctxt =
|
2017-03-15 04:17:20 +04:00
|
|
|
let block = Client_commands.(cctxt.config.block) in
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.Client_commands.message "Calling the 'echo' RPC." >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let msg = "test" in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.echo cctxt.rpc_config block msg >>=? fun reply ->
|
2017-04-19 23:46:10 +04:00
|
|
|
fail_unless (reply = msg) (failure "...") >>=? fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
begin
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Calling the 'failing' RPC." >>= fun () ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_proto_rpcs.failing cctxt.rpc_config block 3 >>= function
|
2016-09-08 21:13:10 +04:00
|
|
|
| Error [Ecoproto_error [Error.Demo_error 3]] ->
|
|
|
|
return ()
|
|
|
|
| _ -> failwith "..."
|
|
|
|
end >>=? fun () ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.message "Direct call to `demo_error`." >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
begin Error.demo_error 101010 >|= wrap_error >>= function
|
|
|
|
| Error [Ecoproto_error [Error.Demo_error 101010]] ->
|
|
|
|
return ()
|
|
|
|
| _ -> failwith "...."
|
|
|
|
end >>=? fun () ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.answer "All good!" >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return ()
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let mine cctxt =
|
2017-04-20 10:26:43 +04:00
|
|
|
let block = Client_rpcs.last_mined_block cctxt.Client_commands.config.block in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.Blocks.info cctxt.rpc_config block >>=? fun bi ->
|
2016-09-08 21:13:10 +04:00
|
|
|
let fitness =
|
|
|
|
match bi.fitness with
|
|
|
|
| [ v ; b ] ->
|
|
|
|
let f = MBytes.get_int64 b 0 in
|
|
|
|
MBytes.set_int64 b 0 (Int64.succ f) ;
|
|
|
|
[ v ; b ]
|
|
|
|
| _ ->
|
2016-11-22 20:59:09 +04:00
|
|
|
Lwt.ignore_result
|
2017-10-09 12:55:12 +04:00
|
|
|
(cctxt.message "Cannot parse fitness: %a" Environment.Fitness.pp bi.fitness);
|
2016-09-08 21:13:10 +04:00
|
|
|
exit 2 in
|
2017-04-27 03:01:05 +04:00
|
|
|
Client_node_rpcs.forge_block_header cctxt.rpc_config
|
|
|
|
{ shell = { net_id = bi.net_id ;
|
|
|
|
predecessor = bi.hash ;
|
|
|
|
proto_level = bi.proto_level ;
|
|
|
|
level = Int32.succ bi.level ;
|
|
|
|
timestamp = Time.now () ;
|
|
|
|
fitness ;
|
|
|
|
operations_hash = Operation_list_list_hash.empty } ;
|
|
|
|
proto = MBytes.create 0 } >>=? fun bytes ->
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.inject_block cctxt.rpc_config bytes [] >>=? fun hash ->
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
2016-09-08 21:13:10 +04:00
|
|
|
return ()
|
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let handle_error cctxt = function
|
2016-09-08 21:13:10 +04:00
|
|
|
| Ok res ->
|
|
|
|
Lwt.return res
|
|
|
|
| Error exns ->
|
|
|
|
pp_print_error Format.err_formatter exns ;
|
2016-12-03 16:05:02 +04:00
|
|
|
cctxt.Client_commands.error "%s" "cannot continue"
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let commands () =
|
|
|
|
let open Cli_entries in
|
2016-12-03 16:05:02 +04:00
|
|
|
let group = {name = "demo" ; title = "Some demo command" } in
|
2016-09-08 21:13:10 +04:00
|
|
|
[
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "A demo command"
|
2017-09-19 13:31:35 +04:00
|
|
|
no_options
|
2016-09-08 21:13:10 +04:00
|
|
|
(fixed [ "demo" ])
|
2017-09-19 13:31:35 +04:00
|
|
|
(fun () cctxt -> demo cctxt) ;
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "A failing command"
|
2017-09-19 13:31:35 +04:00
|
|
|
no_options
|
2016-09-08 21:13:10 +04:00
|
|
|
(fixed [ "fail" ])
|
2017-09-19 13:31:35 +04:00
|
|
|
(fun () _cctxt ->
|
2016-09-08 21:13:10 +04:00
|
|
|
Error.demo_error 101010
|
2017-04-05 01:35:41 +04:00
|
|
|
>|= wrap_error) ;
|
2016-12-03 16:05:02 +04:00
|
|
|
command ~group ~desc: "Mine an empty block"
|
2017-09-19 13:31:35 +04:00
|
|
|
no_options
|
2016-09-08 21:13:10 +04:00
|
|
|
(fixed [ "mine" ])
|
2017-09-19 13:31:35 +04:00
|
|
|
(fun () cctxt -> mine cctxt) ;
|
2016-09-08 21:13:10 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
let () =
|
2016-12-03 16:05:02 +04:00
|
|
|
Client_commands.register protocol @@
|
2016-09-08 21:13:10 +04:00
|
|
|
commands ()
|