Lots of development
This commit is contained in:
parent
5cbec6bd23
commit
3a244f691e
19 changed files with 594 additions and 837 deletions
|
|
@ -2,6 +2,7 @@ const _ = require('lodash/fp')
|
|||
const pgp = require('pg-promise')()
|
||||
const db = require('./db')
|
||||
const BN = require('./bn')
|
||||
const logger = require('./logger')
|
||||
|
||||
const mapValuesWithKey = _.mapValues.convert({cap: false})
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ function post (tx, pi) {
|
|||
return upsert(row, tx)
|
||||
.then(vector => {
|
||||
return insertNewBills(billRows, tx)
|
||||
.then(newBills => _.concat(vector, [billRows]))
|
||||
.then(newBills => _.concat(vector, [newBills]))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
@ -51,7 +52,6 @@ function diff (oldTx, newTx) {
|
|||
let updatedTx = {}
|
||||
|
||||
UPDATEABLE_FIELDS.forEach(fieldKey => {
|
||||
console.log('DEBUG80: %j', [oldTx[fieldKey], newTx[fieldKey]])
|
||||
if (oldTx && _.isEqualWith(nilEqual, oldTx[fieldKey], newTx[fieldKey])) return
|
||||
|
||||
// We never null out an existing field
|
||||
|
|
@ -139,15 +139,6 @@ function insert (tx) {
|
|||
.then(toObj)
|
||||
}
|
||||
|
||||
// const tx = JSON.parse('{"id":"677ec2b7-8e7a-4efc-99fc-1c1aa1b6a3a6","fiat":"1","cryptoAtoms":"73100","bills":[{"id":"afc6103f-b8bf-4ef3-aa28-6bd14f0c2633","fiat":"1","fiatCode":"USD","cryptoAtoms":"73100","cryptoCode":"BTC","deviceTime":1489642154270,"cashInTxsId":"677ec2b7-8e7a-4efc-99fc-1c1aa1b6a3a6"}],"fiatCode":"USD","cryptoCode":"BTC","direction":"cashIn","toAddress":"1MyRmwUVffy5QC5NEbdu9u1Lb9pZkwcNGg","deviceId":"F2:9C:7F:2C:59:F6:3C:EB:C5:A7:AE:4D:C0:59:32:70:0B:9D:3D:FE"}')
|
||||
|
||||
// insert(tx)
|
||||
// .then(console.log)
|
||||
// .catch(err => {
|
||||
// console.log(err.stack)
|
||||
// process.exit(1)
|
||||
// })
|
||||
|
||||
function update (tx, changes) {
|
||||
if (_.isEmpty(changes)) return Promise.resolve(tx)
|
||||
|
||||
|
|
@ -159,13 +150,21 @@ function update (tx, changes) {
|
|||
.then(toObj)
|
||||
}
|
||||
|
||||
function registerTrades (pi, txVector) {
|
||||
console.log('DEBUG400')
|
||||
const newBills = _.last(txVector)
|
||||
console.log('DEBUG401: %j', newBills)
|
||||
_.forEach(bill => pi.buy(bill), newBills)
|
||||
}
|
||||
|
||||
function postProcess (txVector, pi) {
|
||||
const [oldTx, newTx] = txVector
|
||||
|
||||
registerTrades(pi, txVector)
|
||||
|
||||
if (newTx.send && !oldTx.send) {
|
||||
return pi.sendCoins(newTx)
|
||||
.then(txHash => ({txHash}))
|
||||
.catch(error => ({error}))
|
||||
}
|
||||
|
||||
return Promise.resolve({})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue