Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
env:
# what the docker compose commands of the steps work on
COMPOSE_FILE: tests/docker-compose.yml
TEST_SERVICES: node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
TEST_SERVICES: node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws

strategy:
fail-fast: false
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
- name: Install the Python test requirements (tests/requirements.txt)
run: pip3 install -r tests/requirements.txt --break-system-packages

- name: Start the test environment (2 nodes and 3 wallet rpc servers in docker)
- name: Start the test environment (2 nodes, 3 wallet rpc servers and monero-lws in docker)
if: ${{ matrix.docker }}
run: |
read -r -a services <<< "$TEST_SERVICES"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ For example: `export LD_PRELOAD=/path/to/libjemalloc.so.2` then run your app. It
```
3. Start the regtest network of the integration tests in docker (two daemons and three wallet RPC servers), run them, and stop it:
```bash
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws
pytest -m integration
docker compose -f tests/docker-compose.yml down -v
```
Expand Down
2 changes: 1 addition & 1 deletion bin/setup_test_environment.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

# start docker containers
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws
5 changes: 5 additions & 0 deletions bin/stop_wallet_rpc_servers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

# stop the wallet rpc servers of the test environment, only the rpc wallet tests use them
# the containers and their volumes stay, setup_test_environment.sh starts them again
sudo docker compose -f tests/docker-compose.yml stop xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
3 changes: 2 additions & 1 deletion docs/mkdocs/docs/en/api/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ to, or a wallet server for the RPC wallet.

## The daemon and the wallets

The daemon has one implementation, the wallet has three. Each wallet implements the same interface, [`MoneroWallet`][monero.MoneroWallet],
The daemon has one implementation, the wallet has four. Each wallet implements the same interface, [`MoneroWallet`][monero.MoneroWallet],
and code written for it works with any of them, within what each one supports ([Wallet Support](wallet_support.md)).

| Class | What it is made on | What it needs |
| --- | --- | --- |
| [`MoneroDaemonRpc`][monero.MoneroDaemonRpc] | a client of the RPC of `monerod`, over HTTP(S) | a daemon |
| [`MoneroWalletFull`][monero.MoneroWalletFull] | `wallet2` in the process: a wallet file on disk, which syncs with a daemon | a daemon to sync with |
| [`MoneroWalletRpc`][monero.MoneroWalletRpc] | a client of `monero-wallet-rpc`, over HTTP(S): the wallet files are on the server | a wallet server, connected to a daemon |
| [`MoneroWalletLight`][monero.MoneroWalletLight] | a client of [`monero-lws`](https://github.com/vtnerd/monero-lws), which scans the chain for it: the wallet keeps the spend key and signs | a `monero-lws` server |
| [`MoneroWalletKeys`][monero.MoneroWalletKeys] | the keys of a wallet alone, in memory: seed, keys, addresses | nothing, it works offline |

The connection to a server is a [`MoneroRpcConnection`][monero.MoneroRpcConnection]: its URI, its credentials, a proxy, and the time to
Expand Down
6 changes: 3 additions & 3 deletions docs/mkdocs/docs/en/api/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ title: Wallet Interface
---
# Wallet Interface

[`MoneroWallet`][monero.MoneroWallet] is the interface that the three wallets implement: code written for it works with a
[full](wallet_full.md), an [RPC](wallet_rpc.md) or a [keys-only](wallet_keys.md) wallet, within what each one supports
([Wallet Support](wallet_support.md), which groups its methods by topic).
[`MoneroWallet`][monero.MoneroWallet] is the interface that the four wallets implement: code written for it works with a
[full](wallet_full.md), an [RPC](wallet_rpc.md), a [light](wallet_light.md) or a [keys-only](wallet_keys.md) wallet, within what each
one supports ([Wallet Support](wallet_support.md), which groups its methods by topic).

| Topic | Methods |
| --- | --- |
Expand Down
66 changes: 66 additions & 0 deletions docs/mkdocs/docs/en/api/wallet_light.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Light Wallet
---
# Light Wallet

A light wallet is a client of [`monero-lws`](https://github.com/vtnerd/monero-lws), the light wallet server: the server scans the chain
for the wallet, which does not download blocks. The wallet keeps the keys in memory, builds and signs its transactions, and sends them
through the server.

!!! warning "The server learns the private view key"

The wallet gives the server its primary address and its private view key: the server sees what the wallet receives. The spend key
stays in the wallet, so the server can not spend the funds. Use a server that you run, or one that you trust with that.

## Creating and opening

The server is a [`MoneroRpcConnection`][monero.MoneroRpcConnection], given when the wallet is made:

```python
from monero import MoneroNetworkType, MoneroRpcConnection, MoneroWalletConfig, MoneroWalletLight

server = MoneroRpcConnection("http://localhost:8443")

