diff --git a/lib/http/server.js b/lib/http/server.js index 5ae7e318..5ab20361 100644 --- a/lib/http/server.js +++ b/lib/http/server.js @@ -347,7 +347,7 @@ class HTTPServer extends Server { handleSocket(socket) { socket.hook('auth', (...args) => { - if (socket.auth) + if (socket.channel('auth')) throw new Error('Already authed.'); if (!this.options.noAuth) { @@ -364,7 +364,7 @@ class HTTPServer extends Server { throw new Error('Invalid API key.'); } - socket.auth = true; + socket.join('auth'); this.logger.info('Successful auth from %s.', socket.remoteAddress); this.handleAuth(socket); diff --git a/lib/wallet/http.js b/lib/wallet/http.js index 12f06bb9..d7ce6e31 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -797,48 +797,60 @@ class HTTPServer extends Server { */ initSockets() { - this.wdb.on('tx', (w, tx, details) => { - if (!this.channel(`w:${w.id}`)) + this.wdb.on('tx', (wallet, tx, details) => { + const name = `w:${wallet.id}`; + + if (!this.channel(name)) return; const json = details.toJSON(this.network, this.wdb.height); - this.to(`w:${w.id}`, 'wallet tx', json); + this.to(name, 'wallet tx', json); }); - this.wdb.on('confirmed', (w, tx, details) => { - if (!this.channel(`w:${w.id}`)) + this.wdb.on('confirmed', (wallet, tx, details) => { + const name = `w:${wallet.id}`; + + if (!this.channel(name)) return; const json = details.toJSON(this.network, this.wdb.height); - this.to(`w:${w.id}`, 'wallet confirmed', json); + this.to(name, 'wallet confirmed', json); }); - this.wdb.on('unconfirmed', (w, tx, details) => { - if (!this.channel(`w:${w.id}`)) + this.wdb.on('unconfirmed', (wallet, tx, details) => { + const name = `w:${wallet.id}`; + + if (!this.channel(name)) return; const json = details.toJSON(this.network, this.wdb.height); - this.to(`w:${w.id}`, 'wallet unconfirmed', json); + this.to(name, 'wallet unconfirmed', json); }); - this.wdb.on('conflict', (w, tx, details) => { - if (!this.channel(`w:${w.id}`)) + this.wdb.on('conflict', (wallet, tx, details) => { + const name = `w:${wallet.id}`; + + if (!this.channel(name)) return; const json = details.toJSON(this.network, this.wdb.height); - this.to(`w:${w.id}`, 'wallet conflict', json); + this.to(name, 'wallet conflict', json); }); - this.wdb.on('balance', (w, balance) => { - if (!this.channel(`w:${w.id}`)) + this.wdb.on('balance', (wallet, balance) => { + const name = `w:${wallet.id}`; + + if (!this.channel(name)) return; const json = balance.toJSON(); - this.to(`w:${w.id}`, 'wallet balance', json); + this.to(name, 'wallet balance', json); }); - this.wdb.on('address', (w, receive) => { - if (!this.channel(`w:${w.id}`)) + this.wdb.on('address', (wallet, receive) => { + const name = `w:${wallet.id}`; + + if (!this.channel(name)) return; const json = []; @@ -846,7 +858,7 @@ class HTTPServer extends Server { for (const addr of receive) json.push(addr.toJSON(this.network)); - this.to(`w:${w.id}`, 'wallet address', json); + this.to(name, 'wallet address', json); }); } @@ -858,7 +870,7 @@ class HTTPServer extends Server { handleSocket(socket) { socket.hook('wallet auth', (...args) => { - if (socket.auth) + if (socket.channel('wallet auth')) throw new Error('Already authed.'); if (!this.options.noAuth) { @@ -875,7 +887,7 @@ class HTTPServer extends Server { throw new Error('Invalid API key.'); } - socket.auth = true; + socket.join('wallet auth'); this.logger.info('Successful auth from %s.', socket.remoteAddress);