Skip to content

Commit

Permalink
move a bunch of same-line comments to previous line
Browse files Browse the repository at this point in the history
This improves the code formatting by black
  • Loading branch information
PiRK committed Jan 13, 2023
1 parent 7b4e5cd commit 3101135
Show file tree
Hide file tree
Showing 21 changed files with 184 additions and 168 deletions.
3 changes: 2 additions & 1 deletion contrib/build-wine/deterministic.spec
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ datas = [
datas += collect_data_files('trezorlib')
datas += collect_data_files('btchip')
datas += collect_data_files('keepkeylib')
datas += collect_data_files('mnemonic') # wordlists used by keepkeylib from lib mnemonic
# wordlists used by keepkeylib from lib mnemonic
datas += collect_data_files('mnemonic')

# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports
a = Analysis([home+'electrum-abc',
Expand Down
3 changes: 2 additions & 1 deletion contrib/osx/osx.spec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ datas = [
datas += collect_data_files('trezorlib')
datas += collect_data_files('btchip')
datas += collect_data_files('keepkeylib')
datas += collect_data_files('mnemonic') # wordlists used by keepkeylib from lib mnemonic
# wordlists used by keepkeylib from lib mnemonic
datas += collect_data_files('mnemonic')


# Add libusb so Trezor will work
Expand Down
6 changes: 4 additions & 2 deletions electrumabc/bitcoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,8 @@ def hash160_to_b58_address(h160, addrtype):

def b58_address_to_hash160(addr):
addr = to_bytes(addr, "ascii")
_bytes = base_decode(addr, 25, base=58) # will raise ValueError on bad characters
# will raise ValueError on bad characters
_bytes = base_decode(addr, 25, base=58)
return _bytes[0], _bytes[1:21]


Expand Down Expand Up @@ -697,10 +698,11 @@ def deserialize_privkey(key, *, net=None):
return "p2pkh", minikey_to_private_key(key), False
elif vch:
txin_type = inv_dict(SCRIPT_TYPES)[vch[0] - net.WIF_PREFIX]
# We do it this way because eg iOS runs with PYTHONOPTIMIZE=1
if len(vch) not in (
33,
34,
): # We do it this way because eg iOS runs with PYTHONOPTIMIZE=1
):
raise AssertionError("Key {} has invalid length".format(key))
compressed = len(vch) == 34
if compressed and vch[33] != 0x1:
Expand Down
5 changes: 2 additions & 3 deletions electrumabc/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,8 @@ def _save(data: List[Contact], v1_too: bool = False) -> dict:
return ret

def save(self):
d = self._save(
self.data, v1_too=False
) # Note: set v1_too = True if you want to save to v1 so older EC wallets can also see the updated contacts
# Note: set v1_too = True if you want to save to v1 so older EC wallets can also see the updated contacts
d = self._save(self.data, v1_too=False)
for k, v in d.items():
self.storage.put(k, v) # "contacts2", "contacts" are the two expected keys

Expand Down
19 changes: 10 additions & 9 deletions electrumabc/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,8 @@ def get_instance():
return Network.INSTANCE

def callback_listener_count(self, event):
return len(
self.callbacks.get(event, [])
) # we intentionally don't take any locks here as a performance optimization
# we intentionally don't take any locks here as a performance optimization
return len(self.callbacks.get(event, []))

def register_callback(self, callback, events):
with self.lock:
Expand Down Expand Up @@ -426,14 +425,16 @@ def _legacy_callback_detector_and_mogrifier(self, event, *args):
# electron cash plugins that still use this event, and we need
# to keep this hack here so they don't break on new EC
# versions. "Technical debt" :)
self.trigger_callback(
"updated"
) # we will re-enter this function with event == 'updated' (triggering the warning in the elif clause below)
#
# we will re-enter this function with event == 'updated' (triggering the
# warning in the elif clause below)
self.trigger_callback("updated")
elif event == "verified2" and "verified" in self.callbacks:
# pop off the 'wallet' arg as the old bad 'verified' callback lacked it.
self.trigger_callback(
"verified", args[1:]
) # we will re-enter this function with event == 'verified' (triggering the warning in the elif clause below)
#
# we will re-enter this function with event == 'verified' (triggering the
# warning in the elif clause below)
self.trigger_callback("verified", args[1:])
elif event in self._deprecated_alternatives:
# If we see updated or verified events come through here, warn:
# deprecated. Note that the above 2 clauses will also trigger this
Expand Down
37 changes: 23 additions & 14 deletions electrumabc/slp/slp.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def __new__(cls, script):
)
script = bytes(script) if isinstance(script, bytearray) else script
self = super(__class__, cls).__new__(cls, script)
self.message = cls._script_message_cache.get(
self.script
) # will return a valid object or None
# will return a valid object or None
self.message = cls._script_message_cache.get(self.script)
if self.message is None:
self.message = Message.parse(self) # raises on parse error
# raises on parse error
self.message = Message.parse(self)
return self

@classmethod
Expand Down Expand Up @@ -812,21 +812,28 @@ def save(self):
def clear(self):
"""Caller should hold locks"""
self.need_rebuild = False
self.validity = dict() # txid -> int
self.txo_byaddr = dict() # [address] -> set of "prevouthash:n" for that address
self.token_quantities = (
dict()
) # [token_id_hex] -> dict of ["prevouthash:n"] -> qty (-1 for qty indicates minting baton)
self.txo_token_id = dict() # ["prevouthash:n"] -> "token_id_hex"

# txid -> int
self.validity = dict()

# [address] -> set of "prevouthash:n" for that address
self.txo_byaddr = dict()

# [token_id_hex] -> dict of ["prevouthash:n"] -> qty (-1 for qty indicates
# minting baton)
self.token_quantities = dict()

# ["prevouthash:n"] -> "token_id_hex"
self.txo_token_id = dict()

def rebuild(self):
"""This takes wallet.lock"""
with self.wallet.lock:
self.clear()
for txid, tx in self.wallet.transactions.items():
self.add_tx(
txid, Transaction(tx.raw)
) # we take a copy of the transaction so prevent storing deserialized tx in wallet.transactions dict
# we take a copy of the transaction so prevent storing deserialized tx
# in wallet.transactions dict
self.add_tx(txid, Transaction(tx.raw))

# --- GETTERS / SETTERS from wallet
def token_info_for_txo(self, txo) -> Tuple[str, int]:
Expand All @@ -838,10 +845,12 @@ def token_info_for_txo(self, txo) -> Tuple[str, int]:
"""
token_id_hex = self.txo_token_id.get(txo)
if token_id_hex is not None:
# we want this to raise KeyError here if missing as it indicates a
# programming error
return (
token_id_hex,
self.token_quantities[token_id_hex][txo],
) # we want this to raise KeyError here if missing as it indicates a programming error
)

def txo_has_token(self, txo) -> bool:
"""Takes no locks."""
Expand Down
5 changes: 2 additions & 3 deletions electrumabc/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,8 @@ def got_tx_info(r):
"block_height"
) # indicate to other thread we got the block_height reply from network
try:
confs = r.get("result").get(
"confirmations", 0
) # will raise of error reply
# will raise of error reply
confs = r.get("result").get("confirmations", 0)
if confs and lh:
# the whole point.. was to get this piece of data.. the block_height
eph["block_height"] = bh = lh - confs + 1
Expand Down
5 changes: 2 additions & 3 deletions electrumabc/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1275,9 +1275,8 @@ def can_do_work():
# .txid()) which ensures the tx from the server
# is not junk.
assert prevout_hash == tx.txid(), "txid mismatch"
Transaction.tx_cache_put(
tx, prevout_hash
) # will cache a copy
# will cache a copy
Transaction.tx_cache_put(tx, prevout_hash)
except Exception as e:
self.print_error(
f"{me.name}: Error retrieving txid",
Expand Down
12 changes: 6 additions & 6 deletions electrumabc_gui/qt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,9 +1159,9 @@ def main(self):
return
signal.signal(signal.SIGINT, lambda signum, frame: self.shutdown_signal.emit())

self.app.setQuitOnLastWindowClosed(
False
) # we want to control this in our slot (since we support non-visible, backgrounded windows via the systray show/hide facility)
# we want to control this in our slot (since we support non-visible,
# backgrounded windows via the systray show/hide facility)
self.app.setQuitOnLastWindowClosed(False)
self.app.lastWindowClosed.connect(self._quit_after_last_window)

def clean_up():
Expand All @@ -1178,9 +1178,9 @@ def clean_up():

self.app.aboutToQuit.connect(clean_up)

ExceptionHook(
self.config
) # This wouldn't work anyway unless the app event loop is active, so we must install it once here and no earlier.
# This wouldn't work anyway unless the app event loop is active, so we must
# install it once here and no earlier.
ExceptionHook(self.config)
# main loop
self.app.exec_()
# on some platforms the exec_ call may not return, so use clean_up()
44 changes: 29 additions & 15 deletions electrumabc_gui/qt/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,10 +1166,12 @@ def timer_actions(self):
# Note this runs in the GUI thread

if self.need_update.is_set():
self._update_wallet() # will clear flag when it runs. (also clears labels_need_update as well)
# will clear flag when it runs. (also clears labels_need_update as well)
self._update_wallet()

if self.labels_need_update.is_set():
self._update_labels() # will clear flag when it runs.
# will clear flag when it runs.
self._update_labels()

# resolve aliases
# FIXME this is a blocking network call that has a timeout of 5 sec
Expand All @@ -1179,7 +1181,8 @@ def timer_actions(self):
self.do_update_fee()
self.require_fee_update = False

# hook for other classes to be called here. For example the tx_update_mgr is called here (see TxUpdateMgr.do_check).
# hook for other classes to be called here. For example the tx_update_mgr is
# called here (see TxUpdateMgr.do_check).
self.on_timer_signal.emit()

def format_amount(self, x, is_diff=False, whitespaces=False):
Expand Down Expand Up @@ -1338,7 +1341,8 @@ def update_status(self):
run_hook("window_update_status", self)

def update_wallet(self):
self.need_update.set() # will enqueue an _update_wallet() call in at most 0.5 seconds from now.
# will enqueue an _update_wallet() call in at most 0.5 seconds from now.
self.need_update.set()

def _update_wallet(self):
"""Called by self.timer_actions every 0.5 secs if need_update flag is set.
Expand All @@ -1364,15 +1368,22 @@ def update_tabs(self):
self.contact_list.update()
self.invoice_list.update()
self.update_completions()
self.history_updated_signal.emit() # inform things like address_dialog that there's a new history, also clears self.tx_update_mgr.verif_q
# inform things like address_dialog that there's a new history, also clears
# self.tx_update_mgr.verif_q
self.history_updated_signal.emit()
self.need_update.clear() # clear flag
if self.labels_need_update.is_set():
# if flag was set, might as well declare the labels updated since they necessarily were due to a full update.
self.labels_updated_signal.emit() # just in case client code was waiting for this signal to proceed.
self.labels_need_update.clear() # clear flag
# if flag was set, might as well declare the labels updated since they
# necessarily were due to a full update.
#
# just in case client code was waiting for this signal to proceed.
self.labels_updated_signal.emit()
# clear flag
self.labels_need_update.clear()

def update_labels(self):
self.labels_need_update.set() # will enqueue an _update_labels() call in at most 0.5 seconds from now
# will enqueue an _update_labels() call in at most 0.5 seconds from now
self.labels_need_update.set()

@rate_limited(1.0)
def _update_labels(self):
Expand All @@ -1384,7 +1395,8 @@ def _update_labels(self):
self.utxo_list.update_labels()
self.update_completions()
self.labels_updated_signal.emit()
self.labels_need_update.clear() # clear flag
# clear flag
self.labels_need_update.clear()

def create_history_tab(self):
history_list = HistoryList(self)
Expand Down Expand Up @@ -1664,9 +1676,9 @@ def save_payment_request(self):
self.wallet.add_payment_request(req, self.config)
self.sign_payment_request(self.receive_address)
self.request_list.update()
self.request_list.select_item_by_address(
req.get("address")
) # when adding items to the view the current selection may not reflect what's in the UI. Make sure it's selected.
# when adding items to the view the current selection may not reflect what's in
# the UI. Make sure it's selected.
self.request_list.select_item_by_address(req.get("address"))
self.address_list.update()
self.save_request_button.setEnabled(False)

Expand Down Expand Up @@ -3818,7 +3830,8 @@ def _on_qr_reader_finished(success: bool, error: str, result):
# else if the user scanned an offline signed tx
try:
result = bh2u(bitcoin.base_decode(result, length=None, base=43))
tx = self.tx_from_text(result) # will show an error dialog on error
# will show an error dialog on error
tx = self.tx_from_text(result)
if not tx:
return
except BaseException as e:
Expand Down Expand Up @@ -4196,7 +4209,8 @@ def on_dialog_closed(*args):
except TypeError:
pass
if thr and thr.is_alive():
thr.join(timeout=1.0) # wait for thread to end for maximal GC mojo
# wait for thread to end for maximal GC mojo
thr.join(timeout=1.0)

def computing_privkeys_slot():
if stop:
Expand Down
10 changes: 4 additions & 6 deletions electrumabc_gui/qt/network_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,13 @@ def hideEvent(slf, e):
grid.addWidget(self.server_host, 3, 1, 1, 2)
grid.addWidget(self.server_port, 3, 3)

self.server_list_label = label = QtWidgets.QLabel(
""
) # will get set by self.update()
# will get set by self.update()
self.server_list_label = label = QtWidgets.QLabel("")
grid.addWidget(label, 4, 0, 1, 5)
self.servers_list = ServerListWidget(self)
grid.addWidget(self.servers_list, 5, 0, 1, 5)
self.legend_label = label = WWLabel(
""
) # will get populated with the legend by self.update()
# will get populated with the legend by self.update()
self.legend_label = label = WWLabel("")
label.setTextInteractionFlags(
label.textInteractionFlags() & (~Qt.TextSelectableByMouse)
) # disable text selection by mouse here
Expand Down
11 changes: 5 additions & 6 deletions electrumabc_gui/qt/seed_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,11 @@ def __init__(
opt_button = EnterButton(_("Options"), self.seed_options)
hbox.addWidget(opt_button)
self.addLayout(hbox)
grid_maybe = (
QtWidgets.QGridLayout()
) # may not be used if none of the below if expressions evaluates to true, that's ok.
grid_maybe.setColumnStretch(
1, 1
) # we want the right-hand column to take up as much space as it needs.
# may not be used if none of the below if expressions evaluates to true,
# that's ok.
grid_maybe = QtWidgets.QGridLayout()
# we want the right-hand column to take up as much space as it needs.
grid_maybe.setColumnStretch(1, 1)
grid_row = 0
if seed_type:
seed_type_text = mnemo.format_seed_type_name_for_ui(seed_type)
Expand Down
Loading

0 comments on commit 3101135

Please sign in to comment.