123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199(*****************************************************************************)(* *)(* 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:"smart_rollup_inbox_message_encoding"~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 smart rollup management protocol inbox message value"inregister_error_kind`Permanent~id:"smart_rollup_inbox_message_decoding"~title:msg~pp:(funfmt()->Format.fprintffmt"%s"msg)~description:msgunit(functionError_decode_inbox_message->Some()|_->None)(fun()->Error_decode_inbox_message)typeinternal_inbox_message=|Transferof{payload:Script_repr.expr;sender:Contract_hash.t;source:Signature.public_key_hash;destination:Sc_rollup_repr.Address.t;}|Start_of_level|End_of_level|Info_per_levelof{predecessor_timestamp:Time.t;predecessor:Block_hash.t;}letinternal_inbox_message_encoding=letopenData_encodinginletkindname=req"internal_inbox_message_kind"(constantname)inunion[case(Tag0)~title:"Transfer"(obj5(kind"transfer")(req"payload"Script_repr.expr_encoding)(req"sender"Contract_hash.encoding)(req"source"Signature.Public_key_hash.encoding)(req"destination"Sc_rollup_repr.Address.encoding))(function|Transfer{payload;sender;source;destination}->Some((),payload,sender,source,destination)|_->None)(fun((),payload,sender,source,destination)->Transfer{payload;sender;source;destination});case(Tag1)~title:"Start_of_level"(obj1(kind"start_of_level"))(functionStart_of_level->Some()|_->None)(fun()->Start_of_level);case(Tag2)~title:"End_of_level"(obj1(kind"end_of_level"))(functionEnd_of_level->Some()|_->None)(fun()->End_of_level);case(Tag3)~title:"Info_per_level"(obj3(kind"info_per_level")(req"predecessor_timestamp"Time.encoding)(req"predecessor"Block_hash.encoding))(function|Info_per_level{predecessor_timestamp;predecessor}->Some((),predecessor_timestamp,predecessor)|_->None)(fun((),predecessor_timestamp,predecessor)->Info_per_level{predecessor_timestamp;predecessor});]typet=Internalofinternal_inbox_message|Externalofstringletencoding=letopenData_encodingincheck_sizeConstants_repr.sc_rollup_message_size_limit(union[case(Tag0)~title:"Internal"internal_inbox_message_encoding(function|Internalinternal_message->Someinternal_message|External_->None)(funinternal_message->Internalinternal_message);case(Tag1)~title:"External"Variable.(stringHex)(functionExternalmsg->Somemsg|Internal_->None)(funmsg->Externalmsg);])typeserialized=stringletserializemsg=letopenResult_syntaxinmatchData_encoding.Binary.to_string_optencodingmsgwith|None->tzfailError_encode_inbox_message|Somestr->returnstrletdeserializes=letopenResult_syntaxinmatchData_encoding.Binary.of_string_optencodingswith|None->tzfailError_decode_inbox_message|Somemsg->returnmsgletunsafe_of_strings=sletunsafe_to_strings=s(* 32 *)lethash_prefix="\003\255\138\145\170"(* srib3(55) *)moduleHash=structletprefix="srib3"letencoded_size=55moduleH=Blake2B.Make(Base58)(structletname="Smart_rollup_serialized_message_hash"lettitle="The hash of a serialized message of the smart rollup inbox."letb58check_prefix=hash_prefix(* defaults to 32 *)letsize=Noneend)includeHlet()=Base58.check_encoded_prefixb58check_encodingprefixencoded_sizeendlethash_serialized_message(payload:serialized)=Hash.hash_string[(payload:>string)]letstart_of_level_serialized=(* If [Start_of_level] cannot be serialized, this will be detected at
compilation time as we are defining a top-level value. *)Data_encoding.Binary.to_string_exnencoding(InternalStart_of_level)letend_of_level_serialized=(* If [End_of_level] cannot be serialized, this will be detected at
compilation time as we are defining a top-level value. *)Data_encoding.Binary.to_string_exnencoding(InternalEnd_of_level)