minor fixups in cash_in_txs

This commit is contained in:
Josh Harvey 2017-12-01 14:17:53 +02:00
parent ed298283c7
commit 29f85a77d7

View file

@ -83,6 +83,7 @@ function ensureRatchet (oldField, newField, fieldKey) {
return true
}
if (_.isNil(newField)) return false
if (oldField.isBigNumber && newField.isBigNumber) return BN(oldField).eq(newField)
if (oldField.toString() === newField.toString()) return true
@ -231,35 +232,33 @@ function isClearToSend (oldTx, newTx) {
function postProcess (r, pi) {
registerTrades(pi, r.newBills)
if (isClearToSend(r.dbTx, r.tx)) {
return pi.sendCoins(r.tx)
.then(txHash => ({
txHash,
sendConfirmed: true,
if (!isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
return pi.sendCoins(r.tx)
.then(txHash => ({
txHash,
sendConfirmed: true,
sendTime: 'now()^',
sendPending: false,
error: null,
errorCode: null
}))
.catch(err => {
// Important: We don't know what kind of error this is
// so not safe to assume that funds weren't sent.
// Therefore, don't set sendPending to false except for
// errors (like InsufficientFundsError) that are guaranteed
// not to send.
const sendPending = err.name !== 'InsufficientFundsError'
return {
sendTime: 'now()^',
sendPending: false,
error: null,
errorCode: null
}))
.catch(err => {
// Important: We don't know what kind of error this is
// so not safe to assume that funds weren't sent.
// Therefore, don't set sendPending to false except for
// errors (like InsufficientFundsError) that are guaranteed
// not to send.
const sendPending = err.name !== 'InsufficientFundsError'
return {
sendTime: 'now()^',
error: err.message,
errorCode: err.name,
sendPending
}
})
.then(sendRec => logAction(sendRec, r.tx))
}
return Promise.resolve({})
error: err.message,
errorCode: err.name,
sendPending
}
})
.then(sendRec => logAction(sendRec, r.tx))
}
function preProcess (dbTx, machineTx, pi) {