Trait Service

Source
pub trait Service {
    // Required methods
    fn refine(
        id: ServiceId,
        payload: WorkPayload,
        package_hash: WorkPackageHash,
        context: RefineContext,
        auth_code_hash: CodeHash,
    ) -> WorkOutput;
    fn accumulate(
        slot: Slot,
        id: ServiceId,
        results: Vec<AccumulateItem>,
    ) -> Option<Hash>;
    fn on_transfer(slot: Slot, id: ServiceId, transfers: Vec<TransferRecord>);
}
Expand description

The invocation trait for a JAM service.

The declare_service macro requires that its parameter implement this trait.

Required Methods§

Source

fn refine( id: ServiceId, payload: WorkPayload, package_hash: WorkPackageHash, context: RefineContext, auth_code_hash: CodeHash, ) -> WorkOutput

The Refine entry-point, used in-core on a single Work Item.

  • id: The index of the service being refined.
  • payload: The payload data to process.
  • package_hash: The hash of the Work Package.
  • context: Various pieces of contextual information for the Refinement process.
  • auth_code_hash: The hash of the authorizer code which was used to authorize the Work Package.

Returns the Work Output, which will be passed into Self::accumulate in the on-chain (stateful) context.

Source

fn accumulate( slot: Slot, id: ServiceId, results: Vec<AccumulateItem>, ) -> Option<Hash>

The Accumulate entry-point, used on-chain on one or more Work Item Outputs, or possibly none in the case of an always-accumulate service.

  • slot: The current time slot.
  • id: The service ID being accumulated.
  • results: The Work Outputs of the Work Items, together with additional information on the Work Packages which brought them about.
Source

fn on_transfer(slot: Slot, id: ServiceId, transfers: Vec<TransferRecord>)

The On Transfer entry-point, used on-chain on one or more Transfers.

  • slot: The current time slot.
  • id: The service ID being accumulated.
  • transfers: Information on the Transfers to the service ID in question.

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§