remove sockets
This commit is contained in:
parent
56078e2487
commit
b836390b22
@ -35,7 +35,6 @@ app.use((req, res) => res.status(404).send({
|
||||
error: 'Not found',
|
||||
}));
|
||||
|
||||
// Socket server
|
||||
const server = require('http').Server(app);
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -1,68 +0,0 @@
|
||||
const server = require('.');
|
||||
const io = require('socket.io')(server);
|
||||
|
||||
let refreshBlocks = false;
|
||||
const txInterval = 200;
|
||||
let txCounter = 0;
|
||||
|
||||
// Not quite debouncing
|
||||
setInterval(() => {
|
||||
refreshBlocks = true;
|
||||
}, 10000);
|
||||
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
socket.on('subscribe', (data) => {
|
||||
});
|
||||
|
||||
socket.on('message', (data) => {
|
||||
});
|
||||
|
||||
socket.on('unsubscribe', (data) => {
|
||||
});
|
||||
|
||||
socket.on('disconnect', (data) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Emit block refresh and txs
|
||||
function processBlock(entry, block) {
|
||||
if (refreshBlocks) {
|
||||
refreshBlocks = false;
|
||||
emitBlock(entry);
|
||||
}
|
||||
block.txs.forEach((tx) => {
|
||||
txCounter++;
|
||||
if (txCounter % txInterval === 0) {
|
||||
txCounter = 0;
|
||||
emitTx(tx);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function emitBlock(block) {
|
||||
io.sockets.emit('block', {
|
||||
hash: block.toJSON().hash,
|
||||
});
|
||||
}
|
||||
|
||||
function emitTx(transaction) {
|
||||
const txJSON = transaction.toJSON();
|
||||
io.sockets.emit('tx', {
|
||||
txid: txJSON.hash,
|
||||
valueOut: transaction.outputs.reduce((sum, output) => {
|
||||
output = output.toJSON();
|
||||
|
||||
const valB = (output.value || output.valueOut.value || 0) / 1e8;
|
||||
|
||||
return sum + valB;
|
||||
}, 0),
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
io,
|
||||
processBlock,
|
||||
emitBlock,
|
||||
emitTx,
|
||||
};
|
||||
@ -20,7 +20,6 @@
|
||||
"helmet": "^3.8.1",
|
||||
"mongoose": "^4.11.5",
|
||||
"request": "^2.81.0",
|
||||
"socket.io": "^2.0.3",
|
||||
"winston": "^2.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user