From 02232b227eda25037560e20e1470ce8a07b74eb5 Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 12 May 2025 10:00:38 +0200 Subject: [PATCH 1/5] fix IndexError if self.channel_ids is empty --- electrum/gui/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electrum/gui/text.py b/electrum/gui/text.py index c66dc3910..17c506b9c 100644 --- a/electrum/gui/text.py +++ b/electrum/gui/text.py @@ -524,7 +524,7 @@ class ElectrumGui(BaseElectrumGui, EventListener): pass def run_channels_tab(self, c): - if c == ord("\n"): + if c == ord("\n") and self.channel_ids: out = self.run_popup('Channel Details', ['Short channel ID:', self.channel_ids[self.pos]]) def run_banner_tab(self, c): From b0fd126e1bf3ec9f4030ebc0ace0e58a665ce8d0 Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 12 May 2025 10:08:52 +0200 Subject: [PATCH 2/5] fix: exception if payment amount is not set if payment amount is not set and the user tried to pay, the application would crash. This shows a message instead. Also uses show_message instead of show_error, as show_error doesn't exist. --- electrum/gui/text.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/electrum/gui/text.py b/electrum/gui/text.py index 17c506b9c..2e9ddb827 100644 --- a/electrum/gui/text.py +++ b/electrum/gui/text.py @@ -625,10 +625,13 @@ class ElectrumGui(BaseElectrumGui, EventListener): if amount_sat: invoice.set_amount_msat(int(amount_sat * 1000)) else: - self.show_error(_('No amount')) - return + self.show_message(_('No amount')) + return None elif is_address(self.str_recipient): amount_sat = self.parse_amount(self.str_amount) + if not amount_sat: + self.show_message(_('No amount')) + return None scriptpubkey = address_to_script(self.str_recipient) outputs = [PartialTxOutput(scriptpubkey=scriptpubkey, value=amount_sat)] invoice = self.wallet.create_invoice( @@ -638,7 +641,7 @@ class ElectrumGui(BaseElectrumGui, EventListener): URI=None) else: self.show_message(_('Invalid Bitcoin address')) - return + return None return invoice def do_save_invoice(self): From bfe895fc3ec9596794ac5a4240a961a798e504bc Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 12 May 2025 10:17:30 +0200 Subject: [PATCH 3/5] remove unused imports, fix type hint --- electrum/gui/text.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/electrum/gui/text.py b/electrum/gui/text.py index 2e9ddb827..da398fdff 100644 --- a/electrum/gui/text.py +++ b/electrum/gui/text.py @@ -13,12 +13,11 @@ try: except ImportError: # only use vendored lib as fallback, to allow Linux distros to bring their own from electrum._vendor import pyperclip -import electrum from electrum.gui import BaseElectrumGui from electrum.bip21 import parse_bip21_URI -from electrum.util import format_satoshis, format_time +from electrum.util import format_time from electrum.util import EventListener, event_listener -from electrum.bitcoin import is_address, address_to_script, COIN +from electrum.bitcoin import is_address, address_to_script from electrum.transaction import PartialTxOutput from electrum.wallet import Wallet, Abstract_Wallet from electrum.wallet_db import WalletDB @@ -87,7 +86,7 @@ class ElectrumGui(BaseElectrumGui, EventListener): curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.halfdelay(1) - self.stdscr.keypad(1) + self.stdscr.keypad(True) self.stdscr.border(0) self.maxy, self.maxx = self.stdscr.getmaxyx() self.set_cursor(0) @@ -549,7 +548,7 @@ class ElectrumGui(BaseElectrumGui, EventListener): finally: tty.setcbreak(sys.stdin) curses.nocbreak() - self.stdscr.keypad(0) + self.stdscr.keypad(False) curses.echo() curses.endwin() From 6e21dac387529cb45cd071e30107632410d92440 Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 12 May 2025 10:51:19 +0200 Subject: [PATCH 4/5] fix: tui contacts edit label and delete button the edit label button did crash the application because get_string returned bytes instead of a string. The delete button was not implemented but shown in the tui. --- electrum/gui/text.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/electrum/gui/text.py b/electrum/gui/text.py index da398fdff..4fa602ea7 100644 --- a/electrum/gui/text.py +++ b/electrum/gui/text.py @@ -136,11 +136,11 @@ class ElectrumGui(BaseElectrumGui, EventListener): def verify_seed(self): pass - def get_string(self, y, x): + def get_string(self, y, x) -> str: self.set_cursor(1) curses.echo() self.stdscr.addstr(y, x, " "*20, curses.A_REVERSE) - s = self.stdscr.getstr(y,x) + s = self.stdscr.getstr(y,x).decode() curses.noecho() self.set_cursor(0) return s @@ -514,7 +514,10 @@ class ElectrumGui(BaseElectrumGui, EventListener): elif out == "Edit label": s = self.get_string(6 + self.pos, 18) if s: - self.wallet.set_label(key, s) + self.contacts[key] = ('address', s) + elif out == "Delete": + self.contacts.pop(key) + self.pos = 0 def run_addresses_tab(self, c): pass From 5bfddad67c88bc74196742e16e6391a0ad00e87b Mon Sep 17 00:00:00 2001 From: f321x Date: Mon, 12 May 2025 10:53:12 +0200 Subject: [PATCH 5/5] use daemon.load_wallet instead of constructing manually --- electrum/gui/text.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/electrum/gui/text.py b/electrum/gui/text.py index 4fa602ea7..861e5e1c5 100644 --- a/electrum/gui/text.py +++ b/electrum/gui/text.py @@ -63,15 +63,14 @@ class ElectrumGui(BaseElectrumGui, EventListener): BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins) self.network = daemon.network storage = WalletStorage(config.get_wallet_path(use_gui_last_wallet=True)) + password = None if not storage.file_exists(): print("Wallet not found. try 'electrum create'") exit() if storage.is_encrypted(): password = getpass.getpass('Password:', stream=None) - storage.decrypt(password) - db = WalletDB(storage.read(), storage=storage, upgrade=True) - self.wallet = Wallet(db, config=config) # type: Optional[Abstract_Wallet] - self.wallet.start_network(self.network) + del storage + self.wallet = self.daemon.load_wallet(config.get_wallet_path(use_gui_last_wallet=True), password) self.contacts = self.wallet.contacts locale.setlocale(locale.LC_ALL, '')