Commit Graph

89 Commits

Author SHA1 Message Date
SomberNight
dbd2e56e85 qt gui: more resilient startup
Example log:
app tries to auto-open to wallet "test_segwit_2", which has too new db version,
then user manually tries to open wallet "test_segwit_3" instead,
which opens okay but - immediately after - the process shuts down (due to line 383 -> line 458).
```
$ ./run_electrum -v --testnet -o
  0.59 | I | simple_config.SimpleConfig | electrum directory /home/user/.electrum/testnet
  0.59 | I | logging | Electrum version: 4.3.4 - https://electrum.org - https://github.com/spesmilo/electrum
  0.59 | I | logging | Python version: 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]. On platform: Linux-5.15.0-58-generic-x86_64-with-glibc2.35
  0.59 | I | logging | Logging to file: /home/user/.electrum/testnet/logs/electrum_log_20230202T151759Z_220451.log
  0.59 | I | logging | Log filters: verbosity '*', verbosity_shortcuts ''
  0.59 | I | p/plugin.Plugins | registering hardware bitbox02: ('hardware', 'bitbox02', 'BitBox02')
  0.59 | I | p/plugin.Plugins | registering hardware coldcard: ('hardware', 'coldcard', 'Coldcard Wallet')
  0.59 | I | p/plugin.Plugins | registering hardware digitalbitbox: ('hardware', 'digitalbitbox', 'Digital Bitbox wallet')
  0.60 | I | p/plugin.Plugins | registering hardware jade: ('hardware', 'jade', 'Jade wallet')
  0.60 | I | p/plugin.Plugins | registering hardware keepkey: ('hardware', 'keepkey', 'KeepKey wallet')
  0.60 | I | p/plugin.Plugins | registering hardware ledger: ('hardware', 'ledger', 'Ledger wallet')
  1.74 | I | p/plugin.Plugins | loaded payserver
  1.74 | I | p/plugin.Plugins | registering hardware safe_t: ('hardware', 'safe_t', 'Safe-T mini wallet')
  1.74 | I | p/plugin.Plugins | registering hardware trezor: ('hardware', 'trezor', 'Trezor wallet')
  1.74 | I | p/plugin.Plugins | registering wallet type ('2fa', 'trustedcoin')
  1.74 | D | util.profiler | Plugins.__init__ 1.1522 sec
  1.74 | I | exchange_rate.FxThread | using exchange CoinGecko
  1.75 | D | util.profiler | Daemon.__init__ 0.0033 sec
  1.75 | I | daemon.Daemon | starting taskgroup.
  1.75 | I | daemon.Daemon | launching GUI: qt
  1.75 | I | gui.qt.ElectrumGui | Qt GUI starting up... Qt=5.15.3, PyQt=5.15.6
  1.75 | I | daemon.CommandsServer | now running and listening. socktype=unix, addr=/home/user/.electrum/testnet/daemon_rpc_socket
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
  2.04 | D | util.profiler | ElectrumGui.__init__ 0.2865 sec
  2.04 | I | storage.WalletStorage | wallet path /home/user/.electrum/testnet/wallets/test_segwit_2
  2.13 | I | storage.WalletStorage | wallet path /home/user/.electrum/testnet/wallets/test_segwit_2
  5.24 | E | gui.qt.ElectrumGui |
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/gui/qt/__init__.py", line 354, in start_new_window
    wallet = self._start_wizard_to_select_or_create_wallet(path)
  File "/home/user/wspace/electrum/electrum/gui/qt/__init__.py", line 401, in _start_wizard_to_select_or_create_wallet
    db = WalletDB(storage.read(), manual_upgrades=False)
  File "/home/user/wspace/electrum/electrum/wallet_db.py", line 72, in __init__
    self.load_data(raw)
  File "/home/user/wspace/electrum/electrum/wallet_db.py", line 102, in load_data
    if not self.requires_upgrade():
  File "/home/user/wspace/electrum/electrum/wallet_db.py", line 153, in requires_upgrade
    return self.get_seed_version() < FINAL_SEED_VERSION
  File "/home/user/wspace/electrum/electrum/json_db.py", line 44, in wrapper
    return func(self, *args, **kwargs)
  File "/home/user/wspace/electrum/electrum/wallet_db.py", line 1035, in get_seed_version
    raise WalletFileException('This version of Electrum is too old to open this wallet.\n'
electrum.util.WalletFileException: This version of Electrum is too old to open this wallet.
(highest supported storage version: 50, version of this file: 51)
  5.35 | I | storage.WalletStorage | wallet path /home/user/.electrum/testnet/wallets/wallet_20
  7.90 | I | storage.WalletStorage | wallet path /home/user/.electrum/testnet/wallets/test_segwit_3
  8.48 | D | util.profiler | WalletDB._load_transactions 0.0517 sec
  8.48 | D | util.profiler | AddressSynchronizer.load_local_history 0.0005 sec
  8.48 | D | util.profiler | AddressSynchronizer.check_history 0.0005 sec
  8.70 | D | util.profiler | AddressList.update 0.0000 sec
  9.00 | D | util.profiler | Deterministic_Wallet.try_detecting_internal_addresses_corruption 0.0223 sec
  9.01 | D | util.profiler | ElectrumWindow.load_wallet 0.0808 sec
  9.01 | I | daemon.Daemon | stop() entered. initiating shutdown
  9.01 | I | gui.qt.ElectrumGui | closing GUI
  9.01 | I | daemon.Daemon | stopping all wallets
  9.04 | I | storage.WalletStorage | saved /home/user/.electrum/testnet/wallets/test_segwit_3
  9.04 | D | util.profiler | WalletDB._write 0.0265 sec
  9.04 | I | daemon.Daemon | stopping network and taskgroup
  9.04 | I | daemon.Daemon | taskgroup stopped.
  9.04 | I | daemon.Daemon | removing lockfile
  9.04 | I | daemon.Daemon | stopped
  9.08 | I | p/plugin.Plugins | stopped
QThread: Destroyed while thread is still running
Aborted (core dumped)
```
2023-02-02 15:25:15 +00:00
SomberNight
f2e3d11014 qt gui __init__: rm deprecated QApplication attr AA_X11InitThreads
From https://doc.qt.io/qt-5/qt.html :
> The following values are deprecated or obsolete:
> Constant              Value   Description
> Qt::AA_X11InitThreads 10      This value is obsolete and has no effect.

