Skip to content

Commit 238077a

Browse files
committed
refactor config
1 parent f511ecb commit 238077a

File tree

7 files changed

+35
-28
lines changed

7 files changed

+35
-28
lines changed

bws.js

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var ExpressApp = require('./lib/expressapp');
44
var WsApp = require('./lib/wsapp');
55
var config = require('./config');
66

7-
var port = process.env.BWS_PORT || 3232;
7+
var port = process.env.BWS_PORT || config.port || 3232;
88

99
var app = ExpressApp.start(config);
1010
//app.listen(port);

config.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
var config = {
22
basePath: '/bws/api',
33
disableLogs: false,
4-
BlockchainMonitor: {
4+
/* port: 3232, */
5+
6+
storageOpts: {
7+
dbPath: './db',
8+
/* To use multilevel, uncomment this:
9+
multiLevel: {
10+
host: 'localhost',
11+
port: 3230,
12+
},
13+
*/
14+
},
15+
lockOpts: {
16+
// To use locker-server, uncomment this:
17+
lockerServer: {
18+
host: 'localhost',
19+
port: 3231,
20+
},
21+
22+
},
23+
blockchainExplorerOpts: {
524
livenet: {
625
name: 'insight',
726
url: 'https://insight.bitpay.com:443',
@@ -11,24 +30,5 @@ var config = {
1130
url: 'https://test-insight.bitpay.com:443',
1231
},
1332
},
14-
WalletService: {
15-
storageOpts: {
16-
dbPath: './db',
17-
/* To use multilevel, uncomment this:
18-
multiLevel: {
19-
host: 'localhost',
20-
port: 3230,
21-
},
22-
*/
23-
},
24-
lockOpts: {
25-
/* To use locker-server, uncomment this:
26-
lockerServer: {
27-
host: 'localhost',
28-
port: 3231,
29-
},
30-
*/
31-
},
32-
},
3333
};
3434
module.exports = config;

lib/expressapp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var ExpressApp = function() {};
2424
ExpressApp.start = function(opts) {
2525
opts = opts || {};
2626

27-
WalletService.initialize(opts.WalletService);
27+
WalletService.initialize(opts);
2828
var app = express();
2929
app.use(function(req, res, next) {
3030
res.setHeader('Access-Control-Allow-Origin', '*');

lib/lock.js

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function Lock(opts) {
1111
if (opts.lockerServer) {
1212
this.lock = new RemoteLock(opts.lockerServer.port, opts.lockerServer.host);
1313

14+
log.info('Using locker server:' + opts.lockerServer.host + ':' + opts.lockerServer.port);
15+
1416
this.lock.on('reset', function() {
1517
log.debug('Locker server reset');
1618
});

lib/server.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var TxProposal = require('./model/txproposal');
2525
var Notification = require('./model/notification');
2626

2727
var initialized = false;
28-
var lock, storage, blockchainExplorer;
28+
var lock, storage, blockchainExplorer, blockchainExplorerOpts;
2929

3030

3131
/**
@@ -39,6 +39,7 @@ function WalletService() {
3939
this.lock = lock;
4040
this.storage = storage;
4141
this.blockchainExplorer = blockchainExplorer;
42+
this.blockchainExplorerOpts = blockchainExplorerOpts;
4243
this.notifyTicker = 0;
4344
};
4445

@@ -57,6 +58,7 @@ WalletService.initialize = function(opts) {
5758
lock = opts.lock || new Lock(opts.lockOpts);
5859
storage = opts.storage || new Storage(opts.storageOpts);
5960
blockchainExplorer = opts.blockchainExplorer;
61+
blockchainExplorerOpts = opts.blockchainExplorerOpts;
6062
initialized = true;
6163
};
6264

@@ -430,10 +432,13 @@ WalletService.prototype.verifyMessageSignature = function(opts, cb) {
430432

431433
WalletService.prototype._getBlockchainExplorer = function(provider, network) {
432434
if (!this.blockchainExplorer) {
433-
this.blockchainExplorer = new BlockchainExplorer({
434-
provider: provider,
435-
network: network,
436-
});
435+
var opts = {};
436+
if (this.blockchainExplorerOpts && this.blockchainExplorerOpts[network]) {
437+
opts = this.blockchainExplorerOpts[network];
438+
}
439+
opts.provider = provider;
440+
opts.network = network;
441+
this.blockchainExplorer = new BlockchainExplorer(opts);
437442
}
438443

439444
return this.blockchainExplorer;

lib/wsapp.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ WsApp.handleNotification = function(service, notification) {
3434

3535
WsApp.start = function(server, config) {
3636
io = require('socket.io')(server);
37-
bcMonitor = new BlockchainMonitor(config.BlockchainMonitor);
37+
bcMonitor = new BlockchainMonitor(config.blockchainExplorerOpts);
3838

3939
function handleNotification(notification) {
4040
if (notification.type == 'NewAddress') {

locker/locker.js

100644100755
File mode changed.

0 commit comments

Comments
 (0)