Client: add get script code command

This commit is contained in:
Milo Davis 2018-06-27 20:05:38 +00:00 committed by Benjamin Canou
parent 44ca820944
commit d0dd6be9c0
4 changed files with 32 additions and 2 deletions

View File

@ -169,7 +169,7 @@ get_contract_addr () {
contract_storage () { contract_storage () {
local CONTRACT_NAME="$1" # Can be either an alias or hash 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 () { assert_storage_contains () {

View File

@ -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 = let get_storage (rpc : #Proto_alpha.rpc_context) ~chain ~block contract =
Alpha_services.Contract.storage_opt rpc (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 = let parse_expression arg =
Lwt.return Lwt.return
(Micheline_parser.no_parsing_error (Micheline_parser.no_parsing_error

View File

@ -23,6 +23,13 @@ val get_storage:
Contract.t -> Contract.t ->
Script.expr option tzresult Lwt.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: val get_manager:
#Proto_alpha.full -> #Proto_alpha.full ->
chain:Shell_services.chain -> chain:Shell_services.chain ->

View File

@ -103,7 +103,7 @@ let commands () =
command ~group ~desc: "Get the storage of a contract." command ~group ~desc: "Get the storage of a contract."
no_options no_options
(prefixes [ "get" ; "storage" ; "for" ] (prefixes [ "get" ; "script" ; "storage" ; "for" ]
@@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract"
@@ stop) @@ stop)
begin fun () (_, contract) (cctxt : Proto_alpha.full) -> begin fun () (_, contract) (cctxt : Proto_alpha.full) ->
@ -117,6 +117,26 @@ let commands () =
return_unit return_unit
end ; 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." command ~group ~desc: "Get the manager of a contract."
no_options no_options
(prefixes [ "get" ; "manager" ; "for" ] (prefixes [ "get" ; "manager" ; "for" ]