Commit Graph

79 Commits

Author SHA1 Message Date
SomberNight
612a8e6424 qt: fix: bip70 pay reqs need x509 verification
regression from https://github.com/spesmilo/electrum/pull/8462

- pr.verify() was called in qml, but not in qt gui
- we now call pr.verify() in get_payment_request(), to make the API less error-prone
- it is now ok to call pr.verify() multiple times, the result is cached
2023-07-10 17:50:53 +00:00
Sander van Grieken
f980bd97b5 payment_identifier: factor out bip21 functions to bip21.py to break cyclic dependencies,
parse bolt11 only once, store invoice internally instead of bolt11 string
add is_onchain method to indicate if payment identifier can be paid onchain
2023-07-08 12:18:37 +02:00
Sander van Grieken
eed016bd7e qt: move setting frozen styling to edit components themselves, fix re-enabling Clear button after finalize 2023-06-28 16:49:28 +02:00
Sander van Grieken
ca283a75d0 qml: exclude non-address SPK from supported payment identifiers 2023-06-28 16:49:28 +02:00
Sander van Grieken
74a1f38a8b payment identifier types as enum 2023-06-28 16:49:28 +02:00
Sander van Grieken
fc141c0182 payment_identfier: refactor qml and tests 2023-06-28 16:49:28 +02: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
312e50e9a9 qml: send screen: bip21: fallback to onchain addr if no LN channels
given a bip21 uri that has both onchain addr and bolt11,
if we have LN enabled but no LN channels, auto-fallback to paying onchain

we will have to clean up and unify this logic between GUIs. becoming spaghetti :/
rumour has it, Thomas has a branch? :P
2023-04-25 22:23:24 +00:00
Sander van Grieken
a23457f48d qml: consistency camelcase pyqtProperties 2023-04-25 14:15:13 +02:00
Sander van Grieken
264540e12b qml: consistency camelcase public slots qedaemon, qeinvoice, qewizard 2023-04-25 13:40:16 +02:00
SomberNight
312f2641e7 don't use bare except
use "except Exception", or if really needed explicitly "except BaseException"
2023-04-24 12:58:01 +00:00
SomberNight
a8623f63bb qml: fix send "flow with LN but not LN enabled AND having bip21 uri"
closes https://github.com/spesmilo/electrum/issues/8334
2023-04-23 16:42:08 +00:00
SomberNight
7907eb1f86 qml/qeinvoice.py: turn _bip21 field into local var 2023-04-23 16:36:32 +00:00
ThomasV
a03f4769ca auth_protect: pass authMessage in the auth_protect decorator,
instead of relying on side-effects

This is probably safer, and also more self-contained.
2023-04-17 18:17:29 +02:00
ThomasV
85291b2de3 follow-up 5b6a16e097 2023-04-17 16:54:26 +02:00
SomberNight
2c1abf24fa (trivial) use util.get_asyncio_loop() in some places 2023-04-13 23:08:02 +00:00
ThomasV
d4c386a62c qml: use daemon threads everywhere the network is involved
The app hangs indefinitely if we try to quit it while one of
these threads is active, because once asyncio has shut down,
futures never return. This was already fixed for lightning
payments in c5dc133, but there are many other cases.
2023-04-05 12:31:20 +02:00
ThomasV
f04e2e2e6f Add an extra state for invoices where our tx has been broadcast
successfully, but it is not in our history yet.

(follow-up 159646fe54)
2023-04-04 19:31:25 +02:00
ThomasV
159646fe54 Set status of onchain invoices to PR_INFLIGHT while tx is being broadcast 2023-04-04 18:22:30 +02:00
Sander van Grieken
cf3613b7d5 qml: handle max too 2023-04-04 17:59:40 +02:00
Sander van Grieken
793cbd1c6e qml: save with user entered amount 2023-04-04 17:47:37 +02:00
Sander van Grieken
6c65161d27 qml: refactor qeinvoice.py
QEInvoice/QEInvoiceParser now properly split for mapping to Invoice type (QEInvoice)
and parsing/resolving of payment identifiers (QEInvoiceParser).
additionally, old, unused QEUserEnteredPayment was removed.

invoices are now never saved with user-entered amount if the original invoice
did not specify an amount (e.g. address-only, no-amount bip21 uri, or no-amount
lightning invoice). Furthermore, QEInvoice now adds an isSaved property so the
UI doesn't need to infer that from the existence of the invoice key.

Payments of lightning invoices are now triggered through QEInvoice.pay_lightning_invoice(),
using the internally kept Invoice instance. This replaces the old call path of
QEWallet.pay_lightning_invoice(invoice_key) which required the invoice to be saved
in the backend wallet before payment.

