123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.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. *)(* *)(*****************************************************************************)openError_monadmoduleMakeRaw(H:sigtypetvalname:stringvalof_bytes_opt:Bytes.t->toptionvalto_string:t->stringvalof_string_opt:string->toptionend)=structletof_bytes_exns=matchH.of_bytes_optswith|None->Format.kasprintfinvalid_arg"of_bytes_exn (%s)"H.name|Somepk->pkletof_bytess=matchH.of_bytes_optswith|None->error_with"of_bytes (%s)"H.name|Somepk->Okpkletof_string_exns=matchH.of_string_optswith|None->Format.kasprintfinvalid_arg"of_string_exn (%s)"H.name|Somepk->pkletof_strings=matchH.of_string_optswith|None->error_with"of_string (%s)"H.name|Somepk->Okpkletto_hexs=Hex.of_string(H.to_strings)letof_hex_opts=Option.bind(Hex.to_strings)H.of_string_optletof_hex_exns=matchof_hex_optswith|Somex->x|None->Format.kasprintfinvalid_arg"of_hex_exn (%s)"H.nameletof_hexs=matchof_hex_optswith|None->error_with"of_hex (%s)"H.name|Somepk->OkpkendmoduleMakeB58(H:sigtypetvalname:stringvalb58check_encoding:tBase58.encodingend)=structletof_b58check_opts=Base58.simple_decodeH.b58check_encodingsletof_b58check_exns=matchof_b58check_optswith|Somex->x|None->Format.kasprintfStdlib.failwith"Unexpected data (%s)"H.nameletof_b58checks=matchof_b58check_optswith|Somex->Okx|None->error_with"Failed to read a b58check_encoding data (%s): %S"H.namesletto_b58checks=Base58.simple_encodeH.b58check_encodingsletto_short_b58checks=String.sub(to_b58checks)0(10+String.length(Base58.prefixH.b58check_encoding))endmoduleMakeEncoder(H:sigtypetvaltitle:stringvalname:stringvalto_b58check:t->stringvalto_short_b58check:t->stringvalof_b58check:string->ttzresultvalof_b58check_exn:string->tvalof_b58check_opt:string->toptionvalraw_encoding:tData_encoding.tend)=structletppppft=Format.pp_print_stringppf(H.to_b58checkt)letpp_shortppft=Format.pp_print_stringppf(H.to_short_b58checkt)letencoding=letopenData_encodinginsplitted~binary:(obj1(reqH.nameH.raw_encoding))~json:(defH.name~title:(H.title^" (Base58Check-encoded)")@@convH.to_b58check(Data_encoding.Json.wrap_errorH.of_b58check_exn)string)letof_b58check=H.of_b58checkletrpc_arg=Tezos_rpc.Arg.make~name:H.name~descr:(Format.asprintf"%s (Base58Check-encoded)"H.name)~destruct:(funs->matchH.of_b58check_optswith|None->Error(Format.asprintf"failed to decode Base58Check-encoded data (%s): %S"H.names)|Somev->Okv)~construct:H.to_b58check()endmoduleMakeIterator(H:sigtypetvalencoding:tData_encoding.tvalcompare:t->t->intvalequal:t->t->boolvalhash:t->int(* [seeded_hash] is a seeded alternative to [hash] meant to be used to create
seeded hashtables. Check {!Stdlib.Hashtbl.MakeSeeded} for details. *)valseeded_hash:int->t->intend)=structmoduleSet=structincludeSet.Make(structtypet=H.tletcompare=H.compareend)exceptionFoundofeltletrandom_elts=letn=Random.int(cardinals)intryignore(fold(funxi->ifi=nthenraise(Foundx);i+1)s0:int);assertfalsewithFoundx->xletencoding=Data_encoding.convelements(funl->List.fold_left(funmx->addxm)emptyl)Data_encoding.(listH.encoding)endmoduleTable=structincludeHashtbl.MakeSeeded(structtypet=H.t(* See [src/lib_base/tzPervasives.ml] for an explanation *)[@@@ocaml.warning"-32"]lethash=H.seeded_hashletseeded_hash=H.seeded_hash[@@@ocaml.warning"+32"]letequal=H.equalend)letencodingarg_encoding=Data_encoding.conv(funh->fold(funkvl->(k,v)::l)h[])(funl->leth=create(List.lengthl)inList.iter(fun(k,v)->addhkv)l;h)Data_encoding.(list(tup2H.encodingarg_encoding))endmoduleMap=structincludeMap.Make(structtypet=H.tletcompare=H.compareend)letencodingarg_encoding=Data_encoding.convbindings(funl->List.fold_left(funm(k,v)->addkvm)emptyl)Data_encoding.(list(tup2H.encodingarg_encoding))endmoduleError_table=structincludeTezos_error_monad.TzLwtreslib.Hashtbl.Make_es(H)endmoduleWeakRingTable=structleth_encoding=H.encodingincludeAches.Vache.Map(Aches.Vache.FIFO_Sloppy)(Aches.Vache.Weak)(H)letencodingarg_encoding=letopenData_encodinginconv(funh->(capacityh,fold(funkvl->(k,v)::l)h[]))(fun(capacity,l)->leth=createcapacityinList.iter(fun(k,v)->replacehkv)l;h)@@obj2(req"capacity"int31)(req"content"@@list(tup2h_encodingarg_encoding))endendmoduleMake(H:sigtypetvaltitle:stringvalname:stringvalb58check_encoding:tBase58.encodingvalraw_encoding:tData_encoding.tvalcompare:t->t->intvalequal:t->t->boolvalhash:t->intvalseeded_hash:int->t->intend)=structincludeMakeB58(H)includeMakeEncoder(structincludeHletto_b58check=to_b58checkletto_short_b58check=to_short_b58checkletof_b58check=of_b58checkletof_b58check_opt=of_b58check_optletof_b58check_exn=of_b58check_exnend)includeMakeIterator(structincludeHletencoding=encodingend)end