return after generating notification

This commit is contained in:
Ivan Socolsky 2015-04-30 20:31:45 -03:00
parent bef20234f1
commit 1422107c6e
2 changed files with 59 additions and 40 deletions

View File

@ -260,11 +260,11 @@ WalletService.prototype.replaceTemporaryRequestKey = function(opts, cb) {
walletId: opts.walletId, walletId: opts.walletId,
copayerId: self.copayerId, copayerId: self.copayerId,
copayerName: opts.name, copayerName: opts.name,
}); }, false, function() {
return cb(null, {
return cb(null, { copayerId: self.copayerId,
copayerId: self.copayerId, wallet: wallet
wallet: wallet });
}); });
}); });
}); });
@ -297,7 +297,7 @@ WalletService.prototype._emit = function(eventName, args) {
* @param {Object} data * @param {Object} data
* @param {Boolean} isGlobal - If true, the notification is not issued on behalf of any particular copayer (defaults to false) * @param {Boolean} isGlobal - If true, the notification is not issued on behalf of any particular copayer (defaults to false)
*/ */
WalletService.prototype._notify = function(type, data, isGlobal) { WalletService.prototype._notify = function(type, data, isGlobal, cb) {
var self = this; var self = this;
log.debug('Notification', type, data); log.debug('Notification', type, data);
@ -316,6 +316,7 @@ WalletService.prototype._notify = function(type, data, isGlobal) {
}); });
this.storage.storeNotification(walletId, n, function() { this.storage.storeNotification(walletId, n, function() {
self._emit('notification', n); self._emit('notification', n);
if (cb) return cb();
}); });
}; };
@ -379,10 +380,11 @@ WalletService.prototype.joinWallet = function(opts, cb) {
walletId: opts.walletId, walletId: opts.walletId,
copayerId: copayer.id, copayerId: copayer.id,
copayerName: copayer.name, copayerName: copayer.name,
}); }, false, function() {
return cb(null, { return cb(null, {
copayerId: copayer.id, copayerId: copayer.id,
wallet: wallet wallet: wallet
});
}); });
}); });
}); });
@ -411,8 +413,9 @@ WalletService.prototype.createAddress = function(opts, cb) {
self._notify('NewAddress', { self._notify('NewAddress', {
address: address.address, address: address.address,
}, false, function() {
return cb(null, address);
}); });
return cb(null, address);
}); });
}); });
}); });
@ -710,8 +713,9 @@ WalletService.prototype.createTx = function(opts, cb) {
self._notify('NewTxProposal', { self._notify('NewTxProposal', {
amount: opts.amount amount: opts.amount
}, false, function() {
return cb(null, txp);
}); });
return cb(null, txp);
}); });
}); });
}); });
@ -783,8 +787,9 @@ WalletService.prototype.removePendingTx = function(opts, cb) {
if (actors.length > 1 || (actors.length == 1 && actors[0] !== self.copayerId)) if (actors.length > 1 || (actors.length == 1 && actors[0] !== self.copayerId))
return cb(new ClientError('TXACTIONED', 'Cannot remove a proposal signed/rejected by other copayers')); return cb(new ClientError('TXACTIONED', 'Cannot remove a proposal signed/rejected by other copayers'));
self._notify('TxProposalRemoved'); self._notify('TxProposalRemoved', {}, false, function() {
self.storage.removeTx(self.walletId, txp.id, cb); self.storage.removeTx(self.walletId, txp.id, cb);
});
}); });
}); });
}; };
@ -839,18 +844,26 @@ WalletService.prototype.signTx = function(opts, cb) {
self.storage.storeTx(self.walletId, txp, function(err) { self.storage.storeTx(self.walletId, txp, function(err) {
if (err) return cb(err); if (err) return cb(err);
self._notify('TxProposalAcceptedBy', { async.parallel([
txProposalId: opts.txProposalId,
copayerId: self.copayerId, function(done) {
self._notify('TxProposalAcceptedBy', {
txProposalId: opts.txProposalId,
copayerId: self.copayerId,
}, false, done);
},
function(done) {
if (txp.isAccepted()) {
self._notify('TxProposalFinallyAccepted', {
txProposalId: opts.txProposalId,
}, false, done);
} else {
done();
}
},
], function() {
return cb(null, txp);
}); });
if (txp.isAccepted()) {
self._notify('TxProposalFinallyAccepted', {
txProposalId: opts.txProposalId,
});
}
return cb(null, txp);
}); });
}); });
}); });
@ -892,9 +905,9 @@ WalletService.prototype.broadcastTx = function(opts, cb) {
self._notify('NewOutgoingTx', { self._notify('NewOutgoingTx', {
txProposalId: opts.txProposalId, txProposalId: opts.txProposalId,
txid: txid txid: txid
}, false, function() {
return cb(null, txp);
}); });
return cb(null, txp);
}); });
}); });
}); });
@ -932,19 +945,26 @@ WalletService.prototype.rejectTx = function(opts, cb) {
self.storage.storeTx(self.walletId, txp, function(err) { self.storage.storeTx(self.walletId, txp, function(err) {
if (err) return cb(err); if (err) return cb(err);
self._notify('TxProposalRejectedBy', { async.parallel([
txProposalId: opts.txProposalId,
copayerId: self.copayerId, function(done) {
self._notify('TxProposalRejectedBy', {
txProposalId: opts.txProposalId,
copayerId: self.copayerId,
}, false, done);
},
function(done) {
if (txp.status == 'rejected') {
self._notify('TxProposalFinallyRejected', {
txProposalId: opts.txProposalId,
}, false, done);
} else {
done();
}
},
], function() {
return cb(null, txp);
}); });
if (txp.status == 'rejected') {
self._notify('TxProposalFinallyRejected', {
txProposalId: opts.txProposalId,
});
};
return cb(null, txp);
}); });
}); });
}; };

View File

@ -3014,7 +3014,6 @@ describe('Wallet service', function() {
should.not.exist(err); should.not.exist(err);
var copayerId2 = result.copayerId; var copayerId2 = result.copayerId;
helpers.getAuthServer(copayerId, function(server) { helpers.getAuthServer(copayerId, function(server) {
server.getWallet({}, function(err, wallet) { server.getWallet({}, function(err, wallet) {