123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106(*****************************************************************************)(* *)(* 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_inbox_message|(* `Permanent *)Error_decode_inbox_messagelet()=letopenData_encodinginletmsg="Failed to encode a rollup management protocol inbox message value"inregister_error_kind`Permanent~id:"sc_rollup_inbox_message_repr.error_encoding_inbox_message"~title:msg~pp:(funfmt()->Format.fprintffmt"%s"msg)~description:msgunit(functionError_encode_inbox_message->Some()|_->None)(fun()->Error_encode_inbox_message);letmsg="Failed to decode a rollup management protocol inbox message value"inregister_error_kind`Permanent~id:"sc_rollup_inbox_message_repr.error_decoding_inbox_message"~title:msg~pp:(funfmt()->Format.fprintffmt"%s"msg)~description:msgunit(functionError_decode_inbox_message->Some()|_->None)(fun()->Error_decode_inbox_message)typeinternal_inbox_message={payload:Script_repr.expr;sender:Contract_hash.t;source:Signature.public_key_hash;}typet=Internalofinternal_inbox_message|Externalofstringletencoding=letopenData_encodinginData_encoding.union[case(Tag0)~title:"Internal"(obj3(req"payload"Script_repr.expr_encoding)(req"sender"Contract_hash.encoding)(req"source"Signature.Public_key_hash.encoding))(function|Internal{payload;sender;source}->Some(payload,sender,source)|External_->None)(fun(payload,sender,source)->Internal{payload;sender;source});case(Tag1)~title:"External"(* TODO: #3116
Add size limit to constrain the maximum size of the string.
The exact limit is yet to be decided. Could be added as a constant.
*)string(functionExternalmsg->Somemsg|Internal_->None)(funmsg->Externalmsg);]typeserialized=stringletto_bytesmsg=letopenTzresult_syntaxinmatchData_encoding.Binary.to_string_optencodingmsgwith|None->failError_encode_inbox_message|Somestr->returnstrmoduleInternal_for_tests=structletof_bytesbytes=letopenTzresult_syntaxinmatchData_encoding.Binary.of_string_optencodingbyteswith|None->failError_decode_inbox_message|Somemsg->returnmsgend