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§

source

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.

source

fn network_state(&self) -> Result<OpaqueNetworkState, ()>

Returns information about the local node’s network state.

source

fn timestamp(&mut self) -> Timestamp

Returns current UNIX timestamp (in millis)

source

fn sleep_until(&mut self, deadline: Timestamp)

Pause the execution until deadline is reached.

source

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.

source

fn set_authorized_nodes( &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 an OpaquePeerId, here it just use plain bytes without any encoding. Invalid OpaquePeerIds 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§

source§

impl<T: Externalities + ?Sized> Externalities for Box<T>

source§

fn is_validator(&self) -> bool

source§

fn network_state(&self) -> Result<OpaqueNetworkState, ()>

source§

fn timestamp(&mut self) -> Timestamp

source§

fn sleep_until(&mut self, deadline: Timestamp)

source§

fn random_seed(&mut self) -> [u8; 32]

source§

fn set_authorized_nodes( &mut self, nodes: Vec<OpaquePeerId>, authorized_only: bool, )

Implementors§