Kagome
Polkadot Runtime Engine in C++17
|
#include <offchain_extension.hpp>
Public Member Functions | |
OffchainExtension (const OffchainExtensionConfig &config, std::shared_ptr< const runtime::MemoryProvider > memory_provider, std::shared_ptr< offchain::OffchainStorage > offchain_storage, std::shared_ptr< offchain::OffchainWorkerPool > ocw_pool) | |
runtime::WasmI32 | ext_offchain_is_validator_version_1 () |
Check whether the local node is a potential validator. Even if this function returns 1, it does not mean that any keys are configured or that the validator is registered in the chain. More... | |
runtime::WasmSpan | ext_offchain_submit_transaction_version_1 (runtime::WasmSpan data) |
Given a SCALE encoded extrinsic, this function submits the extrinsic to the Host's transaction pool, ready to be propagated to remote peers. More... | |
runtime::WasmSpan | ext_offchain_network_state_version_1 () |
Returns the SCALE encoded, opaque information about the local node's network state. More... | |
runtime::WasmU64 | ext_offchain_timestamp_version_1 () |
Returns current timestamp. More... | |
void | ext_offchain_sleep_until_version_1 (runtime::WasmU64 deadline) |
Pause the execution until deadline is reached. More... | |
runtime::WasmPointer | ext_offchain_random_seed_version_1 () |
Generates a random seed. This is a truly random non deterministic seed generated by the host environment. More... | |
void | ext_offchain_local_storage_set_version_1 (runtime::WasmI32 kind, runtime::WasmSpan key, runtime::WasmSpan value) |
Sets a value in the local storage. This storage is not part of the consensus, it's only accessible by the offchain worker tasks running on the same machine and is persisted between runs. More... | |
void | ext_offchain_local_storage_clear_version_1 (runtime::WasmI32 kind, runtime::WasmSpan key) |
Remove a value from the local storage. More... | |
runtime::WasmI32 | ext_offchain_local_storage_compare_and_set_version_1 (runtime::WasmI32 kind, runtime::WasmSpan key, runtime::WasmSpan expected, runtime::WasmSpan value) |
Sets a new value in the local storage if the condition matches the current value. More... | |
runtime::WasmSpan | ext_offchain_local_storage_get_version_1 (runtime::WasmI32 kind, runtime::WasmSpan key) |
Gets a value from the local storage. More... | |
runtime::WasmSpan | ext_offchain_http_request_start_version_1 (runtime::WasmSpan method, runtime::WasmSpan uri, runtime::WasmSpan meta) |
Initiates a HTTP request given by the HTTP method and the URL. Returns the id of a newly started request. More... | |
runtime::WasmSpan | ext_offchain_http_request_add_header_version_1 (runtime::WasmI32 request_id, runtime::WasmSpan name, runtime::WasmSpan value) |
Append header to the request. Returns an error if the request identifier is invalid, http_response_wait has already been called on the specified request identifier, the deadline is reached or an I/O error has happened (e.g. the remote has closed the connection) More... | |
runtime::WasmSpan | ext_offchain_http_request_write_body_version_1 (runtime::WasmI32 request_id, runtime::WasmSpan chunk, runtime::WasmSpan deadline) |
Writes a chunk of the request body. Returns a non-zero value in case the deadline is reached or the chunk could not be written. More... | |
runtime::WasmSpan | ext_offchain_http_response_wait_version_1 (runtime::WasmSpan ids, runtime::WasmSpan deadline) |
Returns an array of request statuses (the length is the same as IDs). Note that if deadline is not provided the method will block indefinitely, otherwise unready responses will produce DeadlineReached status. More... | |
runtime::WasmSpan | ext_offchain_http_response_headers_version_1 (runtime::WasmI32 request_id) |
Read all HTTP response headers. Returns an array of key/value pairs. Response headers must be read before the response body. More... | |
runtime::WasmSpan | ext_offchain_http_response_read_body_version_1 (runtime::WasmI32 request_id, runtime::WasmSpan buffer, runtime::WasmSpan deadline) |
Reads a chunk of body response to the given buffer. Returns the number of bytes written or an error in case a deadline is reached or the server closed the connection. If 0 is returned it means that the response has been fully consumed and the request_id is now invalid. This implies that response headers must be read before draining the body. More... | |
void | ext_offchain_set_authorized_nodes_version_1 (runtime::WasmSpan nodes, runtime::WasmI32 authorized_only) |
Set the authorized nodes which are allowed to connect to the local node. This function is offered by the Substrate codebase and is primarily used for custom, non-Polkadot/Kusama chains. It is not required for the public and open Polkadot protocol. More... | |
void | ext_offchain_index_set_version_1 (runtime::WasmSpan key, runtime::WasmSpan value) |
Write a key value pair to the offchain database in a buffered fashion. More... | |
void | ext_offchain_index_clear_version_1 (runtime::WasmSpan key) |
Remove a key and its associated value from the offchain database. More... | |
Private Member Functions | |
std::shared_ptr< offchain::OffchainWorker > | getWorker () |
Private Attributes | |
const OffchainExtensionConfig & | config_ |
std::shared_ptr< const runtime::MemoryProvider > | memory_provider_ |
std::shared_ptr< offchain::OffchainStorage > | offchain_storage_ |
std::shared_ptr< offchain::OffchainWorkerPool > | ocw_pool_ |
log::Logger | log_ |
Definition at line 30 of file offchain_extension.hpp.
kagome::host_api::OffchainExtension::OffchainExtension | ( | const OffchainExtensionConfig & | config, |
std::shared_ptr< const runtime::MemoryProvider > | memory_provider, | ||
std::shared_ptr< offchain::OffchainStorage > | offchain_storage, | ||
std::shared_ptr< offchain::OffchainWorkerPool > | ocw_pool | ||
) |
Definition at line 26 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_http_request_add_header_version_1 | ( | runtime::WasmI32 | request_id, |
runtime::WasmSpan | name, | ||
runtime::WasmSpan | value | ||
) |
Append header to the request. Returns an error if the request identifier is invalid, http_response_wait has already been called on the specified request identifier, the deadline is reached or an I/O error has happened (e.g. the remote has closed the connection)
request_id | an i32 integer indicating the ID of the started request |
name | a pointer-size indicating the HTTP header name |
value | a pointer-size indicating the HTTP header value |
Result
. Neither on success or failure is there any additional data provided. The cause of failure is implementation specific Definition at line 283 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_http_request_start_version_1 | ( | runtime::WasmSpan | method, |
runtime::WasmSpan | uri, | ||
runtime::WasmSpan | meta | ||
) |
Initiates a HTTP request given by the HTTP method and the URL. Returns the id of a newly started request.
method | a pointer-size indicating the HTTP method. Possible values are "GET" and "POST" |
uri | a pointer-size indicating the URI |
meta | a future-reserved field containing additional, SCALE encoded parameters. Currently, an empty array should be passed |
Result
containing the i16
ID of the newly started request. On failure no additionally data is provided. The cause of failure is implementation specific Definition at line 231 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_http_request_write_body_version_1 | ( | runtime::WasmI32 | request_id, |
runtime::WasmSpan | chunk, | ||
runtime::WasmSpan | deadline | ||
) |
Writes a chunk of the request body. Returns a non-zero value in case the deadline is reached or the chunk could not be written.
request_id | an i32 integer indicating the ID of the started request |
chunk | a pointer-size indicating the chunk of bytes. Writing an empty chunk finalizes the request |
deadline | a pointer-size indicating the SCALE encoded Option containing the UNIX timestamp. Passing None blocks indefinitely |
Result
. On success, no additional data is provided. On error it contains the HTTP error
type Definition at line 318 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_http_response_headers_version_1 | ( | runtime::WasmI32 | request_id | ) |
Read all HTTP response headers. Returns an array of key/value pairs. Response headers must be read before the response body.
request_id | an i32 integer indicating the ID of the started request |
Definition at line 374 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_http_response_read_body_version_1 | ( | runtime::WasmI32 | request_id, |
runtime::WasmSpan | buffer, | ||
runtime::WasmSpan | deadline | ||
) |
Reads a chunk of body response to the given buffer. Returns the number of bytes written or an error in case a deadline is reached or the server closed the connection. If 0 is returned it means that the response has been fully consumed and the request_id is now invalid. This implies that response headers must be read before draining the body.
request_id | an i32 integer indicating the ID of the started request |
deadline | a pointer-size indicating the SCALE encoded Option containing the UNIX timestamp. Passing None blocks indefinitely |
Result
as defined. On success it contains an i32
integer specifying the number of bytes written or a HTTP error
type on failure Definition at line 389 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_http_response_wait_version_1 | ( | runtime::WasmSpan | ids, |
runtime::WasmSpan | deadline | ||
) |
Returns an array of request statuses (the length is the same as IDs). Note that if deadline is not provided the method will block indefinitely, otherwise unready responses will produce DeadlineReached status.
ids | a pointer-size indicating the SCALE encoded array of started request IDs |
deadline | a pointer-size indicating the SCALE encoded Option containing the UNIX timestamp. Passing None blocks indefinitely |
Definition at line 345 of file offchain_extension.cpp.
void kagome::host_api::OffchainExtension::ext_offchain_index_clear_version_1 | ( | runtime::WasmSpan | key | ) |
Remove a key and its associated value from the offchain database.
key | a pointer-size indicating the key |
Definition at line 464 of file offchain_extension.cpp.
void kagome::host_api::OffchainExtension::ext_offchain_index_set_version_1 | ( | runtime::WasmSpan | key, |
runtime::WasmSpan | value | ||
) |
Write a key value pair to the offchain database in a buffered fashion.
key | a pointer-size indicating the key |
value | a pointer-size indicating the value |
Definition at line 445 of file offchain_extension.cpp.
runtime::WasmI32 kagome::host_api::OffchainExtension::ext_offchain_is_validator_version_1 | ( | ) |
Check whether the local node is a potential validator. Even if this function returns 1, it does not mean that any keys are configured or that the validator is registered in the chain.
Definition at line 50 of file offchain_extension.cpp.
void kagome::host_api::OffchainExtension::ext_offchain_local_storage_clear_version_1 | ( | runtime::WasmI32 | kind, |
runtime::WasmSpan | key | ||
) |
Remove a value from the local storage.
kind | an i32 integer indicating the storage kind. A value equal to 1 is used for a persistent storage and a value equal to 2 for local storage |
key | a pointer-size indicating the key |
Definition at line 130 of file offchain_extension.cpp.
runtime::WasmI32 kagome::host_api::OffchainExtension::ext_offchain_local_storage_compare_and_set_version_1 | ( | runtime::WasmI32 | kind, |
runtime::WasmSpan | key, | ||
runtime::WasmSpan | expected, | ||
runtime::WasmSpan | value | ||
) |
Sets a new value in the local storage if the condition matches the current value.
kind | an i32 integer indicating the storage kind. A value equal to 1 is used for a persistent storage and a value equal to 2 for local storage |
key | a pointer-size indicating the key |
expected | a pointer-size indicating the old value |
value | a pointer-size indicating the new value |
Definition at line 156 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_local_storage_get_version_1 | ( | runtime::WasmI32 | kind, |
runtime::WasmSpan | key | ||
) |
Gets a value from the local storage.
kind | an i32 integer indicating the storage kind. A value equal to 1 is used for a persistent storage and a value equal to 2 for local storage |
key | a pointer-size indicating the key |
Option
containing the value or the corresponding key Definition at line 201 of file offchain_extension.cpp.
void kagome::host_api::OffchainExtension::ext_offchain_local_storage_set_version_1 | ( | runtime::WasmI32 | kind, |
runtime::WasmSpan | key, | ||
runtime::WasmSpan | value | ||
) |
Sets a value in the local storage. This storage is not part of the consensus, it's only accessible by the offchain worker tasks running on the same machine and is persisted between runs.
kind | an i32 integer indicating the storage kind. A value equal to 1 is used for a persistent storage and a value equal to 2 for local storage |
key | a pointer-size indicating the key |
value | a pointer-size indicating the value |
Definition at line 103 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_network_state_version_1 | ( | ) |
Returns the SCALE encoded, opaque information about the local node's network state.
Result
. On success it contains the OpaqueNetworkState
structure. On failure, an empty value is yielded where its cause is implementation specific Definition at line 75 of file offchain_extension.cpp.
runtime::WasmPointer kagome::host_api::OffchainExtension::ext_offchain_random_seed_version_1 | ( | ) |
Generates a random seed. This is a truly random non deterministic seed generated by the host environment.
Definition at line 96 of file offchain_extension.cpp.
void kagome::host_api::OffchainExtension::ext_offchain_set_authorized_nodes_version_1 | ( | runtime::WasmSpan | nodes, |
runtime::WasmI32 | authorized_only | ||
) |
Set the authorized nodes which are allowed to connect to the local node. This function is offered by the Substrate codebase and is primarily used for custom, non-Polkadot/Kusama chains. It is not required for the public and open Polkadot protocol.
nodes | a pointer-size indicating the SCALE encoded array of libp2p PeerId's. Invalid PeerId's are silently ignored |
authorized_only | If set to 1, then only the authorized nodes are allowed to connect to the local node (whitelist). All other nodes are rejected. If set to 0, then no such restriction is placed |
Definition at line 419 of file offchain_extension.cpp.
void kagome::host_api::OffchainExtension::ext_offchain_sleep_until_version_1 | ( | runtime::WasmU64 | deadline | ) |
Pause the execution until deadline
is reached.
deadline | an u64 integer indicating the current UNIX timestamp (milliseconds) |
Definition at line 90 of file offchain_extension.cpp.
runtime::WasmSpan kagome::host_api::OffchainExtension::ext_offchain_submit_transaction_version_1 | ( | runtime::WasmSpan | data | ) |
Given a SCALE encoded extrinsic, this function submits the extrinsic to the Host's transaction pool, ready to be propagated to remote peers.
data | byte array storing the encoded extrinsic |
Result
. Neither on success or failure is there any additional data provided Definition at line 57 of file offchain_extension.cpp.
runtime::WasmU64 kagome::host_api::OffchainExtension::ext_offchain_timestamp_version_1 | ( | ) |
Returns current timestamp.
Definition at line 84 of file offchain_extension.cpp.
|
private |
Definition at line 41 of file offchain_extension.cpp.
|
private |
Definition at line 379 of file offchain_extension.hpp.
|
private |
Definition at line 384 of file offchain_extension.hpp.
|
private |
Definition at line 380 of file offchain_extension.hpp.
|
private |
Definition at line 382 of file offchain_extension.hpp.
|
private |
Definition at line 381 of file offchain_extension.hpp.