12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 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. *)(* *)(*****************************************************************************)typesources_config={min_agreement:float;uris:Uri.tlist}letsources_config_to_uris({uris;_}:sources_config)=urisletdefault_agreement=1.0letsources_encoding=letopenData_encodinginobj2(opt"min_agreement"float)(req"uris"(liststring))letsources_config_encoding=letopenData_encodinginconv(funsrcs_config->(Somesrcs_config.min_agreement,List.mapUri.to_stringsrcs_config.uris))(fun(min_agreement,uris)->{min_agreement=Option.valuemin_agreement~default:default_agreement;uris=List.mapUri.of_stringuris;})sources_encodingletmk_sources_config~min_agreement~uris=ifmin_agreement<=0.0||1.0<min_agreementthenErrorFormat.(sprintf"min_agreement value must be within 0 (exclusive) and 1 (inclusive) \
but you provided %f"min_agreement)elseifCompare.List_length_with.(uris<2)thenErrorFormat.(asprintf"A minimum of 2 endpoints is required in Light mode: one endpoint to \
retrieve data and one to validate data. You only provided %a"(pp_print_listUri.pp_hum)uris)elseOk{min_agreement;uris}letexample_sources={|{"min_agreement": 1.0, "uris": ["http://localhost:8732", "https://localhost:8733"]}|}letdestruct_sources_configjson=let{min_agreement;uris}=Data_encoding.Json.destructsources_config_encodingjsoninmk_sources_config~min_agreement~uristypesources={min_agreement:float;endpoints:(Uri.t*Tezos_rpc.Context.simple)list;}letsources_config_to_sourcesrpc_context_builder{min_agreement;uris}=letendpoints=List.map(funu->(u,rpc_context_builderu))urisin{min_agreement;endpoints}lethash_of_block(block:Tezos_shell_services.Block_services.block):Block_hash.toption=matchblockwith|`Hash(h,0)->Someh|`Alias(_,_)|`Genesis|`Head_|`Level_|`Hash(_,_)->None