backport some missed changes in cash-in and cash-out
This commit is contained in:
parent
3cb5ddb24d
commit
e22333b7af
3 changed files with 15 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ const pgp = require('pg-promise')()
|
|||
const BN = require('../bn')
|
||||
const T = require('../time')
|
||||
const logger = require('../logger')
|
||||
const E = require('../error')
|
||||
|
||||
const PENDING_INTERVAL_MS = 60 * T.minutes
|
||||
|
||||
|
|
@ -85,7 +86,7 @@ function diff (oldTx, newTx) {
|
|||
logger.warn('Value from lamassu-machine would violate ratchet [%s]', fieldKey)
|
||||
logger.warn('Old tx: %j', oldTx)
|
||||
logger.warn('New tx: %j', newTx)
|
||||
throw new Error('Value from lamassu-machine would violate ratchet')
|
||||
throw new E.RatchetError('Value from lamassu-machine would violate ratchet')
|
||||
}
|
||||
|
||||
updatedTx[fieldKey] = newField
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ module.exports = {logDispense, logActionById, logAction, logError}
|
|||
function logDispense (t, tx) {
|
||||
const baseRec = {error: tx.error, error_code: tx.errorCode}
|
||||
const rec = _.merge(mapDispense(tx), baseRec)
|
||||
const action = tx.dispenseConfirmed ? 'dispense' : 'dispenseError'
|
||||
const action = _.isEmpty(tx.error) ? 'dispense' : 'dispenseError'
|
||||
return logAction(t, action, rec, tx)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ function preProcess (t, oldTx, newTx, pi) {
|
|||
.then(newTxHd => {
|
||||
return pi.newAddress(newTxHd)
|
||||
.then(_.set('toAddress', _, newTxHd))
|
||||
.then(_.unset('isLightning'))
|
||||
})
|
||||
.then(addressedTx => {
|
||||
const rec = {to_address: addressedTx.toAddress}
|
||||
|
|
@ -68,7 +69,10 @@ function preProcess (t, oldTx, newTx, pi) {
|
|||
return cashOutActions.logAction(t, updatedTx.status, rec, updatedTx)
|
||||
}
|
||||
|
||||
if (!oldTx.dispenseConfirmed && updatedTx.dispenseConfirmed) {
|
||||
const hasError = !oldTx.error && newTx.error
|
||||
const hasDispenseOccurred = !dispenseOccurred(oldTx.bills) && dispenseOccurred(newTx.bills)
|
||||
|
||||
if (hasError || hasDispenseOccurred) {
|
||||
return cashOutActions.logDispense(t, updatedTx)
|
||||
.then(updateCassettes(t, updatedTx))
|
||||
}
|
||||
|
|
@ -93,6 +97,8 @@ function nextHd (t, isHd, tx) {
|
|||
}
|
||||
|
||||
function updateCassettes (t, tx) {
|
||||
if (!dispenseOccurred(tx.bills)) return Promise.resolve()
|
||||
|
||||
const sql = `update devices set
|
||||
cassette1 = cassette1 - $1,
|
||||
cassette2 = cassette2 - $2
|
||||
|
|
@ -158,3 +164,8 @@ function ratchetStatus (oldStatus, newStatus) {
|
|||
const idx = Math.max(statusOrder.indexOf(oldStatus), statusOrder.indexOf(newStatus))
|
||||
return statusOrder[idx]
|
||||
}
|
||||
|
||||
function dispenseOccurred (bills) {
|
||||
if (_.isEmpty(bills)) return false
|
||||
return _.every(_.overEvery([_.has('dispensed'), _.has('rejected')]), bills)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue