123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)typedeposit={sender:Signature.Public_key_hash.t;destination:Tx_rollup_l2_address.Indexable.value;ticket_hash:Ticket_hash_repr.t;amount:Tx_rollup_l2_qty.t;}letdeposit_encoding=letopenData_encodinginconv(fun{sender;destination;ticket_hash;amount}->(sender,destination,ticket_hash,amount))(fun(sender,destination,ticket_hash,amount)->{sender;destination;ticket_hash;amount})@@obj4(req"sender"Signature.Public_key_hash.encoding)(req"destination"Tx_rollup_l2_address.Indexable.value_encoding)(req"ticket_hash"Ticket_hash_repr.encoding)(req"amount"Tx_rollup_l2_qty.encoding)letbatch_encoding=letopenData_encodinginletjson=convBytes.of_stringBytes.to_stringbytesinsplitted~json~binary:stringtypet=Batchofstring|Depositofdepositletencoding=letopenData_encodinginunion~tag_size:`Uint8[case(Tag0)~title:"Batch"(obj1(req"batch"batch_encoding))(functionBatchbatch->Somebatch|_->None)(funbatch->Batchbatch);case(Tag1)~title:"Deposit"(obj1(req"deposit"deposit_encoding))(functionDepositdeposit->Somedeposit|_->None)(fundeposit->Depositdeposit);]letppfmt=letopenFormatinfunction|Batchstr->letsubsize=10inletstr,ellipsis=ifCompare.Int.(subsize<String.lengthstr)thenletsubstring=String.substr0subsizein(substring,"...")else(str,"")infprintffmt"@[<hov 2>Batch:@ %s%s@]"(Hex.of_stringstr|>Hex.show)ellipsis|Deposit{sender;destination;ticket_hash;amount}->fprintffmt"@[<hov 2>Deposit:@ sender=%a,@ destination=%a,@ ticket_hash=%a,@ \
amount:%a@]"Signature.Public_key_hash.ppsenderTx_rollup_l2_address.Indexable.ppdestinationTicket_hash_repr.ppticket_hashTx_rollup_l2_qty.ppamountletsize=function|Batchbatch->String.lengthbatch|Deposit{sender=_;destination=d;ticket_hash=_;amount=_}->(* Size of a BLS public key, that is the underlying type of a
l2 address. See [Tx_rollup_l2_address] *)letsender_size=Signature.Public_key_hash.sizein(* Size of a BLS public key, that is the underlying type of a
l2 address. See [Tx_rollup_l2_address] *)letdestination_size=Tx_rollup_l2_address.Indexable.sizedin(* Size of a [Script_expr_hash.t], that is the underlying type
of [Ticket_hash_repr.t]. *)letkey_hash_size=32in(* [int64] *)letamount_size=8insender_size+destination_size+key_hash_size+amount_size