Kagome
Polkadot Runtime Engine in C++17
block_tree.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_BLOCK_TREE_HPP
7 #define KAGOME_BLOCK_TREE_HPP
8 
9 #include <cstdint>
10 #include <optional>
11 #include <vector>
12 
14 #include "outcome/outcome.hpp"
15 #include "primitives/block.hpp"
16 #include "primitives/block_id.hpp"
17 #include "primitives/common.hpp"
19 #include "primitives/version.hpp"
20 
21 namespace kagome::blockchain {
30  class BlockTree {
31  public:
32  using BlockHashVecRes = outcome::result<std::vector<primitives::BlockHash>>;
33 
34  virtual ~BlockTree() = default;
35 
39  virtual const primitives::BlockHash &getGenesisBlockHash() const = 0;
40 
46  virtual outcome::result<bool> hasBlockHeader(
47  const primitives::BlockId &block) const = 0;
48 
54  virtual outcome::result<primitives::BlockHeader> getBlockHeader(
55  const primitives::BlockId &block) const = 0;
56 
63  virtual outcome::result<primitives::BlockBody> getBlockBody(
64  const primitives::BlockId &block) const = 0;
65 
72  virtual outcome::result<primitives::Justification> getBlockJustification(
73  const primitives::BlockId &block) const = 0;
74 
81  virtual outcome::result<void> addBlockHeader(
82  const primitives::BlockHeader &header) = 0;
83 
92  virtual outcome::result<void> addBlockBody(
93  primitives::BlockNumber block_number,
94  const primitives::BlockHash &block_hash,
95  const primitives::BlockBody &block_body) = 0;
96 
104  virtual outcome::result<void> addExistingBlock(
105  const primitives::BlockHash &block_hash,
106  const primitives::BlockHeader &block_header) = 0;
107 
120  virtual outcome::result<void> addBlock(const primitives::Block &block) = 0;
121 
127  virtual outcome::result<void> removeLeaf(
128  const primitives::BlockHash &block_hash) = 0;
129 
136  virtual outcome::result<void> finalize(
137  const primitives::BlockHash &block,
138  const primitives::Justification &justification) = 0;
139 
141 
149  const primitives::BlockHash &block, uint64_t maximum) const = 0;
150 
158  const primitives::BlockHash &block, uint64_t maximum) const = 0;
159 
168  const primitives::BlockHash &ancestor,
169  const primitives::BlockHash &descendant) const = 0;
170 
177  virtual bool hasDirectChain(
178  const primitives::BlockHash &ancestor,
179  const primitives::BlockHash &descendant) const = 0;
180 
188  virtual primitives::BlockInfo deepestLeaf() const = 0;
189 
198  virtual outcome::result<primitives::BlockInfo> getBestContaining(
199  const primitives::BlockHash &target_hash,
200  const std::optional<primitives::BlockNumber> &max_number) const = 0;
201 
206  virtual std::vector<primitives::BlockHash> getLeaves() const = 0;
207 
214  const primitives::BlockHash &block) const = 0;
215 
220  virtual primitives::BlockInfo getLastFinalized() const = 0;
221  };
222 
223 } // namespace kagome::blockchain
224 
225 #endif // KAGOME_BLOCK_TREE_HPP
virtual bool hasDirectChain(const primitives::BlockHash &ancestor, const primitives::BlockHash &descendant) const =0
virtual BlockHashVecRes getChildren(const primitives::BlockHash &block) const =0
std::vector< Extrinsic > BlockBody
Definition: block.hpp:14
Block class represents polkadot block primitive.
Definition: block.hpp:19
virtual outcome::result< void > addBlockHeader(const primitives::BlockHeader &header)=0
virtual outcome::result< primitives::BlockHeader > getBlockHeader(const primitives::BlockId &block) const =0
virtual outcome::result< primitives::Justification > getBlockJustification(const primitives::BlockId &block) const =0
virtual outcome::result< bool > hasBlockHeader(const primitives::BlockId &block) const =0
virtual outcome::result< primitives::BlockInfo > getBestContaining(const primitives::BlockHash &target_hash, const std::optional< primitives::BlockNumber > &max_number) const =0
Get the most recent block of the best (longest) chain among those that contain a block with...
uint32_t BlockNumber
Definition: common.hpp:18
virtual outcome::result< void > addBlock(const primitives::Block &block)=0
virtual outcome::result< void > addExistingBlock(const primitives::BlockHash &block_hash, const primitives::BlockHeader &block_header)=0
virtual BlockHashVecRes getBestChainFromBlock(const primitives::BlockHash &block, uint64_t maximum) const =0
virtual outcome::result< void > removeLeaf(const primitives::BlockHash &block_hash)=0
outcome::result< std::vector< primitives::BlockHash >> BlockHashVecRes
Definition: block_tree.hpp:32
virtual BlockHashVecRes getChainByBlocks(const primitives::BlockHash &ancestor, const primitives::BlockHash &descendant) const =0
virtual std::vector< primitives::BlockHash > getLeaves() const =0
virtual BlockHashVecRes getDescendingChainToBlock(const primitives::BlockHash &block, uint64_t maximum) const =0
virtual outcome::result< void > addBlockBody(primitives::BlockNumber block_number, const primitives::BlockHash &block_hash, const primitives::BlockBody &block_body)=0
boost::variant< BlockHash, BlockNumber > BlockId
Block id is the variant over BlockHash and BlockNumber.
Definition: block_id.hpp:18
virtual const primitives::BlockHash & getGenesisBlockHash() const =0
virtual outcome::result< void > finalize(const primitives::BlockHash &block, const primitives::Justification &justification)=0
virtual primitives::BlockInfo deepestLeaf() const =0
virtual ~BlockTree()=default
virtual outcome::result< primitives::BlockBody > getBlockBody(const primitives::BlockId &block) const =0
virtual primitives::BlockInfo getLastFinalized() const =0