1
0
Commit Graph

75 Commits

Author SHA1 Message Date
SomberNight
72e1be6f5e swaps: rm support for p2wsh-p2sh lockup scripts
- unused
- the client was already refusing to fund such lockup addresses (if the server asked)
- no existing unit tests for it, and as the choice is up to the server, it is hard to create tests
- no clear reason to want to use p2sh-nested scripts here, aside from curiosity
2023-02-17 14:10:03 +00:00
SomberNight
8a4c06b692 swaps: small refactor and add unit tests for claim tx 2023-02-17 14:04:03 +00:00
ThomasV
5e88b0da88 swaps: cache pairs to file 2023-02-11 10:27:12 +01:00
ThomasV
215629235d submarine_swaps: fix bugs and create method for max_amount_forward_swap 2023-02-11 10:21:01 +01:00
ThomasV
f617887509 RBF dialog: do not decrease payment for swap funding transactions. 2023-02-10 16:30:08 +01:00
SomberNight
e3485de496 qt gui: handle swap server unreachable
note: testnet swap server is offline atm
closes https://github.com/spesmilo/electrum/issues/8107
2023-01-01 23:43:25 +00:00
ThomasV
3131fde97b submarine swaps: set rbf for CLI transactions
(it was already the case with GUI)
2022-12-07 13:26:29 +01:00
SomberNight
5b0aad5084 network: rename _send_http_on_proxy and make it part of public API 2022-06-28 18:51:21 +02:00
ThomasV
53c054ece4 swaps: set spending_txid as soon as tx is added to wallet
This fixes the GUI not displaying the label of the transaction immediately
2022-06-13 10:27:40 +02:00
ThomasV
121d8732f1 Persist LNWatcher transactions in wallet file:
- separate AddressSynchronizer from Wallet and LNWatcher
 - the AddressSynchronizer class is referred to as 'adb' (address database)
 - Use callbacks to replace overloaded methods
2022-06-10 13:07:53 +02:00
ThomasV
5bb99ddfaf submarine_swaps: fix order of operations in get_send_amount 2022-05-24 18:51:09 +02:00
ThomasV
feb10bc67b remove unneeded parameter (follow-up e392197ab9) 2022-05-24 13:33:16 +02:00
ThomasV
53151244e2 LNWorker: Add suggest_rebalance methods for sending and receiving.
These methods return a list of channels that can be rebalanced,
in order to receive or send a given amount.

Also add 'channels' parameter to submarine swaps.
Previously, swaps were not considering which channel to use.

When we do not have liquidity to pay an invoice:
 - add 'rebalance' option in order to pay an invoice
 - use the suggested channel in the 'swap' option

When we do not have the liquidity to receive an invoice:
 - add 'Rebalance' and 'Swap' buttons to the receive tab
2022-05-21 20:25:44 +02:00
SomberNight
2ec9e869b3 invoice.get_amount_sat: handle None in more places
I believe lightning requests created before https://github.com/spesmilo/electrum/pull/7730
can have an amount of None - ones created after have amount 0 instead.
We could do a wallet db upgrade potentially.
Regardless, the type hint is `get_amount_sat(self) -> Union[int, str, None]`,
so None should be handled. (well, arguably "!" should be handled too...)

```
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
  File "...\electrum\electrum\gui\qt\request_list.py", line 101, in item_changed
    self.parent.show_receive_request(req)
  File "...\electrum\electrum\gui\qt\main_window.py", line 1279, in show_receive_request
    URI = req.get_bip21_URI(lightning=bip21_lightning)
  File "...\electrum\electrum\invoices.py", line 164, in get_bip21_URI
    amount = int(self.get_amount_sat())
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
```

