123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Marigold <contact@marigold.dev> *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 Oxhead Alpha <info@oxhead-alpha.com> *)(* *)(* 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. *)(* *)(*****************************************************************************)moduleEl=structtypet=Tx_rollup_message_hash_repr.tletto_bytes=Data_encoding.Binary.to_bytes_exnTx_rollup_message_hash_repr.encodingendmodulePrefix=structletname="Inbox_list_hash"lettitle="A merkle root hash for inboxes"letb58check_prefix=Tx_rollup_prefixes.inbox_list_hash.b58check_prefixletsize=SomeTx_rollup_prefixes.inbox_list_hash.hash_sizeendmoduleH=Blake2B.Make(Base58)(Prefix)moduleMerkle_list=Merkle_list.Make(El)(H)moduleMerkle=structtypetree=Merkle_list.ttyperoot=Merkle_list.htypepath=Merkle_list.pathletempty=Merkle_list.nilletroot=Merkle_list.rootlet(=)=H.(=)letcompare=H.compareletroot_encoding=H.encodingletroot_of_b58check_opt=H.of_b58check_optletpp_root=H.ppletpath_encoding=Merkle_list.path_encodingletadd_message=Merkle_list.snoclettree_of_messages=List.fold_leftMerkle_list.snocMerkle_list.nilletcompute_pathmessagesposition=lettree=tree_of_messagesmessagesinMerkle_list.compute_pathtreepositionletcheck_path=Merkle_list.check_pathletpath_depth=Merkle_list.path_depthletmerklize_listmessages=lettree=tree_of_messagesmessagesinroottreeendtypet={inbox_length:int;cumulated_size:int;merkle_root:Merkle.root}let(=){inbox_length=inbox_length_left;cumulated_size=cumulated_size_left;merkle_root=merkle_root_left;}{inbox_length=inbox_length_right;cumulated_size=cumulated_size_right;merkle_root=merkle_root_right;}=Compare.Int.(inbox_length_left=inbox_length_right)&&Compare.Int.(cumulated_size_left=cumulated_size_right)&&Merkle.(merkle_root_left=merkle_root_right)letencoding=letopenData_encodinginconv(fun{inbox_length;cumulated_size;merkle_root}->(inbox_length,cumulated_size,merkle_root))(fun(inbox_length,cumulated_size,merkle_root)->{inbox_length;cumulated_size;merkle_root})(obj3(req"inbox_length"int31)(req"cumulated_size"int31)(req"merkle_root"Merkle.root_encoding))letempty={inbox_length=0;cumulated_size=0;merkle_root=Merkle_list.empty}letsize=Z.of_int@@Data_encoding.Binary.lengthencodingemptyletppfmt{inbox_length;cumulated_size;merkle_root}=Format.fprintffmt"Inbox with length %d, size %d, merkle root %a"inbox_lengthcumulated_sizeMerkle.pp_rootmerkle_root