Skip to content

Commit b1a2d63

Browse files
author
Micah Riggan
committed
fix(node): remove wallet from websockets
websocket events shouldn't contain wallet ids
1 parent 6e15cd4 commit b1a2d63

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/bitcore-node/src/services/socket.ts

+14-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import SocketIO = require('socket.io');
22
import { LoggifyClass } from '../decorators/Loggify';
33
import { EventModel, IEvent } from '../models/events';
44
import { Event } from './event';
5+
import { ObjectID } from 'mongodb';
6+
7+
function SanitizeWallet(x: { wallets: ObjectID[] }) {
8+
const sanitized = Object.assign({}, x, { wallets: undefined });
9+
if (sanitized.wallets && sanitized.wallets.length > 0) {
10+
delete sanitized.wallets;
11+
}
12+
return sanitized;
13+
}
514

615
@LoggifyClass
716
export class SocketService {
@@ -29,7 +38,8 @@ export class SocketService {
2938
Event.txStream.on('data', (tx: IEvent.TxEvent) => {
3039
if (this.io) {
3140
const { chain, network } = tx;
32-
this.io.sockets.in(`/${chain}/${network}/inv`).emit('tx', tx);
41+
const sanitizedTx = SanitizeWallet(tx);
42+
this.io.sockets.in(`/${chain}/${network}/inv`).emit('tx', sanitizedTx);
3343
}
3444
});
3545

@@ -44,8 +54,9 @@ export class SocketService {
4454
if (this.io) {
4555
const { coin, address } = addressCoin;
4656
const { chain, network } = coin;
47-
this.io.sockets.in(`/${chain}/${network}/address`).emit(address, coin);
48-
this.io.sockets.in(`/${chain}/${network}/inv`).emit('coin', coin);
57+
const sanitizedCoin = SanitizeWallet(coin);
58+
this.io.sockets.in(`/${chain}/${network}/address`).emit(address, sanitizedCoin);
59+
this.io.sockets.in(`/${chain}/${network}/inv`).emit('coin', sanitizedCoin);
4960
}
5061
});
5162
}

0 commit comments

Comments
 (0)