UNPKG

dagcoin-wallet-workflows

Version:

Dagcoin wallet workflows implementation using Dagcoin Finite State Machine

89 lines (87 loc) 3.09 kB
"use strict"; var StateMachine = require('dagcoin-fsm/lib/stateMachine'); module.exports = function (props) { return new StateMachine({ 'properties': { name: 'payment-fsm', directory: '' + __dirname }, 'states': [{ name: 'new', fetchers: [{ name: 'enoughBytesClient', baseBalance: { stable: props.baseBalance.stable }, constants: { MIN_BYTE_FEE: props.constants.MIN_BYTE_FEE } }] }, { name: 'check-bytes-funding-node', fetchers: [{ name: 'enoughBytes', fundingExchangeClientService: props.fundingExchangeClientService, constants: { MIN_BYTE_FEE: props.constants.MIN_BYTE_FEE } }] }, { name: 'payment-attempt', fetchers: [{ name: 'paymentSent', fc: props.fc }], actionsIn: [{ name: 'sendPayment', paymentProps: props.paymentProps, walletAddresses: props.fundingExchangeClientService.walletAddresses, dagcoinOrigin: props.fundingExchangeClientService.dagcoinOrigin, dagcoinDestination: props.fundingExchangeClientService.dagcoinDestination, fc: props.fc, walletDefinedByKeys: props.walletDefinedByKeys, constants: { DAG_FEE: props.constants.DAG_FEE } }] }, { name: 'payment-done', isFinal: true }, { name: 'payment-failed', isFinal: true }], 'firstState': 'new', 'transitions': [{ fromState: 'new', toState: 'payment-attempt', checkCondition: function checkCondition(data) { return data['enoughBytesClient']; } }, { fromState: 'new', toState: 'check-bytes-funding-node', checkCondition: function checkCondition(data) { return !data['enoughDagcoins']; } }, { fromState: 'check-bytes-funding-node', toState: 'payment-attempt', checkCondition: function checkCondition(data) { return data['enoughBytes']; } }, { fromState: 'check-bytes-funding-node', toState: 'payment-failed', checkCondition: function checkCondition(data) { return !data['enoughBytes']; } }, { fromState: 'payment-attempt', toState: 'payment-failed', checkCondition: function checkCondition(data) { return !data['paymentSent']; } }, { fromState: 'payment-attempt', toState: 'payment-done', checkCondition: function checkCondition(data) { return data['paymentSent']; } }] }); };