Browse Source

init fiat rate service from within bws

activeAddress
Ivan Socolsky 9 years ago
parent
commit
10ac3a4d65
  1. 4
      config.js
  2. 3
      lib/expressapp.js
  3. 29
      lib/server.js
  4. 2
      test/integration/fiatrateservice.js

4
config.js

@ -52,6 +52,10 @@ var config = {
subjectPrefix: '', subjectPrefix: '',
pushServerUrl: 'http://localhost:8000/send', pushServerUrl: 'http://localhost:8000/send',
}, },
fiatRateServiceOpts: {
defaultProvider: 'BitPay',
fetchInterval: 15, // in minutes
},
// To use email notifications uncomment this: // To use email notifications uncomment this:
// emailOpts: { // emailOpts: {
// host: 'localhost', // host: 'localhost',

3
lib/expressapp.js

@ -506,9 +506,6 @@ ExpressApp.prototype.start = function(opts, cb) {
source: req.query.source, source: req.query.source,
ts: req.query.ts, ts: req.query.ts,
} }
// if (_.isString(ts) && ts.indexOf(',') !== -1) {
// ts = ts.split(',');
// }
server.getFiatRate(opts, function(err, rates) { server.getFiatRate(opts, function(err, rates) {
if (err) returnError({ if (err) returnError({
code: 500, code: 500,

29
lib/server.js

@ -22,6 +22,7 @@ var Lock = require('./lock');
var Storage = require('./storage'); var Storage = require('./storage');
var MessageBroker = require('./messagebroker'); var MessageBroker = require('./messagebroker');
var BlockchainExplorer = require('./blockchainexplorer'); var BlockchainExplorer = require('./blockchainexplorer');
var FiatRateService = require('./fiatrateservice');
var Model = require('./model'); var Model = require('./model');
var Wallet = Model.Wallet; var Wallet = Model.Wallet;
@ -33,6 +34,7 @@ var storage;
var blockchainExplorer; var blockchainExplorer;
var blockchainExplorerOpts; var blockchainExplorerOpts;
var messageBroker; var messageBroker;
var fiatRateService;
var serviceVersion; var serviceVersion;
var HISTORY_LIMIT = 10; var HISTORY_LIMIT = 10;
@ -50,6 +52,7 @@ function WalletService() {
this.blockchainExplorer = blockchainExplorer; this.blockchainExplorer = blockchainExplorer;
this.blockchainExplorerOpts = blockchainExplorerOpts; this.blockchainExplorerOpts = blockchainExplorerOpts;
this.messageBroker = messageBroker; this.messageBroker = messageBroker;
this.fiatRateService = fiatRateService;
this.notifyTicker = 0; this.notifyTicker = 0;
}; };
@ -101,6 +104,22 @@ WalletService.initialize = function(opts, cb) {
return cb(); return cb();
}; };
function initFiatRateService(cb) {
if (opts.fiatRateService) {
fiatRateService = opts.fiatRateService;
return cb();
} else {
var newFiatRateService = new FiatRateService();
var opts2 = opts.fiatRateServiceOpts || {};
opts2.storage = storage;
newFiatRateService.init(opts2, function(err) {
if (err) return cb(err);
fiatRateService = newFiatRateService;
return cb();
});
}
};
async.series([ async.series([
function(next) { function(next) {
@ -109,6 +128,9 @@ WalletService.initialize = function(opts, cb) {
function(next) { function(next) {
initMessageBroker(next); initMessageBroker(next);
}, },
function(next) {
initFiatRateService(next);
},
], function(err) { ], function(err) {
if (err) { if (err) {
log.error('Could not initialize', err); log.error('Could not initialize', err);
@ -2373,13 +2395,16 @@ WalletService.prototype.startScan = function(opts, cb) {
* @param {String} [opts.provider] - A provider of exchange rates (default 'BitPay'). * @param {String} [opts.provider] - A provider of exchange rates (default 'BitPay').
* @returns {Object} rates - The exchange rate. * @returns {Object} rates - The exchange rate.
*/ */
WalletService.prototype.getRate = function(opts, cb) { WalletService.prototype.getFiatRate = function(opts, cb) {
var self = this; var self = this;
if (!Utils.checkRequired(opts, ['code'])) if (!Utils.checkRequired(opts, ['code']))
return cb(new ClientError('Required argument missing')); return cb(new ClientError('Required argument missing'));
self.fiatRateService.getRate(opts, function(err, rate) {
if (err) return cb(err);
return cb(null, rate);
});
}; };

2
test/integration/fiatrateservice.js

@ -14,7 +14,7 @@ var helpers = require('./helpers');
var FiatRateService = require('../../lib/fiatrateservice'); var FiatRateService = require('../../lib/fiatrateservice');
describe.only('Fiat rate service', function() { describe('Fiat rate service', function() {
var service, request; var service, request;
before(function(done) { before(function(done) {

Loading…
Cancel
Save