123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116(*****************************************************************************)(* *)(* 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:"sc_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:"sc_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. *)}typet=Atomic_transaction_batchof{transactions:transactionlist}lettransaction_encoding=letopenData_encodingin(* TODO: #3116
Add size limit to constrain the maximum size of the encoded message.
The exact limit is yet to be decided. Could be added as a constant.
*)conv(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)(req"entrypoint"Entrypoint_repr.simple_encoding)letencoding=letopenData_encodinginconv(fun(Atomic_transaction_batch{transactions})->transactions)(funtransactions->Atomic_transaction_batch{transactions})(obj1(req"transactions"(listtransaction_encoding)))letpp_transactionfmt{destination;entrypoint;unparsed_parameters=_}=Format.fprintffmt"@[%a@;%a@]"Contract_hash.ppdestinationEntrypoint_repr.ppentrypointletppfmt(Atomic_transaction_batch{transactions})=Format.pp_print_list~pp_sep:Format.pp_print_spacepp_transactionfmttransactionsletof_bytesbytes=letopenTzresult_syntaxinmatchData_encoding.Binary.of_string_optencodingbyteswith|Somex->returnx|None->failError_decode_outbox_messagemoduleInternal_for_tests=structletto_bytesoutbox_message=letopenTzresult_syntaxinmatchData_encoding.Binary.to_string_optencodingoutbox_messagewith|Somestr->returnstr|None->failError_encode_outbox_messageend