We started setting this attribute back when using Qt4,
as a workaround for some threading issues: https://github.com/spesmilo/electrum/pull/2820

However,
- in Qt5 it no longer has any effect,
- the original threading issues were fixed
  in https://github.com/spesmilo/electrum/pull/3326 and https://github.com/spesmilo/electrum/pull/3330
2022-10-14 19:02:23 +00:00
SomberNight
abef454237 qt: better handle unparseable URIs
fixes https://github.com/spesmilo/electrum/issues/7941
2022-08-16 15:27:13 +00:00
SomberNight
2d68350900 qt: (refactor) split "send tab" out from main_window.py 2022-06-30 20:29:08 +02:00
bitromortac
fe2fbbd9b1 add lnurl-pay and lightning address support
* bundles all payment identifiers into handle_payment_identifier
* adds lnurl decoding
* adds lightning address decoding
2022-06-29 16:18:15 +02:00
ThomasV
dbf055de9a EventListener class to handle callbacks
and QtEventListener for Qt
2022-06-22 02:07:46 +02:00
ThomasV
fdee31af05 Qt settings_dialog: use signals
- changes must apply to all windows
 - do not keep reference to the window object
2022-04-29 17:04:16 +02:00
SomberNight
e47e0afa91 commands: add "version_info" cmd
example:
```
$ ./run_electrum -o version_info
{
    "aiohttp.version": "3.8.1",
    "aiorpcx.version": "0.22.1",
    "certifi.version": "2021.10.08",
    "cryptodome.version": null,
    "cryptography.path": "/home/user/.local/lib/python3.8/site-packages/cryptography",
    "cryptography.version": "3.4.6",
    "dnspython.version": "2.2.0",
    "electrum.path": "/home/user/wspace/electrum/electrum",
    "electrum.version": "4.2.1",
    "hidapi.version": "0.11.0.post2",
    "libsecp256k1.path": "/home/user/wspace/electrum/electrum/libsecp256k1.so.0",
    "libusb.path": "libusb-1.0.so",
    "libusb.version": "1.0.23.11397",
    "libzbar.path": "/home/user/wspace/electrum/electrum/libzbar.so.0",
    "pyaes.version": "1.3.0",
    "pyqt.path": "/usr/lib/python3/dist-packages/PyQt5",
    "pyqt.version": "5.14.1",
    "qt.version": "5.12.8"
}
```
2022-04-11 17:40:22 +02:00
SomberNight
419fc6e1c1 gui init: raise GuiImportError instead of sys.exit if dep is missing 2022-04-11 17:40:16 +02:00
SomberNight
8e234f3ccd qt gui: better detection of missing PyQt5 at startup
If I use apt on ubuntu to install python3-pyqt5 and then remove it, it leaves an empty namespace:
```
$ python3
Python 3.8.10 (default, Mar 15 2022, 12:22:08)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt5
>>> import PyQt5.QtGui
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtGui'
>>> PyQt5
<module 'PyQt5' (namespace)>
```
2022-04-11 17:38:45 +02:00
SomberNight
05649861c8 qt gui: more resilient startup: catch more exceptions, better fallback
fixes https://github.com/spesmilo/electrum/issues/7447

