http: minor.

This commit is contained in:
Christopher Jeffrey 2017-10-23 12:40:32 -07:00
parent a87260c959
commit f6ca348566
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 34 additions and 22 deletions

View File

@ -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);

View File

@ -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);