electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 547b231b8000ad96ed8ae3af0f8b6040e7422cd6
parent ef84716e8b2675a144c2f6dcc439c70e0bfe218b
Author: SomberNight <somber.night@protonmail.com>
Date:   Thu, 15 Oct 2020 19:50:59 +0200

config: make sure fee_per_kb() returns Optional[int]

electrs sends fee histogram with float feerates

Diffstat:
Melectrum/simple_config.py | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/electrum/simple_config.py b/electrum/simple_config.py @@ -5,7 +5,7 @@ import os import stat import ssl from decimal import Decimal -from typing import Union, Optional +from typing import Union, Optional, Dict from numbers import Real from copy import deepcopy @@ -65,7 +65,7 @@ class SimpleConfig(Logger): # a thread-safe way. self.lock = threading.RLock() - self.mempool_fees = {} + self.mempool_fees = {} # type: Dict[Union[float, int], int] self.fee_estimates = {} self.fee_estimates_last_updated = {} self.last_time_fee_estimates_requested = 0 # zero ensures immediate fees @@ -341,6 +341,8 @@ class SimpleConfig(Logger): fee = int(fee) else: fee = self.fee_estimates.get(num_blocks) + if fee is not None: + fee = int(fee) return fee def fee_to_depth(self, target_fee: Real) -> int: @@ -374,9 +376,10 @@ class SimpleConfig(Logger): return 0 # add one sat/byte as currently that is # the max precision of the histogram + # (well, in case of ElectrumX at least. not for electrs) fee += 1 # convert to sat/kbyte - return fee * 1000 + return int(fee * 1000) def depth_target(self, slider_pos): slider_pos = max(slider_pos, 0) @@ -514,7 +517,7 @@ class SimpleConfig(Logger): fee_rate = FEERATE_STATIC_VALUES[slider_pos] return fee_rate - def fee_per_kb(self, dyn: bool=None, mempool: bool=None, fee_level: float=None) -> Union[int, None]: + def fee_per_kb(self, dyn: bool=None, mempool: bool=None, fee_level: float=None) -> Optional[int]: """Returns sat/kvB fee to pay for a txn. Note: might return None. @@ -538,6 +541,8 @@ class SimpleConfig(Logger): fee_rate = self.eta_to_fee(self.get_fee_level()) else: fee_rate = self.get('fee_per_kb', FEERATE_FALLBACK_STATIC_FEE) + if fee_rate is not None: + fee_rate = int(fee_rate) return fee_rate def fee_per_byte(self):