Add expired status to cash-out txs

This commit is contained in:
Rafael Taranto 2019-07-23 10:05:12 +01:00 committed by Josh Harvey
parent 919848aecd
commit 9ca3e88495
7 changed files with 75 additions and 37 deletions

View file

@ -4,6 +4,7 @@ const db = require('../db')
const machineLoader = require('../machine-loader')
const tx = require('../tx')
const cashInTx = require('../cash-in/cash-in-tx')
const { REDEEMABLE_AGE } = require('../cash-out/cash-out-helper')
const NUM_RESULTS = 1000
@ -31,11 +32,12 @@ function batch () {
from cash_in_txs
order by created desc limit $2`
const cashOutSql = `select 'cashOut' as tx_class, cash_out_txs.*
const cashOutSql = `select 'cashOut' as tx_class, cash_out_txs.*,
(extract(epoch from (now() - greatest(created, confirmed_at))) * 1000) >= $2 as expired
from cash_out_txs
order by created desc limit $1`
return Promise.all([db.any(cashInSql, [cashInTx.PENDING_INTERVAL, NUM_RESULTS]), db.any(cashOutSql, [NUM_RESULTS])])
return Promise.all([db.any(cashInSql, [cashInTx.PENDING_INTERVAL, NUM_RESULTS]), db.any(cashOutSql, [NUM_RESULTS, REDEEMABLE_AGE])])
.then(packager)
}
@ -48,13 +50,15 @@ function single (txId) {
from cash_in_txs
where id=$2`
const cashOutSql = `select 'cashOut' as tx_class, cash_out_txs.*
const cashOutSql = `select 'cashOut' as tx_class,
(extract(epoch from (now() - greatest(created, confirmed_at))) * 1000) >= $2 as expired,
cash_out_txs.*
from cash_out_txs
where id=$1`
return Promise.all([
db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]),
db.oneOrNone(cashOutSql, [txId])
db.oneOrNone(cashOutSql, [txId, REDEEMABLE_AGE])
])
.then(packager)
.then(_.head)