Add fee slider class with network callback.
This commit is contained in:
@@ -6,6 +6,8 @@ import os
|
||||
from copy import deepcopy
|
||||
from util import user_dir, print_error, print_msg, print_stderr, PrintError
|
||||
|
||||
from bitcoin import MAX_FEE_RATE, FEE_TARGETS
|
||||
|
||||
SYSTEM_CONFIG_PATH = "/etc/electrum.conf"
|
||||
|
||||
config = None
|
||||
@@ -40,6 +42,8 @@ class SimpleConfig(PrintError):
|
||||
# a thread-safe way.
|
||||
self.lock = threading.RLock()
|
||||
|
||||
self.fee_estimates = {}
|
||||
|
||||
# The following two functions are there for dependency injection when
|
||||
# testing.
|
||||
if read_system_config_function is None:
|
||||
@@ -190,6 +194,43 @@ class SimpleConfig(PrintError):
|
||||
path = wallet.storage.path
|
||||
self.set_key('gui_last_wallet', path)
|
||||
|
||||
def max_fee_rate(self):
|
||||
return self.get('max_fee_rate', MAX_FEE_RATE)
|
||||
|
||||
def dynfee(self, i):
|
||||
if i < 4:
|
||||
j = FEE_TARGETS[i]
|
||||
fee = self.fee_estimates.get(j)
|
||||
else:
|
||||
assert i == 4
|
||||
fee = self.fee_estimates.get(2)
|
||||
if fee is not None:
|
||||
fee += fee/2
|
||||
if fee is not None:
|
||||
fee = min(5*MAX_FEE_RATE, fee)
|
||||
return fee
|
||||
|
||||
def reverse_dynfee(self, fee_per_kb):
|
||||
import operator
|
||||
dist = map(lambda x: (x[0], abs(x[1] - fee_per_kb)), self.fee_estimates.items())
|
||||
min_target, min_value = min(dist, key=operator.itemgetter(1))
|
||||
if fee_per_kb < self.fee_estimates.get(25)/2:
|
||||
min_target = -1
|
||||
return min_target
|
||||
|
||||
def has_fee_estimates(self):
|
||||
return len(self.fee_estimates)==4
|
||||
|
||||
def is_dynfee(self):
|
||||
return self.get('dynamic_fees') and self.has_fee_estimates()
|
||||
|
||||
def fee_per_kb(self):
|
||||
dyn = self.is_dynfee()
|
||||
if dyn:
|
||||
fee_rate = self.dynfee(self.get('fee_level', 2))
|
||||
else:
|
||||
fee_rate = self.get('fee_per_kb', self.max_fee_rate()/2)
|
||||
return fee_rate
|
||||
|
||||
def read_system_config(path=SYSTEM_CONFIG_PATH):
|
||||
"""Parse and return the system config settings in /etc/electrum.conf."""
|
||||
|
||||
Reference in New Issue
Block a user