Kagome
Polkadot Runtime Engine in C++17
trie_batches.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_STORAGE_TRIE_IMPL_TRIE_BATCH
7 #define KAGOME_STORAGE_TRIE_IMPL_TRIE_BATCH
8 
11 #include "storage/trie/types.hpp"
12 
13 namespace kagome::storage::trie {
14 
15  class TrieBatch
16  : public face::ReadableMap<BufferView, Buffer>,
17  public face::Writeable<BufferView, Buffer>,
18  public face::Iterable<Buffer, common::BufferConstRef, BufferView> {
19  public:
20  ~TrieBatch() override = default;
21 
22  using Cursor =
24  std::unique_ptr<Cursor> cursor() final {
25  return trieCursor();
26  }
27 
28  virtual std::unique_ptr<PolkadotTrieCursor> trieCursor() = 0;
29 
33  virtual outcome::result<std::tuple<bool, uint32_t>> clearPrefix(
34  const BufferView &prefix,
35  std::optional<uint64_t> limit = std::nullopt) = 0;
36  };
37 
38  class TopperTrieBatch;
39 
45  : public TrieBatch,
46  public std::enable_shared_from_this<PersistentTrieBatch> {
47  public:
52  virtual outcome::result<RootHash> commit() = 0;
53 
57  virtual std::unique_ptr<TopperTrieBatch> batchOnTop() = 0;
58  };
59 
64  class EphemeralTrieBatch : public TrieBatch {
65  public:
69  virtual outcome::result<RootHash> hash() = 0;
70  };
71 
76  class TopperTrieBatch : public TrieBatch {
77  public:
81  virtual outcome::result<void> writeBack() = 0;
82  };
83 
84 } // namespace kagome::storage::trie
85 
86 #endif // KAGOME_STORAGE_TRIE_IMPL_TRIE_BATCH
A mixin for read-only map.
Definition: readable.hpp:40
An abstraction over generic map cursor.
Definition: map_cursor.hpp:22
A mixin for an iterable map.
Definition: iterable.hpp:22
An mixin for modifiable map.
Definition: writeable.hpp:19
virtual outcome::result< std::tuple< bool, uint32_t > > clearPrefix(const BufferView &prefix, std::optional< uint64_t > limit=std::nullopt)=0
virtual std::unique_ptr< PolkadotTrieCursor > trieCursor()=0
std::unique_ptr< Cursor > cursor() final
Returns new key-value iterator.