From 3a057ddad1d6563c6ccecdd895fcc5a144bea00b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Wed, 21 Feb 2018 22:19:21 +0100 Subject: [PATCH] Alpha/client: add command "reveal key for " --- .../lib_client/client_proto_context.ml | 17 +++++++++++++++++ .../lib_client/client_proto_context.mli | 10 ++++++++++ .../client_proto_context_commands.ml | 13 +++++++++++++ .../lib_protocol/src/helpers_services.ml | 4 ++++ .../lib_protocol/src/helpers_services.mli | 9 +++++++++ 5 files changed, 53 insertions(+) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index a5bbbd715..f72c10f35 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -73,6 +73,23 @@ let transfer cctxt assert (Operation_hash.equal oph injected_oph) ; return (oph, contracts) +let reveal cctxt + block ?branch ~source ~src_pk ~src_sk ~fee () = + get_branch cctxt block branch >>=? fun (chain_id, branch) -> + Alpha_services.Contract.counter cctxt block source >>=? fun pcounter -> + let counter = Int32.succ pcounter in + Alpha_services.Forge.Manager.reveal + cctxt block + ~branch ~source ~sourcePubKey:src_pk ~counter ~fee () >>=? fun bytes -> + Client_keys.sign cctxt src_sk bytes >>=? fun signature -> + let signed_bytes = + MBytes.concat bytes (Ed25519.Signature.to_bytes signature) in + let oph = Operation_hash.hash_bytes [ signed_bytes ] in + Shell_services.inject_operation + cctxt ~chain_id signed_bytes >>=? fun injected_oph -> + assert (Operation_hash.equal oph injected_oph) ; + return oph + let originate rpc_config ?chain_id ~block ?signature bytes = let signed_bytes = match signature with diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index d267ee31a..fdc270166 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -118,6 +118,16 @@ val transfer : unit -> (Operation_hash.t * Contract.t list) tzresult Lwt.t +val reveal : + #Proto_alpha.full -> + Block_services.block -> + ?branch:int -> + source:Contract.t -> + src_pk:public_key -> + src_sk:Client_keys.sk_locator -> + fee:Tez.t -> + unit -> Operation_hash.t tzresult Lwt.t + val dictate : #Proto_alpha.rpc_context -> Block_services.block -> diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 40315689f..7b575288a 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml @@ -229,6 +229,19 @@ let commands () = operation_submitted_message cctxt ~contracts oph end; + command ~group ~desc: "Reveal the public key of the contract manager." + (args1 fee_arg) + (prefixes [ "reveal" ; "key" ; "for" ] + @@ ContractAlias.alias_param + ~name: "src" ~desc: "name of the source contract" + @@ stop) + begin fun fee (_, source) cctxt -> + source_to_keys cctxt cctxt#block source >>=? fun (src_pk, src_sk) -> + reveal cctxt ~fee cctxt#block + ~source ~src_pk ~src_sk () >>=? fun oph -> + operation_submitted_message cctxt oph + end; + command ~group:alphanet ~desc: "Open a new FREE account (Alphanet only)." (args1 force_switch) (prefixes [ "originate" ; "free" ; "account" ] diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.ml b/src/proto_alpha/lib_protocol/src/helpers_services.ml index 27edc711f..c77055cac 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.ml +++ b/src/proto_alpha/lib_protocol/src/helpers_services.ml @@ -315,6 +315,10 @@ module Forge = struct (RPC_context.make_call0 S.operations ctxt block () ({ branch }, Sourced_operations ops)) + let reveal ctxt + block ~branch ~source ~sourcePubKey ~counter ~fee ()= + operations ctxt block ~branch ~source ~sourcePubKey ~counter ~fee [] + let transaction ctxt block ~branch ~source ?sourcePubKey ~counter ~amount ~destination ?parameters ~fee ()= diff --git a/src/proto_alpha/lib_protocol/src/helpers_services.mli b/src/proto_alpha/lib_protocol/src/helpers_services.mli index 5e59a421c..99e44c2f8 100644 --- a/src/proto_alpha/lib_protocol/src/helpers_services.mli +++ b/src/proto_alpha/lib_protocol/src/helpers_services.mli @@ -69,6 +69,15 @@ module Forge : sig fee:Tez.t -> manager_operation list -> MBytes.t shell_tzresult Lwt.t + val reveal: + 'a #RPC_context.simple -> 'a -> + branch:Block_hash.t -> + source:Contract.t -> + sourcePubKey:public_key -> + counter:int32 -> + fee:Tez.t -> + unit -> MBytes.t shell_tzresult Lwt.t + val transaction: 'a #RPC_context.simple -> 'a -> branch:Block_hash.t ->