Skip to content

Commit

Permalink
fix(node): remove wallet from websockets
Browse files Browse the repository at this point in the history
websocket events shouldn't contain wallet ids
  • Loading branch information
Micah Riggan committed Dec 21, 2018
1 parent 6e15cd4 commit b1a2d63
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/bitcore-node/src/services/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import SocketIO = require('socket.io');
import { LoggifyClass } from '../decorators/Loggify';
import { EventModel, IEvent } from '../models/events';
import { Event } from './event';
import { ObjectID } from 'mongodb';

function SanitizeWallet(x: { wallets: ObjectID[] }) {
const sanitized = Object.assign({}, x, { wallets: undefined });
if (sanitized.wallets && sanitized.wallets.length > 0) {
delete sanitized.wallets;
}
return sanitized;
}

@LoggifyClass
export class SocketService {
Expand Down Expand Up @@ -29,7 +38,8 @@ export class SocketService {
Event.txStream.on('data', (tx: IEvent.TxEvent) => {
if (this.io) {
const { chain, network } = tx;
this.io.sockets.in(`/${chain}/${network}/inv`).emit('tx', tx);
const sanitizedTx = SanitizeWallet(tx);
this.io.sockets.in(`/${chain}/${network}/inv`).emit('tx', sanitizedTx);
}
});

Expand All @@ -44,8 +54,9 @@ export class SocketService {
if (this.io) {
const { coin, address } = addressCoin;
const { chain, network } = coin;
this.io.sockets.in(`/${chain}/${network}/address`).emit(address, coin);
this.io.sockets.in(`/${chain}/${network}/inv`).emit('coin', coin);
const sanitizedCoin = SanitizeWallet(coin);
this.io.sockets.in(`/${chain}/${network}/address`).emit(address, sanitizedCoin);
this.io.sockets.in(`/${chain}/${network}/inv`).emit('coin', sanitizedCoin);
}
});
}
Expand Down

0 comments on commit b1a2d63

Please sign in to comment.