123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2023 Functori, <contact@functori.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. *)(* *)(*****************************************************************************)moduleHash=Inbox_hashmoduleSkip_list_parameters=structletbasis=4endmoduleSkip_list=Skip_list.Make(Skip_list_parameters)moduleV1=structtypelevel_proof={hash:Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.t;level:int32;}letlevel_proof_encoding=letopenData_encodinginconv(fun{hash;level}->(hash,level))(fun(hash,level)->{hash;level})(obj2(req"hash"Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.encoding)(req"level"int32))letequal_level_proof{hash;level}level_proof_2=Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.equalhashlevel_proof_2.hash&&Int32.equallevellevel_proof_2.leveltypehistory_proof=(level_proof,Hash.t)Skip_list.celllethash_history_proofcell=let{hash;level}=Skip_list.contentcellinletback_pointers_hashes=Skip_list.back_pointerscellinTezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.to_byteshash::(level|>Int32.to_string|>Bytes.of_string)::List.mapHash.to_bytesback_pointers_hashes|>Hash.hash_bytesletequal_history_proof=Skip_list.equalHash.equalequal_level_prooflethistory_proof_encoding:history_proofData_encoding.t=Skip_list.encodingHash.encodinglevel_proof_encodingletpp_level_prooffmt{hash;level}=Format.fprintffmt"hash: %a@,level: %ld"Tezos_crypto.Hashed.Smart_rollup_merkelized_payload_hashes_hash.pphashlevelletpp_history_prooffmthistory_proof=(Skip_list.pp~pp_content:pp_level_proof~pp_ptr:Hash.pp)fmthistory_proof(* An inbox is composed of a metadata of type {!t}, and a [level witness]
representing the messages of the current level (held by the
[Raw_context.t] in the protocol).
The metadata contains :
- [level] : the inbox level ;
- [old_levels_messages] : a witness of the inbox history.
*)typet={level:int32;old_levels_messages:history_proof}letequalinbox1inbox2=(* To be robust to addition of fields in [t]. *)let{level;old_levels_messages}=inbox1inInt32.equallevelinbox2.level&&equal_history_proofold_levels_messagesinbox2.old_levels_messagesletppfmt{level;old_levels_messages}=Format.fprintffmt"@[<hov 2>{ level = %ld@;old_levels_messages = %a@;}@]"levelpp_history_proofold_levels_messageslethashinbox=hash_history_proofinbox.old_levels_messagesletinbox_levelinbox=inbox.levelletold_levels_messagesinbox=inbox.old_levels_messagesletcurrent_witnessinbox=let{hash;_}=Skip_list.contentinbox.old_levels_messagesinhashletencoding=Data_encoding.(conv(fun{level;old_levels_messages}->(level,old_levels_messages))(fun(level,old_levels_messages)->{level;old_levels_messages})(obj2(req"level"int32)(req"old_levels_messages"history_proof_encoding)))endtypeversioned=V1ofV1.tletversioned_encoding=letopenData_encodinginunion[case~title:"smart_rollup_inbox.v1"(Tag0)V1.encoding(functionV1inbox->Someinbox)(funinbox->V1inbox);]includeV1letof_versioned=functionV1inbox->inbox[@@inline]letto_versionedinbox=V1inbox[@@inline]