implement confirmation sms, bug fixes
This commit is contained in:
parent
380f47082e
commit
014033b73e
5 changed files with 134 additions and 18 deletions
|
|
@ -511,12 +511,14 @@ function normalizeTxs (txs) {
|
|||
tx.txHash = tx.tx_hash
|
||||
tx.cryptoCode = tx.crypto_code
|
||||
tx.cryptoAtoms = new BigNumber(tx.satoshis)
|
||||
tx.sessionId = tx.session_id
|
||||
|
||||
tx.to_address = undefined
|
||||
tx.currency_code = undefined
|
||||
tx.tx_hash = undefined
|
||||
tx.crypto_code = undefined
|
||||
tx.satoshis = undefined
|
||||
tx.session_id = undefined
|
||||
|
||||
return tx
|
||||
})
|
||||
|
|
@ -525,12 +527,14 @@ function normalizeTxs (txs) {
|
|||
exports.fetchPhoneTxs = function fetchPhoneTxs (phone, dispenseTimeout) {
|
||||
var sql = 'SELECT * FROM transactions ' +
|
||||
'WHERE phone=$1 AND dispensed=$2 ' +
|
||||
'AND (EXTRACT(EPOCH FROM (now() - created))) * 1000 < $1'
|
||||
'AND (EXTRACT(EPOCH FROM (now() - created))) * 1000 < $1 ' +
|
||||
'AND stage=$3 AND authority=$4 AND incoming=$5'
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
connect(function (cerr, client, done) {
|
||||
if (cerr) return reject(cerr)
|
||||
query(client, sql, [phone, false, dispenseTimeout], function (err, results) {
|
||||
var values = [phone, false, dispenseTimeout, 'initial_request', 'pending', true]
|
||||
query(client, sql, values, function (err, results) {
|
||||
done()
|
||||
if (err) return reject(err)
|
||||
resolve(normalizeTxs(results.rows))
|
||||
|
|
@ -542,12 +546,12 @@ exports.fetchPhoneTxs = function fetchPhoneTxs (phone, dispenseTimeout) {
|
|||
exports.fetchTx = function fetchTx (session) {
|
||||
var sql = 'SELECT * FROM transactions ' +
|
||||
'WHERE device_fingerprint=$1 AND session_id=$2 ' +
|
||||
'AND stage=$3 AND authority=$4'
|
||||
'AND stage=$3 AND authority=$4 and incoming=$5'
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
connect(function (cerr, client, done) {
|
||||
if (cerr) return reject(cerr)
|
||||
var values = [session.fingerprint, session.id, 'initial_request', 'pending']
|
||||
var values = [session.fingerprint, session.id, 'initial_request', 'pending', true]
|
||||
query(client, sql, values, function (err, results) {
|
||||
done()
|
||||
if (err) return reject(err)
|
||||
|
|
@ -578,8 +582,9 @@ exports.addDispenseRequest = function addDispenseRequest (session, tx) {
|
|||
|
||||
function updateDispense (client, session, dispensed, cb) {
|
||||
var sql = 'UPDATE transactions SET dispensed=$1 ' +
|
||||
'WHERE stage=$2 AND authority=$3 AND device_fingerprint=$4 AND session_id=$5'
|
||||
var values = [dispensed, 'initial_request', 'pending', session.fingerprint, session.id]
|
||||
'WHERE stage=$2 AND authority=$3 AND device_fingerprint=$4 AND ' +
|
||||
'session_id=$5 AND incoming=$6'
|
||||
var values = [dispensed, 'initial_request', 'pending', session.fingerprint, session.id, true]
|
||||
query(client, sql, values, function (err) {
|
||||
cb(err)
|
||||
})
|
||||
|
|
@ -686,6 +691,28 @@ exports.fetchOpenTxs = function fetchOpenTxs (statuses, age, cb) {
|
|||
})
|
||||
}
|
||||
|
||||
exports.fetchUnnotifiedTxs = function fetchUnnotifiedTxs (age, waitPeriod, cb) {
|
||||
var sql = 'SELECT * ' +
|
||||
'FROM transactions ' +
|
||||
'WHERE incoming=$1 AND ' +
|
||||
'((EXTRACT(EPOCH FROM (now() - created))) * 1000)<$2 ' +
|
||||
'AND stage=$3 AND authority=$4 AND notified=$5 AND dispensed=$6 ' +
|
||||
'AND phone IS NOT NULL ' +
|
||||
"AND status IN ('instant', 'confirmed') " +
|
||||
'AND (redeem=$7 OR ((EXTRACT(EPOCH FROM (now() - created))) * 1000)>$8)'
|
||||
|
||||
connect(function (cerr, client, done) {
|
||||
if (cerr) return cb(cerr)
|
||||
|
||||
var values = [true, age, 'initial_request', 'pending', false, false, true, waitPeriod]
|
||||
query(client, sql, values, function (err, results) {
|
||||
done()
|
||||
if (err) return cb(err)
|
||||
cb(null, normalizeTxs(results.rows))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
exports.updateTxStatus = function updateTxStatus (tx, status, cb) {
|
||||
var sql = 'UPDATE transactions SET status=$1 WHERE id=$2'
|
||||
|
||||
|
|
@ -699,6 +726,38 @@ exports.updateTxStatus = function updateTxStatus (tx, status, cb) {
|
|||
})
|
||||
}
|
||||
|
||||
exports.updateRedeem = function updateRedeem (session, cb) {
|
||||
var sql = 'UPDATE transactions SET redeem=$1 ' +
|
||||
'WHERE incoming=$1 AND device_fingerprint=$2 AND session_id=$3 ' +
|
||||
'AND stage=$4 AND authority=$5'
|
||||
|
||||
connect(function (cerr, client, done) {
|
||||
if (cerr) return cb(cerr)
|
||||
var values = [true, true, session.fingerprint, session.id, 'initial_request', 'pending']
|
||||
query(client, sql, values, function (err) {
|
||||
done(err)
|
||||
cb(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
exports.updateNotify = function updateNotify (tx) {
|
||||
var sql = 'UPDATE transactions SET notified=$1 ' +
|
||||
'WHERE id=$2'
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
connect(function (cerr, client, done) {
|
||||
if (cerr) return reject(cerr)
|
||||
var values = [true, tx.id]
|
||||
query(client, sql, values, function (err) {
|
||||
done(err)
|
||||
if (err) return reject(err)
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/*
|
||||
exports.init('postgres://lamassu:lamassu@localhost/lamassu')
|
||||
connect(function(err, client, done) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue