From 30bbc13a4b1eda9f2b0be682ac89aec911558671 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 8 Apr 2022 17:24:19 +0200 Subject: [PATCH 1/6] Proto: expose Contract.t constructors --- src/proto_alpha/lib_protocol/alpha_context.mli | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 3c7f194115b4..9e30d6c9b5c0 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1473,7 +1473,11 @@ module Ticket_hash : sig end module Contract : sig - include BASIC_DATA + type t = private + | Implicit of Signature.Public_key_hash.t + | Originated of Contract_hash.t + + include BASIC_DATA with type t := t val in_memory_size : t -> Cache_memory_helpers.sint -- GitLab From dfdbdf9deba3f63994c4ccbe4d4c26363da60a4d Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Fri, 8 Apr 2022 17:42:36 +0200 Subject: [PATCH 2/6] Proto: remove Contract.is_implicit --- .../lib_client/client_proto_context.ml | 8 +- .../lib_client/client_proto_contracts.ml | 8 +- .../lib_client/client_proto_fa12.ml | 6 +- .../lib_client/client_proto_multisig.ml | 6 +- src/proto_alpha/lib_client/injection.ml | 4 +- .../lib_client/managed_contract.ml | 12 +- .../client_proto_context_commands.ml | 156 +++++++++--------- .../client_proto_fa12_commands.ml | 8 +- .../client_proto_multisig_commands.ml | 52 +++--- .../client_proto_stresstest_contracts.ml | 6 +- .../client_sapling_commands.ml | 9 +- .../lib_protocol/alpha_context.mli | 2 - src/proto_alpha/lib_protocol/apply.ml | 12 +- .../lib_protocol/contract_services.ml | 18 +- .../lib_protocol/script_ir_translator.ml | 13 +- .../lib_protocol/test/helpers/context.ml | 31 ++-- .../test/helpers/contract_helpers.ml | 4 +- .../lib_protocol/ticket_operations_diff.ml | 10 +- 18 files changed, 182 insertions(+), 183 deletions(-) diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index fdbf108f330b..0f7f32ceec28 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -257,21 +257,21 @@ let list_contract_labels cctxt ~chain ~block = Alpha_services.Contract.list cctxt (chain, block) >>=? fun contracts -> List.rev_map_es (fun h -> - (match Contract.is_implicit h with - | Some m -> ( + (match (h : Contract.t) with + | Implicit m -> ( Public_key_hash.rev_find cctxt m >>=? function | None -> return "" | Some nm -> ( RawContractAlias.find_opt cctxt nm >>=? function | None -> return (" (known as " ^ nm ^ ")") | Some _ -> return (" (known as key:" ^ nm ^ ")"))) - | None -> ( + | Originated _ -> ( RawContractAlias.rev_find cctxt h >>=? function | None -> return "" | Some nm -> return (" (known as " ^ nm ^ ")"))) >>=? fun nm -> let kind = - match Contract.is_implicit h with Some _ -> " (implicit)" | None -> "" + match h with Implicit _ -> " (implicit)" | Originated _ -> "" in let h_b58 = Contract.to_b58check h in return (nm, h_b58, kind)) diff --git a/src/proto_alpha/lib_client/client_proto_contracts.ml b/src/proto_alpha/lib_client/client_proto_contracts.ml index 903e0ddd0968..1c54377a64e3 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.ml +++ b/src/proto_alpha/lib_client/client_proto_contracts.ml @@ -54,13 +54,13 @@ module ContractAlias = struct Client_keys.Public_key_hash.find cctxt name >>=? fun v -> return (name, Contract.implicit_contract v) - let rev_find cctxt c = - match Contract.is_implicit c with - | Some hash -> ( + let rev_find cctxt (c : Contract.t) = + match c with + | Implicit hash -> ( Client_keys.Public_key_hash.rev_find cctxt hash >>=? function | Some name -> return_some ("key:" ^ name) | None -> return_none) - | None -> RawContractAlias.rev_find cctxt c + | Originated _ -> RawContractAlias.rev_find cctxt c let get_contract cctxt s = match String.split ~limit:1 ':' s with diff --git a/src/proto_alpha/lib_client/client_proto_fa12.ml b/src/proto_alpha/lib_client/client_proto_fa12.ml index 61be8cf50cc5..89983ce1935b 100644 --- a/src/proto_alpha/lib_client/client_proto_fa12.ml +++ b/src/proto_alpha/lib_client/client_proto_fa12.ml @@ -717,9 +717,9 @@ let contract_has_fa12_interface : unit -> unit tzresult Lwt.t = fun cctxt ~chain ~block ~contract () -> - match Contract.is_implicit contract with - | Some _ -> fail (Contract_has_no_script contract) - | None -> + match contract with + | Implicit _ -> fail (Contract_has_no_script contract) + | Originated _ -> Michelson_v1_entrypoints.list_contract_entrypoints cctxt ~chain diff --git a/src/proto_alpha/lib_client/client_proto_multisig.ml b/src/proto_alpha/lib_client/client_proto_multisig.ml index 41a267cb4e5a..e6fb13365686 100644 --- a/src/proto_alpha/lib_client/client_proto_multisig.ml +++ b/src/proto_alpha/lib_client/client_proto_multisig.ml @@ -614,14 +614,14 @@ type multisig_action = let action_to_expr_generic ~loc = function | Transfer {amount; destination; entrypoint; parameter_type; parameter} -> ( - match Contract.is_implicit destination with - | Some destination -> + match destination with + | Implicit destination -> lambda_from_string @@ Managed_contract.build_lambda_for_transfer_to_implicit ~destination ~amount >|? left ~loc - | None -> + | Originated _ -> lambda_from_string @@ Managed_contract.build_lambda_for_transfer_to_originated ~destination diff --git a/src/proto_alpha/lib_client/injection.ml b/src/proto_alpha/lib_client/injection.ml index 128ba6715bed..15c34c2d8114 100644 --- a/src/proto_alpha/lib_client/injection.ml +++ b/src/proto_alpha/lib_client/injection.ml @@ -784,9 +784,7 @@ let may_patch_limits (type kind) (cctxt : #Protocol_client_context.full) else let safety_guard = match c.operation with - | Transaction {destination = Contract destination; _} - when Option.is_some (Contract.is_implicit destination) -> - Gas.Arith.zero + | Transaction {destination = Contract (Implicit _); _} | Reveal _ | Delegation _ | Set_deposits_limit _ -> Gas.Arith.zero | _ -> safety_guard diff --git a/src/proto_alpha/lib_client/managed_contract.ml b/src/proto_alpha/lib_client/managed_contract.ml index 247af38850ae..d4e5d622f313 100644 --- a/src/proto_alpha/lib_client/managed_contract.ml +++ b/src/proto_alpha/lib_client/managed_contract.ml @@ -227,12 +227,12 @@ let build_lambda_for_transfer_to_originated ~destination ~entrypoint ~amount parameter let build_transaction_operation (cctxt : #full) ~chain ~block ~contract - ~destination ?(entrypoint = Entrypoint.default) ?arg ~amount ?fee ?gas_limit - ?storage_limit () = - (match Alpha_context.Contract.is_implicit destination with - | Some destination when Entrypoint.is_default entrypoint -> + ~(destination : Contract.t) ?(entrypoint = Entrypoint.default) ?arg ~amount + ?fee ?gas_limit ?storage_limit () = + (match destination with + | Implicit destination when Entrypoint.is_default entrypoint -> return @@ build_lambda_for_transfer_to_implicit ~destination ~amount - | Some _ -> + | Implicit _ -> cctxt#error "Implicit accounts have no entrypoints. (targeted entrypoint %%%a on \ contract %a)" @@ -240,7 +240,7 @@ let build_transaction_operation (cctxt : #full) ~chain ~block ~contract entrypoint Contract.pp destination - | None -> + | Originated _ -> (Michelson_v1_entrypoints.contract_entrypoint_type cctxt ~chain diff --git a/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_context_commands.ml index 32e6046fbad7..9cd39bf97cc0 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 @@ -593,14 +593,14 @@ let commands_ro () = @@ ContractAlias.destination_param ~name:"src" ~desc:"source delegate" @@ stop) (fun () (_, contract) (cctxt : Protocol_client_context.full) -> - match Contract.is_implicit contract with - | None -> + match contract with + | Originated _ -> cctxt#error "Cannot change deposits limit on contract %a. This operation is \ invalid on originated contracts." Contract.pp contract - | Some delegate -> ( + | Implicit delegate -> ( get_frozen_deposits_limit cctxt ~chain:cctxt#chain @@ -666,7 +666,8 @@ let force_switch = switch requires --gas-limit, --storage-limit, and --fee." () -let transfer_command amount source destination (cctxt : #Client_context.printer) +let transfer_command amount (source : Contract.t) destination + (cctxt : #Client_context.printer) ( fee, dry_run, verbose_signing, @@ -712,8 +713,8 @@ let transfer_command amount source destination (cctxt : #Client_context.printer) check_force_dependency "--fee" fee else Lwt.return_unit) >>= fun () -> - (match Contract.is_implicit source with - | None -> + (match source with + | Originated _ -> let contract = source in Managed_contract.get_contract_manager cctxt source >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> @@ -740,7 +741,7 @@ let transfer_command amount source destination (cctxt : #Client_context.printer) ?storage_limit ?counter () - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let destination : Alpha_context.Destination.t = Contract destination in transfer @@ -776,7 +777,7 @@ let transfer_command amount source destination (cctxt : #Client_context.printer) | Some (_res, _contracts) -> return_unit let prepare_batch_operation cctxt ?arg ?fee ?gas_limit ?storage_limit - ?entrypoint source index batch = + ?entrypoint (source : Contract.t) index batch = Client_proto_contracts.ContractAlias.find_destination cctxt batch.destination >>=? fun (_, destination) -> tez_of_string_exn index "amount" batch.amount >>=? fun amount -> @@ -787,8 +788,8 @@ let prepare_batch_operation cctxt ?arg ?fee ?gas_limit ?storage_limit let storage_limit = Option.either batch.storage_limit storage_limit in let entrypoint = Option.either batch.entrypoint entrypoint in parse_arg_transfer arg >>=? fun parameters -> - (match Contract.is_implicit source with - | None -> + (match source with + | Originated _ -> Managed_contract.build_transaction_operation cctxt ~chain:cctxt#chain @@ -802,7 +803,7 @@ let prepare_batch_operation cctxt ?arg ?fee ?gas_limit ?storage_limit ?gas_limit ?storage_limit () - | Some _ -> + | Implicit _ -> return (build_transaction_operation ~amount @@ -941,8 +942,8 @@ let commands_rw () = burn_cap; } in - match Contract.is_implicit contract with - | None -> + match contract with + | Originated _ -> Managed_contract.get_contract_manager cctxt contract >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> @@ -968,7 +969,7 @@ let commands_rw () = cctxt errors >>= fun _ -> return_unit - | Some mgr -> + | Implicit mgr -> Client_keys.get_key cctxt mgr >>=? fun (_, src_pk, manager_sk) -> set_delegate cctxt @@ -1022,8 +1023,8 @@ let commands_rw () = burn_cap; } in - match Contract.is_implicit contract with - | None -> + match contract with + | Originated _ -> Managed_contract.get_contract_manager cctxt contract >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> @@ -1048,7 +1049,7 @@ let commands_rw () = cctxt errors >>= fun _ -> return_unit - | Some mgr -> + | Implicit mgr -> Client_keys.get_key cctxt mgr >>=? fun (_, src_pk, manager_sk) -> set_delegate cctxt @@ -1123,11 +1124,11 @@ let commands_rw () = RawContractAlias.of_fresh cctxt force alias_name >>=? fun alias_name -> Lwt.return (Micheline_parser.no_parsing_error program) >>=? fun {expanded = code; _} -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of an origination" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -1259,13 +1260,13 @@ let commands_rw () = with | [] -> failwith "Empty operation list" | operations -> - (match Contract.is_implicit source with - | None -> + (match source with + | Originated _ -> Managed_contract.get_contract_manager cctxt source >>=? fun source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> return (source, src_pk, src_sk) - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> return (source, src_pk, src_sk)) >>=? fun (source, src_pk, src_sk) -> @@ -1445,10 +1446,10 @@ let commands_rw () = global_constant_str (_, source) cctxt -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "Only implicit accounts can register global constants" - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -1590,11 +1591,11 @@ let commands_rw () = force_low_fee, fee_cap, burn_cap ) - (_, source) + (_, (source : Contract.t)) cctxt -> - match Contract.is_implicit source with - | None -> failwith "only implicit accounts can be revealed" - | Some source -> + match source with + | Originated _ -> failwith "only implicit accounts can be revealed" + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -1749,9 +1750,9 @@ let commands_rw () = (_name, source) proposals (cctxt : Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> failwith "only implicit accounts can submit proposals" - | Some src_pkh -> ( + match source with + | Originated _ -> failwith "only implicit accounts can submit proposals" + | Implicit src_pkh -> ( Client_keys.get_key cctxt src_pkh >>=? fun (src_name, _src_pk, src_sk) -> get_period_info @@ -1932,9 +1933,9 @@ let commands_rw () = proposal ballot (cctxt : Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> failwith "only implicit accounts can submit ballot" - | Some src_pkh -> + match source with + | Originated _ -> failwith "only implicit accounts can submit ballot" + | Implicit src_pkh -> Client_keys.get_key cctxt src_pkh >>=? fun (src_name, _src_pk, src_sk) -> get_period_info @@ -2040,15 +2041,15 @@ let commands_rw () = burn_cap; } in - match Contract.is_implicit contract with - | None -> + match contract with + | Originated _ -> cctxt#error "Cannot change deposits limit on contract %a. This operation is \ invalid on originated contracts or unregistered delegate \ contracts." Contract.pp contract - | Some mgr -> + | Implicit mgr -> Client_keys.get_key cctxt mgr >>=? fun (_, src_pk, manager_sk) -> set_deposits_limit cctxt @@ -2104,15 +2105,15 @@ let commands_rw () = burn_cap; } in - match Contract.is_implicit contract with - | None -> + match contract with + | Originated _ -> cctxt#error "Cannot change deposits limit on contract %a. This operation is \ invalid on originated contracts or unregistered delegate \ contracts." Contract.pp contract - | Some mgr -> + | Implicit mgr -> Client_keys.get_key cctxt mgr >>=? fun (_, src_pk, manager_sk) -> set_deposits_limit cctxt @@ -2165,10 +2166,10 @@ let commands_rw () = burn_cap ) (_, source) cctxt -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "Only implicit accounts can originate transaction rollups" - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2244,11 +2245,11 @@ let commands_rw () = tx_rollup (_, source) cctxt -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "Only implicit accounts can submit transaction rollup batches" - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2339,11 +2340,11 @@ let commands_rw () = inbox_merkle_root messages cctxt -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "Only implicit accounts can submit transaction rollup commitments" - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2416,9 +2417,10 @@ let commands_rw () = tx_rollup (_, source) cctxt -> - match Contract.is_implicit source with - | None -> failwith "Only implicit accounts can finalize commitments" - | Some source -> + match source with + | Originated _ -> + failwith "Only implicit accounts can finalize commitments" + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2486,9 +2488,10 @@ let commands_rw () = (_, source) tx_rollup cctxt -> - match Contract.is_implicit source with - | None -> failwith "Only implicit accounts can deposit/recover bonds" - | Some source -> + match source with + | Originated _ -> + failwith "Only implicit accounts can deposit/recover bonds" + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2557,9 +2560,10 @@ let commands_rw () = tx_rollup (_, source) cctxt -> - match Contract.is_implicit source with - | None -> failwith "Only implicit accounts can remove commitments." - | Some source -> + match source with + | Originated _ -> + failwith "Only implicit accounts can remove commitments." + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2682,12 +2686,12 @@ let commands_rw () = proof (_, source) cctxt -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "Only implicit accounts can reject transaction rollup \ commitments." - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2800,12 +2804,12 @@ let commands_rw () = message_result_path tickets_info cctxt -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "Only implicit account can dispatch tickets for a transaction \ rollup." - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2906,9 +2910,10 @@ let commands_rw () = ty (_, ticketer) cctxt -> - match Contract.is_implicit source with - | None -> failwith "Only implicit accounts can transfer tickets." - | Some source -> + match source with + | Originated _ -> + failwith "Only implicit accounts can transfer tickets." + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -2990,11 +2995,11 @@ let commands_rw () = pvm boot_sector cctxt -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "Only implicit accounts can originate smart-contract rollups" - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -3077,9 +3082,10 @@ let commands_rw () = (_, source) rollup cctxt -> - (match Contract.is_implicit source with - | None -> failwith "Only implicit accounts can send messages to rollups" - | Some source -> return source) + (match source with + | Originated _ -> + failwith "Only implicit accounts can send messages to rollups" + | Implicit source -> return source) >>=? fun source -> (match messages with | `Bin message -> return [message] 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 bcba15ba8e5f..292fba90ead4 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 @@ -121,11 +121,11 @@ let view_options = let dummy_callback = Contract.implicit_contract Signature.Public_key_hash.zero -let get_contract_caller_keys cctxt caller = - match Contract.is_implicit caller with - | None -> +let get_contract_caller_keys cctxt (caller : Contract.t) = + match caller with + | Originated _ -> failwith "only implicit accounts can be the source of a contract call" - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, caller_pk, caller_sk) -> return (source, caller_pk, caller_sk) 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 d20ca7fa7de4..1a5e5922deaa 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 @@ -140,13 +140,13 @@ let prepare_command_display prepared_command bytes_only = Signature.Public_key.pp)) prepared_command.Client_proto_multisig.keys -let get_parameter_type (cctxt : #Protocol_client_context.full) ~destination - ~entrypoint = - match Contract.is_implicit destination with - | Some _ -> +let get_parameter_type (cctxt : #Protocol_client_context.full) + ~(destination : Contract.t) ~entrypoint = + match destination with + | Implicit _ -> let open Micheline in return @@ strip_locations @@ Prim (0, Script.T_unit, [], []) - | None -> ( + | Originated _ -> ( Michelson_v1_entrypoints.contract_entrypoint_type cctxt ~chain:cctxt#chain @@ -254,11 +254,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = force alias_name >>=? fun alias_name -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of an origination" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -527,11 +527,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = >>=? fun {expanded = parameter; _} -> get_parameter_type cctxt ~destination ~entrypoint >>=? fun parameter_type -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of a contract call" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -612,11 +612,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = (_, source) signatures (cctxt : #Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of a contract call" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -694,11 +694,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = (_, source) signatures (cctxt : #Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of a contract call" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -768,11 +768,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = (_, source) signatures (cctxt : #Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of a contract call" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { @@ -847,11 +847,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = (_, source) signatures (cctxt : #Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of a contract call" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> List.map_es (fun (pk_uri, _) -> Client_keys.public_key pk_uri) @@ -939,11 +939,11 @@ let commands_rw () : #Protocol_client_context.full Clic.command list = (_, source) signatures (cctxt : #Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of a contract call" - | Some source -> ( + | Implicit source -> ( Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let fee_parameter = { diff --git a/src/proto_alpha/lib_client_commands/client_proto_stresstest_contracts.ml b/src/proto_alpha/lib_client_commands/client_proto_stresstest_contracts.ml index bd7dc3f14371..e1054673e913 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_stresstest_contracts.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_stresstest_contracts.ml @@ -175,10 +175,10 @@ let originate_command = ~desc:"name of the source contract" @@ stop) (fun () (_, source) (cctxt : Protocol_client_context.full) -> - match Contract.is_implicit source with - | None -> + match source with + | Originated _ -> failwith "only implicit accounts can be the source of an origination" - | Some source -> + | Implicit source -> Client_keys.get_key cctxt source >>=? fun (_, src_pk, src_sk) -> let originate_one (scontract : smart_contract) = let fee_parameter = 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 3cf95744a87a..100ea07e6497 100644 --- a/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml +++ b/src/proto_alpha/lib_client_sapling/client_sapling_commands.ml @@ -42,10 +42,11 @@ let group = title = "Commands for working with Sapling transactions"; } -let keys_of_implicit_account cctxt source = - match Protocol.Alpha_context.Contract.is_implicit source with - | None -> assert false - | Some src -> +let keys_of_implicit_account cctxt (source : Protocol.Alpha_context.Contract.t) + = + match source with + | Originated _ -> assert false + | Implicit src -> Client_keys.get_key cctxt src >>=? fun (_, pk, sk) -> return (src, pk, sk) let viewing_key_of_string s = diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 9e30d6c9b5c0..0d37fcb07e88 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1489,8 +1489,6 @@ module Contract : sig val implicit_contract : public_key_hash -> t - val is_implicit : t -> public_key_hash option - val is_originated : t -> Contract_hash.t option val exists : context -> t -> bool Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 376b23108034..5e746ccfecd9 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -939,10 +939,10 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount in (ctxt, result, operations) ) -let apply_transaction ~ctxt ~parameter ~source ~contract ~amount ~entrypoint - ~before_operation ~payer ~chain_id ~mode ~internal = - (match Contract.is_implicit contract with - | None -> +let apply_transaction ~ctxt ~parameter ~source ~(contract : Contract.t) ~amount + ~entrypoint ~before_operation ~payer ~chain_id ~mode ~internal = + (match contract with + | Originated _ -> (if Tez.(amount = zero) then (* Detect potential call to non existent contract. *) Contract.must_exist ctxt contract @@ -951,7 +951,7 @@ let apply_transaction ~ctxt ~parameter ~source ~contract ~amount ~entrypoint (* Since the contract is originated, nothing will be allocated or the next transfer of tokens will fail. *) return_false - | Some _ -> + | Implicit _ -> (* Transfers of zero to implicit accounts are forbidden. *) error_when Tez.(amount = zero) (Empty_transaction contract) >>?= fun () -> (* If the implicit contract is not yet allocated at this point then @@ -1401,7 +1401,7 @@ let apply_external_manager_operation_content : error_when Compare.Z.(amount <= Z.zero) Forbidden_zero_ticket_quantity >>?= fun () -> error_when - (Option.is_some @@ Contract.is_implicit destination) + (match destination with Implicit _ -> true | Originated _ -> false) Cannot_transfer_ticket_to_implicit >>?= fun () -> Tx_rollup_ticket.parse_ticket_and_operation diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_protocol/contract_services.ml index 5c84635f5301..f8548df76106 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_protocol/contract_services.ml @@ -363,18 +363,18 @@ let[@coq_axiom_with_reason "gadt"] register () = S.balance_and_frozen_bonds Contract.get_balance_and_frozen_bonds ; opt_register1 ~chunked:false S.manager_key (fun ctxt contract () () -> - match Contract.is_implicit contract with - | None -> return_none - | Some mgr -> ( + match contract with + | Originated _ -> return_none + | Implicit mgr -> ( Contract.is_manager_key_revealed ctxt mgr >>=? function | false -> return_some None | true -> Contract.get_manager_key ctxt mgr >|=? fun key -> Some (Some key))) ; register_opt_field ~chunked:false S.delegate Delegate.find ; opt_register1 ~chunked:false S.counter (fun ctxt contract () () -> - match Contract.is_implicit contract with - | None -> return_none - | Some mgr -> + match contract with + | Originated _ -> return_none + | Implicit mgr -> Contract.get_counter ctxt mgr >|=? fun counter -> Some counter) ; register_opt_field ~chunked:true S.script (fun c v -> Contract.get_script c v >|=? fun (_, v) -> v) ; @@ -502,11 +502,11 @@ let[@coq_axiom_with_reason "gadt"] register () = (fun ctxt contract {normalize_types} -> Contract.get_balance ctxt contract >>=? fun balance -> Delegate.find ctxt contract >>=? fun delegate -> - (match Contract.is_implicit contract with - | Some manager -> + (match contract with + | Implicit manager -> Contract.get_counter ctxt manager >>=? fun counter -> return_some counter - | None -> return_none) + | Originated _ -> return_none) >>=? fun counter -> Contract.get_script ctxt contract >>=? fun (ctxt, script) -> (match script with diff --git a/src/proto_alpha/lib_protocol/script_ir_translator.ml b/src/proto_alpha/lib_protocol/script_ir_translator.ml index 5100fbce9b32..ecdc6de7df2a 100644 --- a/src/proto_alpha/lib_protocol/script_ir_translator.ml +++ b/src/proto_alpha/lib_protocol/script_ir_translator.ml @@ -4806,8 +4806,8 @@ and[@coq_axiom_with_reason "complex mutually recursive definition"] parse_contra fun ~stack_depth ctxt loc arg destination ~entrypoint -> match destination with | Contract contract -> ( - match Contract.is_implicit contract with - | Some _ -> + match contract with + | Implicit _ -> if Entrypoint.is_default entrypoint then (* An implicit account on the "default" entrypoint always exists and has type unit. *) Lwt.return @@ -4819,8 +4819,7 @@ and[@coq_axiom_with_reason "complex mutually recursive definition"] parse_contra let address = {destination; entrypoint} in (ctxt, Typed_contract {arg_ty = arg; address}) ) else fail (No_such_entrypoint entrypoint) - | None -> ( - (* Originated account *) + | Originated _ -> ( trace (Invalid_contract (loc, contract)) @@ Contract.get_script_code ctxt contract >>=? fun (ctxt, code) -> @@ -4999,8 +4998,8 @@ let parse_contract_for_script : fun ctxt loc arg contract ~entrypoint -> match contract with | Contract contract -> ( - match Contract.is_implicit contract with - | Some _ -> + match contract with + | Implicit _ -> if Entrypoint.is_default entrypoint then (* An implicit account on the "default" entrypoint always exists and has type unit. *) Lwt.return @@ -5019,7 +5018,7 @@ let parse_contract_for_script : >|? fun ctxt -> (* An implicit account on any other entrypoint is not a valid contract. *) (ctxt, None) ) - | None -> ( + | Originated _ -> ( (* Originated account *) trace (Invalid_contract (loc, contract)) @@ Contract.get_script_code ctxt contract diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 1092404a993f..2436fb7479f5 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -264,10 +264,9 @@ module Contract = struct let equal a b = Alpha_context.Contract.compare a b = 0 - let pkh c = - match Alpha_context.Contract.is_implicit c with - | Some p -> p - | None -> Stdlib.failwith "pkh: only for implicit contracts" + let pkh = function + | Contract.Implicit p -> p + | Originated _ -> Stdlib.failwith "pkh: only for implicit contracts" let balance ctxt contract = Alpha_services.Contract.balance rpc_ctxt ctxt contract @@ -278,20 +277,20 @@ module Contract = struct let balance_and_frozen_bonds ctxt contract = Alpha_services.Contract.balance_and_frozen_bonds rpc_ctxt ctxt contract - let counter ctxt contract = - match Contract.is_implicit contract with - | None -> invalid_arg "Helpers.Context.counter" - | Some mgr -> Alpha_services.Contract.counter rpc_ctxt ctxt mgr + let counter ctxt (contract : Contract.t) = + match contract with + | Originated _ -> invalid_arg "Helpers.Context.counter" + | Implicit mgr -> Alpha_services.Contract.counter rpc_ctxt ctxt mgr - let manager _ contract = - match Contract.is_implicit contract with - | None -> invalid_arg "Helpers.Context.manager" - | Some pkh -> Account.find pkh + let manager _ (contract : Contract.t) = + match contract with + | Originated _ -> invalid_arg "Helpers.Context.manager" + | Implicit pkh -> Account.find pkh - let is_manager_key_revealed ctxt contract = - match Contract.is_implicit contract with - | None -> invalid_arg "Helpers.Context.is_manager_key_revealed" - | Some mgr -> + let is_manager_key_revealed ctxt (contract : Contract.t) = + match contract with + | Originated _ -> invalid_arg "Helpers.Context.is_manager_key_revealed" + | Implicit mgr -> Alpha_services.Contract.manager_key rpc_ctxt ctxt mgr >|=? fun res -> res <> None 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 82a78014a6c7..acf671cfed4e 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml @@ -32,9 +32,7 @@ open Error_monad_operators let init () = Context.init3 ~consensus_threshold:0 () >|=? fun (b, (src0, src1, src2)) -> let baker = - match Alpha_context.Contract.is_implicit src0 with - | Some v -> v - | None -> assert false + match src0 with Implicit v -> v | Originated _ -> assert false in (b, baker, src1, src2) diff --git a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml index f38d1aa7c211..5d0038750cea 100644 --- a/src/proto_alpha/lib_protocol/ticket_operations_diff.ml +++ b/src/proto_alpha/lib_protocol/ticket_operations_diff.ml @@ -174,11 +174,11 @@ let cast_transaction_parameter (type a ac b bc) ctxt location >>?= fun (res, ctxt) -> res >>?= fun Script_ir_translator.Eq -> return ((parameters : a), ctxt) -let tickets_of_transaction ctxt ~destination ~entrypoint ~location - ~parameters_ty ~parameters = - match Contract.is_implicit destination with - | Some _ -> return (None, ctxt) - | None -> +let tickets_of_transaction ctxt ~(destination : Contract.t) ~entrypoint + ~location ~parameters_ty ~parameters = + match destination with + | Implicit _ -> return (None, ctxt) + | Originated _ -> (* TODO: #2653 Avoid having to load the script from the cache. This is currently in place to avoid regressions for type-checking -- GitLab From 5fd865e07273be216400557f799ee0421ceb1476 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 13:53:06 +0200 Subject: [PATCH 3/6] Proto: remove Contract_repr.is_implicit --- src/proto_alpha/lib_protocol/contract_repr.ml | 2 - .../lib_protocol/contract_repr.mli | 2 - .../lib_protocol/contract_storage.ml | 55 ++++++++++--------- .../lib_protocol/delegate_storage.ml | 18 +++--- .../test/unit/test_contract_repr.ml | 24 -------- 5 files changed, 37 insertions(+), 64 deletions(-) diff --git a/src/proto_alpha/lib_protocol/contract_repr.ml b/src/proto_alpha/lib_protocol/contract_repr.ml index d6ddf1baefb0..50b0cdb3a3ad 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.ml +++ b/src/proto_alpha/lib_protocol/contract_repr.ml @@ -132,8 +132,6 @@ let () = let implicit_contract id = Implicit id -let is_implicit = function Implicit m -> Some m | Originated _ -> None - let is_originated = function Implicit _ -> None | Originated h -> Some h let originated_contract nonce = diff --git a/src/proto_alpha/lib_protocol/contract_repr.mli b/src/proto_alpha/lib_protocol/contract_repr.mli index ce6a926729fb..9d79d76066f8 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.mli +++ b/src/proto_alpha/lib_protocol/contract_repr.mli @@ -50,8 +50,6 @@ val in_memory_size : t -> Cache_memory_helpers.sint val implicit_contract : Signature.Public_key_hash.t -> t -val is_implicit : t -> Signature.Public_key_hash.t option - (** {2 Originated contracts} *) (** [originated_contract nonce] is the contract address originated from [nonce]. diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 3225ef3ee908..4a4a664e26cb 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -406,9 +406,9 @@ let update_script_lazy_storage c = function let create_base c ~prepaid_bootstrap_storage (* Free space for bootstrap contracts *) contract ~balance ~manager ?script () = - (match Contract_repr.is_implicit contract with - | None -> return c - | Some _ -> + (match contract with + | Contract_repr.Originated _ -> return c + | Implicit _ -> Storage.Contract.Global_counter.get c >>=? fun counter -> Storage.Contract.Counter.init c contract counter) >>=? fun c -> @@ -463,11 +463,11 @@ let create_implicit c manager ~balance = () let delete c contract = - match Contract_repr.is_implicit contract with - | None -> + match contract with + | Contract_repr.Originated _ -> (* For non implicit contract Big_map should be cleared *) failwith "Non implicit contracts cannot be removed" - | Some _ -> + | Implicit _ -> Contract_delegate_storage.unlink c contract >>=? fun c -> Storage.Contract.Spendable_balance.remove_existing c contract >>=? fun c -> @@ -481,9 +481,9 @@ let delete c contract = let allocated c contract = Storage.Contract.Spendable_balance.mem c contract let exists c contract = - match Contract_repr.is_implicit contract with - | Some _ -> Lwt.return_true - | None -> allocated c contract + match contract with + | Contract_repr.Implicit _ -> Lwt.return_true + | Originated _ -> allocated c contract let must_exist c contract = exists c contract >>= function @@ -494,9 +494,9 @@ let must_be_allocated c contract = allocated c contract >>= function | true -> return_unit | false -> ( - match Contract_repr.is_implicit contract with - | Some pkh -> fail (Empty_implicit_contract pkh) - | None -> fail (Non_existing_contract contract)) + match contract with + | Implicit pkh -> fail (Empty_implicit_contract pkh) + | Originated _ -> fail (Non_existing_contract contract)) let list c = Storage.Contract.list c @@ -551,17 +551,17 @@ let get_counter c manager = let contract = Contract_repr.implicit_contract manager in Storage.Contract.Counter.find c contract >>=? function | None -> ( - match Contract_repr.is_implicit contract with - | Some _ -> Storage.Contract.Global_counter.get c - | None -> failwith "get_counter") + match contract with + | Contract_repr.Implicit _ -> Storage.Contract.Global_counter.get c + | Originated _ -> failwith "get_counter") | Some v -> return v let get_balance c contract = Storage.Contract.Spendable_balance.find c contract >>=? function | None -> ( - match Contract_repr.is_implicit contract with - | Some _ -> return Tez_repr.zero - | None -> failwith "get_balance") + match contract with + | Implicit _ -> return Tez_repr.zero + | Originated _ -> failwith "get_balance") | Some v -> return v let get_balance_carbonated c contract = @@ -594,9 +594,9 @@ let spend_only_call_from_token c contract amount = Stake_storage.remove_contract_stake c contract amount >>=? fun c -> if Tez_repr.(new_balance > Tez_repr.zero) then return c else - match Contract_repr.is_implicit contract with - | None -> return c - | Some pkh -> ( + match contract with + | Originated _ -> return c + | Implicit pkh -> ( Contract_delegate_storage.find c contract >>=? function | Some pkh' -> if Signature.Public_key_hash.equal pkh pkh' then return c @@ -611,9 +611,9 @@ let spend_only_call_from_token c contract amount = let credit_only_call_from_token c contract amount = Storage.Contract.Spendable_balance.find c contract >>=? function | None -> ( - match Contract_repr.is_implicit contract with - | None -> fail (Non_existing_contract contract) - | Some manager -> create_implicit c manager ~balance:amount) + match contract with + | Originated _ -> fail (Non_existing_contract contract) + | Implicit manager -> create_implicit c manager ~balance:amount) | Some balance -> Tez_repr.(amount +? balance) >>?= fun balance -> Storage.Contract.Spendable_balance.update c contract balance >>=? fun c -> @@ -712,9 +712,10 @@ let fold_on_bond_ids ctxt contract = Storage.Contract.fold_bond_ids (ctxt, contract) let ensure_deallocated_if_empty ctxt contract = - match Contract_repr.is_implicit contract with - | None -> return ctxt (* Never delete originated contracts *) - | Some _ -> ( + match contract with + | Contract_repr.Originated _ -> + return ctxt (* Never delete originated contracts *) + | Implicit _ -> ( Storage.Contract.Spendable_balance.find ctxt contract >>=? fun balance_opt -> match balance_opt with diff --git a/src/proto_alpha/lib_protocol/delegate_storage.ml b/src/proto_alpha/lib_protocol/delegate_storage.ml index 58e78810f5d5..a4b9ae1d45d3 100644 --- a/src/proto_alpha/lib_protocol/delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_storage.ml @@ -206,11 +206,11 @@ let set c contract delegate = match delegate with | None -> ( (* check if contract is a registered delegate *) - (match Contract_repr.is_implicit contract with - | Some pkh -> + (match contract with + | Contract_repr.Implicit pkh -> Contract_delegate_storage.registered c pkh >>=? fun is_registered -> fail_when is_registered (No_deletion pkh) - | None -> return_unit) + | Originated _ -> return_unit) >>=? fun () -> Contract_delegate_storage.find c contract >>=? function | None -> return c @@ -226,9 +226,9 @@ let set c contract delegate = Contract_delegate_storage.registered c delegate >>=? fun registered_delegate -> let self_delegation = - match Contract_repr.is_implicit contract with - | Some pkh -> Signature.Public_key_hash.equal pkh delegate - | None -> false + match contract with + | Implicit pkh -> Signature.Public_key_hash.equal pkh delegate + | Originated _ -> false in if (not known_delegate) || not (registered_delegate || self_delegation) then fail (Unregistered_delegate delegate) @@ -245,14 +245,14 @@ let set c contract delegate = | None | Some _ -> return_unit) >>=? fun () -> (* check if contract is a registered delegate *) - (match Contract_repr.is_implicit contract with - | Some pkh -> + (match contract with + | Contract_repr.Implicit pkh -> Contract_delegate_storage.registered c pkh >>=? fun is_registered -> (* allow self-delegation to re-activate *) if (not self_delegation) && is_registered then fail (No_deletion pkh) else return_unit - | None -> return_unit) + | Originated _ -> return_unit) >>=? fun () -> Storage.Contract.Spendable_balance.mem c contract >>= fun exists -> error_when diff --git a/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml index 0c0e32855030..7227b8ab3e32 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml @@ -65,20 +65,6 @@ module Test_contract_repr = struct let dummy_originated_contract = originated_contract @@ dummy_origination_nonce - let test_implicit () = - match is_implicit dummy_implicit_contract with - | Some _ -> return_unit - | None -> - failwith - "must have returned the public key hash of implicit contract. \n\ - \ Instead, returned None" - - (** Check if [is_implicit] catches a non-implicit (originated) contract and returns None *) - let test_not_implicit () = - match is_implicit dummy_originated_contract with - | None -> return_unit - | Some _ -> failwith "must have returned the None. Instead, returned Some _" - let test_originated () = match is_originated dummy_originated_contract with | Some _ -> return_unit @@ -128,16 +114,6 @@ end let tests = [ - tztest - "Contract_repr.is_implicit: must correctly identify a valid implicit \ - contract" - `Quick - Test_contract_repr.test_implicit; - tztest - "Contract_repr.is_implicit: must correctly return None for a originated \ - contract" - `Quick - Test_contract_repr.test_not_implicit; tztest "Contract_repr.is_originated: must correctly return operation hash of \ the originated contract" -- GitLab From a37cf13e764caa372f6efcdc9cccfc6ff9fc3afb Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 15:52:20 +0200 Subject: [PATCH 4/6] Proto: remove Contract.is_originated --- .../lib_protocol/alpha_context.mli | 2 -- src/proto_alpha/lib_protocol/contract_repr.ml | 2 -- .../lib_protocol/contract_repr.mli | 2 -- .../test/unit/test_contract_repr.ml | 23 ------------------- 4 files changed, 29 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 0d37fcb07e88..31e1e90af2ac 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1489,8 +1489,6 @@ module Contract : sig val implicit_contract : public_key_hash -> t - val is_originated : t -> Contract_hash.t option - val exists : context -> t -> bool Lwt.t val must_exist : context -> t -> unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/contract_repr.ml b/src/proto_alpha/lib_protocol/contract_repr.ml index 50b0cdb3a3ad..8b7dcd4f4361 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.ml +++ b/src/proto_alpha/lib_protocol/contract_repr.ml @@ -132,8 +132,6 @@ let () = let implicit_contract id = Implicit id -let is_originated = function Implicit _ -> None | Originated h -> Some h - let originated_contract nonce = let data = Data_encoding.Binary.to_bytes_exn Origination_nonce.encoding nonce diff --git a/src/proto_alpha/lib_protocol/contract_repr.mli b/src/proto_alpha/lib_protocol/contract_repr.mli index 9d79d76066f8..b2dae835a60a 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.mli +++ b/src/proto_alpha/lib_protocol/contract_repr.mli @@ -63,8 +63,6 @@ val originated_contract : Origination_nonce.t -> t val originated_contracts : since:Origination_nonce.t -> until:Origination_nonce.t -> t list -val is_originated : t -> Contract_hash.t option - (** {2 Human readable notation} *) type error += Invalid_contract_notation of string (* `Permanent *) diff --git a/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml index 7227b8ab3e32..3430a780e5a0 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml @@ -65,19 +65,6 @@ module Test_contract_repr = struct let dummy_originated_contract = originated_contract @@ dummy_origination_nonce - let test_originated () = - match is_originated dummy_originated_contract with - | Some _ -> return_unit - | None -> - failwith - "must have returned the origination nonce correctly. Instead \ - returned None." - - let test_not_originated () = - match is_originated dummy_implicit_contract with - | None -> return_unit - | Some _ -> failwith "must have returned the None. Instead, returned Some _" - let test_to_b58check_implicit () = Assert.equal ~loc:__LOC__ @@ -114,16 +101,6 @@ end let tests = [ - tztest - "Contract_repr.is_originated: must correctly return operation hash of \ - the originated contract" - `Quick - Test_contract_repr.test_originated; - tztest - "Contract_repr.is_originated: must correctly return None for an implicit \ - contract contract" - `Quick - Test_contract_repr.test_not_originated; tztest "Contract_repr.to_b58check: must correctly stringify, b58check encoded, \ an implicit contract" -- GitLab From 12f7e50d64ffd5310f51a0136411d046923e73f1 Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 15:55:14 +0200 Subject: [PATCH 5/6] Proto: make Contract.t non-private --- src/proto_alpha/lib_protocol/alpha_context.mli | 2 +- src/proto_alpha/lib_protocol/contract_repr.mli | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 31e1e90af2ac..21fda5f4a8ed 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1473,7 +1473,7 @@ module Ticket_hash : sig end module Contract : sig - type t = private + type t = | Implicit of Signature.Public_key_hash.t | Originated of Contract_hash.t diff --git a/src/proto_alpha/lib_protocol/contract_repr.mli b/src/proto_alpha/lib_protocol/contract_repr.mli index b2dae835a60a..f78d795849ca 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.mli +++ b/src/proto_alpha/lib_protocol/contract_repr.mli @@ -38,7 +38,7 @@ used to create it. The owner of the corresponding private key is the holder of the account. An originated contract's hash is derived from its origination nonce (see below). *) -type t = private +type t = | Implicit of Signature.Public_key_hash.t | Originated of Contract_hash.t -- GitLab From bac329dcde0874198d098b5ec610ad79b0b58dcf Mon Sep 17 00:00:00 2001 From: Mehdi Bouaziz Date: Mon, 11 Apr 2022 15:59:59 +0200 Subject: [PATCH 6/6] Proto: remove Contract.implicit dumb constructor --- .../lib_benchmark/michelson_samplers.ml | 5 +- .../interpreter_benchmarks.ml | 6 +- .../lib_benchmarks_proto/ticket_benchmarks.ml | 2 +- .../lib_client/client_proto_context.ml | 2 +- .../lib_client/client_proto_contracts.ml | 8 +-- src/proto_alpha/lib_client/mockup.ml | 2 +- .../lib_client/operation_result.ml | 5 +- .../client_proto_fa12_commands.ml | 2 +- .../client_proto_stresstest_commands.ml | 4 +- .../lib_protocol/alpha_context.mli | 2 - src/proto_alpha/lib_protocol/apply.ml | 26 +++---- .../lib_protocol/bootstrap_storage.ml | 2 +- .../lib_protocol/contract_delegate_storage.ml | 10 +-- .../lib_protocol/contract_manager_storage.ml | 6 +- src/proto_alpha/lib_protocol/contract_repr.ml | 2 - .../lib_protocol/contract_repr.mli | 4 -- .../lib_protocol/contract_services.ml | 16 +---- .../lib_protocol/contract_storage.ml | 8 +-- .../delegate_activation_storage.ml | 14 ++-- .../lib_protocol/delegate_storage.ml | 30 ++++----- .../lib_protocol/frozen_deposits_storage.ml | 4 +- .../lib_protocol/script_interpreter.ml | 2 +- .../lib_protocol/test/helpers/context.ml | 4 +- .../test/helpers/contract_helpers.ml | 2 +- .../test/helpers/lqt_fa12_repr.ml | 2 +- .../lib_protocol/test/helpers/op.ml | 2 +- .../consensus/test_deactivation.ml | 6 +- .../integration/consensus/test_delegation.ml | 62 +++++++++-------- .../consensus/test_double_endorsement.ml | 4 +- .../consensus/test_frozen_deposits.ml | 10 +-- .../test/integration/consensus/test_seed.ml | 4 +- .../michelson/test_interpretation.ml | 4 +- .../integration/operations/test_activation.ml | 22 +++--- .../integration/operations/test_reveal.ml | 8 +-- .../integration/operations/test_transfer.ml | 21 +++--- .../integration/operations/test_voting.ml | 2 +- .../test/integration/test_frozen_bonds.ml | 8 +-- .../test/integration/test_token.ml | 67 +++++++++---------- .../test/pbt/test_tx_rollup_l2_encoding.ml | 4 +- .../test/unit/test_contract_repr.ml | 2 +- .../lib_protocol/test/unit/test_receipt.ml | 5 +- src/proto_alpha/lib_protocol/token.ml | 12 ++-- src/proto_alpha/lib_protocol/token.mli | 2 +- 43 files changed, 184 insertions(+), 231 deletions(-) diff --git a/src/proto_alpha/lib_benchmark/michelson_samplers.ml b/src/proto_alpha/lib_benchmark/michelson_samplers.ml index a480cc3b9894..de5fc7ebf630 100644 --- a/src/proto_alpha/lib_benchmark/michelson_samplers.ml +++ b/src/proto_alpha/lib_benchmark/michelson_samplers.ml @@ -493,8 +493,7 @@ end) let address rng_state = if Base_samplers.uniform_bool rng_state then let contract = - Alpha_context.Contract.implicit_contract - (Crypto_samplers.pkh rng_state) + Alpha_context.Contract.Implicit (Crypto_samplers.pkh rng_state) in { destination = Contract contract; @@ -723,7 +722,7 @@ end) fun ty rng_state -> let contents = value ty rng_state in let ticketer = - Alpha_context.Contract.implicit_contract (Crypto_samplers.pkh rng_state) + Alpha_context.Contract.Implicit (Crypto_samplers.pkh rng_state) in let amount = Michelson_base.nat rng_state in Script_typed_ir.{ticketer; contents; amount} diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index 632fd4831fac..0d6add9c5bc7 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -2673,7 +2673,7 @@ module Registration_section = struct let ticket = { ticketer = - Alpha_context.Contract.implicit_contract + Alpha_context.Contract.Implicit Environment.Signature.Public_key_hash.zero; contents = (); amount = zero; @@ -2862,9 +2862,7 @@ module Registration_section = struct ~cont_and_stack_sampler:(fun _cfg _rng_state -> let open Script_typed_ir in let open Alpha_context in - let zero = - Contract.implicit_contract Signature.Public_key_hash.zero - in + let zero = Contract.Implicit Signature.Public_key_hash.zero in let step_constants = { source = zero; diff --git a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml index 46df2541fd29..236bd10adedd 100644 --- a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml @@ -246,7 +246,7 @@ let () = Registration_helpers.register (module Has_tickets_type_benchmark) let ticket_sampler rng_state = let seed = Base_samplers.uniform_bytes ~nbytes:32 rng_state in let (pkh, _, _) = Signature.generate_key ~algo:Signature.Ed25519 ~seed () in - let ticketer = Alpha_context.Contract.implicit_contract pkh in + let ticketer = Alpha_context.Contract.Implicit pkh in Script_typed_ir. {ticketer; contents = Script_int.zero; amount = Script_int.one_n} diff --git a/src/proto_alpha/lib_client/client_proto_context.ml b/src/proto_alpha/lib_client/client_proto_context.ml index 0f7f32ceec28..717321510f30 100644 --- a/src/proto_alpha/lib_client/client_proto_context.ml +++ b/src/proto_alpha/lib_client/client_proto_context.ml @@ -571,7 +571,7 @@ let inject_activate_operation cctxt ~chain ~block ?confirmations ?dry_run alias Alpha_services.Contract.balance cctxt (chain, block) - (Contract.implicit_contract (Ed25519 pkh)) + (Contract.Implicit (Ed25519 pkh)) >>=? fun balance -> cctxt#message "Account %s (%a) activated with %s%a." diff --git a/src/proto_alpha/lib_client/client_proto_contracts.ml b/src/proto_alpha/lib_client/client_proto_contracts.ml index 1c54377a64e3..11029130b00a 100644 --- a/src/proto_alpha/lib_client/client_proto_contracts.ml +++ b/src/proto_alpha/lib_client/client_proto_contracts.ml @@ -47,12 +47,12 @@ module ContractAlias = struct | Some v -> return (s, v) | None -> ( Client_keys.Public_key_hash.find_opt cctxt s >>=? function - | Some v -> return (s, Contract.implicit_contract v) + | Some v -> return (s, Contract.Implicit v) | None -> failwith "no contract or key named %s" s) let find_key cctxt name = Client_keys.Public_key_hash.find cctxt name >>=? fun v -> - return (name, Contract.implicit_contract v) + return (name, Contract.Implicit v) let rev_find cctxt (c : Contract.t) = match c with @@ -90,7 +90,7 @@ module ContractAlias = struct | ["alias"; alias] -> find cctxt alias | ["key"; text] -> Client_keys.Public_key_hash.find cctxt text >>=? fun v -> - return (s, Contract.implicit_contract v) + return (s, Contract.Implicit v) | _ -> ( find cctxt s >>= function | Ok v -> return v @@ -147,7 +147,7 @@ let list_contracts cctxt = (fun (n, v) -> RawContractAlias.mem cctxt n >>=? fun mem -> let p = if mem then "key:" else "" in - let v' = Contract.implicit_contract v in + let v' = Contract.Implicit v in return (p, n, v')) keys >>=? fun accounts -> return (contracts @ accounts) diff --git a/src/proto_alpha/lib_client/mockup.ml b/src/proto_alpha/lib_client/mockup.ml index d50bccad0a5a..5703c8731297 100644 --- a/src/proto_alpha/lib_client/mockup.ml +++ b/src/proto_alpha/lib_client/mockup.ml @@ -1092,7 +1092,7 @@ module Parsed_account = struct List.iter_s (function | (name, pkh, _pk_opt, Some sk_uri) -> ( - let contract = Contract.implicit_contract pkh in + let contract = Contract.Implicit pkh in Client_proto_context.get_balance rpc_context ~chain:cctxt#chain diff --git a/src/proto_alpha/lib_client/operation_result.ml b/src/proto_alpha/lib_client/operation_result.ml index 9b307d950be3..da71a64bf3ee 100644 --- a/src/proto_alpha/lib_client/operation_result.ml +++ b/src/proto_alpha/lib_client/operation_result.ml @@ -899,10 +899,7 @@ let pp_manager_operation_contents_and_result ppf Format.fprintf ppf "@,%a" - (pp_manager_operation_content - (Contract.implicit_contract source) - false - pp_result) + (pp_manager_operation_content (Contract.Implicit source) false pp_result) (operation, operation_result) ; (match internal_operation_results with | [] -> () 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 292fba90ead4..912444dd68f2 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 @@ -119,7 +119,7 @@ let view_options = payer_arg (unparsing_mode_arg ~default:"Readable") -let dummy_callback = Contract.implicit_contract Signature.Public_key_hash.zero +let dummy_callback = Contract.Implicit Signature.Public_key_hash.zero let get_contract_caller_keys cctxt (caller : Contract.t) = match caller with diff --git a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml index ec3e8bfa1787..d9374dc83d19 100644 --- a/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml +++ b/src/proto_alpha/lib_client_commands/client_proto_stresstest_commands.ml @@ -199,7 +199,7 @@ let transaction_costs_encoding = let destination_to_contract dst = match dst with - | Implicit x -> Contract.implicit_contract x + | Implicit x -> Contract.Implicit x | Originated x -> x.destination let parse_strategy s = @@ -429,7 +429,7 @@ let rec sample_transfer (cctxt : Protocol_client_context.full) chain block Alpha_services.Contract.balance cctxt (chain, block) - (Contract.implicit_contract src.pkh) + (Contract.Implicit src.pkh) >>=? fun tez -> if Tez.(tez = zero) then log Debug (fun () -> diff --git a/src/proto_alpha/lib_protocol/alpha_context.mli b/src/proto_alpha/lib_protocol/alpha_context.mli index 21fda5f4a8ed..0ed90a5b8a0e 100644 --- a/src/proto_alpha/lib_protocol/alpha_context.mli +++ b/src/proto_alpha/lib_protocol/alpha_context.mli @@ -1487,8 +1487,6 @@ module Contract : sig val of_b58check : string -> t tzresult - val implicit_contract : public_key_hash -> t - val exists : context -> t -> bool Lwt.t val must_exist : context -> t -> unit tzresult Lwt.t diff --git a/src/proto_alpha/lib_protocol/apply.ml b/src/proto_alpha/lib_protocol/apply.ml index 5e746ccfecd9..052f177cd8da 100644 --- a/src/proto_alpha/lib_protocol/apply.ml +++ b/src/proto_alpha/lib_protocol/apply.ml @@ -872,7 +872,7 @@ let apply_transaction_to_smart_contract ~ctxt ~source ~contract ~amount let open Script_interpreter in { source; - payer = Contract.implicit_contract payer; + payer = Contract.Implicit payer; self = contract; amount; chain_id; @@ -1056,11 +1056,7 @@ let apply_transaction_to_tx_rollup ~ctxt ~parameters_ty ~parameters ~amount in Tx_rollup_state.get ctxt dst_rollup >>=? fun (ctxt, state) -> Tx_rollup_state.burn_cost ~limit:None state message_size >>?= fun cost -> - Token.transfer - ctxt - (`Contract (Contract.implicit_contract payer)) - `Burned - cost + Token.transfer ctxt (`Contract (Contract.Implicit payer)) `Burned cost >>=? fun (ctxt, balance_updates) -> Tx_rollup_inbox.append_message ctxt dst_rollup state deposit >>=? fun (ctxt, state, paid_storage_size_diff) -> @@ -1267,7 +1263,7 @@ let apply_external_manager_operation_content : tzresult Lwt.t = fun ctxt mode ~source ~chain_id ~gas_consumed_in_precheck operation -> - let source_contract = Contract.implicit_contract source in + let source_contract = Contract.Implicit source in prepare_apply_manager_operation_content ~ctxt ~source:source_contract @@ -1371,7 +1367,7 @@ let apply_external_manager_operation_content : let amount = Tx_rollup_l2_qty.to_z amount in Ticket_balance_key.of_ex_token ctxt - ~owner:(Contract (Contract.implicit_contract claimer)) + ~owner:(Contract (Contract.Implicit claimer)) ticket_token >>=? fun (claimer_ticket_hash, ctxt) -> Tx_rollup_ticket.transfer_ticket_with_hashes @@ -1579,7 +1575,7 @@ let apply_external_manager_operation_content : >>=? fun (ctxt, state, to_slash) -> (match to_slash with | Some pkh -> - let committer = Contract.implicit_contract pkh in + let committer = Contract.Implicit pkh in Tx_rollup_commitment.slash_bond ctxt tx_rollup pkh >>=? fun (ctxt, slashed) -> if slashed then @@ -1725,7 +1721,7 @@ let apply_external_manager_operation_content : Tx_rollup_commitment.slash_bond ctxt tx_rollup commitment.committer >>=? fun (ctxt, slashed) -> (if slashed then - let committer = Contract.implicit_contract commitment.committer in + let committer = Contract.Implicit commitment.committer in let bid = Bond_id.Tx_rollup_bond_id tx_rollup in Token.balance ctxt (`Frozen_bonds (committer, bid)) >>=? fun (ctxt, burn) -> @@ -1855,7 +1851,7 @@ let precheck_manager_contents (type kind) ctxt (op : kind Kind.manager contents) let ctxt = Gas.set_limit ctxt gas_limit in let ctxt_before = ctxt in Fees.check_storage_limit ctxt ~storage_limit >>?= fun () -> - let source_contract = Contract.implicit_contract source in + let source_contract = Contract.Implicit source in Contract.must_be_allocated ctxt source_contract >>=? fun () -> Contract.check_counter_increment ctxt source counter >>=? fun () -> let consume_deserialization_gas = Script.Always in @@ -2009,7 +2005,7 @@ let burn_storage_fees : payer:public_key_hash -> (context * Z.t * kind successful_manager_operation_result) tzresult Lwt.t = fun ctxt smopr ~storage_limit ~payer -> - let payer = `Contract (Contract.implicit_contract payer) in + let payer = `Contract (Contract.Implicit payer) in match smopr with | Transaction_result (Transaction_to_contract_result payload) -> let consumed = payload.paid_storage_size_diff in @@ -2757,7 +2753,7 @@ let punish_delegate ctxt delegate level mistake mk_result ~payload_producer = Token.transfer ctxt `Double_signing_evidence_rewards - (`Contract (Contract.implicit_contract payload_producer)) + (`Contract (Contract.Implicit payload_producer)) reward | Error _ -> (* reward is Tez.zero *) return (ctxt, [])) >|=? fun (ctxt, reward_balance_updates) -> @@ -2969,7 +2965,7 @@ let apply_contents_list (type kind) ctxt chain_id (apply_mode : apply_mode) mode let level = Level.from_raw ctxt level in Nonce.reveal ctxt level nonce >>=? fun ctxt -> let tip = Constants.seed_nonce_revelation_tip ctxt in - let contract = Contract.implicit_contract payload_producer in + let contract = Contract.Implicit payload_producer in Token.transfer ctxt `Revelation_rewards (`Contract contract) tip >|=? fun (ctxt, balance_updates) -> (ctxt, Single_result (Seed_nonce_revelation_result balance_updates)) @@ -2998,7 +2994,7 @@ let apply_contents_list (type kind) ctxt chain_id (apply_mode : apply_mode) mode let src = `Collected_commitments blinded_pkh in Token.allocated ctxt src >>=? fun (ctxt, src_exists) -> fail_unless src_exists (Invalid_activation {pkh}) >>=? fun () -> - let contract = Contract.implicit_contract (Signature.Ed25519 pkh) in + let contract = Contract.Implicit (Signature.Ed25519 pkh) in Token.balance ctxt src >>=? fun (ctxt, amount) -> Token.transfer ctxt src (`Contract contract) amount >>=? fun (ctxt, bupds) -> diff --git a/src/proto_alpha/lib_protocol/bootstrap_storage.ml b/src/proto_alpha/lib_protocol/bootstrap_storage.ml index 3636d5f1793e..df398aca79c9 100644 --- a/src/proto_alpha/lib_protocol/bootstrap_storage.ml +++ b/src/proto_alpha/lib_protocol/bootstrap_storage.ml @@ -26,7 +26,7 @@ let init_account (ctxt, balance_updates) ({public_key_hash; public_key; amount} : Parameters_repr.bootstrap_account) = - let contract = Contract_repr.implicit_contract public_key_hash in + let contract = Contract_repr.Implicit public_key_hash in Token.transfer ~origin:Protocol_migration ctxt diff --git a/src/proto_alpha/lib_protocol/contract_delegate_storage.ml b/src/proto_alpha/lib_protocol/contract_delegate_storage.ml index a4b8bed1a7da..8dbb1063250d 100644 --- a/src/proto_alpha/lib_protocol/contract_delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_delegate_storage.ml @@ -27,7 +27,7 @@ let find = Storage.Contract.Delegate.find (* A delegate is registered if its "implicit account" delegates to itself. *) let registered c delegate = - Storage.Contract.Delegate.find c (Contract_repr.implicit_contract delegate) + Storage.Contract.Delegate.find c (Contract_repr.Implicit delegate) >|=? function | Some current_delegate -> Signature.Public_key_hash.equal delegate current_delegate @@ -35,14 +35,14 @@ let registered c delegate = let init ctxt contract delegate = Storage.Contract.Delegate.init ctxt contract delegate >>=? fun ctxt -> - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Storage.Contract.Delegated.add (ctxt, delegate_contract) contract >|= ok let unlink ctxt contract = Storage.Contract.Delegate.find ctxt contract >>=? function | None -> return ctxt | Some delegate -> - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Storage.Contract.Delegated.remove (ctxt, delegate_contract) contract >|= ok @@ -53,9 +53,9 @@ let delete ctxt contract = let set ctxt contract delegate = unlink ctxt contract >>=? fun ctxt -> Storage.Contract.Delegate.add ctxt contract delegate >>= fun ctxt -> - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Storage.Contract.Delegated.add (ctxt, delegate_contract) contract >|= ok let delegated_contracts ctxt delegate = - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Storage.Contract.Delegated.elements (ctxt, contract) diff --git a/src/proto_alpha/lib_protocol/contract_manager_storage.ml b/src/proto_alpha/lib_protocol/contract_manager_storage.ml index 71bf78b566a0..f1785234da5c 100644 --- a/src/proto_alpha/lib_protocol/contract_manager_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_manager_storage.ml @@ -109,14 +109,14 @@ let () = let init = Storage.Contract.Manager.init let is_manager_key_revealed c manager = - let contract = Contract_repr.implicit_contract manager in + let contract = Contract_repr.Implicit manager in Storage.Contract.Manager.find c contract >>=? function | None -> return_false | Some (Manager_repr.Hash _) -> return_false | Some (Manager_repr.Public_key _) -> return_true let reveal_manager_key c manager public_key = - let contract = Contract_repr.implicit_contract manager in + let contract = Contract_repr.Implicit manager in Storage.Contract.Manager.get c contract >>=? function | Public_key _ -> fail (Previously_revealed_key contract) | Hash v -> @@ -130,7 +130,7 @@ let reveal_manager_key c manager public_key = {public_key; expected_hash = v; provided_hash = actual_hash}) let get_manager_key ?error ctxt pkh = - let contract = Contract_repr.implicit_contract pkh in + let contract = Contract_repr.Implicit pkh in Storage.Contract.Manager.find ctxt contract >>=? function | None -> ( match error with diff --git a/src/proto_alpha/lib_protocol/contract_repr.ml b/src/proto_alpha/lib_protocol/contract_repr.ml index 8b7dcd4f4361..038143560ba3 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.ml +++ b/src/proto_alpha/lib_protocol/contract_repr.ml @@ -130,8 +130,6 @@ let () = (function Invalid_contract_notation loc -> Some loc | _ -> None) (fun loc -> Invalid_contract_notation loc) -let implicit_contract id = Implicit id - let originated_contract nonce = let data = Data_encoding.Binary.to_bytes_exn Origination_nonce.encoding nonce diff --git a/src/proto_alpha/lib_protocol/contract_repr.mli b/src/proto_alpha/lib_protocol/contract_repr.mli index f78d795849ca..a818e5654e77 100644 --- a/src/proto_alpha/lib_protocol/contract_repr.mli +++ b/src/proto_alpha/lib_protocol/contract_repr.mli @@ -46,10 +46,6 @@ include Compare.S with type t := t val in_memory_size : t -> Cache_memory_helpers.sint -(** {2 Implicit contracts} *) - -val implicit_contract : Signature.Public_key_hash.t -> t - (** {2 Originated contracts} *) (** [originated_contract nonce] is the contract address originated from [nonce]. diff --git a/src/proto_alpha/lib_protocol/contract_services.ml b/src/proto_alpha/lib_protocol/contract_services.ml index f8548df76106..07f0b1c454bd 100644 --- a/src/proto_alpha/lib_protocol/contract_services.ml +++ b/src/proto_alpha/lib_protocol/contract_services.ml @@ -539,13 +539,7 @@ let balance_and_frozen_bonds ctxt block contract = RPC_context.make_call1 S.balance_and_frozen_bonds ctxt block contract () () let manager_key ctxt block mgr = - RPC_context.make_call1 - S.manager_key - ctxt - block - (Contract.implicit_contract mgr) - () - () + RPC_context.make_call1 S.manager_key ctxt block (Contract.Implicit mgr) () () let delegate ctxt block contract = RPC_context.make_call1 S.delegate ctxt block contract () () @@ -554,13 +548,7 @@ let delegate_opt ctxt block contract = RPC_context.make_opt_call1 S.delegate ctxt block contract () () let counter ctxt block mgr = - RPC_context.make_call1 - S.counter - ctxt - block - (Contract.implicit_contract mgr) - () - () + RPC_context.make_call1 S.counter ctxt block (Contract.Implicit mgr) () () let script ctxt block contract = RPC_context.make_call1 S.script ctxt block contract () () diff --git a/src/proto_alpha/lib_protocol/contract_storage.ml b/src/proto_alpha/lib_protocol/contract_storage.ml index 4a4a664e26cb..9ce34d750ceb 100644 --- a/src/proto_alpha/lib_protocol/contract_storage.ml +++ b/src/proto_alpha/lib_protocol/contract_storage.ml @@ -456,7 +456,7 @@ let create_implicit c manager ~balance = create_base c ~prepaid_bootstrap_storage:false - (Contract_repr.implicit_contract manager) + (Contract_repr.Implicit manager) ~balance ~manager:(Some manager) ?script:None @@ -513,7 +513,7 @@ let originated_from_current_nonce ~since:ctxt_since ~until:ctxt_until = >|= ok let check_counter_increment c manager counter = - let contract = Contract_repr.implicit_contract manager in + let contract = Contract_repr.Implicit manager in Storage.Contract.Counter.get c contract >>=? fun contract_counter -> let expected = Z.succ contract_counter in if Compare.Z.(expected = counter) then return_unit @@ -522,7 +522,7 @@ let check_counter_increment c manager counter = else fail (Counter_in_the_future (contract, expected, counter)) let increment_counter c manager = - let contract = Contract_repr.implicit_contract manager in + let contract = Contract_repr.Implicit manager in Storage.Contract.Global_counter.get c >>=? fun global_counter -> Storage.Contract.Global_counter.update c (Z.succ global_counter) >>=? fun c -> Storage.Contract.Counter.get c contract >>=? fun contract_counter -> @@ -548,7 +548,7 @@ let get_storage ctxt contract = return (ctxt, Some storage) let get_counter c manager = - let contract = Contract_repr.implicit_contract manager in + let contract = Contract_repr.Implicit manager in Storage.Contract.Counter.find c contract >>=? function | None -> ( match contract with diff --git a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml index 296502f80389..e7aead3a4515 100644 --- a/src/proto_alpha/lib_protocol/delegate_activation_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_activation_storage.ml @@ -24,15 +24,13 @@ (*****************************************************************************) let is_inactive ctxt delegate = - Storage.Contract.Inactive_delegate.mem - ctxt - (Contract_repr.implicit_contract delegate) + Storage.Contract.Inactive_delegate.mem ctxt (Contract_repr.Implicit delegate) >>= fun inactive -> if inactive then return inactive else Storage.Contract.Delegate_last_cycle_before_deactivation.find ctxt - (Contract_repr.implicit_contract delegate) + (Contract_repr.Implicit delegate) >|=? function | Some last_active_cycle -> let ({Level_repr.cycle = current_cycle; _} : Level_repr.t) = @@ -45,13 +43,11 @@ let is_inactive ctxt delegate = false let last_cycle_before_deactivation ctxt delegate = - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Storage.Contract.Delegate_last_cycle_before_deactivation.get ctxt contract let set_inactive ctxt delegate = - Storage.Contract.Inactive_delegate.add - ctxt - (Contract_repr.implicit_contract delegate) + Storage.Contract.Inactive_delegate.add ctxt (Contract_repr.Implicit delegate) let set_active ctxt delegate = is_inactive ctxt delegate >>=? fun inactive -> @@ -63,7 +59,7 @@ let set_active ctxt delegate = - if the delegate is new or inactive, we give it additionally `preserved_cycles` because the delegate needs this number of cycles to receive rights, so `1 + 2 * preserved_cycles` in total. *) - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Storage.Contract.Delegate_last_cycle_before_deactivation.find ctxt delegate_contract diff --git a/src/proto_alpha/lib_protocol/delegate_storage.ml b/src/proto_alpha/lib_protocol/delegate_storage.ml index a4b9ae1d45d3..a82e2fcd8363 100644 --- a/src/proto_alpha/lib_protocol/delegate_storage.ml +++ b/src/proto_alpha/lib_protocol/delegate_storage.ml @@ -273,12 +273,12 @@ let set c contract delegate = let frozen_deposits_limit ctxt delegate = Storage.Contract.Frozen_deposits_limit.find ctxt - (Contract_repr.implicit_contract delegate) + (Contract_repr.Implicit delegate) let set_frozen_deposits_limit ctxt delegate limit = Storage.Contract.Frozen_deposits_limit.add_or_remove ctxt - (Contract_repr.implicit_contract delegate) + (Contract_repr.Implicit delegate) limit let update_activity ctxt last_cycle = @@ -346,7 +346,7 @@ let distribute_endorsing_rewards ctxt last_cycle unrevealed_nonces = Stake_storage.get_selected_distribution ctxt last_cycle >>=? fun delegates -> List.fold_left_es (fun (ctxt, balance_updates) (delegate, active_stake) -> - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in delegate_participated_enough ctxt delegate_contract >>=? fun sufficient_participation -> let has_revealed_nonces = @@ -463,7 +463,7 @@ let freeze_deposits ?(origin = Receipt_repr.Block_application) ctxt ~new_cycle (* Here we make sure to preserve the following invariant : maximum_stake_to_be_deposited <= frozen_deposits + balance See select_distribution_for_cycle *) - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Frozen_deposits_storage.update_initial_amount ctxt delegate_contract @@ -513,7 +513,7 @@ let freeze_deposits ?(origin = Receipt_repr.Block_application) ctxt ~new_cycle and therefore it should have no frozen deposits. *) Signature.Public_key_hash.Set.fold_es (fun delegate (ctxt, balance_updates) -> - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Frozen_deposits_storage.update_initial_amount ctxt delegate_contract @@ -579,7 +579,7 @@ let get_stakes_for_selected_index ctxt index = ctxt ~index ~f:(fun (delegate, staking_balance) (acc, total_stake) -> - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in let open Tez_repr in let open Lwt_result_syntax in let* frozen_deposits_limit = @@ -683,15 +683,15 @@ let cycle_end ctxt last_cycle unrevealed_nonces = return (ctxt, balance_updates, deactivated_delagates) let balance ctxt delegate = - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Storage.Contract.Spendable_balance.get ctxt contract let frozen_deposits ctxt delegate = - Frozen_deposits_storage.get ctxt (Contract_repr.implicit_contract delegate) + Frozen_deposits_storage.get ctxt (Contract_repr.Implicit delegate) let full_balance ctxt delegate = frozen_deposits ctxt delegate >>=? fun frozen_deposits -> - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Contract_storage.get_balance_and_frozen_bonds ctxt delegate_contract >>=? fun balance_and_frozen_bonds -> Lwt.return @@ -813,7 +813,7 @@ let already_slashed_for_double_baking ctxt delegate (level : Level_repr.t) = | Some slashed -> return slashed.for_double_baking let punish_double_endorsing ctxt delegate (level : Level_repr.t) = - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Frozen_deposits_storage.get ctxt delegate_contract >>=? fun frozen_deposits -> let slashing_ratio : Ratio_repr.t = Constants_storage.ratio_of_frozen_deposits_slashed_per_double_endorsement @@ -851,7 +851,7 @@ let punish_double_endorsing ctxt delegate (level : Level_repr.t) = >>= fun ctxt -> return (ctxt, amount_to_burn, balance_updates) let punish_double_baking ctxt delegate (level : Level_repr.t) = - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in Frozen_deposits_storage.get ctxt delegate_contract >>=? fun frozen_deposits -> let slashing_for_one_block = Constants_storage.double_baking_punishment ctxt @@ -890,7 +890,7 @@ let record_endorsing_participation ctxt ~delegate ~participation match participation with | Participated -> set_active ctxt delegate | Didn't_participate -> ( - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Storage.Contract.Missed_endorsements.find ctxt contract >>=? function | Some {remaining_slots; missed_levels} -> let remaining_slots = remaining_slots - endorsing_power in @@ -940,7 +940,7 @@ let record_baking_activity_and_pay_rewards_and_fees ctxt ~payload_producer else return ctxt) >>=? fun ctxt -> let pay_payload_producer ctxt delegate = - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Token.balance ctxt `Block_fees >>=? fun (ctxt, block_fees) -> Token.transfer_n ctxt @@ -948,7 +948,7 @@ let record_baking_activity_and_pay_rewards_and_fees ctxt ~payload_producer (`Contract contract) in let pay_block_producer ctxt delegate bonus = - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Token.transfer ctxt `Baking_bonuses (`Contract contract) bonus in pay_payload_producer ctxt payload_producer @@ -1014,7 +1014,7 @@ let delegate_participation_info ctxt delegate = let expected_endorsing_rewards = Tez_repr.mul_exn endorsing_reward_per_slot expected_cycle_activity in - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Storage.Contract.Missed_endorsements.find ctxt contract >>=? fun missed_endorsements -> let (missed_slots, missed_levels, remaining_allowed_missed_slots) = diff --git a/src/proto_alpha/lib_protocol/frozen_deposits_storage.ml b/src/proto_alpha/lib_protocol/frozen_deposits_storage.ml index 99a9fb136390..7dc89b2e24f3 100644 --- a/src/proto_alpha/lib_protocol/frozen_deposits_storage.ml +++ b/src/proto_alpha/lib_protocol/frozen_deposits_storage.ml @@ -26,7 +26,7 @@ let init ctxt delegate = Storage.Contract.Frozen_deposits.init ctxt - (Contract_repr.implicit_contract delegate) + (Contract_repr.Implicit delegate) {initial_amount = Tez_repr.zero; current_amount = Tez_repr.zero} let allocated = Storage.Contract.Frozen_deposits.mem @@ -36,7 +36,7 @@ let get = Storage.Contract.Frozen_deposits.get let find = Storage.Contract.Frozen_deposits.find let update_balance ctxt delegate f amount = - let delegate_contract = Contract_repr.implicit_contract delegate in + let delegate_contract = Contract_repr.Implicit delegate in get ctxt delegate_contract >>=? fun frozen_deposits -> f frozen_deposits.current_amount amount >>?= fun new_amount -> Storage.Contract.Frozen_deposits.update diff --git a/src/proto_alpha/lib_protocol/script_interpreter.ml b/src/proto_alpha/lib_protocol/script_interpreter.ml index 7165051cb6dd..0b837ff570ac 100644 --- a/src/proto_alpha/lib_protocol/script_interpreter.ml +++ b/src/proto_alpha/lib_protocol/script_interpreter.ml @@ -1029,7 +1029,7 @@ and step : type a s b t r f. (a, s, b, t, r, f) step_type = let arg_ty = unit_t in let address = { - destination = Contract (Contract.implicit_contract key); + destination = Contract (Contract.Implicit key); entrypoint = Entrypoint.default; } in diff --git a/src/proto_alpha/lib_protocol/test/helpers/context.ml b/src/proto_alpha/lib_protocol/test/helpers/context.ml index 2436fb7479f5..807fe29bd939 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/context.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/context.ml @@ -402,7 +402,7 @@ let init_gen tup ?rng_state ?commitments ?(initial_balances = []) let accounts = Account.generate_accounts ?rng_state ~initial_balances n in let contracts = List.map - (fun (a, _) -> Alpha_context.Contract.implicit_contract Account.(a.pkh)) + (fun (a, _) -> Alpha_context.Contract.Implicit Account.(a.pkh)) accounts in Block.genesis @@ -439,7 +439,7 @@ let init_with_constants_gen tup constants = let accounts = Account.generate_accounts n in let contracts = List.map - (fun (a, _) -> Alpha_context.Contract.implicit_contract Account.(a.pkh)) + (fun (a, _) -> Alpha_context.Contract.Implicit Account.(a.pkh)) accounts in let open Tezos_protocol_alpha_parameters in 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 acf671cfed4e..a462c485afd6 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/contract_helpers.ml @@ -57,7 +57,7 @@ let originate_contract file storage src b baker = Incremental.add_operation incr operation >>=? fun incr -> Incremental.finalize_block incr >|=? fun b -> (dst, b) -let default_source = Contract.implicit_contract Signature.Public_key_hash.zero +let default_source = Contract.Implicit Signature.Public_key_hash.zero let default_step_constants = Script_interpreter. diff --git a/src/proto_alpha/lib_protocol/test/helpers/lqt_fa12_repr.ml b/src/proto_alpha/lib_protocol/test/helpers/lqt_fa12_repr.ml index 8cdfa341d05c..7dc62faa10e5 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/lqt_fa12_repr.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/lqt_fa12_repr.ml @@ -135,7 +135,7 @@ module Storage = struct { tokens = Big_map.Id.parse_z Z.zero; allowances = Big_map.Id.parse_z Z.one; - admin = Contract.implicit_contract Signature.Public_key_hash.zero; + admin = Contract.Implicit Signature.Public_key_hash.zero; totalSupply = Z.zero; } diff --git a/src/proto_alpha/lib_protocol/test/helpers/op.ml b/src/proto_alpha/lib_protocol/test/helpers/op.ml index efd574bc1567..ecfc414634ce 100644 --- a/src/proto_alpha/lib_protocol/test/helpers/op.ml +++ b/src/proto_alpha/lib_protocol/test/helpers/op.ml @@ -279,7 +279,7 @@ let manager_operation ?counter ?(fee = Tez.zero) ?gas_limit ?storage_limit let revelation ?(fee = Tez.zero) ctxt public_key = let pkh = Signature.Public_key.hash public_key in - let source = Contract.implicit_contract pkh in + let source = Contract.Implicit pkh in Context.Contract.counter ctxt source >>=? fun counter -> Context.Contract.manager ctxt source >|=? fun account -> let counter = Z.succ counter in diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml index 84544c955cbc..ff2329138240 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_deactivation.ml @@ -210,7 +210,7 @@ let test_deactivation_then_empty_then_self_delegation () = (* empty the contract *) Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> let sink_account = Account.new_account () in - let sink_contract = Contract.implicit_contract sink_account.pkh in + let sink_contract = Contract.Implicit sink_account.pkh in Context.get_constants (B b) >>=? fun {parametric = {origination_size; cost_per_byte; _}; _} -> cost_per_byte *? Int64.of_int origination_size >>?= fun origination_burn -> @@ -249,7 +249,7 @@ let test_deactivation_then_empty_then_self_delegation_then_recredit () = (* empty the contract *) Context.Contract.balance (B b) deactivated_contract >>=? fun balance -> let sink_account = Account.new_account () in - let sink_contract = Contract.implicit_contract sink_account.pkh in + let sink_contract = Contract.Implicit sink_account.pkh in Context.get_constants (B b) >>=? fun {parametric = {origination_size; cost_per_byte; _}; _} -> cost_per_byte *? Int64.of_int origination_size >>?= fun origination_burn -> @@ -297,7 +297,7 @@ let test_delegation () = Account.add_account m3 ; Context.Contract.manager (B b) a1 >>=? fun m1 -> Context.Contract.manager (B b) a2 >>=? fun m2 -> - let a3 = Contract.implicit_contract m3.pkh in + let a3 = Contract.Implicit m3.pkh in Context.Contract.delegate_opt (B b) a1 >>=? fun delegate -> (match delegate with | None -> assert false diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml index 2810de0eb97e..a92324b2a502 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_delegation.ml @@ -130,7 +130,7 @@ let delegate_can_be_changed_from_unregistered_contract ~fee () = Context.init2 () >>=? fun (b, (bootstrap0, bootstrap1)) -> let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let unregistered = Contract.implicit_contract unregistered_pkh in + let unregistered = Contract.Implicit unregistered_pkh in Incremental.begin_construction b >>=? fun i -> Context.Contract.manager (I i) bootstrap0 >>=? fun manager0 -> Context.Contract.manager (I i) bootstrap1 >>=? fun manager1 -> @@ -163,7 +163,7 @@ let delegate_can_be_removed_from_unregistered_contract ~fee () = Context.init1 () >>=? fun (b, bootstrap) -> let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let unregistered = Contract.implicit_contract unregistered_pkh in + let unregistered = Contract.Implicit unregistered_pkh in Incremental.begin_construction b >>=? fun i -> Context.Contract.manager (I i) bootstrap >>=? fun manager -> let credit = of_int 10 in @@ -196,7 +196,7 @@ let bootstrap_manager_already_registered_delegate ~fee () = Incremental.begin_construction b >>=? fun i -> Context.Contract.manager (I i) bootstrap >>=? fun manager -> let pkh = manager.pkh in - let impl_contract = Contract.implicit_contract pkh in + let impl_contract = Contract.Implicit pkh in Context.Contract.balance (I i) impl_contract >>=? fun balance -> Op.delegation ~fee (I i) impl_contract (Some pkh) >>=? fun sec_reg -> if fee > balance then expect_too_low_balance_error i sec_reg @@ -466,7 +466,7 @@ let test_unregistered_delegate_key_init_delegation ~fee () = Incremental.begin_construction b >>=? fun i -> let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* initial credit for the delegated contract *) @@ -504,7 +504,7 @@ let test_unregistered_delegate_key_switch_delegation ~fee () = let bootstrap_pkh = Context.Contract.pkh bootstrap in let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* initial credit for the delegated contract *) @@ -543,7 +543,7 @@ let test_unregistered_delegate_key_init_origination_credit ~fee ~amount () = Incremental.begin_construction b >>=? fun i -> let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in (* credit + check balance *) Op.transaction ~fee:Tez.zero (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -580,7 +580,7 @@ let test_unregistered_delegate_key_init_delegation_credit ~fee ~amount () = Incremental.begin_construction b >>=? fun i -> let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) @@ -621,7 +621,7 @@ let test_unregistered_delegate_key_switch_delegation_credit ~fee ~amount () = let bootstrap_pkh = Context.Contract.pkh bootstrap in let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) @@ -667,7 +667,7 @@ let test_unregistered_delegate_key_init_origination_credit_debit ~fee ~amount () Incremental.begin_construction b >>=? fun i -> let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in (* credit + check balance *) Op.transaction (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -709,7 +709,7 @@ let test_unregistered_delegate_key_init_delegation_credit_debit ~amount ~fee () Incremental.begin_construction b >>=? fun i -> let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) @@ -755,7 +755,7 @@ let test_unregistered_delegate_key_switch_delegation_credit_debit ~fee ~amount let bootstrap_pkh = Context.Contract.pkh bootstrap in let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in let unregistered_delegate_account = Account.new_account () in let unregistered_delegate_pkh = Account.(unregistered_delegate_account.pkh) in (* credit + check balance *) @@ -804,7 +804,7 @@ let test_failed_self_delegation_no_transaction () = Incremental.begin_construction b >>=? fun i -> let account = Account.new_account () in let unregistered_pkh = Account.(account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in (* check balance *) Context.Contract.balance (I i) impl_contract >>=? fun balance -> Assert.equal_tez ~loc:__LOC__ Tez.zero balance >>=? fun _ -> @@ -822,7 +822,7 @@ let test_failed_self_delegation_emptied_implicit_contract amount () = Incremental.begin_construction b >>=? fun i -> let account = Account.new_account () in let unregistered_pkh = Account.(account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in (* credit implicit contract and check balance *) Op.transaction (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -848,7 +848,7 @@ let test_emptying_delegated_implicit_contract_fails amount () = Context.Contract.manager (I i) bootstrap >>=? fun bootstrap_manager -> let account = Account.new_account () in let unregistered_pkh = Account.(account.pkh) in - let impl_contract = Contract.implicit_contract unregistered_pkh in + let impl_contract = Contract.Implicit unregistered_pkh in (* credit unregistered implicit contract and check balance *) Op.transaction (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -882,7 +882,7 @@ let test_valid_delegate_registration_init_delegation_credit amount () = Incremental.begin_construction b >>=? fun i -> let delegate_account = Account.new_account () in let delegate_pkh = Account.(delegate_account.pkh) in - let impl_contract = Contract.implicit_contract delegate_pkh in + let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ + check balance *) Op.transaction (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -897,7 +897,7 @@ let test_valid_delegate_registration_init_delegation_credit amount () = (* create an implicit contract with no delegate *) let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let delegator = Contract.implicit_contract unregistered_pkh in + let delegator = Contract.Implicit unregistered_pkh in Op.transaction ~fee:Tez.zero (I i) bootstrap delegator Tez.one >>=? fun credit_contract -> Incremental.add_operation i credit_contract >>=? fun i -> @@ -925,7 +925,7 @@ let test_valid_delegate_registration_switch_delegation_credit amount () = Incremental.begin_construction b >>=? fun i -> let delegate_account = Account.new_account () in let delegate_pkh = Account.(delegate_account.pkh) in - let impl_contract = Contract.implicit_contract delegate_pkh in + let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ + check balance *) Op.transaction (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -940,7 +940,7 @@ let test_valid_delegate_registration_switch_delegation_credit amount () = (* create an implicit contract with bootstrap's account as delegate *) let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let delegator = Contract.implicit_contract unregistered_pkh in + let delegator = Contract.Implicit unregistered_pkh in Op.transaction ~fee:Tez.zero (I i) bootstrap delegator Tez.one >>=? fun credit_contract -> Incremental.add_operation i credit_contract >>=? fun i -> @@ -966,7 +966,7 @@ let test_valid_delegate_registration_init_delegation_credit_debit amount () = Incremental.begin_construction b >>=? fun i -> let delegate_account = Account.new_account () in let delegate_pkh = Account.(delegate_account.pkh) in - let impl_contract = Contract.implicit_contract delegate_pkh in + let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ+ check balance *) Op.transaction (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -991,7 +991,7 @@ let test_valid_delegate_registration_init_delegation_credit_debit amount () = (* create an implicit contract with no delegate *) let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let delegator = Contract.implicit_contract unregistered_pkh in + let delegator = Contract.Implicit unregistered_pkh in Op.transaction ~fee:Tez.zero (I i) bootstrap delegator Tez.one >>=? fun credit_contract -> Incremental.add_operation i credit_contract >>=? fun i -> @@ -1020,7 +1020,7 @@ let test_valid_delegate_registration_switch_delegation_credit_debit amount () = Incremental.begin_construction b >>=? fun i -> let delegate_account = Account.new_account () in let delegate_pkh = Account.(delegate_account.pkh) in - let impl_contract = Contract.implicit_contract delegate_pkh in + let impl_contract = Contract.Implicit delegate_pkh in (* credit > 0ꜩ + check balance *) Op.transaction (I i) bootstrap impl_contract amount >>=? fun create_contract -> @@ -1042,7 +1042,7 @@ let test_valid_delegate_registration_switch_delegation_credit_debit amount () = (* create an implicit contract with bootstrap's account as delegate *) let unregistered_account = Account.new_account () in let unregistered_pkh = Account.(unregistered_account.pkh) in - let delegator = Contract.implicit_contract unregistered_pkh in + let delegator = Contract.Implicit unregistered_pkh in Op.transaction ~fee:Tez.zero (I i) bootstrap delegator Tez.one >>=? fun credit_contract -> Incremental.add_operation i credit_contract >>=? fun i -> @@ -1071,7 +1071,7 @@ let test_double_registration () = Incremental.begin_construction b >>=? fun i -> let account = Account.new_account () in let pkh = Account.(account.pkh) in - let impl_contract = Contract.implicit_contract pkh in + let impl_contract = Contract.Implicit pkh in (* credit 1μꜩ+ check balance *) Op.transaction (I i) bootstrap impl_contract Tez.one_mutez >>=? fun create_contract -> @@ -1091,7 +1091,7 @@ let test_double_registration_when_empty () = Incremental.begin_construction b >>=? fun i -> let account = Account.new_account () in let pkh = Account.(account.pkh) in - let impl_contract = Contract.implicit_contract pkh in + let impl_contract = Contract.Implicit pkh in (* credit 1μꜩ+ check balance *) Op.transaction (I i) bootstrap impl_contract Tez.one_mutez >>=? fun create_contract -> @@ -1116,7 +1116,7 @@ let test_double_registration_when_recredited () = Incremental.begin_construction b >>=? fun i -> let account = Account.new_account () in let pkh = Account.(account.pkh) in - let impl_contract = Contract.implicit_contract pkh in + let impl_contract = Contract.Implicit pkh in (* credit 1μꜩ+ check balance *) Op.transaction (I i) bootstrap impl_contract Tez.one_mutez >>=? fun create_contract -> @@ -1145,7 +1145,7 @@ let test_unregistered_and_unrevealed_self_delegate_key_init_delegation ~fee () = Incremental.begin_construction b >>=? fun i -> let {Account.pkh; _} = Account.new_account () in let {Account.pkh = delegate_pkh; _} = Account.new_account () in - let contract = Alpha_context.Contract.implicit_contract pkh in + let contract = Alpha_context.Contract.Implicit pkh in Op.transaction (I i) bootstrap contract (of_int 10) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Op.delegation ~fee (I i) contract (Some delegate_pkh) >>=? fun op -> @@ -1166,7 +1166,7 @@ let test_unregistered_and_revealed_self_delegate_key_init_delegation ~fee () = Incremental.begin_construction b >>=? fun i -> let {Account.pkh; pk; _} = Account.new_account () in let {Account.pkh = delegate_pkh; _} = Account.new_account () in - let contract = Alpha_context.Contract.implicit_contract pkh in + let contract = Alpha_context.Contract.Implicit pkh in Op.transaction (I i) bootstrap contract (of_int 10) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Op.revelation (I i) pk >>=? fun op -> @@ -1189,7 +1189,7 @@ let test_self_delegation_emptying_contract () = Incremental.begin_construction b >>=? fun i -> let {Account.pkh; pk; _} = Account.new_account () in let {Account.pkh = delegate_pkh; _} = Account.new_account () in - let contract = Alpha_context.Contract.implicit_contract pkh in + let contract = Alpha_context.Contract.Implicit pkh in let amount = of_int 10 in Op.transaction (I i) bootstrap contract amount >>=? fun op -> Incremental.add_operation i op >>=? fun i -> @@ -1216,10 +1216,8 @@ let test_registered_self_delegate_key_init_delegation () = let {Account.pkh = delegate_pkh; pk = delegate_pk; _} = Account.new_account () in - let contract = Alpha_context.Contract.implicit_contract pkh in - let delegate_contract = - Alpha_context.Contract.implicit_contract delegate_pkh - in + let contract = Alpha_context.Contract.Implicit pkh in + let delegate_contract = Alpha_context.Contract.Implicit delegate_pkh in Op.transaction (I i) bootstrap contract (of_int 10) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Op.transaction (I i) bootstrap delegate_contract (of_int 1) >>=? fun op -> diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml index 9c65e938bc6c..b5e849ed6baf 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_double_endorsement.ml @@ -353,8 +353,8 @@ let test_freeze_more_with_low_balance = Context.Delegate.info (B genesis) account1 >>=? fun info1 -> Op.transaction (B genesis) - (Contract.implicit_contract account1) - (Contract.implicit_contract account2) + (Contract.Implicit account1) + (Contract.Implicit account2) Test_tez.(info1.full_balance -! info1.frozen_deposits) >>=? fun op -> Block.bake ~policy:(Block.By_account account2) genesis ~operations:[op] diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml index ceab5304647e..e097a222b058 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_frozen_deposits.ml @@ -89,7 +89,7 @@ let test_invariants () = why we go through new_account as an intermediate *) Context.Contract.balance (B genesis) contract2 >>=? fun spendable_balance2 -> let new_account = (Account.new_account ()).pkh in - let new_contract = Contract.implicit_contract new_account in + let new_contract = Contract.Implicit new_account in (* we first put some money in new_account *) Op.transaction (B genesis) contract2 new_contract spendable_balance2 >>=? fun transfer -> @@ -419,7 +419,7 @@ let test_frozen_deposits_with_delegation () = >>=? fun initial_frozen_deposits -> Context.Contract.balance (B genesis) contract2 >>=? fun delegated_amount -> let new_account = Account.new_account () in - let new_contract = Contract.implicit_contract new_account.pkh in + let new_contract = Contract.Implicit new_account.pkh in Op.transaction (B genesis) contract2 new_contract delegated_amount >>=? fun transfer -> Block.bake ~operation:transfer genesis >>=? fun b -> @@ -484,7 +484,7 @@ let test_frozen_deposits_with_overdelegation () = Context.Contract.balance (B genesis) contract1 >>=? fun amount -> Context.Contract.balance (B genesis) contract2 >>=? fun amount' -> let new_account = (Account.new_account ()).pkh in - let new_contract = Contract.implicit_contract new_account in + let new_contract = Contract.Implicit new_account in Op.transaction (B genesis) contract1 new_contract amount >>=? fun transfer1 -> Op.transaction (B genesis) contract2 new_contract amount' >>=? fun transfer2 -> @@ -564,7 +564,7 @@ let test_set_limit_with_overdelegation () = let amount' = Test_tez.(initial_staking_balance' *! 8L /! 10L) in let limit = Test_tez.(initial_staking_balance *! 15L /! 100L) in let new_account = (Account.new_account ()).pkh in - let new_contract = Contract.implicit_contract new_account in + let new_contract = Contract.Implicit new_account in Op.transaction (B genesis) contract1 new_contract amount >>=? fun transfer1 -> Op.transaction (B genesis) contract2 new_contract amount' >>=? fun transfer2 -> @@ -627,7 +627,7 @@ let test_error_is_thrown_when_smaller_upper_bound_for_frozen_window () = than [new_cycle + preserved_cycles]. *) Context.Contract.balance (B genesis) contract2 >>=? fun delegated_amount -> let new_account = Account.new_account () in - let new_contract = Contract.implicit_contract new_account.pkh in + let new_contract = Contract.Implicit new_account.pkh in Op.transaction (B genesis) contract2 new_contract delegated_amount >>=? fun transfer -> Block.bake ~operation:transfer genesis >>=? fun b -> diff --git a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml index 504bdec22b5f..e51bd253c91d 100644 --- a/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml +++ b/src/proto_alpha/lib_protocol/test/integration/consensus/test_seed.ml @@ -74,7 +74,7 @@ let test_revelation_early_wrong_right_twice () = in (* get the pkh of a baker *) Block.get_next_baker b >>=? fun (pkh, _, _) -> - let id = Alpha_context.Contract.implicit_contract pkh in + let id = Alpha_context.Contract.Implicit pkh in let policy = Block.Excluding [pkh] in (* bake until commitment - 2, excluding id *) Block.bake_n ~policy (blocks_per_commitment - 2) b >>=? fun b -> @@ -120,7 +120,7 @@ let test_revelation_early_wrong_right_twice () = (WithExceptions.Option.to_exn ~none:Not_found @@ Nonce.get committed_hash) |> fun operation -> Block.get_next_baker ~policy b >>=? fun (baker_pkh, _, _) -> - let baker = Alpha_context.Contract.implicit_contract baker_pkh in + let baker = Alpha_context.Contract.Implicit baker_pkh in Context.Contract.balance (B b) baker >>=? fun baker_bal -> Block.bake ~policy:(Block.By_account baker_pkh) ~operation b >>=? fun b -> (* test that the baker gets the tip reward plus the baking reward*) 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 8525753db6fe..bc2229ba4345 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 @@ -214,9 +214,7 @@ let test_json_roundtrip_err name e () = e let error_encoding_tests = - let contract_zero = - Contract.implicit_contract Signature.Public_key_hash.zero - in + let contract_zero = Contract.Implicit Signature.Public_key_hash.zero in let script_expr_int = Micheline.strip_locations (Micheline.Int (0, Z.zero)) in List.map (fun (name, e) -> diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_activation.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_activation.ml index 318e08c656a5..fcb83a09cb24 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_activation.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_activation.ml @@ -352,11 +352,7 @@ let test_single_activation () = WithExceptions.Option.get ~loc:__LOC__ @@ List.hd secrets in (* Contract does not exist *) - Assert.balance_is - ~loc:__LOC__ - (B blk) - (Contract.implicit_contract account) - Tez.zero + Assert.balance_is ~loc:__LOC__ (B blk) (Contract.Implicit account) Tez.zero >>=? fun () -> Op.activation (B blk) account activation_code >>=? fun operation -> Block.bake ~operation blk >>=? fun blk -> @@ -364,7 +360,7 @@ let test_single_activation () = Assert.balance_is ~loc:__LOC__ (B blk) - (Contract.implicit_contract account) + (Contract.Implicit account) expected_amount (** 10 activations, one per bake. *) @@ -377,7 +373,7 @@ let test_multi_activation_1 () = Assert.balance_is ~loc:__LOC__ (B blk) - (Contract.implicit_contract account) + (Contract.Implicit account) expected_amount >|=? fun () -> blk) blk @@ -400,7 +396,7 @@ let test_multi_activation_2 () = Assert.balance_is ~loc:__LOC__ (B blk) - (Contract.implicit_contract account) + (Contract.Implicit account) expected_amount) secrets @@ -410,7 +406,7 @@ let test_activation_and_transfer () = let ({account; activation_code; _} as _first_one) = WithExceptions.Option.get ~loc:__LOC__ @@ List.hd secrets in - let first_contract = Contract.implicit_contract account in + let first_contract = Contract.Implicit account in Op.activation (B blk) account activation_code >>=? fun operation -> Block.bake ~operation blk >>=? fun blk -> Context.Contract.balance (B blk) bootstrap_contract >>=? fun amount -> @@ -423,7 +419,7 @@ let test_activation_and_transfer () = Assert.balance_was_credited ~loc:__LOC__ (B blk) - (Contract.implicit_contract account) + (Contract.Implicit account) activated_amount_before half_amount @@ -433,7 +429,7 @@ let test_transfer_to_unactivated_then_activate () = let ({account; activation_code; amount} as _first_one) = WithExceptions.Option.get ~loc:__LOC__ @@ List.hd secrets in - let unactivated_commitment_contract = Contract.implicit_contract account in + let unactivated_commitment_contract = Contract.Implicit account in Context.Contract.balance (B blk) bootstrap_contract >>=? fun b_amount -> b_amount /? 2L >>?= fun b_half_amount -> Incremental.begin_construction blk >>=? fun inc -> @@ -450,7 +446,7 @@ let test_transfer_to_unactivated_then_activate () = Assert.balance_was_credited ~loc:__LOC__ (B blk2) - (Contract.implicit_contract account) + (Contract.Implicit account) amount b_half_amount @@ -518,7 +514,7 @@ let test_invalid_transfer_from_unactivated_account () = let ({account; _} as _first_one) = WithExceptions.Option.get ~loc:__LOC__ @@ List.hd secrets in - let unactivated_commitment_contract = Contract.implicit_contract account in + let unactivated_commitment_contract = Contract.Implicit account in (* No activation *) Op.transaction (B blk) diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_reveal.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_reveal.ml index 7235c59d19d1..b81f17252142 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_reveal.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_reveal.ml @@ -43,7 +43,7 @@ let ten_tez = of_int 10 let test_simple_reveal () = Context.init1 ~consensus_threshold:0 () >>=? fun (blk, c) -> let new_c = Account.new_account () in - let new_contract = Alpha_context.Contract.implicit_contract new_c.pkh in + let new_contract = Alpha_context.Contract.Implicit new_c.pkh in (* Create the contract *) Op.transaction (B blk) c new_contract Tez.one >>=? fun operation -> Block.bake blk ~operation >>=? fun blk -> @@ -61,7 +61,7 @@ let test_simple_reveal () = let test_empty_account_on_reveal () = Context.init1 ~consensus_threshold:0 () >>=? fun (blk, c) -> let new_c = Account.new_account () in - let new_contract = Alpha_context.Contract.implicit_contract new_c.pkh in + let new_contract = Alpha_context.Contract.Implicit new_c.pkh in let amount = Tez.one_mutez in (* Create the contract *) Op.transaction (B blk) c new_contract amount >>=? fun operation -> @@ -82,7 +82,7 @@ let test_empty_account_on_reveal () = let test_not_enough_found_for_reveal () = Context.init1 () >>=? fun (blk, c) -> let new_c = Account.new_account () in - let new_contract = Alpha_context.Contract.implicit_contract new_c.pkh in + let new_contract = Alpha_context.Contract.Implicit new_c.pkh in (* Create the contract *) Op.transaction (B blk) c new_contract Tez.one_mutez >>=? fun operation -> Block.bake blk ~operation >>=? fun blk -> @@ -98,7 +98,7 @@ let test_not_enough_found_for_reveal () = let test_transfer_fees_emptying_after_reveal_batched () = Context.init1 () >>=? fun (blk, c) -> let new_c = Account.new_account () in - let new_contract = Alpha_context.Contract.implicit_contract new_c.pkh in + let new_contract = Alpha_context.Contract.Implicit new_c.pkh in (* Create the contract *) Op.transaction (B blk) c new_contract Tez.one >>=? fun operation -> Block.bake blk ~operation >>=? fun blk -> 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 c4f27750fb37..dd9b0850bb54 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 @@ -118,7 +118,7 @@ let test_transfer_zero_implicit () = Context.init1 () >>=? fun (b, dest) -> let account = Account.new_account () in Incremental.begin_construction b >>=? fun i -> - let src = Contract.implicit_contract account.Account.pkh in + let src = Contract.Implicit account.Account.pkh in Op.transaction (I i) src dest Tez.zero >>=? fun op -> Incremental.add_operation i op >>= fun res -> Assert.proto_error_with_info ~loc:__LOC__ res "Empty implicit contract" @@ -184,7 +184,7 @@ let test_transfer_zero_implicit_with_bal_src_as_fee () = Context.init1 () >>=? fun (b, dest) -> let account = Account.new_account () in Incremental.begin_construction b >>=? fun i -> - let src = Contract.implicit_contract account.Account.pkh in + let src = Contract.Implicit account.Account.pkh in Op.transaction (I i) dest src (Tez.of_mutez_exn 100L) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Context.Contract.balance (I i) src >>=? fun bal_src -> @@ -198,7 +198,7 @@ let test_transfer_zero_to_originated_with_bal_src_as_fee () = Context.init1 () >>=? fun (b, dest) -> let account = Account.new_account () in Incremental.begin_construction b >>=? fun i -> - let src = Contract.implicit_contract account.Account.pkh in + let src = Contract.Implicit account.Account.pkh in Op.transaction (I i) dest src (Tez.of_mutez_exn 100L) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Op.contract_origination (I i) dest ~script:Op.dummy_script @@ -215,7 +215,7 @@ let test_transfer_one_to_implicit_with_bal_src_as_fee () = Context.init1 () >>=? fun (b, dest) -> let account = Account.new_account () in Incremental.begin_construction b >>=? fun i -> - let src = Contract.implicit_contract account.Account.pkh in + let src = Contract.Implicit account.Account.pkh in Op.transaction (I i) dest src (Tez.of_mutez_exn 100L) >>=? fun op -> Incremental.add_operation i op >>=? fun i -> Context.Contract.balance (I i) src >>=? fun bal_src -> @@ -239,7 +239,7 @@ let test_transfer_from_implicit_to_implicit_contract () = let account_a = Account.new_account () in let account_b = Account.new_account () in Incremental.begin_construction b >>=? fun b -> - let src = Contract.implicit_contract account_a.Account.pkh in + let src = Contract.Implicit account_a.Account.pkh in two_over_n_of_balance b bootstrap_contract 3L >>=? fun amount1 -> two_over_n_of_balance b bootstrap_contract 10L >>=? fun fee1 -> transfer_and_check_balances @@ -252,7 +252,7 @@ let test_transfer_from_implicit_to_implicit_contract () = amount1 >>=? fun (b, _) -> (* Create an implicit contract as a destination contract. *) - let dest = Contract.implicit_contract account_b.pkh in + let dest = Contract.Implicit account_b.pkh in two_over_n_of_balance b bootstrap_contract 4L >>=? fun amount2 -> two_over_n_of_balance b bootstrap_contract 10L >>=? fun fee2 -> (* Transfer from implicit contract to another implicit contract. *) @@ -272,7 +272,7 @@ let test_transfer_from_implicit_to_originated_contract () = Context.init1 () >>=? fun (b, bootstrap_contract) -> let contract = bootstrap_contract in let account = Account.new_account () in - let src = Contract.implicit_contract account.Account.pkh in + let src = Contract.Implicit account.Account.pkh in Incremental.begin_construction b >>=? fun b -> two_over_n_of_balance b bootstrap_contract 3L >>=? fun amount1 -> (* transfer the money to implicit contract *) @@ -368,7 +368,7 @@ let test_empty_implicit () = Context.init1 () >>=? fun (b, dest) -> let account = Account.new_account () in Incremental.begin_construction b >>=? fun incr -> - let src = Contract.implicit_contract account.Account.pkh in + let src = Contract.Implicit account.Account.pkh in two_over_n_of_balance incr dest 3L >>=? fun amount -> (* Transfer zero tez from an implicit contract. *) Op.transaction (I incr) src dest amount >>=? fun op -> @@ -491,8 +491,7 @@ let test_ownership_sender () = Incremental.begin_construction b >>=? fun b -> (* get the manager of the contract_1 as a sender *) Context.Contract.manager (I b) contract_1 >>=? fun manager -> - (* create an implicit_contract *) - let imcontract_1 = Alpha_context.Contract.implicit_contract manager.pkh in + let imcontract_1 = Alpha_context.Contract.Implicit manager.pkh in transfer_and_check_balances ~loc:__LOC__ b imcontract_1 contract_2 Tez.one >>=? fun (b, _) -> Incremental.finalize_block b >>=? fun _ -> return_unit @@ -587,7 +586,7 @@ let test_bad_parameter () = ~equal:( = ) (Environment.Ecoproto_error (Script_interpreter.Bad_contract_parameter - (Contract.implicit_contract Signature.Public_key_hash.zero))) + (Contract.Implicit Signature.Public_key_hash.zero))) lst -> return () | Error errs -> diff --git a/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml b/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml index 9fbb4c0c1228..a57fdbb3bec7 100644 --- a/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml +++ b/src/proto_alpha/lib_protocol/test/integration/operations/test_voting.ml @@ -200,7 +200,7 @@ let assert_empty_ballots b loc = | _ -> failwith "%s - Unexpected ballot list" loc let mk_contracts_from_pkh pkh_list = - List.map Contract.implicit_contract pkh_list + List.map (fun c -> Contract.Implicit c) pkh_list (* get the list of delegates and the list of their voting power from listings *) let get_delegates_and_power_from_listings b = diff --git a/src/proto_alpha/lib_protocol/test/integration/test_frozen_bonds.ml b/src/proto_alpha/lib_protocol/test/integration/test_frozen_bonds.ml index 8e5af11ece3b..ecc194564347 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_frozen_bonds.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_frozen_bonds.ml @@ -75,13 +75,13 @@ let create_context () = let init_test ~user_is_delegate = create_context () >>=? fun (ctxt, _) -> let (delegate, delegate_pk, _) = Signature.generate_key () in - let delegate_contract = Contract.implicit_contract delegate in - let delegate_account = `Contract (Contract.implicit_contract delegate) in + let delegate_contract = Contract.Implicit delegate in + let delegate_account = `Contract (Contract.Implicit delegate) in let user_contract = if user_is_delegate then delegate_contract else let (user, _, _) = Signature.generate_key () in - Contract.implicit_contract user + Contract.Implicit user in let user_account = `Contract user_contract in (* Allocate contracts for user and delegate. *) @@ -321,7 +321,7 @@ let test_scenario scenario = init_test ~user_is_delegate:false >>=? fun (ctxt, user_contract, user_account, delegate1) -> let (delegate2, delegate_pk2, _) = Signature.generate_key () in - let delegate_contract2 = Contract.implicit_contract delegate2 in + let delegate_contract2 = Contract.Implicit delegate2 in let delegate_account2 = `Contract delegate_contract2 in let delegate_balance2 = big_random_amount () in Token.transfer ctxt `Minted delegate_account2 delegate_balance2 diff --git a/src/proto_alpha/lib_protocol/test/integration/test_token.ml b/src/proto_alpha/lib_protocol/test/integration/test_token.ml index 7b4294e4fccf..717b55d4b82e 100644 --- a/src/proto_alpha/lib_protocol/test/integration/test_token.ml +++ b/src/proto_alpha/lib_protocol/test/integration/test_token.ml @@ -60,9 +60,9 @@ let mk_rollup () = Tx_rollup.Internal_for_tests.originated_tx_rollup nonce let test_simple_balances () = Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> - let src = `Contract (Contract.implicit_contract pkh) in + let src = `Contract (Contract.Implicit pkh) in let (pkh, _pk, _sk) = Signature.generate_key () in - let dest = `Contract (Contract.implicit_contract pkh) in + let dest = `Contract (Contract.Implicit pkh) in let amount = Tez.one in wrap (Token.transfer ctxt src dest amount) >>=? fun (ctxt', _) -> wrap (Token.balance ctxt src) >>=? fun (ctxt, bal_src) -> @@ -79,9 +79,9 @@ let test_simple_balances () = let test_simple_balance_updates () = Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> - let src = Contract.implicit_contract pkh in + let src = Contract.Implicit pkh in let (pkh, _pk, _sk) = Signature.generate_key () in - let dest = Contract.implicit_contract pkh in + let dest = Contract.Implicit pkh in let amount = Tez.one in wrap (Token.transfer ctxt (`Contract src) (`Contract dest) amount) >>=? fun (_, bal_updates) -> @@ -130,7 +130,7 @@ let test_allocated () = let dest = `Delegate_balance pkh in test_allocated_and_still_allocated_when_empty ctxt dest true >>=? fun _ -> let (pkh, _pk, _sk) = Signature.generate_key () in - let dest = `Contract (Contract.implicit_contract pkh) in + let dest = `Contract (Contract.Implicit pkh) in test_allocated_and_deallocated_when_empty ctxt dest >>=? fun _ -> let dest = `Collected_commitments Blinded_public_key_hash.zero in test_allocated_and_deallocated_when_empty ctxt dest >>=? fun _ -> @@ -140,7 +140,7 @@ let test_allocated () = test_allocated_and_still_allocated_when_empty ctxt dest true >>=? fun _ -> let dest = let bond_id = Bond_id.Tx_rollup_bond_id (mk_rollup ()) in - `Frozen_bonds (Contract.implicit_contract pkh, bond_id) + `Frozen_bonds (Contract.Implicit pkh, bond_id) in test_allocated_and_deallocated_when_empty ctxt dest @@ -156,7 +156,7 @@ let check_sink_balances ctxt ctxt' dest amount = let force_allocation_if_need_be ctxt account = match account with | `Delegate_balance pkh -> - let account = `Contract (Contract.implicit_contract pkh) in + let account = `Contract (Contract.Implicit pkh) in wrap (Token.transfer ctxt `Minted account Tez.one_mutez) >|=? fst | _ -> return ctxt @@ -183,7 +183,7 @@ let test_transferring_to_sink ctxt sink amount expected_bupds = let test_transferring_to_contract ctxt = let (pkh, _pk, _sk) = Signature.generate_key () in - let dest = Contract.implicit_contract pkh in + let dest = Contract.Implicit pkh in let amount = random_amount () in test_transferring_to_sink ctxt @@ -202,7 +202,7 @@ let test_transferring_to_collected_commitments ctxt = let test_transferring_to_delegate_balance ctxt = let (pkh, _pk, _sk) = Signature.generate_key () in - let dest = Contract.implicit_contract pkh in + let dest = Contract.Implicit pkh in let amount = random_amount () in test_transferring_to_sink ctxt @@ -269,7 +269,7 @@ let test_transferring_to_burned ctxt = let test_transferring_to_frozen_bonds ctxt = let (pkh, _pk, _sk) = Signature.generate_key () in - let contract = Contract.implicit_contract pkh in + let contract = Contract.Implicit pkh in let tx_rollup = mk_rollup () in let bond_id = Bond_id.Tx_rollup_bond_id tx_rollup in let amount = random_amount () in @@ -369,7 +369,7 @@ let test_transferring_from_bounded_source ctxt src amount expected_bupds = let test_transferring_from_contract ctxt = let (pkh, _pk, _sk) = Signature.generate_key () in - let src = Contract.implicit_contract pkh in + let src = Contract.Implicit pkh in let amount = random_amount () in test_transferring_from_bounded_source ctxt @@ -389,7 +389,7 @@ let test_transferring_from_collected_commitments ctxt = let test_transferring_from_delegate_balance ctxt = let (pkh, _pk, _sk) = Signature.generate_key () in let amount = random_amount () in - let src = Contract.implicit_contract pkh in + let src = Contract.Implicit pkh in test_transferring_from_bounded_source ctxt (`Delegate_balance pkh) @@ -415,7 +415,7 @@ let test_transferring_from_collected_fees ctxt = let test_transferring_from_frozen_bonds ctxt = let (pkh, _pk, _sk) = Signature.generate_key () in - let contract = Contract.implicit_contract pkh in + let contract = Contract.Implicit pkh in let tx_rollup = mk_rollup () in let bond_id = Bond_id.Tx_rollup_bond_id tx_rollup in let amount = random_amount () in @@ -484,15 +484,15 @@ let cast_to_container_type x = (** Generates all combinations of constructors. *) let build_test_cases () = create_context () >>=? fun (ctxt, pkh) -> - let origin = `Contract (Contract.implicit_contract pkh) in + let origin = `Contract (Contract.Implicit pkh) in let (user1, _, _) = Signature.generate_key () in - let user1c = `Contract (Contract.implicit_contract user1) in + let user1c = `Contract (Contract.Implicit user1) in let (user2, _, _) = Signature.generate_key () in - let user2c = `Contract (Contract.implicit_contract user2) in + let user2c = `Contract (Contract.Implicit user2) in let (baker1, baker1_pk, _) = Signature.generate_key () in - let baker1c = `Contract (Contract.implicit_contract baker1) in + let baker1c = `Contract (Contract.Implicit baker1) in let (baker2, baker2_pk, _) = Signature.generate_key () in - let baker2c = `Contract (Contract.implicit_contract baker2) in + let baker2c = `Contract (Contract.Implicit baker2) in (* Allocate contracts for user1, user2, baker1, and baker2. *) wrap (Token.transfer ctxt origin user1c (random_amount ())) >>=? fun (ctxt, _) -> @@ -505,20 +505,20 @@ let build_test_cases () = (* Configure baker1, and baker2 as delegates by self-delegation, for which revealing their manager key is a prerequisite. *) wrap (Contract.reveal_manager_key ctxt baker1 baker1_pk) >>=? fun ctxt -> - wrap (Delegate.set ctxt (Contract.implicit_contract baker1) (Some baker1)) + wrap (Delegate.set ctxt (Contract.Implicit baker1) (Some baker1)) >>=? fun ctxt -> wrap (Contract.reveal_manager_key ctxt baker2 baker2_pk) >>=? fun ctxt -> - wrap (Delegate.set ctxt (Contract.implicit_contract baker2) (Some baker2)) + wrap (Delegate.set ctxt (Contract.Implicit baker2) (Some baker2)) (* Let user1 delegate to baker2. *) >>=? fun ctxt -> - wrap (Delegate.set ctxt (Contract.implicit_contract user1) (Some baker2)) + wrap (Delegate.set ctxt (Contract.Implicit user1) (Some baker2)) >>=? fun ctxt -> let tx_rollup1 = mk_rollup () in let bond_id1 = Bond_id.Tx_rollup_bond_id tx_rollup1 in let tx_rollup2 = mk_rollup () in let bond_id2 = Bond_id.Tx_rollup_bond_id tx_rollup2 in - let user1ic = Contract.implicit_contract user1 in - let baker2ic = Contract.implicit_contract baker2 in + let user1ic = Contract.Implicit user1 in + let baker2ic = Contract.Implicit baker2 in let src_list = [ (`Invoice, random_amount ()); @@ -568,12 +568,11 @@ let check_sink_balances ctxt ctxt' dest amount = let rec check_balances ctxt ctxt' src dest amount = match (cast_to_container_type src, cast_to_container_type dest) with | (None, None) -> return_unit - | (Some (`Delegate_balance d), Some (`Contract c as contract)) - when Contract.implicit_contract d = c -> - (* src and dest are in fact referring to the same contract *) - check_balances ctxt ctxt' contract contract amount - | (Some (`Contract c as contract), Some (`Delegate_balance d)) - when Contract.implicit_contract d = c -> + | ( Some (`Delegate_balance d), + Some (`Contract (Contract.Implicit c) as contract) ) + | ( Some (`Contract (Contract.Implicit c) as contract), + Some (`Delegate_balance d) ) + when d = c -> (* src and dest are in fact referring to the same contract *) check_balances ctxt ctxt' contract contract amount | (Some src, Some dest) when src = dest -> @@ -694,15 +693,15 @@ let test_transfer_n_with_empty_source () = let test_transfer_n_with_non_empty_source () = Random.init 0 ; create_context () >>=? fun (ctxt, pkh) -> - let origin = `Contract (Contract.implicit_contract pkh) in + let origin = `Contract (Contract.Implicit pkh) in let (user1, _, _) = Signature.generate_key () in - let user1c = `Contract (Contract.implicit_contract user1) in + let user1c = `Contract (Contract.Implicit user1) in let (user2, _, _) = Signature.generate_key () in - let user2c = `Contract (Contract.implicit_contract user2) in + let user2c = `Contract (Contract.Implicit user2) in let (user3, _, _) = Signature.generate_key () in - let user3c = `Contract (Contract.implicit_contract user3) in + let user3c = `Contract (Contract.Implicit user3) in let (user4, _, _) = Signature.generate_key () in - let user4c = `Contract (Contract.implicit_contract user4) in + let user4c = `Contract (Contract.Implicit user4) in (* Allocate contracts for user1, user2, user3, and user4. *) let amount = match Tez.of_mutez 1000L with None -> assert false | Some x -> x diff --git a/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml b/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml index 02cd7382a325..d54ee927adaf 100644 --- a/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml +++ b/src/proto_alpha/lib_protocol/test/pbt/test_tx_rollup_l2_encoding.ml @@ -91,9 +91,7 @@ let ticket_hash : Protocol.Alpha_context.Ticket_hash.t = we could introduce a bit more randomness here *) let ticketer_b58 = "tz1Ke2h7sDdakHJQh8WX4Z372du1KChsksyU" in let ticketer_pkh = Signature.Public_key_hash.of_b58check_exn ticketer_b58 in - let ticketer = - Protocol.Alpha_context.Contract.implicit_contract ticketer_pkh - in + let ticketer = Protocol.Alpha_context.Contract.Implicit ticketer_pkh in Tx_rollup_l2_helpers.make_unit_ticket_key ticketer l2_address let idx_ticket_hash_idx_gen : diff --git a/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml b/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml index 3430a780e5a0..1f7f33a7cfa6 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_contract_repr.ml @@ -61,7 +61,7 @@ module Test_contract_repr = struct in Contract_hash.hash_bytes [data] - let dummy_implicit_contract = implicit_contract Signature.Public_key_hash.zero + let dummy_implicit_contract = Implicit Signature.Public_key_hash.zero let dummy_originated_contract = originated_contract @@ dummy_origination_nonce diff --git a/src/proto_alpha/lib_protocol/test/unit/test_receipt.ml b/src/proto_alpha/lib_protocol/test/unit/test_receipt.ml index f0282d307d00..962ebb06e208 100644 --- a/src/proto_alpha/lib_protocol/test/unit/test_receipt.ml +++ b/src/proto_alpha/lib_protocol/test/unit/test_receipt.ml @@ -69,7 +69,7 @@ let test_encodings balance = let test_encodings () = let open Receipt in let pkh = Signature.Public_key_hash.zero in - test_encodings (Contract (Contract.implicit_contract pkh)) >>=? fun () -> + test_encodings (Contract (Contract.Implicit pkh)) >>=? fun () -> test_encodings Block_fees >>=? fun () -> test_encodings (Deposits pkh) >>=? fun () -> test_encodings Nonce_revelation_rewards >>=? fun () -> @@ -93,8 +93,7 @@ let test_encodings () = in let tx_rollup = Tx_rollup.Internal_for_tests.originated_tx_rollup nonce in let bond_id = Bond_id.Tx_rollup_bond_id tx_rollup in - test_encodings (Frozen_bonds (Contract.implicit_contract pkh, bond_id)) - >>=? fun () -> + test_encodings (Frozen_bonds (Contract.Implicit pkh, bond_id)) >>=? fun () -> test_encodings Tx_rollup_rejection_punishments >>=? fun () -> test_encodings Tx_rollup_rejection_rewards diff --git a/src/proto_alpha/lib_protocol/token.ml b/src/proto_alpha/lib_protocol/token.ml index 325dea7a2800..a26ae07f96cc 100644 --- a/src/proto_alpha/lib_protocol/token.ml +++ b/src/proto_alpha/lib_protocol/token.ml @@ -64,11 +64,11 @@ let allocated ctxt stored = Commitment_storage.exists ctxt bpkh >|= fun allocated -> ok (ctxt, allocated) | `Delegate_balance delegate -> - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Contract_storage.allocated ctxt contract >|= fun allocated -> ok (ctxt, allocated) | `Frozen_deposits delegate -> - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Frozen_deposits_storage.allocated ctxt contract >|= fun allocated -> ok (ctxt, allocated) | `Block_fees -> return (ctxt, true) @@ -84,11 +84,11 @@ let balance ctxt stored = Commitment_storage.committed_amount ctxt bpkh >|=? fun balance -> (ctxt, balance) | `Delegate_balance delegate -> - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Storage.Contract.Spendable_balance.get ctxt contract >|=? fun balance -> (ctxt, balance) | `Frozen_deposits delegate -> - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Frozen_deposits_storage.find ctxt contract >|=? fun frozen_deposits -> let balance = match frozen_deposits with @@ -127,7 +127,7 @@ let credit ctxt dest amount origin = amount >|=? fun ctxt -> (ctxt, Commitments bpkh) | `Delegate_balance delegate -> - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Contract_storage.increase_balance_only_call_from_token ctxt contract @@ -186,7 +186,7 @@ let spend ctxt src amount origin = amount >|=? fun ctxt -> (ctxt, Commitments bpkh) | `Delegate_balance delegate -> - let contract = Contract_repr.implicit_contract delegate in + let contract = Contract_repr.Implicit delegate in Contract_storage.decrease_balance_only_call_from_token ctxt contract diff --git a/src/proto_alpha/lib_protocol/token.mli b/src/proto_alpha/lib_protocol/token.mli index 2fe5f2cb8446..31009881c8f0 100644 --- a/src/proto_alpha/lib_protocol/token.mli +++ b/src/proto_alpha/lib_protocol/token.mli @@ -39,7 +39,7 @@ (** [container] is the type of token holders with finite capacity, and whose assets are contained in the context. Let [d] be a delegate. Be aware that transferring to/from [`Delegate_balance d] will not update [d]'s stake, while transferring - to/from [`Contract (Contract_repr.implicit_contract d)] will update [d]'s + to/from [`Contract (Contract_repr.Implicit d)] will update [d]'s stake. *) type container = -- GitLab