post-merge cleanup

This commit is contained in:
Josh Harvey 2016-04-19 19:35:08 +03:00
parent c98c4dc606
commit c644d0f789
3 changed files with 78 additions and 82 deletions

View file

@ -69,13 +69,9 @@ function loadPlugin (name, config) {
// each used plugin MUST be installed
try {
plugin = require('lamassu-' + name)
} catch (_) {
try {
require('plugins/' + name)
} catch (_) {
throw new Error(name + ' module is not installed. ' +
'Try running \'npm install --save lamassu-' + name + '\' first')
}
}
// each plugin MUST implement those
@ -160,27 +156,27 @@ exports.configure = function configure (config) {
cryptoCodes.forEach(function (cryptoCode) {
// TICKER [required] configure (or load)
loadOrConfigPlugin(
loadOrConfigPlugin(
tickerPlugins[cryptoCode],
'ticker',
'ticker',
cryptoCode,
deviceCurrency, // device currency
deviceCurrency, // device currency
function onTickerChange (newTicker) {
tickerPlugins[cryptoCode] = newTicker
pollRate(cryptoCode)
}
}
)
// WALLET [required] configure (or load)
loadOrConfigPlugin(
// WALLET [required] configure (or load)
loadOrConfigPlugin(
walletPlugins[cryptoCode],
'transfer',
'transfer',
cryptoCode,
null,
null,
function onWalletChange (newWallet) {
walletPlugins[cryptoCode] = newWallet
pollBalance(cryptoCode)
}
}
)
tradesQueues[cryptoCode] = tradesQueues[cryptoCode] || []
@ -189,12 +185,12 @@ exports.configure = function configure (config) {
traderPlugins[cryptoCode],
'trader',
cryptoCode,
null,
null,
function onTraderChange (newTrader) {
traderPlugins[cryptoCode] = newTrader
if (newTrader === null) stopTrader(cryptoCode)
else startTrader(cryptoCode)
}
}
)
})
@ -267,7 +263,7 @@ function executeTx (session, tx, authority, cb) {
if (cryptoAtomsToSend === 0) {
logger.debug('No cryptoAtoms to send')
return cb(null, {statusCode: 204, txId: tx.txId, txHash: null})
}
}
var cryptoCode = tx.cryptoCode
_sendCoins(tx.toAddress, cryptoAtomsToSend, cryptoCode, function (_err, txHash) {
@ -358,32 +354,32 @@ exports.trade = function trade (session, rawTrade, cb) {
async.apply(db.addOutgoingPending, session, rawTrade.currency, rawTrade.cryptoCode, rawTrade.toAddress),
async.apply(db.recordBill, session, rawTrade)
], cb)
};
}
exports.stateChange = function stateChange(session, rec, cb) {
var rec = {
exports.stateChange = function stateChange (session, rec, cb) {
var event = {
id: rec.uuid,
fingerprint: session.fingerprint,
eventType: 'stateChange',
note: JSON.stringify({state: rec.state, sessionId: session.id}),
deviceTime: session.deviceTime
}
db.machineEvent(rec, cb)
};
db.machineEvent(event, cb)
}
exports.recordPing = function recordPing(session, rec, cb) {
var rec = {
exports.recordPing = function recordPing (session, rec, cb) {
var event = {
id: uuid.v4(),
fingerprint: session.fingerprint,
eventType: 'ping',
note: JSON.stringify({state: rec.state, sessionId: session.id}),
deviceTime: session.deviceTime
}
db.machineEvent(rec, cb)
};
db.machineEvent(event, cb)
}
exports.sendCoins = function sendCoins(session, rawTx, cb) {
executeTx(session, rawTx, 'machine', cb);
exports.sendCoins = function sendCoins (session, rawTx, cb) {
executeTx(session, rawTx, 'machine', cb)
}
exports.cashOut = function cashOut (session, tx, cb) {
@ -457,9 +453,9 @@ function startTrader (cryptoCode) {
tradeIntervals[cryptoCode] = setInterval(
function () { executeTrades(cryptoCode) },
cachedConfig.exchanges.settings.tradeInterval
cachedConfig.exchanges.settings.tradeInterval
)
}
}
function stopTrader (cryptoCode) {
if (!tradeIntervals[cryptoCode]) return
@ -468,7 +464,7 @@ function stopTrader (cryptoCode) {
clearInterval(tradeIntervals[cryptoCode])
tradeIntervals[cryptoCode] = null
tradesQueues[cryptoCode] = []
}
}
function pollBalance (cryptoCode, cb) {
logger.debug('[%s] collecting balance', cryptoCode)