2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
(* Tezos Command line interface - RPC Calls *)
|
|
|
|
|
2017-04-05 01:35:41 +04:00
|
|
|
open Client_rpcs
|
2016-09-08 21:13:10 +04:00
|
|
|
module Services = Node_rpc_services
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-12-07 20:43:21 +04:00
|
|
|
let errors (rpc : #Client_rpcs.ctxt) =
|
2017-11-07 20:38:11 +04:00
|
|
|
call_service0 rpc Services.Error.service ()
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-11-07 20:38:11 +04:00
|
|
|
let forge_block_header rpc header =
|
|
|
|
call_service0 rpc Services.forge_block_header header
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-11-14 06:14:26 +04:00
|
|
|
let inject_block cctxt
|
|
|
|
?(async = false) ?(force = false) ?net_id
|
|
|
|
raw operations =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_err_service0 cctxt Services.inject_block
|
2017-11-14 06:14:26 +04:00
|
|
|
{ raw ; blocking = not async ; force ; net_id ; operations }
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-11-14 05:41:37 +04:00
|
|
|
let inject_operation cctxt ?(async = false) ?force ?net_id operation =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_err_service0 cctxt Services.inject_operation
|
2017-11-14 05:41:37 +04:00
|
|
|
(operation, not async, net_id, force)
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-03-30 15:08:33 +04:00
|
|
|
let inject_protocol cctxt ?(async = false) ?force protocol =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_err_service0 cctxt Services.inject_protocol
|
|
|
|
(protocol, not async, force)
|
|
|
|
|
2017-02-28 03:48:22 +04:00
|
|
|
let bootstrapped cctxt =
|
|
|
|
call_streamed_service0 cctxt Services.bootstrapped ()
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let complete cctxt ?block prefix =
|
2016-11-15 17:44:16 +04:00
|
|
|
match block with
|
|
|
|
| None ->
|
2016-12-03 16:05:02 +04:00
|
|
|
call_service1 cctxt Services.complete prefix ()
|
2016-11-15 17:44:16 +04:00
|
|
|
| Some block ->
|
2016-12-03 16:05:02 +04:00
|
|
|
call_service2 cctxt Services.Blocks.complete block prefix ()
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
let describe config ?(recurse = true) path =
|
2017-12-09 06:51:58 +04:00
|
|
|
let { RPC_service.meth ; uri } =
|
|
|
|
RPC_service.forge_request Node_rpc_services.describe
|
|
|
|
((), path) { RPC_description.recurse } in
|
2017-12-07 20:43:21 +04:00
|
|
|
let path = String.split_path (Uri.path uri) in (* Temporary *)
|
2017-11-07 20:38:11 +04:00
|
|
|
config#get_json meth path (`O []) >>=? fun json ->
|
2017-12-09 06:51:58 +04:00
|
|
|
match Data_encoding.Json.destruct (RPC_service.output_encoding Node_rpc_services.describe) json with
|
2017-11-27 09:13:12 +04:00
|
|
|
| exception msg ->
|
|
|
|
let msg =
|
|
|
|
Format.asprintf "%a" (fun x -> Data_encoding.Json.print_error x) msg in
|
|
|
|
failwith "Failed to parse Json answer: %s" msg
|
|
|
|
| v -> return v
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
module Blocks = struct
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
type block = Services.Blocks.block
|
|
|
|
|
|
|
|
type block_info = Services.Blocks.block_info = {
|
|
|
|
hash: Block_hash.t ;
|
2017-04-10 19:06:11 +04:00
|
|
|
net_id: Net_id.t ;
|
2017-04-10 15:01:22 +04:00
|
|
|
level: Int32.t ;
|
2017-04-12 20:22:40 +04:00
|
|
|
proto_level: int ; (* uint8 *)
|
2016-09-08 21:13:10 +04:00
|
|
|
predecessor: Block_hash.t ;
|
|
|
|
timestamp: Time.t ;
|
2017-09-29 20:43:13 +04:00
|
|
|
validation_passes: int ; (* uint8 *)
|
2017-03-30 15:16:21 +04:00
|
|
|
operations_hash: Operation_list_list_hash.t ;
|
2017-04-10 19:06:11 +04:00
|
|
|
fitness: MBytes.t list ;
|
|
|
|
data: MBytes.t ;
|
2017-11-14 02:27:19 +04:00
|
|
|
operations: (Operation_hash.t * Operation.t) list list option ;
|
2017-04-10 19:06:11 +04:00
|
|
|
protocol: Protocol_hash.t ;
|
2017-11-27 09:13:12 +04:00
|
|
|
test_network: Test_network_status.t;
|
2016-09-08 21:13:10 +04:00
|
|
|
}
|
|
|
|
type preapply_param = Services.Blocks.preapply_param = {
|
2017-04-27 03:01:05 +04:00
|
|
|
timestamp: Time.t ;
|
|
|
|
proto_header: MBytes.t ;
|
2017-11-14 02:27:19 +04:00
|
|
|
operations: Operation.t list ;
|
2017-04-27 03:01:05 +04:00
|
|
|
sort_operations: bool ;
|
2016-09-08 21:13:10 +04:00
|
|
|
}
|
|
|
|
type preapply_result = Services.Blocks.preapply_result = {
|
2017-04-27 03:01:05 +04:00
|
|
|
shell_header: Block_header.shell_header ;
|
2017-11-27 09:13:12 +04:00
|
|
|
operations: error Preapply_result.t ;
|
2016-09-08 21:13:10 +04:00
|
|
|
}
|
2017-04-20 10:26:43 +04:00
|
|
|
let net_id cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.net_id h ()
|
2017-04-10 15:01:22 +04:00
|
|
|
let level cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.level h ()
|
2017-04-05 01:35:41 +04:00
|
|
|
let predecessor cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.predecessor h ()
|
|
|
|
let predecessors cctxt h l =
|
|
|
|
call_service1 cctxt Services.Blocks.predecessors h l
|
|
|
|
let hash cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.hash h ()
|
|
|
|
let timestamp cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.timestamp h ()
|
|
|
|
let fitness cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.fitness h ()
|
2017-04-19 23:46:10 +04:00
|
|
|
let operations cctxt ?(contents = false) h =
|
|
|
|
call_service1 cctxt Services.Blocks.operations h
|
|
|
|
{ contents ; monitor = false }
|
2017-04-05 01:35:41 +04:00
|
|
|
let protocol cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.protocol h ()
|
|
|
|
let test_network cctxt h =
|
|
|
|
call_service1 cctxt Services.Blocks.test_network h ()
|
2017-04-10 15:01:22 +04:00
|
|
|
|
2017-04-27 03:01:05 +04:00
|
|
|
let preapply cctxt h
|
|
|
|
?(timestamp = Time.now ()) ?(sort = false) ~proto_header operations =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_err_service1
|
|
|
|
cctxt Services.Blocks.preapply h
|
2017-04-27 03:01:05 +04:00
|
|
|
{ timestamp ; proto_header ; sort_operations = sort ; operations }
|
2016-12-03 16:05:02 +04:00
|
|
|
let pending_operations cctxt block =
|
|
|
|
call_service1 cctxt Services.Blocks.pending_operations block ()
|
2017-04-10 19:06:11 +04:00
|
|
|
let info cctxt ?(include_ops = true) h =
|
|
|
|
call_service1 cctxt Services.Blocks.info h include_ops
|
2016-12-03 16:05:02 +04:00
|
|
|
let complete cctxt block prefix =
|
|
|
|
call_service2 cctxt Services.Blocks.complete block prefix ()
|
2017-04-10 19:06:11 +04:00
|
|
|
let list cctxt ?(include_ops = false)
|
2017-03-22 20:21:52 +04:00
|
|
|
?length ?heads ?delay ?min_date ?min_heads () =
|
2016-12-03 16:05:02 +04:00
|
|
|
call_service0 cctxt Services.Blocks.list
|
2017-04-10 19:06:11 +04:00
|
|
|
{ include_ops ; length ; heads ; monitor = Some false ; delay ;
|
2016-09-21 18:22:43 +04:00
|
|
|
min_date ; min_heads }
|
2017-04-10 19:06:11 +04:00
|
|
|
let monitor cctxt ?(include_ops = false)
|
2017-03-22 20:21:52 +04:00
|
|
|
?length ?heads ?delay ?min_date ?min_heads () =
|
2016-12-03 16:05:02 +04:00
|
|
|
call_streamed_service0 cctxt Services.Blocks.list
|
2017-04-10 19:06:11 +04:00
|
|
|
{ include_ops ; length ; heads ; monitor = Some true ; delay ;
|
2016-09-21 18:22:43 +04:00
|
|
|
min_date ; min_heads }
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
module Operations = struct
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-04-19 23:46:10 +04:00
|
|
|
let monitor cctxt ?(contents = false) () =
|
|
|
|
call_streamed_service1 cctxt Services.Blocks.operations
|
|
|
|
`Prevalidation
|
|
|
|
{ contents ; monitor = true }
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2016-09-08 21:13:10 +04:00
|
|
|
end
|
2016-10-25 21:00:03 +04:00
|
|
|
|
|
|
|
module Protocols = struct
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-03-30 16:31:16 +04:00
|
|
|
let contents cctxt hash =
|
|
|
|
call_service1 cctxt Services.Protocols.contents hash ()
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2016-12-03 16:05:02 +04:00
|
|
|
let list cctxt ?contents () =
|
2017-04-05 01:35:41 +04:00
|
|
|
call_service0
|
|
|
|
cctxt Services.Protocols.list
|
|
|
|
{ contents; monitor = Some false }
|
|
|
|
|
2016-10-25 21:00:03 +04:00
|
|
|
end
|
2017-03-02 18:39:36 +04:00
|
|
|
|
|
|
|
module Network = struct
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-03-02 18:39:36 +04:00
|
|
|
let stat cctxt =
|
|
|
|
call_service0 cctxt Services.Network.stat ()
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-03-02 18:39:36 +04:00
|
|
|
let connections cctxt =
|
|
|
|
call_service0 cctxt Services.Network.Connection.list ()
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-03-02 18:39:36 +04:00
|
|
|
let peers cctxt =
|
|
|
|
call_service0 cctxt Services.Network.Peer_id.list []
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-03-02 18:39:36 +04:00
|
|
|
let points cctxt =
|
|
|
|
call_service0 cctxt Services.Network.Point.list []
|
2017-04-05 01:35:41 +04:00
|
|
|
|
2017-03-02 18:39:36 +04:00
|
|
|
end
|