<commit_before>'use strict';

var logger = require('./logger');

var mock = false;

var plugins;
var lamassuConfig;

module.exports = {
  init: init,
  getFingerprint: getFingerprint
};

// Make sure these are higher than polling interval
// or there will be a lot of errors
var STALE_TICKER  = 180000;
var STALE_BALANCE = 180000;

function poll(req, res) {
  var rateRec = plugins.getDeviceRate();
  var balanceRec = plugins.getBalance();

  logger.debug('poll request from: %s', getFingerprint(req));

  // `rateRec` and `balanceRec` are both objects, so there's no danger
  // of misinterpreting rate or balance === 0 as 'Server initializing'.
  if (!rateRec || !balanceRec) {
    return res.json({err: 'Server initializing'});
  }

  var now = Date.now();
  if (now - rateRec.timestamp > STALE_TICKER) {
    return res.json({err: 'Stale ticker'});
  }

  if (now - balanceRec.timestamp > STALE_BALANCE) {
    return res.json({err: 'Stale balance'});
  }

  var rate = rateRec.rates.ask;
  var fiatRate = rateRec.rates.bid || rate;

  if (rate === null) return res.json({err: 'No rate available'});
  if (!fiatRate)
    logger.warn('No bid rate, using ask rate');

  var fiatBalance = plugins.fiatBalance();
  if (fiatBalance === null) {
    logger.warn('No balance available.');
    return res.json({err: 'No balance available'});
  }

  var config = plugins.getConfig();
  var settings = config.exchanges.settings;
  var complianceSettings = settings.compliance;
  var fiatCommission = settings.fiatCommission || settings.commission;

  plugins.pollQueries(session(req), function(err, results) {
    if (err) return logger.error(err);
    var cartridges = results.cartridges;
    var response = {
      err: null,
      rate: rate * settings.commission,
      fiatRate: fiatRate / fiatCommission,
      fiat: fiatBalance,
      locale: config.brain.locale,
      txLimit: parseInt(complianceSettings.maximum.limit, 10),
      idVerificationEnabled: complianceSettings.idVerificationEnabled,
      cartridges: cartridges,
      twoWayMode: cartridges ? true : false,
      zeroConfLimit: settings.zeroConfLimit,<commit_msg>support remit on and off<commit_after>'use strict';

var logger = require('./logger');

var mock = false;

var plugins;
var lamassuConfig;

module.exports = {
  init: init,
  getFingerprint: getFingerprint
};

// Make sure these are higher than polling interval
// or there will be a lot of errors
var STALE_TICKER  = 180000;
var STALE_BALANCE = 180000;

function poll(req, res) {
  var rateRec = plugins.getDeviceRate();
  var balanceRec = plugins.getBalance();

  logger.debug('poll request from: %s', getFingerprint(req));

  // `rateRec` and `balanceRec` are both objects, so there's no danger
  // of misinterpreting rate or balance === 0 as 'Server initializing'.
  if (!rateRec || !balanceRec) {
    return res.json({err: 'Server initializing'});
  }

  var now = Date.now();
  if (now - rateRec.timestamp > STALE_TICKER) {
    return res.json({err: 'Stale ticker'});
  }

  if (now - balanceRec.timestamp > STALE_BALANCE) {
    return res.json({err: 'Stale balance'});
  }

  var rate = rateRec.rates.ask;
  var fiatRate = rateRec.rates.bid || rate;

  if (rate === null) return res.json({err: 'No rate available'});
  if (!fiatRate)
    logger.warn('No bid rate, using ask rate');

  var fiatBalance = plugins.fiatBalance();
  if (fiatBalance === null) {
    logger.warn('No balance available.');
    return res.json({err: 'No balance available'});
  }

  var config = plugins.getConfig();
  var settings = config.exchanges.settings;
  var complianceSettings = settings.compliance;
  var fiatCommission = settings.fiatCommission || settings.commission;

  plugins.pollQueries(session(req), function(err, results) {
    if (err) return logger.error(err);
    var cartridges = results.cartridges;
    var response = {
      err: null,
      rate: rate * settings.commission,
      fiatRate: fiatRate / fiatCommission,
      fiat: fiatBalance,
      locale: config.brain.locale,
      txLimit: parseInt(complianceSettings.maximum.limit, 10),
      idVerificationEnabled: complianceSettings.idVerificationEnabled,
      cartridges: cartridges,
      twoWayMode: cartridges ? true : false,
      remitMode: settings.remitMode,
      zeroConfLimit: settings.zeroConfLimit,
{'fraction_non_alphanumeric': 0.12296606229660623, 'fraction_numerical': 0.00697350069735007, 'mean_word_length': 3.749448123620309, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6108500', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1329, 'n_words': 375}