Trait sp_core::offchain::Externalities [−][src]
An extended externalities for offchain workers.
Required methods
fn is_validator(&self) -> bool
[src]
Returns if the local node is a potential validator.
Even if this function returns true
, it does not mean that any keys are configured
and that the validator is registered in the chain.
fn network_state(&self) -> Result<OpaqueNetworkState, ()>
[src]
Returns information about the local node's network state.
fn timestamp(&mut self) -> Timestamp
[src]
Returns current UNIX timestamp (in millis)
fn sleep_until(&mut self, deadline: Timestamp)
[src]
Pause the execution until deadline
is reached.
fn random_seed(&mut self) -> [u8; 32]
[src]
Returns a random seed.
This is a truly random non deterministic seed generated by host environment. Obviously fine in the off-chain worker context.
fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8])
[src]
Sets a value in the local storage.
Note this storage is not part of the consensus, it's only accessible by offchain worker tasks running on the same machine. It is persisted between runs.
fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8])
[src]
Removes a value in the local storage.
Note this storage is not part of the consensus, it's only accessible by offchain worker tasks running on the same machine. It is persisted between runs.
fn local_storage_compare_and_set(
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
[src]
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
Sets a value in the local storage if it matches current value.
Since multiple offchain workers may be running concurrently, to prevent data races use CAS to coordinate between them.
Returns true
if the value has been set, false
otherwise.
Note this storage is not part of the consensus, it's only accessible by offchain worker tasks running on the same machine. It is persisted between runs.
fn local_storage_get(
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
[src]
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
Gets a value from the local storage.
If the value does not exist in the storage None
will be returned.
Note this storage is not part of the consensus, it's only accessible by
offchain worker tasks running on the same machine. It is persisted between runs.
fn http_request_start(
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<HttpRequestId, ()>
[src]
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<HttpRequestId, ()>
Initiates a http request given HTTP verb and the URL.
Meta is a future-reserved field containing additional, parity-scale-codec encoded parameters. Returns the id of newly started request.
Returns an error if:
- No new request identifier could be allocated.
- The method or URI contain invalid characters.
fn http_request_add_header(
&mut self,
request_id: HttpRequestId,
name: &str,
value: &str
) -> Result<(), ()>
[src]
&mut self,
request_id: HttpRequestId,
name: &str,
value: &str
) -> Result<(), ()>
Append header to the request.
Calling this function multiple times with the same header name continues appending new headers. In other words, headers are never replaced.
Returns an error if:
- The request identifier is invalid.
- You have called
http_request_write_body
on that request. - The name or value contain invalid characters.
An error doesn't poison the request, and you can continue as if the call had never been made.
fn http_request_write_body(
&mut self,
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
) -> Result<(), HttpError>
[src]
&mut self,
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
) -> Result<(), HttpError>
Write a chunk of request body.
Calling this function with a non-empty slice may or may not start the
HTTP request. Calling this function with an empty chunks finalizes the
request and always starts it. It is no longer valid to write more data
afterwards.
Passing None
as deadline blocks forever.
Returns an error if:
- The request identifier is invalid.
http_response_wait
has already been called on this request.- The deadline is reached.
- An I/O error has happened, for example the remote has closed our request. The request is then considered invalid.
fn http_response_wait(
&mut self,
ids: &[HttpRequestId],
deadline: Option<Timestamp>
) -> Vec<HttpRequestStatus>ⓘ
[src]
&mut self,
ids: &[HttpRequestId],
deadline: Option<Timestamp>
) -> Vec<HttpRequestStatus>ⓘ
Block and wait for the responses for given requests.
Returns a vector of request statuses (the len is the same as ids).
Note that if deadline is not provided the method will block indefinitely,
otherwise unready responses will produce DeadlineReached
status.
If a response returns an IoError
, it is then considered destroyed.
Its id is then invalid.
Passing None
as deadline blocks forever.
fn http_response_headers(
&mut self,
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
[src]
&mut self,
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
Read all response headers.
Returns a vector of pairs (HeaderKey, HeaderValue)
.
Dispatches the request if it hasn't been done yet. It is no longer valid to modify the headers or write data to the request.
Returns an empty list if the identifier is unknown/invalid, hasn't received a response, or has finished.
fn http_response_read_body(
&mut self,
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
) -> Result<usize, HttpError>
[src]
&mut self,
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
) -> Result<usize, HttpError>
Read a chunk of body response to given buffer.
Dispatches the request if it hasn't been done yet. It is no longer valid to modify the headers or write data to the request.
Returns the number of bytes written or an error in case a deadline
is reached or server closed the connection.
Passing None
as a deadline blocks forever.
If Ok(0)
or Err(IoError)
is returned, the request is considered
destroyed. Doing another read or getting the response's headers, for
example, is then invalid.
Returns an error if:
- The request identifier is invalid.
- The deadline is reached.
- An I/O error has happened, for example the remote has closed our request. The request is then considered invalid.
fn set_authorized_nodes(
&mut self,
nodes: Vec<OpaquePeerId>,
authorized_only: bool
)
[src]
&mut self,
nodes: Vec<OpaquePeerId>,
authorized_only: bool
)
Set the authorized nodes from runtime.
In a permissioned network, the connections between nodes need to reach a consensus between participants.
nodes
: a set of nodes which are allowed to connect for the local node. each one is identified with anOpaquePeerId
, here it just use plain bytes without any encoding. InvalidOpaquePeerId
s are silently ignored.authorized_only
: if true, only the authorized nodes are allowed to connect, otherwise unauthorized nodes can also be connected through other mechanism.
Implementations on Foreign Types
impl<T: Externalities + ?Sized> Externalities for Box<T>
[src]
fn is_validator(&self) -> bool
[src]
fn network_state(&self) -> Result<OpaqueNetworkState, ()>
[src]
fn timestamp(&mut self) -> Timestamp
[src]
fn sleep_until(&mut self, deadline: Timestamp)
[src]
fn random_seed(&mut self) -> [u8; 32]
[src]
fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8])
[src]
fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8])
[src]
fn local_storage_compare_and_set(
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
[src]
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
fn local_storage_get(
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
[src]
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
fn http_request_start(
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<HttpRequestId, ()>
[src]
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<HttpRequestId, ()>
fn http_request_add_header(
&mut self,
request_id: HttpRequestId,
name: &str,
value: &str
) -> Result<(), ()>
[src]
&mut self,
request_id: HttpRequestId,
name: &str,
value: &str
) -> Result<(), ()>
fn http_request_write_body(
&mut self,
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
) -> Result<(), HttpError>
[src]
&mut self,
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
) -> Result<(), HttpError>
fn http_response_wait(
&mut self,
ids: &[HttpRequestId],
deadline: Option<Timestamp>
) -> Vec<HttpRequestStatus>ⓘ
[src]
&mut self,
ids: &[HttpRequestId],
deadline: Option<Timestamp>
) -> Vec<HttpRequestStatus>ⓘ
fn http_response_headers(
&mut self,
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
[src]
&mut self,
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
fn http_response_read_body(
&mut self,
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
) -> Result<usize, HttpError>
[src]
&mut self,
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
) -> Result<usize, HttpError>
fn set_authorized_nodes(
&mut self,
nodes: Vec<OpaquePeerId>,
authorized_only: bool
)
[src]
&mut self,
nodes: Vec<OpaquePeerId>,
authorized_only: bool
)
Implementors
impl Externalities for TestOffchainExt
[src]
fn is_validator(&self) -> bool
[src]
fn network_state(&self) -> Result<OpaqueNetworkState, ()>
[src]
fn timestamp(&mut self) -> Timestamp
[src]
fn sleep_until(&mut self, deadline: Timestamp)
[src]
fn random_seed(&mut self) -> [u8; 32]
[src]
fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8])
[src]
fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8])
[src]
fn local_storage_compare_and_set(
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
[src]
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
fn local_storage_get(
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
[src]
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
fn http_request_start(
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<RequestId, ()>
[src]
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<RequestId, ()>
fn http_request_add_header(
&mut self,
request_id: RequestId,
name: &str,
value: &str
) -> Result<(), ()>
[src]
&mut self,
request_id: RequestId,
name: &str,
value: &str
) -> Result<(), ()>
fn http_request_write_body(
&mut self,
request_id: RequestId,
chunk: &[u8],
_deadline: Option<Timestamp>
) -> Result<(), HttpError>
[src]
&mut self,
request_id: RequestId,
chunk: &[u8],
_deadline: Option<Timestamp>
) -> Result<(), HttpError>
fn http_response_wait(
&mut self,
ids: &[RequestId],
_deadline: Option<Timestamp>
) -> Vec<RequestStatus>ⓘ
[src]
&mut self,
ids: &[RequestId],
_deadline: Option<Timestamp>
) -> Vec<RequestStatus>ⓘ
fn http_response_headers(
&mut self,
request_id: RequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
[src]
&mut self,
request_id: RequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
fn http_response_read_body(
&mut self,
request_id: RequestId,
buffer: &mut [u8],
_deadline: Option<Timestamp>
) -> Result<usize, HttpError>
[src]
&mut self,
request_id: RequestId,
buffer: &mut [u8],
_deadline: Option<Timestamp>
) -> Result<usize, HttpError>
fn set_authorized_nodes(
&mut self,
_nodes: Vec<OpaquePeerId>,
_authorized_only: bool
)
[src]
&mut self,
_nodes: Vec<OpaquePeerId>,
_authorized_only: bool
)
impl<T: Externalities> Externalities for LimitedExternalities<T>
[src]
fn is_validator(&self) -> bool
[src]
fn network_state(&self) -> Result<OpaqueNetworkState, ()>
[src]
fn timestamp(&mut self) -> Timestamp
[src]
fn sleep_until(&mut self, deadline: Timestamp)
[src]
fn random_seed(&mut self) -> [u8; 32]
[src]
fn local_storage_set(&mut self, kind: StorageKind, key: &[u8], value: &[u8])
[src]
fn local_storage_clear(&mut self, kind: StorageKind, key: &[u8])
[src]
fn local_storage_compare_and_set(
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
[src]
&mut self,
kind: StorageKind,
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8]
) -> bool
fn local_storage_get(
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
[src]
&mut self,
kind: StorageKind,
key: &[u8]
) -> Option<Vec<u8>>
fn http_request_start(
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<HttpRequestId, ()>
[src]
&mut self,
method: &str,
uri: &str,
meta: &[u8]
) -> Result<HttpRequestId, ()>
fn http_request_add_header(
&mut self,
request_id: HttpRequestId,
name: &str,
value: &str
) -> Result<(), ()>
[src]
&mut self,
request_id: HttpRequestId,
name: &str,
value: &str
) -> Result<(), ()>
fn http_request_write_body(
&mut self,
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
) -> Result<(), HttpError>
[src]
&mut self,
request_id: HttpRequestId,
chunk: &[u8],
deadline: Option<Timestamp>
) -> Result<(), HttpError>
fn http_response_wait(
&mut self,
ids: &[HttpRequestId],
deadline: Option<Timestamp>
) -> Vec<HttpRequestStatus>ⓘ
[src]
&mut self,
ids: &[HttpRequestId],
deadline: Option<Timestamp>
) -> Vec<HttpRequestStatus>ⓘ
fn http_response_headers(
&mut self,
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
[src]
&mut self,
request_id: HttpRequestId
) -> Vec<(Vec<u8>, Vec<u8>)>ⓘ
fn http_response_read_body(
&mut self,
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
) -> Result<usize, HttpError>
[src]
&mut self,
request_id: HttpRequestId,
buffer: &mut [u8],
deadline: Option<Timestamp>
) -> Result<usize, HttpError>
fn set_authorized_nodes(
&mut self,
nodes: Vec<OpaquePeerId>,
authorized_only: bool
)
[src]
&mut self,
nodes: Vec<OpaquePeerId>,
authorized_only: bool
)