diff --git a/src/proto_alpha/lib_benchmark/execution_context.ml b/src/proto_alpha/lib_benchmark/execution_context.ml index ede85b37f8bbc2aca60b333d67f2b5e72edf80bc..86fbdd7278e7e06ecbc7145e122df9f5e09f128a 100644 --- a/src/proto_alpha/lib_benchmark/execution_context.ml +++ b/src/proto_alpha/lib_benchmark/execution_context.ml @@ -58,10 +58,10 @@ let make ~rng_state = let level = Script_int.zero_n in let open Script_interpreter in (match context with - | `Mem_block (block, (bs1, bs2, bs3, _, _)) -> + | `Mem_block (block, (bs1, bs2, _, _, _)) -> let source = bs1 in let payer = bs2 in - let self = bs3 in + let self = Contract_helpers.default_self in let step_constants = { source; diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index d934fca4a4aaa006bc28974629210cd83ad69bfc..5e885fe2d41f488ce46fb57918043df63ab4b157 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -2867,7 +2867,7 @@ module Registration_section = struct { source = zero; payer = zero; - self = zero; + self = Contract_hash.zero; amount = Tez.zero; balance = Tez.zero; chain_id = Chain_id.zero; diff --git a/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml index c1571830c6d48674bf2f31769a019ca10474e2b8..53246451c72b29d37873f3ca045dafdb07149475 100644 --- a/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/sapling_benchmarks.ml @@ -102,7 +102,7 @@ module Apply_diff_bench : Benchmark.S = struct Format.eprintf "tx hash: %d@." (Hashtbl.hash sapling_transition.sapling_tx) ; - let address = Alpha_context.Contract.to_b58check step_constants.self in + let address = Contract_hash.to_b58check step_constants.self in let chain_id = Environment.Chain_id.to_b58check step_constants.chain_id in diff --git a/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml b/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml index 15b69c5e1208a006878e2b7f4179f2d100f04d3c..bbe1c2c2ec905cfbc0db8ffbe95c0035f142899b 100644 --- a/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml +++ b/src/proto_alpha/lib_benchmarks_proto/sapling_generation.ml @@ -504,7 +504,7 @@ let generate (save_to : string) (tx_count : int) @@ Option.fold ~none:shared_seed ~some:(fun seed -> [|seed|]) seed in Execution_context.make ~rng_state >>=? fun (ctxt, step_constants) -> - let address = Alpha_context.Contract.to_b58check step_constants.self in + let address = Contract_hash.to_b58check step_constants.self in let chain_id = Environment.Chain_id.to_b58check step_constants.chain_id in diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 581634628ed0b1057d0b2aeaa0269d3195227ede..e1e2baad06b7704aa7b8113bedbe006fced28a70 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -408,7 +408,7 @@ let originate_contract (cctxt : #full) ~chain ~block ?confirmations ?dry_run return (oph, op, result)) >>=? fun res -> Lwt.return (Injection.originated_contracts ~force:false result) >>=? function - | [contract] -> return (res, contract) + | [contract] -> return (res, Contract.Originated contract) | contracts -> failwith "The origination introduced %d contracts instead of one." diff --git a/src/proto_alpha/lib_client/client_proto_context.mli b/src/proto_alpha/lib_client/client_proto_context.mli index 63887eab680b812fe3cd84fb3c0dc866f0fffd7d..e4fe99e770b3e71ed598a6026a232912de5e865a 100644 --- a/src/proto_alpha/lib_client/client_proto_context.mli +++ b/src/proto_alpha/lib_client/client_proto_context.mli @@ -229,7 +229,8 @@ val transfer_with_script : fee_parameter:Injection.fee_parameter -> ?replace_by_fees:bool -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t val transfer : @@ -257,7 +258,8 @@ val transfer : fee_parameter:Injection.fee_parameter -> ?replace_by_fees:bool -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t val build_reveal_operation : diff --git a/src/proto_alpha/lib_client/client_proto_fa12.mli b/src/proto_alpha/lib_client/client_proto_fa12.mli index a8d4644848a922cb09d3368227b1a0ac77604d73..5eaf1989abbc56ac1a729a5f2f9d75b4290e9814 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.mli +++ b/src/proto_alpha/lib_client/client_proto_fa12.mli @@ -109,7 +109,8 @@ val call_contract : ?counter:Z.t -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t (** Single transfer operation. *) diff --git a/src/proto_alpha/lib_client/client_proto_multisig.mli b/src/proto_alpha/lib_client/client_proto_multisig.mli index 76543977831f8a789d70b11dacec9c503052bf5c..bd2f3d746552f6a392a419a1654013952d0417b7 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.mli +++ b/src/proto_alpha/lib_client/client_proto_multisig.mli @@ -120,7 +120,8 @@ val call_multisig : ?counter:Z.t -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t (* Same as [call_multisig] but the action to be performed is reconstructed from @@ -146,5 +147,6 @@ val call_multisig_on_bytes : ?counter:Z.t -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t diff --git a/src/proto_alpha/lib_client/client_proto_programs.ml b/src/proto_alpha/lib_client/client_proto_programs.ml index f79f858fee94d115ce4af5147e1254214c22b14e..e2e7d31e3803719f9df725ee37a1a49f05879354 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.ml +++ b/src/proto_alpha/lib_client/client_proto_programs.ml @@ -150,7 +150,7 @@ type run_params = { program : Michelson_v1_parser.parsed; storage : Michelson_v1_parser.parsed; entrypoint : Entrypoint.t option; - self : Contract.t option; + self : Contract_hash.t option; } let run_view (cctxt : #Protocol_client_context.rpc_context) diff --git a/src/proto_alpha/lib_client/client_proto_programs.mli b/src/proto_alpha/lib_client/client_proto_programs.mli index 4276f29fc585d1c0c777d9356ff3c25ac4175932..f24f4abeaa667a68d45adcc03b0e3913b28db4c3 100644 --- a/src/proto_alpha/lib_client/client_proto_programs.mli +++ b/src/proto_alpha/lib_client/client_proto_programs.mli @@ -66,7 +66,7 @@ type run_params = { program : Michelson_v1_parser.parsed; storage : Michelson_v1_parser.parsed; entrypoint : Entrypoint.t option; - self : Contract.t option; + self : Contract_hash.t option; } val run_view : diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 9ab3b795ef02f57098a25ce8cf292869a126e9e4..c1ae74b26d7f337281b3add54e6c1459fe23c02a 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -1051,7 +1051,7 @@ let inject_operation_internal (type kind) cctxt ~chain ~block ?confirmations Lwt.return (originated_contracts result.contents ~force) >>=? fun contracts -> List.iter_s - (fun c -> cctxt#message "New contract %a originated." Contract.pp c) + (fun c -> cctxt#message "New contract %a originated." Contract_hash.pp c) contracts >>= fun () -> (match confirmations with diff --git a/src/proto_alpha/lib_client/injection.mli b/src/proto_alpha/lib_client/injection.mli index fd1b1104a74b6c6c71ceeb45db251b74d73dfb86..d9e81c89e14d57a50f517e3a1b4f1bc2da69510b 100644 --- a/src/proto_alpha/lib_client/injection.mli +++ b/src/proto_alpha/lib_client/injection.mli @@ -119,4 +119,4 @@ val inject_manager_operation : by looking at the operation results. Fails if an operation in the batch is failed unless [force] is given. *) val originated_contracts : - force:bool -> 'kind contents_result_list -> Contract.t list tzresult + force:bool -> 'kind contents_result_list -> Contract_hash.t list tzresult diff --git a/src/proto_alpha/lib_client/managed_contract.ml b/src/proto_alpha/lib_client/managed_contract.ml index 96294964ec368f76fc3243c99ba8f5e224d2a240..0696ec0cf423828ac0909e1ce9c83e72ce16be7c 100644 --- a/src/proto_alpha/lib_client/managed_contract.ml +++ b/src/proto_alpha/lib_client/managed_contract.ml @@ -290,7 +290,8 @@ let transfer (cctxt : #full) ~chain ~block ?confirmations ?dry_run ?verbose_signing ?simulation ?(force = false) ?branch ~source ~src_pk ~src_sk ~contract ~destination ?(entrypoint = Entrypoint.default) ?arg ~amount ?fee ?gas_limit ?storage_limit ?counter ~fee_parameter () : - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t = build_transaction_operation cctxt diff --git a/src/proto_alpha/lib_client/managed_contract.mli b/src/proto_alpha/lib_client/managed_contract.mli index 67c4a4226e981c02db0fd2204915825e09e41dbd..e02cf3fa7aab6e658ba9992b98fd535495013865 100644 --- a/src/proto_alpha/lib_client/managed_contract.mli +++ b/src/proto_alpha/lib_client/managed_contract.mli @@ -110,7 +110,8 @@ val transfer : ?counter:counter -> fee_parameter:Injection.fee_parameter -> unit -> - (Kind.transaction Kind.manager Injection.result * Contract.t list) tzresult + (Kind.transaction Kind.manager Injection.result * Contract_hash.t list) + tzresult Lwt.t val build_lambda_for_set_delegate : delegate:public_key_hash option -> string diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index fdc7ce243ae07bb0cd7acd3704511b58e1df506e..0af57d8b6f855fca77252af12f105db6f9e4ff26 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -474,7 +474,7 @@ let pp_manager_operation_contents_and_result ppf Format.fprintf ppf "@,@[Originated contracts:@,%a@]" - (Format.pp_print_list Contract.pp) + (Format.pp_print_list Contract_hash.pp) contracts) ; (match storage with | None -> () @@ -526,7 +526,7 @@ let pp_manager_operation_contents_and_result ppf Format.fprintf ppf "@,@[Originated contracts:@,%a@]" - (Format.pp_print_list Contract.pp) + (Format.pp_print_list Contract_hash.pp) contracts) ; if storage_size <> Z.zero then Format.fprintf ppf "@,Storage size: %s bytes" (Z.to_string storage_size) ; 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 b1124799d886097923ffa8067ceb4d4f8a508428..d82c6be1bc6c8e9a372a055057149908d1129358 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 @@ -97,7 +97,7 @@ let commands () = () in let self_arg = - ContractAlias.destination_arg + OriginatedContractAlias.destination_arg ~name:"self-address" ~doc:"address of the contract (i.e. SELF_ADDRESS) for the transaction" () diff --git a/src/proto_alpha/lib_plugin/plugin.ml b/src/proto_alpha/lib_plugin/plugin.ml index d810ee1c7fef46c5cd3fdf7c3137fd64100cb86a..a4e87f1dd557e66bbae04eb48f81556ee6eb9301 100644 --- a/src/proto_alpha/lib_plugin/plugin.ml +++ b/src/proto_alpha/lib_plugin/plugin.ml @@ -1711,7 +1711,7 @@ module RPC = struct (req "chain_id" Chain_id.encoding) (opt "source" Contract.encoding) (opt "payer" Contract.encoding) - (opt "self" Contract.encoding) + (opt "self" Contract.originated_encoding) (dft "entrypoint" Entrypoint.simple_encoding Entrypoint.default)) (obj4 (opt "unparsing_mode" unparsing_mode_encoding) @@ -2439,7 +2439,7 @@ module RPC = struct (* A convenience type for return values of [ensure_contracts_exist] below. *) type run_code_config = { balance : Tez.t; - self : Contract.t; + self : Contract_hash.t; payer : Contract.t; source : Contract.t; } @@ -2452,13 +2452,13 @@ module RPC = struct let ctxt = Origination_nonce.init ctxt Operation_hash.zero in Contract.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, dummy_contract_hash) -> - let dummy_contract = Contract.Originated dummy_contract_hash in Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false - dummy_contract + dummy_contract_hash ~script:(script, None) >>=? fun ctxt -> + let dummy_contract = Contract.Originated dummy_contract_hash in Token.transfer ~origin:Simulation ctxt @@ -2472,18 +2472,19 @@ module RPC = struct | None -> let balance = Option.value ~default:default_balance balance in originate_dummy_contract ctxt script balance - >>=? fun (ctxt, addr) -> - return (ctxt, Contract.Originated addr, balance) + >>=? fun (ctxt, addr) -> return (ctxt, addr, balance) | Some addr -> default_from_context ctxt - (fun c -> Contract.get_balance c addr) + (fun c -> Contract.get_balance c (Contract.Originated addr)) balance >>=? fun bal -> return (ctxt, addr, bal)) >>=? fun (ctxt, self, balance) -> let source, payer = match (src_opt, pay_opt) with - | None, None -> (self, self) + | None, None -> + let self = Contract.Originated self in + (self, self) | Some c, None | None, Some c -> (c, c) | Some src, Some pay -> (src, pay) in @@ -2669,7 +2670,7 @@ module RPC = struct (fun ctxt () - ( contract, + ( contract_hash, entrypoint, input, chain_id, @@ -2680,7 +2681,7 @@ module RPC = struct now, level ) -> - let contract = Contract.Originated contract in + let contract = Contract.Originated contract_hash in Contract.get_script ctxt contract >>=? fun (ctxt, script_opt) -> Option.fold ~some:ok @@ -2727,7 +2728,7 @@ module RPC = struct { source; payer; - self = contract; + self = contract_hash; amount = Tez.zero; balance; chain_id; @@ -2769,7 +2770,7 @@ module RPC = struct (fun ctxt () - ( ( contract, + ( ( contract_hash, view, input, unlimited_gas, @@ -2781,7 +2782,7 @@ module RPC = struct now ), level ) -> - let contract = Contract.Originated contract in + let contract = Contract.Originated contract_hash in Contract.get_script ctxt contract >>=? fun (ctxt, script_opt) -> Option.fold ~some:ok @@ -2828,7 +2829,7 @@ module RPC = struct { Script_interpreter.source; payer; - self = contract; + self = contract_hash; amount = Tez.zero; balance; chain_id; diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index dd2be744c94306f6676db1e9e7d3db4394cb9b73..07627ae7e429f2baa69b8134c813050159de4a84 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1582,7 +1582,7 @@ module Contract : sig val raw_originate : context -> prepaid_bootstrap_storage:bool -> - t -> + Contract_hash.t -> script:Script.t * Lazy_storage.diffs option -> context tzresult Lwt.t @@ -3423,7 +3423,7 @@ end module Migration : sig type origination_result = { balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; storage_size : Z.t; paid_storage_size_diff : Z.t; } diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index c297a43f71b4ab566f1e3ba6cce72ae1881db8bf..b818245830e0c496515c0dc2303c756d23f0599d 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -878,7 +878,7 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract_hash ~amount { source; payer = Contract.Implicit payer; - self = contract; + self = contract_hash; amount; chain_id; balance; @@ -929,9 +929,6 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract_hash ~amount >>=? fun (ctxt, new_size, contract_paid_storage_size_diff) -> Contract.originated_from_current_nonce ~since:before_operation ~until:ctxt >>=? fun originated_contracts -> - let originated_contracts = - List.map (fun c -> Contract.Originated c) originated_contracts - in Lwt.return ( Script_cache.update ctxt @@ -1038,8 +1035,8 @@ let apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters ~payer in return (ctxt, result, []) -let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract - ~delegate ~source ~credit ~before_operation = +let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code + ~contract:contract_hash ~delegate ~source ~credit ~before_operation = Script_ir_translator.collect_lazy_storage ctxt storage_type storage >>?= fun (to_duplicate, ctxt) -> let to_update = Script_ir_translator.no_lazy_storage_id in @@ -1065,13 +1062,13 @@ let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract Gas.consume ctxt (Script.strip_locations_cost code) >>?= fun ctxt -> let code = Script.lazy_expr (Micheline.strip_locations code) in let script = {Script.code; storage} in - let contract = Contract.Originated contract in Contract.raw_originate ctxt ~prepaid_bootstrap_storage:false - contract + contract_hash ~script:(script, lazy_storage_diff) >>=? fun ctxt -> + let contract = Contract.Originated contract_hash in (match delegate with | None -> return ctxt | Some delegate -> Delegate.init ctxt contract delegate) @@ -1085,7 +1082,7 @@ let apply_origination ~ctxt ~storage_type ~storage ~unparsed_code ~contract { lazy_storage_diff; balance_updates; - originated_contracts = [contract]; + originated_contracts = [contract_hash]; consumed_gas = Gas.consumed ~since:before_operation ~until:ctxt; storage_size = size; paid_storage_size_diff; @@ -3164,7 +3161,7 @@ let apply_liquidity_baking_subsidy ctxt ~toggle_vote = { source = liquidity_baking_cpmm_contract; payer = liquidity_baking_cpmm_contract; - self = liquidity_baking_cpmm_contract; + self = liquidity_baking_cpmm_contract_hash; amount = liquidity_baking_subsidy; balance; chain_id = Chain_id.zero; diff --git a/src/proto_alpha/lib_protocol/apply_results.ml b/src/proto_alpha/lib_protocol/apply_results.ml index bd9911b11ee510bd1f704edac24bc829994e093c..3743c02991f478e71815042663378a0c01d64ef6 100644 --- a/src/proto_alpha/lib_protocol/apply_results.ml +++ b/src/proto_alpha/lib_protocol/apply_results.ml @@ -113,7 +113,7 @@ type successful_transaction_result = storage : Script.expr option; lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; @@ -137,7 +137,7 @@ type _ successful_manager_operation_result = | Origination_result : { lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; @@ -387,7 +387,7 @@ module Manager_result = struct (obj9 (opt "storage" Script.expr_encoding) (dft "balance_updates" Receipt.balance_updates_encoding []) - (dft "originated_contracts" (list Contract.encoding) []) + (dft "originated_contracts" (list Contract.originated_encoding) []) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (dft "storage_size" z Z.zero) @@ -494,7 +494,7 @@ module Manager_result = struct ~encoding: (obj7 (dft "balance_updates" Receipt.balance_updates_encoding []) - (dft "originated_contracts" (list Contract.encoding) []) + (dft "originated_contracts" (list Contract.originated_encoding) []) (dft "consumed_gas" Gas.Arith.n_integral_encoding Gas.Arith.zero) (dft "consumed_milligas" Gas.Arith.n_fp_encoding Gas.Arith.zero) (dft "storage_size" z Z.zero) diff --git a/src/proto_alpha/lib_protocol/apply_results.mli b/src/proto_alpha/lib_protocol/apply_results.mli index bf62d799c485c2cceeedfb3a54a6b36ccc527c77..980e8cda1f629a6c56ffd8a3ad4d75240050f55c 100644 --- a/src/proto_alpha/lib_protocol/apply_results.mli +++ b/src/proto_alpha/lib_protocol/apply_results.mli @@ -141,7 +141,7 @@ and successful_transaction_result = storage : Script.expr option; lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; @@ -167,7 +167,7 @@ and _ successful_manager_operation_result = | Origination_result : { lazy_storage_diff : Lazy_storage.diffs option; balance_updates : Receipt.balance_updates; - originated_contracts : Contract.t list; + originated_contracts : Contract_hash.t list; consumed_gas : Gas.Arith.fp; storage_size : Z.t; paid_storage_size_diff : Z.t; diff --git a/src/proto_alpha/lib_protocol/bootstrap_storage.ml b/src/proto_alpha/lib_protocol/bootstrap_storage.ml index 62a38dae77119498cfab342203158908d4ebb0dc..ce7a64777383033371ced4c3243360916cb36d11 100644 --- a/src/proto_alpha/lib_protocol/bootstrap_storage.ml +++ b/src/proto_alpha/lib_protocol/bootstrap_storage.ml @@ -52,14 +52,14 @@ let init_contract ~typecheck (ctxt, balance_updates) ({delegate; amount; script} : Parameters_repr.bootstrap_contract) = Contract_storage.fresh_contract_from_current_nonce ctxt >>?= fun (ctxt, contract_hash) -> - let contract = Contract_repr.Originated contract_hash in typecheck ctxt script >>=? fun (script, ctxt) -> Contract_storage.raw_originate ctxt ~prepaid_bootstrap_storage:true - contract + contract_hash ~script >>=? fun ctxt -> + let contract = Contract_repr.Originated contract_hash in (match delegate with | None -> return ctxt | Some delegate -> Delegate_storage.init ctxt contract delegate) diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 8fc19e17cc918488050d1abc25e16259c8e2f72b..39c197670228d5474a39a2c2459e71f00c73dc1b 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -405,6 +405,7 @@ let update_script_lazy_storage c = function let raw_originate c ~prepaid_bootstrap_storage (* Free space for bootstrap contracts *) contract ~script = + let contract = Contract_repr.Originated contract in Storage.Contract.Spendable_balance.init c contract Tez_repr.zero >>=? fun c -> let {Script_repr.code; storage}, lazy_storage_diff = script in Storage.Contract.Code.init c contract code >>=? fun (c, code_size) -> diff --git a/src/proto_alpha/lib_protocol/contract_storage.mli b/src/proto_alpha/lib_protocol/contract_storage.mli index 7c92fff7e9f04b19cc2da71d8a5e37d9d73b82bd..ec287ace252ea049ac0cc90ebf314a1287734d2d 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.mli +++ b/src/proto_alpha/lib_protocol/contract_storage.mli @@ -145,7 +145,7 @@ val spend_only_call_from_token : val raw_originate : Raw_context.t -> prepaid_bootstrap_storage:bool -> - Contract_repr.t -> + Contract_hash.t -> script:Script_repr.t * Lazy_storage_diff.diffs option -> Raw_context.t tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml index 8e773910ffb294657d95aca7d6fc146edf0f36f9..4f4d13dfa38ebc7b1bbda76bac8c88d888a15afc 100644 --- a/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml +++ b/src/proto_alpha/lib_protocol/liquidity_baking_migration.ml @@ -112,13 +112,13 @@ let test_fa12_init_storage manager = [] ))) let originate ctxt address_hash ~balance script = - let address = Contract_repr.Originated address_hash in Contract_storage.raw_originate ctxt ~prepaid_bootstrap_storage:true - address + address_hash ~script >>=? fun ctxt -> + let address = Contract_repr.Originated address_hash in Contract_storage.used_storage_space ctxt address >>=? fun size -> Fees_storage.burn_origination_fees ~origin:Protocol_migration @@ -146,7 +146,7 @@ let originate ctxt address_hash ~balance script = let result : Migration_repr.origination_result = { balance_updates; - originated_contracts = [address]; + originated_contracts = [address_hash]; storage_size = size; paid_storage_size_diff = size; } diff --git a/src/proto_alpha/lib_protocol/migration_repr.ml b/src/proto_alpha/lib_protocol/migration_repr.ml index 5d4d513caff1b23713b9e39b8d967309a20215be..0008eed3f77873acb03c695efb68d9c5fde5eee7 100644 --- a/src/proto_alpha/lib_protocol/migration_repr.ml +++ b/src/proto_alpha/lib_protocol/migration_repr.ml @@ -25,7 +25,7 @@ type origination_result = { balance_updates : Receipt_repr.balance_updates; - originated_contracts : Contract_repr.t list; + originated_contracts : Contract_hash.t list; storage_size : Z.t; paid_storage_size_diff : Z.t; } @@ -57,6 +57,9 @@ let origination_result_list_encoding = }) (obj4 (dft "balance_updates" Receipt_repr.balance_updates_encoding []) - (dft "originated_contracts" (list Contract_repr.encoding) []) + (dft + "originated_contracts" + (list Contract_repr.originated_encoding) + []) (dft "storage_size" z Z.zero) (dft "paid_storage_size_diff" z Z.zero))) diff --git a/src/proto_alpha/lib_protocol/migration_repr.mli b/src/proto_alpha/lib_protocol/migration_repr.mli index ea34cb1b7ee6b7498d5e1bfc09e80b4ff709bca8..1fb90c08c0d78c0610ac61a47217acfa13101d76 100644 --- a/src/proto_alpha/lib_protocol/migration_repr.mli +++ b/src/proto_alpha/lib_protocol/migration_repr.mli @@ -31,7 +31,7 @@ *) type origination_result = { balance_updates : Receipt_repr.balance_updates; - originated_contracts : Contract_repr.t list; + originated_contracts : Contract_hash.t list; storage_size : Z.t; paid_storage_size_diff : Z.t; } diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 48703975164b49117fc74b7d3c062656e49535a8..49d2809b34e950f75158c93397fda2f23be4719e 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -92,7 +92,7 @@ module S = Saturation_repr type step_constants = Script_typed_ir.step_constants = { source : Contract.t; payer : Contract.t; - self : Contract.t; + self : Contract_hash.t; amount : Tez.t; balance : Tez.t; chain_id : Chain_id.t; @@ -1040,7 +1040,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = match c with | Contract (Implicit _) | Tx_rollup _ | Sc_rollup _ -> (return_none [@ocaml.tailcall]) ctxt - | Contract (Originated _contract_hash as c) -> ( + | Contract (Originated contract_hash as c) -> ( Contract.get_script ctxt c >>=? fun (ctxt, script_opt) -> match script_opt with | None -> (return_none [@ocaml.tailcall]) ctxt @@ -1106,8 +1106,8 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = (step [@ocaml.tailcall]) ( ctxt, { - source = sc.self; - self = c; + source = Contract.Originated sc.self; + self = contract_hash; amount = Tez.zero; balance; (* The following remain unchanged, but let's @@ -1137,7 +1137,10 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let operation = Delegation delegate in let ctxt = update_context gas ctxt in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> - let piop = Internal_operation {source = sc.self; operation; nonce} in + let piop = + Internal_operation + {source = Contract.Originated sc.self; operation; nonce} + in let res = {piop; lazy_storage_diff = None} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in (step [@ocaml.tailcall]) (ctxt, sc) gas k ks res stack @@ -1188,12 +1191,12 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let res = {destination; entrypoint = Entrypoint.default} in (step [@ocaml.tailcall]) g gas k ks res (accu, stack) | ISelf (_, ty, entrypoint, k) -> - let destination : Destination.t = Contract sc.self in + let destination : Destination.t = Contract (Originated sc.self) in let address = {destination; entrypoint} in let res = Typed_contract {arg_ty = ty; address} in (step [@ocaml.tailcall]) g gas k ks res (accu, stack) | ISelf_address (_, k) -> - let destination : Destination.t = Contract sc.self in + let destination : Destination.t = Contract (Originated sc.self) in let res = {destination; entrypoint = Entrypoint.default} in (step [@ocaml.tailcall]) g gas k ks res (accu, stack) | IAmount (_, k) -> @@ -1249,7 +1252,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = | ISapling_verify_update (_, k) -> ( let transaction = accu in let state, stack = stack in - let address = Contract.to_b58check sc.self in + let address = Contract_hash.to_b58check sc.self in let sc_chain_id = Script_chain_id.make sc.chain_id in let chain_id = Script_chain_id.to_b58check sc_chain_id in let anti_replay = address ^ chain_id in @@ -1269,7 +1272,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = | ISapling_verify_update_deprecated (_, k) -> ( let transaction = accu in let state, stack = stack in - let address = Contract.to_b58check sc.self in + let address = Contract_hash.to_b58check sc.self in let sc_chain_id = Script_chain_id.make sc.chain_id in let chain_id = Script_chain_id.to_b58check sc_chain_id in let anti_replay = address ^ chain_id in @@ -1433,7 +1436,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = (* Tickets *) | ITicket (_, k) -> let contents = accu and amount, stack = stack in - let ticketer = sc.self in + let ticketer = Contract.Originated sc.self in let accu = {ticketer; contents; amount} in (step [@ocaml.tailcall]) g gas k ks accu stack | IRead_ticket (_, k) -> @@ -1729,11 +1732,12 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal entrypoints entrypoint) >>?= fun (r, ctxt) -> - record_trace (Bad_contract_parameter step_constants.self) r + let self_contract = Contract.Originated step_constants.self in + record_trace (Bad_contract_parameter self_contract) r >>?= fun (Ex_ty_cstr {ty = entrypoint_ty; construct; original_type_expr = _}) -> trace - (Bad_contract_parameter step_constants.self) + (Bad_contract_parameter self_contract) (lift_execution_arg ctxt ~internal entrypoint_ty construct arg) >>=? fun (arg, ctxt) -> Script_ir_translator.collect_lazy_storage ctxt arg_type arg @@ -1741,7 +1745,7 @@ let execute_any_arg logger ctxt mode step_constants ~entrypoint ~internal Script_ir_translator.collect_lazy_storage ctxt storage_type old_storage >>?= fun (to_update, ctxt) -> trace - (Runtime_contract_error step_constants.self) + (Runtime_contract_error self_contract) (interp logger (ctxt, step_constants) code (arg, old_storage)) >>=? fun ((ops, new_storage), ctxt) -> Script_ir_translator.extract_lazy_storage_diff diff --git a/src/proto_alpha/lib_protocol/script_interpreter.mli b/src/proto_alpha/lib_protocol/script_interpreter.mli index bd1ddafad9da0ad1bfd10fa358aaa761e8ccd016..28e3a106e61bc237ee28868ac44f8710759b8eac 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.mli +++ b/src/proto_alpha/lib_protocol/script_interpreter.mli @@ -62,7 +62,7 @@ type execution_result = { type step_constants = Script_typed_ir.step_constants = { source : Contract.t; payer : Contract.t; - self : Contract.t; + self : Contract_hash.t; amount : Tez.t; balance : Tez.t; chain_id : Chain_id.t; diff --git a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml index 9aa149aef72aa60e6dafd07deeff1af3bce8b06c..e4b53ba12eede142e6ca2ae6046fc4216357d453 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter_defs.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter_defs.ml @@ -625,7 +625,7 @@ let transfer (ctxt, sc) gas amount location parameters_ty parameters failwith "Transferring to smart-contract rollups is not yet supported") >>=? fun (operation, ctxt) -> fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> - let iop = {source = sc.self; operation; nonce} in + let iop = {source = Contract.Originated sc.self; operation; nonce} in let res = {piop = Internal_operation iop; lazy_storage_diff} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in return (res, ctxt, gas) @@ -664,7 +664,8 @@ let create_contract (ctxt, sc) gas storage_type code delegate credit init = Origination {origination; preorigination; storage_type; storage = init} in fresh_internal_nonce ctxt >>?= fun (ctxt, nonce) -> - let piop = Internal_operation {source = sc.self; operation; nonce} in + let source = Contract.Originated sc.self in + let piop = Internal_operation {source; operation; nonce} in let res = {piop; lazy_storage_diff} in let gas, ctxt = local_gas_counter_and_outdated_context ctxt in return (res, preorigination, ctxt, gas) diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.ml b/src/proto_alpha/lib_protocol/script_typed_ir.ml index 2d474f7207e7a6c1309f8bd2d78f18047d46e731..dd097f86a2320d26edda223490d229c100d5c1f6 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.ml +++ b/src/proto_alpha/lib_protocol/script_typed_ir.ml @@ -43,7 +43,7 @@ type step_constants = { (** The address calling this contract, as returned by SENDER. *) payer : Contract.t; (** The address of the implicit account that initiated the chain of contract calls, as returned by SOURCE. *) - self : Contract.t; + self : Contract_hash.t; (** The address of the contract being executed, as returned by SELF and SELF_ADDRESS. Also used: - as ticketer in TICKET diff --git a/src/proto_alpha/lib_protocol/script_typed_ir.mli b/src/proto_alpha/lib_protocol/script_typed_ir.mli index c6cdfdd5929fb95d75eabd967ef35415ccbae24a..5d1bb7692169eb02b2ef7462d21e12d28d842eb6 100644 --- a/src/proto_alpha/lib_protocol/script_typed_ir.mli +++ b/src/proto_alpha/lib_protocol/script_typed_ir.mli @@ -32,7 +32,7 @@ open Dependent_bool type step_constants = { source : Contract.t; payer : Contract.t; - self : Contract.t; + self : Contract_hash.t; amount : Tez.t; balance : Tez.t; chain_id : Chain_id.t; diff --git a/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml b/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml index c5f774a911925ba24e8660447fbc0db90d2646aa..aced2a46bffc95b270f49313429d27342f469308 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml @@ -67,7 +67,7 @@ let originate_contract file storage src b baker = let fake_KT1 = Contract_hash.of_b58check_exn "KT1FAKEFAKEFAKEFAKEFAKEFAKEFAKGGSE2x" -let default_self = Contract.Originated fake_KT1 +let default_self = fake_KT1 let default_source = Contract.Implicit Signature.Public_key_hash.zero diff --git a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml index d39adf2fcd75d4f8693a42e79669e3ae49e097bf..7ff42e4752ff165f122daba7f022d144dec882c3 100644 --- a/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/michelson/test_interpretation.ml @@ -80,7 +80,7 @@ let test_bad_contract_parameter () = | Error (Environment.Ecoproto_error (Bad_contract_parameter source') :: _) -> Alcotest.(check Testable.contract) "incorrect field in Bad_contract_parameter" - Contract_helpers.default_self + (Contract.Originated Contract_helpers.default_self) source' ; return_unit | Error errs -> diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml index ea16261ab2623c8f41f7ae06cd6c6573c18ed9ef..da6145768a97ea2e2849195cd00a961e6a4f5ef7 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_combined_operations.ml @@ -149,7 +149,9 @@ let test_multiple_origination_and_delegation () = Assert.balance_was_debited ~loc:__LOC__ (I inc) c1 c1_old_balance total_cost >>=? fun () -> List.iter_es - (fun c -> Assert.balance_is ~loc:__LOC__ (I inc) c (Test_tez.of_int 10)) + (fun c -> + let c = Contract.Originated c in + Assert.balance_is ~loc:__LOC__ (I inc) c (Test_tez.of_int 10)) new_contracts let expect_failure = function diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml index 534f32f849e2578c10ac18ab53a278f514f7496e..6a263f9ef1240ab5f1011d21e76c8e83c6ca7664 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_transfer.ml @@ -586,7 +586,7 @@ let test_bad_parameter () = ~equal:( = ) (Environment.Ecoproto_error (Script_interpreter.Bad_contract_parameter - Contract_helpers.default_self)) + (Contract.Originated Contract_helpers.default_self))) lst -> return () | Error errs -> diff --git a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml index 4272ebd3f7b9d92fee294a83b7537000c72f461e..78c42d5fce1b8dc2f4017213e64ce34f8edbd1bf 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_liquidity_baking.ml @@ -359,7 +359,7 @@ let get_lqt_result results = let get_address_in_result result = match result with | Apply_results.Origination_result {originated_contracts; _} -> ( - match originated_contracts with [Originated c] -> c | _ -> assert false) + match originated_contracts with [c] -> c | _ -> assert false) let get_balance_updates_in_result result = match result with