12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 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. *)(* *)(*****************************************************************************)(* Conveniences to construct RPC directory
against a subcontext of the Node_context *)letget_headstore=letopenLwt_result_syntaxinlet*head=Node_context.last_processed_head_optstoreinmatchheadwith|None->failwith"No head"|Some{header={block_hash;_};_}->returnblock_hashletget_head_levelstore=letopenLwt_result_syntaxinlet*head=Node_context.last_processed_head_optstoreinmatchheadwith|None->failwith"No head"|Some{header={level;_};_}->returnlevelletget_finalizednode_ctxt=letopenLwt_result_syntaxinlet*level=Node_context.get_finalized_levelnode_ctxtinNode_context.hash_of_levelnode_ctxtlevelletget_last_cemented(node_ctxt:_Node_context.t)=protect@@fun()->letlcc=Reference.getnode_ctxt.lccinNode_context.hash_of_levelnode_ctxtlcc.levelletblock_of_prefixnode_ctxtblock=matchblockwith|`Head->get_headnode_ctxt|`Hashb->Lwt_result.returnb|`Levell->Node_context.hash_of_levelnode_ctxtl|`Finalized->get_finalizednode_ctxt|`Cemented->get_last_cementednode_ctxtletblock_level_of_idnode_ctxtblock=matchblockwith|`Head->get_head_levelnode_ctxt|`Hashb->Node_context.level_of_hashnode_ctxtb|`Levell->Lwt_result.returnl|`Finalized->Node_context.get_finalized_levelnode_ctxt|`Cemented->Lwt_result.return(Reference.getnode_ctxt.lcc).level