2021-05-20 12:03:40 -03:00
|
|
|
import mempoolJS from "@mempool/mempool.js";
|
2021-02-09 16:22:48 -03:00
|
|
|
|
2021-05-20 12:03:40 -03:00
|
|
|
const { bitcoin: { websocket } } = mempoolJS();
|
2021-04-08 10:15:30 -03:00
|
|
|
|
2021-05-20 12:03:40 -03:00
|
|
|
const init = async () => {
|
|
|
|
|
2021-04-08 10:15:30 -03:00
|
|
|
const ws = websocket.initServer({
|
2021-05-20 12:03:40 -03:00
|
|
|
options: ["blocks", "stats", "mempool-blocks", "live-2h-chart"],
|
2021-02-09 16:22:48 -03:00
|
|
|
});
|
2021-05-20 12:03:40 -03:00
|
|
|
|
|
|
|
ws.on("message", function incoming(data) {
|
2021-04-08 10:15:30 -03:00
|
|
|
const res = JSON.parse(data.toString());
|
2021-02-09 16:22:48 -03:00
|
|
|
if (res.blocks) {
|
2021-04-14 17:27:28 -03:00
|
|
|
console.log(res.blocks);
|
2021-02-09 16:22:48 -03:00
|
|
|
}
|
|
|
|
if (res.mempoolInfo) {
|
|
|
|
console.log(res.mempoolInfo);
|
|
|
|
}
|
|
|
|
if (res.transactions) {
|
|
|
|
console.log(res.transactions);
|
|
|
|
}
|
|
|
|
if (res.mempoolBlocks) {
|
|
|
|
console.log(res.mempoolBlocks);
|
|
|
|
}
|
|
|
|
});
|
2021-05-20 12:03:40 -03:00
|
|
|
}
|
2021-02-09 16:22:48 -03:00
|
|
|
init();
|