Kagome
Polkadot Runtime Engine in C++17
block_header.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_PRIMITIVES_BLOCK_HEADER_HPP
7 #define KAGOME_PRIMITIVES_BLOCK_HEADER_HPP
8 
9 #include <type_traits>
10 #include <vector>
11 
12 #include <scale/scale.hpp>
13 
14 #include "common/blob.hpp"
15 #include "crypto/hasher.hpp"
16 #include "primitives/common.hpp"
18 #include "primitives/digest.hpp"
19 #include "storage/trie/types.hpp"
20 
21 namespace kagome::primitives {
25  struct BlockHeader {
31 
32  bool operator==(const BlockHeader &rhs) const {
33  return std::tie(parent_hash, number, state_root, extrinsics_root, digest)
34  == std::tie(rhs.parent_hash,
35  rhs.number,
36  rhs.state_root,
37  rhs.extrinsics_root,
38  rhs.digest);
39  }
40 
41  bool operator!=(const BlockHeader &rhs) const {
42  return !operator==(rhs);
43  }
44  };
45 
48  const BlockHash hash;
49  };
50 
58  template <class Stream,
59  typename = std::enable_if_t<Stream::is_encoder_stream>>
60  Stream &operator<<(Stream &s, const BlockHeader &bh) {
61  return s << bh.parent_hash << CompactInteger(bh.number) << bh.state_root
62  << bh.extrinsics_root << bh.digest;
63  }
64 
72  template <class Stream,
73  typename = std::enable_if_t<Stream::is_decoder_stream>>
75  CompactInteger number_compact;
76  s >> bh.parent_hash >> number_compact >> bh.state_root >> bh.extrinsics_root
77  >> bh.digest;
78  bh.number = number_compact.convert_to<BlockNumber>();
79  return s;
80  }
81 
82  outcome::result<BlockHash> calculateBlockHash(
83  BlockHeader const &header, crypto::Hasher const &hasher);
84 
85 } // namespace kagome::primitives
86 
87 #endif // KAGOME_PRIMITIVES_BLOCK_HEADER_HPP
Digest digest
chain-specific auxiliary data
Stream & operator>>(Stream &s, ArithmeticError &v)
storage::trie::RootHash state_root
root of the Merkle tree
outcome::result< BlockHash > calculateBlockHash(BlockHeader const &header, crypto::Hasher const &hasher)
Definition: block_header.cpp:5
uint32_t BlockNumber
Definition: common.hpp:18
bool operator==(const BlockHeader &rhs) const
scale::CompactInteger CompactInteger
Stream & operator<<(Stream &s, const ArithmeticError &v)
libp2p::connection::Stream Stream
BlockNumber number
index of the block in the chain
BlockHash parent_hash
32-byte Blake2s hash of parent header
common::Hash256 extrinsics_root
field for validation integrity
bool operator!=(const BlockHeader &rhs) const