block & tx throttling through the sockets. Blocks emits every 10s. Tx every 100 tx
This commit is contained in:
parent
bdbb086e10
commit
eb7e5d10c9
@ -13,8 +13,7 @@ let refreshBlocks = false;
|
||||
// Super Hacky but better than inline Maths.
|
||||
setInterval(() => {
|
||||
refreshBlocks = true;
|
||||
}, 5000); // Only refresh sockets after 5s passes
|
||||
|
||||
}, 10000); // Only refresh sockets after 5s passes
|
||||
|
||||
function start() {
|
||||
node.open()
|
||||
@ -26,8 +25,7 @@ function start() {
|
||||
});
|
||||
|
||||
node.chain.on('connect', (entry, block) => {
|
||||
logger.log('debug',
|
||||
'New Block & Ledger Entry');
|
||||
|
||||
BlockParser.parse(entry, block);
|
||||
TxParser.parse(entry, block.txs);
|
||||
addrParser.parse(entry, block.txs);
|
||||
@ -49,14 +47,9 @@ function start() {
|
||||
`${err}`);
|
||||
});
|
||||
|
||||
// node.mempool.on('tx' ...)
|
||||
}
|
||||
|
||||
// Super Hack
|
||||
function setSocket(client) {
|
||||
console.log('setting socket for node');
|
||||
//socket = client;
|
||||
|
||||
node.mempool.on('tx', (tx) => {
|
||||
console.log(tx)
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -4,11 +4,32 @@ const OutputModel = require('../../models/output');
|
||||
const config = require('../../config');
|
||||
const util = require('../../lib/util');
|
||||
const logger = require('../logger');
|
||||
const io = require('../api').io;
|
||||
|
||||
const socketThrottle = 100;
|
||||
let counter = 0;
|
||||
|
||||
function parse(entry, txs) {
|
||||
txs.forEach((tx) => {
|
||||
const txJSON = tx.toJSON();
|
||||
|
||||
counter++;
|
||||
|
||||
if (counter % socketThrottle === 0) {
|
||||
io.sockets.emit('tx', {
|
||||
txid: txJSON.hash,
|
||||
valueOut: tx.outputs.reduce((a, b) => {
|
||||
a = a.toJSON();
|
||||
b = b.toJSON();
|
||||
|
||||
const valA = (a.value || a.valueOut.value || 0) / 1e8;
|
||||
const valB = (b.value || b.valueOut.value || 0) / 1e8;
|
||||
|
||||
return valA + valB;
|
||||
}),
|
||||
}, 0);
|
||||
}
|
||||
|
||||
const t = new TxModel({
|
||||
hash: txJSON.hash,
|
||||
witnessHash: txJSON.witnessHash,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user