Kagome
Polkadot Runtime Engine in C++17
kagome::host_api::OffchainExtension Class Referencefinal

#include <offchain_extension.hpp>

Collaboration diagram for kagome::host_api::OffchainExtension:

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::OffchainWorkergetWorker ()
 

Private Attributes

const OffchainExtensionConfigconfig_
 
std::shared_ptr< const runtime::MemoryProvidermemory_provider_
 
std::shared_ptr< offchain::OffchainStorageoffchain_storage_
 
std::shared_ptr< offchain::OffchainWorkerPoolocw_pool_
 
log::Logger log_
 

Detailed Description

Definition at line 30 of file offchain_extension.hpp.

Constructor & Destructor Documentation

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.

Member Function Documentation

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)

1 (func $ext_offchain_http_request_add_header_version_1
2  (param $request_id i32)
3  (param $name i64)
4  (param $value i64)
5  (result i64)
6 )
Parameters
request_idan i32 integer indicating the ID of the started request
namea pointer-size indicating the HTTP header name
valuea pointer-size indicating the HTTP header value
Returns
a pointer-size indicating the SCALE encoded 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.

1 (func $ext_offchain_http_request_start_version_1
2  (param $method i64)
3  (param $uri i64)
4  (param $meta i64)
5  (result i64)
6 )
Parameters
methoda pointer-size indicating the HTTP method. Possible values are "GET" and "POST"
uria pointer-size indicating the URI
metaa future-reserved field containing additional, SCALE encoded parameters. Currently, an empty array should be passed
Returns
a pointer-size indicating the SCALE encoded 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.

1 (func $ext_offchain_http_request_write_body_version_1
2  (param $request_id i32)
3  (param $chunk i64)
4  (param $deadline i64)
5  (result i64)
6 )
Parameters
request_idan i32 integer indicating the ID of the started request
chunka pointer-size indicating the chunk of bytes. Writing an empty chunk finalizes the request
deadlinea pointer-size indicating the SCALE encoded Option containing the UNIX timestamp. Passing None blocks indefinitely
Returns
a pointer-size indicating the SCALE encoded 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.

1 (func $ext_offchain_http_response_headers_version_1
2  (param $request_id i32)
3  (result i64)
4 )
Parameters
request_idan i32 integer indicating the ID of the started request
Returns
a pointer-size indicating a SCALE encoded array of key/value pairs

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.

1 (func $ext_offchain_http_response_read_body_version_1
2  (param $request_id i32)
3  (param $buffer i64)
4  (param $deadline i64)
5  (result i64)
6 )
Parameters
request_idan i32 integer indicating the ID of the started request
deadlinea pointer-size indicating the SCALE encoded Option containing the UNIX timestamp. Passing None blocks indefinitely
Returns
a pointer-size indicating the SCALE encoded 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.

1 (func $ext_offchain_http_response_wait_version_1
2  (param $ids i64)
3  (param $deadline i64)
4  (result i64)
5 )
Parameters
idsa pointer-size indicating the SCALE encoded array of started request IDs
deadlinea pointer-size indicating the SCALE encoded Option containing the UNIX timestamp. Passing None blocks indefinitely
Returns
a pointer-size indicating the SCALE encoded array of request statuses

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.

1 (func $ext_offchain_index_clear_version_1 (param $key i64))
Parameters
keya 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.

1 (func $ext_offchain_index_set_version_1
2  (param $key i64)
3  (param $value i64)
4 )
Parameters
keya pointer-size indicating the key
valuea 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.

1 (func $ext_offchain_is_validator_version_1 (return i8))
Returns
a boolean equal to true if the node is a validator, false if otherwise

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.

1 (func $ext_offchain_local_storage_clear_version_1
2  (param $kind i32)
3  (param $key i64)
4 )
Parameters
kindan 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
keya 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.

1 (func $ext_offchain_local_storage_compare_and_set_version_1
2  (param $kind i32)
3  (param $key i64)
4  (param $old_value i64)
5  (param $new_value i64)
6  (result i8)
7 )
Parameters
kindan 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
keya pointer-size indicating the key
expecteda pointer-size indicating the old value
valuea pointer-size indicating the new value
Returns
a boolean equal to true if the new value has been set, false if otherwise

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.

1 (func $ext_offchain_local_storage_get_version_1
2  (param $kind i32)
3  (param $key i64)
4  (result i64)
5 )
Parameters
kindan 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
keya pointer-size indicating the key
Returns
a pointer-size indicating the SCALE encoded 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.

1 (func $ext_offchain_local_storage_set_version_1
2  (param $kind i32)
3  (param $key i64)
4  (param $value i64)
5 )
Parameters
kindan 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
keya pointer-size indicating the key
valuea 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.

1 (func $ext_offchain_network_state_version_1 (result i64))
Returns
SCALE encoded 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.

1 (func $ext_offchain_random_seed_version_1 (result i32))
Returns
a 32-bit pointer to the buffer containing the 256-bit seed

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.

1 (func $ext_offchain_set_authorized_nodes_version_1
2  (param $nodes i64)
3  (param $authorized_only i32)
4 )
Parameters
nodesa pointer-size indicating the SCALE encoded array of libp2p PeerId's. Invalid PeerId's are silently ignored
authorized_onlyIf 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.

1 (func $ext_offchain_sleep_until_version_1 (param $deadline u64))
Parameters
deadlinean 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.

1 (func $ext_offchain_submit_transaction_version_1
2  (param $data i64)
3  (return i64)
4 )
Parameters
databyte array storing the encoded extrinsic
Returns
SCALE encoded 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.

1 (func $ext_offchain_timestamp_version_1 (result u64))
Returns
an u64 integer indicating the current UNIX timestamp (milliseconds)

Definition at line 84 of file offchain_extension.cpp.

std::shared_ptr< offchain::OffchainWorker > kagome::host_api::OffchainExtension::getWorker ( )
private

Definition at line 41 of file offchain_extension.cpp.

Member Data Documentation

const OffchainExtensionConfig& kagome::host_api::OffchainExtension::config_
private

Definition at line 379 of file offchain_extension.hpp.

log::Logger kagome::host_api::OffchainExtension::log_
private

Definition at line 384 of file offchain_extension.hpp.

std::shared_ptr<const runtime::MemoryProvider> kagome::host_api::OffchainExtension::memory_provider_
private

Definition at line 380 of file offchain_extension.hpp.

std::shared_ptr<offchain::OffchainWorkerPool> kagome::host_api::OffchainExtension::ocw_pool_
private

Definition at line 382 of file offchain_extension.hpp.

std::shared_ptr<offchain::OffchainStorage> kagome::host_api::OffchainExtension::offchain_storage_
private

Definition at line 381 of file offchain_extension.hpp.


The documentation for this class was generated from the following files: