Commit Graph

450 Commits

Author SHA1 Message Date
Sander van Grieken
3590385fa2 Revert "only create lightning invoice if the wallet has channels in a suitable state"
This reverts commit 717b6dd5fb.
2022-10-19 14:50:38 +02:00
Sander van Grieken
717b6dd5fb only create lightning invoice if the wallet has channels in a suitable state 2022-10-19 12:27:19 +02:00
ThomasV
ff5ba7cca4 rbf: fix issues with bump_frr_through_decreasing_change
- break from loop if target is reached
- recompute delta if there is no next iteration.
2022-10-04 10:23:58 +02:00
Sander van Grieken
d4df633f22 move request details into separate dialog 2022-09-28 18:21:07 +02:00
ThomasV
60e2ad4316 follow-up 444dc7fb7f 2022-09-26 18:28:02 +02:00
ThomasV
444dc7fb7f wallet: fix race condition that inhibits proper call of set_up_to_date 2022-09-26 17:02:30 +02:00
ThomasV
30dfecc5dc wallet: check whether address can be reused in get_request_by_addr 2022-09-22 17:37:11 +02:00
Sander van Grieken
5681311fc2 fix request_status callback not passing the correct request key 2022-09-22 11:54:14 +02:00
ThomasV
14e96f4d53 Index request by ID instead of receiving address.
Replace get_key_for_outgoing_invoice, get_key_for_incoming_request
with Invoice.get_id()

