Browse Source

send email from blockchain monitor

activeAddress
Ivan Socolsky 10 years ago
parent
commit
c864675b20
  1. 30
      lib/blockchainmonitor.js
  2. 2
      lib/server.js

30
lib/blockchainmonitor.js

@ -18,6 +18,8 @@ BlockchainMonitor.prototype.start = function(opts, cb) {
opts = opts || {}; opts = opts || {};
$.checkArgument(opts.blockchainExplorerOpts); $.checkArgument(opts.blockchainExplorerOpts);
$.checkArgument(opts.storageOpts); $.checkArgument(opts.storageOpts);
$.checkArgument(opts.lockOpts);
$.checkArgument(opts.emailOpts);
var self = this; var self = this;
@ -38,8 +40,20 @@ BlockchainMonitor.prototype.start = function(opts, cb) {
self.messageBroker = new MessageBroker(opts.messageBrokerOpts); self.messageBroker = new MessageBroker(opts.messageBrokerOpts);
done(); 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) { 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) { BlockchainMonitor.prototype._createNotification = function(walletId, txid, address, amount, cb) {
var self = this; var self = this;
var n = Notification.create({ var notification = Notification.create({
type: 'NewIncomingTx', type: 'NewIncomingTx',
data: { data: {
txid: txid, txid: txid,
@ -115,9 +129,13 @@ BlockchainMonitor.prototype._createNotification = function(walletId, txid, addre
}, },
walletId: walletId, walletId: walletId,
}); });
self.storage.storeNotification(walletId, n, function() { self.storage.storeNotification(walletId, notification, function() {
self.messageBroker.send(n) self.messageBroker.send(notification)
return cb(); if (self.emailService) {
self.emailService.sendEmail(notification, function() {
if (cb) return cb();
});
}
}); });
}; };

2
lib/server.js

@ -82,7 +82,7 @@ WalletService.initialize = function(opts, cb) {
}; };
function initEmailService(cb) { function initEmailService(cb) {
if (!opts.mailer && !opts.email) return cb(); if (!opts.mailer && !opts.emailOpts) return cb();
emailService = new EmailService({ emailService = new EmailService({
lock: lock, lock: lock,
storage: storage, storage: storage,

Loading…
Cancel
Save