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 => {
|
.then(updatedTx => {
|
||||||
if (updatedTx.status !== oldTx.status) {
|
if (updatedTx.status !== oldTx.status) {
|
||||||
const isZeroConf = pi.isZeroConf(updatedTx)
|
const isZeroConf = pi.isZeroConf(updatedTx)
|
||||||
if (wasJustAuthorized(oldTx, updatedTx, isZeroConf)) {
|
updatedTx.justAuthorized = wasJustAuthorized(oldTx, updatedTx, isZeroConf)
|
||||||
pi.sell(updatedTx)
|
|
||||||
pi.notifyOperator(updatedTx, { isRedemption: false })
|
|
||||||
.catch((err) => logger.error('Failure sending transaction notification', err))
|
|
||||||
}
|
|
||||||
|
|
||||||
const rec = {
|
const rec = {
|
||||||
to_address: updatedTx.toAddress,
|
to_address: updatedTx.toAddress,
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ function upsert (t, oldTx, tx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return update(t, tx, diff(oldTx, tx))
|
return update(t, tx, diff(oldTx, tx))
|
||||||
.then(newTx => [oldTx, newTx])
|
.then(newTx => [oldTx, newTx, tx.justAuthorized])
|
||||||
}
|
}
|
||||||
|
|
||||||
function insert (t, tx) {
|
function insert (t, tx) {
|
||||||
|
|
|
||||||
|
|
@ -45,15 +45,21 @@ function selfPost (tx, pi) {
|
||||||
function post (tx, pi, fromClient = true) {
|
function post (tx, pi, fromClient = true) {
|
||||||
return db.tx(cashOutAtomic.atomic(tx, pi, fromClient))
|
return db.tx(cashOutAtomic.atomic(tx, pi, fromClient))
|
||||||
.then(txVector => {
|
.then(txVector => {
|
||||||
const [, newTx] = txVector
|
const [, newTx, justAuthorized] = txVector
|
||||||
return postProcess(txVector, pi)
|
return postProcess(txVector, justAuthorized, pi)
|
||||||
.then(changes => cashOutLow.update(db, newTx, changes))
|
.then(changes => cashOutLow.update(db, newTx, changes))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function postProcess (txVector, pi) {
|
function postProcess (txVector, justAuthorized, pi) {
|
||||||
const [oldTx, newTx] = txVector
|
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)) {
|
if ((newTx.dispense && !oldTx.dispense) || (newTx.redeem && !oldTx.redeem)) {
|
||||||
return pi.buildAvailableCassettes(newTx.id)
|
return pi.buildAvailableCassettes(newTx.id)
|
||||||
.then(cassettes => {
|
.then(cassettes => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue