From 48f5ddf4fdeadfb2b3aeb288fca12dfa039e54f0 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Wed, 27 May 2020 15:50:08 +0100 Subject: [PATCH 1/2] QValidator port number restriction only for ports Prior to this fix, the settings which were integers were all restricted to numbers <= 65535, but this is not acceptable for the tx_fees setting which can be sats per kilobyte. Note that several other integer inputs are left without any specific validation; this change is considered important because there will be use cases where a large sat/kB is needed. --- scripts/joinmarket-qt.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index 3b88272..d837392 100755 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -271,7 +271,13 @@ class SettingsTab(QDialog): else: qt = QLineEdit(val) if t == int: - qt.setValidator(QIntValidator(0, 65535)) + if name in ["rpc_port", "socks5_port", "daemon_port"]: + qt.setValidator(QIntValidator(0, 65535)) + elif name == "tx_fees": + # must account for both tx_fees settings type, + # and we set upper limit well above default absurd + # check just in case a high value is needed: + qt.setValidator(QIntValidator(1, 1000000)) else: qt = QLineEdit(val) label = 'Testnet' if name == 'network' else name From 3cd54cb4c33b6d752c88d98e94ce392c1bd1f289 Mon Sep 17 00:00:00 2001 From: Adam Gibson Date: Tue, 2 Jun 2020 15:55:43 +0100 Subject: [PATCH 2/2] Adds JMIntValidator to ensure exact integer range Makes BitcoinSatValidator a derived class with a specific range. Makes all port fields respond correctly to correct or incorrect entries of port numbers. Changes badly named 'qt' variable to 'sf' in getSettingsFields. --- scripts/joinmarket-qt.py | 21 +++++++++++---------- scripts/qtsupport.py | 28 +++++++++++++++++----------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/scripts/joinmarket-qt.py b/scripts/joinmarket-qt.py index d837392..e2419fc 100755 --- a/scripts/joinmarket-qt.py +++ b/scripts/joinmarket-qt.py @@ -79,7 +79,7 @@ from jmclient import load_program_config, get_network, update_persist_config,\ from qtsupport import ScheduleWizard, TumbleRestartWizard, config_tips,\ config_types, QtHandler, XStream, Buttons, OkButton, CancelButton,\ PasswordDialog, MyTreeWidget, JMQtMessageBox, BLUE_FG,\ - donation_more_message, BitcoinAmountEdit + donation_more_message, BitcoinAmountEdit, JMIntValidator from twisted.internet import task @@ -261,27 +261,28 @@ class SettingsTab(QDialog): if name in config_types: t = config_types[name] if t == bool: - qt = QCheckBox() + sf = QCheckBox() if val == 'testnet' or val.lower() == 'true': - qt.setChecked(True) + sf.setChecked(True) elif t == 'amount': - qt = BitcoinAmountEdit(val) + sf = BitcoinAmountEdit(val) elif not t: continue else: - qt = QLineEdit(val) + sf = QLineEdit(val) if t == int: - if name in ["rpc_port", "socks5_port", "daemon_port"]: - qt.setValidator(QIntValidator(0, 65535)) + if name in ["port", "rpc_port", "socks5_port", + "daemon_port"]: + sf.setValidator(JMIntValidator(1, 65535)) elif name == "tx_fees": # must account for both tx_fees settings type, # and we set upper limit well above default absurd # check just in case a high value is needed: - qt.setValidator(QIntValidator(1, 1000000)) + sf.setValidator(JMIntValidator(1, 1000000)) else: - qt = QLineEdit(val) + sf = QLineEdit(val) label = 'Testnet' if name == 'network' else name - results.append((QLabel(label), qt)) + results.append((QLabel(label), sf)) return results class SpendStateMgr(object): diff --git a/scripts/qtsupport.py b/scripts/qtsupport.py index 583a8e5..95d95b5 100644 --- a/scripts/qtsupport.py +++ b/scripts/qtsupport.py @@ -522,6 +522,22 @@ class MyTreeWidget(QTreeWidget): # lambda: checkAddress(self, wdgts[0][1].text())) # self.setLayout(layout) +class JMIntValidator(QIntValidator): + def __init__(self, minval, maxval): + super().__init__(minval, maxval) + self.minval = minval + self.maxval = maxval + self.allowed = set(string.digits) + + def validate(self, arg__1, arg__2): + if not arg__1: + return QValidator.Intermediate + if not set(arg__1) <= self.allowed: + return QValidator.Invalid + # above guarantees integer + if not (int(arg__1) <= self.maxval and int(arg__1) >= self.minval): + return QValidator.Invalid + return super().validate(arg__1, arg__2) class BitcoinAmountBTCValidator(QDoubleValidator): @@ -540,20 +556,10 @@ class BitcoinAmountBTCValidator(QDoubleValidator): return super().validate(arg__1, arg__2) -class BitcoinAmountSatValidator(QIntValidator): +class BitcoinAmountSatValidator(JMIntValidator): def __init__(self): super().__init__(0, 2147483647) - self.setLocale(QtCore.QLocale.c()) - self.allowed = set(string.digits) - - def validate(self, arg__1, arg__2): - if not arg__1: - return QValidator.Intermediate - if not set(arg__1) <= self.allowed: - return QValidator.Invalid - return super().validate(arg__1, arg__2) - class BitcoinAmountEdit(QWidget):