2017-02-24 18:38:42 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2016. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-04-05 01:35:41 +04:00
|
|
|
open Client_commands
|
|
|
|
|
2017-02-24 18:38:42 +04:00
|
|
|
let protocol =
|
|
|
|
Protocol_hash.of_b58check
|
|
|
|
"ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im"
|
|
|
|
|
|
|
|
let call_service1 cctxt s block a1 =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_rpcs.call_service1 cctxt
|
2017-02-24 18:38:42 +04:00
|
|
|
(s Node_rpc_services.Blocks.proto_path) block a1
|
|
|
|
|
|
|
|
let call_error_service1 cctxt s block a1 =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_service1 cctxt s block a1 >>= function
|
|
|
|
| Ok (Error _ as err) -> Lwt.return (wrap_error err)
|
|
|
|
| Ok (Ok v) -> return v
|
|
|
|
| Error _ as err -> Lwt.return err
|
2017-02-24 18:38:42 +04:00
|
|
|
|
2017-02-25 21:10:29 +04:00
|
|
|
let forge_block
|
|
|
|
cctxt block net_id ?(timestamp = Time.now ()) command fitness =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_blocks.get_block_hash cctxt block >>=? fun pred ->
|
2017-02-24 18:38:42 +04:00
|
|
|
call_service1 cctxt
|
|
|
|
Services.Forge.block block
|
2017-02-25 21:10:29 +04:00
|
|
|
((net_id, pred, timestamp, fitness), command)
|
2017-02-24 18:38:42 +04:00
|
|
|
|
2017-03-06 18:54:05 +04:00
|
|
|
let mine cctxt ?timestamp block command fitness seckey =
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_blocks.get_block_info cctxt.rpc_config block >>=? fun bi ->
|
|
|
|
forge_block cctxt.rpc_config ?timestamp block bi.net command fitness >>=? fun blk ->
|
2017-02-28 05:56:40 +04:00
|
|
|
let signed_blk = Environment.Ed25519.Signature.append seckey blk in
|
2017-04-05 01:35:41 +04:00
|
|
|
Client_node_rpcs.inject_block cctxt.rpc_config signed_blk [[]] >>=? fun hash ->
|
2017-02-24 18:38:42 +04:00
|
|
|
cctxt.answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
|
|
|
return ()
|
|
|
|
|
|
|
|
let handle_error cctxt = function
|
|
|
|
| Ok res ->
|
|
|
|
Lwt.return res
|
|
|
|
| Error exns ->
|
|
|
|
pp_print_error Format.err_formatter exns ;
|
|
|
|
cctxt.Client_commands.error "%s" "cannot continue"
|
|
|
|
|
|
|
|
let commands () =
|
2017-03-06 18:54:05 +04:00
|
|
|
let timestamp = ref None in
|
|
|
|
let args =
|
|
|
|
[ "-timestamp",
|
|
|
|
Arg.String (fun t -> timestamp := Some (Time.of_notation_exn t)),
|
|
|
|
"Set the timestamp of the block (and initial time of the chain)" ] in
|
2017-02-24 18:38:42 +04:00
|
|
|
let open Cli_entries in
|
|
|
|
[
|
2017-03-30 15:16:21 +04:00
|
|
|
|
2017-03-06 18:54:05 +04:00
|
|
|
command ~args ~desc: "Activate a protocol" begin
|
2017-02-24 18:38:42 +04:00
|
|
|
prefixes [ "activate" ; "protocol" ] @@
|
|
|
|
param ~name:"version" ~desc:"Protocol version (b58check)"
|
|
|
|
(fun _ p -> Lwt.return @@ Protocol_hash.of_b58check p) @@
|
|
|
|
prefixes [ "with" ; "fitness" ] @@
|
|
|
|
param ~name:"fitness"
|
|
|
|
~desc:"Hardcoded fitness of the first block (integer)"
|
|
|
|
(fun _ p -> Lwt.return (Int64.of_string p)) @@
|
|
|
|
prefixes [ "and" ; "key" ] @@
|
2017-02-28 11:18:06 +04:00
|
|
|
Client_keys.Secret_key.source_param
|
|
|
|
~name:"password" ~desc:"Dictator's key" @@
|
|
|
|
stop
|
2017-03-30 15:16:21 +04:00
|
|
|
end begin fun hash fitness seckey cctxt ->
|
2017-03-06 18:54:05 +04:00
|
|
|
let timestamp = !timestamp in
|
2017-02-25 21:01:29 +04:00
|
|
|
let fitness =
|
|
|
|
Client_embedded_proto_alpha.Fitness_repr.from_int64 fitness in
|
2017-03-15 04:17:20 +04:00
|
|
|
mine cctxt ?timestamp cctxt.config.block
|
2017-04-05 01:35:41 +04:00
|
|
|
(Activate hash) fitness seckey
|
2017-03-30 15:16:21 +04:00
|
|
|
end ;
|
|
|
|
|
|
|
|
command ~args ~desc: "Fork a test protocol" begin
|
2017-02-24 18:38:42 +04:00
|
|
|
prefixes [ "fork" ; "test" ; "protocol" ] @@
|
|
|
|
param ~name:"version" ~desc:"Protocol version (b58check)"
|
|
|
|
(fun _ p -> Lwt.return (Protocol_hash.of_b58check p)) @@
|
|
|
|
prefixes [ "with" ; "fitness" ] @@
|
|
|
|
param ~name:"fitness"
|
|
|
|
~desc:"Hardcoded fitness of the first block (integer)"
|
|
|
|
(fun _ p -> Lwt.return (Int64.of_string p)) @@
|
|
|
|
prefixes [ "and" ; "key" ] @@
|
|
|
|
param ~name:"password" ~desc:"Dictator's key"
|
|
|
|
(fun _ key ->
|
2017-03-30 15:16:21 +04:00
|
|
|
Lwt.return (Environment.Ed25519.Secret_key.of_b58check key)) @@
|
|
|
|
stop
|
|
|
|
end begin fun hash fitness seckey cctxt ->
|
|
|
|
let timestamp = !timestamp in
|
|
|
|
let fitness =
|
|
|
|
Client_embedded_proto_alpha.Fitness_repr.from_int64 fitness in
|
|
|
|
mine cctxt ?timestamp cctxt.config.block
|
2017-04-05 01:35:41 +04:00
|
|
|
(Activate_testnet hash) fitness seckey
|
2017-03-30 15:16:21 +04:00
|
|
|
end ;
|
|
|
|
|
2017-02-24 18:38:42 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
let () =
|
|
|
|
Client_commands.register protocol @@
|
|
|
|
commands ()
|