-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mempool periodic update and get_info endpoint
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
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |