Browse Source

config: (trivial) add some type hints and rm unused variable

patch-4
SomberNight 4 years ago
parent
commit
7ffb2c3cb0
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 5
      electrum/interface.py
  2. 2
      electrum/network.py
  3. 16
      electrum/simple_config.py

5
electrum/interface.py

@ -29,7 +29,7 @@ import sys
import traceback
import asyncio
import socket
from typing import Tuple, Union, List, TYPE_CHECKING, Optional, Set, NamedTuple, Any, Sequence
from typing import Tuple, Union, List, TYPE_CHECKING, Optional, Set, NamedTuple, Any, Sequence, Dict
from collections import defaultdict
from ipaddress import IPv4Network, IPv6Network, ip_address, IPv6Address, IPv4Address
import itertools
@ -371,7 +371,7 @@ class Interface(Logger):
self.tip_header = None
self.tip = 0
self.fee_estimates_eta = {}
self.fee_estimates_eta = {} # type: Dict[int, int]
# Dump network messages (only for this interface). Set at runtime from the console.
self.debug = False
@ -683,6 +683,7 @@ class Interface(Logger):
for nblock_target, task in fee_tasks:
fee = task.result()
if fee < 0: continue
assert isinstance(fee, int)
self.fee_estimates_eta[nblock_target] = fee
self.network.update_fee_estimates()
await asyncio.sleep(60)

2
electrum/network.py

@ -534,7 +534,7 @@ class Network(Logger, NetworkRetryManager[ServerAddr]):
return {}
return self.interface.fee_estimates_eta
def update_fee_estimates(self, *, fee_est: Dict = None):
def update_fee_estimates(self, *, fee_est: Dict[int, int] = None):
if fee_est is None:
fee_est = self.get_fee_estimates()
for nblock_target, fee in fee_est.items():

16
electrum/simple_config.py

@ -66,8 +66,7 @@ class SimpleConfig(Logger):
self.lock = threading.RLock()
self.mempool_fees = None # type: Optional[Sequence[Tuple[Union[float, int], int]]]
self.fee_estimates = {}
self.fee_estimates_last_updated = {}
self.fee_estimates = {} # type: Dict[int, int]
self.last_time_fee_estimates_requested = 0 # zero ensures immediate fees
# The following two functions are there for dependency injection when
@ -517,10 +516,10 @@ class SimpleConfig(Logger):
def static_fee(self, i):
return FEERATE_STATIC_VALUES[i]
def static_fee_index(self, value) -> int:
if value is None:
def static_fee_index(self, fee_per_kb: Optional[int]) -> int:
if fee_per_kb is None:
raise TypeError('static fee cannot be None')
dist = list(map(lambda x: abs(x - value), FEERATE_STATIC_VALUES))
dist = list(map(lambda x: abs(x - fee_per_kb), FEERATE_STATIC_VALUES))
return min(range(len(dist)), key=dist.__getitem__)
def has_fee_etas(self):
@ -611,9 +610,10 @@ class SimpleConfig(Logger):
fee_per_byte = quantize_feerate(fee_per_byte)
return round(fee_per_byte * size)
def update_fee_estimates(self, key, value):
self.fee_estimates[key] = value
self.fee_estimates_last_updated[key] = time.time()
def update_fee_estimates(self, nblock_target: int, fee_per_kb: int):
assert isinstance(nblock_target, int), f"expected int, got {nblock_target!r}"
assert isinstance(fee_per_kb, int), f"expected int, got {fee_per_kb!r}"
self.fee_estimates[nblock_target] = fee_per_kb
def is_fee_estimates_update_required(self):
"""Checks time since last requested and updated fee estimates.

Loading…
Cancel
Save