Kagome
Polkadot Runtime Engine in C++17
offchain_extension.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_OFFCHAIN_EXTENSION_HPP
7 #define KAGOME_OFFCHAIN_EXTENSION_HPP
8 
9 #include "clock/clock.hpp"
11 #include "log/logger.hpp"
13 #include "runtime/types.hpp"
14 
15 namespace kagome::offchain {
16  class OffchainWorker;
17  class OffchainWorkerPool;
18 } // namespace kagome::offchain
19 
20 namespace kagome::runtime {
21  class MemoryProvider;
22 }
23 
24 namespace kagome::host_api {
25 
27  bool is_indexing_enabled = false;
28  };
29 
30  class OffchainExtension final {
31  public:
33  const OffchainExtensionConfig &config,
34  std::shared_ptr<const runtime::MemoryProvider> memory_provider,
35  std::shared_ptr<offchain::OffchainStorage> offchain_storage,
36  std::shared_ptr<offchain::OffchainWorkerPool> ocw_pool);
37 
48  runtime::WasmI32 ext_offchain_is_validator_version_1();
49 
64  runtime::WasmSpan ext_offchain_submit_transaction_version_1(
65  runtime::WasmSpan data);
66 
77  runtime::WasmSpan ext_offchain_network_state_version_1();
78 
87  runtime::WasmU64 ext_offchain_timestamp_version_1();
88 
97  void ext_offchain_sleep_until_version_1(runtime::WasmU64 deadline);
98 
107  runtime::WasmPointer ext_offchain_random_seed_version_1();
108 
126  void ext_offchain_local_storage_set_version_1(runtime::WasmI32 kind,
127  runtime::WasmSpan key,
128  runtime::WasmSpan value);
129 
143  void ext_offchain_local_storage_clear_version_1(runtime::WasmI32 kind,
144  runtime::WasmSpan key);
145 
167  runtime::WasmI32 ext_offchain_local_storage_compare_and_set_version_1(
168  runtime::WasmI32 kind,
169  runtime::WasmSpan key,
170  runtime::WasmSpan expected,
171  runtime::WasmSpan value);
172 
189  runtime::WasmSpan ext_offchain_local_storage_get_version_1(
191 
212  runtime::WasmSpan ext_offchain_http_request_start_version_1(
213  runtime::WasmSpan method,
214  runtime::WasmSpan uri,
215  runtime::WasmSpan meta);
216 
237  runtime::WasmSpan ext_offchain_http_request_add_header_version_1(
238  runtime::WasmI32 request_id,
239  runtime::WasmSpan name,
240  runtime::WasmSpan value);
241 
262  runtime::WasmSpan ext_offchain_http_request_write_body_version_1(
263  runtime::WasmI32 request_id,
264  runtime::WasmSpan chunk,
265  runtime::WasmSpan deadline);
266 
286  runtime::WasmSpan ext_offchain_http_response_wait_version_1(
287  runtime::WasmSpan ids, runtime::WasmSpan deadline);
288 
302  runtime::WasmSpan ext_offchain_http_response_headers_version_1(
303  runtime::WasmI32 request_id);
304 
326  runtime::WasmSpan ext_offchain_http_response_read_body_version_1(
327  runtime::WasmI32 request_id,
328  runtime::WasmSpan buffer,
329  runtime::WasmSpan deadline);
330 
348  void ext_offchain_set_authorized_nodes_version_1(
349  runtime::WasmSpan nodes, runtime::WasmI32 authorized_only);
350 
363  void ext_offchain_index_set_version_1(runtime::WasmSpan key,
364  runtime::WasmSpan value);
365 
374  void ext_offchain_index_clear_version_1(runtime::WasmSpan key);
375 
376  private:
377  std::shared_ptr<offchain::OffchainWorker> getWorker();
378 
380  std::shared_ptr<const runtime::MemoryProvider> memory_provider_;
381  std::shared_ptr<offchain::OffchainStorage> offchain_storage_;
382  std::shared_ptr<offchain::OffchainWorkerPool> ocw_pool_;
383 
385  };
386 
387 } // namespace kagome::host_api
388 
389 #endif /* KAGOME_OFFCHAIN_EXTENSION_HPP */
uint64_t WasmU64
Definition: types.hpp:47
int32_t WasmI32
Definition: types.hpp:46
const OffchainExtensionConfig & config_
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
std::shared_ptr< const runtime::MemoryProvider > memory_provider_
std::shared_ptr< offchain::OffchainWorkerPool > ocw_pool_
std::shared_ptr< offchain::OffchainStorage > offchain_storage_