sgns::blockchain::KeyValueBlockStorage¶
#include <key_value_block_storage.hpp>
Inherits from sgns::blockchain::BlockStorage, IComponent
Public Types¶
| Name | |
|---|---|
| enum class | Error |
| using std::function< void(const primitives::Block &)> | BlockHandler |
Public Functions¶
| Name | |
|---|---|
| ~KeyValueBlockStorage() override =default | |
| virtual outcome::result< primitives::BlockHash > | getGenesisBlockHash() const override Get hash of genesis block. |
| virtual outcome::result< primitives::BlockHash > | getLastFinalizedBlockHash() const override |
| virtual outcome::result< void > | setLastFinalizedBlockHash(const primitives::BlockHash & hash) override |
| virtual outcome::result< primitives::BlockHeader > | getBlockHeader(const primitives::BlockId & id) const override |
| virtual outcome::result< primitives::BlockBody > | getBlockBody(const primitives::BlockId & id) const override |
| virtual outcome::result< primitives::BlockData > | getBlockData(const primitives::BlockId & id) const override |
| outcome::result< base::Buffer > | GetRawBlock(const primitives::BlockId & id) const |
| virtual outcome::result< primitives::Justification > | getJustification(const primitives::BlockId & block) const override |
| virtual outcome::result< primitives::BlockHash > | putBlockHeader(const primitives::BlockHeader & header) override |
| virtual outcome::result< void > | putBlockData(primitives::BlockNumber block_number, const primitives::BlockData & block_data) override |
| virtual outcome::result< primitives::BlockHash > | putBlock(const primitives::Block & block) override |
| virtual outcome::result< void > | putJustification(const primitives::Justification & j, const primitives::BlockHash & hash, const primitives::BlockNumber & number) override |
| virtual outcome::result< void > | removeBlock(const primitives::BlockHash & hash, const primitives::BlockNumber & number) override |
| virtual std::string | GetName() override |
| std::vector< uint8_t > | GetSerializedBlockData(const primitives::BlockData & block_data) |
| primitives::BlockData | GetBlockDataFromSerialized(const std::vector< uint8_t > & serialized_data) const |
| outcome::result< std::shared_ptr< KeyValueBlockStorage > > | create(base::Buffer state_root, const std::shared_ptr< crdt::GlobalDB > & db, const std::shared_ptr< crypto::Hasher > & hasher, const std::shared_ptr< KeyValueBlockHeaderRepository > & header_repo, const BlockHandler & on_finalized_block_found) |
| outcome::result< std::shared_ptr< KeyValueBlockStorage > > | loadExisting(std::shared_ptr< crdt::GlobalDB > db, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< KeyValueBlockHeaderRepository > header_repo, const BlockHandler & on_finalized_block_found) |
| outcome::result< std::shared_ptr< KeyValueBlockStorage > > | createWithGenesis(base::Buffer state_root, const std::shared_ptr< crdt::GlobalDB > & db, std::shared_ptr< crypto::Hasher > hasher, std::shared_ptr< KeyValueBlockHeaderRepository > header_repo, const BlockHandler & on_genesis_created) |
Additional inherited members¶
Public Functions inherited from sgns::blockchain::BlockStorage
| Name | |
|---|---|
| ~BlockStorage() override =default |
Public Functions inherited from IComponent
| Name | |
|---|---|
| virtual | ~IComponent() =default |
Public Types Documentation¶
enum Error¶
| Enumerator | Value | Description |
|---|---|---|
| BLOCK_EXISTS | 1 | |
| BODY_DOES_NOT_EXIST | ||
| JUSTIFICATION_DOES_NOT_EXIST | ||
| GENESIS_BLOCK_ALREADY_EXISTS | ||
| GENESIS_BLOCK_NOT_FOUND | ||
| FINALIZED_BLOCK_NOT_FOUND |
using BlockHandler¶
using sgns::blockchain::KeyValueBlockStorage::BlockHandler = std::function<void( const primitives::Block & )>;
Public Functions Documentation¶
function ~KeyValueBlockStorage¶
function getGenesisBlockHash¶
Get hash of genesis block.
Reimplements: sgns::blockchain::BlockStorage::getGenesisBlockHash
function getLastFinalizedBlockHash¶
Reimplements: sgns::blockchain::BlockStorage::getLastFinalizedBlockHash
function setLastFinalizedBlockHash¶
virtual outcome::result< void > setLastFinalizedBlockHash(
const primitives::BlockHash & hash
) override
Reimplements: sgns::blockchain::BlockStorage::setLastFinalizedBlockHash
function getBlockHeader¶
virtual outcome::result< primitives::BlockHeader > getBlockHeader(
const primitives::BlockId & id
) const override
Reimplements: sgns::blockchain::BlockStorage::getBlockHeader
function getBlockBody¶
virtual outcome::result< primitives::BlockBody > getBlockBody(
const primitives::BlockId & id
) const override
Reimplements: sgns::blockchain::BlockStorage::getBlockBody
function getBlockData¶
virtual outcome::result< primitives::BlockData > getBlockData(
const primitives::BlockId & id
) const override
Reimplements: sgns::blockchain::BlockStorage::getBlockData
function GetRawBlock¶
function getJustification¶
virtual outcome::result< primitives::Justification > getJustification(
const primitives::BlockId & block
) const override
Reimplements: sgns::blockchain::BlockStorage::getJustification
function putBlockHeader¶
virtual outcome::result< primitives::BlockHash > putBlockHeader(
const primitives::BlockHeader & header
) override
Reimplements: sgns::blockchain::BlockStorage::putBlockHeader
function putBlockData¶
virtual outcome::result< void > putBlockData(
primitives::BlockNumber block_number,
const primitives::BlockData & block_data
) override
Reimplements: sgns::blockchain::BlockStorage::putBlockData
function putBlock¶
virtual outcome::result< primitives::BlockHash > putBlock(
const primitives::Block & block
) override
Reimplements: sgns::blockchain::BlockStorage::putBlock
function putJustification¶
virtual outcome::result< void > putJustification(
const primitives::Justification & j,
const primitives::BlockHash & hash,
const primitives::BlockNumber & number
) override
Reimplements: sgns::blockchain::BlockStorage::putJustification
function removeBlock¶
virtual outcome::result< void > removeBlock(
const primitives::BlockHash & hash,
const primitives::BlockNumber & number
) override
Reimplements: sgns::blockchain::BlockStorage::removeBlock
function GetName¶
Reimplements: IComponent::GetName
function GetSerializedBlockData¶
function GetBlockDataFromSerialized¶
primitives::BlockData GetBlockDataFromSerialized(
const std::vector< uint8_t > & serialized_data
) const
function create¶
static outcome::result< std::shared_ptr< KeyValueBlockStorage > > create(
base::Buffer state_root,
const std::shared_ptr< crdt::GlobalDB > & db,
const std::shared_ptr< crypto::Hasher > & hasher,
const std::shared_ptr< KeyValueBlockHeaderRepository > & header_repo,
const BlockHandler & on_finalized_block_found
)
function loadExisting¶
static outcome::result< std::shared_ptr< KeyValueBlockStorage > > loadExisting(
std::shared_ptr< crdt::GlobalDB > db,
std::shared_ptr< crypto::Hasher > hasher,
std::shared_ptr< KeyValueBlockHeaderRepository > header_repo,
const BlockHandler & on_finalized_block_found
)
Parameters:
- db underlying storage (must be empty)
- hasher a hasher instance
- header_repo header repository
- on_finalized_block_found callback when finalized block is found
Initialise block storage with existing data.
function createWithGenesis¶
static outcome::result< std::shared_ptr< KeyValueBlockStorage > > createWithGenesis(
base::Buffer state_root,
const std::shared_ptr< crdt::GlobalDB > & db,
std::shared_ptr< crypto::Hasher > hasher,
std::shared_ptr< KeyValueBlockHeaderRepository > header_repo,
const BlockHandler & on_genesis_created
)
Parameters:
- state_root merkle trie state root
- db underlying storage (must be empty)
- hasher a hasher instance
- header_repo header repository
- on_genesis_created callback when genesis is created
Initialise block storage with a genesis block created from the merkle trie root.
Updated on 2026-03-04 at 13:10:43 -0800