Skip to content

Commit 12512b0

Browse files
Add MoneroWalletLight
1 parent ce5656d commit 12512b0

29 files changed

Lines changed: 964 additions & 121 deletions

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
8181
- name: Setup test environment
8282
run: |
83-
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
83+
docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws
8484
sleep 10
8585
8686
- name: Reset coverage counters
@@ -97,7 +97,7 @@ jobs:
9797
if: always()
9898
run: |
9999
mkdir -p container-logs
100-
for svc in node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3; do
100+
for svc in node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws; do
101101
docker compose -f tests/docker-compose.yml logs --no-color --timestamps "$svc" > "container-logs/$svc.log" 2>&1 || true
102102
done
103103

‎bin/setup_test_environment.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22

33
# start docker containers
4-
sudo docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3
4+
sudo docker compose -f tests/docker-compose.yml up -d node_1 node_2 xmr_wallet_1 xmr_wallet_2 xmr_wallet_3 xmr_lws

‎conftest.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def pytest_runtest_call(item: pytest.Item):
1818
try:
1919
# run test
2020
item.runtest()
21-
except RuntimeError as e:
21+
except Exception as e:
2222
e_str = str(e).lower()
23-
if "not supported" in e_str or "does not support" in e_str:
23+
if "not supported" in e_str or "does not support" in e_str or "doesn't support" in e_str:
2424
# Ok
2525
pytest.xfail(str(e))
2626
if not_implemented and "not implemented" in e_str:

‎pytest.ini‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ log_level = INFO
55
log_cli = True
66
log_cli_level = INFO
77
console_output_style = progress
8+
log_file = tests.log
9+
log_file_level = DEBUG
10+
log_file_format = %(asctime)s %(levelname)-8s %(name)s:%(lineno)s %(message)s
11+
log_file_date_format = %Y-%m-%d %H:%M:%S
812
testpaths =
913
tests
1014
markers =

‎src/cpp/py_monero_types.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "wallet/monero_wallet_rpc.h"
6161
#include "wallet/monero_wallet_keys.h"
6262
#include "wallet/monero_wallet_full.h"
63+
#include "wallet/monero_wallet_light.h"
6364
#include "utils/py_monero_utils.h"
6465

