refactor(cb): all callback renamed to cb, and local callbacks to _cb
This commit is contained in:
parent
f15f6d9a0a
commit
f7f98d986e
2 changed files with 22 additions and 22 deletions
|
|
@ -175,7 +175,7 @@ exports.logEvent = function event(rawEvent, deviceFingerprint) {
|
||||||
|
|
||||||
|
|
||||||
// Just prompts plugin to send BTC
|
// Just prompts plugin to send BTC
|
||||||
function _sendBitcoins(tx, callback) {
|
function _sendBitcoins(tx, cb) {
|
||||||
logger.debug('executing tx: %j', tx);
|
logger.debug('executing tx: %j', tx);
|
||||||
db.changeTxStatus(tx.txId, 'executing');
|
db.changeTxStatus(tx.txId, 'executing');
|
||||||
walletPlugin.sendBitcoins(
|
walletPlugin.sendBitcoins(
|
||||||
|
|
@ -191,14 +191,14 @@ function _sendBitcoins(tx, callback) {
|
||||||
|
|
||||||
// report insufficient funds error
|
// report insufficient funds error
|
||||||
db.changeTxStatus(tx.txId, status, {error: err.message});
|
db.changeTxStatus(tx.txId, status, {error: err.message});
|
||||||
return callback(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (txHash) db.changeTxStatus(tx.txId, 'completed', {hash: txHash});
|
if (txHash) db.changeTxStatus(tx.txId, 'completed', {hash: txHash});
|
||||||
else db.changeTxStatus(tx.txId, 'failed', {error: 'No txHash received'});
|
else db.changeTxStatus(tx.txId, 'failed', {error: 'No txHash received'});
|
||||||
|
|
||||||
pollBalance();
|
pollBalance();
|
||||||
callback(null, txHash);
|
cb(null, txHash);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -272,8 +272,8 @@ exports.trade = function trade(rawTrade, deviceFingerprint, cb) {
|
||||||
db.recordBill(deviceFingerprint, rawTrade, cb);
|
db.recordBill(deviceFingerprint, rawTrade, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.sendBitcoins = function sendBitcoins(deviceFingerprint, rawTx, callback) {
|
exports.sendBitcoins = function sendBitcoins(deviceFingerprint, rawTx, cb) {
|
||||||
executeTx(deviceFingerprint, rawTx.txId, false, callback);
|
executeTx(deviceFingerprint, rawTx.txId, false, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -344,7 +344,7 @@ function stopTrader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function pollBalance(callback) {
|
function pollBalance(cb) {
|
||||||
logger.debug('collecting balance');
|
logger.debug('collecting balance');
|
||||||
|
|
||||||
var jobs = {
|
var jobs = {
|
||||||
|
|
@ -360,31 +360,31 @@ function pollBalance(callback) {
|
||||||
async.parallel(jobs, function(err, balance) {
|
async.parallel(jobs, function(err, balance) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return callback && callback(err);
|
return cb && cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('Balance update:', balance);
|
logger.debug('Balance update:', balance);
|
||||||
balance.timestamp = Date.now();
|
balance.timestamp = Date.now();
|
||||||
lastBalances = balance;
|
lastBalances = balance;
|
||||||
|
|
||||||
return callback && callback(null, lastBalances);
|
return cb && cb(null, lastBalances);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function pollRate(callback) {
|
function pollRate(cb) {
|
||||||
logger.debug('polling for rates (%s)', tickerPlugin.NAME);
|
logger.debug('polling for rates (%s)', tickerPlugin.NAME);
|
||||||
|
|
||||||
tickerPlugin.ticker(deviceCurrency, function(err, resRates) {
|
tickerPlugin.ticker(deviceCurrency, function(err, resRates) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return callback && callback(err);
|
return cb && cb(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug('got rates: %j', resRates);
|
logger.debug('got rates: %j', resRates);
|
||||||
resRates.timestamp = new Date();
|
resRates.timestamp = new Date();
|
||||||
lastRates = resRates;
|
lastRates = resRates;
|
||||||
|
|
||||||
return callback && callback(null, lastRates);
|
return cb && cb(null, lastRates);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,11 +422,11 @@ function clearSession(deviceFingerprint) {
|
||||||
/*
|
/*
|
||||||
* Trader functions
|
* Trader functions
|
||||||
*/
|
*/
|
||||||
function purchase(trade, callback) {
|
function purchase(trade, cb) {
|
||||||
traderPlugin.purchase(trade.satoshis, null, function(err) {
|
traderPlugin.purchase(trade.satoshis, null, function(err) {
|
||||||
if (err) return callback(err);
|
if (err) return cb(err);
|
||||||
pollBalance();
|
pollBalance();
|
||||||
if (typeof callback === 'function') callback();
|
if (typeof cb === 'function') cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -470,10 +470,10 @@ function executeTrades() {
|
||||||
/*
|
/*
|
||||||
* ID Verifier functions
|
* ID Verifier functions
|
||||||
*/
|
*/
|
||||||
exports.verifyUser = function verifyUser(data, callback) {
|
exports.verifyUser = function verifyUser(data, cb) {
|
||||||
idVerifierPlugin.verifyUser(data, callback);
|
idVerifierPlugin.verifyUser(data, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.verifyTx = function verifyTx(data, callback) {
|
exports.verifyTx = function verifyTx(data, cb) {
|
||||||
idVerifierPlugin.verifyTransaction(data, callback);
|
idVerifierPlugin.verifyTransaction(data, cb);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -117,18 +117,18 @@ exports.getTxs = function getTxs(txId, cb) {
|
||||||
exports.getPendingAmount = function getPendingAmount(txId, cb) {
|
exports.getPendingAmount = function getPendingAmount(txId, cb) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
// NOTE: `async.apply()` would strip context here
|
// NOTE: `async.apply()` would strip context here
|
||||||
txs: function(callback) {
|
txs: function(_cb) {
|
||||||
client.query(
|
client.query(
|
||||||
'SELECT * FROM transactions WHERE id=$1',
|
'SELECT * FROM transactions WHERE id=$1',
|
||||||
[txId],
|
[txId],
|
||||||
callback
|
_cb
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
bills: function(callback) {
|
bills: function(_cb) {
|
||||||
client.query(
|
client.query(
|
||||||
'SELECT * FROM bills WHERE transaction_id=$1 ORDER BY created DESC',
|
'SELECT * FROM bills WHERE transaction_id=$1 ORDER BY created DESC',
|
||||||
[txId],
|
[txId],
|
||||||
callback
|
_cb
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}, function(err, results) {
|
}, function(err, results) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue