Proto/Alpha: more RPCs

This commit is contained in:
Grégoire Henry 2017-04-20 15:50:02 +02:00
parent d06fcebd1f
commit 89814a3d4e
4 changed files with 69 additions and 8 deletions

View File

@ -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 ()

View File

@ -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 ->

View File

@ -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 =

View File

@ -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 =