Kagome
Polkadot Runtime Engine in C++17
storage_util.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_CORE_BLOCKCHAIN_IMPL_PERSISTENT_MAP_UTIL_HPP
7 #define KAGOME_CORE_BLOCKCHAIN_IMPL_PERSISTENT_MAP_UTIL_HPP
8 
9 #include "common/buffer.hpp"
11 #include "primitives/block_id.hpp"
13 
19 namespace kagome::blockchain {
20 
24  namespace prefix {
25  enum Prefix : uint8_t {
26  // mapping of block id to a storage lookup key
28 
29  // block headers
30  HEADER = 4,
31 
32  // body of the block (extrinsics)
34 
35  // node of a trie db
37  };
38  }
39 
44 
45  outcome::result<void> putNumberToIndexKey(storage::BufferStorage &map,
46  const primitives::BlockInfo &block);
47 
53  prefix::Prefix key_column);
54 
65  outcome::result<void> putWithPrefix(storage::BufferStorage &map,
66  prefix::Prefix prefix,
68  common::Hash256 block_hash,
69  const common::Buffer &value);
70 
78  outcome::result<bool> hasWithPrefix(const storage::BufferStorage &storage,
79  prefix::Prefix prefix,
80  const primitives::BlockId &block_id);
81 
89  outcome::result<std::optional<common::Buffer>> getWithPrefix(
90  const storage::BufferStorage &storage,
91  prefix::Prefix prefix,
92  const primitives::BlockId &block_id);
93 
102 
108  const common::Hash256 &hash);
109 
113  outcome::result<primitives::BlockNumber> lookupKeyToNumber(
114  const common::BufferView &key);
115 
116 } // namespace kagome::blockchain
117 
119 
120 #endif // KAGOME_CORE_BLOCKCHAIN_IMPL_PERSISTENT_MAP_UTIL_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
outcome::result< primitives::BlockNumber > lookupKeyToNumber(const common::BufferView &key)
OUTCOME_HPP_DECLARE_ERROR(kagome::blockchain, KeyValueRepositoryError)
common::Buffer numberAndHashToLookupKey(primitives::BlockNumber number, const common::Hash256 &hash)
common::Buffer numberToIndexKey(primitives::BlockNumber n)
outcome::result< void > putWithPrefix(storage::BufferStorage &map, prefix::Prefix prefix, BlockNumber num, Hash256 block_hash, const common::Buffer &value)
outcome::result< void > putNumberToIndexKey(storage::BufferStorage &map, const primitives::BlockInfo &block)
uint32_t BlockNumber
Definition: common.hpp:18
outcome::result< std::optional< common::Buffer > > getWithPrefix(const storage::BufferStorage &map, prefix::Prefix prefix, const primitives::BlockId &block_id)
boost::variant< BlockHash, BlockNumber > BlockId
Block id is the variant over BlockHash and BlockNumber.
Definition: block_id.hpp:18
outcome::result< bool > hasWithPrefix(const storage::BufferStorage &map, prefix::Prefix prefix, const primitives::BlockId &block_id)
common::Buffer prependPrefix(common::BufferView key, prefix::Prefix key_column)