When a new request is created, reuse addresses of expired requests (fixes #7927)

The API is changed for the following commands:
 get_request, get_invoice,
 list_requests, list_invoices,
 delete_request, delete_invoice
2022-09-02 10:58:11 +02:00
ThomasV
7d317761da wallet API: remove get_request_status, it is redundant with get_invoice_status 2022-09-01 10:01:09 +02:00
SomberNight
42f2a3da31 Qt pay_lightning_invoice: handle NoDynamicFeeEstimates
`wallet.make_unsigned_transaction` can raise NotEnoughFunds or NoDynamicFeeEstimates.
These are "expected" exceptions that need to be handled or worked around. Added a note
of this in the docstring now.

We now handle NoDynamicFeeEstimates by allowing a static fallback fee in
`wallet.can_pay_onchain` and `lnworker.suggest_funding_amount`. It should be
fine to have a static fallback in these cases, as the user still has a chance
to set their own fee later in the flow.
(though ofc the static fallback might be too high in some mempool conditions,
in which case e.g. can_pay_onchain might return a false-negative, but this
is still an improvement over raising I believe)

fixes https://github.com/spesmilo/electrum/issues/5784
2022-08-30 11:46:52 +00:00
ThomasV
6a9e8da218 remove sign_payment_request: broken and not used 2022-08-29 12:50:02 +02:00
ThomasV
2df45faeae follow-up previous commit 2022-08-29 10:27:56 +02:00
ThomasV
cf94ebc106 If an invoice cannot be parsed in import_invoices or import_requests,
raise FileImportFailed. Fixes #7950
2022-08-29 10:21:14 +02:00
ThomasV
d9f77a50e8 wallet API: remove get_request_status, it is redundant with get_invoice_status 2022-08-29 09:48:08 +02:00
SomberNight
757ec53ea2 AddressSynchronizer: set diagnostic_name for better logs
fixes regression from 121d8732f1

in particular, this is needed for Synchronizer.diagnostic_name and SPV.diagnostic_name
2022-08-24 11:05:01 +00:00
ThomasV
60c493dc15 adb: trigger adb_added_tx event only if the transaction is new 2022-08-17 10:40:43 +02:00
SomberNight
d1c15fe5e9 wallet: (perf) avoid iterating over all invoices in add_transaction 2022-08-16 12:14:44 +00:00
ThomasV
24145f1f52 detect paid invoices in on_event_adb_added_tx 2022-08-16 10:14:47 +02:00
ThomasV
a64aa45e85 get default label for txid based on invoices 2022-08-16 08:50:46 +02:00
ThomasV
2c53af1664 wallet: load lnworker earlier 2022-08-16 08:50:46 +02:00
SomberNight
13570a465c kivy request dialog: follow-up c95791d7ee
related https://github.com/spesmilo/electrum/pull/7929
2022-08-12 11:10:54 +00:00
SomberNight
c95791d7ee qt/kivy: receive tab: add wallet.ReceiveRequestHelp and refactor 2022-08-12 10:06:13 +02:00
SomberNight
767b058946 qt history tab: fix "View Channel" in context menu
related: https://github.com/spesmilo/electrum/issues/7930
2022-08-12 02:30:29 +00:00
SomberNight
659d6890d9 wallet.get_request_URI: rm code duplication 2022-08-11 13:07:56 +00:00
SomberNight
bd2ca30f95 kivy: fix creating dust amount receive requests
fixes https://github.com/spesmilo/electrum/issues/7928
2022-08-11 12:38:46 +00:00
SomberNight
ea5c49b3ab wallet.delete_request(key): piggyback on get_request(key)
So that the two methods are consistent with each other.

As concrete motivation, see e.g.
- how the `getrequest(key)` command calls `wallet.get_request(key)`, and
- the `delete_request(address)` command calls `wallet.delete_request(address)`
2022-08-10 23:48:44 +02:00
SomberNight
0c81dc13a0 wallet: rm confusing get_request_by_address method
The _receive_requests dict is keyed by either 'address' or 'rhash' (see get_key_for_receive_request):
- 'rhash' is used if `req.lightning_invoice is not None`
- address is used otherwise

The `get_request_by_address` method was quite error-prone: it only worked for requests that had an LN part...
2022-08-10 23:23:00 +02:00
SomberNight
396a68cb58 wallet: delete_{invoice,request}: add "write_to_disk=True" param
to support faster batch-deletion
2022-08-10 22:50:23 +02:00
SomberNight
7b095158bf wallet: add get_label_for_address, and make get_label private
fixes https://github.com/spesmilo/electrum/issues/7919

In the past, when creating payment requests, we keyed them by on-chain address,
and set/saved the msg of the request as label for the address.
Many places in the code were calling wallet.get_label(addr) with the expectation that
relevant payment requests are found and their message/description (if any) is considered.

wallet.get_label(key) is now made private, and instead the explicit non-polymorphic
wallet.get_label_for_{address,rhash,txid} alternatives should be used.
2022-08-09 17:21:14 +02:00
SomberNight
73ba00d7dd wallet.restore_wallet_from_text: support creating wallet in-memory 2022-08-08 16:34:04 +02:00
ThomasV
a59c8797dc wallet: write to disk in create_request 2022-07-22 17:01:46 +02:00
SomberNight
ed65f335bd wallet_db upgrade: fix possible corruption of invoice amounts
see https://github.com/spesmilo/electrum/pull/7774
2022-07-15 18:26:13 +02:00
SomberNight
d067e0e314 wallet: make "invoices" and "receive_requests" private
Other modules should use getters such as "get_request(key)" or "get_unpaid_requests()",
direct access is error-prone.
2022-07-12 15:46:47 +02:00
SomberNight
056de017f0 wallet: use get_request(addr) instead of receive_requests[addr]
since "invoice unification", requests are often keyed by rhash
2022-07-12 15:38:54 +02:00
SomberNight
2c73e7f854 wallet: (regression) fix get_spendable_coins when "domain" arg is given
`get_spendable_coins` was ignoring the "domain" param, and returning utxos for the whole wallet
2022-07-11 16:18:38 +02:00
ThomasV
9ae0e5bffc remove lightning parameter from wallet.create_request 2022-07-11 13:52:13 +02:00
ThomasV
88b2dc3589 show onchain address of request in CLI. Fixes #7886 2022-07-11 11:35:21 +02:00
SomberNight
9b8750b9cc wallet.export_invoice: should support onchain invoice with "!" (max) amount
As the GUI allows saving such invoices, CLI should not break for these wallets.
Also note the pre-existing assert on the next line.

follow-up bf4455ef30

```
>>> list_invoices()
Traceback (most recent call last):
  File "...\electrum\gui\qt\main_window.py", line 1506, in <lambda>
    return lambda *args, **kwargs: f(method,
  File "...\electrum\commands.py", line 191, in _run
    result = fut.result()
  File "...\Python310\lib\concurrent\futures\_base.py", line 446, in result
    return self.__get_result()
  File "...\Python310\lib\concurrent\futures\_base.py", line 391, in __get_result
    raise self._exception
  File "...\electrum\commands.py", line 154, in func_wrapper
    return await func(*args, **kwargs)
  File "...\electrum\commands.py", line 1188, in list_invoices
    return [wallet.export_invoice(x) for x in l]
  File "...\electrum\commands.py", line 1188, in <listcomp>
    return [wallet.export_invoice(x) for x in l]
  File "...\electrum\wallet.py", line 2405, in export_invoice
    amount_sat = int(x.get_amount_sat())
ValueError: invalid literal for int() with base 10: '!'
```
2022-07-10 16:26:20 +02:00
SomberNight
68581ce80a invoices: fix type hint for get_address() 2022-07-10 16:08:02 +02:00
SomberNight
9c5277c9a1 wallet: rm get_onchain_request_status; just use is_onchain_invoice_paid
There is some duplication between `wallet.get_onchain_request_status` and `wallet.is_onchain_invoice_paid`
(both in terms of code, and conceptually). `get_onchain_request_status` is used for incoming invoices (receive requests),
and `is_onchain_invoice_paid` is used for outgoing invoices. I think `get_onchain_request_status` existed first,
but as it uses txi/txo, it only works for ismine addresses, so `is_onchain_invoice_paid` was added later
(along with a `get_prevouts_by_scripthash` and corresponding new persisted data structure) to handle the non-ismine
addresses corresponding to outgoing invoices.

I think we could just merge the two functions together... (?)
and this PR does that.
2022-07-09 03:32:33 +02:00
SomberNight
c463f5e23d password unification refactor: move methods from wallet to daemon
Note in particular that check_password_for_directory was not safe to use while the daemon had wallets loaded,
as the same file would have two corresponding Wallet() instances in memory. This was specifically handled in
the kivy GUI, on the caller side, by stopping-before and reloading-after the wallets; but it was dirty to
have the caller handle this.
2022-07-06 19:57:27 +02:00
SomberNight
cafd5c4af0 lnworker.add_request: force keyword args
and change type-hint to reflect that fallback_address can be None
2022-06-22 02:26:54 +02:00
ThomasV
dbf055de9a EventListener class to handle callbacks
and QtEventListener for Qt
2022-06-22 02:07:46 +02:00
ThomasV
9fe93524b7 Index lightning requests with rhash instead of onchain address.
get_unused_addresses() has been broken since #7730, because
addresses are considered as permanently used if they are in
the list of keys of receive_requests. This is true even if
an address is used as fallback for a lightning payment. This
means that the number of lightning payments we can receive
is constrained by the gap limit.

If a payment succeeds off-chain, we want to be able to reuse
its fallback address in other requests (this does not reduce
privacy, because invoices already share the same public key).

This implies that we should not use the onchain address as key
for lightning-enabled requests in wallet.receive_requests. If
we did, paid invoices would be overwritten when the address is
reused. That is the reason for the wallet_db upgrade.

Related: a3faf85e3c
2022-06-15 18:44:52 +02:00
ThomasV
7df24f0adf fix typo 2022-06-14 17:14:02 +02:00
ThomasV
a3faf85e3c wallet:
- add new index: requests_rhash_to_key (fixes #7845)
 - when creating a request, do not save its description in labels.
   Instead, return it as default value in wallet.get_label_by_rhash
lnworker:
  - rename 'payments' to 'payment_info'
  - add note to delete_payment_info
commands: rename 'rmrequest' to 'delete_request'
2022-06-14 13:39:18 +02:00
ThomasV
7d5125c935 lnwatcher: fix tx replacement and notifications
- revert the logic of do_breach_remedy to what it was
   before 0ca3d66d15,
   but now calling self.maybe_redeem unconditionally.
 - replace mempool transactions only if the fee increases
 - do not notify the GUI if a local tx is replaced
 - delete labels when replacing
2022-06-12 14:28:11 +02:00
SomberNight
29d8d8de26 wallet: (fix) cannot just piggyback on adb.is_up_to_date()
The wallet needs its own up_to_date logic:
- the adb being up_to_date means all its addresses are synced
- but an HD wallet might decide to roll the gap limit and generate new addresses
  - the adb does not know about this...
  - the wallet should be considered *not* up_to_date
- relatedly, it is now the wallet that decides to reset the network request counters

- note that wallet.main() was never cleaned up previously.
  - now wallet gets its own taskgroup, which is cleaned up in wallet.stop.

Follow-up to adb refactor: 121d8732f1
2022-06-10 18:55:55 +02:00
ThomasV
d81610b2e1 wallet: filter non-wallet transactions before rebroadcasting event 2022-06-10 13:07:53 +02:00