This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.env.NODE_ENV = 'development'; | |
require('../env'); | |
import { | |
StateVariablesWithHash, | |
StateVariables, | |
} from '@statechannels/wallet-core'; | |
import { | |
Machine, | |
MachineConfig, | |
send, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { State, StateVariables } from '@statechannels/wallet-core'; | |
import { Channel } from '../models/channel'; | |
type PresentStage = 'PrefundSetup' | 'PostfundSetup' | 'Running' | 'Final'; | |
type Stage = PresentStage | 'Missing'; | |
export type ChannelState = Channel & { peer: string }; | |
// stage is a property with a finite number of values, so it is easy to partition | |
const stage = (state?: State): Stage => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wireMachine = Machine({ | |
initial: 'setup', | |
invoke: {src: 'watcher'}, | |
states: { | |
setup: {invoke: {src: 'createPaymentChannel', onDone: 'uploading'}, exit: 'sendSpacerState'}, | |
uploading: { | |
initial: 'unblocked', | |
on: {DONE: 'refunding'}, | |
states: { | |
unblocked: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const taskHandler = () => new Promise(resolve => setTimeout(() => { | |
console.log("Done task") | |
resolve() | |
}, 1000)) | |
let taskCounter = 0 | |
const taskManager = Machine({ | |
context: {tasks: {}}, | |
on: { | |
RUN_TASK: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const guards = {}; | |
const customActions = {}; | |
const config = { | |
key: 'create-and-fund', | |
initial: 'preFundSetup', | |
on: {'xstate.error': {target: 'failure'}}, | |
states: { | |
preFundSetup: { | |
initial: 'getPreFundSetup', | |
states: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const guards = { | |
channelOpen: {name: 'channelOpen', predicate: () => true, type: 'xstate.guard'}, | |
channelClosing: {name: 'channelClosing', predicate: () => true, type: 'xstate.guard'}, | |
channelClosed: {name: 'channelClosed', predicate: () => true, type: 'xstate.guard'}, | |
isDirectFunding: {name: 'isDirectFunding', predicate: () => true, type: 'xstate.guard'}, | |
isLedgerFunding: {name: 'isLedgerFunding', predicate: () => true, type: 'xstate.guard'}, | |
isVirtualFunding: {name: 'isVirtualFunding', predicate: () => true, type: 'xstate.guard'}, | |
amCreator: {name: 'amCreator', predicate: () => true, type: 'xstate.guard'}, | |
amJoiner: {name: 'amJoiner', predicate: () => true, type: 'xstate.guard'} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const guards = { | |
channelOpen: {name: 'channelOpen', predicate: () => true, type: 'xstate.guard'}, | |
channelClosing: {name: 'channelClosing', predicate: () => true, type: 'xstate.guard'}, | |
channelClosed: {name: 'channelClosed', predicate: () => true, type: 'xstate.guard'}, | |
isDirectFunding: {name: 'isDirectFunding', predicate: () => true, type: 'xstate.guard'}, | |
isLedgerFunding: {name: 'isLedgerFunding', predicate: () => true, type: 'xstate.guard'}, | |
isVirtualFunding: {name: 'isVirtualFunding', predicate: () => true, type: 'xstate.guard'}, | |
amCreator: {name: 'amCreator', predicate: () => true, type: 'xstate.guard'}, | |
amJoiner: {name: 'amJoiner', predicate: () => true, type: 'xstate.guard'} | |
}; |
NewerOlder