6566
#define MONERO_CATCH_AND_RETHROW(expr) \
@@ -148,6 +149,7 @@ struct PyMoneroTypes {
148149
py::class_<monero_wallet_keys, monero_wallet, std::shared_ptr<monero_wallet_keys>> py_monero_wallet_keys;
149150
py::class_<monero_wallet_full, monero_wallet, std::shared_ptr<monero_wallet_full>> py_monero_wallet_full;
150151
py::class_<monero_wallet_rpc, monero_wallet, std::shared_ptr<monero_wallet_rpc>> py_monero_wallet_rpc;
152+
py::class_<monero_wallet_light, monero_wallet_keys, std::shared_ptr<monero_wallet_light>> py_monero_wallet_light;
151153
py::class_<PyMoneroUtils> py_monero_utils;
152154

153155
py::class_<monero_tx_height_comparator, std::shared_ptr<monero_tx_height_comparator>> py_tx_height_comparator;
@@ -200,6 +202,7 @@ struct PyMoneroTypes {
200202
py_monero_wallet(m, "MoneroWallet"),
201203
py_monero_wallet_keys(m, "MoneroWalletKeys"),
202204
py_monero_wallet_full(m, "MoneroWalletFull"),
205+
py_monero_wallet_light(m, "MoneroWalletLight"),
203206
py_monero_wallet_rpc(m, "MoneroWalletRpc"),
204207
py_monero_utils(m, "MoneroUtils"),
205208
py_tx_height_comparator(m, "TxHeightComparator"),

‎src/cpp/wallet/py_monero_wallet_bindings.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,24 @@ void py_monero_bind_wallet(py::module_& m, PyMoneroTypes& t) {
10371037
MONERO_CATCH_AND_RETHROW(self.get_cache_file_buffer());
10381038
}, py::call_guard<py::gil_scoped_release>());
10391039

1040+
// monero_wallet_light
1041+
t.py_monero_wallet_light
1042+
.def_static("wallet_exists", [](const std::string& primary_address, const std::string& private_view_key, const std::shared_ptr<monero_rpc_connection>& rpc) {
1043+
MONERO_CATCH_AND_RETHROW(monero_wallet_light::wallet_exists(primary_address, private_view_key, rpc));
1044+
}, py::arg("primary_address"), py::arg("private_view_key"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
1045+
.def_static("wallet_exists", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
1046+
MONERO_CATCH_AND_RETHROW(monero_wallet_light::wallet_exists(config, rpc));
1047+
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
1048+
.def_static("open_wallet", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
1049+
MONERO_CATCH_AND_RETHROW(monero_wallet_light::open_wallet(config, rpc));
1050+
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
1051+
.def_static("create_wallet", [](const monero_wallet_config& config, const std::shared_ptr<monero_rpc_connection>& rpc) {
1052+
MONERO_CATCH_AND_RETHROW(monero_wallet_light::create_wallet(config, rpc));
1053+
}, py::arg("config"), py::arg("rpc"), py::call_guard<py::gil_scoped_release>())
1054+
.def("get_rpc_connection", [](monero_wallet_rpc& self) {
1055+
MONERO_CATCH_AND_RETHROW(self.get_rpc_connection());
1056+
}, py::call_guard<py::gil_scoped_release>());
1057+
10401058
// monero_wallet_rpc
10411059
t.py_monero_wallet_rpc
10421060
.def(py::init<const std::shared_ptr<monero_rpc_connection>&>(), py::arg("rpc_connection"), py::call_guard<py::gil_scoped_release>())

‎src/python/__init__.pyi‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ from .monero_wallet_full import MoneroWalletFull
130130
from .monero_wallet_keys import MoneroWalletKeys
131131
from .monero_wallet_listener import MoneroWalletListener
132132
from .monero_wallet_rpc import MoneroWalletRpc
133+
from .monero_wallet_light import MoneroWalletLight
133134

134135

135136
__all__ = [
@@ -206,6 +207,7 @@ __all__ = [
206207
'MoneroWalletKeys',
207208
'MoneroWalletListener',
208209
'MoneroWalletRpc',
210+
'MoneroWalletLight',
209211
'SslOptions',
210212
'SerializableStruct'
211213
]

‎src/python/monero_wallet_light.pyi‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from typing import overload
2+
3+
from .monero_rpc_connection import MoneroRpcConnection
4+
from .monero_wallet_config import MoneroWalletConfig
5+
from .monero_wallet_keys import MoneroWalletKeys
6+
7+
8+
class MoneroWalletLight(MoneroWalletKeys):
9+
"""
10+
Implements a Monero wallet using `monero-lws`_.
11+
12+
.. _monero-lws: https://github.com/vtnerd/monero-lws
13+
"""
14+
15+
@staticmethod
16+
@overload
17+
def wallet_exists(primary_address: str, private_view_key: str, rpc: MoneroRpcConnection) -> bool:
18+
"""
19+
Check if a wallet exists on the server.
20+
21+
:param primary_address: The primary address of the wallet.
22+
:param private_view_key: The private view key of the wallet.
23+
:param rpc: The RPC connection to the Monero server.
24+
:return: True if the wallet exists, False otherwise.
25+
"""
26+
...
27+
28+
@staticmethod
29+
@overload
30+
def wallet_exists(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> bool:
31+
"""
32+
Check if a wallet exists on the server.
33+
34+
:param config: The wallet configuration.
35+
:param rpc: The RPC connection to the Monero server.
36+
:return: True if the wallet exists, False otherwise.
37+
"""
38+
...
39+
40+
@staticmethod
41+
def open_wallet(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> MoneroWalletLight:
42+
"""
43+
Open an existing light wallet with the given configuration.
44+
45+
:param config: The configuration for opening the wallet.
46+
:param rpc: The RPC connection to the Monero server.
47+
:return: An instance of MoneroWalletLight.
48+
"""
49+
...
50+
51+
@staticmethod
52+
def create_wallet(config: MoneroWalletConfig, rpc: MoneroRpcConnection) -> MoneroWalletLight:
53+
"""
54+
Create a new light wallet with the given configuration.
55+
56+
:param config: The configuration for creating the wallet.
57+
:param rpc: The RPC connection to the Monero server.
58+
:return: An instance of MoneroWalletLight.
59+
"""
60+
...
61+
62+
def get_rpc_connection(self) -> MoneroRpcConnection | None:
63+
"""
64+
Get the wallet's RPC connection.
65+
66+
:returns MoneroRpcConnection | None: the wallet's rpc connection.
67+
"""
68+
...

‎tests/config/config.ini‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ auto_connect_timeout_ms=3000
1111
rpc_uri=http://127.0.0.1:18081
1212
rpc_username=rpc_daemon_user
1313
rpc_password=abc123
14+
zmq_uri=tcp://127.0.0.1:18085
15+
zmq_pub_uri=tcp://127.0.0.1:18086
16+
lws_uri=http://127.0.0.1:8443
1417

1518
[wallet]
1619
name=test_wallet_1

0 commit comments

Comments
 (0)