123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.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. *)(* *)(*****************************************************************************)moduleHeader=struct(* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3101
Datatype is mocked for the moment while the cryptography is not
provided by the environment. *)typet=intletencoding=Data_encoding.int31letpp=Format.pp_print_intendmoduleIndex=structtypet=intletmax_value=255letencoding=Data_encoding.uint8letpp=Format.pp_print_intletzero=0letof_intslot_index=ifCompare.Int.(slot_index<=max_value&&slot_index>=zero)thenSomeslot_indexelseNoneletto_intslot_index=slot_index[@@ocaml.inlinealways]letcompare=Compare.Int.compareendtypeheader=Header.ttypet={level:Raw_level_repr.t;index:Index.t;header:header}typeslot=tletmake~level~index~header={level;index;header}letencoding=letopenData_encodinginconv(fun{level;index;header}->(level,index,header))(fun(level,index,header)->{level;index;header})(obj3(req"level"Raw_level_repr.encoding)(req"index"Data_encoding.uint8)(req"header"Header.encoding))letppfmt{level;index;header}=Format.fprintffmt"level: %a index: %a header: %a"Raw_level_repr.pplevelFormat.pp_print_intindexHeader.ppheadermoduleSlot_market=struct(* DAL/FIXME https://gitlab.com/tezos/tezos/-/issues/3108
Think harder about this data structure and whether it can be
optimized. *)moduleSlot_index_map=Map.Make(Index)typet={length:int;slots:slotSlot_index_map.t}letinit~length=ifCompare.Int.(length<0)theninvalid_arg"Dal_slot_repr.Slot_market.init: length cannot be negative";letslots=Slot_index_map.emptyin{length;slots}letlength{length;_}=lengthletregistertnew_slot=ifnotCompare.Int.(0<=new_slot.index&&new_slot.index<t.length)thenNoneelselethas_changed=reffalseinletupdate=function|None->has_changed:=true;Somenew_slot|Somex->Somexinletslots=Slot_index_map.updatenew_slot.indexupdatet.slotsinlett={twithslots}inSome(t,!has_changed)letcandidatest=t.slots|>Slot_index_map.to_seq|>Seq.mapsnd|>List.of_seqend