http: minor.
This commit is contained in:
parent
a87260c959
commit
f6ca348566
@ -347,7 +347,7 @@ class HTTPServer extends Server {
|
|||||||
|
|
||||||
handleSocket(socket) {
|
handleSocket(socket) {
|
||||||
socket.hook('auth', (...args) => {
|
socket.hook('auth', (...args) => {
|
||||||
if (socket.auth)
|
if (socket.channel('auth'))
|
||||||
throw new Error('Already authed.');
|
throw new Error('Already authed.');
|
||||||
|
|
||||||
if (!this.options.noAuth) {
|
if (!this.options.noAuth) {
|
||||||
@ -364,7 +364,7 @@ class HTTPServer extends Server {
|
|||||||
throw new Error('Invalid API key.');
|
throw new Error('Invalid API key.');
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.auth = true;
|
socket.join('auth');
|
||||||
|
|
||||||
this.logger.info('Successful auth from %s.', socket.remoteAddress);
|
this.logger.info('Successful auth from %s.', socket.remoteAddress);
|
||||||
this.handleAuth(socket);
|
this.handleAuth(socket);
|
||||||
|
|||||||
@ -797,48 +797,60 @@ class HTTPServer extends Server {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
initSockets() {
|
initSockets() {
|
||||||
this.wdb.on('tx', (w, tx, details) => {
|
this.wdb.on('tx', (wallet, tx, details) => {
|
||||||
if (!this.channel(`w:${w.id}`))
|
const name = `w:${wallet.id}`;
|
||||||
|
|
||||||
|
if (!this.channel(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const json = details.toJSON(this.network, this.wdb.height);
|
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) => {
|
this.wdb.on('confirmed', (wallet, tx, details) => {
|
||||||
if (!this.channel(`w:${w.id}`))
|
const name = `w:${wallet.id}`;
|
||||||
|
|
||||||
|
if (!this.channel(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const json = details.toJSON(this.network, this.wdb.height);
|
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) => {
|
this.wdb.on('unconfirmed', (wallet, tx, details) => {
|
||||||
if (!this.channel(`w:${w.id}`))
|
const name = `w:${wallet.id}`;
|
||||||
|
|
||||||
|
if (!this.channel(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const json = details.toJSON(this.network, this.wdb.height);
|
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) => {
|
this.wdb.on('conflict', (wallet, tx, details) => {
|
||||||
if (!this.channel(`w:${w.id}`))
|
const name = `w:${wallet.id}`;
|
||||||
|
|
||||||
|
if (!this.channel(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const json = details.toJSON(this.network, this.wdb.height);
|
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) => {
|
this.wdb.on('balance', (wallet, balance) => {
|
||||||
if (!this.channel(`w:${w.id}`))
|
const name = `w:${wallet.id}`;
|
||||||
|
|
||||||
|
if (!this.channel(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const json = balance.toJSON();
|
const json = balance.toJSON();
|
||||||
this.to(`w:${w.id}`, 'wallet balance', json);
|
this.to(name, 'wallet balance', json);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.wdb.on('address', (w, receive) => {
|
this.wdb.on('address', (wallet, receive) => {
|
||||||
if (!this.channel(`w:${w.id}`))
|
const name = `w:${wallet.id}`;
|
||||||
|
|
||||||
|
if (!this.channel(name))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const json = [];
|
const json = [];
|
||||||
@ -846,7 +858,7 @@ class HTTPServer extends Server {
|
|||||||
for (const addr of receive)
|
for (const addr of receive)
|
||||||
json.push(addr.toJSON(this.network));
|
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) {
|
handleSocket(socket) {
|
||||||
socket.hook('wallet auth', (...args) => {
|
socket.hook('wallet auth', (...args) => {
|
||||||
if (socket.auth)
|
if (socket.channel('wallet auth'))
|
||||||
throw new Error('Already authed.');
|
throw new Error('Already authed.');
|
||||||
|
|
||||||
if (!this.options.noAuth) {
|
if (!this.options.noAuth) {
|
||||||
@ -875,7 +887,7 @@ class HTTPServer extends Server {
|
|||||||
throw new Error('Invalid API key.');
|
throw new Error('Invalid API key.');
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.auth = true;
|
socket.join('wallet auth');
|
||||||
|
|
||||||
this.logger.info('Successful auth from %s.', socket.remoteAddress);
|
this.logger.info('Successful auth from %s.', socket.remoteAddress);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user