123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Trili Tech, <contact@trili.tech> *)(* *)(* 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. *)(* *)(*****************************************************************************)typeerror+=|(* `Permanent *)Error_encode_outbox_message|(* `Permanent *)Error_decode_outbox_messagelet()=letopenData_encodinginletmsg="Failed to encode a rollup management protocol outbox message value"inregister_error_kind`Permanent~id:"smart_rollup_outbox_message_repr.error_encoding_outbox_message"~title:msg~pp:(funfmt()->Format.fprintffmt"%s"msg)~description:msgunit(functionError_encode_outbox_message->Some()|_->None)(fun()->Error_encode_outbox_message);letmsg="Failed to decode a rollup management protocol outbox message value"inregister_error_kind`Permanent~id:"smart_rollup_outbox_message_repr.error_decoding_outbox_message"~title:msg~pp:(funfmt()->Format.fprintffmt"%s"msg)~description:msgunit(functionError_decode_outbox_message->Some()|_->None)(fun()->Error_decode_outbox_message)typetransaction={unparsed_parameters:Script_repr.expr;(** The payload. *)destination:Contract_hash.t;(** The recipient contract. *)entrypoint:Entrypoint_repr.t;(** Entrypoint of the destination. *)}lettransaction_encoding=letopenData_encodinginconv(fun{unparsed_parameters;destination;entrypoint}->(unparsed_parameters,destination,entrypoint))(fun(unparsed_parameters,destination,entrypoint)->{unparsed_parameters;destination;entrypoint})@@obj3(req"parameters"Script_repr.expr_encoding)(req"destination"Contract_repr.originated_encoding)Entrypoint_repr.(dft"entrypoint"simple_encodingdefault)letpp_untyped_transactionfmt{destination;entrypoint;unparsed_parameters}=letjson=Data_encoding.Json.constructScript_repr.expr_encodingunparsed_parametersinFormat.fprintffmt"@[%a@;%a@;%a@]"Contract_hash.ppdestinationEntrypoint_repr.ppentrypointData_encoding.Json.ppjsontypetyped_transaction={unparsed_parameters:Script_repr.expr;unparsed_ty:Script_repr.expr;destination:Contract_hash.t;entrypoint:Entrypoint_repr.t;}lettyped_transaction_encoding=letopenData_encodinginconv(fun{unparsed_parameters;unparsed_ty;destination;entrypoint}->(unparsed_parameters,unparsed_ty,destination,entrypoint))(fun(unparsed_parameters,unparsed_ty,destination,entrypoint)->{unparsed_parameters;unparsed_ty;destination;entrypoint})@@obj4(req"parameters"Script_repr.expr_encoding)(req"parameters_ty"Script_repr.expr_encoding)(req"destination"Contract_repr.originated_encoding)Entrypoint_repr.(dft"entrypoint"simple_encodingdefault)letpp_typed_transactionfmt{destination;entrypoint;unparsed_parameters;unparsed_ty}=letjson_param=Data_encoding.Json.constructScript_repr.expr_encodingunparsed_parametersinletjson_ty=Data_encoding.Json.constructScript_repr.expr_encodingunparsed_tyinFormat.fprintffmt"@[%a@;%a@;%a@;%a@]"Contract_hash.ppdestinationEntrypoint_repr.ppentrypointData_encoding.Json.ppjson_paramData_encoding.Json.ppjson_tytypet=|Atomic_transaction_batchof{transactions:transactionlist}|Atomic_transaction_batch_typedof{transactions:typed_transactionlist}letencoding=letopenData_encodingin(* We use a union encoding in order to guarantee backwards compatibility
when outbox messages are extended with more constructors.
Each new constructor must be added with an increased tag number.
*)check_sizeConstants_repr.sc_rollup_message_size_limit(union[case(Tag0)~title:"Atomic_transaction_batch"(obj2(req"transactions"(listtransaction_encoding))(req"kind"(constant"untyped")))(function|Atomic_transaction_batch{transactions}->Some(transactions,())|_->None)(fun(transactions,())->Atomic_transaction_batch{transactions});case(Tag1)~title:"Atomic_transaction_batch_typed"(obj2(req"transactions"(listtyped_transaction_encoding))(req"kind"(constant"typed")))(function|Atomic_transaction_batch_typed{transactions}->Some(transactions,())|_->None)(fun(transactions,())->Atomic_transaction_batch_typed{transactions});])letppfmt=function|Atomic_transaction_batch{transactions}->Format.pp_print_list~pp_sep:Format.pp_print_spacepp_untyped_transactionfmttransactions|Atomic_transaction_batch_typed{transactions}->Format.pp_print_list~pp_sep:Format.pp_print_spacepp_typed_transactionfmttransactionstypeserialized=stringletdeserializedata=letopenResult_syntaxinmatchData_encoding.Binary.of_string_optencodingdatawith|Somex->returnx|None->tzfailError_decode_outbox_messageletserializeoutbox_message=letopenResult_syntaxinmatchData_encoding.Binary.to_string_optencodingoutbox_messagewith|Somestr->returnstr|None->tzfailError_encode_outbox_messageletunsafe_of_strings=sletunsafe_to_strings=s