ligo/vendors/ligo-utils/tezos-protocol-alpha/alpha_context.ml

282 lines
7.5 KiB
OCaml
Raw Normal View History

2019-09-05 17:21:01 +04:00
(*****************************************************************************)
(* *)
(* Open Source License *)
(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* Permission is hereby granted, free of charge, to any person obtaining a *)
(* copy of this software and associated documentation files (the "Software"),*)
(* to deal in the Software without restriction, including without limitation *)
(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)
(* and/or sell copies of the Software, and to permit persons to whom the *)
(* Software is furnished to do so, subject to the following conditions: *)
(* *)
(* The above copyright notice and this permission notice shall be included *)
(* in all copies or substantial portions of the Software. *)
(* *)
(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)
(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)
(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)
(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)
(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)
(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)
(* DEALINGS IN THE SOFTWARE. *)
(* *)
(*****************************************************************************)
type t = Raw_context.t
2019-09-05 17:21:01 +04:00
type context = t
module type BASIC_DATA = sig
type t
2019-09-05 17:21:01 +04:00
include Compare.S with type t := t
val encoding : t Data_encoding.t
val pp : Format.formatter -> t -> unit
2019-09-05 17:21:01 +04:00
end
module Tez = Tez_repr
module Period = Period_repr
module Timestamp = struct
include Time_repr
2019-09-05 17:21:01 +04:00
let current = Raw_context.current_timestamp
end
include Operation_repr
2019-09-05 17:21:01 +04:00
module Operation = struct
type 'kind t = 'kind operation = {
shell : Operation.shell_header;
protocol_data : 'kind protocol_data;
2019-09-05 17:21:01 +04:00
}
2019-09-05 17:21:01 +04:00
type packed = packed_operation
2019-09-05 17:21:01 +04:00
let unsigned_encoding = unsigned_operation_encoding
2019-09-05 17:21:01 +04:00
include Operation_repr
end
2019-09-05 17:21:01 +04:00
module Block_header = Block_header_repr
2019-09-05 17:21:01 +04:00
module Vote = struct
include Vote_repr
include Vote_storage
end
2019-09-05 17:21:01 +04:00
module Raw_level = Raw_level_repr
module Cycle = Cycle_repr
module Script_int = Script_int_repr
2019-09-05 17:21:01 +04:00
module Script_timestamp = struct
include Script_timestamp_repr
2019-09-05 17:21:01 +04:00
let now ctxt =
let {Constants_repr.time_between_blocks; _} = Raw_context.constants ctxt in
2019-10-17 13:45:27 +04:00
match time_between_blocks with
| [] ->
failwith
"Internal error: 'time_between_block' constants is an empty list."
2019-10-17 13:45:27 +04:00
| first_delay :: _ ->
let current_timestamp = Raw_context.predecessor_timestamp ctxt in
Time.add current_timestamp (Period_repr.to_seconds first_delay)
|> Timestamp.to_seconds |> of_int64
2019-09-05 17:21:01 +04:00
end
2019-09-05 17:21:01 +04:00
module Script = struct
include Michelson_v1_primitives
include Script_repr
2019-09-05 17:21:01 +04:00
let force_decode ctxt lexpr =
Lwt.return
( Script_repr.force_decode lexpr
>>? fun (v, cost) ->
Raw_context.consume_gas ctxt cost >|? fun ctxt -> (v, ctxt) )
2019-09-05 17:21:01 +04:00
let force_bytes ctxt lexpr =
Lwt.return
( Script_repr.force_bytes lexpr
>>? fun (b, cost) ->
Raw_context.consume_gas ctxt cost >|? fun ctxt -> (b, ctxt) )
2019-10-17 13:45:27 +04:00
module Legacy_support = Legacy_script_support_repr
2019-09-05 17:21:01 +04:00
end
2019-09-05 17:21:01 +04:00
module Fees = Fees_storage
type public_key = Signature.Public_key.t
2019-09-05 17:21:01 +04:00
type public_key_hash = Signature.Public_key_hash.t
type signature = Signature.t
2019-09-05 17:21:01 +04:00
module Constants = struct
include Constants_repr
include Constants_storage
end
module Voting_period = Voting_period_repr
module Gas = struct
include Gas_limit_repr
2019-09-05 17:21:01 +04:00
type error += Gas_limit_too_high = Raw_context.Gas_limit_too_high
2019-09-05 17:21:01 +04:00
let check_limit = Raw_context.check_gas_limit
2019-09-05 17:21:01 +04:00
let set_limit = Raw_context.set_gas_limit
2019-09-05 17:21:01 +04:00
let set_unlimited = Raw_context.set_gas_unlimited
2019-09-05 17:21:01 +04:00
let consume = Raw_context.consume_gas
2019-09-05 17:21:01 +04:00
let check_enough = Raw_context.check_enough_gas
2019-09-05 17:21:01 +04:00
let level = Raw_context.gas_level
2019-09-05 17:21:01 +04:00
let consumed = Raw_context.gas_consumed
2019-09-05 17:21:01 +04:00
let block_level = Raw_context.block_gas_level
end
2019-09-05 17:21:01 +04:00
module Level = struct
include Level_repr
include Level_storage
end
2019-09-05 17:21:01 +04:00
module Contract = struct
include Contract_repr
include Contract_storage
2019-10-17 13:45:27 +04:00
let originate c contract ~balance ~script ~delegate =
originate c contract ~balance ~script ~delegate
2019-09-05 17:21:01 +04:00
let init_origination_nonce = Raw_context.init_origination_nonce
2019-09-05 17:21:01 +04:00
let unset_origination_nonce = Raw_context.unset_origination_nonce
2020-03-05 23:52:47 +04:00
let set_balance = Contract_storage.set_balance
2019-09-05 17:21:01 +04:00
end
2020-03-05 23:52:47 +04:00
2019-10-17 13:45:27 +04:00
module Big_map = struct
type id = Z.t
2019-10-17 13:45:27 +04:00
let fresh = Storage.Big_map.Next.incr
2019-10-17 13:45:27 +04:00
let fresh_temporary = Raw_context.fresh_temporary_big_map
2019-10-17 13:45:27 +04:00
let mem c m k = Storage.Big_map.Contents.mem (c, m) k
2019-10-17 13:45:27 +04:00
let get_opt c m k = Storage.Big_map.Contents.get_option (c, m) k
2019-10-17 13:45:27 +04:00
let rpc_arg = Storage.Big_map.rpc_arg
2019-10-17 13:45:27 +04:00
let cleanup_temporary c =
Raw_context.temporary_big_maps c Storage.Big_map.remove_rec c
>>= fun c -> Lwt.return (Raw_context.reset_temporary_big_map c)
2019-10-17 13:45:27 +04:00
let exists c id =
Lwt.return
(Raw_context.consume_gas c (Gas_limit_repr.read_bytes_cost Z.zero))
>>=? fun c ->
Storage.Big_map.Key_type.get_option c id
>>=? fun kt ->
2019-10-17 13:45:27 +04:00
match kt with
| None ->
return (c, None)
2019-10-17 13:45:27 +04:00
| Some kt ->
Storage.Big_map.Value_type.get c id
>>=? fun kv -> return (c, Some (kt, kv))
2019-10-17 13:45:27 +04:00
end
2019-09-05 17:21:01 +04:00
module Delegate = Delegate_storage
2019-09-05 17:21:01 +04:00
module Roll = struct
include Roll_repr
include Roll_storage
end
2019-09-05 17:21:01 +04:00
module Nonce = Nonce_storage
2019-09-05 17:21:01 +04:00
module Seed = struct
include Seed_repr
include Seed_storage
end
module Fitness = struct
include Fitness_repr
include Fitness
2019-09-05 17:21:01 +04:00
type fitness = t
include Fitness_storage
2019-09-05 17:21:01 +04:00
end
module Bootstrap = Bootstrap_storage
module Commitment = struct
include Commitment_repr
include Commitment_storage
end
module Global = struct
2019-10-17 13:45:27 +04:00
let get_block_priority = Storage.Block_priority.get
2019-10-17 13:45:27 +04:00
let set_block_priority = Storage.Block_priority.set
2019-09-05 17:21:01 +04:00
end
let prepare_first_block = Init_storage.prepare_first_block
2019-09-05 17:21:01 +04:00
let prepare = Init_storage.prepare
let finalize ?commit_message:message c =
let fitness = Fitness.from_int64 (Fitness.current c) in
let context = Raw_context.recover c in
{
Updater.context;
fitness;
message;
max_operations_ttl = 60;
2019-09-05 17:21:01 +04:00
last_allowed_fork_level =
Raw_level.to_int32 @@ Level.last_allowed_fork_level c;
}
let activate = Raw_context.activate
2019-09-05 17:21:01 +04:00
let fork_test_chain = Raw_context.fork_test_chain
let record_endorsement = Raw_context.record_endorsement
2019-09-05 17:21:01 +04:00
let allowed_endorsements = Raw_context.allowed_endorsements
2019-09-05 17:21:01 +04:00
let init_endorsements = Raw_context.init_endorsements
2019-10-17 13:45:27 +04:00
let included_endorsements = Raw_context.included_endorsements
2019-09-05 17:21:01 +04:00
let reset_internal_nonce = Raw_context.reset_internal_nonce
2019-09-05 17:21:01 +04:00
let fresh_internal_nonce = Raw_context.fresh_internal_nonce
2019-09-05 17:21:01 +04:00
let record_internal_nonce = Raw_context.record_internal_nonce
let internal_nonce_already_recorded =
Raw_context.internal_nonce_already_recorded
2019-09-05 17:21:01 +04:00
let add_deposit = Raw_context.add_deposit
2019-09-05 17:21:01 +04:00
let add_fees = Raw_context.add_fees
2019-09-05 17:21:01 +04:00
let add_rewards = Raw_context.add_rewards
let get_deposits = Raw_context.get_deposits
2019-09-05 17:21:01 +04:00
let get_fees = Raw_context.get_fees
2019-09-05 17:21:01 +04:00
let get_rewards = Raw_context.get_rewards
let description = Raw_context.description