Consider this trace for 4.2.0:
```
Traceback (most recent call last):
  File "electrum/gui/qt/__init__.py", line 332, in start_new_window
  File "electrum/gui/qt/__init__.py", line 363, in _start_wizard_to_select_or_create_wallet
  File "electrum/gui/qt/installwizard.py", line 302, in select_storage
  File "electrum/util.py", line 504, in get_new_wallet_name
PermissionError: [Errno 1] Operation not permitted: '/Users/admin/Documents/Peach/MS'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "electrum/gui/qt/__init__.py", line 426, in main
  File "electrum/gui/qt/__init__.py", line 307, in wrapper
  File "electrum/gui/qt/__init__.py", line 349, in start_new_window
  File "electrum/util.py", line 504, in get_new_wallet_name
PermissionError: [Errno 1] Operation not permitted: '/Users/admin/Documents/Peach/MS'
```

Note that `get_new_wallet_name` (os.listdir) can raise OSError,
and we were calling that on the main entrypoint codepath without exception-handling.
We were also calling it in the fallback codepath without exception-handling.
i.e. the GUI errored out on every startup for affected users, and without CLI usage
it was not possible to recover.
2022-03-23 03:58:33 +01:00
SomberNight
d8e2582889 qt gui: (maybe fix) opening "Preferences" segfaults on macOS for some
see https://github.com/spesmilo/electrum/issues/7725
related https://github.com/Electron-Cash/Electron-Cash/pull/1545
2022-03-21 15:50:28 +01:00
SomberNight
15643b7951 qt init: make sure wallet file parsing errors are shown in gui
Some exceptions were just killing the gui silently and not even logged.

E.g.:
```
E | gui.qt.ElectrumGui | error loading wallet (or creating window for it)
Traceback (most recent call last):
  File "/opt/electrum/electrum/gui/qt/__init__.py", line 433, in main
    if not self.start_new_window(path, self.config.get('url'), app_is_starting=True):
  File "/opt/electrum/electrum/gui/qt/__init__.py", line 307, in wrapper
    return func(self, *args, **kwargs)
  File "/opt/electrum/electrum/gui/qt/__init__.py", line 332, in start_new_window
    wallet = self._start_wizard_to_select_or_create_wallet(path)
  File "/opt/electrum/electrum/gui/qt/__init__.py", line 377, in _start_wizard_to_select_or_create_wallet
    db = WalletDB(storage.read(), manual_upgrades=False)
  File "/opt/electrum/electrum/wallet_db.py", line 73, in __init__
    self.load_data(raw)
  File "/opt/electrum/electrum/wallet_db.py", line 104, in load_data
    self._after_upgrade_tasks()
  File "/opt/electrum/electrum/wallet_db.py", line 202, in _after_upgrade_tasks
    self._load_transactions()
  File "/opt/electrum/electrum/util.py", line 439, in <lambda>
    return lambda *args, **kw_args: do_profile(args, kw_args)
  File "/opt/electrum/electrum/util.py", line 435, in do_profile
    o = func(*args, **kw_args)
  File "/opt/electrum/electrum/wallet_db.py", line 1310, in _load_transactions
    self.data = StoredDict(self.data, self, [])
  File "/opt/electrum/electrum/json_db.py", line 79, in __init__
    self.__setitem__(k, v)
  File "/opt/electrum/electrum/json_db.py", line 44, in wrapper
    return func(self, *args, **kwargs)
  File "/opt/electrum/electrum/json_db.py", line 97, in __setitem__
    v = self.db._convert_dict(self.path, key, v)
  File "/opt/electrum/electrum/wallet_db.py", line 1361, in _convert_dict
    v = dict((k, SwapData(**x)) for k, x in v.items())
```
2022-03-15 14:23:30 +01:00
SomberNight
7a47eb9906 qt: again disable changing light/dark theme at runtime
partially reverts 11a04c0d72

