OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::watchtower::block_cache Class Reference

Stores a set of blocks in memory and maintains an index of the UHS IDs contained therein. More...

#include <block_cache.hpp>

Public Member Functions

 block_cache ()=delete
 
 block_cache (size_t k)
 Constructor.
 
void push_block (cbdc::atomizer::block &&blk)
 Moves a block into the block cache, evicting the oldest block if the cache has reached its maximum size.
 
auto check_unspent (const hash_t &uhs_id) const -> std::optional< block_cache_result >
 Checks to see if the given UHS ID is spendable according to the blocks in the cache.
 
auto check_spent (const hash_t &uhs_id) const -> std::optional< block_cache_result >
 Checks to see if the given UHS ID has been spent according to the blocks in the cache.
 
auto best_block_height () const -> uint64_t
 Returns the block height of the highest observed block.
 

Detailed Description

Stores a set of blocks in memory and maintains an index of the UHS IDs contained therein.

Definition at line 30 of file block_cache.hpp.

Constructor & Destructor Documentation

◆ block_cache() [1/2]

cbdc::watchtower::block_cache::block_cache ( )
delete

◆ block_cache() [2/2]

cbdc::watchtower::block_cache::block_cache ( size_t k)
explicit

Constructor.

Parameters
knumber of blocks to store in memory. 0 -> no limit.

Definition at line 9 of file block_cache.cpp.

Member Function Documentation

◆ best_block_height()

auto cbdc::watchtower::block_cache::best_block_height ( ) const -> uint64_t

Returns the block height of the highest observed block.

Returns
the highest block height.

Definition at line 64 of file block_cache.cpp.

◆ check_spent()

auto cbdc::watchtower::block_cache::check_spent ( const hash_t & uhs_id) const -> std::optional<block_cache_result>

Checks to see if the given UHS ID has been spent according to the blocks in the cache.

Parameters
uhs_idUHS ID to check.
Returns
a BlockCacheResult containing the block height and ID of the transaction that spent this UHS ID.

Definition at line 56 of file block_cache.cpp.

Referenced by cbdc::watchtower::watchtower::add_errors().

◆ check_unspent()

auto cbdc::watchtower::block_cache::check_unspent ( const hash_t & uhs_id) const -> std::optional<block_cache_result>

Checks to see if the given UHS ID is spendable according to the blocks in the cache.

Parameters
uhs_idUHS ID to check.
Returns
a BlockCacheResult containing the block height and ID of the transaction that originated this UHS ID.

Definition at line 47 of file block_cache.cpp.

Referenced by cbdc::watchtower::watchtower::add_errors().

◆ push_block()

void cbdc::watchtower::block_cache::push_block ( cbdc::atomizer::block && blk)

Moves a block into the block cache, evicting the oldest block if the cache has reached its maximum size.

Parameters
blkthe block to move into the cache.

Definition at line 16 of file block_cache.cpp.

Referenced by cbdc::watchtower::watchtower::add_block().


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