Skip to content

Commit

Permalink
config: (trivial) add some type hints and rm unused variable
Browse files Browse the repository at this point in the history
  • Loading branch information
SomberNight committed Apr 15, 2021
1 parent f53f177 commit 7ffb2c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions electrum/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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
Expand Down Expand Up @@ -371,7 +371,7 @@ def __init__(self, *, network: 'Network', server: ServerAddr, proxy: Optional[di
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
Expand Down Expand Up @@ -683,6 +683,7 @@ async def request_fee_estimates(self):
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)
Expand Down
2 changes: 1 addition & 1 deletion electrum/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def get_fee_estimates(self):
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():
Expand Down
16 changes: 8 additions & 8 deletions electrum/simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def __init__(self, options=None, read_user_config_function=None,
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
Expand Down Expand Up @@ -517,10 +516,10 @@ def get_fee_slider(self, dyn, mempool) -> Tuple[int, int, Optional[int]]:
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):
Expand Down Expand Up @@ -611,9 +610,10 @@ def estimate_fee_for_feerate(cls, fee_per_kb: Union[int, float, Decimal],
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.
Expand Down

0 comments on commit 7ffb2c3

Please sign in to comment.