123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020 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. *)(* *)(*****************************************************************************)openTezos_proxymoduleService=Tezos_rpc.ServicemoduleEvents=Proxy_eventsletrecprint_path:typeprp.(pr,p)Resto.Internal.path->stringlist=funpath->matchpathwith|Root->[]|Static(path,s)->s::print_pathpath|Dynamic(path,arg)->Printf.sprintf"<%s>"arg.descr.name::print_pathpath|DynamicTail(path,arg)->Printf.sprintf"<%s>"arg.descr.name::print_pathpath(* TODO Once https://gitlab.com/nomadic-labs/resto/-/issues/3 is
fixed, use the corresponding function from resto. The same applies
to print_path above.
And at the same time, do the same in the mockup mode; which
has these functions too. *)letprint_service:typepqio.(_,_,p,q,i,o)Service.t->string=funserv->letiserv=Service.Internal.to_serviceservinString.concat"/"(List.rev(print_pathiserv.path))letmethod_is_writer=function|`POST|`DELETE|`PUT|`PATCH->true|`GET->falseclasshttp_local_ctxt(printer:Tezos_client_base.Client_context.printer)(http_ctxt:Tezos_rpc.Context.generic)(mode:Proxy_services.mode)protocol:Tezos_rpc.Context.generic=letlocal_ctxt=Tezos_mockup_proxy.RPC_client.local_ctxt(Proxy_services.build_directoryprinterhttp_ctxtmodeprotocol)inletdispatch_local_or_distant~debug_name~local~distantmethpath=letopenLwt_syntaxinletmeth_string=Tezos_rpc.Service.string_of_methmethinletdelegate()=let*()=Events.(emitdelegate_to_http)(meth_string,debug_name,path)indistant()inifmethod_is_writermeththendelegate()elselet*r=local()inmatchrwith|Okx->let*()=Events.(emitdone_locally)(meth_string,debug_name,path)inreturn_okx|Error[Tezos_rpc.Context.Not_found_]->delegate()|Error_aserr->Lwt.returnerrinobjectmethodbase=Uri.emptymethodcall_service:'m'p'q'i'o.(([<Resto.meth]as'm),unit,'p,'q,'i,'o)Tezos_rpc.Service.t->'p->'q->'i->'otzresultLwt.t=funserviceparamsqueryinput->letlocal()=local_ctxt#call_serviceserviceparamsqueryinputinletdistant()=http_ctxt#call_serviceserviceparamsqueryinputinletmeth=Tezos_rpc.Service.methserviceindispatch_local_or_distant~debug_name:"call_service"~local~distantmeth@@print_serviceservicemethodcall_streamed_service:'m'p'q'i'o.(([<Resto.meth]as'm),'pr,'p,'q,'i,'o)Tezos_rpc.Service.t->on_chunk:('o->unit)->on_close:(unit->unit)->'p->'q->'i->(unit->unit)tzresultLwt.t=funservice~on_chunk~on_closeparamsqueryinput->letlocal()=local_ctxt#call_streamed_serviceservice~on_chunk~on_closeparamsqueryinputinletdistant()=http_ctxt#call_streamed_serviceservice~on_chunk~on_closeparamsqueryinputinletmeth=Tezos_rpc.Service.methserviceindispatch_local_or_distant~debug_name:"call_streamed_service"~local~distantmeth@@print_serviceservicemethodgeneric_media_type_call:Service.meth->?body:Data_encoding.json->Uri.t->Tezos_rpc.Context.generic_call_resultTezos_error_monad.Error_monad.tzresultLwt.t=letopenLwt_syntaxinfunmeth?bodyuri->letmeth_string=Tezos_rpc.Service.string_of_methmethinleturi_string=Uri.to_stringuriinletdelegate()=let*()=Events.(emitdelegate_media_type_call_to_http)(meth_string,uri_string)inhttp_ctxt#generic_media_type_callmeth?bodyuriinifmethod_is_writermeththendelegate()elselet*answer=local_ctxt#generic_media_type_callmeth?bodyuriinmatchanswerwith|Ok(`Json(`Not_found_))|Ok(`Binary(`Not_found_))|Ok(`Other(_,`Not_found_))|Error[Tezos_rpc.Context.Not_found_]->delegate()|Okx->let*()=Events.(emitdone_media_type_call_locally)(meth_string,uri_string)inreturn_okx|Error_aserr->Lwt.returnerrend