UNPKG

dagcoin-wallet-workflows

Version:

Dagcoin wallet workflows implementation using Dagcoin Finite State Machine

70 lines (68 loc) 2.49 kB
"use strict"; var StateMachine = require('dagcoin-fsm/lib/stateMachine'); module.exports = function (fundingExchangeClientService, MIN_BYTE_FEE) { return new StateMachine({ 'properties': { name: 'enough-bytes-fsm', directory: '' + __dirname }, 'states': [{ name: 'init', fetchers: [{ name: 'fundingNodeActive', fundingExchangeClientService: fundingExchangeClientService }] }, { name: 'shared-address-exists', fetchers: [{ name: 'sharedAddressExists', fundingExchangeClientService: fundingExchangeClientService }] }, { name: 'enough-bytes-finding-node', fetchers: [{ name: 'enoughBytesFundingNode', fundingExchangeClientService: fundingExchangeClientService, MIN_BYTE_FEE: MIN_BYTE_FEE }] }, { name: 'enough-bytes', isFinal: true }, { name: 'not-enough-bytes', isFinal: true }], 'firstState': 'init', 'transitions': [{ fromState: 'init', toState: 'shared-address-exists', checkCondition: function checkCondition(data) { return data['fundingNodeActive']; } }, { fromState: 'init', toState: 'not-enough-bytes', checkCondition: function checkCondition(data) { return !data['fundingNodeActive']; } }, { fromState: 'shared-address-exists', toState: 'enough-bytes-finding-node', checkCondition: function checkCondition(data) { return data['sharedAddressExists']; } }, { fromState: 'shared-address-exists', toState: 'not-enough-bytes', checkCondition: function checkCondition(data) { return !data['sharedAddressExists']; } }, { fromState: 'enough-bytes-finding-node', toState: 'enough-bytes', checkCondition: function checkCondition(data) { return data['enoughBytesFundingNode']; } }, { fromState: 'enough-bytes-finding-node', toState: 'not-enough-bytes', checkCondition: function checkCondition(data) { return !data['enoughBytesFundingNode']; } }] }); };