socket moved to api level and socket block refresh signal set to 5s
This commit is contained in:
parent
923128de59
commit
bdbb086e10
2
index.js
2
index.js
@ -1,7 +1,7 @@
|
|||||||
const Bcoin = require('./lib/node');
|
const Bcoin = require('./lib/node');
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const logger = require('./lib/logger');
|
const logger = require('./lib/logger');
|
||||||
const Api = require('./lib/api');
|
const Api = require('./lib/api').server;
|
||||||
const db = require('./lib/db');
|
const db = require('./lib/db');
|
||||||
|
|
||||||
logger.log('debug',
|
logger.log('debug',
|
||||||
|
|||||||
@ -38,4 +38,7 @@ const io = require('socket.io')(server);
|
|||||||
|
|
||||||
const SocketAPI = require('./socket')(io);
|
const SocketAPI = require('./socket')(io);
|
||||||
|
|
||||||
module.exports = server;
|
module.exports = {
|
||||||
|
server,
|
||||||
|
io,
|
||||||
|
};
|
||||||
|
|||||||
@ -4,9 +4,16 @@ const BlockParser = require('../parser').Block;
|
|||||||
const TxParser = require('../parser').Transaction;
|
const TxParser = require('../parser').Transaction;
|
||||||
const addrParser = require('../parser').Address;
|
const addrParser = require('../parser').Address;
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
const io = require('../api').io;
|
||||||
|
|
||||||
const node = new FullNode(config.bcoin);
|
const node = new FullNode(config.bcoin);
|
||||||
let socket;
|
|
||||||
|
// Hacky move this to config
|
||||||
|
let refreshBlocks = false;
|
||||||
|
// Super Hacky but better than inline Maths.
|
||||||
|
setInterval(() => {
|
||||||
|
refreshBlocks = true;
|
||||||
|
}, 5000); // Only refresh sockets after 5s passes
|
||||||
|
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
@ -25,7 +32,12 @@ function start() {
|
|||||||
TxParser.parse(entry, block.txs);
|
TxParser.parse(entry, block.txs);
|
||||||
addrParser.parse(entry, block.txs);
|
addrParser.parse(entry, block.txs);
|
||||||
|
|
||||||
|
if (refreshBlocks) {
|
||||||
|
refreshBlocks = false;
|
||||||
|
io.sockets.emit('block', {
|
||||||
|
hash: block.toJSON().hash,
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
node.pool.on('peer', (peer) => {
|
node.pool.on('peer', (peer) => {
|
||||||
@ -49,5 +61,4 @@ function setSocket(client) {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
start,
|
start,
|
||||||
setSocket,
|
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user