2021-04-08 10:15:30 -03:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
|
|
import mempoolJS from '../../src/index';
|
2021-02-09 16:22:48 -03:00
|
|
|
|
|
|
|
const init = async () => {
|
2021-04-08 10:15:30 -03:00
|
|
|
const { websocket } = mempoolJS();
|
|
|
|
|
|
|
|
const ws = websocket.initServer({
|
2021-02-09 16:22:48 -03:00
|
|
|
options: ['blocks', 'stats', 'mempool-blocks', 'live-2h-chart'],
|
|
|
|
});
|
|
|
|
|
2021-04-08 10:15:30 -03:00
|
|
|
ws.on('message', function incoming(data) {
|
|
|
|
const res = JSON.parse(data.toString());
|
2021-02-09 16:22:48 -03:00
|
|
|
if (res.blocks) {
|
2021-04-08 10:15:30 -03:00
|
|
|
res.blocks.forEach((block: { height: any }) => {
|
2021-02-09 16:22:48 -03:00
|
|
|
console.log(block.height);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (res.mempoolInfo) {
|
|
|
|
console.log(res.mempoolInfo);
|
|
|
|
}
|
|
|
|
if (res.transactions) {
|
|
|
|
console.log(res.transactions);
|
|
|
|
}
|
|
|
|
if (res.mempoolBlocks) {
|
|
|
|
console.log(res.mempoolBlocks);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
init();
|