Skip to content

Commit

Permalink
Add mempool periodic update and get_info endpoint
Browse files Browse the repository at this point in the history
Incorporated a new periodic mempool update function within `main.py` to emit mempool size changes. Created new `get_info.py` endpoint for retrieving global Kaspa BlockDAG information, and `mempool.py` for handling mempool size updates.
  • Loading branch information
lAmeR1 committed Nov 8, 2024
1 parent d2eda17 commit 0064253
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
11 changes: 11 additions & 0 deletions endpoints/get_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# encoding: utf-8

from server import kaspad_client


async def get_info():
"""
Get some global Kaspa BlockDAG information
"""
resp = await kaspad_client.request("getInfoRequest")
return resp["getInfoResponse"]
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from sockets.blockdag import periodical_blockdag
from sockets.bluescore import periodical_blue_score
from sockets.coinsupply import periodic_coin_supply
from sockets.mempool import periodical_mempool

print(
f"Loaded: {sockets.join_room}"
f"{periodic_coin_supply} {periodical_blockdag} {periodical_blue_score}")
f"{periodic_coin_supply} {periodical_blockdag} {periodical_blue_score} {periodical_mempool}")

BLOCKS_TASK = None # type: Task

Expand Down
23 changes: 23 additions & 0 deletions sockets/mempool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# encoding: utf-8

from fastapi_utils.tasks import repeat_every

from endpoints.get_info import get_info
from server import sio, app

mempool = 0


@app.on_event("startup")
@repeat_every(seconds=1)
async def periodical_mempool():
await emit_mempool()


async def emit_mempool():
global mempool
resp = await get_info()

if resp["mempoolSize"] != mempool:
mempool = resp["mempoolSize"]
await sio.emit("mempool", mempool, room="mempool")

0 comments on commit 0064253

Please sign in to comment.