Merge pull request #35 from chester1000/refactor-fixes
Post-refactor fixes
This commit is contained in:
commit
291bf21bc3
4 changed files with 34 additions and 23 deletions
14
lib/app.js
14
lib/app.js
|
|
@ -13,18 +13,18 @@ module.exports = function (options) {
|
|||
var app = express();
|
||||
var connectionString;
|
||||
var server;
|
||||
var config;
|
||||
var lamassuConfig;
|
||||
var db;
|
||||
|
||||
connectionString = options.postgres ||
|
||||
'postgres://lamassu:lamassu@localhost/lamassu';
|
||||
|
||||
config = new LamassuConfig(connectionString);
|
||||
lamassuConfig = new LamassuConfig(connectionString);
|
||||
db = new PostgresqlInterface(connectionString);
|
||||
plugins.init(db);
|
||||
|
||||
|
||||
config.load(function (err, config) {
|
||||
lamassuConfig.load(function (err, config) {
|
||||
if (err) {
|
||||
logger.error('Loading config failed');
|
||||
throw err;
|
||||
|
|
@ -34,8 +34,8 @@ module.exports = function (options) {
|
|||
plugins.startPolling();
|
||||
});
|
||||
|
||||
config.on('configUpdate', function () {
|
||||
config.load(function (err, config) {
|
||||
lamassuConfig.on('configUpdate', function () {
|
||||
lamassuConfig.load(function (err, config) {
|
||||
if (err) {
|
||||
return logger.error('Error while reloading config');
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ module.exports = function (options) {
|
|||
server = https.createServer(serverOptions, app);
|
||||
|
||||
authMiddleware = function(req, res, next) {
|
||||
config.isAuthorized(routes.getFingerprint(req), function (err, device) {
|
||||
lamassuConfig.isAuthorized(routes.getFingerprint(req), function (err, device) {
|
||||
if (err) {
|
||||
res.json({err: 'Internal Server Error'});
|
||||
return next(err);
|
||||
|
|
@ -88,7 +88,7 @@ module.exports = function (options) {
|
|||
|
||||
routes.init({
|
||||
app: app,
|
||||
lamassuConfig: config,
|
||||
lamassuConfig: lamassuConfig,
|
||||
plugins: plugins,
|
||||
authMiddleware: authMiddleware,
|
||||
mock: options.mock
|
||||
|
|
|
|||
|
|
@ -144,6 +144,9 @@ exports.configure = function configure(config) {
|
|||
pollBalance();
|
||||
pollRate();
|
||||
};
|
||||
exports.getCachedConfig = function getCachedConfig() {
|
||||
return cachedConfig;
|
||||
};
|
||||
|
||||
|
||||
// This is where we record starting trade balance at the beginning
|
||||
|
|
@ -168,7 +171,7 @@ exports.trade = function trade(rawTrade, deviceFingerprint) {
|
|||
|
||||
exports.fiatBalance = function fiatBalance(deviceFingerprint) {
|
||||
var rawRate = exports.getDeviceRate().rates.ask;
|
||||
var commision = cachedConfig.exchanges.settings.commision;
|
||||
var commission = cachedConfig.exchanges.settings.commission;
|
||||
|
||||
if (!rawRate || !lastBalances) return null;
|
||||
|
||||
|
|
@ -181,7 +184,7 @@ exports.fiatBalance = function fiatBalance(deviceFingerprint) {
|
|||
|
||||
// `balance.transferBalance` is the balance of our transfer account (the one
|
||||
// we use to send Bitcoins to clients) in satoshis.
|
||||
var transferBalance = balance.transferBalance;
|
||||
var transferBalance = lastBalances.transferBalance.BTC;
|
||||
|
||||
// Since `transferBalance` is in satoshis, we need to turn it into
|
||||
// bitcoins and then fiat to learn how much fiat currency we can exchange.
|
||||
|
|
@ -367,6 +370,8 @@ function consolidateTrades() {
|
|||
}, 0)
|
||||
};
|
||||
|
||||
tradesQueue = [];
|
||||
|
||||
logger.debug('consolidated: ', JSON.stringify(consolidatedTrade));
|
||||
return consolidatedTrade;
|
||||
};
|
||||
|
|
@ -383,9 +388,12 @@ function executeTrades() {
|
|||
return;
|
||||
}
|
||||
|
||||
logger.trade.debug('making a trade: %d', trade.satoshis / SATOSHI_FACTOR);
|
||||
logger.debug('making a trade: %d', trade.satoshis / SATOSHI_FACTOR);
|
||||
purchase(trade, function(err) {
|
||||
if (err) logger.error(err);
|
||||
if (err) {
|
||||
tradesQueue.push(trade);
|
||||
logger.error(err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ var logger = require('./logger');
|
|||
var mock = false;
|
||||
|
||||
var plugins;
|
||||
var lamassuConfig;
|
||||
var config;
|
||||
|
||||
module.exports = {
|
||||
|
|
@ -44,19 +45,22 @@ function poll(req, res) {
|
|||
var fiatBalance = plugins.fiatBalance(fingerprint);
|
||||
if (fiatBalance === null) return res.json({err: 'No balance available'});
|
||||
|
||||
var idVerificationLimit = _trader.config.exchanges.settings.
|
||||
compliance.hasOwnProperty('idVerificationLimit') ?
|
||||
_trader.config.exchanges.settings.compliance.idVerificationLimit :
|
||||
null;
|
||||
var config = plugins.getCachedConfig();
|
||||
var complianceSettings = config.exchanges.settings.compliance;
|
||||
|
||||
res.json({
|
||||
var response = {
|
||||
err: null,
|
||||
rate: rate * config.exchanges.settings.commission,
|
||||
fiat: fiatBalance,
|
||||
locale: config.brain.locale,
|
||||
txLimit: parseInt(config.exchanges.settings.compliance.maximum.limit, 10),
|
||||
idVerificationLimit: idVerificationLimit
|
||||
});
|
||||
txLimit: parseInt(complianceSettings.maximum.limit, 10),
|
||||
idVerificationEnabled: complianceSettings.idVerificationEnabled
|
||||
};
|
||||
|
||||
if (response.idVerificationEnabled)
|
||||
response.idVerificationLimit = complianceSettings.idVerificationLimit
|
||||
|
||||
res.json(response);
|
||||
}
|
||||
|
||||
function trade(req, res) {
|
||||
|
|
@ -67,7 +71,7 @@ function trade(req, res) {
|
|||
|
||||
function deviceEvent(req, res) {
|
||||
var fingerprint = req.connection.getPeerCertificate().fingerprint;
|
||||
_trader.event(req.body, fingerprint);
|
||||
plugins.event(req.body, fingerprint);
|
||||
res.json({err: null});
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +116,7 @@ function pair(req, res) {
|
|||
var token = req.body.token;
|
||||
var name = req.body.name;
|
||||
|
||||
config.pair(
|
||||
lamassuConfig.pair(
|
||||
token,
|
||||
getFingerprint(req),
|
||||
name,
|
||||
|
|
@ -127,7 +131,7 @@ function pair(req, res) {
|
|||
}
|
||||
|
||||
function init(localConfig) {
|
||||
config = localConfig.lamassuConfig;
|
||||
lamassuConfig = localConfig.lamassuConfig;
|
||||
plugins = localConfig.plugins;
|
||||
mock = localConfig.mock;
|
||||
|
||||
|
|
|
|||
|
|
@ -131,6 +131,5 @@ describe('Plugins', function() {
|
|||
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue