From cc31bbfa9beb1811f84fc76642d805b9eddce50f Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 16:12:25 +0200 Subject: [PATCH 01/13] Proto/Client: originated contract aliases Use it for the 'get cached contract rank for' command --- .../lib_client/client_proto_contracts.ml | 41 +++++++++++++++++++ .../lib_client/client_proto_contracts.mli | 9 ++++ .../client_proto_context_commands.ml | 3 +- 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_client/client_proto_contracts.ml b/src/proto_alpha/lib_client/client_proto_contracts.ml index d23c0a8b6070..ddd2c02d2d87 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.ml +++ b/src/proto_alpha/lib_client/client_proto_contracts.ml @@ -41,6 +41,47 @@ end module RawContractAlias = Client_aliases.Alias (ContractEntity) +module OriginatedContractAlias = struct + let find cctxt s = + RawContractAlias.find_opt cctxt s >>=? function + | Some (Contract.Originated v) -> return v + | Some (Implicit _) -> failwith "contract %s is an implicit account" s + | None -> failwith "no contract named %s" s + + let of_literal s = + ContractEntity.of_source s >>= function + | Ok (Contract.Originated v) -> return v + | Ok (Implicit _) -> failwith "contract %s is an implicit account" s + | Error _ as err -> Lwt.return err + + let find_destination cctxt s = + match String.split ~limit:1 ':' s with + | ["alias"; alias] -> find cctxt alias + | ["text"; text] -> of_literal text + | _ -> ( + of_literal s >>= function + | Ok _ as ok_v -> Lwt.return ok_v + | Error k_errs -> ( + find cctxt s >|= function + | Ok _ as ok_v -> ok_v + | Error c_errs -> Error (c_errs @ k_errs))) + + let destination_parameter () = + Clic.parameter ~autocomplete:RawContractAlias.autocomplete find_destination + + let destination_param ?(name = "dst") ?(desc = "destination contract") next = + let desc = + String.concat + "\n" + [ + desc; + "Can be a literal or an alias (autodetected in order).\n\ + Use 'text:literal' or 'alias:name' to force."; + ] + in + Clic.param ~name ~desc (destination_parameter ()) next +end + module ContractAlias = struct let find cctxt s = RawContractAlias.find_opt cctxt s >>=? function diff --git a/src/proto_alpha/lib_client/client_proto_contracts.mli b/src/proto_alpha/lib_client/client_proto_contracts.mli index 7c9ac5136a5f..9582c337d339 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.mli +++ b/src/proto_alpha/lib_client/client_proto_contracts.mli @@ -29,6 +29,15 @@ open Clic module RawContractAlias : Client_aliases.Alias with type t = Contract.t +(** Like [ContractAlias] below but restricted to originated contracts. *) +module OriginatedContractAlias : sig + val destination_param : + ?name:string -> + ?desc:string -> + ('a, (#Client_context.wallet as 'wallet)) params -> + (Contract_hash.t -> 'a, 'wallet) params +end + module ContractAlias : sig val get_contract : #Client_context.wallet -> string -> Contract.t tzresult Lwt.t 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 688a7e45517a..d3e1d48eb283 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 @@ -204,9 +204,10 @@ let commands_ro () = ~desc:"Get the key rank of a cache key." no_options (prefixes ["get"; "cached"; "contract"; "rank"; "for"] - @@ ContractAlias.destination_param ~name:"src" ~desc:"contract" + @@ OriginatedContractAlias.destination_param ~name:"src" ~desc:"contract" @@ stop) (fun () contract (cctxt : Protocol_client_context.full) -> + let contract = Contract.Originated contract in contract_rank cctxt ~chain:cctxt#chain ~block:cctxt#block contract >>=? fun rank -> match rank with -- GitLab From ca110415e681cd7265987448e16e13ddf93bce49 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 14 Apr 2022 19:17:50 +0200 Subject: [PATCH 02/13] Proto/Client: fix error registration --- src/proto_alpha/lib_plugin/plugin.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index e6ec2daf2091..6c493f963f9d 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1402,8 +1402,8 @@ module View_helpers = struct obj2 (req "entrypoint" Entrypoint.simple_encoding) (req "callback" Contract.encoding)) - (function View_never_returns (e, c) -> Some (e, c) | _ -> None) - (fun (e, c) -> View_never_returns (e, c)) ; + (function View_unexpected_return (e, c) -> Some (e, c) | _ -> None) + (fun (e, c) -> View_unexpected_return (e, c)) ; Environment.Error_monad.register_error_kind `Permanent ~id:"viewNotFound" -- GitLab From 0b7abeca62a29cbd7e40748593f578978f4e85ff Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Thu, 14 Apr 2022 19:21:43 +0200 Subject: [PATCH 03/13] Proto/Plugin: originate_dummy_contract returns a contract hash --- src/proto_alpha/lib_plugin/plugin.ml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 6c493f963f9d..17148347c3ab 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -2442,14 +2442,15 @@ module RPC = struct `Minted (`Contract dummy_contract) balance - >>=? fun (ctxt, _) -> return (ctxt, dummy_contract) + >>=? fun (ctxt, _) -> return (ctxt, dummy_contract_hash) in let configure_contracts ctxt script balance ~src_opt ~pay_opt ~self_opt = (match self_opt with | None -> let balance = Option.value ~default:default_balance balance in originate_dummy_contract ctxt script balance - >>=? fun (ctxt, addr) -> return (ctxt, addr, balance) + >>=? fun (ctxt, addr) -> + return (ctxt, Contract.Originated addr, balance) | Some addr -> default_from_context ctxt @@ -2713,7 +2714,7 @@ module RPC = struct let parameter = View_helpers.make_view_parameter (Micheline.root input) - viewer_contract + (Contract.Originated viewer_contract) in Script_interpreter.execute ctxt @@ -2737,7 +2738,7 @@ module RPC = struct (View_helpers.extract_parameter_from_operations entrypoint operations - viewer_contract)) ; + (Contract.Originated viewer_contract))) ; Registration.register0 ~chunked:true S.run_script_view -- GitLab From 50dc051bb06770072f60572dc82b68efb455f4c0 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 08:51:50 +0200 Subject: [PATCH 04/13] Proto/Client: get_contract_big_map_value accepts only originated contracts --- src/proto_alpha/lib_client/client_proto_context.ml | 2 +- src/proto_alpha/lib_client/client_proto_context.mli | 2 +- .../lib_client_commands/client_proto_context_commands.ml | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 4850838c452f..9c5eba56001d 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -53,7 +53,7 @@ let get_contract_big_map_value (rpc : #rpc_context) ~chain ~block contract key = Alpha_services.Contract.contract_big_map_get_opt rpc (chain, block) - contract + (Contract.Originated contract) key let get_script (rpc : #rpc_context) ~chain ~block ~unparsing_mode diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 6ad41787284f..594a888c3dbb 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -44,7 +44,7 @@ val get_contract_big_map_value : #Protocol_client_context.rpc_context -> chain:Shell_services.chain -> block:Shell_services.block -> - Contract.t -> + Contract_hash.t -> Script.expr * Script.expr -> Script.expr option tzresult Lwt.t 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 d3e1d48eb283..bcd55287a98d 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 @@ -278,7 +278,9 @@ let commands_ro () = @@ prefixes ["of"; "type"] @@ Clic.param ~name:"type" ~desc:"type of the key" data_parameter @@ prefix "in" - @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" + @@ OriginatedContractAlias.destination_param + ~name:"src" + ~desc:"source contract" @@ stop) (fun () key key_type contract (cctxt : Protocol_client_context.full) -> get_contract_big_map_value -- GitLab From a115c7c79db5bcee00e4318c2f8d92a74ce42b70 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 10:13:14 +0200 Subject: [PATCH 05/13] Proto/Client: restrict sapling context to originated contracts --- .../lib_client/client_proto_contracts.ml | 12 +++++++++ .../lib_client/client_proto_contracts.mli | 6 +++++ .../client_sapling_commands.ml | 25 +++++++++---------- src/proto_alpha/lib_client_sapling/context.ml | 9 ++++--- .../lib_client_sapling/context.mli | 6 ++--- 5 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_contracts.ml b/src/proto_alpha/lib_client/client_proto_contracts.ml index ddd2c02d2d87..5f61928d27fc 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.ml +++ b/src/proto_alpha/lib_client/client_proto_contracts.ml @@ -80,6 +80,18 @@ module OriginatedContractAlias = struct ] in Clic.param ~name ~desc (destination_parameter ()) next + + let destination_arg ?(name = "dst") ?(doc = "destination contract") () = + let doc = + String.concat + "\n" + [ + doc; + "Can be a literal or an alias (autodetected in order).\n\ + Use 'text:literal' or 'alias:name' to force."; + ] + in + Clic.arg ~long:name ~doc ~placeholder:name (destination_parameter ()) end module ContractAlias = struct diff --git a/src/proto_alpha/lib_client/client_proto_contracts.mli b/src/proto_alpha/lib_client/client_proto_contracts.mli index 9582c337d339..e92a2523af00 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.mli +++ b/src/proto_alpha/lib_client/client_proto_contracts.mli @@ -36,6 +36,12 @@ module OriginatedContractAlias : sig ?desc:string -> ('a, (#Client_context.wallet as 'wallet)) params -> (Contract_hash.t -> 'a, 'wallet) params + + val destination_arg : + ?name:string -> + ?doc:string -> + unit -> + (Contract_hash.t option, #Client_context.wallet) Clic.arg end module ContractAlias : sig diff --git a/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml b/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml index 801dcefee60d..caa46a48fb84 100644 --- a/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml +++ b/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml @@ -61,7 +61,7 @@ let viewing_key_of_string s = let anti_replay cctxt contract = Tezos_shell_services.Chain_services.chain_id cctxt ~chain:cctxt#chain () >>=? fun chain_id -> - let address = Protocol.Alpha_context.Contract.to_b58check contract in + let address = Protocol.Contract_hash.to_b58check contract in let chain_id = Chain_id.to_b58check chain_id in return (address ^ chain_id) @@ -166,7 +166,7 @@ let shield_cmd = @@ prefix "to" @@ Clic.string ~name:"dst-sap" ~desc:"Sapling address of destination." @@ prefix "using" - @@ ContractAlias.destination_param + @@ OriginatedContractAlias.destination_param ~name:"sapling contract" ~desc:"Smart contract to submit this transaction to." @@ stop) @@ -205,7 +205,7 @@ let shield_cmd = ~amount ~src_pk ~src_sk - ~destination:(Contract contract_dst) + ~destination:(Contract (Originated contract_dst)) ~source:pkh ~arg ?confirmations:cctxt#confirmations @@ -256,7 +256,7 @@ let unshield_cmd = ~name:"dst-tz" ~desc:"Transparent destination account." @@ prefix "using" - @@ ContractAlias.destination_param + @@ OriginatedContractAlias.destination_param ~name:"sapling contract" ~desc:"Smart contract to submit this transaction to." @@ stop) @@ -294,7 +294,7 @@ let unshield_cmd = ~amount:Tez.zero ~src_sk ~src_pk - ~destination:(Contract contract_dst) + ~destination:(Contract (Originated contract_dst)) ~source ~arg ?confirmations:cctxt#confirmations @@ -358,7 +358,7 @@ let forge_shielded_cmd = @@ prefix "to" @@ Clic.string ~name:"dst-sap" ~desc:"Sapling address of destination." @@ prefix "using" - @@ ContractAlias.destination_param + @@ OriginatedContractAlias.destination_param ~name:"sapling contract" ~desc:"Smart contract to submit this transaction to." @@ stop) @@ -426,7 +426,7 @@ let submit_shielded_cmd = ~name:"alias-tz" ~desc:"Transparent account paying the fees." @@ prefix "using" - @@ ContractAlias.destination_param + @@ OriginatedContractAlias.destination_param ~name:"sapling contract" ~desc:"Smart contract to submit this transaction to." @@ stop) @@ -443,11 +443,10 @@ let submit_shielded_cmd = source destination (cctxt : Protocol_client_context.full) -> - let open Protocol.Alpha_context in cctxt#message "Reading forge transaction from file %s -- sending it to %a@." filename - Contract.pp + Protocol.Contract_hash.pp destination >>= fun () -> let open Context in @@ -476,7 +475,7 @@ let submit_shielded_cmd = ~amount:Tez.zero ~src_pk ~src_sk - ~destination:(Contract destination) + ~destination:(Contract (Originated destination)) ~source ~arg:contract_input ?confirmations:cctxt#confirmations @@ -498,7 +497,7 @@ let submit_shielded_cmd = | Some (_res, _contracts) -> return_unit) let for_contract_arg = - Client_proto_contracts.ContractAlias.destination_arg + Client_proto_contracts.OriginatedContractAlias.destination_arg ~name:"for-contract" ~doc:"name of the contract to associate new key with" () @@ -540,7 +539,7 @@ let use_key_for_contract_cmd = ~name:"sapling-key" ~desc:"Sapling key to use for the contract." @@ prefixes ["for"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"contract" ~desc:"Contract the key will be used on." @@ stop) @@ -697,7 +696,7 @@ let commands () = ~name:"sapling-key" ~desc:"Sapling key we get balance for." @@ prefixes ["in"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"contract" ~desc:"Contract we get balance from." @@ stop) diff --git a/src/proto_alpha/lib_client_sapling/context.ml b/src/proto_alpha/lib_client_sapling/context.ml index 0ce463e82e4e..b7579a005ab0 100644 --- a/src/proto_alpha/lib_client_sapling/context.ml +++ b/src/proto_alpha/lib_client_sapling/context.ml @@ -327,7 +327,7 @@ module Contract_state = struct end module Client_state = struct - module Map = Map.Make (Protocol.Alpha_context.Contract) + module Map = Map.Make (Protocol.Contract_hash) type t = Contract_state.t Map.t @@ -338,7 +338,7 @@ module Client_state = struct (List.fold_left (fun m (k, v) -> Map.add k v m) Map.empty) (list (obj2 - (req "contract" Protocol.Alpha_context.Contract.encoding) + (req "contract" Protocol.Alpha_context.Contract.originated_encoding) (req "state" Contract_state.encoding))) let filename = "sapling_state" @@ -356,7 +356,7 @@ module Client_state = struct failwith "Unknown memo size for contract %s and none was provided in \ options" - @@ Protocol.Alpha_context.Contract.to_b58check contract + @@ Protocol.Contract_hash.to_b58check contract | Some memo_size -> let contract_state = Contract_state.empty ~memo_size in let client_state = Map.add contract contract_state client_state in @@ -376,11 +376,12 @@ module Client_state = struct | None -> cctxt#error "Contract %s not found" - (Protocol.Alpha_context.Contract.to_b58check contract) + (Protocol.Contract_hash.to_b58check contract) | Some v -> return v (** Call the node RPC to obtain the storage diff of a contract *) let get_diff cctxt contract offset_commitment offset_nullifier = + let contract = Protocol.Alpha_context.Contract.Originated contract in Protocol.Alpha_services.Contract.single_sapling_get_diff cctxt (cctxt#chain, cctxt#block) diff --git a/src/proto_alpha/lib_client_sapling/context.mli b/src/proto_alpha/lib_client_sapling/context.mli index 2c553438dd7e..5520393c1402 100644 --- a/src/proto_alpha/lib_client_sapling/context.mli +++ b/src/proto_alpha/lib_client_sapling/context.mli @@ -78,7 +78,7 @@ module Client_state : sig val find : Protocol_client_context.full -> - Protocol.Alpha_context.Contract.t -> + Protocol.Contract_hash.t -> t -> Contract_state.t tzresult Lwt.t @@ -86,7 +86,7 @@ module Client_state : sig Protocol_client_context.full -> force:bool -> default_memo_size:int option -> - Protocol.Alpha_context.Contract.t -> + Protocol.Contract_hash.t -> Viewing_key.t -> unit tzresult Lwt.t @@ -98,7 +98,7 @@ module Client_state : sig **) val sync_and_scan : Protocol_client_context.full -> - Protocol.Alpha_context.Contract.t -> + Protocol.Contract_hash.t -> Contract_state.t tzresult Lwt.t end -- GitLab From 53d763596e4277812b7c28a5b6a607a1bf10fb51 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 10:42:23 +0200 Subject: [PATCH 06/13] Proto/Client/FA1.2: restrict to originated contracts --- .../lib_client/client_proto_contracts.mli | 3 ++ .../lib_client/client_proto_fa12.ml | 31 +++++++++---------- .../lib_client/client_proto_fa12.mli | 6 ++-- .../client_proto_fa12_commands.ml | 4 +-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_contracts.mli b/src/proto_alpha/lib_client/client_proto_contracts.mli index e92a2523af00..77de84eb5a8e 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.mli +++ b/src/proto_alpha/lib_client/client_proto_contracts.mli @@ -31,6 +31,9 @@ module RawContractAlias : Client_aliases.Alias with type t = Contract.t (** Like [ContractAlias] below but restricted to originated contracts. *) module OriginatedContractAlias : sig + val find_destination : + #Client_context.wallet -> string -> Contract_hash.t tzresult Lwt.t + val destination_param : ?name:string -> ?desc:string -> diff --git a/src/proto_alpha/lib_client/client_proto_fa12.ml b/src/proto_alpha/lib_client/client_proto_fa12.ml index a278f8c22a04..c14384cc97a9 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.ml +++ b/src/proto_alpha/lib_client/client_proto_fa12.ml @@ -713,22 +713,19 @@ let contract_has_fa12_interface : #Protocol_client_context.rpc_context -> chain:Shell_services.chain -> block:Shell_services.block -> - contract:Alpha_context.Contract.t -> + contract:Contract_hash.t -> unit -> unit tzresult Lwt.t = fun cctxt ~chain ~block ~contract () -> - match contract with - | Implicit _ -> fail (Contract_has_no_script contract) - | Originated _ -> - Michelson_v1_entrypoints.list_contract_entrypoints - cctxt - ~chain - ~block - ~contract - ~normalize_types:true - >>=? fun entrypoints -> - List.iter_e (check_entrypoint entrypoints) standard_entrypoints - |> Lwt.return + let contract = Contract.Originated contract in + Michelson_v1_entrypoints.list_contract_entrypoints + cctxt + ~chain + ~block + ~contract + ~normalize_types:true + >>=? fun entrypoints -> + List.iter_e (check_entrypoint entrypoints) standard_entrypoints |> Lwt.return let translate_action_to_argument action = let entrypoint = action_to_entrypoint action in @@ -782,7 +779,7 @@ let call_contract (cctxt : #Protocol_client_context.full) ~chain ~block ~source ~src_pk ~src_sk - ~destination:(Contract contract) + ~destination:(Contract (Originated contract)) ~parameters ~amount:tez_amount ~entrypoint @@ -886,7 +883,7 @@ let build_transaction_operation ?(tez_amount = Tez.zero) ?fee ?gas_limit let prepare_single_token_transfer cctxt ?default_fee ?default_gas_limit ?default_storage_limit ~chain ~block src index transfer = - Client_proto_contracts.ContractAlias.find_destination + Client_proto_contracts.OriginatedContractAlias.find_destination cctxt transfer.token_contract >>=? fun token -> @@ -911,7 +908,7 @@ let prepare_single_token_transfer cctxt ?default_fee ?default_gas_limit ?fee ?gas_limit ?storage_limit - (Contract token) + (Contract (Originated token)) action in return (Annotated_manager_operation.Annotated_manager_operation operation) @@ -973,7 +970,7 @@ let run_view_action (cctxt : #Protocol_client_context.full) ~chain ~block Plugin.RPC.Scripts.run_tzip4_view cctxt (chain, block) - ~contract + ~contract:(Contract.Originated contract) ~input ~chain_id ?source diff --git a/src/proto_alpha/lib_client/client_proto_fa12.mli b/src/proto_alpha/lib_client/client_proto_fa12.mli index a0f7ce685278..a8d4644848a9 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.mli +++ b/src/proto_alpha/lib_client/client_proto_fa12.mli @@ -85,7 +85,7 @@ val contract_has_fa12_interface : full -> chain:Shell_services.chain -> block:Shell_services.block -> - contract:Alpha_context.Contract.t -> + contract:Contract_hash.t -> unit -> unit tzresult Lwt.t @@ -100,7 +100,7 @@ val call_contract : source:public_key_hash -> src_pk:public_key -> src_sk:Client_keys.sk_uri -> - contract:Contract.t -> + contract:Contract_hash.t -> action:action -> tez_amount:Tez.t -> ?fee:Tez.t -> @@ -152,7 +152,7 @@ val run_view_action : chain:Shell_services.chain -> block:Shell_services.block -> ?source:Contract.t -> - contract:Contract.t -> + contract:Contract_hash.t -> action:action -> ?payer:Contract.t -> ?gas:Gas.Arith.integral -> diff --git a/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml index 1edd286d3ef5..3c276d20c0df 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_fa12_commands.ml @@ -36,7 +36,7 @@ let group = let alias_param = Client_proto_contracts.ContractAlias.destination_param let token_contract_param () = - alias_param + Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"contract" ~desc:"name or address of the FA1.2-compatible contract" @@ -140,7 +140,7 @@ let commands_ro () : #Protocol_client_context.full Clic.command list = >>=? fun _ -> Format.printf "Contract %a has an FA1.2 interface.\n%!" - Contract.pp + Contract_hash.pp contract ; return_unit); command -- GitLab From a42230f3b9037e67b5274172e3fe91096c104913 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 10:46:56 +0200 Subject: [PATCH 07/13] Proto/Client: restrict list_entrypoints to originated contracts --- src/proto_alpha/lib_client/client_proto_fa12.ml | 1 - src/proto_alpha/lib_client/michelson_v1_entrypoints.ml | 8 ++++---- src/proto_alpha/lib_client/michelson_v1_entrypoints.mli | 8 ++++---- .../lib_client_commands/client_proto_context_commands.ml | 8 ++++++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_fa12.ml b/src/proto_alpha/lib_client/client_proto_fa12.ml index c14384cc97a9..058c101e056e 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.ml +++ b/src/proto_alpha/lib_client/client_proto_fa12.ml @@ -717,7 +717,6 @@ let contract_has_fa12_interface : unit -> unit tzresult Lwt.t = fun cctxt ~chain ~block ~contract () -> - let contract = Contract.Originated contract in Michelson_v1_entrypoints.list_contract_entrypoints cctxt ~chain diff --git a/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml b/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml index 2104fc101705..bdedf7c6ccba 100644 --- a/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml +++ b/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml @@ -111,7 +111,7 @@ let list_contract_unreachables_and_entrypoints cctxt ~chain ~block ~contract Alpha_services.Contract.list_entrypoints cctxt (chain, block) - contract + (Contract.Originated contract) ~normalize_types let list_contract_unreachables cctxt ~chain ~block ~contract = @@ -140,7 +140,7 @@ let list_contract_entrypoints cctxt ~chain ~block ~contract ~normalize_types = cctxt ~chain ~block - ~contract + ~contract:(Contract.Originated contract) ~entrypoint:Entrypoint.default ~normalize_types >>= function @@ -189,7 +189,7 @@ let print_entrypoints_list (cctxt : #Client_context.printer) cctxt#message "@[Entrypoints%a%a: @,%a@]@." (Format.pp_print_option (fun ppf -> - Format.fprintf ppf " for contract %a" Contract.pp)) + Format.fprintf ppf " for contract %a" Contract_hash.pp)) contract (Format.pp_print_option (fun ppf -> Format.fprintf ppf " for script %s")) @@ -231,7 +231,7 @@ let print_unreachables (cctxt : #Client_context.printer) cctxt#message "@[Unreachable paths in the argument%a%a: @[%a@]@." (Format.pp_print_option (fun ppf -> - Format.fprintf ppf " of contract %a" Contract.pp)) + Format.fprintf ppf " of contract %a" Contract_hash.pp)) contract (Format.pp_print_option (fun ppf -> Format.fprintf ppf " of script %s")) diff --git a/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli b/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli index 03ed32851ed2..47c85421de5f 100644 --- a/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli +++ b/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli @@ -61,7 +61,7 @@ val list_contract_unreachables : #Protocol_client_context.rpc_context -> chain:Chain_services.chain -> block:Block_services.block -> - contract:Alpha_context.Contract.t -> + contract:Contract_hash.t -> Michelson_v1_primitives.prim list list tzresult Lwt.t val list_unreachables : @@ -75,7 +75,7 @@ val print_unreachables : #Client_context.printer -> ?on_errors:(error list -> unit tzresult Lwt.t) -> emacs:bool -> - ?contract:Alpha_context.Contract.t -> + ?contract:Contract_hash.t -> ?script_name:string -> Michelson_v1_primitives.prim list list tzresult -> unit tzresult Lwt.t @@ -87,7 +87,7 @@ val list_contract_entrypoints : #Protocol_client_context.rpc_context -> chain:Chain_services.chain -> block:Block_services.block -> - contract:Alpha_context.Contract.t -> + contract:Contract_hash.t -> normalize_types:bool -> (string * Alpha_context.Script.expr) list tzresult Lwt.t @@ -104,7 +104,7 @@ val print_entrypoints_list : #Client_context.printer -> ?on_errors:(error list -> unit tzresult Lwt.t) -> emacs:bool -> - ?contract:Alpha_context.Contract.t -> + ?contract:Contract_hash.t -> ?script_name:string -> (string * Alpha_context.Script.expr) list tzresult -> unit tzresult Lwt.t 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 bcd55287a98d..bdac89d44786 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 @@ -395,7 +395,9 @@ let commands_ro () = ~desc:"Get the entrypoint list of a contract." (args1 normalize_types_switch) (prefixes ["get"; "contract"; "entrypoints"; "for"] - @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" + @@ OriginatedContractAlias.destination_param + ~name:"src" + ~desc:"source contract" @@ stop) (fun normalize_types contract (cctxt : Protocol_client_context.full) -> Michelson_v1_entrypoints.list_contract_entrypoints @@ -413,7 +415,9 @@ let commands_ro () = ~desc:"Get the list of unreachable paths in a contract's parameter type." no_options (prefixes ["get"; "contract"; "unreachable"; "paths"; "for"] - @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" + @@ OriginatedContractAlias.destination_param + ~name:"src" + ~desc:"source contract" @@ stop) (fun () contract (cctxt : Protocol_client_context.full) -> Michelson_v1_entrypoints.list_contract_unreachables -- GitLab From a6ea6b6d88ddb05aaece96daabf5e8ffd67aa2a5 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 11:11:29 +0200 Subject: [PATCH 08/13] Proto/Client: managed contract work on originated contracts only --- src/proto_alpha/lib_client/client_proto_multisig.ml | 2 +- src/proto_alpha/lib_client/managed_contract.ml | 11 ++++++----- src/proto_alpha/lib_client/managed_contract.mli | 9 +++++---- .../client_proto_context_commands.ml | 13 +++++++------ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_multisig.ml b/src/proto_alpha/lib_client/client_proto_multisig.ml index 380b8c59b86d..3212f5fa1a9c 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.ml +++ b/src/proto_alpha/lib_client/client_proto_multisig.ml @@ -621,7 +621,7 @@ let action_to_expr_generic ~loc = function ~destination ~amount >|? left ~loc - | Originated _ -> + | Originated destination -> lambda_from_string @@ Managed_contract.build_lambda_for_transfer_to_originated ~destination diff --git a/src/proto_alpha/lib_client/managed_contract.ml b/src/proto_alpha/lib_client/managed_contract.ml index d4e5d622f313..6834749fba9e 100644 --- a/src/proto_alpha/lib_client/managed_contract.ml +++ b/src/proto_alpha/lib_client/managed_contract.ml @@ -41,7 +41,7 @@ let get_contract_manager (cctxt : #full) contract = ~chain:cctxt#chain ~block:cctxt#block ~unparsing_mode:Optimized - contract + (Contract.Originated contract) >>=? function | None -> cctxt#error "This is not a smart contract." | Some storage -> ( @@ -103,6 +103,7 @@ let entrypoint_remove_delegate = Entrypoint.remove_delegate let build_delegate_operation (cctxt : #full) ~chain ~block ?fee contract (* the KT1 to delegate *) (delegate : Signature.public_key_hash option) = + let contract = Contract.Originated contract in let entrypoint = entrypoint_do in (Michelson_v1_entrypoints.contract_entrypoint_type cctxt @@ -198,7 +199,7 @@ let build_lambda_for_transfer_to_implicit ~destination ~amount = let build_lambda_for_transfer_to_originated ~destination ~entrypoint ~amount ~parameter_type ~parameter = let destination = - Data_encoding.Binary.to_bytes_exn Contract.encoding destination + Data_encoding.Binary.to_bytes_exn Contract.originated_encoding destination in let amount = Tez.to_mutez amount in let (`Hex destination) = Hex.of_bytes destination in @@ -240,19 +241,19 @@ let build_transaction_operation (cctxt : #full) ~chain ~block ~contract entrypoint Contract.pp destination - | Originated _ -> + | Originated destination -> (Michelson_v1_entrypoints.contract_entrypoint_type cctxt ~chain ~block - ~contract:destination + ~contract:(Contract.Originated destination) ~entrypoint ~normalize_types:true >>=? function | None -> cctxt#error "Contract %a has no entrypoint named %a" - Contract.pp + Contract_hash.pp destination Entrypoint.pp entrypoint diff --git a/src/proto_alpha/lib_client/managed_contract.mli b/src/proto_alpha/lib_client/managed_contract.mli index cc40c9caa8ff..67c4a4226e98 100644 --- a/src/proto_alpha/lib_client/managed_contract.mli +++ b/src/proto_alpha/lib_client/managed_contract.mli @@ -29,7 +29,8 @@ open Protocol_client_context (** Retrieve the manager key in a contract storage. The storage has to be of type `pair key_hash 'a`. *) -val get_contract_manager : #full -> Contract.t -> public_key_hash tzresult Lwt.t +val get_contract_manager : + #full -> Contract_hash.t -> public_key_hash tzresult Lwt.t (** Builds a delegation operation ready for injection *) val build_delegate_operation : @@ -37,7 +38,7 @@ val build_delegate_operation : chain:Chain_services.chain -> block:Block_services.block -> ?fee:Tez.t -> - Contract.t -> + Contract_hash.t -> public_key_hash option -> Kind.transaction Annotated_manager_operation.t tzresult Lwt.t @@ -60,7 +61,7 @@ val set_delegate : source:public_key_hash -> src_pk:public_key -> src_sk:Client_keys.sk_uri -> - Contract.t -> + Contract_hash.t -> public_key_hash option -> Kind.transaction Kind.manager Injection.result tzresult Lwt.t @@ -118,7 +119,7 @@ val build_lambda_for_transfer_to_implicit : destination:public_key_hash -> amount:Tez.t -> string val build_lambda_for_transfer_to_originated : - destination:Contract.t -> + destination:Contract_hash.t -> entrypoint:Entrypoint.t -> amount:Tez.t -> parameter_type:Script.expr -> 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 bdac89d44786..e70837a5ae76 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 @@ -715,9 +715,10 @@ let transfer_command amount (source : Contract.t) destination else Lwt.return_unit) >>= fun () -> (match source with - | Originated _ -> + | Originated contract_hash -> let contract = source in - Managed_contract.get_contract_manager cctxt source >>=? fun source -> + Managed_contract.get_contract_manager cctxt contract_hash + >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> Managed_contract.transfer cctxt @@ -918,7 +919,7 @@ let commands_rw () = delegate (cctxt : Protocol_client_context.full) -> match contract with - | Originated _ -> + | Originated contract -> Managed_contract.get_contract_manager cctxt contract >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> @@ -972,7 +973,7 @@ let commands_rw () = contract (cctxt : Protocol_client_context.full) -> match contract with - | Originated _ -> + | Originated contract -> Managed_contract.get_contract_manager cctxt contract >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> @@ -1169,8 +1170,8 @@ let commands_rw () = | [] -> failwith "Empty operation list" | operations -> (match source with - | Originated _ -> - Managed_contract.get_contract_manager cctxt source + | Originated contract -> + Managed_contract.get_contract_manager cctxt contract >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> return (source, src_pk, src_sk) -- GitLab From dec9b9e4bc73e741589356faf57d42b2f18ffefc Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 10:58:42 +0200 Subject: [PATCH 09/13] Proto/Client: restrict entrypoint_type to originated contracts --- src/proto_alpha/lib_client/managed_contract.ml | 5 ++--- src/proto_alpha/lib_client/michelson_v1_entrypoints.ml | 6 +++--- src/proto_alpha/lib_client/michelson_v1_entrypoints.mli | 4 ++-- .../lib_client_commands/client_proto_context_commands.ml | 4 +++- .../lib_client_commands/client_proto_multisig_commands.ml | 8 ++++---- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/proto_alpha/lib_client/managed_contract.ml b/src/proto_alpha/lib_client/managed_contract.ml index 6834749fba9e..ad470dd35a9f 100644 --- a/src/proto_alpha/lib_client/managed_contract.ml +++ b/src/proto_alpha/lib_client/managed_contract.ml @@ -103,7 +103,6 @@ let entrypoint_remove_delegate = Entrypoint.remove_delegate let build_delegate_operation (cctxt : #full) ~chain ~block ?fee contract (* the KT1 to delegate *) (delegate : Signature.public_key_hash option) = - let contract = Contract.Originated contract in let entrypoint = entrypoint_do in (Michelson_v1_entrypoints.contract_entrypoint_type cctxt @@ -154,7 +153,7 @@ let build_delegate_operation (cctxt : #full) ~chain ~block ?fee ~parameters ~entrypoint ?fee - (Contract contract)) + (Contract (Originated contract))) let set_delegate (cctxt : #full) ~chain ~block ?confirmations ?dry_run ?verbose_signing ?simulation ?branch ~fee_parameter ?fee ~source ~src_pk @@ -246,7 +245,7 @@ let build_transaction_operation (cctxt : #full) ~chain ~block ~contract cctxt ~chain ~block - ~contract:(Contract.Originated destination) + ~contract:destination ~entrypoint ~normalize_types:true >>=? function diff --git a/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml b/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml index bdedf7c6ccba..d98497739434 100644 --- a/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml +++ b/src/proto_alpha/lib_client/michelson_v1_entrypoints.ml @@ -66,7 +66,7 @@ let contract_entrypoint_type cctxt ~(chain : Chain_services.chain) ~block Alpha_services.Contract.entrypoint_type cctxt (chain, block) - contract + (Contract.Originated contract) entrypoint ~normalize_types >>= function @@ -99,7 +99,7 @@ let print_entrypoint_type (cctxt : #Client_context.printer) Entrypoint.pp entrypoint (Format.pp_print_option (fun ppf -> - Format.fprintf ppf " for contract %a" Contract.pp)) + Format.fprintf ppf " for contract %a" Contract_hash.pp)) contract (Format.pp_print_option (fun ppf -> Format.fprintf ppf " for script %s")) script_name @@ -140,7 +140,7 @@ let list_contract_entrypoints cctxt ~chain ~block ~contract ~normalize_types = cctxt ~chain ~block - ~contract:(Contract.Originated contract) + ~contract ~entrypoint:Entrypoint.default ~normalize_types >>= function diff --git a/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli b/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli index 47c85421de5f..230b8edc998b 100644 --- a/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli +++ b/src/proto_alpha/lib_client/michelson_v1_entrypoints.mli @@ -39,7 +39,7 @@ val contract_entrypoint_type : #Protocol_client_context.rpc_context -> chain:Chain_services.chain -> block:Block_services.block -> - contract:Alpha_context.Contract.t -> + contract:Contract_hash.t -> entrypoint:Alpha_context.Entrypoint.t -> normalize_types:bool -> Alpha_context.Script.expr option tzresult Lwt.t @@ -48,7 +48,7 @@ val print_entrypoint_type : #Client_context.printer -> ?on_errors:(error list -> unit tzresult Lwt.t) -> emacs:bool -> - ?contract:Alpha_context.Contract.t -> + ?contract:Contract_hash.t -> ?script_name:string -> entrypoint:Alpha_context.Entrypoint.t -> Alpha_context.Script.expr option tzresult -> 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 e70837a5ae76..dca122217d04 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 @@ -372,7 +372,9 @@ let commands_ro () = ~desc:"the entrypoint to describe" entrypoint_parameter @@ prefixes ["for"] - @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" + @@ OriginatedContractAlias.destination_param + ~name:"src" + ~desc:"source contract" @@ stop) (fun normalize_types entrypoint diff --git a/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml index 20c23c212f45..40f28b76d178 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml @@ -136,20 +136,20 @@ let get_parameter_type (cctxt : #Protocol_client_context.full) | Implicit _ -> let open Micheline in return @@ strip_locations @@ Prim (0, Script.T_unit, [], []) - | Originated _ -> ( + | Originated contract -> ( Michelson_v1_entrypoints.contract_entrypoint_type cctxt ~chain:cctxt#chain ~block:cctxt#block - ~contract:destination + ~contract ~entrypoint ~normalize_types:true >>=? function | None -> cctxt#error "Contract %a has no entrypoint named %a" - Contract.pp - destination + Contract_hash.pp + contract Entrypoint.pp entrypoint | Some parameter_type -> return parameter_type) -- GitLab From 3e104c11c5dee3706739a88dac2bba0894ed5765 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 11:16:16 +0200 Subject: [PATCH 10/13] Proto/Client: tzip4 views work on originated contracts only --- src/proto_alpha/lib_client/client_proto_fa12.ml | 2 +- src/proto_alpha/lib_client/client_proto_programs.ml | 2 +- src/proto_alpha/lib_client/client_proto_programs.mli | 2 +- .../lib_client_commands/client_proto_programs_commands.ml | 2 +- src/proto_alpha/lib_plugin/plugin.ml | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_fa12.ml b/src/proto_alpha/lib_client/client_proto_fa12.ml index 058c101e056e..5659acdc5925 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.ml +++ b/src/proto_alpha/lib_client/client_proto_fa12.ml @@ -969,7 +969,7 @@ let run_view_action (cctxt : #Protocol_client_context.full) ~chain ~block Plugin.RPC.Scripts.run_tzip4_view cctxt (chain, block) - ~contract:(Contract.Originated contract) + ~contract ~input ~chain_id ?source diff --git a/src/proto_alpha/lib_client/client_proto_programs.ml b/src/proto_alpha/lib_client/client_proto_programs.ml index d2a2b0555f21..7ec6c100f8d6 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.ml +++ b/src/proto_alpha/lib_client/client_proto_programs.ml @@ -132,7 +132,7 @@ type simulation_params = { type run_view_params = { shared_params : simulation_params; - contract : Contract.t; + contract : Contract_hash.t; entrypoint : Entrypoint.t; } diff --git a/src/proto_alpha/lib_client/client_proto_programs.mli b/src/proto_alpha/lib_client/client_proto_programs.mli index c8938eabf327..9ea3f12150c9 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.mli +++ b/src/proto_alpha/lib_client/client_proto_programs.mli @@ -46,7 +46,7 @@ type simulation_params = { (* Parameters specific to simulations of TZIP4 views *) type run_view_params = { shared_params : simulation_params; - contract : Contract.t; + contract : Contract_hash.t; entrypoint : Entrypoint.t; } diff --git a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml index 487c3a3f3f47..eaca6b37b54b 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml @@ -950,7 +950,7 @@ let commands () = ~desc:"the name of the view" entrypoint_parameter @@ prefixes ["on"; "contract"] - @@ ContractAlias.destination_param + @@ OriginatedContractAlias.destination_param ~name:"contract" ~desc:"viewed contract" @@ prefixes ["with"; "input"] diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 17148347c3ab..b23003efced8 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1741,7 +1741,7 @@ module RPC = struct let run_tzip4_view_encoding = let open Data_encoding in obj10 - (req "contract" Contract.encoding) + (req "contract" Contract.originated_encoding) (req "entrypoint" Entrypoint.simple_encoding) (req "input" Script.expr_encoding) (req "chain_id" Chain_id.encoding) @@ -2657,6 +2657,7 @@ module RPC = struct now, level ) -> + let contract = Contract.Originated contract in Contract.get_script ctxt contract >>=? fun (ctxt, script_opt) -> Option.fold ~some:ok -- GitLab From 7dac2970397e8b78cc408de5f2041174436a070b Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 11:19:46 +0200 Subject: [PATCH 11/13] Proto/Client: script views work on originated contracts only --- src/proto_alpha/lib_client/client_proto_programs.ml | 2 +- src/proto_alpha/lib_client/client_proto_programs.mli | 2 +- .../lib_client_commands/client_proto_programs_commands.ml | 4 ++-- src/proto_alpha/lib_plugin/plugin.ml | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_programs.ml b/src/proto_alpha/lib_client/client_proto_programs.ml index 7ec6c100f8d6..8a802bd1f784 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.ml +++ b/src/proto_alpha/lib_client/client_proto_programs.ml @@ -138,7 +138,7 @@ type run_view_params = { type run_script_view_params = { shared_params : simulation_params; - contract : Contract.t; + contract : Contract_hash.t; view : string; unlimited_gas : bool; } diff --git a/src/proto_alpha/lib_client/client_proto_programs.mli b/src/proto_alpha/lib_client/client_proto_programs.mli index 9ea3f12150c9..4276f29fc585 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.mli +++ b/src/proto_alpha/lib_client/client_proto_programs.mli @@ -53,7 +53,7 @@ type run_view_params = { (* Parameters specific to simulations of Michelson views *) type run_script_view_params = { shared_params : simulation_params; - contract : Contract.t; + contract : Contract_hash.t; view : string; unlimited_gas : bool; } diff --git a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml index eaca6b37b54b..b1124799d886 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_programs_commands.ml @@ -986,7 +986,7 @@ let commands () = (prefixes ["run"; "view"] @@ param ~name:"view" ~desc:"the name of the view" string_parameter @@ prefixes ["on"; "contract"] - @@ ContractAlias.destination_param + @@ OriginatedContractAlias.destination_param ~name:"contract" ~desc:"the contract containing the view" @@ stop) @@ -1023,7 +1023,7 @@ let commands () = (prefixes ["run"; "view"] @@ param ~name:"view" ~desc:"the name of the view" string_parameter @@ prefixes ["on"; "contract"] - @@ ContractAlias.destination_param + @@ OriginatedContractAlias.destination_param ~name:"contract" ~desc:"the contract containing the view" @@ prefixes ["with"; "input"] diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index b23003efced8..3031c6174b65 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1756,7 +1756,7 @@ module RPC = struct let open Data_encoding in merge_objs (obj10 - (req "contract" Contract.encoding) + (req "contract" Contract.originated_encoding) (req "view" string) (req "input" Script.expr_encoding) (dft "unlimited_gas" bool false) @@ -2758,6 +2758,7 @@ module RPC = struct now ), level ) -> + let contract = Contract.Originated contract in Contract.get_script ctxt contract >>=? fun (ctxt, script_opt) -> Option.fold ~some:ok -- GitLab From aa082e4d094f434fb1ae8910e740c25950de70f3 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 13 May 2022 09:02:17 +0200 Subject: [PATCH 12/13] Tezt: adapt run_view error message --- tezt/tests/client_run_view.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tezt/tests/client_run_view.ml b/tezt/tests/client_run_view.ml index 9750680dd727..55ebbcade7fb 100644 --- a/tezt/tests/client_run_view.ml +++ b/tezt/tests/client_run_view.ml @@ -196,9 +196,9 @@ let test_run_view_fail_generic ~protocol ~view ~contract ~input ~msg () = let failed_command = Client.spawn_run_view ~view ~contract ?input client in Process.check_error ~exit_code:1 ~msg failed_command -(* Runs view `add_v` on an implict account and fails *) +(* Runs view `add_v` on an implicit account and fails *) let test_run_view_implicit_account ~protocol () = - let msg = rex "A view was called on a contract with no script." in + let msg = rex "Erroneous command line argument 6 \\(tz1" in test_run_view_fail_generic ~protocol ~view:"add_v" -- GitLab From ef411c20156e32383bb53fb78edf70d7ee9806f2 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 9 May 2022 13:33:28 +0200 Subject: [PATCH 13/13] Proto/Client: get_script/get_storage work on originated contracts only --- .../lib_client/client_proto_context.ml | 1 + .../lib_client/client_proto_context.mli | 4 +- .../lib_client/client_proto_multisig.ml | 42 +++++++++++-------- .../lib_client/client_proto_multisig.mli | 6 +-- .../lib_client/managed_contract.ml | 2 +- .../client_proto_context_commands.ml | 8 +++- .../client_proto_multisig_commands.ml | 32 +++++++------- src/proto_alpha/lib_plugin/plugin.ml | 2 +- 8 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 9c5eba56001d..48c315bc7889 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -66,6 +66,7 @@ let get_script (rpc : #rpc_context) ~chain ~block ~unparsing_mode ~contract let get_script_hash (rpc : #rpc_context) ~chain ~block contract = + let contract = Contract.Originated contract in Alpha_services.Contract.script_opt rpc (chain, block) contract >>=? fun script_opt -> Lwt.return @@ Environment.wrap_tzresult diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 594a888c3dbb..dac109654d59 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -37,7 +37,7 @@ val get_storage : chain:Shell_services.chain -> block:Shell_services.block -> unparsing_mode:Script_ir_translator.unparsing_mode -> - Contract.t -> + Contract_hash.t -> Script.expr option tzresult Lwt.t val get_contract_big_map_value : @@ -91,7 +91,7 @@ val get_script_hash : #Protocol_client_context.rpc_context -> chain:Shell_services.chain -> block:Shell_services.block -> - Contract.t -> + Contract_hash.t -> Script_expr_hash.t option tzresult Lwt.t val get_balance : diff --git a/src/proto_alpha/lib_client/client_proto_multisig.ml b/src/proto_alpha/lib_client/client_proto_multisig.ml index 3212f5fa1a9c..8c7815505c2d 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.ml +++ b/src/proto_alpha/lib_client/client_proto_multisig.ml @@ -28,13 +28,13 @@ open Protocol open Alpha_context open Michelson_v1_helpers -type error += Contract_has_no_script of Contract.t +type error += Contract_has_no_script of Contract_hash.t type error += Not_a_supported_multisig_contract of Script_expr_hash.t -type error += Contract_has_no_storage of Contract.t +type error += Contract_has_no_storage of Contract_hash.t -type error += Contract_has_unexpected_storage of Contract.t +type error += Contract_has_unexpected_storage of Contract_hash.t type error += Invalid_signature of signature @@ -44,7 +44,7 @@ type error += Action_deserialisation_error of Script.expr type error += Bytes_deserialisation_error of Bytes.t -type error += Bad_deserialized_contract of (Contract.t * Contract.t) +type error += Bad_deserialized_contract of (Contract_hash.t * Contract_hash.t) type error += Bad_deserialized_counter of (counter * counter) @@ -73,8 +73,8 @@ let () = "A multisig command has referenced a scriptless smart contract instead \ of a multisig smart contract." ~pp:(fun ppf contract -> - Format.fprintf ppf "Contract has no script %a." Contract.pp contract) - Data_encoding.(obj1 (req "contract" Contract.encoding)) + Format.fprintf ppf "Contract has no script %a." Contract_hash.pp contract) + Data_encoding.(obj1 (req "contract" Contract.originated_encoding)) (function Contract_has_no_script c -> Some c | _ -> None) (fun c -> Contract_has_no_script c) ; register_error_kind @@ -104,8 +104,8 @@ let () = "A multisig command has referenced a smart contract without storage \ instead of a multisig smart contract." ~pp:(fun ppf contract -> - Format.fprintf ppf "Contract has no storage %a." Contract.pp contract) - Data_encoding.(obj1 (req "contract" Contract.encoding)) + Format.fprintf ppf "Contract has no storage %a." Contract_hash.pp contract) + Data_encoding.(obj1 (req "contract" Contract.originated_encoding)) (function Contract_has_no_storage c -> Some c | _ -> None) (fun c -> Contract_has_no_storage c) ; register_error_kind @@ -121,9 +121,9 @@ let () = Format.fprintf ppf "Contract has unexpected storage %a." - Contract.pp + Contract_hash.pp contract) - Data_encoding.(obj1 (req "contract" Contract.encoding)) + Data_encoding.(obj1 (req "contract" Contract.originated_encoding)) (function Contract_has_unexpected_storage c -> Some c | _ -> None) (fun c -> Contract_has_unexpected_storage c) ; register_error_kind @@ -199,12 +199,15 @@ let () = Format.fprintf ppf "Bad deserialized contract, received %a expected %a." - Contract.pp + Contract_hash.pp received - Contract.pp + Contract_hash.pp expected) Data_encoding.( - obj1 (req "received_expected" (tup2 Contract.encoding Contract.encoding))) + obj1 + (req + "received_expected" + (tup2 Contract.originated_encoding Contract.originated_encoding))) (function Bad_deserialized_contract b -> Some b | _ -> None) (fun b -> Bad_deserialized_contract b) ; register_error_kind @@ -1013,6 +1016,7 @@ let prepare_multisig_transaction (cctxt : #Protocol_client_context.full) ~chain multisig_get_information cctxt ~chain ~block contract >>=? fun {counter; threshold; keys} -> Chain_services.chain_id cctxt ~chain () >>=? fun chain_id -> + let contract = Contract.Originated contract in multisig_bytes ~counter ~action ~contract ~descr ~chain_id () >>=? fun bytes -> Client_proto_context.get_balance @@ -1092,7 +1096,7 @@ let call_multisig (cctxt : #Protocol_client_context.full) ~chain ~block ~source ~src_pk ~src_sk - ~destination:(Contract multisig_contract) + ~destination:(Contract (Originated multisig_contract)) ?entrypoint ~parameters ~amount @@ -1128,10 +1132,12 @@ let action_of_bytes ~multisig_contract ~stored_counter ~descr ~chain_id bytes = [] ) when not descr.requires_chain_id -> let contract = - Data_encoding.Binary.of_bytes_exn Contract.encoding contract_bytes + Data_encoding.Binary.of_bytes_exn + Contract.originated_encoding + contract_bytes in if counter = stored_counter then - if Contract.(multisig_contract = contract) then + if Contract_hash.(multisig_contract = contract) then action_of_expr ~generic:descr.generic e else fail (Bad_deserialized_contract (contract, multisig_contract)) @@ -1157,7 +1163,9 @@ let action_of_bytes ~multisig_contract ~stored_counter ~descr ~chain_id bytes = [] ) when descr.requires_chain_id -> let contract = - Data_encoding.Binary.of_bytes_exn Contract.encoding contract_bytes + Data_encoding.Binary.of_bytes_exn + Contract.originated_encoding + contract_bytes in let cid = Data_encoding.Binary.of_bytes_exn Chain_id.encoding chain_id_bytes diff --git a/src/proto_alpha/lib_client/client_proto_multisig.mli b/src/proto_alpha/lib_client/client_proto_multisig.mli index 909cc0b550cd..76543977831f 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.mli +++ b/src/proto_alpha/lib_client/client_proto_multisig.mli @@ -93,7 +93,7 @@ val prepare_multisig_transaction : full -> chain:Shell_services.chain -> block:Shell_services.block -> - multisig_contract:Contract.t -> + multisig_contract:Contract_hash.t -> action:multisig_action -> unit -> multisig_prepared_action tzresult Lwt.t @@ -110,7 +110,7 @@ val call_multisig : source:public_key_hash -> src_pk:public_key -> src_sk:Client_keys.sk_uri -> - multisig_contract:Contract.t -> + multisig_contract:Contract_hash.t -> action:multisig_action -> signatures:Signature.t list -> amount:Tez.t -> @@ -136,7 +136,7 @@ val call_multisig_on_bytes : source:public_key_hash -> src_pk:public_key -> src_sk:Client_keys.sk_uri -> - multisig_contract:Contract.t -> + multisig_contract:Contract_hash.t -> bytes:Bytes.t -> signatures:Signature.t list -> amount:Tez.t -> diff --git a/src/proto_alpha/lib_client/managed_contract.ml b/src/proto_alpha/lib_client/managed_contract.ml index ad470dd35a9f..a4cb3896dc3c 100644 --- a/src/proto_alpha/lib_client/managed_contract.ml +++ b/src/proto_alpha/lib_client/managed_contract.ml @@ -41,7 +41,7 @@ let get_contract_manager (cctxt : #full) contract = ~chain:cctxt#chain ~block:cctxt#block ~unparsing_mode:Optimized - (Contract.Originated contract) + contract >>=? function | None -> cctxt#error "This is not a smart contract." | Some storage -> ( 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 dca122217d04..0aba15d71216 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 @@ -253,7 +253,9 @@ let commands_ro () = ~desc:"Get the storage of a contract." (args1 (unparsing_mode_arg ~default:"Readable")) (prefixes ["get"; "contract"; "storage"; "for"] - @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" + @@ OriginatedContractAlias.destination_param + ~name:"src" + ~desc:"source contract" @@ stop) (fun unparsing_mode contract (cctxt : Protocol_client_context.full) -> get_storage @@ -354,7 +356,9 @@ let commands_ro () = ~desc:"Get the `BLAKE2B` script hash of a contract." no_options (prefixes ["get"; "contract"; "script"; "hash"; "for"] - @@ ContractAlias.destination_param ~name:"src" ~desc:"source contract" + @@ OriginatedContractAlias.destination_param + ~name:"src" + ~desc:"source contract" @@ stop) (fun () contract (cctxt : Protocol_client_context.full) -> get_script_hash cctxt ~chain:cctxt#chain ~block:cctxt#block contract diff --git a/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml index 40f28b76d178..f3ed1dbf2ade 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_multisig_commands.ml @@ -285,7 +285,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Sign a transaction for a multisig contract." (args2 arg_arg entrypoint_arg) (prefixes ["sign"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefix "transferring" @@ -330,7 +330,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Sign a lambda for a generic multisig contract." no_options (prefixes ["sign"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["running"; "lambda"] @@ -360,7 +360,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Sign a delegate change for a multisig contract." no_options (prefixes ["sign"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["setting"; "delegate"; "to"] @@ -389,7 +389,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Sign a delegate withdraw for a multisig contract." no_options (prefixes ["sign"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["withdrawing"; "delegate"] @@ -412,7 +412,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = "Sign a change of public keys and threshold for a multisig contract." no_options (prefixes ["sign"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["using"; "secret"; "key"] @@ -447,7 +447,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Transfer tokens using a multisig contract." transfer_options (prefixes ["from"; "multisig"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name/literal of the multisig contract" @@ prefix "transfer" @@ -535,7 +535,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Run a lambda on a generic multisig contract." non_transfer_options (prefixes ["from"; "multisig"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name/literal of the multisig contract" @@ prefixes ["run"; "lambda"] @@ -600,7 +600,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Change the delegate of a multisig contract." non_transfer_options (prefixes ["set"; "delegate"; "of"; "multisig"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefix "to" @@ -664,7 +664,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Withdraw the delegate of a multisig contract." non_transfer_options (prefixes ["withdraw"; "delegate"; "of"; "multisig"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["on"; "behalf"; "of"] @@ -723,7 +723,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = ~desc:"Change public keys and threshold for a multisig contract." non_transfer_options (prefixes ["set"; "threshold"; "of"; "multisig"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["to"] @@ threshold_param () @@ -803,7 +803,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = be obtained by one of the \"prepare multisig transaction\" \ commands" @@ prefixes ["on"; "multisig"; "contract"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["on"; "behalf"; "of"] @@ -865,7 +865,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = multisigned transfer." (args3 bytes_only_switch arg_arg entrypoint_arg) (prefixes ["prepare"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefix "transferring" @@ -909,7 +909,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = multisigned lambda execution in a generic multisig contract." (args1 bytes_only_switch) (prefixes ["prepare"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["running"; "lambda"] @@ -937,7 +937,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = multisigned delegate change." (args1 bytes_only_switch) (prefixes ["prepare"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["setting"; "delegate"; "to"] @@ -965,7 +965,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = multisigned delegate withdraw." (args1 bytes_only_switch) (prefixes ["prepare"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["withdrawing"; "delegate"] @@ -989,7 +989,7 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = multisigned change of keys and threshold." (args1 bytes_only_switch) (prefixes ["prepare"; "multisig"; "transaction"; "on"] - @@ Client_proto_contracts.ContractAlias.destination_param + @@ Client_proto_contracts.OriginatedContractAlias.destination_param ~name:"multisig" ~desc:"name or address of the originated multisig contract" @@ prefixes ["setting"; "threshold"; "to"] diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index 3031c6174b65..fa563890968c 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -3232,7 +3232,7 @@ module RPC = struct S.get_storage_normalized ctxt block - contract + (Contract.Originated contract) () unparsing_mode -- GitLab