package tezos-protocol-015-PtLimaPt

  1. Overview
  2. Docs
Tezos/Protocol: economic-protocol definition

Install

Dune Dependency

Authors

Maintainers

Sources

tezos-17.3.tar.gz
sha256=7062cd57addd452852598a2214ade393130efa087b99068d53713bdf912b3680
sha512=08e4091144a03ce3c107fb91a66501bd8b65ca3278917c455a2eaac6df3e108ade63f6ab8340a4bb152d60f404326e464d0ec95d26cafe8e82f870465d24a5fc

doc/tezos-protocol-015-PtLimaPt.raw/Tezos_raw_protocol_015_PtLimaPt/Indexable/index.html

Module Tezos_raw_protocol_015_PtLimaPt.IndexableSource

In transaction rollups, some values can be replaced by indexes in the messages sent from the layer-1 to the layer-2.

This module provides various type-safe helpers to manipulate these particular values.

Sourcetype value_only =
  1. | Value_only
Sourcetype index_only =
  1. | Index_only
Sourcetype unknown =
  1. | Unknown
Sourcetype (_, 'a) t = private
  1. | Value : 'a -> (value_only, 'a) t
  2. | Hidden_value : 'a -> (unknown, 'a) t
  3. | Index : int32 -> (index_only, 'a) t
  4. | Hidden_index : int32 -> (unknown, 'a) t

An indexable value is a value which can be replaced by an integer. The first type parameter determines whether or not this replacement has happened already.

Sourcetype 'a value = (value_only, 'a) t

The type of indexable values identified as not being indexes.

Sourcetype 'a index = (index_only, 'a) t

The type of indexable values identified as being indexes.

Sourcetype 'a either = (unknown, 'a) t

The type of indexable values whose content is still unknown.

Sourceval value : 'a -> 'a value

value v wraps v into an indexable value identified as not being an index.

Sourceval from_value : 'a -> 'a either

from_value v wraps v into an indexable value, but forget about the nature of the content of the result.

index i wraps i into an indexable value identified as being an index.

Returns the error Index_cannot_be_negative iff i <= 0l.

from_index i wraps i into an indexable value, but forget about the nature of the content of the result.

Returns the error Index_cannot_be_negative iff i <= 0l.

Sourceval index_exn : int32 -> 'a index

index_exn i wraps i into an indexable value identified as being an index.

Sourceval from_index_exn : int32 -> 'a either

from_index_exn i wraps i into an indexable value, but forget about the nature of the content of the result.

compact val_encoding is a combinator to derive a compact encoding for an indexable value of type 'a from an encoding for 'a. It uses two bits in the shared tag. 00 is used for indexes fitting in one byte, 01 for indexes fitting in two bytes, 10 for indexes fitting in four bytes, and 11 for the values of type 'a.

Sourceval destruct : ('state, 'a) t -> ('a index, 'a) Tezos_protocol_environment_015_PtLimaPt.Either.t

destruct x returns either the index or the (unwrapped) value contained in x.

Note: If you want to manipulate a value of type 'a value, you can use value.

Sourceval forget : ('state, 'a) t -> (unknown, 'a) t

forget x returns an indexable value whose kind of contents has been forgotten.

Sourceval to_int32 : 'a index -> int32

to_int32 x unwraps and returns the integer behind x.

Sourceval to_value : 'a value -> 'a

to_value x unwraps and returns the value behind x.

Sourceval is_value_e : error:'trace -> ('state, 'a) t -> ('a, 'trace) Tezos_protocol_environment_015_PtLimaPt.Pervasives.result

is_value_e err x unwraps and returns the value behind x, and throws an err if x is an index.

Sourceval in_memory_size : ('a -> Cache_memory_helpers.sint) -> ('state, 'a) t -> Cache_memory_helpers.sint

in_memory_size a returns the number of bytes allocated in RAM for a.

Sourceval size : ('a -> int) -> ('state, 'a) t -> int

size a returns the number of bytes allocated in an inbox to store a.

Sourceval compare : ('a -> 'a -> int) -> ('state, 'a) t -> ('state', 'a) t -> int

compare f x y is a total order on indexable values, which proceeds as follows.

  • If both x and y are a value, then use f to compare them.
  • If both x and y are indexes, then uses the Int32.compare function to compare them.
  • Finally, if x and y have not the same kind, the logic is that indexes are smaller than values.

Note: This can be dangerous, as you may end up comparing two things that are equivalent (a value and its index) but declare they are not equal.

Sourceval compare_values : ('a -> 'a -> int) -> 'a value -> 'a value -> int

compare_values f x y compares the value x and y using f, and relies on the type system of OCaml to ensure that x and y are indeed both values.

Sourceval compare_indexes : 'a index -> 'a index -> int

compare_indexes x y compares the indexes x and y, and relies on the type system of OCaml to ensure that x and y are indeed both indexes.

Sourcemodule type VALUE = sig ... end
Sourcemodule Make (V : VALUE) : sig ... end
Sourcetype Tezos_protocol_environment_015_PtLimaPt.Error_monad.error +=
  1. | Index_cannot_be_negative of int32
OCaml

Innovation. Community. Security.