Kagome
Polkadot Runtime Engine in C++17
kagome::blockchain::TreeNode Class Reference

#include <cached_tree.hpp>

Inheritance diagram for kagome::blockchain::TreeNode:
Collaboration diagram for kagome::blockchain::TreeNode:

Public Types

enum  Error { Error::NO_CHAIN_BETWEEN_BLOCKS = 1 }
 
enum  ExitToken { ExitToken::EXIT, ExitToken::CONTINUE }
 

Public Member Functions

 TreeNode (const primitives::BlockHash &hash, primitives::BlockNumber depth, bool finalized=false)
 
 TreeNode (const primitives::BlockHash &hash, primitives::BlockNumber depth, const std::shared_ptr< TreeNode > &parent, bool finalized=false)
 
std::shared_ptr< const TreeNodefindByHash (const primitives::BlockHash &hash) const
 
std::shared_ptr< TreeNodefindByHash (const primitives::BlockHash &hash)
 
outcome::result< void > applyToChain (const primitives::BlockInfo &chain_end, std::function< outcome::result< ExitToken >(TreeNode const &node)> const &op) const
 
primitives::BlockInfo getBlockInfo () const
 
bool operator== (const TreeNode &other) const
 
bool operator!= (const TreeNode &other) const
 

Public Attributes

primitives::BlockHash block_hash
 
primitives::BlockNumber depth
 
std::weak_ptr< TreeNodeparent
 
bool finalized
 
std::vector< std::shared_ptr< TreeNode > > children {}
 

Detailed Description

In-memory light representation of the tree, used for efficiency and usage convenience - we would only ask the database for some info, when directly requested

Definition at line 24 of file cached_tree.hpp.

Member Enumeration Documentation

Enumerator
NO_CHAIN_BETWEEN_BLOCKS 

Definition at line 26 of file cached_tree.hpp.

Exit token for applyToChain method. Simply a value denoting whether applyToChain should stop.

Enumerator
EXIT 
CONTINUE 

Definition at line 60 of file cached_tree.hpp.

Constructor & Destructor Documentation

kagome::blockchain::TreeNode::TreeNode ( const primitives::BlockHash hash,
primitives::BlockNumber  depth,
bool  finalized = false 
)

Definition at line 23 of file cached_tree.cpp.

kagome::blockchain::TreeNode::TreeNode ( const primitives::BlockHash hash,
primitives::BlockNumber  depth,
const std::shared_ptr< TreeNode > &  parent,
bool  finalized = false 
)

Definition at line 28 of file cached_tree.cpp.

Member Function Documentation

outcome::result< void > kagome::blockchain::TreeNode::applyToChain ( const primitives::BlockInfo chain_end,
std::function< outcome::result< ExitToken >(TreeNode const &node)> const &  op 
) const

Applies

  • op for each node starting from this and ending with
  • chain_end. If op returns success(EXIT), stops.
    Note
    if
  • op returns an error, execution will stop immediately and the rest of nodes will not be processed
    Note
    inefficient in case chain_end is not in chain with the current node. Will traverse the whole subtree trying to find it.
    Returns
    error if chain doesn't exist or op() returns an error on a call, success otherwise

Definition at line 34 of file cached_tree.cpp.

std::shared_ptr< const TreeNode > kagome::blockchain::TreeNode::findByHash ( const primitives::BlockHash hash) const

Get a node of the tree, containing block with the specified hash, if it can be found

Definition at line 88 of file cached_tree.cpp.

std::shared_ptr<TreeNode> kagome::blockchain::TreeNode::findByHash ( const primitives::BlockHash hash)
inline

Definition at line 51 of file cached_tree.hpp.

primitives::BlockInfo kagome::blockchain::TreeNode::getBlockInfo ( ) const
inline

Definition at line 77 of file cached_tree.hpp.

bool kagome::blockchain::TreeNode::operator!= ( const TreeNode other) const

Definition at line 116 of file cached_tree.cpp.

bool kagome::blockchain::TreeNode::operator== ( const TreeNode other) const

Definition at line 106 of file cached_tree.cpp.

Member Data Documentation

primitives::BlockHash kagome::blockchain::TreeNode::block_hash

Definition at line 37 of file cached_tree.hpp.

std::vector<std::shared_ptr<TreeNode> > kagome::blockchain::TreeNode::children {}

Definition at line 42 of file cached_tree.hpp.

primitives::BlockNumber kagome::blockchain::TreeNode::depth

Definition at line 38 of file cached_tree.hpp.

bool kagome::blockchain::TreeNode::finalized

Definition at line 40 of file cached_tree.hpp.

std::weak_ptr<TreeNode> kagome::blockchain::TreeNode::parent

Definition at line 39 of file cached_tree.hpp.


The documentation for this class was generated from the following files: