Kagome
Polkadot Runtime Engine in C++17
storage_extension.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_HOST_API_STORAGE_EXTENSION_HPP
7 #define KAGOME_HOST_API_STORAGE_EXTENSION_HPP
8 
9 #include <cstdint>
10 
11 #include "log/logger.hpp"
12 #include "runtime/types.hpp"
14 
15 namespace kagome::runtime {
16  class MemoryProvider;
17  class TrieStorageProvider;
18 } // namespace kagome::runtime
19 
20 namespace kagome::host_api {
25  public:
27  std::shared_ptr<runtime::TrieStorageProvider> storage_provider,
28  std::shared_ptr<const runtime::MemoryProvider> memory_provider);
29 
30  void reset();
31 
32  // -------------------------Trie operations--------------------------
33 
37  runtime::WasmSpan ext_storage_read_version_1(runtime::WasmSpan key,
38  runtime::WasmSpan value_out,
39  runtime::WasmOffset offset);
40 
41  // ------------------------ VERSION 1 ------------------------
42 
46  void ext_storage_set_version_1(runtime::WasmSpan key,
47  runtime::WasmSpan value);
48 
52  runtime::WasmSpan ext_storage_get_version_1(runtime::WasmSpan key);
53 
57  void ext_storage_clear_version_1(runtime::WasmSpan key_data);
58 
62  runtime::WasmSize ext_storage_exists_version_1(
63  runtime::WasmSpan key_data) const;
64 
68  void ext_storage_clear_prefix_version_1(runtime::WasmSpan prefix);
69 
73  runtime::WasmSpan ext_storage_clear_prefix_version_2(
74  runtime::WasmSpan prefix, runtime::WasmSpan limit);
75 
79  runtime::WasmSpan ext_storage_root_version_1();
80 
84  runtime::WasmSpan ext_storage_root_version_2(
85  runtime::WasmI32 state_version);
86 
90  runtime::WasmSpan ext_storage_changes_root_version_1(
91  runtime::WasmSpan parent_hash);
92 
96  runtime::WasmSpan ext_storage_next_key_version_1(
97  runtime::WasmSpan key) const;
98 
102  void ext_storage_append_version_1(runtime::WasmSpan key,
103  runtime::WasmSpan value) const;
104 
108  void ext_storage_start_transaction_version_1();
109 
113  void ext_storage_commit_transaction_version_1();
114 
118  void ext_storage_rollback_transaction_version_1();
119 
123  runtime::WasmPointer ext_trie_blake2_256_root_version_1(
124  runtime::WasmSpan values_data);
125 
129  runtime::WasmPointer ext_trie_blake2_256_ordered_root_version_1(
130  runtime::WasmSpan values_data);
131 
135  runtime::WasmPointer ext_trie_blake2_256_ordered_root_version_2(
136  runtime::WasmSpan values_data, runtime::WasmI32 state_version);
137 
138  private:
146  outcome::result<std::optional<common::BufferConstRef>> get(
147  const common::BufferView &key) const;
148 
156  common::Buffer loadKey(runtime::WasmSpan key) const;
161  outcome::result<std::optional<common::Buffer>> getStorageNextKey(
162  const common::Buffer &key) const;
163 
164  runtime::WasmSpan clearPrefix(common::BufferView prefix,
165  std::optional<uint32_t> limit);
166 
171  void removeEmptyChildStorages();
172 
173  std::shared_ptr<runtime::TrieStorageProvider> storage_provider_;
174  std::shared_ptr<const runtime::MemoryProvider> memory_provider_;
177 
178  constexpr static auto kDefaultLoggerTag = "WASM Runtime [StorageExtension]";
179  };
180 
181 } // namespace kagome::host_api
182 
183 #endif // KAGOME_HOST_API_STORAGE_EXTENSION_HPP
Class represents arbitrary (including empty) byte buffer.
Definition: buffer.hpp:29
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
Definition: types.hpp:35
std::shared_ptr< runtime::TrieStorageProvider > storage_provider_
uint32_t WasmOffset
Offset type is uint32_t because we are working in 32 bit address space.
Definition: types.hpp:44
int32_t WasmI32
Definition: types.hpp:46
storage::trie::PolkadotCodec codec_
std::shared_ptr< const runtime::MemoryProvider > memory_provider_
std::shared_ptr< soralog::Logger > Logger
Definition: logger.hpp:23
uint64_t WasmSpan
combination of pointer and size, where less significant part represents wasm pointer, and most significant represents size
Definition: types.hpp:31
uint32_t WasmPointer
type of wasm memory is 32 bit integer
Definition: types.hpp:26