From dda91cacfcd0b7e8b9ed5d571d0a6d742ecf1bc2 Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Wed, 26 Apr 2017 03:11:09 +0300 Subject: [PATCH] fix cash-in-tx db mapping --- lib/cash-in-tx.js | 5 +++++ lib/tx.js | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/cash-in-tx.js b/lib/cash-in-tx.js index 07319764..2a59ca7c 100644 --- a/lib/cash-in-tx.js +++ b/lib/cash-in-tx.js @@ -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) diff --git a/lib/tx.js b/lib/tx.js index 540deee8..85f9453a 100644 --- a/lib/tx.js +++ b/lib/tx.js @@ -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}