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