related https://github.com/spesmilo/electrum/issues/7209
2022-02-18 22:17:44 +01:00
SomberNight
11a04c0d72 qt: allow changing light/dark theme at runtime
Looks like the stylesheet can be changed at any time...
so we don't need to ask the user to restart the program.

closes https://github.com/spesmilo/electrum/issues/7209
2022-02-18 18:08:38 +01:00
SomberNight
ca9b48e2d6 gui: add BaseElectrumGui base class for guis 2021-11-05 20:21:50 +01:00
SomberNight
c331c311db crash reporter: add EarlyExceptionsQueue
`util.send_exception_to_crash_reporter` is now useful and can be transparently
used even before the exception hook is set up.
2021-11-05 20:01:43 +01:00
SomberNight
e0246b30b9 daemon: if taskgroup dies, show error in GUI
If daemon.taskgroup dies
- in GUI mode, show a crash reporter window to the user,
  instead of immediately stopping the whole process.
- in daemon mode, log exception and stop process, as before.
2021-11-05 20:01:38 +01:00
SomberNight
3643b9f056 daemon: rework stopping
The CLI stop() command can now also stop the GUI.
2021-11-05 19:57:39 +01:00
SomberNight
8945dcda7a qt init: on exc, let crash reporter appear instead of silently dying
related: https://github.com/spesmilo/electrum/issues/7390

```
20210706T091826.513398Z |    ERROR | __main__ | daemon.run_gui errored
Traceback (most recent call last):
  File "run_electrum", line 407, in handle_cmd
  File "electrum\daemon.py", line 584, in run_gui
  File "electrum\gui\qt\__init__.py", line 414, in main
  File "electrum\gui\qt\__init__.py", line 291, in wrapper
  File "electrum\gui\qt\__init__.py", line 316, in start_new_window
  File "electrum\gui\qt\__init__.py", line 361, in _start_wizard_to_select_or_create_wallet
  File "electrum\wallet_db.py", line 73, in __init__
  File "electrum\wallet_db.py", line 106, in load_data
  File "electrum\util.py", line 412, in <lambda>
  File "electrum\util.py", line 408, in do_profile
  File "electrum\wallet_db.py", line 175, in upgrade
  File "electrum\wallet_db.py", line 540, in _convert_version_24
ValueError: too many values to unpack (expected 2)
```
2021-07-07 19:19:43 +02:00
SomberNight
013cf869f1 qt: qrreader: keep both old and new toolchain; try to abstract it away 2021-06-25 16:52:02 +02:00
SomberNight
c1dbcab9bb qt: new qrreader using QtMultimedia; drop CalinsQRReader(mac)
This commit ports the work of EchterAgo and cculianu from Electron-Cash,
to implement a new toolchain to scan qr codes.

Previously, on Linux and Win, we have been using zbar to access the camera
and read qrcodes; and on macOS we used CalinsQRReader (an objective-C
project by cculianu).

The new toolchain added here can use QtMultimedia to access the camera,
and then feed that image into zbar. When used this way, zbar needs
fewer dependencies and is easier to compile, in particular it can be
compiled for macOS.

The new toolchain works on all three platforms, with some caveats
(see code comments in related commits) -- so we also keep the end-to-end
zbar toolchain; but at least we can drop CalinsQRReader.

The related changes in Electron-Cash are spread over 50+ commits (several PRs and direct
pushes to master), but see in particular:
https://github.com/Electron-Cash/Electron-Cash/pull/1376

some other interesting links:
b2b737001c
163224cf1f
3b31e0fcb1
eda015908e
https://github.com/Electron-Cash/Electron-Cash/pull/1545
052aa06c23
2021-06-25 16:51:58 +02:00
SomberNight
c41cd4ae04 qt init: move Ctrl-C handling earlier 2021-04-06 18:27:28 +02:00
SomberNight
1cd5235426 qt init: rm gui.close() method
There is gui.stop() already, which does the same thing (which is shared API with kivy).
Also, the _cleanup_before_exit() call was redundant in close(),
aboutToQuit handles that.
2021-04-04 01:05:23 +02:00
SomberNight
a3b16c7640 qt init: shutdown properly if last open window was a wizard
fixes #7171
2021-04-04 00:49:25 +02:00
SomberNight
981381346f qt: even more clean-up before exiting
related: https://github.com/spesmilo/electrum/issues/6889#issuecomment-812776695
2021-04-03 19:17:32 +02:00
SomberNight
be43632cc4 qt init: more clean-up for system tray
related: https://github.com/spesmilo/electrum/issues/6889#issuecomment-812776695
2021-04-03 06:17:47 +02:00
SomberNight
14c5ceeacf qt init: (trivial) refactor system tray 2021-04-03 05:42:32 +02:00
SomberNight
e686b40819 qt init: don't catch BaseException unless there is good reason
let KeyboardInterrupt propagate out
2021-04-03 01:47:44 +02:00
SomberNight
34e64ef152 qt gui: some more clean-up when exiting
related: https://github.com/spesmilo/electrum/issues/6889

