import { UpdateChannelParams, CreateChannelParams, SyncChannelParams, CloseChannelParams, GetStateParams, ChannelId, ChannelResult, } from '@statechannels/client-api-schema'; import {Config} from 'knex'; import {ChainRequest} from '../chain-service'; import {WalletObjective} from '../models/objective'; import {Outgoing} from '../protocols/actions'; import {Bytes32} from '../type-aliases'; import {MetricsConfiguration} from '.'; export type SingleChannelOutput = { outbox: Outgoing[]; channelResult: ChannelResult; newObjective: WalletObjective | undefined; chainRequests: ChainRequest[]; }; export type MultipleChannelOutput = { outbox: Outgoing[]; channelResults: ChannelResult[]; newObjectives: WalletObjective[]; completedObjectives: WalletObjective[]; chainRequests: ChainRequest[]; }; export type Output = SingleChannelOutput | MultipleChannelOutput; export interface EngineInterface { // App channel management createChannels( args: CreateChannelParams, numberOfChannels: number ): Promise; joinChannels(channelIds: ChannelId[]): Promise; updateChannel(args: UpdateChannelParams): Promise; closeChannel(args: CloseChannelParams): Promise; getChannels(): Promise; getState(args: GetStateParams): Promise; syncChannels(chanelIds: Bytes32[]): Promise; syncChannel(args: SyncChannelParams): Promise; challenge(channelId: string): Promise; // Engine <-> Engine communication pushMessage(m: unknown): Promise; pushUpdate(m: unknown): Promise; crank(channelIds: string[]): Promise; } export function isMultipleChannelOutput( output: SingleChannelOutput | MultipleChannelOutput ): output is MultipleChannelOutput { return 'newObjectives' in output; } export function hasNewObjective( response: SingleChannelOutput ): response is SingleChannelOutput & {newObjective: WalletObjective} { return !!response.newObjective; } export type EngineConfig = { skipEvmValidation: boolean; metrics: MetricsConfiguration; dbConfig: Config; chainNetworkID: string; workerThreadAmount: number; };