123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)(** Block header *)typecontents={priority:int;seed_nonce_hash:Nonce_hash.toption;proof_of_work_nonce:bytes;liquidity_baking_escape_vote:bool;}typeprotocol_data={contents:contents;signature:Signature.t}typet={shell:Block_header.shell_header;protocol_data:protocol_data}typeblock_header=ttyperaw=Block_header.ttypeshell_header=Block_header.shell_headerletraw_encoding=Block_header.encodingletshell_header_encoding=Block_header.shell_header_encodingletcontents_encoding=letopenData_encodingindef"block_header.alpha.unsigned_contents"@@conv(fun{priority;seed_nonce_hash;proof_of_work_nonce;liquidity_baking_escape_vote;}->(priority,proof_of_work_nonce,seed_nonce_hash,liquidity_baking_escape_vote))(fun(priority,proof_of_work_nonce,seed_nonce_hash,liquidity_baking_escape_vote)->{priority;seed_nonce_hash;proof_of_work_nonce;liquidity_baking_escape_vote;})(obj4(req"priority"uint16)(req"proof_of_work_nonce"(Fixed.bytesConstants_repr.proof_of_work_nonce_size))(opt"seed_nonce_hash"Nonce_hash.encoding)(req"liquidity_baking_escape_vote"Data_encoding.bool))letprotocol_data_encoding=letopenData_encodingindef"block_header.alpha.signed_contents"@@conv(fun{contents;signature}->(contents,signature))(fun(contents,signature)->{contents;signature})(merge_objscontents_encoding(obj1(req"signature"Signature.encoding)))letraw{shell;protocol_data}=letprotocol_data=Data_encoding.Binary.to_bytes_exnprotocol_data_encodingprotocol_datain{Block_header.shell;protocol_data}letunsigned_encoding=letopenData_encodinginmerge_objsBlock_header.shell_header_encodingcontents_encodingletencoding=letopenData_encodingindef"block_header.alpha.full_header"@@conv(fun{shell;protocol_data}->(shell,protocol_data))(fun(shell,protocol_data)->{shell;protocol_data})(merge_objsBlock_header.shell_header_encodingprotocol_data_encoding)(** Constants *)letmax_header_length=letfake_shell={Block_header.level=0l;proto_level=0;predecessor=Block_hash.zero;timestamp=Time.of_seconds0L;validation_passes=0;operations_hash=Operation_list_list_hash.zero;fitness=Fitness_repr.from_int640L;context=Context_hash.zero;}andfake_contents={priority=0;proof_of_work_nonce=Bytes.makeConstants_repr.proof_of_work_nonce_size'0';seed_nonce_hash=SomeNonce_hash.zero;liquidity_baking_escape_vote=false;}inData_encoding.Binary.lengthencoding{shell=fake_shell;protocol_data={contents=fake_contents;signature=Signature.zero};}(** Header parsing entry point *)lethash_raw=Block_header.hashlethash{shell;protocol_data}=Block_header.hash{shell;protocol_data=Data_encoding.Binary.to_bytes_exnprotocol_data_encodingprotocol_data;}