Browse Source

add config.js file

activeAddress
Matias Alejo Garcia 10 years ago
parent
commit
3a45a2c416
  1. 8
      app.js
  2. 24
      config.js
  3. 12
      lib/blockchainexplorer.js
  4. 10
      lib/blockchainmonitor.js
  5. 2
      lib/server.js
  6. 5
      lib/wsapp.js

8
app.js

@ -2,18 +2,16 @@
var ExpressApp = require('./lib/expressapp');
var WsApp = require('./lib/wsapp');
var config = require('./config');
var basePath = process.env.BWS_BASE_PATH || '/bws/api';
var port = process.env.BWS_PORT || 3001;
var app = ExpressApp.start({
basePath: basePath,
});
var app = ExpressApp.start(config);
//app.listen(port);
var server = require('http').Server(app);
var ws = WsApp.start(server);
var ws = WsApp.start(server, config);
server.listen(port);

24
config.js

@ -0,0 +1,24 @@
var config = {
basePath: '/bws/api',
disableLogs: false,
BlockchainMonitor: {
livenet: {
name: 'insight',
url: 'https://insight.bitpay.com:443',
},
testnet: {
name: 'insight',
url: 'https://test-insight.bitpay.com:443',
},
},
WalletService: {
storageOpts: {
dbPath: './db',
/*
dbHost: 'http://db.host.org',
dbPort: '8188',
*/
},
},
};
module.exports = config;

12
lib/blockchainexplorer.js

@ -14,19 +14,13 @@ function BlockChainExplorer(opts) {
$.checkArgument(opts);
var provider = opts.provider || 'insight';
var network = opts.network || 'livenet';
var dfltUrl = network == 'livenet' ? 'https://insight.bitpay.com:443' :
'https://test-insight.bitpay.com:443';
var url = opts.url || dfltUrl;
var url;
switch (provider) {
case 'insight':
switch (network) {
default:
case 'livenet':
url = 'https://insight.bitpay.com:443';
break;
case 'testnet':
url = 'https://test-insight.bitpay.com:443'
break;
}
var explorer = new Explorers.Insight(url, network);
explorer.getTransactions = _.bind(getTransactionsInsight, explorer, url);
explorer.getAddressActivity = _.bind(getAddressActivityInsight, explorer, url);

10
lib/blockchainmonitor.js

@ -17,12 +17,16 @@ var BlockchainExplorer = require('./blockchainexplorer');
var Notification = require('./model/notification');
function BlockchainMonitor() {
function BlockchainMonitor(opts) {
opts = opts || {};
var self = this;
this.subscriptions = {};
this.subscriber = {};
this.subscriber['livenet'] = self._getAddressSubscriber('insight', 'livenet');
this.subscriber['testnet'] = self._getAddressSubscriber('insight', 'testnet');
_.each(['livenet', 'testnet'], function(network) {
opts[network] = opts[network] || {};
self.subscriber[network] = self._getAddressSubscriber(
opts[network].name, network, opts[network].url);
});
};
nodeutil.inherits(BlockchainMonitor, events.EventEmitter);

2
lib/server.js

@ -52,7 +52,7 @@ WalletService.onNotification = function(func) {
*/
WalletService.initialize = function(opts) {
opts = opts || {};
storage = opts.storage ||  new Storage();
storage = opts.storage ||  new Storage(opts.storageOpts);
blockchainExplorer = opts.blockchainExplorer;
initialized = true;
};

5
lib/wsapp.js

@ -32,10 +32,9 @@ WsApp.handleNotification = function(service, notification) {
io.to(notification.walletId).emit('notification', notification);
};
WsApp.start = function(server) {
WsApp.start = function(server, config) {
io = require('socket.io')(server);
bcMonitor = new BlockchainMonitor();
bcMonitor = new BlockchainMonitor(config.BlockchainMonitor);
function handleNotification(notification) {
if (notification.type == 'NewAddress') {

Loading…
Cancel
Save