fix partial_send reporting for timeout
This commit is contained in:
parent
ad65869229
commit
cb11552c11
2 changed files with 35 additions and 31 deletions
|
|
@ -95,8 +95,8 @@ exports.recordBill = function recordBill(session, rec, cb) {
|
|||
};
|
||||
|
||||
exports.recordDeviceEvent = function recordDeviceEvent(session, event) {
|
||||
connect(function(err, client, done) {
|
||||
if (err) return;
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return;
|
||||
var sql = 'INSERT INTO device_events (device_fingerprint, event_type, ' +
|
||||
'note, device_time) VALUES ($1, $2, $3, $4)';
|
||||
var values = [session.fingerprint, event.eventType, event.note,
|
||||
|
|
@ -185,7 +185,8 @@ function computeSendAmount(tx, totals) {
|
|||
}
|
||||
|
||||
exports.removeOldPending = function removeOldPending(timeoutMS) {
|
||||
connect(function(err, client, done) {
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return;
|
||||
var sql = 'DELETE FROM pending_transactions ' +
|
||||
'WHERE incoming AND extract(EPOCH FROM now() - created) > $1';
|
||||
var timeoutS = timeoutMS / 1000;
|
||||
|
|
@ -198,7 +199,8 @@ exports.removeOldPending = function removeOldPending(timeoutMS) {
|
|||
};
|
||||
|
||||
exports.pendingTxs = function pendingTxs(timeoutMS, cb) {
|
||||
connect(function(err, client, done) {
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return cb(cerr);
|
||||
var sql = 'SELECT * ' +
|
||||
'FROM pending_transactions ' +
|
||||
'WHERE (incoming OR extract(EPOCH FROM now() - created) > $1) ' +
|
||||
|
|
@ -228,7 +230,7 @@ function insertOutgoingTx(client, session, tx, totals, cb) {
|
|||
function(err) {
|
||||
|
||||
if (err) return cb(err);
|
||||
cb(null, satoshis);
|
||||
cb(null, {satoshis: satoshis, fiat: fiat});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -317,8 +319,8 @@ function buildOutgoingTx(client, session, tx, cb) {
|
|||
|
||||
// Calling function should only send bitcoins if result.satoshisToSend > 0
|
||||
exports.addOutgoingTx = function addOutgoingTx(session, tx, cb) {
|
||||
connect(function(err, client, done) {
|
||||
if (err) return cb(err);
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return cb(cerr);
|
||||
async.series([
|
||||
async.apply(silentQuery, client, 'BEGIN'),
|
||||
async.apply(insertOutgoingCompleteTx, client, session, tx),
|
||||
|
|
@ -331,25 +333,25 @@ exports.addOutgoingTx = function addOutgoingTx(session, tx, cb) {
|
|||
}
|
||||
silentQuery(client, 'COMMIT', function() {
|
||||
done();
|
||||
var satoshisToSend = results[3];
|
||||
cb(null, satoshisToSend);
|
||||
var toSend = results[3];
|
||||
cb(null, toSend);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.sentCoins = function sentCoins(session, tx, authority, satoshis, fee,
|
||||
exports.sentCoins = function sentCoins(session, tx, authority, toSend, fee,
|
||||
error, txHash) {
|
||||
connect(function(err, client, done) {
|
||||
if (err) return logger.error(err);
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return logger.error(cerr);
|
||||
|
||||
var newTx = _.clone(tx);
|
||||
newTx.txHash = txHash;
|
||||
newTx.error = error;
|
||||
insertOutgoing(client, session, newTx, satoshis, newTx.fiat, 'partial_send',
|
||||
authority, function(_err) {
|
||||
insertOutgoing(client, session, newTx, toSend.satoshis, toSend.fiat,
|
||||
'partial_send', authority, function(err) {
|
||||
done();
|
||||
if (err) logger.error(_err);
|
||||
if (err) logger.error(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
@ -362,8 +364,8 @@ function maybeRemovePending(client, session, authority, cb) {
|
|||
exports.addIncomingTx = function addIncomingTx(session, tx, authority,
|
||||
satoshisReceived, cb) {
|
||||
|
||||
connect(function(err, client, done) {
|
||||
if (err) return cb(err);
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return cb(cerr);
|
||||
async.waterfall([
|
||||
async.apply(silentQuery, client, 'BEGIN', null),
|
||||
async.apply(maybeRemovePending, client, session, authority),
|
||||
|
|
@ -396,8 +398,8 @@ exports.addOutgoingPending = function addOutgoingPending(session, currencyCode,
|
|||
};
|
||||
|
||||
exports.addInitialIncoming = function addInitialIncoming(session, tx, cb) {
|
||||
connect(function(err, client, done) {
|
||||
if (err) return cb(err);
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return cb(cerr);
|
||||
async.waterfall([
|
||||
async.apply(silentQuery, client, 'BEGIN', null),
|
||||
async.apply(addPendingTx, client, session, true, tx.currencyCode,
|
||||
|
|
@ -436,15 +438,15 @@ function initialRequest(client, session, cb) {
|
|||
}
|
||||
|
||||
exports.dispenseStatus = function dispenseStatus(session, cb) {
|
||||
connect(function(err, client, done) {
|
||||
if (err) return cb(err);
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return cb(cerr);
|
||||
|
||||
async.parallel([
|
||||
async.apply(initialRequest, client, session),
|
||||
async.apply(lastTxStatus, client, session)
|
||||
], function(_err, results) {
|
||||
], function(err, results) {
|
||||
done();
|
||||
if (_err) return cb(_err);
|
||||
if (err) return cb(err);
|
||||
|
||||
var pending = (results[0].rows.length === 1) &&
|
||||
(results[1].rows.length === 1) &&
|
||||
|
|
@ -500,17 +502,17 @@ function insertDispense(client, session, tx, transactionId, counts, cb) {
|
|||
}
|
||||
|
||||
exports.addDispense = function addDispense(session, tx) {
|
||||
connect(function(err, client, done) {
|
||||
if (err) return logger.error(err);
|
||||
connect(function(cerr, client, done) {
|
||||
if (cerr) return logger.error(cerr);
|
||||
|
||||
async.waterfall([
|
||||
async.apply(insertIncoming, client, session, tx, 0, tx.fiat,
|
||||
'dispense', 'authorized'),
|
||||
async.apply(lastDispenseCount, client, session),
|
||||
async.apply(insertDispense, client, session, tx)
|
||||
], function(_err) {
|
||||
], function(err) {
|
||||
done();
|
||||
if (_err) logger.error(_err);
|
||||
if (err) logger.error(err);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue