1
0
Commit Graph

69 Commits

Author SHA1 Message Date
SomberNight
872ce82418 tests: clean up event-loop creation 2022-05-04 01:53:21 +02:00
SomberNight
2c57c78ebe asyncio: stop using get_event_loop(). introduce ~singleton loop.
asyncio.get_event_loop() became deprecated in python3.10. (see https://github.com/python/cpython/issues/83710)
```
.../electrum/electrum/daemon.py:470: DeprecationWarning: There is no current event loop
  self.asyncio_loop = asyncio.get_event_loop()
.../electrum/electrum/network.py:276: DeprecationWarning: There is no current event loop
  self.asyncio_loop = asyncio.get_event_loop()
```
Also, according to that thread, "set_event_loop() [... is] not deprecated by oversight".
So, we stop using get_event_loop() and set_event_loop() in our own code.
Note that libraries we use (such as the stdlib for python <3.10), might call get_event_loop,
which then relies on us having called set_event_loop e.g. for the GUI thread. To work around
this, a custom event loop policy providing a get_event_loop implementation is used.

Previously, we have been using a single asyncio event loop, created with
util.create_and_start_event_loop, and code in many places got a reference to this loop
using asyncio.get_event_loop().
Now, we still use a single asyncio event loop, but it is now stored as a global in
util._asyncio_event_loop (access with util.get_asyncio_loop()).

I believe these changes also fix https://github.com/spesmilo/electrum/issues/5376
2022-04-29 18:49:07 +02:00
SomberNight
5149ee02a5 wallet: fix delete_address removing too many transactions
See testcase:
- imported wallet with addr1 and addr2
- three txs: tx1 funds addr1, tx2 funds addr2, tx3 spends all
- if we rm addr1 from the wallet,
  - previously both tx1 and tx3 was removed (as tx3 is a child of tx1)
  - now only tx1 is removed (tx3 still relates to the wallet via addr2)

fixes https://github.com/spesmilo/electrum/issues/7587
2022-03-21 19:30:08 +01:00
ghost43
b828627dc6 Merge pull request #6917 from andrewkozlik/slip39
SLIP-0039 wallet recovery
2021-06-22 19:44:02 +02:00
SomberNight
fbd8c5f7b0 imported wallets: respect "use_change" option; default off
Imported wallets used to send change back to the "from address".
We keep this behaviour as default.

There has already been an option "Use change addresses" (exposed in GUI),
ignored so far by imported wallets (was only used by HD wallets).
With this change, imported wallets no longer ignore that option, and if set,
they will send change to a random unused imported address, instead of back to "from address".
If all addresses are used, it falls back to sending change back to the "from address".

see: https://github.com/spesmilo/electrum/pull/7330
see: https://github.com/spesmilo/electrum/issues/5353
2021-06-11 20:12:43 +02:00
Andrew Kozlik
2de82a2fd6 Add SLIP-0039 unit tests. 2021-04-30 19:55:47 +02:00
Andrew Kozlik
19d04546df Replace from_bip39_seed() with from_bip43_rootseed(). 2021-04-30 19:43:53 +02:00
SomberNight
67c6f0e1bd wallet: make sure we don't create zero input txs
fixes #7207
2021-04-14 19:08:04 +02:00
SomberNight
8ea2b4432a tests: add test for keystore.get_lightning_xprv 2021-03-30 19:05:42 +02:00
Benoit Verret
f731c38293 Minor style changes 2021-03-21 00:36:23 -04:00
SomberNight
e25602ab3b wallet: don't put partial tx as UTXO into psbt
if there is a chain of unsigned txs, we cannot populate NON_WITNESS_UTXO

closes #7080
closes #7009
closes #6482
2021-03-04 13:20:49 +01:00
SomberNight
058d9ab6bb wallet.bump_fee: add new strategy: decrease payment amounts
- Rename bump_fee "methods" to "strategies".
- Refactor strategies so that bump_fee can use any subset of them in any permutation.
- Adds a new strategy which decreases the payment outputs (instead of change).
2021-02-25 15:32:07 +01:00
SomberNight
01ed5e7345 wallet.bump_fee: (fix) method2 was bumping too much if output was rm-ed
regression from bafe8a2fff
2021-02-15 10:20:34 +01:00
SomberNight
ca86e35724 wallet.bump_fee: (fix) make sure all inputs have same sequence number
Previously, if bump_fee decided to add new inputs to the tx, they would
have a different sequence number than the existing inputs. This was
unintentional.
2021-02-12 04:59:34 +01:00
SomberNight
21f13e21b1 wallet: fix bump_fee and dscancel for "not all inputs ismine" case
we fetch the missing prev txs over network

fixes #6551
fixes #6864
2020-12-20 15:29:41 +01:00
SomberNight
bb41ef3450 wallet: (fix) bump_fee sometimes created invalid tx that spent orig out
When replacing non-segwit tx, bump_fee in some circumstances created
a tx that tried to spend from the tx-to-be-replaced. There is
explicit logic to avoid this but it only worked for segwit txs.

The change in transaction.py is a no-op, just tried to make it clearer
that the scriptSigs, witnesses are being reset by from_tx().
2020-12-18 19:35:22 +01:00
SomberNight
c81551299e transaction: put full derivation paths into PSBT by default
There are three export options for exporting a PSBT.
The default option previously only put derivation path suffixes for pubkeys
(paths relative to the intermediate xpub), now it puts the full path
(if is known by the keystore).

The "export for hardware device; include xpubs" option works same as before:
it puts both full paths and also global xpubs into the PSBT.
Hence the difference between the default option and the "include xpubs" option
is now only that the latter puts global xpubs into the PSBT.

This change is largely made for user-convenient in mind.
Now exporting a PSBT should be less error-prone: particularly for the
single-signer coldcard with sdcard usage, the default option will now work.

closes #5969
related #5955
2020-12-10 17:39:12 +01:00
SomberNight
c3c64a37c2 keystore: ignore fingerprint for pubkeys in psbt, try to match all keys 2020-12-10 17:39:07 +01:00
SomberNight
4bda6f5e61 test_wallet_vertical: add test case for pre-2.7 "2fa" seed 2020-12-10 14:35:10 +01:00
SomberNight
f74ac1a741 cli/rpc: fix 'sweep' command
fixes #6825
2020-12-08 12:21:56 +01:00
SomberNight
3a4f07c345 wallet: implement cancelling tx by double-spending to self ("dscancel") 2020-10-09 17:36:37 +02:00
SomberNight
ca5b93f07d wallet: cpfp to send to a change address instead of receive address 2020-10-09 17:34:20 +02:00
SomberNight
ad03c1e3cb wallet: (fix) bump_fee and cpfp now returns tx with all wallet-info
Previously e.g. bip32 derivation info was missing for change outputs in partial tx returned by bump_fee.
This was not exposed to users as the GUI TxDialog calls `tx.add_info_from_wallet(self.wallet)`.
2020-10-08 19:30:02 +02:00
SomberNight
364fca6a58 transaction: fix regression: witness_utxo was not included in QR code
fixes #6600
2020-09-23 15:11:53 +02:00
SomberNight
23ea64808d fix tests: follow-up prev 2020-06-13 18:53:50 +02:00
SomberNight
7bcb59ffb5 wallet: when sweeping, do network reqs in parallel, and don't block GUI 2020-06-05 20:30:25 +02:00
SomberNight
e07d5d8422 fix tests: follow-up psbt changes
follow-up e058ee2957

the difference for each tx here is that
- the old ones had witness utxo but not utxo
- the new ones have utxo but not witness utxo
2020-06-03 21:24:05 +02:00
SomberNight
1978bba915 fix tests: follow-up 154b9cab50 2020-06-03 19:00:28 +02:00
SomberNight
ab4e2dd9f0 wallet: fix is_mine/can_sign. don't just rely on ks, also check script
Previously a standard (single-sig) wallet would consider a multisig txin as is_mine
(if the keystore found its pubkey in the txin).

fixes #5948
2020-02-12 18:14:07 +01:00
SomberNight
de1ca27d63 tests: rm "needs_test_with_all_ecc_implementations" decorator
now libsecp256k1 is the only implementation
2020-02-11 16:46:31 +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
fcd9752f19 keystore: change derive_pubkey API to return bytes 2019-12-10 20:41:47 +01:00
SomberNight
8e89c0c971 wallet: some clean-up re get_address_history vs db.get_addr_history
note: tests needed changing due to behavioural change in wallet.get_receiving_address()
Previously wallet.get_receiving_address used wallet.db.get_addr_history,
now it (indirectly) uses wallet.get_address_history, which now also considers local txns.
2019-12-07 05:42:28 +01:00
SomberNight
5b88b8667e also grind ecdsa low R when using libsecp256k1, and fix tests
note: low R grinding would not have to be duplicated if we trusted the caller
to have done it already (as is the case with the classes in ecc.py), and if
we propagated the choice of "random_k" as part of the nonce_function passed
to libsecp256k1 (which is not currently done)
2019-12-05 20:27:55 +01:00
SomberNight
c0b5ebcc5d tests: fix testcase test_restoring_wallet_with_manual_delete 2019-11-29 13:09:21 +01:00
ThomasV
06589df812 simplify add_transaction 2019-11-23 12:46:43 +01:00
SomberNight
6573e7f1f3 test_wallet_vertical: add test for manual coinjoin 2019-11-06 18:40:16 +01:00
SomberNight
8e09d429c0 psbt: "updater" must swap NON_WITNESS_UTXO for WITNESS_UTXO if txin is segwit 2019-11-06 03:46:00 +01:00
SomberNight
c077d77316 psbt: test_wallet_vertical: add asserts to avoid silent breakage of psbts we create 2019-11-06 03:42:14 +01:00
SomberNight
bafe8a2fff integrate PSBT support natively. WIP 2019-11-04 22:24:36 +01:00
SomberNight
d9b5ab3086 wallet: fix bump_fee when there are only change outputs
closes #5718
closes #5603
2019-10-22 17:12:23 +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
9eee36fe00 follow-up prev 2019-09-10 20:18:53 +02:00
SomberNight
098636c69a fix tests 2019-09-10 19:39:52 +02:00
ThomasV
cefa4762ba do not create multiple instances of SimpleConfig (fix #5629). Add config field to wallet 2019-09-10 08:57:40 +02:00
SomberNight
aadde9be17 transaction: fix remove_signatures
closes #5491
2019-07-05 21:16:58 +02:00
SomberNight
94b721baa4 wallet: fix type error in _bump_fee_through_decreasing_outputs
fixes #5483
2019-07-04 17:23:34 +02:00
SomberNight
e0b1bbfc46 tests: new tests for bump_fee and rbf_batching 2019-06-20 22:42:50 +02:00
SomberNight
0c20fcb6b3 tests: fix existing bump_fee tests 2019-06-20 22:42:49 +02:00
SomberNight
d0a43662bd wallet: make "increase fee" RBF logic smarter
There are now two internal strategies to bump the fee of a txn.
bump fee method 1: keep all inputs, keep all not is_mine outputs,
                   allow adding new inputs
bump fee method 2: keep all inputs, no new inputs are added,
                   allow decreasing and removing outputs (change is decreased first)
Method 2 is less "safe" as it might end up decreasing e.g. a payment to a merchant;
but e.g. if the user has sent "Max" previously, this is the only way to RBF.

We try method 1 first, and fail-over to method 2.
Previous versions always used method 2.

fixes #3652
2019-06-20 22:42:48 +02:00