Add estimatesmartfee to monitor mode

master
Daniel Edgecumbe 7 years ago
parent e0bf9041a9
commit df40b10bed

@ -60,12 +60,12 @@ async def handle_hotkeys(window, callback, resize_callback):
await handle_key(key)
async def poll_client(client, method, callback, sleeptime):
async def poll_client(client, method, callback, sleeptime, params=None):
# Allow the rest of the program to start.
await asyncio.sleep(0.1)
while True:
j = await client.request(method)
j = await client.request(method, params=params)
await callback(method, j)
await asyncio.sleep(sleeptime)
@ -155,6 +155,12 @@ def create_tasks(client, window):
on_peerinfo, 5.0),
poll_client(client, "getmempoolinfo",
monitorview.on_mempoolinfo, 5.0),
poll_client(client, "estimatesmartfee",
monitorview.on_estimatesmartfee, 15.0, params=[2]),
poll_client(client, "estimatesmartfee",
monitorview.on_estimatesmartfee, 15.0, params=[5]),
poll_client(client, "estimatesmartfee",
monitorview.on_estimatesmartfee, 15.0, params=[10]),
tick(on_tick, 1.0),
handle_hotkeys(window, footerview.on_mode_change, on_window_resize)
]

@ -25,6 +25,7 @@ class MonitorView(object):
self._bestblock = None # raw json block
self._bestcoinbase = None # raw json tx
self._mempoolinfo = None # raw mempoolinfo
self._estimatesmartfee = {} # blocks -> feerate/kB
self._dt = None
self._window_size = MIN_WINDOW_SIZE
@ -120,6 +121,13 @@ class MonitorView(object):
self._mempoolinfo["bytes"] / 1048576,
))
if self._estimatesmartfee:
estimates = " ".join(
"({: 2d}: {: 8.0f} sat/kB)".format(b, fr*10**8)
for b, fr in sorted(self._estimatesmartfee.items())
)
self._pad.addstr(11, 1, "estimatesmartfee: {}".format(estimates))
self._draw_pad_to_screen()
def _draw_pad_to_screen(self):
@ -166,6 +174,18 @@ class MonitorView(object):
if self._visible:
await self.draw()
async def on_estimatesmartfee(self, key, obj):
try:
estimatesmartfee = obj["result"]
except KeyError:
return
b, fr = estimatesmartfee["blocks"], estimatesmartfee["feerate"]
self._estimatesmartfee[b] = fr
if self._visible:
await self.draw()
async def on_tick(self, dt):
with await self._lock:
self._dt = dt

Loading…
Cancel
Save