Fix up various flow issues.
This commit is contained in:
parent
08bd7da33f
commit
0d8a8547f5
8 changed files with 60 additions and 40 deletions
|
|
@ -7,7 +7,6 @@ const pify = require('pify')
|
|||
const fs = pify(require('fs'))
|
||||
const options = require('./options')
|
||||
const ph = require('./plugin-helper')
|
||||
const db = require('./db')
|
||||
|
||||
const FETCH_INTERVAL = 5000
|
||||
const INSUFFICIENT_FUNDS_CODE = 570
|
||||
|
|
@ -111,27 +110,14 @@ function authorizeZeroConf (settings, tx, machineId) {
|
|||
return zeroConf.authorize(account, tx.toAddress, tx.cryptoAtoms, tx.cryptoCode)
|
||||
}
|
||||
|
||||
function getPublishAge (txId) {
|
||||
const sql = `select extract(epoch from (now() - created)) * 1000 as age
|
||||
from cash_out_actions
|
||||
where tx_id=$1
|
||||
and action=$2`
|
||||
|
||||
return db.oneOrNone(sql, [txId, 'published'])
|
||||
.then(row => row && row.age)
|
||||
}
|
||||
|
||||
function getStatus (settings, tx, machineId) {
|
||||
return getWalletStatus(settings, tx)
|
||||
.then((statusRec) => {
|
||||
if (statusRec.status === 'authorized') {
|
||||
const promises = [
|
||||
getPublishAge(tx.id),
|
||||
authorizeZeroConf(settings, tx, machineId)
|
||||
]
|
||||
return authorizeZeroConf(settings, tx, machineId)
|
||||
.then(isAuthorized => {
|
||||
const publishAge = Date.now() - tx.publishedAt
|
||||
|
||||
return Promise.all(promises)
|
||||
.then(([publishAge, isAuthorized]) => {
|
||||
const unauthorizedStatus = publishAge < ZERO_CONF_EXPIRATION
|
||||
? 'published'
|
||||
: 'rejected'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue