53 Commits

Author SHA1 Message Date
6a39a1401a Replace BTC references with PLM in codebase
Update all instances of BTC currency references to PLM across multiple files including UI components, utility functions, and command descriptions to reflect the new currency denomination
2025-11-20 16:43:48 +01:00
Sander van Grieken
eda88b2972 lnaddr: fix outdated doc reference to lnworker._check_invoice
(and clean some imports/whitespace while we're at it)
2025-05-02 15:57:01 +02:00
ThomasV
3721f04ac8 replace electrum/ecc with electrum_ecc package 2024-10-10 15:46:00 +00:00
wakiyamap
1adc0ad4d9 remove BOLT11_HRP_INV_DICT 2024-09-14 09:51:44 +09:00
SomberNight
cf2ed509b4 dependencies: remove bitstring
- `bitstring` started depending on `bitarray` in version 4.1 [0]
  - that would mean one additional dependency for us (from yet another maintainer), which is not even pure python
- we only use bitstring for bolt11-parsing
- hence this PR rewrites the bolt11-parsing and removes `bitstring` as dependency
- note: I benchmarked lndecode using [1], and the new code performs better,
  taking around 80% time needed for old code (when using bitstring 3.1.9, pure python).
  Though the variance is quite large in both cases.

[0]: 95ee533ee4/release_notes.txt (L108)
[1]: d7597d96d0
2024-04-24 14:14:31 +00:00
SomberNight
bd9d0ccc33 ecc: refactor/clean-up sign/verify APIs 2024-04-11 15:25:45 +00:00
SomberNight
22a8348303 renames: use consistent naming of cltv delta vs cltv abs
to avoid confusing relative vs absolute cltvs
(see b0401a6386)
2023-10-19 16:40:05 +00:00
SomberNight
30c863d32c lnaddr: don't call validate_features in parser
- see comment in lnaddr.py
- Previously we used feature bit 50/51 for trampoline.
  The spec subsequently defined fbit 50/51 as option_zeroconf, which
  requires fbit 46/47 (option_scid_alias) to also be set.
  We moved the non-standard trampoline fbit to a different int.
  However, old wallets might have old invoices saved that set fbit 50/51
  for trampoline, and those would not have the dependent bit set.
  Invoices are parsed at wallet-open, so if the parser ran these checks,
  those wallets could not be opened.
- note: we could potentially also run lnaddr.validate_and_compare_features
  when saving new invoices into the wallet but this is not done here
2023-10-16 17:10:49 +00:00
SomberNight
fc6486ecdb lnaddr: make payment_secret field mandatory, in both directions
we now require payment_secret both for sending and for receiving
(previously was optional for both)

see
https://github.com/lightning/bolts/pull/898
https://github.com/ACINQ/eclair/pull/1810
https://github.com/ElementsProject/lightning/pull/4646

note: payment_secret depends on var_onion_optin, so that becomes mandatory as well,
however this commit does not yet remove the ability of creating legacy onions
2023-06-29 14:34:02 +00:00
SomberNight
e2ee79c378 lnaddr: add LnAddr.to_debug_json() method 2023-06-23 19:53:38 +00:00
SomberNight
a3b0e97c88 lnaddr: make min_cltv logic less error-prone
round-tripping the value behaved unexpectedly before...
2023-06-23 19:53:34 +00:00
SomberNight
01b5e3f8e0 flake8: enable more mandatory tests 2022-10-31 16:13:22 +00:00
ThomasV
7102fb732e follow-up prev:
- detect payment of requests both onchain or LN
 - create single type of requests in GUI
2022-04-20 12:48:22 +02:00
SomberNight
4f9e4c520f ecc: API changes: verify_message_hash to return bool instead of raising
verify_message_hash and verify_message_for_address now return bool
instead of raising Exceptions on bad signatures.
2022-02-16 19:24:38 +01:00
bitromortac
c65caf6c68 qt+android: add lightning URI support 2021-07-30 08:44:15 +02:00
bitromortac
6716004b47 bolt11: fix amount encoding for large values 2021-07-30 08:44:15 +02:00
SomberNight
57e52da77f lnaddr: clean-up SEGWIT_HRP vs BOLT11_HRP confusion
With signet, SEGWIT_HRP != BOLT11_HRP, so the previous "currency" string
became a flawed concept. Instead we pass around net objects now.
2021-06-22 16:16:21 +02:00
ghost43
5dff461aaa Merge pull request #7282 from wakiyamap/add_signet
add signet support
2021-06-22 16:15:38 +02:00
SomberNight
a425ab0301 invoices/lnaddr: LNInvoice.from_bech32 now raises InvoiceError
rm LnAddressError

fixes https://github.com/spesmilo/electrum/issues/7321
related https://github.com/spesmilo/electrum/pull/7234
2021-06-07 14:46:30 +02:00
wakiyamap
9f4d7ec6d1 Add net.BOLT11_HRP 2021-05-08 11:53:58 +09:00
bitromortac
853e912885 invoice: fail gracefully with large amount 2021-05-06 15:37:17 +02:00
wakiyamap
639cd94dcb add signet support 2021-05-06 19:47:22 +09:00
SomberNight
4315fa4371 BIP-0350: use bech32m for witness version 1+ addresses
We have supported sending to any witness version since Electrum 3.0, using
addresses as specified in BIP-0173 (bech32 encoding).
BIP-0350 makes a breaking change in address encoding, and recommends using
(and using only) a new encoding (bech32m) for sending to witness version 1
and later. The address encoding for currently in use witness v0 addresses
remains the same, as in BIP-0173; following the BIP-0350 spec.

closes https://github.com/spesmilo/electrum/issues/6949

related:
cd3885c0fb/bip-0350.mediawiki
https://github.com/bitcoin/bitcoin/pull/20861
2021-03-17 18:11:55 +01:00
SomberNight
4069b455d0 lnaddr: add get_features method 2021-03-08 21:36:27 +01:00
SomberNight
d7597d96d0 lnaddr: 15x speedup for lndecode
benchmarked with:

```
import time
import electrum
from electrum.lnaddr import lndecode

electrum.constants.set_testnet()

inv = "lntb4m1p00zfpppp597ely08ffhk8n3emeswukt0y3qfvt3sj3ufkhnaatlrswj2xvwuqsp5vu3ezu44ka8arvgda44yalysp3k3edlvg56cjkk5lvu4e4anmdssdq2v9ekgctnvscqzynxqyz5vq9qypqsqrzjqv8shunq4nda8mw2mpxhtz8v03wlgug7sln2yvqklxym35ayz3erqxct8vqqqcqqqqqqqqlgqqqqqqgq9qrzjqdxvvgt048y4htef7r63r4ha9kctz3d6l3za0053ahe597wgrkc4gxct8cqqqfsqqqqqqqlgqqqqqqgq9qrzjqwyx8nu2hygyvgc02cwdtvuxe0lcxz06qt3lpsldzcdr46my5epmjxct8vqqqdcqqqqqqqlgqqqqqqgq9qrzjqf56jn5txtqqtepnd0ahg0qg5m5mavfajsx403rem9wgu6rue0de7xct8vqqqtgqqqqqqqlgqqqq86qq9qrzjq027z73uyyl7fy8pkrpcn7x0el82pz3fw974p2052de4uz4j5lqqxx49tuqqqwgqqqqqqqqqqqqqqqqqpurzjqfj34n62wztqjxl59w4drxekg04rrrtf08mdestwhtky84ds7ja0yxct8sqqq3qqqqqqqqlgqqqqqqgq9qrzjqd872t5c5r5a8ssmwelpkdccsyn9mrr40rpp7khad4jr3kssxj9nvx49vgqqqnqqqqqqqqlgqqqq05qqgcxwu0ervh6atmqmqv7pmenhmc207gncyj0mcxedpwm8f56y2yl3qpq6mzjak37ddmeayd9unektmffv5rq8dvlpgq00rmmdalda73yhgqep0zuz"

def f():
  for _ in range(100):
    addr = lndecode(inv)

t0 = time.monotonic()
f()
t1 = time.monotonic()
print(f"{t1-t0:.4f}")
```
2021-02-28 16:26:15 +01:00
SomberNight
0aa36ab5ac invoices: validate 'amount' not to be out-of-bounds 2021-02-18 06:11:09 +01:00
ThomasV
ded449233e Trampoline routing.
- trampoline is enabled by default in config, to prevent download of `gossip_db`.
   (if disabled, `gossip_db` will be downloaded, regardless of the existence of channels)
 - if trampoline is enabled:
    - the wallet can only open channels with trampoline nodes
    - already-existing channels with non-trampoline nodes are frozen for sending.
 - there are two types of trampoline payments: legacy and end-to-end (e2e).
 - we decide to perform legacy or e2e based on the invoice:
    - we use trampoline_routing_opt in features to detect Eclair and Phoenix invoices
    - we use trampoline_routing_hints to detect Electrum invoices
 - when trying a legacy payment, we add a second trampoline to the path to preserve privacy.
   (we fall back to a single trampoline if the payment fails for all trampolines)
 - the trampoline list is hardcoded, it will remain so until `trampoline_routing_opt` feature flag is in INIT.
 - there are currently only two nodes in the hardcoded list, it would be nice to have more.
 - similar to Phoenix, we find the fee/cltv by trial-and-error.
    - if there is a second trampoline in the path, we use the same fee for both.
    - the final spec should add fee info in error messages, so we will be able to fine-tune fees
2021-02-17 17:28:13 +01:00
ThomasV
4febbcdc2d encapsulate get_routing_info in lnaddr 2021-02-07 12:21:00 +01:00
ThomasV
2638c818e9 fix #6757: truncate invoice description to 639 bytes 2020-11-26 12:07:03 +01:00
SomberNight
18066c72a0 lnaddr: fix decoding of min_final_cltv_expiry
Previously we failed to decode min_final_cltv_expiry properly if the highest bit was 1:
in practice, we could not pay invoices that had a value in [16-31] or [512-1023].
Many invoices use a value around 144, so this was simply unnoticed.

also update default value to follow BOLT change:
c5693d336d
2020-11-24 23:42:29 +01:00
SomberNight
d5f368c584 LN invoices: support msat precision
fixes #6250
2020-06-22 22:48:13 +02:00
ThomasV
ee59ad13c4 support new protocol (minerFeeInvoice) 2020-06-18 14:28:40 +02:00
ThomasV
6058829870 Use attr.s classes for invoices and requests:
- storage upgrade
 - fixes #6192
 - add can_pay_invoice, can_receive_invoice to lnworker
2020-06-01 21:02:45 +02:00
ThomasV
312ef15cd6 fix #6056 2020-04-11 12:02:38 +02:00
SomberNight
71635216df ln feature bits: validate transitive feature deps everywhere 2020-04-01 21:49:19 +02:00
SomberNight
94e3c078f8 lnaddr: small clean-up 2020-04-01 21:49:16 +02:00
SomberNight
1be0a710c3 ln: implement option payment_secret 2020-04-01 21:49:12 +02:00
SomberNight
4b78bf94d4 lnaddr: add feature bit support to invoices
see https://github.com/lightningnetwork/lightning-rfc/pull/656
2020-04-01 21:42:52 +02:00
SomberNight
7962e17df6 invoices: deal with expiration of "0" mess
Internally, we've been using an expiration of 0 to mean "never expires".
For LN invoices, BOLT-11 does not specify what an expiration of 0 means.
Other clients seem to treat it as "0 seconds" (i.e. already expired).
This means there is no way to create a BOLT-11 invoice that "never" expires.

For LN invoices,
- we now treat an expiration of 0, , as "0 seconds",
- when creating an invoice, if the user selected never, we will put 100 years as expiration
2020-03-04 14:24:07 +01:00
SomberNight
b99add59c3 lnworker: introduce PaymentAttemptLog NamedTuple 2019-12-10 03:17:57 +01:00
SomberNight
8dabdf8bfb qt send tab: handle invalid ln invoice; and ln invoice with ln disabled
fixes #5639
fixes #5662
2019-10-01 19:15:26 +02:00
JeremyRand
8be94a9919 lnaddr: Pull in Bech32 and Base58 prefixes from constants
Fixes https://github.com/spesmilo/electrum/issues/5581
2019-08-25 13:15:13 +00:00
ThomasV
f9a2e7eeb4 lnworker.get_invoice_status: test if invoice is expired 2019-08-20 09:03:12 +02:00
ThomasV
f2d58d0e3f optimize channel_db:
- use python objects mirrored by sql database
 - write sql to file asynchronously
 - the sql decorator is awaited in sweepstore, not in channel_db
2019-08-20 09:03:12 +02:00
ThomasV
e53ecb9b77 add labels to lightning history 2019-08-20 09:03:11 +02:00
ThomasV
d134937269 update regexp syntax 2019-08-20 09:03:11 +02:00
Janus
762d8be84f lnaddr: make it possible to use lnaddr to decode arbitrary invoices on the cmd line 2019-08-20 09:03:11 +02:00
Janus
e3409d32ef channel details with list of htlcs 2019-08-20 09:03:11 +02:00
SomberNight
e6a0b641d5 lnaddr: encode min_final_cltv into invoice 2019-08-20 09:03:10 +02:00
ThomasV
9a59ffaf44 lnrouter: filter out unsuitable channels 2019-08-20 09:03:10 +02:00