Kagome
Polkadot Runtime Engine in C++17
persistent_trie_batch_impl.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_STORAGE_TRIE_IMPL_PERSISTENT_TRIE_BATCH
7 #define KAGOME_STORAGE_TRIE_IMPL_PERSISTENT_TRIE_BATCH
8 
9 #include <memory>
10 
11 #include "log/logger.hpp"
14 #include "storage/trie/codec.hpp"
17 
18 namespace kagome::storage::trie {
19 
21  public:
22  enum class Error {
23  NO_TRIE = 1,
24  };
25 
26  static std::unique_ptr<PersistentTrieBatchImpl> create(
27  std::shared_ptr<Codec> codec,
28  std::shared_ptr<TrieSerializer> serializer,
29  std::optional<std::shared_ptr<changes_trie::ChangesTracker>> changes,
30  std::shared_ptr<PolkadotTrie> trie);
31  ~PersistentTrieBatchImpl() override = default;
32 
33  outcome::result<RootHash> commit() override;
34  std::unique_ptr<TopperTrieBatch> batchOnTop() override;
35 
36  outcome::result<BufferConstRef> get(const BufferView &key) const override;
37  outcome::result<std::optional<BufferConstRef>> tryGet(
38  const BufferView &key) const override;
39  std::unique_ptr<PolkadotTrieCursor> trieCursor() override;
40  outcome::result<bool> contains(const BufferView &key) const override;
41  bool empty() const override;
42  outcome::result<std::tuple<bool, uint32_t>> clearPrefix(
43  const BufferView &prefix,
44  std::optional<uint64_t> limit = std::nullopt) override;
45  outcome::result<void> put(const BufferView &key,
46  const Buffer &value) override;
47  outcome::result<void> put(const BufferView &key, Buffer &&value) override;
48  outcome::result<void> remove(const BufferView &key) override;
49 
50  private:
52  std::shared_ptr<Codec> codec,
53  std::shared_ptr<TrieSerializer> serializer,
54  std::optional<std::shared_ptr<changes_trie::ChangesTracker>> changes,
55  std::shared_ptr<PolkadotTrie> trie);
56 
57  std::shared_ptr<Codec> codec_;
58  std::shared_ptr<TrieSerializer> serializer_;
59  std::optional<std::shared_ptr<changes_trie::ChangesTracker>> changes_;
60  std::shared_ptr<PolkadotTrie> trie_;
61 
62  log::Logger logger_ = log::createLogger("PersistentTrieBatch", "storage");
63  };
64 
65 } // namespace kagome::storage::trie
66 
69 
70 #endif // KAGOME_STORAGE_TRIE_IMPL_PERSISTENT_TRIE_BATCH
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
PersistentTrieBatchImpl(std::shared_ptr< Codec > codec, std::shared_ptr< TrieSerializer > serializer, std::optional< std::shared_ptr< changes_trie::ChangesTracker >> changes, std::shared_ptr< PolkadotTrie > trie)
std::unique_ptr< TopperTrieBatch > batchOnTop() override
bool empty() const override
Returns true if the storage is empty.
static std::unique_ptr< PersistentTrieBatchImpl > create(std::shared_ptr< Codec > codec, std::shared_ptr< TrieSerializer > serializer, std::optional< std::shared_ptr< changes_trie::ChangesTracker >> changes, std::shared_ptr< PolkadotTrie > trie)
std::unique_ptr< PolkadotTrieCursor > trieCursor() override
outcome::result< std::tuple< bool, uint32_t > > clearPrefix(const BufferView &prefix, std::optional< uint64_t > limit=std::nullopt) override
outcome::result< void > put(const BufferView &key, const Buffer &value) override
Store value by key.
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
outcome::result< std::optional< BufferConstRef > > tryGet(const BufferView &key) const override
Get value by key.
outcome::result< bool > contains(const BufferView &key) const override
Checks if given key-value binding exists in the storage.
OUTCOME_HPP_DECLARE_ERROR(kagome::storage::trie, PersistentTrieBatchImpl::Error)
Logger createLogger(const std::string &tag)
Definition: logger.cpp:112
std::optional< std::shared_ptr< changes_trie::ChangesTracker > > changes_