Trait sp_core::offchain::Externalities
source · pub trait Externalities: Send {
// Required methods
fn is_validator(&self) -> bool;
fn network_state(&self) -> Result<OpaqueNetworkState, ()>;
fn timestamp(&mut self) -> Timestamp;
fn sleep_until(&mut self, deadline: Timestamp);
fn random_seed(&mut self) -> [u8; 32];
fn set_authorized_nodes(
&mut self,
nodes: Vec<OpaquePeerId>,
authorized_only: bool,
);
}
Expand description
An extended externalities for offchain workers.
Required Methods§
sourcefn is_validator(&self) -> bool
fn is_validator(&self) -> bool
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.
sourcefn network_state(&self) -> Result<OpaqueNetworkState, ()>
fn network_state(&self) -> Result<OpaqueNetworkState, ()>
Returns information about the local node’s network state.
sourcefn sleep_until(&mut self, deadline: Timestamp)
fn sleep_until(&mut self, deadline: Timestamp)
Pause the execution until deadline
is reached.
sourcefn random_seed(&mut self) -> [u8; 32]
fn random_seed(&mut self) -> [u8; 32]
Returns a random seed.
This is a truly random non deterministic seed generated by host environment. Obviously fine in the off-chain worker context.
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.