123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021-2022 Marigold <contact@marigold.dev> *)(* Copyright (c) 2021-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. *)(* *)(*****************************************************************************)typeerror+=(* `Permanent *)Invalid_rollup_notationofstringlet()=letopenData_encodinginregister_error_kind`Permanent~id:"rollup.invalid_tx_rollup_notation"~title:"Invalid tx rollup notation"~pp:(funppfx->Format.fprintfppf"Invalid tx rollup notation %S"x)~description:"A malformed tx rollup notation was given to an RPC or in a script."(obj1(req"notation"(stringPlain)))(functionInvalid_rollup_notationloc->Someloc|_->None)(funloc->Invalid_rollup_notationloc)moduleHash=structletrollup_hash=Tx_rollup_prefixes.rollup_address.b58check_prefixmoduleH=Blake2B.Make(Base58)(structletname="Rollup_hash"lettitle="A rollup ID"letb58check_prefix=rollup_hashletsize=SomeTx_rollup_prefixes.rollup_address.hash_sizeend)includeHlet()=Tx_rollup_prefixes.(check_encodingrollup_addressb58check_encoding)includePath_encoding.Make_hex(H)endtypet=Hash.tmoduleCompare_impl=Compare.Make(structtypenonrect=tletcomparer1r2=Hash.comparer1r2end)includeCompare_implletin_memory_size_=letopenCache_memory_helpersinheader_size+!word_size+!string_size_genTx_rollup_prefixes.rollup_address.hash_sizeletto_b58checkrollup=Hash.to_b58checkrollupletof_b58data=functionHash.Datahash->Somehash|_->Noneletof_b58check_opts=Option.bind(Base58.decodes)of_b58dataletof_b58checks=matchof_b58check_optswith|Somehash->okhash|_->error(Invalid_rollup_notations)letppppfhash=Hash.ppppfhashletencoding=letopenData_encodingindef"tx_rollup_id"~title:"A tx rollup handle"~description:"A tx rollup notation as given to an RPC or inside scripts, is a base58 \
tx rollup hash"@@splitted~binary:Hash.encoding~json:(convto_b58check(funs->matchof_b58checkswith|Oks->s|Error_->Json.cannot_destruct"Invalid tx rollup notation.")(stringPlain))letoriginated_tx_rollupnonce=letdata=Data_encoding.Binary.to_bytes_exnOrigination_nonce.encodingnonceinHash.hash_bytes[data]letrpc_arg=letconstruct=to_b58checkinletdestructhash=Result.map_error(fun_->"Cannot parse tx rollup id")(of_b58checkhash)inRPC_arg.make~descr:"A tx rollup identifier encoded in b58check."~name:"tx_rollup_id"~construct~destruct()moduleIndex=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=compareendmoduleCmp=structtypenonrect=tletcompare=compareendmoduleSet=Set.Make(Cmp)moduleMap=Map.Make(Cmp)