1
0
Commit Graph

107 Commits

Author SHA1 Message Date
SomberNight
90f39bce88 run_electrum: have daemon manage Plugins object, and call Plugins.stop
Plugins.stop was never called, so the Plugins thread only stopped
because of the is_running() check in run(), which triggers too late:
the Plugins thread was stopping after the main thread stopped.

E.g. playing around in the qt wizard with wallet creation for a Trezor,
and closing the wizard (only window):
``` 24.85 | E | p/plugin.Plugins |
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/util.py", line 386, in run_jobs
    job.run()
  File "/home/user/wspace/electrum/electrum/plugin.py", line 430, in run
    client.timeout(cutoff)
  File "/home/user/wspace/electrum/electrum/plugin.py", line 363, in wrapper
    return run_in_hwd_thread(partial(func, *args, **kwargs))
  File "/home/user/wspace/electrum/electrum/plugin.py", line 355, in run_in_hwd_thread
    fut = _hwd_comms_executor.submit(func)
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 167, in submit
    raise RuntimeError('cannot schedule new futures after shutdown')
RuntimeError: cannot schedule new futures after shutdown
```
2023-08-24 17:15:14 +00:00
ThomasV
b96cc82333 Make storage a field of db
This comes from the jsonpatch_new branch.
I rather have in master now, because it touches a lot of filese.
2023-08-18 08:08:31 +02:00
ThomasV
0ebb6469ff CLI: make sure we do not load WalletDB while another process is accessing it
- do not load WalletDB in order to check keystore password
- do not allow --offline commands while a daemon is running
2023-08-18 08:05:54 +02:00
SomberNight
44ef5a35b7 CLI: fix regression re handling "unknown command", re locale
if qt is not installed, e.g. on a server, was getting:
```
$ ./run_electrum sadasdasddsa
Traceback (most recent call last):
  File "/home/user/wspace/electrum/./run_electrum", line 532, in <module>
    main()
  File "/home/user/wspace/electrum/./run_electrum", line 383, in main
    lang = get_default_language(gui_name=gui_name)
  File "/home/user/wspace/electrum/electrum/gui/default_lang.py", line 23, in get_default_language
    from PyQt5.QtCore import QLocale
ModuleNotFoundError: No module named 'PyQt5.QtCore'
```
2023-08-09 14:52:40 +00:00
SomberNight
20f4d44f09 cli: "daemon -d": init rpc credentials before os.fork()
follow-up 8b195ee77a
2023-08-03 22:42:08 +00:00
SomberNight
8b195ee77a cli: "./run_electrum daemon -d" to block until daemon becomes ready
Without this,
`$ python3 -m unittest electrum.tests.regtest.TestUnixSockets.test_unixsockets`
was failing on my machine but succeeding on CI, due to timing differences.
2023-08-03 17:21:05 +00:00
Sander van Grieken
db6779bf04 qt: show send tab if payment identifier is passed on the cmdline 2023-07-07 20:49:45 +02:00
Sander van Grieken
a2ca191de1 pass wallet to PaymentIdentifier instead of config and contacts 2023-06-28 16:49:28 +02:00
ThomasV
15eb765eac payment_identifiers:
- this separates GUI from core handling
 - the PaymentIdentifier class handles network requests
 - the GUI is agnostic about the type of PI
2023-06-28 16:49:28 +02:00
SomberNight
3ab47e1c45 (trivial) convert more config keys 2023-06-05 15:29:35 +00:00
SomberNight
ccc012674f unconditionally raise ImportError if asserts are disabled
I have reconsidered and now think that we should always hard-fail
if asserts asserts are disabled. It is just easier to reason about
the code knowing that asserts are evaluated.

If an end-user or library user has a concrete use case where this is
a problem, please open an issue and let us know.

follow-up
0f541be6f1
0e5464ca13
2023-06-01 17:34:32 +00:00
SomberNight
24980feab7 config: introduce ConfigVars
A new config API is introduced, and ~all of the codebase is adapted to it.
The old API is kept but mainly only for dynamic usage where its extra flexibility is needed.

