From a8e984c1af460df0d418980c9a3dcbdef292e30c Mon Sep 17 00:00:00 2001 From: Milo Davis Date: Thu, 13 Jul 2017 11:53:59 +0200 Subject: [PATCH] Alpha: adds an RPC to get the storage of a contract --- src/proto/alpha/contract_storage.ml | 2 ++ src/proto/alpha/contract_storage.mli | 1 + src/proto/alpha/services.ml | 7 +++++++ src/proto/alpha/services_registration.ml | 1 + src/proto/alpha/tezos_context.mli | 2 ++ 5 files changed, 13 insertions(+) diff --git a/src/proto/alpha/contract_storage.ml b/src/proto/alpha/contract_storage.ml index 59a25dc35..ab4732b1e 100644 --- a/src/proto/alpha/contract_storage.ml +++ b/src/proto/alpha/contract_storage.ml @@ -236,6 +236,8 @@ let get_script c contract = | Some code, Some storage -> return (Some { Script_repr.code ; storage }) | None, Some _ | Some _, None -> failwith "get_script" +let get_storage = Storage.Contract.Storage.get_option + let get_counter c contract = Storage.Contract.Counter.get_option c contract >>=? function | None -> begin diff --git a/src/proto/alpha/contract_storage.mli b/src/proto/alpha/contract_storage.mli index 57a841b30..40a766fa7 100644 --- a/src/proto/alpha/contract_storage.mli +++ b/src/proto/alpha/contract_storage.mli @@ -37,6 +37,7 @@ val get_balance: Storage.t -> Contract_repr.t -> Tez_repr.t tzresult Lwt.t val get_counter: Storage.t -> Contract_repr.t -> int32 tzresult Lwt.t val get_script: Storage.t -> Contract_repr.t -> Script_repr.t option tzresult Lwt.t +val get_storage: Storage.t -> Contract_repr.t -> Script_repr.storage option tzresult Lwt.t val update_script_storage_and_fees: Storage.t -> Contract_repr.t -> Tez_repr.t -> Script_repr.expr -> Storage.t tzresult Lwt.t diff --git a/src/proto/alpha/services.ml b/src/proto/alpha/services.ml index dcb3d274e..385aa47d1 100644 --- a/src/proto/alpha/services.ml +++ b/src/proto/alpha/services.ml @@ -301,6 +301,13 @@ module Context = struct ~output: (wrap_tzerror (option Script.encoding)) RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "script") + let storage custom_root = + RPC.service + ~description: "Access the data of the contract." + ~input: empty + ~output: (wrap_tzerror (option Script.storage_encoding)) + RPC.Path.(custom_root / "context" / "contracts" /: Contract.arg / "storage") + type info = { manager: public_key_hash ; balance: Tez.t ; diff --git a/src/proto/alpha/services_registration.ml b/src/proto/alpha/services_registration.ml index 72cdae868..4ff7022bb 100644 --- a/src/proto/alpha/services_registration.ml +++ b/src/proto/alpha/services_registration.ml @@ -213,6 +213,7 @@ let () = register2' Services.Context.Contract.spendable Contract.is_spendable ; register2' Services.Context.Contract.delegatable Contract.is_delegatable ; register2' Services.Context.Contract.script Contract.get_script ; + register2' Services.Context.Contract.storage Contract.get_storage ; register2' Services.Context.Contract.get (fun ctxt contract -> Contract.get_balance ctxt contract >>=? fun balance -> Contract.get_manager ctxt contract >>=? fun manager -> diff --git a/src/proto/alpha/tezos_context.mli b/src/proto/alpha/tezos_context.mli index a20dbe343..564755678 100644 --- a/src/proto/alpha/tezos_context.mli +++ b/src/proto/alpha/tezos_context.mli @@ -330,6 +330,8 @@ module Contract : sig context -> contract -> bool tzresult Lwt.t val get_script: context -> contract -> (Script.t option) tzresult Lwt.t + val get_storage: + context -> contract -> (Script.storage option) tzresult Lwt.t val get_counter: context -> contract -> int32 tzresult Lwt.t val get_balance: