diff --git a/lib/cash-out/cash-out-atomic.js b/lib/cash-out/cash-out-atomic.js index 69854c19..f3365123 100644 --- a/lib/cash-out/cash-out-atomic.js +++ b/lib/cash-out/cash-out-atomic.js @@ -65,11 +65,7 @@ function preProcess (t, oldTx, newTx, pi) { .then(updatedTx => { if (updatedTx.status !== oldTx.status) { const isZeroConf = pi.isZeroConf(updatedTx) - if (wasJustAuthorized(oldTx, updatedTx, isZeroConf)) { - pi.sell(updatedTx) - pi.notifyOperator(updatedTx, { isRedemption: false }) - .catch((err) => logger.error('Failure sending transaction notification', err)) - } + updatedTx.justAuthorized = wasJustAuthorized(oldTx, updatedTx, isZeroConf) const rec = { to_address: updatedTx.toAddress, diff --git a/lib/cash-out/cash-out-low.js b/lib/cash-out/cash-out-low.js index b47f3c76..2f000c42 100644 --- a/lib/cash-out/cash-out-low.js +++ b/lib/cash-out/cash-out-low.js @@ -18,7 +18,7 @@ function upsert (t, oldTx, tx) { } return update(t, tx, diff(oldTx, tx)) - .then(newTx => [oldTx, newTx]) + .then(newTx => [oldTx, newTx, tx.justAuthorized]) } function insert (t, tx) { diff --git a/lib/cash-out/cash-out-tx.js b/lib/cash-out/cash-out-tx.js index 41ee2261..851f3a92 100644 --- a/lib/cash-out/cash-out-tx.js +++ b/lib/cash-out/cash-out-tx.js @@ -45,15 +45,21 @@ function selfPost (tx, pi) { function post (tx, pi, fromClient = true) { return db.tx(cashOutAtomic.atomic(tx, pi, fromClient)) .then(txVector => { - const [, newTx] = txVector - return postProcess(txVector, pi) + const [, newTx, justAuthorized] = txVector + return postProcess(txVector, justAuthorized, pi) .then(changes => cashOutLow.update(db, newTx, changes)) }) } -function postProcess (txVector, pi) { +function postProcess (txVector, justAuthorized, pi) { const [oldTx, newTx] = txVector + if (justAuthorized) { + pi.sell(newTx) + pi.notifyOperator(newTx, { isRedemption: false }) + .catch((err) => logger.error('Failure sending transaction notification', err)) + } + if ((newTx.dispense && !oldTx.dispense) || (newTx.redeem && !oldTx.redeem)) { return pi.buildAvailableCassettes(newTx.id) .then(cassettes => {