From 9872ff8b36859325810a429b70f731b74f8665e2 Mon Sep 17 00:00:00 2001 From: Benjamin Canou Date: Tue, 21 Mar 2017 17:23:06 +0100 Subject: [PATCH] RPCs: make the result of [/operations/X] compatible with Alpha's [/helpers/parse/operation]. fixes #160 --- .../embedded/alpha/baker/client_mining_operations.ml | 2 +- src/client/embedded/alpha/client_proto_rpcs.ml | 7 ++++--- src/client/embedded/alpha/client_proto_rpcs.mli | 2 +- src/node/shell/node_rpc_services.ml | 5 +---- src/proto/alpha/services.ml | 12 +++++------- src/proto/alpha/services_registration.ml | 8 +++++--- src/proto/environment/updater.mli | 1 + 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/client/embedded/alpha/baker/client_mining_operations.ml b/src/client/embedded/alpha/baker/client_mining_operations.ml index 2543bdac0..d7815f78b 100644 --- a/src/client/embedded/alpha/baker/client_mining_operations.ml +++ b/src/client/embedded/alpha/baker/client_mining_operations.ml @@ -26,7 +26,7 @@ let monitor cctxt ?contents ?check () = match bytes with | None -> Lwt.return (Some { hash; content = None }) | Some ({ Store.Operation.shell ; proto } : Updater.raw_operation) -> - Client_proto_rpcs.Helpers.Parse.operations cctxt + Client_proto_rpcs.Helpers.Parse.operation cctxt `Prevalidation ?check shell proto >>= function | Ok proto -> Lwt.return (Some { hash ; content = Some (shell, proto) }) | Error err -> diff --git a/src/client/embedded/alpha/client_proto_rpcs.ml b/src/client/embedded/alpha/client_proto_rpcs.ml index fb80285b5..5f0b4a888 100644 --- a/src/client/embedded/alpha/client_proto_rpcs.ml +++ b/src/client/embedded/alpha/client_proto_rpcs.ml @@ -266,9 +266,10 @@ module Helpers = struct end module Parse = struct - let operations cctxt - block ?check shell bytes = - call_error_service1 cctxt Services.Helpers.Parse.operations block (shell, bytes, check) + let operation cctxt block ?check shell proto = + call_error_service1 cctxt + Services.Helpers.Parse.operation block + (({ shell ; proto } : Updater.raw_operation), check) end end diff --git a/src/client/embedded/alpha/client_proto_rpcs.mli b/src/client/embedded/alpha/client_proto_rpcs.mli index 5315b0890..11a325085 100644 --- a/src/client/embedded/alpha/client_proto_rpcs.mli +++ b/src/client/embedded/alpha/client_proto_rpcs.mli @@ -334,7 +334,7 @@ module Helpers : sig end module Parse : sig - val operations: + val operation: Client_commands.context -> block -> ?check:bool -> Updater.shell_operation -> MBytes.t -> proto_operation tzresult Lwt.t diff --git a/src/node/shell/node_rpc_services.ml b/src/node/shell/node_rpc_services.ml index 83c39291e..77efb36c4 100644 --- a/src/node/shell/node_rpc_services.ml +++ b/src/node/shell/node_rpc_services.ml @@ -406,10 +406,7 @@ module Operations = struct let bytes = RPC.service ~input: empty - ~output: - (obj1 (req "data" - (describe ~title: "Tezos signed operation (hex encoded)" - (Updater.raw_operation_encoding)))) + ~output: Updater.raw_operation_encoding RPC.Path.(root / "operations" /: operations_arg) type list_param = { diff --git a/src/proto/alpha/services.ml b/src/proto/alpha/services.ml index 196a02200..501cb8683 100644 --- a/src/proto/alpha/services.ml +++ b/src/proto/alpha/services.ml @@ -583,17 +583,15 @@ module Helpers = struct module Parse = struct - let operations custom_root = + let operation custom_root = RPC.service ~description:"Parse an operation" ~input: - (obj3 - (req "shell" Updater.shell_operation_encoding) - (req "proto" - (describe ~title: "hex encoded operation" bytes)) - (opt "check_signature" bool)) + (merge_objs + Updater.raw_operation_encoding + (obj1 (opt "check_signature" bool))) ~output: (wrap_tzerror Operation.proto_operation_encoding) - RPC.Path.(custom_root / "helpers" / "parse" / "operations" ) + RPC.Path.(custom_root / "helpers" / "parse" / "operation" ) end diff --git a/src/proto/alpha/services_registration.ml b/src/proto/alpha/services_registration.ml index 79b780fd1..bc908b8d1 100644 --- a/src/proto/alpha/services_registration.ml +++ b/src/proto/alpha/services_registration.ml @@ -470,8 +470,9 @@ let check_signature ctxt signature shell contents = Operation.check_signature key { signature ; shell ; contents ; hash = dummy_hash } -let parse_operations ctxt (shell, bytes, check) = - Operation.parse_proto bytes >>=? fun (proto, signature) -> +let parse_operation ctxt + (({ shell ; proto } : Updater.raw_operation), check) = + Operation.parse_proto proto >>=? fun (proto, signature) -> begin match check with | Some true -> check_signature ctxt signature shell proto @@ -479,7 +480,8 @@ let parse_operations ctxt (shell, bytes, check) = end >>=? fun () -> return proto -let () = register1 Services.Helpers.Parse.operations parse_operations +let () = register1 Services.Helpers.Parse.operation parse_operation + (*****) diff --git a/src/proto/environment/updater.mli b/src/proto/environment/updater.mli index 48d4dd936..accd03ba8 100644 --- a/src/proto/environment/updater.mli +++ b/src/proto/environment/updater.mli @@ -16,6 +16,7 @@ type raw_operation = { shell: shell_operation ; proto: MBytes.t ; } +val raw_operation_encoding: raw_operation Data_encoding.t (** The version agnostic toplevel structure of blocks. *)