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 return true
} }
if (_.isNil(newField)) return false
if (oldField.isBigNumber && newField.isBigNumber) return BN(oldField).eq(newField) if (oldField.isBigNumber && newField.isBigNumber) return BN(oldField).eq(newField)
if (oldField.toString() === newField.toString()) return true if (oldField.toString() === newField.toString()) return true
@ -231,35 +232,33 @@ function isClearToSend (oldTx, newTx) {
function postProcess (r, pi) { function postProcess (r, pi) {
registerTrades(pi, r.newBills) registerTrades(pi, r.newBills)
if (isClearToSend(r.dbTx, r.tx)) { if (!isClearToSend(r.dbTx, r.tx)) return Promise.resolve({})
return pi.sendCoins(r.tx)
.then(txHash => ({ return pi.sendCoins(r.tx)
txHash, .then(txHash => ({
sendConfirmed: true, 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()^', sendTime: 'now()^',
sendPending: false, error: err.message,
error: null, errorCode: err.name,
errorCode: null sendPending
})) }
.catch(err => { })
// Important: We don't know what kind of error this is .then(sendRec => logAction(sendRec, r.tx))
// 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({})
} }
function preProcess (dbTx, machineTx, pi) { function preProcess (dbTx, machineTx, pi) {