commit
62909c34db
|
@ -37,6 +37,7 @@ Notification.create = function(opts) {
|
|||
x.id = _.padLeft(now, 14, '0') + _.padLeft(opts.ticker || 0, 4, '0');
|
||||
x.type = opts.type || 'general';
|
||||
x.data = opts.data;
|
||||
x.walletId = opts.walletId;
|
||||
x.creatorId = opts.creatorId;
|
||||
|
||||
return x;
|
||||
|
@ -49,6 +50,7 @@ Notification.fromObj = function(obj) {
|
|||
x.id = obj.id;
|
||||
x.type = obj.type,
|
||||
x.data = obj.data;
|
||||
x.walletId = obj.walletId;
|
||||
x.creatorId = obj.creatorId;
|
||||
|
||||
return x;
|
||||
|
|
|
@ -20,6 +20,7 @@ TxProposal.create = function(opts) {
|
|||
var now = Date.now();
|
||||
x.createdOn = Math.floor(now / 1000);
|
||||
x.id = _.padLeft(now, 14, '0') + Uuid.v4();
|
||||
x.walletId = opts.walletId;
|
||||
x.creatorId = opts.creatorId;
|
||||
x.toAddress = opts.toAddress;
|
||||
x.amount = opts.amount;
|
||||
|
@ -45,6 +46,7 @@ TxProposal.fromObj = function(obj) {
|
|||
x.version = obj.version;
|
||||
x.createdOn = obj.createdOn;
|
||||
x.id = obj.id;
|
||||
x.walletId = obj.walletId;
|
||||
x.creatorId = obj.creatorId;
|
||||
x.toAddress = obj.toAddress;
|
||||
x.amount = obj.amount;
|
||||
|
|
|
@ -182,13 +182,16 @@ WalletService.prototype._notify = function(type, data) {
|
|||
log.debug('Notification', type, data);
|
||||
|
||||
var walletId = self.walletId || data.walletId;
|
||||
var copayerId = self.copayerId || data.copayerId;
|
||||
|
||||
$.checkState(walletId);
|
||||
|
||||
var n = Notification.create({
|
||||
type: type,
|
||||
data: data,
|
||||
ticker: this.notifyTicker++,
|
||||
creatorId: self.copayerId,
|
||||
creatorId: copayerId,
|
||||
walletId: walletId,
|
||||
});
|
||||
this.storage.storeNotification(walletId, n, function() {
|
||||
self._emit('notification', n);
|
||||
|
@ -351,7 +354,7 @@ WalletService.prototype._getBlockExplorer = function(provider, network) {
|
|||
return this.blockExplorer;
|
||||
|
||||
switch (provider) {
|
||||
default:;
|
||||
default: ;
|
||||
case 'insight':
|
||||
switch (network) {
|
||||
default:
|
||||
|
@ -580,6 +583,7 @@ WalletService.prototype.createTx = function(opts, cb) {
|
|||
var changeAddress = wallet.createAddress(true);
|
||||
|
||||
var txp = TxProposal.create({
|
||||
walletId: self.walletId,
|
||||
creatorId: self.copayerId,
|
||||
toAddress: opts.toAddress,
|
||||
amount: opts.amount,
|
||||
|
|
|
@ -29,7 +29,10 @@ WsApp.start = function(server) {
|
|||
var io = require('socket.io')(server);
|
||||
|
||||
WalletService.onNotification(function(serviceInstance, args) {
|
||||
io.to(serviceInstance.walletId).emit('notification', args);
|
||||
var room = serviceInstance.walletId || args.walletId;
|
||||
if (room) {
|
||||
io.to(room).emit('notification', args);
|
||||
}
|
||||
});
|
||||
|
||||
io.on('connection', function(socket) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "bitcore-wallet-service",
|
||||
"description": "A service for Mutisig HD Bitcoin Wallets",
|
||||
"author": "BitPay Inc",
|
||||
"version": "0.0.15",
|
||||
"version": "0.0.16",
|
||||
"keywords": [
|
||||
"bitcoin",
|
||||
"copay",
|
||||
|
|
|
@ -800,6 +800,8 @@ describe('Copay server', function() {
|
|||
server.createTx(txOpts, function(err, tx) {
|
||||
should.not.exist(err);
|
||||
should.exist(tx);
|
||||
tx.walletId.should.equal(wallet.id);
|
||||
tx.creatorId.should.equal(wallet.copayers[0].id);
|
||||
tx.message.should.equal('some message');
|
||||
tx.isAccepted().should.equal.false;
|
||||
tx.isRejected().should.equal.false;
|
||||
|
@ -1611,6 +1613,7 @@ describe('Copay server', function() {
|
|||
should.not.exist(err);
|
||||
var last = _.last(notifications);
|
||||
last.type.should.equal('TxProposalFinallyAccepted');
|
||||
last.walletId.should.equal(wallet.id);
|
||||
last.creatorId.should.equal(wallet.copayers[1].id);
|
||||
last.data.txProposalId.should.equal(txp.id);
|
||||
done();
|
||||
|
@ -1869,6 +1872,9 @@ describe('Copay server', function() {
|
|||
should.not.exist(err);
|
||||
var types = _.pluck(notifications, 'type');
|
||||
types.should.deep.equal(['NewTxProposal', 'NewTxProposal', 'NewTxProposal', 'NewAddress']);
|
||||
var walletIds = _.uniq(_.pluck(notifications, 'walletId'));
|
||||
walletIds.length.should.equal(1);
|
||||
walletIds[0].should.equal(wallet.id);
|
||||
var creators = _.uniq(_.pluck(notifications, 'creatorId'));
|
||||
creators.length.should.equal(1);
|
||||
creators[0].should.equal(wallet.copayers[0].id);
|
||||
|
@ -1902,6 +1908,19 @@ describe('Copay server', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should contain walletId & creatorId on NewCopayer', function(done) {
|
||||
server.getNotifications({
|
||||
minTs: 0,
|
||||
}, function(err, notifications) {
|
||||
should.not.exist(err);
|
||||
var newCopayer = notifications[0];
|
||||
newCopayer.type.should.equal('NewCopayer');
|
||||
newCopayer.walletId.should.equal(wallet.id);
|
||||
newCopayer.creatorId.should.equal(wallet.copayers[0].id);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should notify sign and acceptance', function(done) {
|
||||
server.getPendingTxs({}, function(err, txs) {
|
||||
helpers.stubBroadcastFail();
|
||||
|
|
|
@ -91,6 +91,7 @@ var aTXP = function() {
|
|||
"version": "1.0.0",
|
||||
"createdOn": 1423146231,
|
||||
"id": "75c34f49-1ed6-255f-e9fd-0c71ae75ed1e",
|
||||
"walletId": "1",
|
||||
"creatorId": "1",
|
||||
"toAddress": "18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7",
|
||||
"amount": 50000000,
|
||||
|
|
Loading…
Reference in New Issue