fix: prevent trading on tx rollback
This commit is contained in:
parent
203b1a33e0
commit
47e5e95332
3 changed files with 11 additions and 9 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue