123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 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. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contextmodulePlugin=structmoduleProto=Registerer.Registeredtypeblock_info=Protocol_client_context.Alpha_block_services.block_infoletparametric_constantschainblockctxt=letcpctxt=newProtocol_client_context.wrap_rpc_contextctxtinProtocol.Constants_services.parametriccpctxt(chain,block)letget_constantschainblockctxt=letopenLwt_result_syntaxinlet*parametric=parametric_constantschainblockctxtinlet{Constants.Parametric.feature_enable;number_of_slots;attestation_lag;attestation_threshold;cryptobox_parameters;blocks_per_epoch;}=parametric.dalinreturn{Dal_plugin.feature_enable;number_of_slots;attestation_lag;attestation_threshold;cryptobox_parameters;blocks_per_epoch;}letblock_info?chain?block~metadatactxt=letcpctxt=newProtocol_client_context.wrap_rpc_contextctxtinProtocol_client_context.Alpha_block_services.infocpctxt?chain?block~metadata()(* Turn the given value of type {!Protocol.Apply_operation_result.operation_result}
into a value of type {!Dal_plugin.operation_application_result}. *)letstatus_of_result=function|Protocol.Apply_operation_result.Applied_->Dal_plugin.Succeeded|_->Dal_plugin.Failedletget_published_slot_headers(block:block_info)=letopenLwt_result_syntaxinletopenProtocol.Alpha_contextinletapply_internalacc~source:__op_res=accinletapply(typekind)acc~source:_(op:kindmanager_operation)(result:(kind,_,_)Protocol.Apply_operation_result.operation_result)=matchopwith|Dal_publish_slot_headeroperation->(operation.slot_index,operation.commitment,status_of_resultresult)::acc|_->accinLayer1_services.(process_manager_operations[]block.operations{apply;apply_internal})|>List.map_es(fun(slot_index,commitment,status)->letpublished_level=block.header.shell.levelinletslot_index=Dal.Slot_index.to_intslot_indexinreturnDal_plugin.({published_level;slot_index;commitment},status))letget_committeectxt~level=letopenLwt_result_syntaxinletcpctxt=newProtocol_client_context.wrap_rpc_contextctxtinlet*?level=Raw_level.of_int32level|>Environment.wrap_tzresultinlet+pkh_to_shards=Plugin.RPC.Dal.dal_shardscpctxt(`Main,`Head0)~level()inList.fold_left(funacc(pkh,s)->Signature.Public_key_hash.Map.addpkhsacc)Signature.Public_key_hash.Map.emptypkh_to_shardsletattested_slot_headers(block:block_info)~number_of_slots=letopenResult_syntaxinlet*metadata=Option.to_resultblock.metadata~none:(TzTrace.make@@Layer1_services.Cannot_read_block_metadatablock.hash)inletconfirmed_slots=Option.value~default:Dal.Attestation.emptymetadata.protocol_data.dal_attestationinlet*all_slots=Dal.Slot_index.slots_range~number_of_slots~lower:0~upper:(number_of_slots-1)|>Environment.wrap_tzresultinList.filter(Dal.Attestation.is_attestedconfirmed_slots)all_slots|>Dal.Slot_index.to_int_list|>returnendlet()=Dal_plugin.register(modulePlugin)