|
|
@ -18,6 +18,8 @@ BlockchainMonitor.prototype.start = function(opts, cb) { |
|
|
|
opts = opts || {}; |
|
|
|
$.checkArgument(opts.blockchainExplorerOpts); |
|
|
|
$.checkArgument(opts.storageOpts); |
|
|
|
$.checkArgument(opts.lockOpts); |
|
|
|
$.checkArgument(opts.emailOpts); |
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
@ -38,8 +40,20 @@ BlockchainMonitor.prototype.start = function(opts, cb) { |
|
|
|
self.messageBroker = new MessageBroker(opts.messageBrokerOpts); |
|
|
|
done(); |
|
|
|
}, |
|
|
|
], cb); |
|
|
|
|
|
|
|
function(done) { |
|
|
|
self.lock = new Lock(opts.lockOpts); |
|
|
|
}, |
|
|
|
], function(err) { |
|
|
|
if (err) return cb(err); |
|
|
|
|
|
|
|
self.emailService = new EmailService({ |
|
|
|
lock: self.lock, |
|
|
|
storage: self.storage, |
|
|
|
mailer: opts.mailer, |
|
|
|
emailOpts: opts.emailOpts, |
|
|
|
}); |
|
|
|
return cb(); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
BlockchainMonitor.prototype._initExplorer = function(provider, network, url) { |
|
|
@ -106,7 +120,7 @@ BlockchainMonitor.prototype._handleIncommingTx = function(data) { |
|
|
|
BlockchainMonitor.prototype._createNotification = function(walletId, txid, address, amount, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var n = Notification.create({ |
|
|
|
var notification = Notification.create({ |
|
|
|
type: 'NewIncomingTx', |
|
|
|
data: { |
|
|
|
txid: txid, |
|
|
@ -115,9 +129,13 @@ BlockchainMonitor.prototype._createNotification = function(walletId, txid, addre |
|
|
|
}, |
|
|
|
walletId: walletId, |
|
|
|
}); |
|
|
|
self.storage.storeNotification(walletId, n, function() { |
|
|
|
self.messageBroker.send(n) |
|
|
|
return cb(); |
|
|
|
self.storage.storeNotification(walletId, notification, function() { |
|
|
|
self.messageBroker.send(notification) |
|
|
|
if (self.emailService) { |
|
|
|
self.emailService.sendEmail(notification, function() { |
|
|
|
if (cb) return cb(); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|