added particles and some code for recent block listing
This commit is contained in:
parent
c9a6769be7
commit
c81df9093d
9 changed files with 1789 additions and 30 deletions
|
@ -2,10 +2,17 @@
|
|||
|
||||
SSE API for node client access
|
||||
"""
|
||||
from pathlib import Path
|
||||
|
||||
from flask import g, Blueprint
|
||||
from gevent import sleep
|
||||
import gevent
|
||||
import ujson
|
||||
|
||||
from onionrblocks.onionrblockapi import Block
|
||||
from coredb.dbfiles import block_meta_db
|
||||
from coredb.blockmetadb import get_block_list
|
||||
from onionrutils.epoch import get_epoch
|
||||
from onionrstatistics.transports.tor import TorStats
|
||||
from .. import wrapper
|
||||
"""
|
||||
|
@ -45,3 +52,22 @@ def stream_tor_circuits():
|
|||
yield "data: " + tor_stats.get_json() + "\n\n"
|
||||
sleep(10)
|
||||
return SSEWrapper.handle_sse_request(circuit_stat_stream)
|
||||
|
||||
@private_sse_blueprint.route('/recentblocks')
|
||||
def stream_recent_blocks():
|
||||
def _compile_json(b_list):
|
||||
js = {}
|
||||
for block in b_list:
|
||||
js[block] = Block(block).btype
|
||||
return ujson.dumps(js, reject_bytes=True)
|
||||
|
||||
def _stream_recent():
|
||||
last_time = Path(block_meta_db).stat().st_ctime
|
||||
while True:
|
||||
if Path(block_meta_db).stat().st_ctime != last_time:
|
||||
last_time = Path(block_meta_db).stat().st_ctime
|
||||
yield "data: " + _compile_json(get_block_list(get_epoch() - 5)) + "\n\n"
|
||||
else:
|
||||
yield "data: none" + "\n\n"
|
||||
sleep(5)
|
||||
return SSEWrapper.handle_sse_request(_stream_recent)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue