123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109(*****************************************************************************)(* *)(* 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_shell_servicesmoduletypeProxy_sig=sigvalprotocol_hash:Protocol_hash.t(** RPCs provided by the protocol *)valdirectory:Tezos_protocol_environment.rpc_contextTezos_rpc.Directory.t(** How to build the context to execute RPCs on *)valinitial_context:Proxy_getter.rpc_context_args->Context_hash.t->Tezos_protocol_environment.Context.ttzresultLwt.tvaltime_between_blocks:Tezos_rpc.Context.generic->Block_services.chain->Block_services.block->int64optiontzresultLwt.tincludeLight_proto.PROTO_RPCSendtypeproxy_environment=(moduleProxy_sig)letregistered:proxy_environmentlistref=ref[]letregister_proxy_contextm=let(moduleINCOMING_P:Proxy_sig)=minifList.exists(fun(moduleP:Proxy_sig)->Protocol_hash.(P.protocol_hash=INCOMING_P.protocol_hash))!registeredthenraise@@Invalid_argument(Format.asprintf"A proxy environment for protocol %a is registered already"Protocol_hash.ppINCOMING_P.protocol_hash)elseregistered:=m::!registeredletget_all_registered():proxy_environmentlist=!registeredletget_registered_proxy(printer:Tezos_client_base.Client_context.printer)(protocol_hash:Protocol_hash.t):proxy_environmenttzresultLwt.t=letopenLwt_result_syntaxinletavailable=!registeredinletproxy_opt=List.find_opt(fun(moduleProxy:Proxy_sig)->Protocol_hash.equalprotocol_hashProxy.protocol_hash)availableinmatchproxy_optwith|Someproxy->returnproxy|None->(matchavailablewith|[]->failwith"There are no proxy environments registered. --mode proxy cannot \
be honored."|fst_available::_->let(moduleProxy:Proxy_sig)=fst_availableinletfst_available_proto=Proxy.protocol_hashinlet*!()=printer#warning"requested protocol (%a) not found in available proxy \
environments: %a@;\
Proceeding with the first available protocol (%a). This will \
work if the mismatch is harmless, otherwise deserialization is \
the failure most likely to happen."Protocol_hash.ppprotocol_hash(Format.pp_print_list~pp_sep:Format.pp_print_spaceProtocol_hash.pp)((List.map(fun(moduleP:Proxy_sig)->P.protocol_hash))available)Protocol_hash.ppfst_available_protoinreturnfst_available)