Using examples, the old config API looked this:
```
>>> config.get("request_expiry", 86400)
604800
>>> config.set_key("request_expiry", 86400)
>>>
```

The new config API instead:
```
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS
604800
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS = 86400
>>>
```

The old API operated on arbitrary string keys, the new one uses
a static ~enum-like list of variables.

With the new API:
- there is a single centralised list of config variables, as opposed to
  these being scattered all over
- no more duplication of default values (in the getters)
- there is now some (minimal for now) type-validation/conversion for
  the config values

closes https://github.com/spesmilo/electrum/pull/5640
closes https://github.com/spesmilo/electrum/pull/5649

Note: there is yet a third API added here, for certain niche/abstract use-cases,
where we need a reference to the config variable itself.
It should only be used when needed:
```
>>> var = config.cv.WALLET_PAYREQ_EXPIRY_SECONDS
>>> var
<ConfigVarWithConfig key='request_expiry'>
>>> var.get()
604800
>>> var.set(3600)
>>> var.get_default_value()
86400
>>> var.is_set()
True
>>> var.is_modifiable()
True
```
2023-05-25 17:39:48 +00:00
SomberNight
68eaa680f8 CLI/RPC: better error msg when running daemon on Windows
`-d` is not supported, due to missing os.fork

related: https://github.com/spesmilo/electrum/issues/5511
2023-05-16 12:28:59 +00:00
SomberNight
a0c43573ab locale/i18n: get default language and set it as early as possible
TODO elaborate xxxxx
2023-05-05 17:00:18 +00:00
SomberNight
0e5464ca13 android build: enable asserts, and add sanity-check for it
Note that 0f541be6f1 added a warning log if asserts are disabled.
It is intentional that these two things are in separate files:
We always want to log that warning, even if someone is using electrum as a library.
However, in that latter case, I think it's fine not to sys.exit(), but leave the decision up to the library user.

Similar thinking when running from source: let's log the warning but don't sys.exit().
2023-03-31 16:24:14 +00:00
SomberNight
1530668960 qt/qml: delay starting network until after first-start-network-setup
The qt, qml, and kivy GUIs have a first-start network-setup screen
that allows the user customising the network settings before creating a wallet.
Previously the daemon used to create the network and start it, before this screen,
before the GUI even starts. If the user changed network settings, those would
be set on the already running network, potentially including restarting the network.

Now it becomes the responsibility of the GUI to start the network, allowing this
first-start customisation to take place before starting the network at all.
The qt and the qml GUIs are adapted to make use of this. Kivy, and the other
prototype GUIs are not adapted and just start the network right away, as before.
2023-03-30 00:59:02 +00:00
SomberNight
cb11e1faed CLI: make "electrum stop" robust to dead daemon / lingering lockfile
follow-up fbf79b148b
2023-01-25 15:35:42 +00:00
ThomasV
fbf79b148b CLI: poor man's detection of already running daemon. 2023-01-14 09:56:18 +01:00
SomberNight
a4276102f2 hw DeviceMgr: don't filter already paired devices in wizard
Related to prev commit: multiple (compatible) keystores can now match
with the same HardwareClientBase, so we might as well also allow
reusing existing Clients for the wizard.
2022-12-19 13:10:20 +00:00
SomberNight
eb2ff94104 android: when running debug apk, disallow changing "enable_debug_logs"
follow-up 34b594ea40
2022-11-04 02:40:04 +00:00
SomberNight
34b594ea40 android: add setting to enable debug logs
If enabled, we log to stderr, which can get inspected via logcat.
Not user-friendly at all - but previously there was no way to get logs from a release build.

