commit aafd3b929b4403b73e4569f6bb058f83c9ce8a8d
parent 4e19484b4aa06557085bde5dcb785dd7e4e9048e
Author: ThomasV <thomasv@electrum.org>
Date: Tue, 6 Feb 2018 11:09:42 +0100
config: sanitize fee_level and depth_level
Diffstat:
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/lib/simple_config.py b/lib/simple_config.py
@@ -325,7 +325,7 @@ class SimpleConfig(PrintError):
def get_fee_status(self):
dyn = self.is_dynfee()
mempool = self.get('mempool_fees')
- pos = self.get('fee_level', 2) if mempool else self.get('depth_level', 2)
+ pos = self.get_depth_level() if mempool else self.get_fee_level()
fee_rate = self.fee_per_kb()
target, tooltip = self.get_fee_text(pos, dyn, mempool, fee_rate)
return target
@@ -356,20 +356,28 @@ class SimpleConfig(PrintError):
tooltip = ''
return text, tooltip
+ def get_depth_level(self):
+ maxp = len(FEE_DEPTH_TARGETS) - 1
+ return min(maxp, self.get('depth_level', 2))
+
+ def get_fee_level(self):
+ maxp = len(FEE_ETA_TARGETS) - 1
+ return min(maxp, self.get('fee_level', 2))
+
def get_fee_slider(self, dyn, mempool):
if dyn:
if mempool:
+ pos = self.get_depth_level()
maxp = len(FEE_DEPTH_TARGETS) - 1
- pos = min(maxp, self.get('depth_level', 2))
fee_rate = self.depth_to_fee(pos)
else:
+ pos = self.get_fee_level()
maxp = len(FEE_ETA_TARGETS) - 1
- pos = min(maxp, self.get('fee_level', 2))
fee_rate = self.eta_to_fee(pos)
else:
fee_rate = self.fee_per_kb()
pos = self.static_fee_index(fee_rate)
- maxp= 9
+ maxp = 9
return maxp, pos, fee_rate
@@ -398,9 +406,9 @@ class SimpleConfig(PrintError):
"""
if self.is_dynfee():
if self.use_mempool_fees():
- fee_rate = self.depth_to_fee(self.get('depth_level', 2))
+ fee_rate = self.depth_to_fee(self.get_depth_level())
else:
- fee_rate = self.eta_to_fee(self.get('fee_level', 2))
+ fee_rate = self.eta_to_fee(self.get_fee_level())
else:
fee_rate = self.get('fee_per_kb', self.max_fee_rate()/2)
return fee_rate