add more db fields for fixed fee

This commit is contained in:
Josh Harvey 2017-05-19 01:34:09 +03:00
parent 8ecc8ce510
commit 8cdad0bc15
10 changed files with 74 additions and 65 deletions

View file

@ -5,8 +5,6 @@ const BN = require('./bn')
const plugins = require('./plugins')
const logger = require('./logger')
const mapValuesWithKey = _.mapValues.convert({cap: false})
module.exports = {post, monitorPending}
const PENDING_INTERVAL = '1 day'
@ -84,12 +82,10 @@ function ensureRatchet (oldField, newField, fieldKey) {
return true
}
if (oldField.isBigNumber && newField.isBigNumber) return BN(oldField).eq(newField)
if (oldField.toString() === newField.toString()) return true
logger.error('This field [%s] should never change', fieldKey)
logger.error('oldField: %j', oldField)
logger.error('newField: %j', newField)
throw new Error(`This field [${fieldKey}] should never change`)
return false
}
function diff (oldTx, newTx) {
@ -108,7 +104,7 @@ function diff (oldTx, newTx) {
logger.warn('Value from lamassu-machine would violate ratchet [%s]', fieldKey)
logger.warn('Old tx: %j', oldTx)
logger.warn('New tx: %j', newTx)
return
throw new Error('Value from lamassu-machine would violate ratchet')
}
updatedTx[fieldKey] = newField
@ -125,7 +121,7 @@ function toObj (row) {
keys.forEach(key => {
const objKey = _.camelCase(key)
if (key === 'crypto_atoms' || key === 'fiat') {
if (key === 'crypto_atoms' || key === 'fiat' || key === 'cash_in_fee') {
newObj[objKey] = BN(row[key])
return
}
@ -144,15 +140,11 @@ function toObj (row) {
}
function convertBigNumFields (obj) {
const convert = (value, key) => _.includes(key, ['cryptoAtoms', 'fiat'])
const convert = value => value && value.isBigNumber
? value.toString()
: value
const convertKey = key => _.includes(key, ['cryptoAtoms', 'fiat'])
? key + '#'
: key
return _.mapKeys(convertKey, mapValuesWithKey(convert, obj))
return _.mapValues(convert, obj)
}
function pullNewBills (billRows, machineTx) {