Mavryk_raw_protocol_alpha.Script_ir_unparser
Flag that drives unparsing of typed values to nodes.
Optimized_legacy
must be kept backward-compatible in order to compute valid hashes (of big map keys).Optimized
may be used as long as the result can be read by Script_ir_translator.parse_data
.Readable
produces with string
values instead of bytes
when feasible.type ('ty, 'depth) comb_witness =
| Comb_Pair : ('t, 'd) comb_witness -> (_ * 't, unit -> 'd) comb_witness
| Comb_Any : (_, _) comb_witness
('t, 'd) comb_witness
describes types of values belonging to a comb
of type 't
and size 'd
.
val serialize_ty_for_error :
('a, 'b) Script_typed_ir.ty ->
Alpha_context.Script.expr
serialize_ty_for_error ty
returns the Micheline representation of ty
suitable for rendering in an error message. Does not consume gas, since when this function is called, the operation must have already failed.
val serialize_stack_for_error :
Alpha_context.context ->
('a, 'b) Script_typed_ir.stack_ty ->
Alpha_context.Script.expr list
serialize_stack_for_error ctxt stack_ty
returns a Micheline representation of stack_ty
as a list of Micheline expressions ONLY IF gas is unlimited in ctxt
. Otherwise returns an empty list.
val unparse_ty :
loc:'loc ->
Alpha_context.context ->
('b, 'c) Script_typed_ir.ty ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
unparse_ty ~loc ctxt ty
returns the Micheline representation of a given type and an update context, where gas has been properly consumed.
val unparse_comparable_ty_uncarbonated :
loc:'loc ->
'a Script_typed_ir.comparable_ty ->
'loc Alpha_context.Script.michelson_node
unparse_comparable_ty_uncarbonated ~loc ty
returns the Michelson representation of comparable type ty
without consuming gas.
val unparse_stack_uncarbonated :
('a, 's) Script_typed_ir.stack_ty ->
Alpha_context.Script.expr list
unparse_stack_uncarbonated stack_ty
returns the Micheline representation of stack_ty
. Does not consume gas.
val unparse_parameter_ty :
loc:'loc ->
Alpha_context.context ->
('a, 'c) Script_typed_ir.ty ->
entrypoints:'a Script_typed_ir.entrypoints ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
unparse_parameter_ty ~loc ctxt ty ~entrypoints
is a specialised version of unparse_ty
, which also analyses entrypoints
in order to annotate the returned type with adequate annotations.
val unparse_bls12_381_g1 :
loc:'loc ->
Alpha_context.context ->
Script_typed_ir.Script_bls.G1.t ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
unparse_bls12_381_g1 ~loc ctxt bls
returns the Micheline representation of bls
and consumes gas from ctxt
.
val unparse_bls12_381_g2 :
loc:'loc ->
Alpha_context.context ->
Script_typed_ir.Script_bls.G2.t ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
unparse_bls12_381_g1 ~loc ctxt bls
returns the Micheline representation of bls
and consumes gas from ctxt
.
val unparse_bls12_381_fr :
loc:'loc ->
Alpha_context.context ->
Script_typed_ir.Script_bls.Fr.t ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
unparse_bls12_381_g1 ~loc ctxt bls
returns the Micheline representation of bls
and consumes gas from ctxt
.
val unparse_operation :
loc:'loc ->
Alpha_context.context ->
Script_typed_ir.operation ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
unparse_operation ~loc ctxt op
returns the Micheline representation of op
and consumes gas from ctxt
. Useful only for producing execution traces in the interpreter.
val unparse_with_data_encoding :
loc:'loc ->
Alpha_context.context ->
'a ->
Alpha_context.Gas.cost ->
'a Mavryk_protocol_environment_alpha.Data_encoding.t ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
Mavryk_protocol_environment_alpha.Lwt.t
unparse_with_data_encoding ~loc ctxt v gas_cost enc
returns the bytes representation of v
wrapped in Micheline.Bytes
, consuming gas_cost
from ctxt
.
val unparse_comparable_data :
Alpha_context.context ->
unparsing_mode ->
'a Script_typed_ir.comparable_ty ->
'a ->
(Alpha_context.Script.expr * Alpha_context.context)
Mavryk_protocol_environment_alpha.Error_monad.tzresult
Mavryk_protocol_environment_alpha.Lwt.t
unparse_comparable_data ctxt unparsing_mode ty v
returns the Micheline representation of v
of type ty
, consuming gas from ctxt
.
val unparse_contract :
loc:'loc ->
Alpha_context.context ->
unparsing_mode ->
'b Script_typed_ir.typed_contract ->
('loc Alpha_context.Script.michelson_node * Alpha_context.context,
Mavryk_protocol_environment_alpha.Error_monad.error
Mavryk_protocol_environment_alpha.Error_monad.trace)
Mavryk_protocol_environment_alpha.Pervasives.result
unparse_contract ~loc ctxt unparsin_mode contract
returns a Micheline representation of a given contract in a given unparsing_mode
. Consumes gas ctxt
.
Lambdas are normalized at parsing and also at unparsing. These normalizations require to parse and unparse data appearing inside PUSH and introduces a mutual dependency between this module and Script_ir_translator
which is resolved as follows:
Script_ir_translator.parse_data
takes the normalization function unparse_code_rec
as argument,unparse_data_rec
and the normalization function unparse_code_rec
are mutually defined in a functor parameterized by the missing bits from Script_ir_translator
; see the module signature MICHELSON_PARSER
below.type unparse_code_rec =
Alpha_context.context ->
stack_depth:int ->
unparsing_mode ->
Alpha_context.Script.node ->
(Alpha_context.Script.node * Alpha_context.context)
Mavryk_protocol_environment_alpha.Error_monad.tzresult
Mavryk_protocol_environment_alpha.Lwt.t
The unparse_code_rec
function is not exported (except through the Internal_for_benchmarking
module), but needs to be called by parse_data
to normalize lambdas so it is passed as argument to the parse_data
of the MICHELSON_PARSER
signature below and to several functions of Script_ir_translator
. To avoid repeating the signature of this function we define a type alias for it.
MICHELSON_PARSER
signature describes a set of dependencies required to unparse arbitrary values in the IR. Because some of those values contain just a Michelson code that does not need to be parsed immediately, unparsing them requires extracting information from that code – that's why we depend on the parser here.
module type MICHELSON_PARSER = sig ... end
module Data_unparser (P : MICHELSON_PARSER) : sig ... end