123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)typet=Sc_rollup_bond_idofSc_rollup_repr.tincludeCompare.Make(structtypenonrect=tletcompareid1id2=match(id1,id2)with|Sc_rollup_bond_idid1,Sc_rollup_bond_idid2->Sc_rollup_repr.Address.compareid1id2end)letencoding=letopenData_encodinginletcase=function|Tagtag->(* The tag was used by old variant. It have been removed in
protocol proposal O, it can be unblocked in the future. *)letto_tx_rollup_reserved_tag=0inassert(Compare.Int.(tag<>to_tx_rollup_reserved_tag));case(Tagtag)|_asc->casecindef"bond_id"@@union[case(Tag1)~title:"Smart_rollup_bond_id"(obj1(req"smart_rollup"Sc_rollup_repr.encoding))(functionSc_rollup_bond_idid->Someid)(funid->Sc_rollup_bond_idid);]letppppf=functionSc_rollup_bond_idid->Sc_rollup_repr.ppppfidletdestructid=(* String.starts_with from the stdlib 4.14, with [unsafe_get] replaced by
[get], comparators replaced by their versions in [Compare.*]. *)letstarts_with~prefixs=letopenStringinletlen_s=lengthsandlen_pre=lengthprefixinletrecauxi=ifCompare.Int.(i=len_pre)thentrueelseifCompare.Char.(getsi<>getprefixi)thenfalseelseaux(i+1)inCompare.Int.(len_s>=len_pre)&&aux0inifstarts_with~prefix:Sc_rollup_repr.Address.prefixidthenmatchSc_rollup_repr.Address.of_b58check_optidwith|Someid->Result.ok(Sc_rollup_bond_idid)|None->Result.error"Cannot parse smart rollup id"elseResult.error"Cannot parse rollup id"letconstruct=function|Sc_rollup_bond_idid->Sc_rollup_repr.Address.to_b58checkidletrpc_arg=RPC_arg.make~descr:"A bond identifier."~name:"bond_id"~construct~destruct()moduleInternal_for_test=structletdestruct=destructletconstruct=constructendmoduleIndex=structtypenonrect=tletpath_length=1letto_pathcl=letraw_key=Data_encoding.Binary.to_bytes_exnencodingcinlet(`Hexkey)=Hex.of_bytesraw_keyinkey::lletof_path=function|[key]->Option.bind(Hex.to_bytes(`Hexkey))(Data_encoding.Binary.of_bytes_optencoding)|_->Noneletrpc_arg=rpc_argletencoding=encodingletcompare=compareend