123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129(*****************************************************************************)(* *)(* 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=|Tx_rollup_bond_idofTx_rollup_repr.t|Sc_rollup_bond_idofSc_rollup_repr.tincludeCompare.Make(structtypenonrect=tletcompareid1id2=match(id1,id2)with|Tx_rollup_bond_idid1,Tx_rollup_bond_idid2->Tx_rollup_repr.compareid1id2|Sc_rollup_bond_idid1,Sc_rollup_bond_idid2->Sc_rollup_repr.Address.compareid1id2|Tx_rollup_bond_id_,Sc_rollup_bond_id_->-1|Sc_rollup_bond_id_,Tx_rollup_bond_id_->1end)letencoding=letopenData_encodingindef"bond_id"@@union[case(Tag0)~title:"Tx_rollup_bond_id"(obj1(req"tx_rollup"Tx_rollup_repr.encoding))(functionTx_rollup_bond_idid->Someid|_->None)(funid->Tx_rollup_bond_idid);case(Tag1)~title:"Smart_rollup_bond_id"(obj1(req"smart_rollup"Sc_rollup_repr.encoding))(functionSc_rollup_bond_idid->Someid|_->None)(funid->Sc_rollup_bond_idid);]letppppf=function|Tx_rollup_bond_idid->Tx_rollup_repr.ppppfid|Sc_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:Tx_rollup_prefixes.rollup_address.prefixidthenmatchTx_rollup_repr.of_b58check_optidwith|Someid->Result.ok(Tx_rollup_bond_idid)|None->Result.error"Cannot parse transaction rollup id"elseifstarts_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|Tx_rollup_bond_idid->Tx_rollup_repr.to_b58checkid|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