123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs, <contact@nomadic-labs.com> *)(* Copyright (c) 2022 Marigold, <contact@marigold.dev> *)(* 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. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contexttypemessage_result=|InterpretedofTx_rollup_l2_apply.Message_result.t|Discardedoftztracetypel2_context_hash={irmin_hash:Tx_rollup_l2_context_hash.t;tree_hash:Context_hash.t;}typemessage={message:Tx_rollup_message.t;result:message_result;l2_context_hash:l2_context_hash;}typet=messagelistletmessage_result_encoding=letopenData_encodinginunion[case~title:"interpreted"(Tag0)Tx_rollup_l2_apply.Message_result.encoding(functionInterpretedr->Somer|_->None)(funr->Interpretedr);case~title:"discarded"(Tag1)(obj1(req"discarded"(obj1(req"reason"Error_monad.trace_encoding))))(functionDiscardede->Somee|_->None)(fune->Discardede);]letl2_context_hash_encoding=letopenData_encodinginconv(fun{irmin_hash;tree_hash}->(irmin_hash,tree_hash))(fun(irmin_hash,tree_hash)->{irmin_hash;tree_hash})(obj2(req"irmin_hash"Tx_rollup_l2_context_hash.encoding)(req"tree_hash"Context_hash.encoding))letmessage_encoding=letopenData_encodinginconv(fun{message;result;l2_context_hash}->(message,result,l2_context_hash))(fun(message,result,l2_context_hash)->{message;result;l2_context_hash})(obj3(req"message"Tx_rollup_message.encoding)(req"result"message_result_encoding)(req"l2_context_hash"l2_context_hash_encoding))letencoding=letopenData_encodinginlistmessage_encodingletmerkle_rootinbox=letmessage_hashes=List.map(funmsg->Tx_rollup_message_hash.hash_uncarbonatedmsg.message)inboxinTx_rollup_inbox.Merkle.merklize_listmessage_hashesletto_protoinbox=letinbox_length=List.lengthinboxinletcumulated_size=List.fold_left(funacc{message;_}->(* TORU/FIXME: https://gitlab.com/tezos/tezos/-/issues/2957
We need to expose [Alpha_context.Tx_rollup_message.size]. *)acc+Tx_rollup_message_repr.size(Obj.magicmessage))0inboxinletmerkle_root=merkle_rootinboxinTx_rollup_inbox.{inbox_length;cumulated_size;merkle_root}letproto_message_resultsinbox=List.map(funmsg->letwithdrawals=matchmsg.resultwith|Discarded_->[]|Interpreted(_result,withdrawals)->withdrawalsinTx_rollup_message_result.{context_hash=msg.l2_context_hash.tree_hash;withdraw_list_hash=Tx_rollup_withdraw_list_hash.hash_uncarbonatedwithdrawals;})inbox