The LNURLpay flow arriving on InvoiceDialog implicitly triggered payment, this is
now indicated by InvoiceDialog.payImmediately property instead of inferrred from the
QEInvoiceParser isLnurlPay property.
2023-04-04 16:13:00 +02:00
ThomasV
6d876da1c4 qml InvoiceDialog: update userinfo messages 2023-04-01 12:46:16 +02:00
Sander van Grieken
478937b8d2 make flake8 not not happy 2023-03-31 15:46:51 +02:00
Sander van Grieken
2bdc303662 qml: keep lnurlData even after bolt11 has been retrieved, add isLnurlPay property and save bolt11 before triggering pay 2023-03-31 15:39:29 +02:00
Sander van Grieken
cf2ba2a5bd qml: replace assert by exception 2023-03-31 15:05:05 +02:00
Sander van Grieken
168efa6cb4 qml: handle scenario for non-lightning wallet scanning lightning invoice with fallback address 2023-03-31 14:42:03 +02:00
Sander van Grieken
b1b71002e6 qml: followup b8aa87ded8 2023-03-31 14:06:12 +02:00
Sander van Grieken
b8aa87ded8 qml: handle phase-2 lnurl errors from within WalletMainView, add sanity check on
the bolt11 invoice we get from the service
2023-03-31 13:21:11 +02:00
Sander van Grieken
d99a220c66 qml: add new 'removed_transaction' callback in wallet.py, hook up callback in qewallet and
emit balanceChanged events for add_transaction and remove_transaction
2023-03-31 12:32:02 +02:00
Sander van Grieken
d064b38f1c qml: split updating userinfo from determine_can_pay, check determine_can_pay also in event handlers 2023-03-30 13:23:14 +02:00
Sander van Grieken
cc60ab0b20 qml: move payment progress info text updates fully into qeinvoice, qeinvoice now updates itself
directly from backend wallet callbacks
2023-03-29 19:08:11 +02:00
Sander van Grieken
7efd6fe1e2 qml: don't show ln payment dialog, update info text instead 2023-03-29 19:08:11 +02:00
ThomasV
5721b7da4b qml: add userinfo to invoices where amount needs to be filled by user 2023-03-29 12:15:07 +02:00
Sander van Grieken
f9a5c22633 qml: lnurl override disabled amount edit color, show lnurlError to user 2023-03-23 14:03:00 +01:00
ThomasV
8e7cbd6ca2 qml: let user enter lnurl6 amount 2023-03-23 13:29:31 +01:00
ThomasV
d7c5c40c1d Save user-entered amount in invoice. fixes #8252.
Note that this allows users to save invoices that have an empty
amount, which is not allowed by the Qt GUI. Qt will complain at
pay time about empty amount if a lightning invoice without amount
is saved. With onchain invoices, Qt will create an onchain tx with
a zero output.
2023-03-18 17:29:56 +01:00
Sander van Grieken
7d2ba3cc39 qml: fix 43d6fd2aef 2023-03-17 16:46:58 +01:00
Sander van Grieken
24a3d6e10f qml: remove editmode toggle, now enabled only on amount-less invoices 2023-03-17 16:46:58 +01:00
Sander van Grieken
a571451179 qml: allow pay while amount in edit mode 2023-03-17 11:51:48 +01:00
ThomasV
43d6fd2aef qml: use get_node_alias in name_for_node_id.
(fixes crash caused by lnworker.channel_db being None with trampoline.)
2023-03-16 08:26:57 +01:00
Sander van Grieken
2881c49671 qml: move technical details to bottom of InvoiceDialog, add routing hints 2023-03-15 15:19:30 +01:00
SomberNight
02a2f02d02 qml: actually do the x509 validation for bip70
as in other GUIs
2023-03-14 17:04:39 +00:00
SomberNight
e14ed717a8 qml: fix paying bip70 invoices 2023-03-14 16:32:14 +00:00
Sander van Grieken
faf0c80893 qml: enable canPay in InvoiceDialog if wallet has insufficient funds to pay via lightning
and invoice has fallback address and amount can be paid on-chain.
In WalletMainView, follow on-chain payment path if available lighting balance is
insufficient for the invoice amount
2023-03-13 18:07:37 +01:00
Sander van Grieken
8e2a5853b8 qml: don't crash on bolt11 invoice when wallet is non-lightning 2023-03-13 17:20:01 +01:00
Sander van Grieken
995754e523 qml: add expiry timers to update status string in InvoiceDialog and ReceiveDialog 2023-02-14 11:36:13 +01:00
Sander van Grieken
d79de092e2 qml: just to be sure, keep QEAmount instances around if exposed to QML 2023-01-16 14:54:42 +01:00
Sander van Grieken
0bc8460005 qml: don't initialize instance variables on class scope for non-singletons
(this somehow escaped attention before, as most objects usually don't have multiple instances,
unless multiple wallets are open at the same time.)
Also, move all signal declarations, class constants and variables to the top of class definitions.
2023-01-12 13:09:21 +01:00
Sander van Grieken
34d39e84f0 qml: don't check min amount for amount-less invoice 2022-10-26 11:18:01 +02:00