|
@ -10,15 +10,11 @@ var BlockchainExplorer = require('./blockchainexplorer'); |
|
|
var Storage = require('./storage'); |
|
|
var Storage = require('./storage'); |
|
|
var MessageBroker = require('./messagebroker'); |
|
|
var MessageBroker = require('./messagebroker'); |
|
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
|
var Notification = require('./model/notification'); |
|
|
var Notification = require('./model/notification'); |
|
|
|
|
|
|
|
|
function BlockchainMonitor() {}; |
|
|
function BlockchainMonitor() {}; |
|
|
|
|
|
|
|
|
BlockchainMonitor.prototype.start = function(opts, cb) { |
|
|
BlockchainMonitor.prototype.start = function(opts, cb) { |
|
|
======= |
|
|
|
|
|
function BlockchainMonitor(opts) { |
|
|
|
|
|
>>>>>>> refactor notification dispatching |
|
|
|
|
|
opts = opts || {}; |
|
|
opts = opts || {}; |
|
|
$.checkArgument(opts.blockchainExplorerOpts); |
|
|
$.checkArgument(opts.blockchainExplorerOpts); |
|
|
$.checkArgument(opts.storageOpts); |
|
|
$.checkArgument(opts.storageOpts); |
|
@ -69,14 +65,8 @@ BlockchainMonitor.prototype._initExplorer = function(provider, network, url) { |
|
|
}); |
|
|
}); |
|
|
socket.on('tx', _.bind(self._handleIncommingTx, self)); |
|
|
socket.on('tx', _.bind(self._handleIncommingTx, self)); |
|
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
|
return explorer; |
|
|
return explorer; |
|
|
}; |
|
|
}; |
|
|
======= |
|
|
|
|
|
BlockchainMonitor.prototype.subscribeAddresses = function(walletService, addresses) { |
|
|
|
|
|
$.checkArgument(walletService); |
|
|
|
|
|
$.checkArgument(walletService.walletId); |
|
|
|
|
|
>>>>>>> refactor notification dispatching |
|
|
|
|
|
|
|
|
|
|
|
BlockchainMonitor.prototype._handleIncommingTx = function(data) { |
|
|
BlockchainMonitor.prototype._handleIncommingTx = function(data) { |
|
|
var self = this; |
|
|
var self = this; |
|
@ -84,27 +74,15 @@ BlockchainMonitor.prototype._handleIncommingTx = function(data) { |
|
|
|
|
|
|
|
|
if (!data || !data.vout) return; |
|
|
if (!data || !data.vout) return; |
|
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
|
var outs = _.compact(_.map(data.vout, function(v) { |
|
|
var outs = _.compact(_.map(data.vout, function(v) { |
|
|
var addr = _.keys(v)[0]; |
|
|
var addr = _.keys(v)[0]; |
|
|
var startingChar = addr.charAt(0); |
|
|
var startingChar = addr.charAt(0); |
|
|
if (startingChar != '2' && startingChar != '3') return; |
|
|
if (startingChar != '2' && startingChar != '3') return; |
|
|
======= |
|
|
|
|
|
function handlerFor(address, txid) { |
|
|
|
|
|
var data = { |
|
|
|
|
|
walletId: this.walletId, |
|
|
|
|
|
address: address, |
|
|
|
|
|
txid: txid, |
|
|
|
|
|
}; |
|
|
|
|
|
self.emit('NewIncomingTx', data, this); |
|
|
|
|
|
}; |
|
|
|
|
|
>>>>>>> refactor notification dispatching |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
address: addr, |
|
|
address: addr, |
|
|
amount: +v[addr] |
|
|
amount: +v[addr] |
|
|
}; |
|
|
}; |
|
|
<<<<<<< HEAD |
|
|
|
|
|
})); |
|
|
})); |
|
|
if (_.isEmpty(outs)) return; |
|
|
if (_.isEmpty(outs)) return; |
|
|
|
|
|
|
|
@ -122,23 +100,12 @@ BlockchainMonitor.prototype._handleIncommingTx = function(data) { |
|
|
}); |
|
|
}); |
|
|
}, function(err) { |
|
|
}, function(err) { |
|
|
return; |
|
|
return; |
|
|
======= |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var addresses = [].concat(addresses); |
|
|
|
|
|
var network = Bitcore.Address.fromString(addresses[0]).network.name; |
|
|
|
|
|
var subscriber = self.subscriber[network]; |
|
|
|
|
|
_.each(addresses, function(address) { |
|
|
|
|
|
self.subscriptions[walletId].addresses.push(address); |
|
|
|
|
|
subscriber.subscribe(address, _.bind(handlerFor, walletService, address)); |
|
|
|
|
|
>>>>>>> refactor notification dispatching |
|
|
|
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
BlockchainMonitor.prototype._createNotification = function(walletId, txid, address, amount, cb) { |
|
|
BlockchainMonitor.prototype._createNotification = function(walletId, txid, address, amount, cb) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
|
|
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
|
var n = Notification.create({ |
|
|
var n = Notification.create({ |
|
|
type: 'NewIncomingTx', |
|
|
type: 'NewIncomingTx', |
|
|
data: { |
|
|
data: { |
|
@ -150,17 +117,6 @@ BlockchainMonitor.prototype._createNotification = function(walletId, txid, addre |
|
|
}); |
|
|
}); |
|
|
self.storage.storeNotification(walletId, n, function() { |
|
|
self.storage.storeNotification(walletId, n, function() { |
|
|
self.messageBroker.send(n) |
|
|
self.messageBroker.send(n) |
|
|
======= |
|
|
|
|
|
var walletId = walletService.walletId; |
|
|
|
|
|
if (self.subscriptions[walletId]) return; |
|
|
|
|
|
|
|
|
|
|
|
walletService.getMainAddresses({}, function(err, addresses) { |
|
|
|
|
|
if (err) { |
|
|
|
|
|
delete self.subscriptions[walletId]; |
|
|
|
|
|
return cb(new Error('Could not subscribe to addresses for wallet ' + walletId)); |
|
|
|
|
|
} |
|
|
|
|
|
self.subscribeAddresses(walletService, _.pluck(addresses, 'address')); |
|
|
|
|
|
>>>>>>> refactor notification dispatching |
|
|
|
|
|
return cb(); |
|
|
return cb(); |
|
|
}); |
|
|
}); |
|
|
}; |
|
|
}; |
|
|