refactor(tx): transaction(s) changed to tx(s)

This commit is contained in:
Damian Mee 2014-09-20 18:52:29 +02:00
parent 55abaa1bb9
commit 5a78376ad5
3 changed files with 16 additions and 14 deletions

View file

@ -203,7 +203,7 @@ function _sendBitcoins(tx, callback) {
); );
} }
function executeTransaction(deviceFingerprint, txId, autoTriggered, cb) { function executeTx(deviceFingerprint, txId, autoTriggered, cb) {
cb = typeof cb === 'function' ? cb : function() {}; cb = typeof cb === 'function' ? cb : function() {};
clearSession(deviceFingerprint); clearSession(deviceFingerprint);
@ -220,7 +220,7 @@ function executeTransaction(deviceFingerprint, txId, autoTriggered, cb) {
return cb(null, {statusCode: 304}); // Not Modified return cb(null, {statusCode: 304}); // Not Modified
} }
db.summonTransaction(deviceFingerprint, tx, function(err, txInfo) { db.summonTx(deviceFingerprint, tx, function(err, txInfo) {
if (err) return cb(err); if (err) return cb(err);
// actual sending // actual sending
@ -255,7 +255,7 @@ exports.trade = function trade(rawTrade, deviceFingerprint, cb) {
sessions[deviceFingerprint] = { sessions[deviceFingerprint] = {
timestamp: Date.now(), timestamp: Date.now(),
reaper: setTimeout(function() { reaper: setTimeout(function() {
executeTransaction(deviceFingerprint, rawTrade.txId, true); executeTx(deviceFingerprint, rawTrade.txId, true);
}, SESSION_TIMEOUT) }, SESSION_TIMEOUT)
}; };
} }
@ -273,7 +273,7 @@ exports.trade = function trade(rawTrade, deviceFingerprint, cb) {
}; };
exports.sendBitcoins = function sendBitcoins(deviceFingerprint, rawTx, callback) { exports.sendBitcoins = function sendBitcoins(deviceFingerprint, rawTx, callback) {
executeTransaction(deviceFingerprint, rawTx.txId, false, callback); executeTx(deviceFingerprint, rawTx.txId, false, callback);
}; };
@ -474,6 +474,6 @@ exports.verifyUser = function verifyUser(data, callback) {
idVerifierPlugin.verifyUser(data, callback); idVerifierPlugin.verifyUser(data, callback);
}; };
exports.verifyTransaction = function verifyTransaction(data, callback) { exports.verifyTx = function verifyTx(data, callback) {
idVerifierPlugin.verifyTransaction(data, callback); idVerifierPlugin.verifyTransaction(data, callback);
}; };

View file

@ -90,7 +90,7 @@ exports.recordDeviceEvent = function recordDeviceEvent(deviceFingerprint, event,
cb); cb);
}; };
function _getTransactions(txId, onlyPending, cb) { function _getTxs(txId, onlyPending, cb) {
var query = 'SELECT * FROM transactions WHERE id=$1'; var query = 'SELECT * FROM transactions WHERE id=$1';
var values = [txId]; var values = [txId];
@ -110,8 +110,8 @@ function _getTransactions(txId, onlyPending, cb) {
} }
// returns complete [txs] // returns complete [txs]
exports.getTransactions = function getTransactions(txId, cb) { exports.getTxs = function getTxs(txId, cb) {
_getTransactions(txId, false, cb); _getTxs(txId, false, cb);
}; };
exports.getPendingAmount = function getPendingAmount(txId, cb) { exports.getPendingAmount = function getPendingAmount(txId, cb) {
@ -162,14 +162,16 @@ exports.getPendingAmount = function getPendingAmount(txId, cb) {
} }
// Nothing to send == nothing to do // Nothing to send == nothing to do
if (newTx.satoshis <= 0) if (newTx.satoshis <= 0) {
logger.error('Negative tx amount (%d) for txId: %s', newTx.satoshis, txId);
return cb(); return cb();
}
cb(null, newTx); cb(null, newTx);
}); });
}; };
exports.summonTransaction = function summonTransaction(deviceFingerprint, tx, cb) { exports.summonTx = function summonTx(deviceFingerprint, tx, cb) {
var fields = [ var fields = [
'id', 'id',
'status', 'status',
@ -202,7 +204,7 @@ exports.summonTransaction = function summonTransaction(deviceFingerprint, tx, cb
function(err) { function(err) {
if (err) { if (err) {
if (PG_ERRORS[err.code] === 'uniqueViolation') if (PG_ERRORS[err.code] === 'uniqueViolation')
return _getTransactions(tx.txId, false, cb); return _getTxs(tx.txId, false, cb);
return cb(err); return cb(err);
} }

View file

@ -87,10 +87,10 @@ function verifyUser(req, res) {
}); });
} }
function verifyTransaction(req, res) { function verifyTx(req, res) {
if (mock) return res.json({success: true}); if (mock) return res.json({success: true});
plugins.verifyTransaction(req.body, function (err, idResult) { plugins.verifyTx(req.body, function (err, idResult) {
if (err) { if (err) {
logger.error(err); logger.error(err);
return res.json({err: 'Verification failed'}); return res.json({err: 'Verification failed'});
@ -140,7 +140,7 @@ function init(localConfig) {
app.post('/trade', authMiddleware, trade); app.post('/trade', authMiddleware, trade);
app.post('/event', authMiddleware, deviceEvent); app.post('/event', authMiddleware, deviceEvent);
app.post('/verify_user', authMiddleware, verifyUser); app.post('/verify_user', authMiddleware, verifyUser);
app.post('/verify_transaction', authMiddleware, verifyTransaction); app.post('/verify_transaction', authMiddleware, verifyTx);
app.post('/pair', pair); app.post('/pair', pair);
return app; return app;