```
E | gui.qt.exception_window.Exception_Hook | exception caught by crash reporter
Traceback (most recent call last):
  File "...\electrum\electrum\gui\qt\request_list.py", line 101, in item_changed
    self.parent.show_receive_request(req)
  File "...\electrum\electrum\gui\qt\main_window.py", line 1281, in show_receive_request
    can_receive_lightning = self.wallet.lnworker and req.get_amount_sat() <= self.wallet.lnworker.num_sats_can_receive()
TypeError: '<=' not supported between instances of 'NoneType' and 'decimal.Decimal'
```
2022-05-19 19:43:07 +02: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
ThomasV
e392197ab9 wallet_db upgrade:
- unify lightning and onchain invoices, with optional fields for bip70 and lightning
 - add receive_address fields to submarine swaps
2022-04-20 12:48:22 +02:00
ThomasV
877a9f553b Merge pull request #7748 from spesmilo/confirm_reverse_swaps
Confirm reverse swaps
2022-04-09 10:41:02 +02:00
SomberNight
0226e7196d swaps: build index(es) for the swaps dict to avoid linear scanning 2022-04-01 21:30:41 +02:00
ThomasV
f01197b6b5 Reverse swaps: Wait until funding tx is confirmed
- override with allow_instant_swaps option (Qt)
2022-04-01 14:05:01 +02:00
ThomasV
670f8dbe42 submarine_swaps: use prevout to determine if a txin is claiming a swap 2022-04-01 13:55:36 +02:00
SomberNight
e36d7fed7d swaps: more precise tx size estimation for claim tx when RBF-ing 2022-03-31 20:55:11 +02:00
SomberNight
357aaff582 swaps: when RBF-ing a forward swap tx, payment amt must not decrease 2022-03-30 19:01:57 +02:00
ThomasV
1364e7538a bump fee of swap claim transactions
Note: This adds a new field, spent_txid, to PartialTxOutput
2022-03-30 13:44:10 +02:00
SomberNight
f52c0fd571 lnchannel: rm HTLC value upper limit of ~42 mBTC
closes #7328
closes #7100
see https://github.com/lightningnetwork/lightning-rfc/pull/877#issuecomment-857577075
2021-06-10 17:26:04 +02:00
bitromortac
b97e51dbd8 swaps: fix off-by-one sanity check
Tolerates discrepancies in the swap amount crosschecks. To ensure we
calculate the send/receive amounts correctly we apply a check, using
amount inversion. The inversion is not exact up to +-1 due to used
floor and ceil functions in the methods. They are not invertible,
which is why we relax the check to off-by-ones.
2021-04-23 07:43:36 +02:00
SomberNight
63ea5587a2 swaps: revise send/recv amount calculation
- document SwapManager._get_recv_amount and SwapManager._get_send_amount
- change calculations so that they match the boltz-backend
  - note that in the reverse swap case, the server does not care about the on-chain claim tx the client
    needs to pay for. This introduced some implicit hacks and inconsistencies in the code in the past,
    it is still a bit ugly but at least this is now explicit.
- SwapManager._get_recv_amount and SwapManager._get_send_amount are now proper inverses of each other

-----

Here are some code snippets to play around with in Qt console.
For the forward swap case:
```
from electrum import ecc; lnworker = wallet.lnworker; sm = lnworker.swap_manager

invoice = network.run_from_another_thread(lnworker.create_invoice(amount_msat=3000000*1000, message="swap", expiry=86400))[1]; request_data = {"type": "submarine", "pairId": "BTC/BTC", "orderSide": "sell", "invoice": invoice, "refundPublicKey": ecc.GENERATOR.get_public_key_bytes().hex()}

network.send_http_on_proxy('post', sm.api_url + '/createswap', json=request_data, timeout=30)

sm.get_send_amount(3000000, is_reverse=False)
sm.get_recv_amount(3026730, is_reverse=False)
```

