Trait RoutineOf

Source
pub trait RoutineOf<Identifier, TimeStamp>: Logging<TimeStamp> + Routines<TimeStamp>
where TimeStamp: Time, Identifier: Portable,
{ // Required method fn who(at: &TimeStamp) -> Result<Identifier, Self::Logger>; }
Expand description

Authorization interface for a Routines.

RoutineOf defines who is allowed to execute a routine at a given point in time. It separates authorization from execution, which is especially important in offchain contexts where signing keys, rotation, and node-local state must be handled explicitly.

§Why this exists

Offchain workers do not have the same execution guarantees as runtime calls:

  • there is no transactional rollback,
  • failures do not revert state,
  • and execution is best-effort.

Because of this, authorization must be explicit and checked separately before a routine is allowed to run. RoutineOf provides a uniform way to:

  • derive the concrete identifier (e.g. public key) authorized to run a routine,
  • enforce key rotation and role-based access,
  • fail early if the node is misconfigured or missing required keys.

§Design principles

  • who() must be pure: it must not mutate state.
  • Failures are logged via Logging and treated as hard stops.
  • The returned Identifier is typically used to sign payloads or parameterize execution.

§Example

Determine authorized signer
       |
       V
  who() -> PublicKey
       |
       V
 run_service(by = PublicKey)

Required Methods§

Source

fn who(at: &TimeStamp) -> Result<Identifier, Self::Logger>

Returns the identifier authorized to execute the routine.

If no valid identifier exists (e.g. missing key, inconsistent state), an error is logged and execution must not proceed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§