move to sha-256 fingerprints

This commit is contained in:
Josh Harvey 2017-04-24 14:08:12 +03:00
parent 8674816d27
commit 91e1077daa
4 changed files with 39 additions and 65 deletions

View file

@ -19,7 +19,7 @@ module.exports = {
const mapValuesWithKey = _.mapValues.convert({cap: false})
const UPDATEABLE_FIELDS = ['txHash', 'status', 'dispense', 'notified', 'redeem',
'phone', 'error', 'confirmationTime', 'swept']
'phone', 'error', 'swept']
const STALE_INCOMING_TX_AGE = T.week
const STALE_LIVE_INCOMING_TX_AGE = 10 * T.minutes
@ -203,6 +203,21 @@ function nextHd (isHd, tx) {
.then(row => _.set('hdIndex', row.hd_index, tx))
}
function updateCassettes (tx) {
const sql = `update devices set
cassette1 = cassette1 - $1,
cassette2 = cassette2 - $2
where device_id = $3`
const values = [
tx.bills[0].dispensed + tx.bills[0].rejected,
tx.bills[1].dispensed + tx.bills[1].rejected,
tx.deviceId
]
return db.none(sql, values)
}
function preProcess (oldTx, newTx, pi) {
if (!oldTx) {
return pi.isHd(newTx)
@ -226,14 +241,18 @@ function preProcess (oldTx, newTx, pi) {
if (!oldTx) return updatedTx
if (updatedTx.status !== oldTx.status) {
return logAction(updatedTx.status, {}, updatedTx)
const rec = {
to_address: updatedTx.toAddress,
tx_hash: updatedTx.txHash
}
return logAction(updatedTx.status, rec, updatedTx)
}
console.log('DEBUG120: %j', [oldTx, updatedTx])
if (!oldTx.dispenseConfirmed && updatedTx.dispenseConfirmed) {
console.log('DEBUG121')
return logDispense(updatedTx)
.then(pi.updateCassettes(updatedTx))
.then(updateCassettes(updatedTx))
}
if (!oldTx.phone && newTx.phone) {
@ -249,9 +268,10 @@ function preProcess (oldTx, newTx, pi) {
}
function postProcess (txVector, pi) {
const [, newTx] = txVector
const [oldTx, newTx] = txVector
if (newTx.dispense && !newTx.bills) {
if (newTx.dispense && !oldTx.dispense) {
console.log('DEBUG130')
return pi.buildCassettes()
.then(cassettes => {
pi.sell(newTx)
@ -277,12 +297,7 @@ function postProcess (txVector, pi) {
}
function updateStatus (oldTx, newTx) {
const tx = _.set('status', ratchetStatus(oldTx.status, newTx.status), newTx)
const isConfirmed = _.includes(tx.status, ['instant', 'confirmed'])
if (tx.status === oldTx.status || !isConfirmed) return tx
return _.set('confirmationTime', 'now()^', tx)
return _.set('status', ratchetStatus(oldTx.status, newTx.status), newTx)
}
function ratchetStatus (oldStatus, newStatus) {