For the reverse swap case:
```
from electrum import ecc; import os; lnworker = wallet.lnworker; sm = lnworker.swap_manager

request_data = {"type": "reversesubmarine", "pairId": "BTC/BTC", "orderSide": "buy", "invoiceAmount": 3000000, "preimageHash": os.urandom(32).hex(), "claimPublicKey": ecc.GENERATOR.get_public_key_bytes().hex()}

network.send_http_on_proxy('post', sm.api_url + '/createswap', json=request_data, timeout=30)

sm.get_recv_amount(3000000, is_reverse=True)
sm.get_send_amount(2974443, is_reverse=True)
```
2021-03-28 18:36:04 +02:00
ThomasV
41f22df26b submarine swaps: use num_sats_can_receive_no_mpp, to prevent funds being locked 2021-03-26 16:27:32 +01:00
ThomasV
0c93394513 rename lnworker._pay to pay_invoice, call it directly from GUIs 2021-02-07 12:09:37 +01:00
SomberNight
337d4890a1 lnworker/swaps: add '_sat' suffix to arg names and force kwargs 2021-02-01 22:11:56 +01:00
SomberNight
3d1796ab1d follow-up prev: fix units when calling lnworker.create_invoice: msat/sat
follow-up e477a43385
2021-02-01 22:08:09 +01:00
bitromortac
64ecf8539a swaps: fix normal amount formulas
In a normal (forward) swap (onchain->offchain):
send_amount = receive_amount * (1 + service_percentage) + normal_fee ,
and vice versa:
receive_amount = (send_amount + normal_fee) / (1 + service_percentage) ,
i.e., the service fee is charged on the received offchain amount.
2020-12-17 07:25:54 +01:00
SomberNight
89bd520185 bitcoin: move construct_witness from transaction.py to bitcoin.py 2020-10-24 05:18:16 +02:00
ThomasV
edc593a886 submarine swap: add comment to explain witness script asymmetry 2020-10-22 17:24:44 +02:00
SomberNight
08f70420e3 submarine_swaps: describe event-flow for both swap direction in docstr
So that I don't have to figure out every time.
2020-10-22 17:22:35 +02:00
SomberNight
1d187d36f0 (fix) allow opening LN wallet with --offline 2020-10-15 14:20:51 +02:00
ThomasV
5f7d8cc462 reverse swap: check that received amount is higher than dust threshold 2020-09-03 16:40:11 +02:00
ThomasV
e9829563d3 forward swaps: save the onchain amount we actually paid 2020-06-26 11:42:55 +02:00
ThomasV
abac4a4340 swaps: check_invoice_amount (fixes #6217) 2020-06-26 09:19:40 +02:00
ThomasV
599797c966 swaps: update server URL 2020-06-22 12:15:31 +02:00
ThomasV
4bda882695 Group swap transactions in Qt history (fixes #6237)
- use tree structure of QTreeView
 - grouped items have a 'group_id' field
 - rename 'Normal' swap as 'Forward'
2020-06-22 11:26:49 +02:00
SomberNight
9385d2dae3 submarine_swaps: minor clean-up (preimage/locktime) 2020-06-21 08:36:40 +02:00
ThomasV
a03d8dc6ac swaps: add testnet url 2020-06-19 14:17:42 +02:00
ThomasV
4344ca47b3 swaps: create invoice without saving the request 2020-06-19 10:31:18 +02:00
SomberNight
fcbc1c9a45 submarine_swaps: increase min locktime delta for reverse swap to 60
10 blocks is not enough to get a tx confirmed without worrying...
2020-06-18 22:25:38 +02:00
SomberNight
c2ffc6ca3a qt swap_dialog: "max" now takes into account the server-provided value 2020-06-18 21:52:48 +02:00
ThomasV
a033cfeee8 submarine swaps: fee_invoice is now a hold invoice 2020-06-18 21:39:30 +02:00
SomberNight
7570c8c1c6 qt swap_dialog: "max" button now respects max htlc value 2020-06-18 21:03:49 +02:00
SomberNight
a74552f3dd qt main_window: fix threading for run_coroutine_from_thread 2020-06-18 20:43:34 +02:00
SomberNight
2be2a510ff submarine_swaps: replace asserts with Exceptions 2020-06-18 19:45:07 +02:00
SomberNight
1849206394 submarine_swaps: small clean-up 2020-06-18 18:18:33 +02:00