Commit 238077a8 authored by Matias Alejo Garcia's avatar Matias Alejo Garcia

refactor config

parent f511ecba
......@@ -4,7 +4,7 @@ var ExpressApp = require('./lib/expressapp');
var WsApp = require('./lib/wsapp');
var config = require('./config');
var port = process.env.BWS_PORT || 3232;
var port = process.env.BWS_PORT || config.port || 3232;
var app = ExpressApp.start(config);
//app.listen(port);
......
var config = {
basePath: '/bws/api',
disableLogs: false,
BlockchainMonitor: {
/* port: 3232, */
storageOpts: {
dbPath: './db',
/* To use multilevel, uncomment this:
multiLevel: {
host: 'localhost',
port: 3230,
},
*/
},
lockOpts: {
// To use locker-server, uncomment this:
lockerServer: {
host: 'localhost',
port: 3231,
},
},
blockchainExplorerOpts: {
livenet: {
name: 'insight',
url: 'https://insight.bitpay.com:443',
......@@ -11,24 +30,5 @@ var config = {
url: 'https://test-insight.bitpay.com:443',
},
},
WalletService: {
storageOpts: {
dbPath: './db',
/* To use multilevel, uncomment this:
multiLevel: {
host: 'localhost',
port: 3230,
},
*/
},
lockOpts: {
/* To use locker-server, uncomment this:
lockerServer: {
host: 'localhost',
port: 3231,
},
*/
},
},
};
module.exports = config;
......@@ -24,7 +24,7 @@ var ExpressApp = function() {};
ExpressApp.start = function(opts) {
opts = opts || {};
WalletService.initialize(opts.WalletService);
WalletService.initialize(opts);
var app = express();
app.use(function(req, res, next) {
res.setHeader('Access-Control-Allow-Origin', '*');
......
......@@ -11,6 +11,8 @@ function Lock(opts) {
if (opts.lockerServer) {
this.lock = new RemoteLock(opts.lockerServer.port, opts.lockerServer.host);
log.info('Using locker server:' + opts.lockerServer.host + ':' + opts.lockerServer.port);
this.lock.on('reset', function() {
log.debug('Locker server reset');
});
......
......@@ -25,7 +25,7 @@ var TxProposal = require('./model/txproposal');
var Notification = require('./model/notification');
var initialized = false;
var lock, storage, blockchainExplorer;
var lock, storage, blockchainExplorer, blockchainExplorerOpts;
/**
......@@ -39,6 +39,7 @@ function WalletService() {
this.lock = lock;
this.storage = storage;
this.blockchainExplorer = blockchainExplorer;
this.blockchainExplorerOpts = blockchainExplorerOpts;
this.notifyTicker = 0;
};
......@@ -57,6 +58,7 @@ WalletService.initialize = function(opts) {
lock = opts.lock || new Lock(opts.lockOpts);
storage = opts.storage || new Storage(opts.storageOpts);
blockchainExplorer = opts.blockchainExplorer;
blockchainExplorerOpts = opts.blockchainExplorerOpts;
initialized = true;
};
......@@ -430,10 +432,13 @@ WalletService.prototype.verifyMessageSignature = function(opts, cb) {
WalletService.prototype._getBlockchainExplorer = function(provider, network) {
if (!this.blockchainExplorer) {
this.blockchainExplorer = new BlockchainExplorer({
provider: provider,
network: network,
});
var opts = {};
if (this.blockchainExplorerOpts && this.blockchainExplorerOpts[network]) {
opts = this.blockchainExplorerOpts[network];
}
opts.provider = provider;
opts.network = network;
this.blockchainExplorer = new BlockchainExplorer(opts);
}
return this.blockchainExplorer;
......
......@@ -34,7 +34,7 @@ WsApp.handleNotification = function(service, notification) {
WsApp.start = function(server, config) {
io = require('socket.io')(server);
bcMonitor = new BlockchainMonitor(config.BlockchainMonitor);
bcMonitor = new BlockchainMonitor(config.blockchainExplorerOpts);
function handleNotification(notification) {
if (notification.type == 'NewAddress') {
......
File mode changed from 100644 to 100755
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment