From d0dd6be9c0704b3ec4b7d6c3a76ac1df0d3d2d4e Mon Sep 17 00:00:00 2001 From: Milo Davis Date: Wed, 27 Jun 2018 20:05:38 +0000 Subject: [PATCH] Client: add get script code command --- src/bin_client/test/test_lib.inc.sh | 2 +- .../lib_client/client_proto_context.ml | 3 +++ .../lib_client/client_proto_context.mli | 7 ++++++ .../client_proto_context_commands.ml | 22 ++++++++++++++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/bin_client/test/test_lib.inc.sh b/src/bin_client/test/test_lib.inc.sh index 422b8ff55..eb28d2bb3 100755 --- a/src/bin_client/test/test_lib.inc.sh +++ b/src/bin_client/test/test_lib.inc.sh @@ -169,7 +169,7 @@ get_contract_addr () { contract_storage () { local CONTRACT_NAME="$1" # Can be either an alias or hash - $client get storage for ${CONTRACT_NAME} + $client get script storage for ${CONTRACT_NAME} } assert_storage_contains () { diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 3c1484598..2e4059259 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -19,6 +19,9 @@ let get_balance (rpc : #Proto_alpha.rpc_context) ~chain ~block contract = let get_storage (rpc : #Proto_alpha.rpc_context) ~chain ~block contract = Alpha_services.Contract.storage_opt rpc (chain, block) contract +let get_script (rpc : #Proto_alpha.rpc_context) ~chain ~block contract = + Alpha_services.Contract.script_opt rpc (chain, block) contract + let parse_expression arg = Lwt.return (Micheline_parser.no_parsing_error diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index bebf5e91e..8e2e64766 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -23,6 +23,13 @@ val get_storage: Contract.t -> Script.expr option tzresult Lwt.t +val get_script: + #Proto_alpha.rpc_context -> + chain:Shell_services.chain -> + block:Shell_services.block -> + Contract.t -> + Script.t option tzresult Lwt.t + val get_manager: #Proto_alpha.full -> chain:Shell_services.chain -> 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 a4c5d9206..63966bc53 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 @@ -103,7 +103,7 @@ let commands () = command ~group ~desc: "Get the storage of a contract." no_options - (prefixes [ "get" ; "storage" ; "for" ] + (prefixes [ "get" ; "script" ; "storage" ; "for" ] @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ stop) begin fun () (_, contract) (cctxt : Proto_alpha.full) -> @@ -117,6 +117,26 @@ let commands () = return_unit end ; + command ~group ~desc: "Get the storage of a contract." + no_options + (prefixes [ "get" ; "script" ; "code" ; "for" ] + @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" + @@ stop) + begin fun () (_, contract) (cctxt : Proto_alpha.full) -> + get_script cctxt + ~chain:`Main ~block:cctxt#block + contract >>=? function + | None -> + cctxt#error "This is not a smart contract." + | Some { code ; storage = _ } -> + match Script.force_decode code with + | Error errs -> cctxt#error "%a" (Format.pp_print_list ~pp_sep:Format.pp_print_newline Alpha_environment.Error_monad.pp) errs + | Ok code -> + begin cctxt#answer "%a" Michelson_v1_printer.print_expr_unwrapped code >>= fun () -> + return () + end + end ; + command ~group ~desc: "Get the manager of a contract." no_options (prefixes [ "get" ; "manager" ; "for" ]