123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148(*****************************************************************************)(* *)(* 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_contextopenApply_resultsopenProtocol_client_contextopenAlpha_block_servicestypeerror+=Cannot_read_block_metadataofBlock_hash.tlet()=register_error_kind~id:"cannot_read_receipt_of_block"~title:"Cannot read receipt of block from L1"~description:"The receipt of a block could not be read."~pp:(funppfhash->Format.fprintfppf"Could not read block receipt for block with hash %a."Block_hash.pphash)`TemporaryData_encoding.(obj1(req"hash"Block_hash.encoding))(functionCannot_read_block_metadatahash->Somehash|_->None)(funhash->Cannot_read_block_metadatahash)type'accusuccessful_operation_processor={apply:'kind.'accu->source:public_key_hash->'kindmanager_operation->'kindApply_results.successful_manager_operation_result->'accu;apply_internal:'kind.'accu->source:public_key_hash->'kindApply_internal_results.internal_operation->'kindApply_internal_results.successful_internal_operation_result->'accu;}type'accuoperation_processor={apply:'kind.'accu->source:public_key_hash->'kindmanager_operation->'kindApply_results.manager_operation_result->'accu;apply_internal:'kind.'accu->source:public_key_hash->'kindApply_internal_results.internal_operation->'kindApply_internal_results.internal_operation_result->'accu;}letprocess_manager_operationsoperationsaccuf=letrecon_operation_and_result:typekind._->kindApply_results.contents_and_result_list->_=funaccu->function|Single_and_result(Manager_operation{operation;source;_},Manager_operation_result{operation_result;internal_operation_results;_})->letaccu=f.applyaccu~sourceoperationoperation_resultinon_internal_operationsaccusourceinternal_operation_results|Single_and_result(_,_)->accu|Cons_and_result(Manager_operation{operation;source;_},Manager_operation_result{operation_result;internal_operation_results;_},rest)->letaccu=f.applyaccu~sourceoperationoperation_resultinletaccu=on_internal_operationsaccusourceinternal_operation_resultsinon_operation_and_resultaccurestandon_internal_operationsaccusourceinternal_operation_results=letopenApply_internal_resultsinList.fold_left(funaccu(Internal_operation_result(operation,result))->f.apply_internalaccu~sourceoperationresult)accuinternal_operation_resultsinletprocess_contentsaccu({protocol_data=Operation_data{contents;_};receipt;_}:operation)=matchreceiptwith|Empty|Too_large|ReceiptNo_operation_metadata->(* This should case should not happen between [operations] is supposed
to be retrieved with `force_metadata:true` and assuming that the
tezos node is running in archive mode. *)assertfalse|Receipt(Operation_metadata{contents=results;_})->(matchApply_results.kind_equal_listcontentsresultswith|SomeEq->on_operation_and_resultaccu@@Apply_results.pack_contents_listcontentsresults|None->(* Should not happen *)assertfalse)inletprocess_operations=List.fold_leftprocess_contentsinList.fold_leftprocess_operationsoperationsacculetprocess_applied_manager_operationsoperationsaccu(f:_successful_operation_processor)=letapply(typekind)accu~source(operation:kindmanager_operation)(result:kindApply_results.manager_operation_result)=matchresultwith|Appliedresult->f.applyaccu~sourceoperationresult|_->accuinletapply_internal(typekind)accu~source(operation:kindApply_internal_results.internal_operation)(result:kindApply_internal_results.internal_operation_result)=matchresultwith|Appliedresult->f.apply_internalaccu~sourceoperationresult|_->accuinprocess_manager_operationsoperationsaccu{apply;apply_internal}