UNPKG

dagcoin-wallet-workflows

Version:

Dagcoin wallet workflows implementation using Dagcoin Finite State Machine

66 lines (55 loc) 2.51 kB
"use strict"; module.exports = function (properties, stateMachine, state) { var Action = require('dagcoin-fsm/lib/action'); var action = new Action(properties, stateMachine, state); action.execute = function () { return new Promise(function (resolve, reject) { var paymentProps = void 0; var fc = properties.fc; if (stateMachine.getData('update-payment-props')) { paymentProps = { from_address: properties.walletAddresses, main_address: properties.dagcoinOrigin, shared_address: stateMachine.getData('shared-address'), merkleProof: properties.paymentProps.merkleProof, asset: properties.paymentProps.asset, send_all: false, arrSigningDeviceAddresses: properties.paymentProps.arrSigningDeviceAddresses, recipientDeviceAddress: properties.paymentProps.recipientDeviceAddress, externallyFundedPayment: true, asset_outputs: [{ address: properties.dagcoinDestination, amount: properties.constants.DAG_FEE }, { address: properties.paymentProps.to_address, amount: properties.paymentProps.amount }] }; } else { paymentProps = properties.paymentProps; } if (fc.isSingleAddress) { var addresses = properties.addresses; paymentProps.change_address = addresses[fc.credentials.walletId]; } else { var walletDefinedByKeys = properties.walletDefinedByKeys; walletDefinedByKeys.issueNextAddress(fc.credentials.walletId, 0, function (addressInfo) { paymentProps.change_address = addressInfo.address; }); } try { properties.fc.sendMultiPayment(paymentProps, function (error) { if (error) { stateMachine.setData('send-payment-error', error); return resolve(false); } resolve(true); }); } catch (e) { stateMachine.setData('send-payment-error', e); resolve(false); } }); }; return action; };