# a new wallet, whose account is registered on the server
config = MoneroWalletConfig()
config.network_type = MoneroNetworkType.STAGENET
wallet = MoneroWalletLight.create_wallet(config, server)
seed = wallet.get_seed()
wallet.close()

# the same wallet later, from its seed
config.seed = seed
wallet = MoneroWalletLight.open_wallet(config, server)

wallet.sync() # fetch what the server has scanned
wallet.start_syncing(5000) # and keep fetching it, every 5 seconds
print(wallet.get_balance())
wallet.close()
```

A light wallet has no file: it is opened from its `seed`, or from its `primary_address` and `private_view_key`, with the
`private_spend_key` or without it, which makes it view-only. [`create_wallet`][monero.MoneroWalletLight.create_wallet] fails when the
server already has the account, [`wallet_exists`][monero.MoneroWalletLight.wallet_exists] tells whether it has it.

A server may wait for its administrator to accept a new account before it scans it.

## Accounts, subaddresses and restore height

- The server reports the transactions of the accounts and subaddresses that are registered on it.
[`create_account`][monero.MoneroWallet.create_account] and [`create_subaddress`][monero.MoneroWallet.create_subaddress] register them,
without a label. To restore a wallet that already used more of them, set `account_lookahead` and `subaddress_lookahead` in the config,
both together.
- `restore_height` asks the server to scan the account again from that height. A server may ask for a payment to do it: the wallet then
raises an error with the address and the amount.

## What it does differently

- The server does not report the transactions of the pool: the wallet sees a transaction that it receives after its first confirmation.
It reports the ones that it sends as unconfirmed on its own, and forgets them when it is closed.
- It does not keep the payment id of the transactions that it creates.
- Its listeners are called after a sync, with what the server has scanned since the one before.
- Nothing is saved: [`close`][monero.MoneroWallet.close] refuses `save=True`.
- No attributes, labels, account tags, notes or address book, no transaction, spend or reserve proofs, no multisig and no mining
([Wallet Support](wallet_support.md)).

::: monero.MoneroWalletLight
11 changes: 6 additions & 5 deletions docs/mkdocs/docs/en/api/wallet_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ title: Wallet Support
# Wallet Support

Which methods of the [wallet interface][monero.MoneroWallet] each wallet implements: the [full wallet][monero.MoneroWalletFull], the
[RPC wallet][monero.MoneroWalletRpc] and the [keys-only wallet][monero.MoneroWalletKeys]. A method that a wallet does not implement
raises an error that says it is not supported. The unit tests call every method on each wallet and fail when this table says otherwise.
[RPC wallet][monero.MoneroWalletRpc], the [light wallet][monero.MoneroWalletLight] and the [keys-only wallet][monero.MoneroWalletKeys].
A method that a wallet does not implement raises an error that says it is not supported. The unit tests call every method on each wallet
and fail when this table says otherwise.

{% set icons = {
"supported": ':material-check:{ .wallet-support--supported title="Supported" }',
Expand All @@ -25,9 +26,9 @@ raises an error that says it is not supported. The unit tests call every method
{% for section, methods in wallet_support.items() %}
## {{ section }}

| Method | Full | RPC | Keys-only |
| --- | :---: | :---: | :---: |
| Method | Full | RPC | Light | Keys-only |
| --- | :---: | :---: | :---: | :---: |
{% for method, entry in methods.items() -%}
| [`{{ method }}`][monero.MoneroWallet.{{ method }}]{% if entry.get("note") %}<br><small>{{ entry["note"] }}</small>{% endif %} | {{ icons[entry["full"]] }} | {{ icons[entry["rpc"]] }} | {{ icons[entry["keys"]] }} |
| [`{{ method }}`][monero.MoneroWallet.{{ method }}]{% if entry.get("note") %}<br><small>{{ entry["note"] }}</small>{% endif %} | {{ icons[entry["full"]] }} | {{ icons[entry["rpc"]] }} | {{ icons[entry["light"]] }} | {{ icons[entry["keys"]] }} |
{% endfor %}
{% endfor %}
2 changes: 1 addition & 1 deletion docs/mkdocs/docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Contributions can be made via issues and pull requests on GitHub, or communicate
## What it has

- **Daemon**: `MoneroDaemonRpc`, a client of `monerod`: blocks, transactions, the pool, peers, mining, and listeners of the new blocks
- **Wallets**: three implementations of `MoneroWallet`: `MoneroWalletFull`, a wallet file that syncs with a daemon through the wallet of monero-project; `MoneroWalletRpc`, a client of `monero-wallet-rpc`; `MoneroWalletKeys`, the keys and the addresses of a wallet, offline. [Wallet Support](api/wallet_support.md) says what each of them does
- **Wallets**: four implementations of `MoneroWallet`: `MoneroWalletFull`, a wallet file that syncs with a daemon through the wallet of monero-project; `MoneroWalletRpc`, a client of `monero-wallet-rpc`; `MoneroWalletLight`, a client of `monero-lws`, which scans the chain for it; `MoneroWalletKeys`, the keys and the addresses of a wallet, offline. [Wallet Support](api/wallet_support.md) says what each of them does
- **Data model**: blocks, transactions, transfers, outputs and the queries that filter them, all serializable to JSON
- **Utilities**: `MoneroUtils`: the validation of addresses, keys and seeds, amounts in atomic units, payment uris
- **Platforms**: deb packages for Debian and Ubuntu on amd64, arm64 and armhf, and wheels for macOS and Windows, with every [release](https://github.com/libmonero/monero-python/releases)
Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ nav:
- Interface: 'api/wallet.md'
- RPC: 'api/wallet_rpc.md'
- Full: 'api/wallet_full.md'
- Light: 'api/wallet_light.md'
- Keys-Only: 'api/wallet_keys.md'
- Support: 'api/wallet_support.md'
- Utils:
Expand Down
5 changes: 5 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
minversion = 9.0
required_plugins = pytest-rerunfailures pytest-timeout pytest-cov
addopts = -s -v --reruns 5 --reruns-delay 10 --only-rerun "Daemon is busy"
timeout = 900
log_level = INFO
log_cli = True
log_cli_level = INFO
Expand All @@ -15,5 +16,9 @@ testpaths =
markers =
unit: fast unit tests, no external dependencies
integration: slow integration tests, requires external services
wallet_full: tests of the full wallet, added to the classes of each wallet type by tests/wallet/conftest.py
wallet_rpc: tests of the rpc wallet
wallet_keys: tests of the keys-only wallet
wallet_light: tests of the light wallet
not_supported: inherited test whose operation is permanently unsupported for this type; passes when it raises a "not supported" error, fails otherwise
not_implemented: inherited test whose operation is not implemented yet; applied as a strict xfail (xfails while it raises, fails once the feature lands, so that the marker is removed)
3 changes: 3 additions & 0 deletions src/cpp/py_monero_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ PYBIND11_MAKE_OPAQUE(VectorUint64);
#include "wallet/monero_wallet_rpc.h"
#include "wallet/monero_wallet_keys.h"
#include "wallet/monero_wallet_full.h"
#include "wallet/monero_wallet_light.h"
#include "utils/py_monero_utils.h"

// The destructor of a daemon or of a wallet waits for the thread of its poller to finish, and that thread can be calling a listener of
Expand Down Expand Up @@ -177,6 +178,7 @@ struct PyMoneroTypes {
py::class_<monero_wallet_keys, monero_wallet, std::shared_ptr<monero_wallet_keys>> py_monero_wallet_keys;
py::class_<monero_wallet_full, monero_wallet, std::shared_ptr<monero_wallet_full>> py_monero_wallet_full;
py::class_<monero_wallet_rpc, monero_wallet, std::shared_ptr<monero_wallet_rpc>> py_monero_wallet_rpc;
py::class_<monero_wallet_light, monero_wallet_keys, std::shared_ptr<monero_wallet_light>> py_monero_wallet_light;
py::class_<PyMoneroUtils> py_monero_utils;
py::class_<PyGenUtils> py_gen_utils;

Expand Down Expand Up @@ -230,6 +232,7 @@ struct PyMoneroTypes {
py_monero_wallet(m, "MoneroWallet"),
py_monero_wallet_keys(m, "MoneroWalletKeys"),
py_monero_wallet_full(m, "MoneroWalletFull"),
py_monero_wallet_light(m, "MoneroWalletLight"),
py_monero_wallet_rpc(m, "MoneroWalletRpc"),
py_monero_utils(m, "MoneroUtils"),
py_gen_utils(m, "GenUtils"),
Expand Down
18 changes: 18 additions & 0 deletions src/cpp/wallet/py_monero_wallet_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,24 @@ void py_monero_bind_wallet(py::module_& m, PyMoneroTypes& t) {
MONERO_CATCH_AND_RETHROW(py::bytes(self.get_cache_file_buffer()));
});

// monero_wallet_light
t.py_monero_wallet_light
.def_static("wallet_exists", [](const std::string& primary_address, const std::string& private_view_key, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::wallet_exists(primary_address, private_view_key, rpc));
}, py::arg("primary_address"), py::arg("private_view_key"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def_static("wallet_exists", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::wallet_exists(config, rpc));
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def_static("open_wallet", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::open_wallet(config, rpc));
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def_static("create_wallet", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
MONERO_CATCH_AND_RETHROW(monero_wallet_light::create_wallet(config, rpc));
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
.def("get_rpc_connection", [](monero_wallet_light& self) {
MONERO_CATCH_AND_RETHROW(self.get_rpc_connection());
}, py::call_guard<py::gil_scoped_release>());

// monero_wallet_rpc
t.py_monero_wallet_rpc
.def(py::init([](const std::shared_ptr<monero_rpc_connection>& rpc_connection) {
Expand Down
2 changes: 2 additions & 0 deletions src/monero/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ from .monero_wallet_full import MoneroWalletFull
from .monero_wallet_keys import MoneroWalletKeys
from .monero_wallet_listener import MoneroWalletListener
from .monero_wallet_rpc import MoneroWalletRpc
from .monero_wallet_light import MoneroWalletLight


__all__ = [
Expand Down Expand Up @@ -226,6 +227,7 @@ __all__ = [
'MoneroWalletKeys',
'MoneroWalletListener',
'MoneroWalletRpc',
'MoneroWalletLight',
'SslOptions',
'SerializableStruct'
]
68 changes: 68 additions & 0 deletions src/monero/monero_wallet_light.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from typing import overload

from .monero_rpc_connection import MoneroRpcConnection
from .monero_wallet_config import MoneroWalletConfig
from .monero_wallet_keys import MoneroWalletKeys


class MoneroWalletLight(MoneroWalletKeys):
"""
Implements a Monero wallet using `monero-lws`_.

.. _monero-lws: https://github.com/vtnerd/monero-lws
"""

@staticmethod
@overload
def wallet_exists(primary_address: str, private_view_key: str, rpc: MoneroRpcConnection) -> bool:
"""
Check if a wallet exists on the server.

:param str primary_address: The primary address of the wallet.
:param str private_view_key: The private view key of the wallet.
:param MoneroRpcConnection rpc: The RPC connection to the Monero server.
:returns bool: `True` if the wallet exists, `False` otherwise.
"""
...

@staticmethod
@overload
def wallet_exists(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> bool:
"""
Check if a wallet exists on the server.

:param MoneroWalletConfig config: The wallet configuration.
:param MoneroRpcConnection rpc: The RPC connection to the Monero server.
:returns bool: `True` if the wallet exists, `False` otherwise.
"""
...

@staticmethod
def open_wallet(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> MoneroWalletLight:
"""
Open an existing light wallet with the given configuration.

:param MoneroWalletConfig config: The configuration for opening the wallet.
:param MoneroRpcConnection rpc: The RPC connection to the Monero server.
:returns MoneroWalletLight: an instance of MoneroWalletLight.
"""
...

@staticmethod
def create_wallet(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> MoneroWalletLight:
"""
Create a new light wallet with the given configuration.

:param MoneroWalletConfig config: The configuration for creating the wallet.
:param MoneroRpcConnection rpc: The RPC connection to the Monero server.
:returns MoneroWalletLight: an instance of MoneroWalletLight.
"""
...

def get_rpc_connection(self) -> MoneroRpcConnection | None:
"""
Get the wallet's RPC connection.

:returns MoneroRpcConnection | None: the wallet's rpc connection.
"""
...
11 changes: 11 additions & 0 deletions tests/common/test_rpc_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def wallet_connection(cls) -> MoneroRpcConnection:
"""Rpc connection test instance."""
return MoneroRpcConnection(Utils.WALLET_RPC_URI, Utils.WALLET_RPC_USERNAME, Utils.WALLET_RPC_PASSWORD, timeout_ms=cls.TIMEOUT_MS)

# Light wallet server rpc connection fixture
@pytest.fixture(scope="class")
def lws_connection(self) -> MoneroRpcConnection:
"""Rpc connection test instance."""
return MoneroRpcConnection(Utils.LWS_RPC_URI, timeout_ms=self.TIMEOUT_MS)

#endregion

#region Tests
Expand Down Expand Up @@ -162,6 +168,11 @@ def test_node_rpc_connection(self, node_connection: MoneroRpcConnection) -> None
def test_wallet_rpc_connection(self, wallet_connection: MoneroRpcConnection) -> None:
RpcConnectionUtils.test_rpc_connection(wallet_connection, Utils.WALLET_RPC_URI, True, MoneroConnectionType.IPV4)

# Test light wallet server rpc connection
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_lws_rpc_connection(self, lws_connection: MoneroRpcConnection) -> None:
RpcConnectionUtils.test_rpc_connection(lws_connection, Utils.LWS_RPC_URI, True, MoneroConnectionType.IPV4)

# Test invalid connection
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_invalid_connection(self) -> None:
Expand Down
2 changes: 2 additions & 0 deletions tests/config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ zmq_uri=tcp://127.0.0.1:18085
zmq_pub_uri=tcp://127.0.0.1:18086
log_level=3
poll_period_in_ms=10000
lws_uri=http://127.0.0.1:8443
lws_admin_uri=http://127.0.0.1:8444

[wallet]
name=test_wallet_1
Expand Down
Loading
Loading