commit 69de3b94db5594ddff36db8c926d787b45baa92e
parent ca1046bce2c8d57c03c7803fab0e14b7c119b2c6
Author: SomberNight <somber.night@protonmail.com>
Date: Fri, 24 Apr 2020 17:17:12 +0200
config: "serverfingerprint" key requires "server" key
follow-up prev
Diffstat:
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/electrum/gui/qt/network_dialog.py b/electrum/gui/qt/network_dialog.py
@@ -26,7 +26,7 @@
import socket
import time
from enum import IntEnum
-from typing import Tuple
+from typing import Tuple, TYPE_CHECKING
from PyQt5.QtCore import Qt, pyqtSignal, QThread
from PyQt5.QtWidgets import (QTreeWidget, QTreeWidgetItem, QMenu, QGridLayout, QComboBox,
@@ -43,6 +43,9 @@ from electrum.logging import get_logger
from .util import (Buttons, CloseButton, HelpButton, read_QIcon, char_width_in_lineedit,
PasswordLineEdit)
+if TYPE_CHECKING:
+ from electrum.simple_config import SimpleConfig
+
_logger = get_logger(__name__)
@@ -209,7 +212,7 @@ class ServerListWidget(QTreeWidget):
class NetworkChoiceLayout(object):
- def __init__(self, network: Network, config, wizard=False):
+ def __init__(self, network: Network, config: 'SimpleConfig', wizard=False):
self.network = network
self.config = config
self.tor_proxy = None
diff --git a/electrum/simple_config.py b/electrum/simple_config.py
@@ -88,6 +88,8 @@ class SimpleConfig(Logger):
# avoid new config getting upgraded
self.user_config = {'config_version': FINAL_CONFIG_VERSION}
+ self._not_modifiable_keys = set()
+
# config "upgrade" - CLI options
self.rename_config_keys(
self.cmdline_options, {'auto_cycle': 'auto_connect'}, True)
@@ -96,6 +98,8 @@ class SimpleConfig(Logger):
if self.requires_upgrade():
self.upgrade()
+ self._check_dependent_keys()
+
def electrum_path(self):
# Read electrum_path from command line
# Otherwise use the user's default data directory.
@@ -159,6 +163,12 @@ class SimpleConfig(Logger):
out = self.user_config.get(key, default)
return out
+ def _check_dependent_keys(self) -> None:
+ if self.get('serverfingerprint'):
+ if not self.get('server'):
+ raise Exception("config key 'serverfingerprint' requires 'server' to also be set")
+ self.make_key_not_modifiable('server')
+
def requires_upgrade(self):
return self.get_config_version() < FINAL_CONFIG_VERSION
@@ -221,8 +231,12 @@ class SimpleConfig(Logger):
.format(config_version, FINAL_CONFIG_VERSION))
return config_version
- def is_modifiable(self, key):
- return key not in self.cmdline_options
+ def is_modifiable(self, key) -> bool:
+ return (key not in self.cmdline_options
+ and key not in self._not_modifiable_keys)
+
+ def make_key_not_modifiable(self, key) -> None:
+ self._not_modifiable_keys.add(key)
def save_user_config(self):
if self.get('forget_config'):