import { WirePayload } from '../type-aliases' ; import { EngineResponse } from '../engine/engine-response' ; import { Store } from '../engine/store' ; /**
 * For making a single update to a running application channel
 * */ export class SingleAppUpdater { private store : Store ; public static create ( store ) { return new SingleAppUpdater ( store ) ; } private constructor ( store ) { this . store = store ; } /**
     * For pushing a message containing a single update to a running application channel
     */ async update ( wirePayload , response ) { if ( wirePayload . signedStates ?. length !== 1 ) throw new Error ( `The payload sent to pushUpdate must contain exactly 1 signedState.` ) ; if ( wirePayload . objectives ) throw new Error ( `The payload sent to pushUpdate must not contain objectives.` ) ; if ( wirePayload . requests ) throw new Error ( `The payload sent to pushUpdate must not contain requests.` ) ; const wireState = wirePayload . signedStates [ 0 ] ; const channelId = wireState . channelId ; await this . store . transaction ( async ( tx ) => { const channel = await this . store . addSignedState ( channelId , wireState , tx ) ; if ( ! channel . isAppChannel ) throw new Error ( `The update sent to pushUpdate must be for an application channel` ) ; if ( ! channel . isRunning ) throw new Error ( `The update sent to pushUpdate must be for a running channel` ) ; response . queueChannel ( channel ) ; } ) ; } }