From 89814a3d4e7810e23b35fc07396354986816d2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Thu, 20 Apr 2017 15:50:02 +0200 Subject: [PATCH] Proto/Alpha: more RPCs --- .../embedded/alpha/client_proto_rpcs.ml | 22 ++++++++++----- .../embedded/alpha/client_proto_rpcs.mli | 10 +++++++ src/proto/alpha/services.ml | 27 ++++++++++++++++++- src/proto/alpha/services_registration.ml | 18 +++++++++++++ 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/client/embedded/alpha/client_proto_rpcs.ml b/src/client/embedded/alpha/client_proto_rpcs.ml index 181c7eaaa..3d8f667b8 100644 --- a/src/client/embedded/alpha/client_proto_rpcs.ml +++ b/src/client/embedded/alpha/client_proto_rpcs.ml @@ -16,13 +16,9 @@ let handle_error cctxt = function pp_print_error Format.err_formatter exns ; cctxt.Client_commands.error "%s" "cannot continue" -type block = [ - | `Genesis - | `Head of int | `Prevalidation - | `Test_head of int | `Test_prevalidation - | `Hash of Block_hash.t -] - +let call_service0 cctxt s block = + Client_rpcs.call_service0 cctxt + (s Node_rpc_services.Blocks.proto_path) block let call_service1 cctxt s block a1 = Client_rpcs.call_service1 cctxt (s Node_rpc_services.Blocks.proto_path) block a1 @@ -40,6 +36,18 @@ let call_error_service2 cctxt s block a1 a2 = | Ok (Ok v) -> return v | Error _ as err -> Lwt.return err +type block = Node_rpc_services.Blocks.block + +let header cctxt block = + call_error_service1 cctxt Services.header block () + +module Header = struct + let priority cctxt block = + call_error_service1 cctxt Services.Header.priority block () + let seed_nonce_hash cctxt block = + call_error_service1 cctxt Services.Header.seed_nonce_hash block () +end + module Constants = struct let errors cctxt block = call_service1 cctxt Services.Constants.errors block () diff --git a/src/client/embedded/alpha/client_proto_rpcs.mli b/src/client/embedded/alpha/client_proto_rpcs.mli index 7ce664a9f..4b2f83890 100644 --- a/src/client/embedded/alpha/client_proto_rpcs.mli +++ b/src/client/embedded/alpha/client_proto_rpcs.mli @@ -17,6 +17,16 @@ type block = [ | `Hash of Block_hash.t ] +val header: + Client_rpcs.config -> block -> Block_header.t tzresult Lwt.t + +module Header : sig + val priority: + Client_rpcs.config -> block -> int tzresult Lwt.t + val seed_nonce_hash: + Client_rpcs.config -> block -> Nonce_hash.t tzresult Lwt.t +end + module Constants : sig val errors: Client_rpcs.config -> diff --git a/src/proto/alpha/services.ml b/src/proto/alpha/services.ml index 5fc3bf10c..81f639ab4 100644 --- a/src/proto/alpha/services.ml +++ b/src/proto/alpha/services.ml @@ -37,12 +37,37 @@ let wrap_tzerror encoding = let operations custom_root = RPC.service - ~description: "All the operations of the block (parsed)." + ~description: "All the operations of the block (fully decoded)." ~input: empty ~output: (wrap_tzerror @@ (list (list (dynamic_size Operation.encoding)))) RPC.Path.(custom_root / "operations") +let header custom_root = + RPC.service + ~description: "The header of the block (fully decoded)." + ~input: empty + ~output: (wrap_tzerror Block_header.encoding) + RPC.Path.(custom_root / "header") + +module Header = struct + + let priority custom_root = + RPC.service + ~description: "Mining priority of the block." + ~input: empty + ~output: (wrap_tzerror uint16) + RPC.Path.(custom_root / "header" / "priority") + + let seed_nonce_hash custom_root = + RPC.service + ~description: "Hash of the seed nonce of the block." + ~input: empty + ~output: (wrap_tzerror Nonce_hash.encoding) + RPC.Path.(custom_root / "header" / "seed_nonce_hash") + +end + module Constants = struct let cycle_length custom_root = diff --git a/src/proto/alpha/services_registration.ml b/src/proto/alpha/services_registration.ml index e0e2a4185..b349a6c13 100644 --- a/src/proto/alpha/services_registration.ml +++ b/src/proto/alpha/services_registration.ml @@ -69,6 +69,24 @@ let () = (map2_s (fun x y -> Lwt.return (Operation.parse x y))) operation_hashes operations) +let () = + register0_fullctxt + Services.header + (fun { block_header } -> + Lwt.return (Block_header.parse block_header) >>=? fun block_header -> + return block_header) ; + register0_fullctxt + Services.Header.priority + (fun { block_header } -> + Lwt.return (Block_header.parse block_header) >>=? fun block_header -> + return block_header.proto.priority) ; + register0_fullctxt + Services.Header.seed_nonce_hash + (fun { block_header } -> + Lwt.return (Block_header.parse block_header) >>=? fun block_header -> + return block_header.proto.seed_nonce_hash) + + (*-- Constants ---------------------------------------------------------------*) let cycle_length ctxt =