Mavryk_raw_protocol_alpha.Global_constants_storage
This module represents access to a global table of constant Micheline values. Users may register a Micheline value in the table, paying the cost of storage. Once stored, scripts may reference this value by its hash.
Note: the table does not typecheck the values stored in it. Instead, any place that uses constants must first call expand
before typechecking the code. This decision was made to make it as easy as possible for users to register values to the table, and also to allow maximum flexibility in the use of constants for different parts of a Michelson script (code, types, data, etc.).
A constant is the prim of the literal characters "constant". A constant must have a single argument, being a string with a well formed hash of a Micheline expression (i.e generated by Script_expr_hash.to_b58check
).
val get :
Raw_context.t ->
Script_expr_hash.t ->
(Raw_context.t * Script_repr.expr)
Mavryk_protocol_environment_alpha.Error_monad.tzresult
Mavryk_protocol_environment_alpha.Lwt.t
get context hash
retrieves the Micheline value with the given hash.
Fails with Nonexistent_global
if no value is found at the given hash.
Fails with Storage_error Corrupted_data
if the deserialisation fails.
Consumes Gas_repr.read_bytes_cost <size of the value>
.
val register :
Raw_context.t ->
Script_repr.expr ->
(Raw_context.t * Script_expr_hash.t * Mavryk_protocol_environment_alpha.Z.t)
Mavryk_protocol_environment_alpha.Error_monad.tzresult
Mavryk_protocol_environment_alpha.Lwt.t
register context value
registers a constant in the global table of constants, returning the hash and storage bytes consumed.
Does not type-check the Micheline code being registered, allow potentially ill-typed Michelson values to be stored in the table (see note at top of module).
The constant is stored unexpanded, but it is temporarily expanded at registration time only to check the expanded version respects the following limits. This also ensures there are no cyclic dependencies between constants.
Fails with Expression_too_deep
if, after fully expanding all constants, the expression would have a depth greater than Constant_repr.max_allowed_global_constant_depth
.
Fails with Badly_formed_constant_expression
if constants are not well-formed (see declaration of Badly_formed_constant_expression
) or with Nonexistent_global
if a referenced constant does not exist in the table.
Consumes serialization cost. Consumes Gas_repr.write_bytes_cost <size>
where size is the number of bytes in the binary serialization provided by Script_repr.expr_encoding
.
val expand :
Raw_context.t ->
Script_repr.expr ->
(Raw_context.t * Script_repr.expr)
Mavryk_protocol_environment_alpha.Error_monad.tzresult
Mavryk_protocol_environment_alpha.Lwt.t
expand context expr
replaces every constant in the given Michelson expression with its value stored in the global table.
The expansion is applied recursively so that the returned expression contains no constant.
Fails with Badly_formed_constant_expression
if constants are not well-formed (see declaration of Badly_formed_constant_expression
) or with Nonexistent_global
if a referenced constant does not exist in the table.
module Internal_for_tests : sig ... end