12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)openProtocolmoduleDemo_block_services=Block_services.Make(Protocol)(Protocol)letbake(cctxt:Protocol_client_context.full)message:unittzresultLwt.t=Demo_block_services.Mempool.pending_operationscctxt()>>=?fun{validated;_}->letoperations=List.mapsndvalidatedinletblock_header_data=Header.createmessageinDemo_block_services.Helpers.Preapply.blockcctxt[operations]~protocol_data:block_header_data>>=?fun(shell,preapply_result)->letblock_header_data_encoded=Data_encoding.Binary.to_bytes_exnHeader.encodingblock_header_datainletheader:Block_header.t={shell;protocol_data=block_header_data_encoded}inletheader_encoded=Data_encoding.Binary.to_bytes_exnBlock_header.encodingheaderinletpreapply_result=WithExceptions.Option.get~loc:__LOC__@@List.hdpreapply_resultinletoperations=[List.mapsndpreapply_result.applied]inShell_services.Injection.blockcctxtheader_encodedoperations>>=?funblock_hash->cctxt#message"Injected block %a"Block_hash.pp_shortblock_hash>>=fun()->return_unitletoperation_encoding=letopenData_encodinginmerge_objsOperation.shell_header_encoding(obj1(req"contents"Proto_operation.encoding))letforge_op=Data_encoding.Binary.to_bytes_exnoperation_encodingletinject_op(cctxt:Protocol_client_context.full)(pop:Proto_operation.t)=Demo_block_services.hashcctxt()>>=?fun(block_hash:Block_hash.t)->letshell_header:Operation.shell_header=Operation.{branch=block_hash}inletop:operation={shell=shell_header;protocol_data=pop}inDemo_block_services.Helpers.Preapply.operationscctxt[op]>>=?function|[(_op_data,op_receipt)]->letreceipt_str=Receipt.to_stringop_receiptincctxt#message"Operation receipt: %s"receipt_str>>=fun()->letmbytes=forge_op(shell_header,pop)inShell_services.Injection.operationcctxtmbytes>>=?funop_hash->letinjected=Operation_hash.to_short_b58checkop_hashincctxt#message"Injected: %s"injected>>=fun()->return_unit|_->assertfalseletget_counter(cctxt:Protocol_client_context.full)account=Services.get_countercctxt(cctxt#chain,cctxt#block)account>>=?funcnt->cctxt#message"The counter value is %d"(Int32.to_intcnt)>>=fun()->return_unit