|
|
@ -83,6 +83,7 @@ BlockchainMonitor.prototype._initExplorer = function(explorer) { |
|
|
|
log.error('Error connecting to ' + explorer.getConnectionInfo()); |
|
|
|
}); |
|
|
|
socket.on('tx', _.bind(self._handleIncommingTx, self)); |
|
|
|
socket.on('block', _.bind(self._handleNewBlock, self)); |
|
|
|
}; |
|
|
|
|
|
|
|
BlockchainMonitor.prototype._handleIncommingTx = function(data) { |
|
|
@ -112,26 +113,42 @@ BlockchainMonitor.prototype._handleIncommingTx = function(data) { |
|
|
|
|
|
|
|
var walletId = address.walletId; |
|
|
|
log.info('Incoming tx for wallet ' + walletId + ' [' + out.amount + 'sat -> ' + out.address + ']'); |
|
|
|
self._createNotification(walletId, data.txid, out.address, out.amount, next); |
|
|
|
|
|
|
|
var notification = Notification.create({ |
|
|
|
type: 'NewIncomingTx', |
|
|
|
data: { |
|
|
|
txid: data.txid, |
|
|
|
address: out.address, |
|
|
|
amount: out.amount, |
|
|
|
}, |
|
|
|
walletId: walletId, |
|
|
|
}); |
|
|
|
self._storeAndBroadcastNotification(notification, next); |
|
|
|
}); |
|
|
|
}, function(err) { |
|
|
|
return; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
BlockchainMonitor.prototype._createNotification = function(walletId, txid, address, amount, cb) { |
|
|
|
BlockchainMonitor.prototype._handleNewBlock = function(hash) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
log.info('New block: ', hash); |
|
|
|
var notification = Notification.create({ |
|
|
|
type: 'NewIncomingTx', |
|
|
|
type: 'NewBlock', |
|
|
|
data: { |
|
|
|
txid: txid, |
|
|
|
address: address, |
|
|
|
amount: amount, |
|
|
|
hash: hash, |
|
|
|
}, |
|
|
|
walletId: walletId, |
|
|
|
}); |
|
|
|
self.storage.storeNotification(walletId, notification, function() { |
|
|
|
self._storeAndBroadcastNotification(notification, function(err) { |
|
|
|
return; |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
BlockchainMonitor.prototype._storeAndBroadcastNotification = function(notification, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
self.storage.storeNotification(notification.walletId, notification, function() { |
|
|
|
self.messageBroker.send(notification) |
|
|
|
return cb(); |
|
|
|
}); |
|
|
|