123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)openAlpha_contexttyperpc_context={block_hash:Block_hash.t;block_header:Block_header.shell_header;context:Alpha_context.t;}letrpc_init({block_hash;block_header;context}:Updater.rpc_context)mode=letopenLwt_result_syntaxinlettimestamp=block_header.timestampinletlevel=matchmodewith|`Head_level->block_header.level|`Successor_level->Int32.succblock_header.levelinlet+context,_,_=Alpha_context.prepare~level~predecessor_timestamp:timestamp~timestampcontextin{block_hash;block_header;context}letrpc_services=ref(RPC_directory.empty:Updater.rpc_contextRPC_directory.t)letregister0_fullctxt~chunkedsf=letopenLwt_result_syntaxinrpc_services:=RPC_directory.register~chunked!rpc_servicess(functxtqi->let*ctxt=rpc_initctxt`Head_levelinfctxtqi)letregister0~chunkedsf=register0_fullctxt~chunkeds(fun{context;_}->fcontext)letregister0_noctxt~chunkedsf=rpc_services:=RPC_directory.register~chunked!rpc_servicess(fun_qi->fqi)letregister1_fullctxt~chunkedsf=letopenLwt_result_syntaxinrpc_services:=RPC_directory.register~chunked!rpc_servicess(fun(ctxt,arg)qi->let*ctxt=rpc_initctxt`Head_levelinfctxtargqi)letregister1~chunkedsf=register1_fullctxt~chunkeds(fun{context;_}x->fcontextx)letregister2_fullctxt~chunkedsf=letopenLwt_result_syntaxinrpc_services:=RPC_directory.register~chunked!rpc_servicess(fun((ctxt,arg1),arg2)qi->let*ctxt=rpc_initctxt`Head_levelinfctxtarg1arg2qi)letregister2~chunkedsf=register2_fullctxt~chunkeds(fun{context;_}a1a2qi->fcontexta1a2qi)letopt_register0_fullctxt~chunkedsf=letopenLwt_result_syntaxinrpc_services:=RPC_directory.opt_register~chunked!rpc_servicess(functxtqi->let*ctxt=rpc_initctxt`Head_levelinfctxtqi)letopt_register0~chunkedsf=opt_register0_fullctxt~chunkeds(fun{context;_}->fcontext)letopt_register1_fullctxt~chunkedsf=letopenLwt_result_syntaxinrpc_services:=RPC_directory.opt_register~chunked!rpc_servicess(fun(ctxt,arg)qi->let*ctxt=rpc_initctxt`Head_levelinfctxtargqi)letopt_register1~chunkedsf=opt_register1_fullctxt~chunkeds(fun{context;_}x->fcontextx)letopt_register2_fullctxt~chunkedsf=letopenLwt_result_syntaxinrpc_services:=RPC_directory.opt_register~chunked!rpc_servicess(fun((ctxt,arg1),arg2)qi->let*ctxt=rpc_initctxt`Head_levelinfctxtarg1arg2qi)letopt_register2~chunkedsf=opt_register2_fullctxt~chunkeds(fun{context;_}a1a2qi->fcontexta1a2qi)letget_rpc_services()=letopenLwt_syntaxinletp=RPC_directory.map(func->let+ctxt=rpc_initc`Head_levelinmatchctxtwith|Errort->raise(Failure(Format.asprintf"%a"Error_monad.pp_tracet))|Okc->c.context)(Storage_description.build_directoryAlpha_context.description)inRPC_directory.register_dynamic_directory!rpc_servicesRPC_path.(open_root/"context"/"raw"/"json")(fun_->Lwt.returnp)