simple_config: factor out self.decimal_point and self.get_decimal_point() in favor of self.BTC_AMOUNTS_DECIMAL_POINT
What changed, and why it matters
This is a routine internal code cleanup in Electrum's settings module. It replaces an old shortcut property (`self.decimal_point`) and its getter method with direct use of a configuration variable (`self.BTC_AMOUNTS_DECIMAL_POINT`). The behavior is unchanged; there is no security issue visible in the commit.
No action required. This is a benign refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors SimpleConfig to remove the decimal_point instance attribute and the get_decimal_point() method, replacing all callers with config.BTC_AMOUNTS_DECIMAL_POINT. The same validation and defaulting logic for unknown base units is preserved. All call sites in QML, Qt GUI, text GUI, payment identifier parsing, and hardware-wallet plugins (BitBox02, Trezor) are updated to use the config variable directly. No functional or security-relevant change is introduced.
Changed components
electrum/simple_config.pyelectrum/gui/qml/qeconfig.pyelectrum/gui/qt/main_window.pyelectrum/gui/qt/settings_dialog.pyelectrum/gui/text.pyelectrum/payment_identifier.pyelectrum/plugins/bitbox02/bitbox02.pyelectrum/plugins/trezor/trezor.pyInspect captured patch +15 / −21
diff --git a/electrum/gui/qml/qeconfig.py b/electrum/gui/qml/qeconfig.py
index 9609289..caa1509 100644
--- a/electrum/gui/qml/qeconfig.py
+++ b/electrum/gui/qml/qeconfig.py
@@ -387,4 +387,4 @@ class QEConfig(AuthMixin, QObject):
@pyqtSlot('quint64', result=float)
def satsToUnits(self, satoshis):
- return satoshis / pow(10, self.config.decimal_point)
+ return satoshis / pow(10, self.config.BTC_AMOUNTS_DECIMAL_POINT)
diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py
index ff860f3..f7c1ec9 100644
--- a/electrum/gui/qt/main_window.py
+++ b/electrum/gui/qt/main_window.py
@@ -1005,7 +1005,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
return self.config.format_fee_rate(fee_rate)
def get_decimal_point(self):
- return self.config.get_decimal_point()
+ return self.config.BTC_AMOUNTS_DECIMAL_POINT
def base_unit(self):
return self.config.get_base_unit()
diff --git a/electrum/gui/qt/settings_dialog.py b/electrum/gui/qt/settings_dialog.py
index ca7fba8..43cfd0d 100644
--- a/electrum/gui/qt/settings_dialog.py
+++ b/electrum/gui/qt/settings_dialog.py
@@ -97,7 +97,7 @@ class SettingsDialog(QDialog, QtEventListener):
nz_label = HelpLabel.from_configvar(self.config.cv.BTC_AMOUNTS_FORCE_NZEROS_AFTER_DECIMAL_POINT)
nz = QSpinBox()
nz.setMinimum(0)
- nz.setMaximum(self.config.decimal_point)
+ nz.setMaximum(self.config.BTC_AMOUNTS_DECIMAL_POINT)
nz.setValue(self.config.num_zeros)
if not self.config.cv.BTC_AMOUNTS_FORCE_NZEROS_AFTER_DECIMAL_POINT.is_modifiable():
for w in [nz, nz_label]: w.setEnabled(False)
@@ -205,7 +205,7 @@ class SettingsDialog(QDialog, QtEventListener):
if self.config.get_base_unit() == unit_result:
return
self.config.set_base_unit(unit_result)
- nz.setMaximum(self.config.decimal_point)
+ nz.setMaximum(self.config.BTC_AMOUNTS_DECIMAL_POINT)
self.app.refresh_tabs_signal.emit()
self.app.update_status_signal.emit()
self.app.refresh_amount_edits_signal.emit()
diff --git a/electrum/gui/text.py b/electrum/gui/text.py
index 6417034..32da41c 100644
--- a/electrum/gui/text.py
+++ b/electrum/gui/text.py
@@ -615,7 +615,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
x = Decimal(text)
except Exception:
return None
- power = pow(10, self.config.get_decimal_point())
+ power = pow(10, self.config.BTC_AMOUNTS_DECIMAL_POINT)
return int(power * x)
def read_invoice(self):
diff --git a/electrum/payment_identifier.py b/electrum/payment_identifier.py
index f7f0b53..a71b1bf 100644
--- a/electrum/payment_identifier.py
+++ b/electrum/payment_identifier.py
@@ -557,7 +557,7 @@ class PaymentIdentifier(Logger):
raise Exception("Amount is empty")
if parse_max_spend(x):
return x
- p = pow(10, self.config.get_decimal_point())
+ p = pow(10, self.config.BTC_AMOUNTS_DECIMAL_POINT)
try:
return int(p * Decimal(x))
except InvalidOperation:
diff --git a/electrum/plugins/bitbox02/bitbox02.py b/electrum/plugins/bitbox02/bitbox02.py
index 2e0c5ec..ead4d8d 100644
--- a/electrum/plugins/bitbox02/bitbox02.py
+++ b/electrum/plugins/bitbox02/bitbox02.py
@@ -518,7 +518,7 @@ class BitBox02Client(HardwareClientBase):
format_unit = bitbox02.btc.BTCSignInitRequest.FormatUnit.DEFAULT
# Base unit is configured to be "sat":
- if self.config.get_decimal_point() == 0:
+ if self.config.BTC_AMOUNTS_DECIMAL_POINT == 0:
format_unit = bitbox02.btc.BTCSignInitRequest.FormatUnit.SAT
sigs = self.bitbox02_device.btc_sign(
diff --git a/electrum/plugins/trezor/trezor.py b/electrum/plugins/trezor/trezor.py
index 456cd25..9487707 100644
--- a/electrum/plugins/trezor/trezor.py
+++ b/electrum/plugins/trezor/trezor.py
@@ -324,11 +324,11 @@ class TrezorPlugin(HW_PluginBase):
raise ValueError('unexpected txin type: {}'.format(electrum_txin_type))
def get_trezor_amount_unit(self):
- if self.config.decimal_point == 0:
+ if self.config.BTC_AMOUNTS_DECIMAL_POINT == 0:
return AmountUnit.SATOSHI
- elif self.config.decimal_point == 2:
+ elif self.config.BTC_AMOUNTS_DECIMAL_POINT == 2:
return AmountUnit.MICROBITCOIN
- elif self.config.decimal_point == 5:
+ elif self.config.BTC_AMOUNTS_DECIMAL_POINT == 5:
return AmountUnit.MILLIBITCOIN
else:
return AmountUnit.BITCOIN
diff --git a/electrum/simple_config.py b/electrum/simple_config.py
index 93621c6..32638bd 100644
--- a/electrum/simple_config.py
+++ b/electrum/simple_config.py
@@ -217,12 +217,10 @@ class SimpleConfig(Logger):
self._check_dependent_keys()
# units and formatting
- # FIXME is this duplication (dp, nz, post_sat, thou_sep) due to performance reasons??
- self.decimal_point = self.BTC_AMOUNTS_DECIMAL_POINT
try:
- decimal_point_to_base_unit_name(self.decimal_point)
+ decimal_point_to_base_unit_name(self.BTC_AMOUNTS_DECIMAL_POINT)
except UnknownBaseUnit:
- self.decimal_point = DECIMAL_POINT_DEFAULT
+ self.BTC_AMOUNTS_DECIMAL_POINT = DECIMAL_POINT_DEFAULT
self.num_zeros = self.BTC_AMOUNTS_FORCE_NZEROS_AFTER_DECIMAL_POINT
self.amt_precision_post_satoshi = self.BTC_AMOUNTS_PREC_POST_SAT
self.amt_add_thousands_sep = self.BTC_AMOUNTS_ADD_THOUSANDS_SEP
@@ -530,7 +528,7 @@ class SimpleConfig(Logger):
return format_satoshis(
amount_sat,
num_zeros=self.num_zeros,
- decimal_point=self.decimal_point,
+ decimal_point=self.BTC_AMOUNTS_DECIMAL_POINT,
is_diff=is_diff,
whitespaces=whitespaces,
precision=precision,
@@ -545,15 +543,11 @@ class SimpleConfig(Logger):
return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + f" {util.UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE}"
def get_base_unit(self):
- return decimal_point_to_base_unit_name(self.decimal_point)
+ return decimal_point_to_base_unit_name(self.BTC_AMOUNTS_DECIMAL_POINT)
def set_base_unit(self, unit):
assert unit in base_units.keys()
- self.decimal_point = base_unit_name_to_decimal_point(unit)
- self.BTC_AMOUNTS_DECIMAL_POINT = self.decimal_point
-
- def get_decimal_point(self):
- return self.decimal_point
+ self.BTC_AMOUNTS_DECIMAL_POINT = base_unit_name_to_decimal_point(unit)
def get_nostr_relays(self) -> Sequence[str]:
relays = []
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.