Kagome
Polkadot Runtime Engine in C++17
host_api.hpp
Go to the documentation of this file.
1 
6 #ifndef KAGOME_HOST_API_HPP
7 #define KAGOME_HOST_API_HPP
8 
9 #include <cstdint>
10 #include <functional>
11 #include <memory>
12 
13 #include "runtime/ptr_size.hpp"
14 #include "runtime/types.hpp"
15 
16 namespace kagome::runtime {
17  class Memory;
18 }
19 
20 namespace kagome::host_api {
25  class HostApi {
26  public:
27  virtual ~HostApi() = default;
28 
29  virtual void reset() = 0;
30 
31  // ------------------------- Storage extensions v1 -------------------------
32 
39  [[nodiscard]] virtual runtime::WasmSpan ext_storage_read_version_1(
41  runtime::WasmSpan value_out,
42  runtime::WasmOffset offset) = 0;
43 
49  virtual void ext_storage_set_version_1(runtime::WasmSpan key,
50  runtime::WasmSpan value) = 0;
51 
57  [[nodiscard]] virtual runtime::WasmSpan ext_storage_get_version_1(
58  runtime::WasmSpan key) = 0;
59 
64  virtual void ext_storage_clear_version_1(runtime::WasmSpan key_data) = 0;
65 
72  [[nodiscard]] virtual runtime::WasmSize ext_storage_exists_version_1(
73  runtime::WasmSpan key_data) const = 0;
74 
80  virtual void ext_storage_clear_prefix_version_1(
81  runtime::WasmSpan prefix) = 0;
82 
89  virtual runtime::WasmSpan ext_storage_clear_prefix_version_2(
90  runtime::WasmSpan prefix, runtime::WasmSpan limit) = 0;
91 
97  [[nodiscard]] virtual runtime::WasmSpan ext_storage_root_version_1() = 0;
98 
107  [[nodiscard]] virtual runtime::WasmSpan ext_storage_root_version_2(
108  runtime::WasmI32 state_version) = 0;
109 
116  [[nodiscard]] virtual runtime::WasmSpan ext_storage_changes_root_version_1(
117  runtime::WasmSpan parent_hash) = 0;
118 
124  [[nodiscard]] virtual runtime::WasmSpan ext_storage_next_key_version_1(
125  runtime::WasmSpan key) const = 0;
126 
137  virtual void ext_storage_append_version_1(
138  runtime::WasmSpan key, runtime::WasmSpan value) const = 0;
139 
146  virtual void ext_storage_start_transaction_version_1() = 0;
147 
152  virtual void ext_storage_rollback_transaction_version_1() = 0;
153 
158  virtual void ext_storage_commit_transaction_version_1() = 0;
159 
167  [[nodiscard]] virtual runtime::WasmPointer
168  ext_trie_blake2_256_root_version_1(runtime::WasmSpan values_data) = 0;
169 
179  [[nodiscard]] virtual runtime::WasmPointer
180  ext_trie_blake2_256_ordered_root_version_1(
181  runtime::WasmSpan values_data) = 0;
182 
183  // TODO(xDimon): add doc-comment
184  [[nodiscard]] virtual runtime::WasmPointer
185  ext_trie_blake2_256_ordered_root_version_2(
186  runtime::WasmSpan values_data, runtime::WasmI32 state_version) = 0;
187 
188  // ------------------------- Memory extensions v1 --------------------------
192  [[nodiscard]] virtual runtime::WasmPointer ext_allocator_malloc_version_1(
193  runtime::WasmSize size) = 0;
194 
198  virtual void ext_allocator_free_version_1(runtime::WasmPointer ptr) = 0;
199 
200  // ---------------------------- I/O extensions -----------------------------
201 
208  virtual void ext_logging_log_version_1(runtime::WasmEnum level,
209  runtime::WasmSpan target,
210  runtime::WasmSpan message) = 0;
214  virtual runtime::WasmEnum ext_logging_max_level_version_1() = 0;
215 
216  // ------------------------ Cryptographic extensions -----------------------
217 
223  virtual void ext_crypto_start_batch_verify_version_1() = 0;
224 
233  [[nodiscard]] virtual int32_t
234  ext_crypto_finish_batch_verify_version_1() = 0;
235 
243  [[nodiscard]] virtual runtime::WasmSpan
244  ext_crypto_secp256k1_ecdsa_recover_version_1(runtime::WasmPointer sig,
245  runtime::WasmPointer msg) = 0;
246  [[nodiscard]] virtual runtime::WasmSpan
247  ext_crypto_secp256k1_ecdsa_recover_version_2(runtime::WasmPointer sig,
248  runtime::WasmPointer msg) = 0;
249 
257  [[nodiscard]] virtual runtime::WasmSpan
258  ext_crypto_secp256k1_ecdsa_recover_compressed_version_1(
260  [[nodiscard]] virtual runtime::WasmSpan
261  ext_crypto_secp256k1_ecdsa_recover_compressed_version_2(
263 
264  // ------------------------- Hashing extension/crypto ----------------------
265 
266  [[nodiscard]] virtual runtime::WasmPointer ext_hashing_keccak_256_version_1(
267  runtime::WasmSpan data) = 0;
268 
269  [[nodiscard]] virtual runtime::WasmPointer ext_hashing_sha2_256_version_1(
270  runtime::WasmSpan data) = 0;
271 
272  [[nodiscard]] virtual runtime::WasmPointer ext_hashing_blake2_128_version_1(
273  runtime::WasmSpan data) = 0;
274 
275  [[nodiscard]] virtual runtime::WasmPointer ext_hashing_blake2_256_version_1(
276  runtime::WasmSpan data) = 0;
277 
278  [[nodiscard]] virtual runtime::WasmPointer ext_hashing_twox_64_version_1(
279  runtime::WasmSpan data) = 0;
280 
281  [[nodiscard]] virtual runtime::WasmPointer ext_hashing_twox_128_version_1(
282  runtime::WasmSpan data) = 0;
283 
284  [[nodiscard]] virtual runtime::WasmPointer ext_hashing_twox_256_version_1(
285  runtime::WasmSpan data) = 0;
286 
287  // --------------------------- Crypto extensions v1 ------------------------
288 
292  [[nodiscard]] virtual runtime::WasmSpan
293  ext_crypto_ed25519_public_keys_version_1(runtime::WasmSize key_type) = 0;
294 
298  [[nodiscard]] virtual runtime::WasmPointer
299  ext_crypto_ed25519_generate_version_1(runtime::WasmSize key_type,
300  runtime::WasmSpan seed) = 0;
301 
305  [[nodiscard]] virtual runtime::WasmSpan ext_crypto_ed25519_sign_version_1(
306  runtime::WasmSize key_type,
308  runtime::WasmSpan msg_data) = 0;
309 
313  [[nodiscard]] virtual runtime::WasmSize ext_crypto_ed25519_verify_version_1(
314  runtime::WasmPointer sig_data,
315  runtime::WasmSpan msg,
316  runtime::WasmPointer pubkey_data) = 0;
317 
321  [[nodiscard]] virtual runtime::WasmSpan
322  ext_crypto_sr25519_public_keys_version_1(runtime::WasmSize key_type) = 0;
323 
327  [[nodiscard]] virtual runtime::WasmPointer
328  ext_crypto_sr25519_generate_version_1(runtime::WasmSize key_type,
329  runtime::WasmSpan seed) = 0;
330 
334  [[nodiscard]] virtual runtime::WasmSpan ext_crypto_sr25519_sign_version_1(
335  runtime::WasmSize key_type,
337  runtime::WasmSpan msg_data) = 0;
338 
352  [[nodiscard]] virtual int32_t ext_crypto_sr25519_verify_version_1(
353  runtime::WasmPointer sig_data,
354  runtime::WasmSpan msg,
355  runtime::WasmPointer pubkey_data) = 0;
356 
357  [[nodiscard]] virtual int32_t ext_crypto_sr25519_verify_version_2(
358  runtime::WasmPointer sig_data,
359  runtime::WasmSpan msg,
360  runtime::WasmPointer pubkey_data) = 0;
361 
365  [[nodiscard]] virtual runtime::WasmSpan
366  ext_crypto_ecdsa_public_keys_version_1(runtime::WasmSize key_type) = 0;
367 
371  [[nodiscard]] virtual runtime::WasmSpan ext_crypto_ecdsa_sign_version_1(
372  runtime::WasmSize key_type,
374  runtime::WasmSpan msg_data) = 0;
375 
389  [[nodiscard]] virtual runtime::WasmSpan
390  ext_crypto_ecdsa_sign_prehashed_version_1(runtime::WasmSize key_type,
392  runtime::WasmSpan msg_data) = 0;
393 
405  [[nodiscard]] virtual runtime::WasmPointer
406  ext_crypto_ecdsa_generate_version_1(runtime::WasmSize key_type,
407  runtime::WasmSpan seed) = 0;
408 
427  [[nodiscard]] virtual int32_t ext_crypto_ecdsa_verify_version_1(
428  runtime::WasmPointer sig_data,
429  runtime::WasmSpan msg,
430  runtime::WasmPointer pubkey_data) = 0;
431 
450  [[nodiscard]] virtual int32_t ext_crypto_ecdsa_verify_prehashed_version_1(
451  runtime::WasmPointer sig_data,
452  runtime::WasmSpan msg,
453  runtime::WasmPointer pubkey_data) = 0;
454 
455  // ---------------------------- Misc extensions ----------------------------
456 
457  [[nodiscard]] virtual runtime::WasmSpan ext_misc_runtime_version_version_1(
458  runtime::WasmSpan data) const = 0;
459 
464  virtual void ext_misc_print_hex_version_1(runtime::WasmSpan data) const = 0;
465 
470  virtual void ext_misc_print_num_version_1(uint64_t value) const = 0;
471 
476  virtual void ext_misc_print_utf8_version_1(
477  runtime::WasmSpan data) const = 0;
478 
479  // -------------------------- Offchain extension ---------------------------
480 
482  [[nodiscard]] virtual runtime::WasmI32
483  ext_offchain_is_validator_version_1() = 0;
484 
486  [[nodiscard]] virtual runtime::WasmSpan
487  ext_offchain_submit_transaction_version_1(runtime::WasmSpan data) = 0;
488 
490  [[nodiscard]] virtual runtime::WasmSpan
491  ext_offchain_network_state_version_1() = 0;
492 
494  [[nodiscard]] virtual runtime::WasmU64
495  ext_offchain_timestamp_version_1() = 0;
496 
498  virtual void ext_offchain_sleep_until_version_1(
499  runtime::WasmU64 deadline) = 0;
500 
502  [[nodiscard]] virtual runtime::WasmPointer
503  ext_offchain_random_seed_version_1() = 0;
504 
506  virtual void ext_offchain_local_storage_set_version_1(
507  runtime::WasmI32 kind,
508  runtime::WasmSpan key,
509  runtime::WasmSpan value) = 0;
510 
512  virtual void ext_offchain_local_storage_clear_version_1(
513  runtime::WasmI32 kind, runtime::WasmSpan key) = 0;
514 
517  [[nodiscard]] virtual runtime::WasmI32
518  ext_offchain_local_storage_compare_and_set_version_1(
519  runtime::WasmI32 kind,
520  runtime::WasmSpan key,
521  runtime::WasmSpan expected,
522  runtime::WasmSpan value) = 0;
523 
525  [[nodiscard]] virtual runtime::WasmSpan
526  ext_offchain_local_storage_get_version_1(runtime::WasmI32 kind,
527  runtime::WasmSpan key) = 0;
528 
530  [[nodiscard]] virtual runtime::WasmSpan
531  ext_offchain_http_request_start_version_1(runtime::WasmSpan method,
532  runtime::WasmSpan uri,
533  runtime::WasmSpan meta) = 0;
534 
537  [[nodiscard]] virtual runtime::WasmSpan
538  ext_offchain_http_request_add_header_version_1(runtime::WasmI32 request_id,
539  runtime::WasmSpan name,
540  runtime::WasmSpan value) = 0;
541 
544  [[nodiscard]] virtual runtime::WasmSpan
545  ext_offchain_http_request_write_body_version_1(
546  runtime::WasmI32 request_id,
547  runtime::WasmSpan chunk,
548  runtime::WasmSpan deadline) = 0;
549 
551  [[nodiscard]] virtual runtime::WasmSpan
552  ext_offchain_http_response_wait_version_1(runtime::WasmSpan ids,
553  runtime::WasmSpan deadline) = 0;
554 
556  virtual runtime::WasmSpan ext_offchain_http_response_headers_version_1(
557  runtime::WasmI32 request_id) = 0;
558 
561  [[nodiscard]] virtual runtime::WasmSpan
562  ext_offchain_http_response_read_body_version_1(
563  runtime::WasmI32 request_id,
564  runtime::WasmSpan buffer,
565  runtime::WasmSpan deadline) = 0;
566 
568  virtual void ext_offchain_set_authorized_nodes_version_1(
569  runtime::WasmSpan nodes, runtime::WasmI32 authorized_only) = 0;
570 
572  virtual void ext_offchain_index_set_version_1(runtime::WasmSpan key,
573  runtime::WasmSpan value) = 0;
574 
576  virtual void ext_offchain_index_clear_version_1(runtime::WasmSpan key) = 0;
577 
578  // ---------------------------- Child Storage ----------------------------
579 
586  virtual void ext_default_child_storage_set_version_1(
587  runtime::WasmSpan child_storage_key,
588  runtime::WasmSpan key,
589  runtime::WasmSpan value) = 0;
590 
599  virtual runtime::WasmSpan ext_default_child_storage_get_version_1(
600  runtime::WasmSpan child_storage_key, runtime::WasmSpan key) const = 0;
601 
608  virtual void ext_default_child_storage_clear_version_1(
609  runtime::WasmSpan child_storage_key, runtime::WasmSpan key) = 0;
610 
620  virtual runtime::WasmSpan ext_default_child_storage_next_key_version_1(
621  runtime::WasmSpan child_storage_key, runtime::WasmSpan key) const = 0;
622 
629  virtual runtime::WasmSpan ext_default_child_storage_root_version_1(
630  runtime::WasmSpan child_storage_key) const = 0;
631 
638  virtual void ext_default_child_storage_clear_prefix_version_1(
639  runtime::WasmSpan child_storage_key, runtime::WasmSpan prefix) = 0;
640 
658  virtual runtime::WasmSpan ext_default_child_storage_read_version_1(
659  runtime::WasmSpan child_storage_key,
660  runtime::WasmSpan key,
661  runtime::WasmSpan value_out,
662  runtime::WasmOffset offset) const = 0;
663 
671  virtual uint32_t ext_default_child_storage_exists_version_1(
672  runtime::WasmSpan child_storage_key, runtime::WasmSpan key) const = 0;
673 
678  virtual void ext_default_child_storage_storage_kill_version_1(
679  runtime::WasmSpan child_storage_key) = 0;
680  };
681 } // namespace kagome::host_api
682 
683 #endif // KAGOME_HOST_API_HPP
uint64_t WasmU64
Definition: types.hpp:47
uint32_t WasmSize
Size type is uint32_t because we are working in 32 bit address space.
Definition: types.hpp:35
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
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 WasmEnum
Enum value is uint32_t.
Definition: types.hpp:39
uint32_t WasmPointer
type of wasm memory is 32 bit integer
Definition: types.hpp:26