From 5aa65ee71f4d06c0499c477054c2bd63de705f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Wed, 6 Jun 2018 15:15:15 +0200 Subject: [PATCH] Shell/RPC: allow to fetch raw `Block_header` --- src/lib_shell/block_directory.ml | 10 +++++++++- src/lib_shell_services/block_services.ml | 23 +++++++++++++++++++++++ src/lib_shell_services/block_services.mli | 17 +++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/lib_shell/block_directory.ml b/src/lib_shell/block_directory.ml index 66f1cad51..1554dcded 100644 --- a/src/lib_shell/block_directory.ml +++ b/src/lib_shell/block_directory.ml @@ -67,6 +67,10 @@ let build_raw_rpc_directory return { Block_services.hash ; chain_id ; shell = header.shell ; protocol_data } end ; + register0 S.raw_header begin fun block () () -> + let header = State.Block.header block in + return (Data_encoding.Binary.to_bytes_exn Block_header.encoding header) + end ; register0 S.Header.shell_header begin fun block () () -> return (State.Block.header block).shell end ; @@ -77,6 +81,10 @@ let build_raw_rpc_directory Proto.block_header_data_encoding header.protocol_data) end ; + register0 S.Header.raw_protocol_data begin fun block () () -> + let header = State.Block.header block in + return header.protocol_data + end ; (* block metadata *) @@ -197,7 +205,7 @@ let build_raw_rpc_directory (* helpers *) - register0 Shell_services.Blocks.S.Helpers.Forge.block_header begin fun _block () header -> + register0 S.Helpers.Forge.block_header begin fun _block () header -> return (Data_encoding.Binary.to_bytes_exn Block_header.encoding header) end ; diff --git a/src/lib_shell_services/block_services.ml b/src/lib_shell_services/block_services.ml index 24f771bb8..852521903 100644 --- a/src/lib_shell_services/block_services.ml +++ b/src/lib_shell_services/block_services.ml @@ -337,6 +337,13 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct ~output: block_header_encoding RPC_path.(path / "header") + let raw_header = + RPC_service.get_service + ~description:"The whole block header (unparsed)." + ~query: RPC_query.empty + ~output: bytes + RPC_path.(path / "header" / "raw") + let metadata = RPC_service.get_service ~description:"All the metadata associated to the block." @@ -375,6 +382,13 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct Proto.block_header_data_encoding)) RPC_path.(path / "protocol_data") + let raw_protocol_data = + RPC_service.get_service + ~description:"The version-specific fragment of the block header (unparsed)." + ~query: RPC_query.empty + ~output: bytes + RPC_path.(path / "protocol_data" / "raw") + end module Operation = struct @@ -611,6 +625,11 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct fun ?(chain = `Main) ?(block = `Head 0) () -> f chain block () () + let raw_header ctxt = + let f = make_call0 S.raw_header ctxt in + fun ?(chain = `Main) ?(block = `Head 0) () -> + f chain block () () + let metadata ctxt = let f = make_call0 S.metadata ctxt in fun ?(chain = `Main) ?(block = `Head 0) () -> @@ -633,6 +652,10 @@ module Make(Proto : PROTO)(Next_proto : PROTO) = struct let f = make_call0 S.protocol_data ctxt in fun ?(chain = `Main) ?(block = `Head 0) () -> f chain block () () + let raw_protocol_data ctxt = + let f = make_call0 S.raw_protocol_data ctxt in + fun ?(chain = `Main) ?(block = `Head 0) () -> + f chain block () () end diff --git a/src/lib_shell_services/block_services.mli b/src/lib_shell_services/block_services.mli index e60493245..73b6db2aa 100644 --- a/src/lib_shell_services/block_services.mli +++ b/src/lib_shell_services/block_services.mli @@ -119,6 +119,10 @@ module Make(Proto : PROTO)(Next_proto : PROTO) : sig #simple -> ?chain:chain -> ?block:block -> unit -> Block_hash.t tzresult Lwt.t + val raw_header: + #simple -> ?chain:chain -> ?block:block -> + unit -> MBytes.t tzresult Lwt.t + val header: #simple -> ?chain:chain -> ?block:block -> unit -> block_header tzresult Lwt.t @@ -135,6 +139,9 @@ module Make(Proto : PROTO)(Next_proto : PROTO) : sig val protocol_data: #simple -> ?chain:chain -> ?block:block -> unit -> Proto.block_header_data tzresult Lwt.t + val raw_protocol_data: + #simple -> ?chain:chain -> ?block:block -> + unit -> MBytes.t tzresult Lwt.t end @@ -228,6 +235,11 @@ module Make(Proto : PROTO)(Next_proto : PROTO) : sig prefix, unit, unit, block_header) RPC_service.t + val raw_header: + ([ `GET ], prefix, + prefix, unit, unit, + MBytes.t) RPC_service.t + val metadata: ([ `GET ], prefix, prefix, unit, unit, @@ -245,6 +257,11 @@ module Make(Proto : PROTO)(Next_proto : PROTO) : sig prefix, unit, unit, Proto.block_header_data) RPC_service.t + val raw_protocol_data: + ([ `GET ], prefix, + prefix, unit, unit, + MBytes.t) RPC_service.t + end module Operation : sig