Kagome
Polkadot Runtime Engine in C++17
block_header_repository.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_BLOCKCHAIN_BLOCK_HEADER_REPOSITORY_HPP
7 #define KAGOME_CORE_BLOCKCHAIN_BLOCK_HEADER_REPOSITORY_HPP
8 
9 #include <optional>
10 
11 #include "common/blob.hpp"
12 #include "common/visitor.hpp"
13 #include "outcome/outcome.hpp"
15 #include "primitives/block_id.hpp"
16 
17 namespace kagome::blockchain {
18 
22  enum class BlockStatus { InChain, Unknown };
23 
30  public:
31  virtual ~BlockHeaderRepository() = default;
32 
38  virtual outcome::result<primitives::BlockNumber> getNumberByHash(
39  const common::Hash256 &hash) const = 0;
40 
46  virtual outcome::result<common::Hash256> getHashByNumber(
47  const primitives::BlockNumber &number) const = 0;
48 
52  virtual outcome::result<primitives::BlockHeader> getBlockHeader(
53  const primitives::BlockId &id) const = 0;
54 
59  virtual outcome::result<kagome::blockchain::BlockStatus> getBlockStatus(
60  const primitives::BlockId &id) const = 0;
61 
67  outcome::result<primitives::BlockNumber> getNumberById(
68  const primitives::BlockId &id) const {
69  return visit_in_place(
70  id,
71  [](const primitives::BlockNumber &n) { return n; },
72  [this](const common::Hash256 &hash) {
73  return getNumberByHash(hash);
74  });
75  }
76 
82  outcome::result<common::Hash256> getHashById(
83  const primitives::BlockId &id) const {
84  return visit_in_place(
85  id,
86  [this](const primitives::BlockNumber &n) {
87  return getHashByNumber(n);
88  },
89  [](const common::Hash256 &hash) { return hash; });
90  }
91  };
92 
93 } // namespace kagome::blockchain
94 
95 #endif // KAGOME_CORE_BLOCKCHAIN_BLOCK_HEADER_REPOSITORY_HPP
uint32_t BlockNumber
Definition: common.hpp:18
boost::variant< BlockHash, BlockNumber > BlockId
Block id is the variant over BlockHash and BlockNumber.
Definition: block_id.hpp:18
outcome::result< common::Hash256 > getHashById(const primitives::BlockId &id) const
outcome::result< primitives::BlockNumber > getNumberById(const primitives::BlockId &id) const