bug fixes for redeem

This commit is contained in:
Josh Harvey 2016-05-10 15:37:07 +03:00
parent 996ebd395b
commit 694f3e5e96
3 changed files with 30 additions and 22 deletions

View file

@ -806,13 +806,13 @@ exports.registerRedeem = function registerRedeem (session) {
} }
exports.fetchPhoneTx = function fetchPhoneTx (phone) { exports.fetchPhoneTx = function fetchPhoneTx (phone) {
db.fetchPhoneTxs(phone, TRANSACTION_EXPIRATION) return db.fetchPhoneTxs(phone, TRANSACTION_EXPIRATION)
.then(txs => { .then(txs => {
const authorizedTxs = txs.filter(tx => tx.authorized) const confirmedTxs = txs.filter(tx => R.contains(tx.status, ['instant', 'confirmed']))
if (authorizedTxs.length > 0) { if (confirmedTxs.length > 0) {
const maxTx = R.reduce((acc, val) => { const maxTx = R.reduce((acc, val) => {
!acc || val.cryptoAtoms.gt(acc.cryptoAtoms) ? val : acc return !acc || val.cryptoAtoms.gt(acc.cryptoAtoms) ? val : acc
}, null, authorizedTxs) }, null, confirmedTxs)
return {tx: maxTx} return {tx: maxTx}
} }
@ -827,5 +827,5 @@ exports.fetchTx = function fetchTx (session) {
} }
exports.requestDispense = function requestDispense (session, tx) { exports.requestDispense = function requestDispense (session, tx) {
return db.addDispenseRequest(session.fingerprint, tx) return db.addDispenseRequest(session, tx)
} }

View file

@ -530,17 +530,10 @@ exports.fetchPhoneTxs = function fetchPhoneTxs (phone, dispenseTimeout) {
'AND (EXTRACT(EPOCH FROM (COALESCE(confirmation_time, now()) - created))) * 1000 < $3 ' + 'AND (EXTRACT(EPOCH FROM (COALESCE(confirmation_time, now()) - created))) * 1000 < $3 ' +
'AND stage=$4 AND authority=$5 AND incoming=$6' 'AND stage=$4 AND authority=$5 AND incoming=$6'
return new Promise((resolve, reject) => { var values = [phone, false, dispenseTimeout, 'initial_request', 'pending', true]
connect(function (cerr, client, done) {
if (cerr) return reject(cerr) return pquery(sql, values)
var values = [phone, false, dispenseTimeout, 'initial_request', 'pending', true] .then(r => normalizeTxs(r.rows))
query(client, sql, values, function (err, results) {
done()
if (err) return reject(err)
resolve(normalizeTxs(results.rows))
})
})
})
} }
exports.fetchTx = function fetchTx (session) { exports.fetchTx = function fetchTx (session) {
@ -585,8 +578,10 @@ function updateDispense (client, session, dispensed, cb) {
'WHERE stage=$2 AND authority=$3 AND device_fingerprint=$4 AND ' + 'WHERE stage=$2 AND authority=$3 AND device_fingerprint=$4 AND ' +
'session_id=$5 AND incoming=$6' 'session_id=$5 AND incoming=$6'
var values = [dispensed, 'initial_request', 'pending', session.fingerprint, session.id, true] var values = [dispensed, 'initial_request', 'pending', session.fingerprint, session.id, true]
query(client, sql, values, function (err) { query(client, sql, values, function (err, results) {
cb(err) if (err) return cb(err)
if (results.rowCount === 0) return cb(new Error('No pending tx'))
cb()
}) })
} }

View file

@ -1,6 +1,19 @@
- change satoshis to crypto_atoms in db (ask neal about this) - change satoshis to crypto_atoms in db (ask neal about this)
- on upgrade, make sure we're not sending out lots of notifications - on upgrade, make sure we're not sending out lots of notifications
- sending two notifications on confirmation
- reproduce by setting db record to unconfirmed, etc -----------------
- something is being called twice, especially notifyConfirmation
If machine is polling when server starts:
TypeError: Cannot read property 'cashIn' of undefined
at /Users/josh/projects/lamassu-server/lib/routes.js:83:22
at /Users/josh/projects/lamassu-server/lib/plugins.js:271:12
at /Users/josh/projects/lamassu-server/lib/postgresql_interface.js:619:7
at null.callback (/Users/josh/projects/lamassu-server/lib/postgresql_interface.js:129:5)
at Query.handleReadyForQuery (/Users/josh/projects/lamassu-server/node_modules/pg/lib/query.js:89:10)
at null.<anonymous> (/Users/josh/projects/lamassu-server/node_modules/pg/lib/client.js:163:19)
at emitOne (events.js:82:20)
at emit (events.js:169:7)
at Socket.<anonymous> (/Users/josh/projects/lamassu-server/node_modules/pg/lib/connection.js:109:12)
at emitOne (events.js:77:13)