fix cash-in-tx db mapping

This commit is contained in:
Josh Harvey 2017-04-26 03:11:09 +03:00
parent 356e7322c8
commit dda91cacfc
2 changed files with 13 additions and 1 deletions

View file

@ -86,6 +86,11 @@ function ensureRatchet (oldField, newField, fieldKey) {
return true
}
const tt = r => Object.prototype.toString.call(r)
console.log('DEBUG100: %j', [tt(oldField), tt(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)

View file

@ -12,7 +12,14 @@ function post (tx, pi) {
}
function massage (tx) {
return _.assign(tx, {cryptoAtoms: BN(tx.cryptoAtoms), fiat: BN(tx.fiat)})
const isDateField = r => r === 'created' || _.endsWith('_time', r)
const transformDate = (v, k) => isDateField(k) ? new Date(v) : v
const mapValuesWithKey = _.mapValues.convert({'cap': false})
const transformDates = r => mapValuesWithKey(transformDate, r)
const mapBN = r => _.assign(r, {cryptoAtoms: BN(r.cryptoAtoms), fiat: BN(r.fiat)})
const mapper = _.flow(transformDates, mapBN)
return mapper(tx)
}
module.exports = {post}