This fixes the case where the user quits by pressing Ctrl+C,
and some other minor things.

There is still another issue that sometimes causes a segfault during shutdown...
2021-04-03 01:44:42 +02:00
ThomasV
a4210ce5e7 Qt: remove the 'local watchtower' option from GUI.
It is not realistic to expect Electrum to be used as a watchtower
in GUI mode, and possibly counter-productive (may set wrong
expectations).

A proper watchtower should be configured as a daemon. The
documentation will be updated to reflect this change.
2021-03-28 10:44:03 +02:00
Neil Booth
8b5e312e7e qt: fix handling BIP21 URI from e.g. website on macOS
fixes #6933

based on e2171f702d

Co-authored-by: SomberNight <somber.night@protonmail.com>
2021-01-21 04:41:03 +01:00
SomberNight
95b08e9961 plugins: remove 'on_new_window' hook 2020-12-08 10:33:43 +01:00
bitromortac
4efcb53d24 network: load gossip db early
The gossip db is loaded early when the network is started to save
time when the gui is locked and a wallet not yet loaded. Side effects
of the LNWallet to start peering when a channel db is loaded is
circumvented.
2020-10-22 18:05:51 +02:00
ThomasV
9547a4e60c Qt: override 'persist_daemon' option if users exits from menu 2020-06-30 11:16:27 +02:00
SomberNight
24221f8fca plugins: fix labels plugin FIXME re "just enabled plugin" 2020-05-25 17:31:13 +02:00
SomberNight
a4bec80efe (trivial) log Qt version at startup 2020-05-14 19:15:50 +02:00
ThomasV
8f41aeb783 Replace wallet backup with channel backups
- channels can be backed up individually
 - backups are added to lnwatcher
 - AbstractChannel ancestor class
2020-04-10 14:45:23 +02:00
SomberNight
e6d43b60fa qt hww show_settings_dialog: don't scan devices in GUI thread
Just makes sense in general.
Also, previously, the GUI would freeze if right after startup the user
clicked the hww status bar icon (especially with multiple hww connected).
2020-04-01 21:09:06 +02:00
ThomasV
0d160cceea Qt: test if lightinng is running 2020-03-06 11:23:26 +01:00
ThomasV
62eceeb573 Save and read lighting backups (Qt) 2020-02-15 16:28:15 +01:00
ThomasV
e1ce3aace7 Separate db from storage
- storage is content-agnostic
 - db and storage are passed to wallet contructor
2020-02-10 17:45:23 +01:00
SomberNight
94888739d3 try to fix "--offline" mode 2020-01-09 19:23:24 +01:00
ThomasV
fc85dcead6 follow-up previous commit 2019-11-23 11:37:01 +01:00
ThomasV
6c62fb03ac fix #5733 2019-11-23 11:02:31 +01:00
ThomasV
90ce9f195b Allow user to enable lightning in the GUI. Make it a per-wallet setting. 2019-10-13 20:34:38 +02:00
ThomasV
af4a3328f7 Qt: separate lightning and watchtower dialogs 2019-10-12 14:30:52 +02:00
SomberNight
04edad9984 config: no longer singleton. it is passed to Wallet.__init__
The few other cases that used SimpleConfig.get_instance() now
either get passed a config instance, or they try to get a reference
to something else that has a reference to a config.
(see lnsweep, qt/qrcodewidget, qt/qrtextedit)
2019-09-22 20:46:01 +02:00
SomberNight
1a08063928 config: remove 'open_last_wallet' side-effecting
related: #5629
2019-09-10 17:10:52 +02:00
SomberNight
bcdb72ae93 qt: add some type hints 2019-09-09 22:19:36 +02:00