123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264(*****************************************************************************)(* *)(* 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_monadclasstype['pr]gen_simple=objectmethodcall_service:'m'p'q'i'o.(([<Resto.meth]as'm),'pr,'p,'q,'i,'o)RPC_service.t->'p->'q->'i->'otzresultLwt.tendclasstype['pr]gen_streamed=objectmethodcall_streamed_service:'m'p'q'i'o.(([<Resto.meth]as'm),'pr,'p,'q,'i,'o)RPC_service.t->on_chunk:('o->unit)->on_close:(unit->unit)->'p->'q->'i->(unit->unit)tzresultLwt.tendclasstype['pr]gen=objectinherit['pr]gen_simpleinherit['pr]gen_streamedendclasstypesimple=objectinherit[unit]gen_simpleendclasstypestreamed=objectinherit[unit]gen_streamedendclasstypet=objectinheritsimpleinheritstreamedendtype('o,'e)rest_result=[`Okof'o|`Conflictof'e|`Errorof'e|`Forbiddenof'e|`Not_foundof'e|`Goneof'e|`Unauthorizedof'e]tzresultclasstypejson=objectinherittmethodgeneric_json_call:RPC_service.meth->?body:Data_encoding.json->Uri.t->(Data_encoding.json,Data_encoding.jsonoption)rest_resultLwt.tmethodbase:Uri.tendtypeerror+=|Not_foundof{meth:RPC_service.meth;uri:Uri.t}|Goneof{meth:RPC_service.meth;uri:Uri.t}|Generic_errorof{meth:RPC_service.meth;uri:Uri.t}letbase=Uri.make~scheme:"ocaml"()letnot_foundspq=let{RPC_service.meth;uri;_}=RPC_service.forge_partial_requests~basepqinfail(Not_found{meth;uri})letgonespq=let{RPC_service.meth;uri;_}=RPC_service.forge_partial_requests~basepqinfail(Gone{meth;uri})letgeneric_errorspq=let{RPC_service.meth;uri;_}=RPC_service.forge_partial_requests~basepqinfail(Generic_error{meth;uri})class['pr]of_directory(dir:'prRPC_directory.t)=objectmethodcall_service:'m'p'q'i'o.(([<Resto.meth]as'm),'pr,'p,'q,'i,'o)RPC_service.t->'p->'q->'i->'otzresultLwt.t=funspqi->RPC_directory.transparent_lookupdirspqi>>=function|`Okv|`OkChunkv->returnv|`OkStream{next;shutdown}->(next()>>=function|Somev->shutdown();returnv|None->shutdown();not_foundspq)|`GoneNone->gonespq|`Not_foundNone->not_foundspq|`Unauthorized(Someerr)|`Forbidden(Someerr)|`Gone(Someerr)|`Not_found(Someerr)|`Conflict(Someerr)|`Error(Someerr)->Lwt.return_errorerr|`UnauthorizedNone|`ErrorNone|`ForbiddenNone|`Created_|`ConflictNone|`No_content->generic_errorspqmethodcall_streamed_service:'m'p'q'i'o.(([<Resto.meth]as'm),'pr,'p,'q,'i,'o)RPC_service.t->on_chunk:('o->unit)->on_close:(unit->unit)->'p->'q->'i->(unit->unit)tzresultLwt.t=funs~on_chunk~on_closepqi->RPC_directory.transparent_lookupdirspqi>>=function|`OkStream{next;shutdown}->letrecloop()=next()>>=function|None->on_close();Lwt.return_unit|Somev->on_chunkv;loop()inlet_=loop()inreturnshutdown|`Okv|`OkChunkv->on_chunkv;on_close();return(fun()->())|`GoneNone->gonespq|`Not_foundNone->not_foundspq|`Unauthorized(Someerr)|`Forbidden(Someerr)|`Gone(Someerr)|`Not_found(Someerr)|`Conflict(Someerr)|`Error(Someerr)->Lwt.return_errorerr|`UnauthorizedNone|`ErrorNone|`ForbiddenNone|`Created_|`ConflictNone|`No_content->generic_errorspqendletmake_calls(ctxt:#simple)=ctxt#call_servicesletmake_call1sctxtx=make_callsctxt((),x)letmake_call2sctxtxy=make_callsctxt(((),x),y)letmake_call3sctxtxyz=make_callsctxt((((),x),y),z)typestopper=unit->unitletmake_streamed_calls(ctxt:#streamed)pqi=let(stream,push)=Lwt_stream.create()inleton_chunkv=push(Somev)andon_close()=pushNoneinctxt#call_streamed_services~on_chunk~on_closepqi>>=?funclose->return(stream,close)let()=letopenData_encodinginregister_error_kind`Branch~id:"RPC_context.Not_found"~title:"RPC lookup failed"~description:"RPC lookup failed. No RPC exists at the URL or the RPC tried to access \
non-existent data."(obj2(req"method"RPC_service.meth_encoding)(req"uri"RPC_encoding.uri_encoding))~pp:(funppf(meth,uri)->Format.fprintfppf"Did not find service: %s %a"(RPC_service.string_of_methmeth)Uri.pp_humuri)(functionNot_found{meth;uri}->Some(meth,uri)|_->None)(fun(meth,uri)->Not_found{meth;uri})let()=letopenData_encodinginregister_error_kind`Branch~id:"RPC_context.Gone"~title:"RPC lookup failed because of deleted data"~description:"RPC lookup failed. Block has been pruned and requested data deleted."(obj2(req"method"RPC_service.meth_encoding)(req"uri"RPC_encoding.uri_encoding))~pp:(funppf(meth,uri)->Format.fprintfppf"RPC lookup failed. Block has been pruned and requested data deleted, \
service: %s %a"(RPC_service.string_of_methmeth)Uri.pp_humuri)(functionGone{meth;uri}->Some(meth,uri)|_->None)(fun(meth,uri)->Gone{meth;uri})