1
0
Commit Graph

259 Commits

Author SHA1 Message Date
SomberNight
f86229f169 Merge pull request #8091 from zouppen/convert_currency_cmd
Add command for currency conversions
2022-12-06 18:29:49 +00:00
Joel Lehtonen OH64K
a24a928e9f commands: Make conversion to/from BTC the default
As suggested by SomberNight in PR #8091, the difference is that this
commit handles currencies in case-insensitive manner.

Co-authored-by: ghost43 <somber.night@protonmail.com>
2022-12-06 16:46:15 +02:00
Joel Lehtonen
62711a57bc commands: Better default currencies in convert_currency
Co-authored-by: ghost43 <somber.night@protonmail.com>
2022-12-06 04:19:48 +02:00
Joel Lehtonen
09170bdd1f commands: Improve error messages in convert_currency
Co-authored-by: ghost43 <somber.night@protonmail.com>
2022-12-06 03:30:24 +02:00
Joel Lehtonen OH64K
cdc1660d47 commands: Remove unused requested_amount and fix a typo (#8090) 2022-12-05 22:31:16 +00:00
Joel Lehtonen
02dba54ab9 commands: Add command "convert_currency"
This adds command "convert_currency" which allows the user to do
currency conversions via command line or JSON RPC. Wallet not
required.
2022-12-05 23:29:37 +02:00
SomberNight
7db396aad9 follow-up prev: indentations should not use tabs in *.py
re https://github.com/spesmilo/electrum/pull/8044
2022-10-31 15:26:27 +00:00
mrmena
6dc4b4f3b3 modified the way the constants module is accessed 2022-10-30 16:03:16 +11:00
mrmena
7a53b2cd47 added network type to getinfo 2022-10-30 15:25:12 +11: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
70da10d662 fix watchtower regtest flakiness caused by CTN variability. fixes #7961 2022-09-01 09:56:46 +02:00
ThomasV
6a9e8da218 remove sign_payment_request: broken and not used 2022-08-29 12:50:02 +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
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
ThomasV
f5abd4f1d1 add command line for rebalancing channels 2022-07-13 10:14:34 +02:00
ThomasV
9ae0e5bffc remove lightning parameter from wallet.create_request 2022-07-11 13:52:13 +02:00
Sander van Grieken
1df5187719 qml: add 'qml' gui option and add gui.qml.ELectrumGui to type hint for gui_object 2022-07-07 18:28:00 +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
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
SomberNight
58be69afd3 commands: add "encrypt_file" arg to "password" command 2022-05-26 21:41:29 +02:00
SomberNight
d128391ea0 daemon: add command-line args for RPC user/pass/host/port
based on c50d8d754c
2022-05-13 16:48:50 +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
ThomasV
f4e902e907 LNWorker: give up payment after timeout, not number of attempts.
Limiting attempts may interrupt a MPP before we receive a MPP_timeout
The attempts parameter is still used in unit tests.
2022-04-29 12:17:38 +02:00
ThomasV
e3beae5c00 Merge pull request #7761 from SomberNight/202204_versioninfo_cmd
add `version_info` command
2022-04-27 09:59:27 +02:00
ThomasV
bf4455ef30 follow-up db invoice unification:
- fix command line
 - deprecate add_lightning_request
2022-04-20 12:48:22 +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
SomberNight
e47e0afa91 commands: add "version_info" cmd
example:
```
$ ./run_electrum -o version_info
{
    "aiohttp.version": "3.8.1",
    "aiorpcx.version": "0.22.1",
    "certifi.version": "2021.10.08",
    "cryptodome.version": null,
    "cryptography.path": "/home/user/.local/lib/python3.8/site-packages/cryptography",
    "cryptography.version": "3.4.6",
    "dnspython.version": "2.2.0",
    "electrum.path": "/home/user/wspace/electrum/electrum",
    "electrum.version": "4.2.1",
    "hidapi.version": "0.11.0.post2",
    "libsecp256k1.path": "/home/user/wspace/electrum/electrum/libsecp256k1.so.0",
    "libusb.path": "libusb-1.0.so",
    "libusb.version": "1.0.23.11397",
    "libzbar.path": "/home/user/wspace/electrum/electrum/libzbar.so.0",
    "pyaes.version": "1.3.0",
    "pyqt.path": "/usr/lib/python3/dist-packages/PyQt5",
    "pyqt.version": "5.14.1",
    "qt.version": "5.12.8"
}
```
2022-04-11 17:40:22 +02:00
ThomasV
cb39bbbd94 lnworker: make calc_routing_hints_for_invoice and create_invoice non-async 2022-03-29 17:42:04 +02:00
johlar
c3506911c0 Add support for cli --version command 2022-02-17 17:53:51 +01:00
SomberNight
3643b9f056 daemon: rework stopping
The CLI stop() command can now also stop the GUI.
2021-11-05 19:57:39 +01:00
yanmaani
b1005694ec cli: Add support for Unix domain sockets 2021-11-03 12:00:00 +00:00
Siddhant Chawla
65c3a892cf Multiple max spends functionality added (#7492)
this implements https://github.com/spesmilo/electrum/issues/7054
2021-09-15 14:35:15 +00:00
Siddhant Chawla
e9f08ef69e Adding BumpFee command to the CLI (#7438)
closes https://github.com/spesmilo/electrum/issues/5791
2021-08-11 11:30:26 +00:00
MrNaif2018
299214835f Add lightning tag for commands 2021-07-12 19:16:34 +03:00
SomberNight
6a049d9901 wallet: make sure payment requests are persisted
Fixes: after adding a payment request, if the process was killed,
the payreq might get lost. In case of using the GUI, neither the
callee nor the caller called wallet.save_db().

Unclear where wallet.save_db() should be called...
Now each method tries to persist their changes by default,
but as an optimisation, the caller can pass write_to_disk=False
e.g. when calling multiple such methods and then call wallet.save_db() itself.

If we had partial writes, which would either rm the need for wallet.save_db()
or at least make it cheaper, this code might get simpler...

related: https://github.com/spesmilo/electrum/pull/6435
related: https://github.com/spesmilo/electrum/issues/4823
2021-07-05 18:39:10 +02:00
ghost43
5dff461aaa Merge pull request #7282 from wakiyamap/add_signet
add signet support
2021-06-22 16:15:38 +02:00
SomberNight
66f68d6b1f commands: fix "close_wallet" cmd, which was deadlocking
fixes #7348
2021-06-17 12:35:31 +02:00
Nima
13e4424922 cmd: add sign with privkey and wallet (#7147)
* Remove check for sign with privkey in init_cmdline

* Add with_privkey and with_wallet variants of signtransaction command

* Add unit tests for signtransaction_with_privkey and signtransaction_with_wallet commands
2021-06-08 14:33:55 +00:00
bitromortac
3c02f6b922 swaps: fix satoshi conversion bug 2021-05-19 07:27:54 +02:00
wakiyamap
639cd94dcb add signet support 2021-05-06 19:47:22 +09:00
bitromortac
4cb0b99996 lnworker: fix path_finder access 2021-04-26 08:43:50 +02:00
ghost43
0f83270053 Merge pull request #7152 from bitromortac/2103-liquidity-hints
Liquidity hints for pathfinding
2021-04-22 14:45:41 +00:00
ThomasV
75d77c55d6 commands, input sanitization: allow 'max' amounts only in specific contexts (payto, paytomany) 2021-04-16 16:03:25 +02:00
bitromortac
5e03d751eb lnrouter: add hint timestamp 2021-04-09 11:11:22 +02:00
bitromortac
4df67a4f78 lnrouter+lnworker: use liquidity hints
Adds liquidity hints for the sending capabilities of routing channels in the
graph. The channel blacklist is incorporated into liquidity hints.
Liquidity hints are updated when a payment fails with a temporary
channel failure or when it succeeds. Liquidity hints are used to give a
penalty in the _edge_cost heuristics used by the pathfinding algorithm.
The base penalty in (_edge_cost) is removed because it is now part of the
liquidity penalty. We don't return early from get_distances, as we want
to explore all channels.
2021-04-06 20:13:42 +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
SomberNight
5beadaab95 commands: clean-up inject_fees cmd 2021-03-25 19:33:40 +01:00
SomberNight
638d4f7472 commands: fix signtransaction cmd when used with "privkey" arg
A naive "solver" is implemented locally for p2pkh-like inputs.
Other more complex scripts cannot be signed atm without a wallet.

closes https://github.com/spesmilo/electrum/issues/7117
2021-03-24 20:52:35 +01:00
ThomasV
64a931f21e Deterministic NodeID:
- use_recoverable_channel is a user setting, available
   only in standard wallets with a 'segwit' seed_type
 - if enabled, 'lightning_xprv' is derived from seed
 - otherwise, wallets use the existing 'lightning_privkey2'

Recoverable channels:
 - channel recovery data is added funding tx using an OP_RETURN
 - recovery data = 4 magic bytes + node id[0:16]
 - recovery data is chacha20 encrypted using funding_address as nonce.
   (this will allow to fund multiple channels in the same tx)

GUI:
  - whether channels are recoverable is shown in wallet info dialog.
  - if the wallet can have recoverable channels but has an old node_id,
    users are told to close their channels and restore from seed
    to have that feature.
2021-03-19 10:17:02 +01:00