2017-02-24 18:38:42 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2017-02-24 18:38:42 +04:00
|
|
|
(* 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-10-27 22:45:31 +04:00
|
|
|
open Tezos_embedded_raw_protocol_genesis
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-02-24 18:38:42 +04:00
|
|
|
let protocol =
|
2017-04-05 11:54:21 +04:00
|
|
|
Protocol_hash.of_b58check_exn
|
2017-02-24 18:38:42 +04:00
|
|
|
"ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im"
|
|
|
|
|
2017-04-06 00:33:46 +04:00
|
|
|
let call_service1 rpc_config s block a1 =
|
|
|
|
Client_rpcs.call_service1 rpc_config
|
2017-02-24 18:38:42 +04:00
|
|
|
(s Node_rpc_services.Blocks.proto_path) block a1
|
|
|
|
|
2017-04-06 00:33:46 +04:00
|
|
|
let call_error_service1 rpc_config s block a1 =
|
|
|
|
call_service1 rpc_config s block a1 >>= function
|
2017-10-27 20:53:07 +04:00
|
|
|
| Ok (Error _ as err) -> Lwt.return (Environment.wrap_error err)
|
2017-04-05 01:35:41 +04:00
|
|
|
| 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
|
2017-04-06 00:33:46 +04:00
|
|
|
rpc_config block net_id ?(timestamp = Time.now ()) command fitness =
|
2017-11-20 06:37:06 +04:00
|
|
|
let block = Client_rpcs.last_baked_block block in
|
2017-04-20 10:26:43 +04:00
|
|
|
Client_node_rpcs.Blocks.info rpc_config block >>=? fun pred ->
|
2017-03-09 17:43:59 +04:00
|
|
|
let proto_level =
|
|
|
|
match command with
|
|
|
|
| Data.Command.Activate _ -> 1
|
2017-11-19 18:07:59 +04:00
|
|
|
| Data.Command.Activate_testnet _ -> 0 in
|
2017-04-06 00:33:46 +04:00
|
|
|
call_service1 rpc_config
|
2017-02-24 18:38:42 +04:00
|
|
|
Services.Forge.block block
|
2017-04-20 10:26:43 +04:00
|
|
|
((net_id, Int32.succ pred.level, proto_level,
|
|
|
|
pred.hash, timestamp, fitness), command)
|
2017-02-24 18:38:42 +04:00
|
|
|
|
2017-11-20 06:37:06 +04:00
|
|
|
let bake rpc_config ?timestamp block command fitness seckey =
|
|
|
|
let block = Client_rpcs.last_baked_block block in
|
2017-04-20 10:26:43 +04:00
|
|
|
Client_node_rpcs.Blocks.info rpc_config block >>=? fun bi ->
|
2017-04-10 19:06:11 +04:00
|
|
|
forge_block
|
|
|
|
rpc_config ?timestamp block bi.net_id command fitness >>=? fun blk ->
|
2017-11-27 09:13:12 +04:00
|
|
|
let signed_blk = Ed25519.Signature.append seckey blk in
|
2017-11-19 18:07:59 +04:00
|
|
|
Client_node_rpcs.inject_block rpc_config signed_blk []
|
2017-02-24 18:38:42 +04:00
|
|
|
|
2017-09-27 11:55:20 +04:00
|
|
|
let int64_parameter =
|
|
|
|
(Cli_entries.parameter (fun _ p ->
|
|
|
|
try return (Int64.of_string p)
|
|
|
|
with _ -> failwith "Cannot read int64"))
|
|
|
|
|
2017-11-19 18:07:59 +04:00
|
|
|
let int_parameter =
|
|
|
|
(Cli_entries.parameter (fun _ p ->
|
|
|
|
try return (int_of_string p)
|
|
|
|
with _ -> failwith "Cannot read int"))
|
|
|
|
|
2017-02-24 18:38:42 +04:00
|
|
|
let commands () =
|
|
|
|
let open Cli_entries in
|
2017-09-19 13:31:35 +04:00
|
|
|
let args =
|
|
|
|
args1
|
|
|
|
(arg
|
|
|
|
~parameter:"-timestamp"
|
|
|
|
~doc:"Set the timestamp of the block (and initial time of the chain)"
|
2017-09-27 11:55:20 +04:00
|
|
|
(parameter (fun _ t ->
|
|
|
|
match (Time.of_notation t) with
|
|
|
|
| None -> Error_monad.failwith "Could not parse value provided to -timestamp option"
|
|
|
|
| Some t -> return t))) in
|
2017-02-24 18:38:42 +04:00
|
|
|
[
|
2017-03-30 15:16:21 +04:00
|
|
|
|
2017-09-19 13:31:35 +04:00
|
|
|
command ~desc: "Activate a protocol"
|
|
|
|
args
|
|
|
|
(prefixes [ "activate" ; "protocol" ]
|
|
|
|
@@ Protocol_hash.param ~name:"version" ~desc:"Protocol version (b58check)"
|
|
|
|
@@ prefixes [ "with" ; "fitness" ]
|
|
|
|
@@ param ~name:"fitness"
|
|
|
|
~desc:"Hardcoded fitness of the first block (integer)"
|
2017-09-27 11:55:20 +04:00
|
|
|
int64_parameter
|
2017-11-19 18:07:59 +04:00
|
|
|
@@ prefixes [ "and" ; "passes" ]
|
|
|
|
@@ param ~name:"passes"
|
|
|
|
~desc:"Hardcoded number of validation passes (integer)"
|
|
|
|
int_parameter
|
2017-09-19 13:31:35 +04:00
|
|
|
@@ prefixes [ "and" ; "key" ]
|
|
|
|
@@ Client_keys.Secret_key.source_param
|
|
|
|
~name:"password" ~desc:"Dictator's key"
|
|
|
|
@@ stop)
|
2017-11-19 18:07:59 +04:00
|
|
|
begin fun timestamp hash fitness validation_passes seckey cctxt ->
|
2017-09-19 13:31:35 +04:00
|
|
|
let fitness =
|
2017-10-27 22:45:31 +04:00
|
|
|
Tezos_embedded_raw_protocol_alpha.Fitness_repr.from_int64 fitness in
|
2017-11-20 06:37:06 +04:00
|
|
|
bake cctxt.rpc_config ?timestamp cctxt.config.block
|
2017-11-19 18:07:59 +04:00
|
|
|
(Activate { protocol = hash ; validation_passes })
|
|
|
|
fitness seckey >>=? fun hash ->
|
2017-09-19 13:31:35 +04:00
|
|
|
cctxt.answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
|
|
|
return ()
|
|
|
|
end ;
|
2017-03-30 15:16:21 +04:00
|
|
|
|
2017-09-19 13:31:35 +04:00
|
|
|
command ~desc: "Fork a test protocol"
|
|
|
|
args
|
|
|
|
(prefixes [ "fork" ; "test" ; "protocol" ]
|
|
|
|
@@ Protocol_hash.param ~name:"version" ~desc:"Protocol version (b58check)"
|
|
|
|
@@ prefixes [ "with" ; "fitness" ]
|
|
|
|
@@ param ~name:"fitness"
|
|
|
|
~desc:"Hardcoded fitness of the first block (integer)"
|
2017-09-27 11:55:20 +04:00
|
|
|
int64_parameter
|
2017-11-19 18:07:59 +04:00
|
|
|
@@ prefixes [ "and" ; "passes" ]
|
|
|
|
@@ param ~name:"passes"
|
|
|
|
~desc:"Hardcoded number of validation passes (integer)"
|
|
|
|
int_parameter
|
2017-09-19 13:31:35 +04:00
|
|
|
@@ prefixes [ "and" ; "key" ]
|
2017-11-27 09:13:12 +04:00
|
|
|
@@ Ed25519.Secret_key.param
|
2017-09-19 13:31:35 +04:00
|
|
|
~name:"password" ~desc:"Dictator's key"
|
|
|
|
@@ stop)
|
2017-11-19 18:07:59 +04:00
|
|
|
begin fun timestamp hash fitness validation_passes seckey cctxt ->
|
2017-09-19 13:31:35 +04:00
|
|
|
let fitness =
|
2017-10-27 22:45:31 +04:00
|
|
|
Tezos_embedded_raw_protocol_alpha.Fitness_repr.from_int64 fitness in
|
2017-11-20 06:37:06 +04:00
|
|
|
bake cctxt.rpc_config ?timestamp cctxt.config.block
|
2017-11-19 18:07:59 +04:00
|
|
|
(Activate_testnet { protocol = hash ;
|
|
|
|
validation_passes ;
|
|
|
|
delay = Int64.mul 24L 3600L })
|
2017-09-19 13:31:35 +04:00
|
|
|
fitness seckey >>=? fun hash ->
|
|
|
|
cctxt.answer "Injected %a" Block_hash.pp_short hash >>= fun () ->
|
|
|
|
return ()
|
|
|
|
end ;
|
2017-03-30 15:16:21 +04:00
|
|
|
|
2017-02-24 18:38:42 +04:00
|
|
|
]
|
|
|
|
|
|
|
|
let () =
|
|
|
|
Client_commands.register protocol @@
|
|
|
|
commands ()
|