closes https://github.com/spesmilo/electrum/issues/7409
2022-10-07 20:28:52 +00:00
SomberNight
57b17d13ac android build: make building testnet apk easier
Just uncomment line 53 in make_apk, and you get a testnet apk that can co-exist with your mainnet install.
No need to do a clean rebuild of ".buildozer/" either.
2022-07-09 04:47:37 +02:00
SomberNight
e72f575eea android build: factor out package name ("org.electrum.electrum")
to make it easier to change, to make it easy to have a co-existing mainnet and testnet install
(or two mainnet installs, etc)
2022-07-09 04:47:32 +02:00
SomberNight
75e7f5e2f8 run_electrum: fix DeprecationWarning re importlib.find_loader 2022-07-08 13:32:41 +02:00
SomberNight
b8b629ca66 run_electrum: (android) restore behaviour of only logging in DEBUG builds 2022-07-08 13:31:40 +02:00
ThomasV
064ac55059 determine android_gui at runtime 2022-07-07 18:28:00 +02:00
Sander van Grieken
c3d37913cd android now uses qml UI 2022-07-07 18:28:00 +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
SomberNight
ffe36e2f56 make "-v" (logging to stderr) work with commands
When running a command, file logging is disabled as every
command-invocation would create a new logfile. However if the user
explicitly sets "-v" on the commandline, there's no reason why that
shouldn't work.
2022-06-12 00:54:35 +02:00
SomberNight
ae76a0daf5 windows binaries: try to prevent users from renaming exe while running
closes https://github.com/spesmilo/electrum/issues/4072
(this fix AFAICT only works on Windows, and #4072 contains some macOS reports as well,
however all recent reports are for Windows and overall most reports are for Windows,
so let's close it optimistically for now)
2022-05-29 03:26:20 +02:00
SomberNight
6a34d93ce2 "--portable": more consistent behaviour
The old and new behaviour is as follows:
1. "pyinstaller" case: portable `.exe`, other `.exe`s with `--portable`, and `.dmg` with `--portable`
    - uses `$PWD`
    - note that when you double-click the portable `.exe` on Windows, `$PWD` is set to the parent folder, i.e. the datadir gets put next to the `.exe`
2. appimage `--portable`
    - was broken (see https://github.com/spesmilo/electrum/issues/5551)
    - (CHANGED NOW to) uses `$PWD`
3. git clone
    - next to `run_electrum`
4. unpacking `tar.gz` and running locally from it
    - next to `run_electrum`
5. `pip install *.tar.gz`, and calling "electrum --portable" from terminal
    - used python's user script directory
        - `~/.local/bin/electrum_data`
        - `$VIRTUAL_ENV/bin/electrum_data`
    - (CHANGED NOW to) uses `$PWD`

That is, we now almost always put the datadir in `$PWD`,
except for the local source case, where we put it next to `run_electrum`.

The "appimage" case (2) is now fixed.

The only breaking change is re case 5 which previously behaved completely
unintuitively and most likely not in a useful way.

closes https://github.com/spesmilo/electrum/issues/7732
fixes https://github.com/spesmilo/electrum/issues/5551
2022-03-23 20:10:11 +01:00
SomberNight
5b500f08ea "--portable": make behaviour independent of pyinstaller version
pyinstaller 4.3 changed the value of `__file__`.
This change makes our behaviour independent of that pyinstaller change
(we always behave like old versions of pyinstaller).

fixes https://github.com/spesmilo/electrum/issues/7729
regression was introduced by b5951adc29
2022-03-23 20:09:34 +01:00
SomberNight
5f1a13e4ea run_electrum: small clean-up, and hide DeprecationWarnings if not git
- rename `is_bundle` to `is_pyinstaller` (no semantic changes, just to clearer name)
- define `is_appimage`
- add comment to explain `is_local`
  - its value is the same as before (but more explicit definition)
- define `is_git_clone`, and restrict DeprecationWarnings to that case
2022-03-23 20:09:30 +01:00
SomberNight
c9c094cfab requirements: bump min aiorpcx to 0.22.0
aiorpcx 0.20 changed the behaviour/API of TaskGroups.
When used as a context manager, TaskGroups no longer propagate
exceptions raised by their tasks. Instead, the calling code has
to explicitly check the results of tasks and decide whether to re-raise
any exceptions.
This is a significant change, and so this commit introduces "OldTaskGroup",
which should behave as the TaskGroup class of old aiorpcx. All existing
usages of TaskGroup are replaced with OldTaskGroup.

closes https://github.com/spesmilo/electrum/issues/7446
2022-02-15 18:22:44 +01:00
SomberNight
dd2f8541b7 bump min required Python version to 3.8 2022-02-15 18:22:32 +01:00
Bradley Ray
90e906aba2 Update new password prompt (#7495)
No longer prompts for new password if --new_password parameter is used
2021-09-10 23:19:06 +00:00
bitromortac
c65caf6c68 qt+android: add lightning URI support 2021-07-30 08:44:15 +02:00
ghost43
5dff461aaa Merge pull request #7282 from wakiyamap/add_signet
add signet support
2021-06-22 16:15:38 +02:00
Nima
13e4424922 cmd: add sign with privkey and wallet (#7147)
* Remove check for sign with privkey in init_cmdline

* Add with_privkey and with_wallet variants of signtransaction command

* Add unit tests for signtransaction_with_privkey and signtransaction_with_wallet commands
2021-06-08 14:33:55 +00:00
wakiyamap
639cd94dcb add signet support 2021-05-06 19:47:22 +09:00
SomberNight
9a38c4d2a1 logging: don't lose log messages during early startup
Previously, during early-startup (until configure_logging(config) is
called in run_electrum),
- the stderr log handler lost all log messages below warning level, and
- the file log handler lost all log messages regardless of log level

We now instead start buffering log messages in memory as soon as
electrum.logging is imported. The buffer is dumped into the
stderr and file log handlers when they are fully set up, and then
the buffer is discarded (and the temporary log handler is removed).

Note that messages are not logged until configure_logging() is called.
Previously WARNING/ERROR messages would get logged immediately to stderr,
but not anymore. This was changed so that the order of the log messages
can be kept intact. (if we log WARNINGs immediately, but need to delay
INFOs until the config is available, messages would either be out of order
or alternatively there would be duplicates)

Relatedly, we now follow the recommendation of the python docs re
logging for libraries [0]: we try to only configure logging if running via
run_electrum (the main script) and not when e.g. a 3rd party script
imports electrum.

[0]: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
2021-04-14 19:14:26 +02:00
SomberNight
a2ed95340c locale/i18n: set language as early as possible
related: #7158
related: #4621
2021-04-01 04:36:02 +02:00
Benoit Verret
f731c38293 Minor style changes 2021-03-21 00:36:23 -04:00
SomberNight
d86c45edac dependencies: bump min aiorpcx, and enforce at runtime
Note that newer aiorpcx started requiring python 3.8, so we cannot use
the latest versions, until we too bump the min python version to 3.8.
We should not do that until debian stable ships python 3.8.
Also, new aiorpcx introduced some API changes which we will need to
adopt, so even if the user locally has recent enough python, we need
old aiorpcx atm.

related: https://github.com/spesmilo/electrum/issues/7118
2021-03-20 17:17:32 +01:00
SomberNight
3c019c2f9c daemon/wallet/network: make stop() methods async 2021-03-09 17:52:36 +01:00
ThomasV
1e4fa83098 Kivy: use the same password for all wallets
When the app is started, the password is checked against all
wallets in the directory.

If the test passes:
 - subsequent wallet creations will use the same password
 - subsequent password updates will be performed on all wallets
 - wallets that are not storage encrypted will encrypted
   on the next password update (even if they are watching-only)

This behaviour is restricted on Android, with a 'single_password' config variable.
Wallet creation without password is disabled if single_password is set
2021-01-13 12:24:19 +01:00
SomberNight
9e45108395 kivy: fix some resource path issues
When running kivy on Linux desktop,
running from git clone, `./run_electrum -g kivy` worked,
but `pip install -e .; electrum -g kivy` did not.
This was due to the relative paths using cwd as base.

see #6835
2020-12-10 07:30:31 +01:00
SomberNight
d40bedb2ac also support uppercase bip21 URIs
related https://github.com/btcpayserver/btcpayserver/issues/2110
2020-12-09 16:09:12 +01:00
SomberNight
5a2d588e8b dependencies: rm python-ecdsa 2020-12-08 16:38:13 +01:00
SomberNight
f74ac1a741 cli/rpc: fix 'sweep' command
fixes #6825
2020-12-08 12:21:56 +01:00