import { Bytes32 } from '../type-aliases' ; import { Store } from '../engine/store' ; import { EngineError , Values } from '../errors/engine-error' ; import { EngineResponse } from '../engine/engine-response' ; import { ObjectiveModel } from '../models/objective' ; export class CloseChannelObjective { public static async commence ( channelId , response , store ) { await store . lockApp ( channelId , async ( tx , channel ) => { const walletObjective = await ObjectiveModel . insert ( { type : 'CloseChannel' , participants : [ ] , data : { targetChannelId : channelId , fundingStrategy : channel . fundingStrategy , txSubmitterOrder : [ 1 , 0 ] , } , } , tx , 'approved' ) ; response . queueCreatedObjective ( walletObjective , channel . myIndex , channel . participants ) ; } , ( ) => { throw new CloseChannelError ( CloseChannelError . reasons . channelMissing , { channelId } ) ; } ) ; } } export class CloseChannelError extends EngineError { readonly type = EngineError . errors . CloseChannelError ; static readonly reasons = { channelMissing : 'channel not found' , } as const ; constructor ( reason , public readonly data = undefined ) { super ( reason ) ; } }