Skip to content

Commit

Permalink
minimised block version for explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
lAmeR1 committed Apr 22, 2023
1 parent db9b611 commit 98b1d95
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions sockets/blocks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# encoding: utf-8
import asyncio

from server import kaspad_client, sio

Expand All @@ -15,16 +14,28 @@ async def on_new_block(e):
return

global BLOCKS_CACHE
BLOCKS_CACHE.append(block_info)

emit_info = {
'block_hash': block_info["verboseData"]["hash"],
'difficulty': block_info["verboseData"]["difficulty"],
'blueScore': block_info["header"]["blueScore"],
'timestamp': block_info["header"]["timestamp"],
'txs': [{
'txId': x["verboseData"]["transactionId"],
'outputs': [(output["verboseData"]["scriptPublicKeyAddress"], output["amount"]) for output in
x["outputs"]]
} for x in block_info["transactions"]]
}

BLOCKS_CACHE.append(emit_info)
if len(BLOCKS_CACHE) > 50:
BLOCKS_CACHE.pop(0)

await sio.emit("new-block", block_info, room="blocks")
await sio.emit("new-block", emit_info, room="blocks")

await kaspad_client.notify("notifyBlockAddedRequest", None, on_new_block)



@sio.on("last-blocks")
async def get_last_blocks(sid, msg):
await sio.emit("last-blocks", BLOCKS_CACHE, to=sid)

0 comments on commit 98b1d95

Please sign in to comment.