Skip to content
Merged
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
64 changes: 64 additions & 0 deletions .github/workflows/build-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Build MacOS

on:
push:
branches: [ main ]
workflow_dispatch:

jobs:
build:
name: ${{ matrix.os }} (arm64)
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-14, macos-15]

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install python boost@1.85 hidapi openssl zmq libpgm miniupnpc expat libunwind-headers protobuf unbound
brew unlink boost || true
brew link boost@1.85 --force
pip3 install pytest pytest-cov setuptools wheel scikit-build-core --break-system-packages

- name: Install pybind11 v2.13.6
run: |
pip3 install pybind11==2.13.6 pybind11-stubgen --break-system-packages

- name: Build monero
run: |
cd external/monero-cpp/external/monero-project
mkdir -p build/release
cd build/release
cmake -DSTATIC=ON -DBUILD_64=ON -DCMAKE_BUILD_TYPE=Release ../../
make -j3 wallet cryptonote_protocol
cd ../../../../../../

- name: Build monero-cpp
run: |
cd external/monero-cpp
mkdir -p build
cd build
cmake ..
cmake --build .
make -j3
cd ../../../

- name: Build monero-python
run: |
mkdir -p build
python3 -m pip wheel . -w dist --no-build-isolation

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: monero-${{ matrix.os }}
path: |
dist/*.whl
external/monero-cpp/build/libmonero-cpp.dylib
69 changes: 61 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ jobs:
- name: Install dependencies
run: |
sudo apt update
sudo apt install -y build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz git curl autoconf libtool gperf nettle-dev libevent-dev debhelper python3-all python3-pip python3-pybind11 python3-pytest python3-pytest-rerunfailures python3-pytest-cov lcov
pip3 install pybind11-stubgen pytest --break-system-packages
sudo apt install -y build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev python3 ccache doxygen graphviz git curl autoconf libtool gperf nettle-dev libevent-dev debhelper python3-all python3-pip python3-pybind11 python3-pytest python3-pytest-rerunfailures python3-pytest-cov lcov python3-scikit-build-core
pip3 install pybind11-stubgen pytest pyproject-metadata --break-system-packages

- name: Install expat
run: |
Expand Down Expand Up @@ -80,10 +80,9 @@ jobs:
- name: Install monero-python
run: |
mkdir -p build
export CFLAGS="--coverage -fprofile-update=atomic -O0 -g"
export CXXFLAGS="--coverage -fprofile-update=atomic -O0 -g"
export LDFLAGS="--coverage"
COVERAGE=1 pip3 install -vvv .
cmake -B build -DENABLE_COVERAGE=ON
cmake --build build
cp build/monero.cpython-312-x86_64-linux-gnu.so ~/.local/lib/python3.12/site-packages/

- name: Setup test environment
run: |
Expand All @@ -105,7 +104,7 @@ jobs:

- name: Generate coverage report
run: |
lcov --capture --directory . --ignore-errors mismatch,mismatch,inconsistent,source,source,gcov,gcov --output-file coverage_full.info
lcov --capture --directory build --ignore-errors mismatch,mismatch,inconsistent,source,source,gcov,gcov --output-file coverage_full.info
lcov --ignore-errors unused,unused --remove coverage_full.info '/usr/*' '*/external/*' '*/pybind11/*' '*monero-cpp/*' '*monero-project/*' --output-file coverage.info
sed -i "s|$(pwd)/||g" coverage.info

Expand Down Expand Up @@ -140,7 +139,7 @@ jobs:
- name: Install pytest
shell: bash
run: |
python -m pip install pytest pytest-rerunfailures typing_extensions
python -m pip install pytest pytest-rerunfailures typing_extensions scikit-build-core

- name: Setup MSYS2 MINGW64
uses: msys2/setup-msys2@v2
Expand Down Expand Up @@ -243,3 +242,57 @@ jobs:
PATH: "${{ github.workspace }}/dist:/usr/bin:$PATH"
run: |
python -m pytest -m unit

macos:
runs-on: macos-15
name: macos (pytest)

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install python boost@1.85 hidapi openssl zmq libpgm miniupnpc expat libunwind-headers protobuf unbound
brew unlink boost || true
brew link boost@1.85 --force
pip3 install pytest pytest-rerunfailures pytest-cov setuptools wheel scikit-build-core --break-system-packages

- name: Install pybind11 v2.13.6
run: |
pip3 install pybind11==2.13.6 pybind11-stubgen --break-system-packages

- name: Clone monero-cpp (regtest)
run: |
cd external
rm -rf monero-cpp
git clone -b regtest-env --single-branch --recurse-submodules https://github.com/everoddandeven/monero-cpp.git
cd ..

- name: Build monero
run: |
cd external/monero-cpp/external/monero-project
mkdir -p build/release
cd build/release
cmake -DSTATIC=ON -DBUILD_64=ON -DCMAKE_BUILD_TYPE=Release ../../
make -j3 wallet cryptonote_protocol
cd ../../../../../../

- name: Install monero-cpp
run: |
cd external/monero-cpp
mkdir -p build
cd build
cmake ..
cmake --build .
make -j3
cp libmonero-cpp.dylib /opt/homebrew/lib/
cd ../../../

- name: Install monero-python
run: |
mkdir -p build
pip3 install --no-build-isolation -vvv . --break-system-packages

- name: Run unit tests
run: |
pytest -m unit
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@ endif()

project(monero LANGUAGES CXX)

option(ENABLE_COVERAGE "Enable coverage" OFF)

if(ENABLE_COVERAGE)
message(STATUS "Coverage enabled")
add_compile_options(--coverage -O0 -g -fprofile-update=atomic)
add_link_options(--coverage)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module)

find_package(pybind11 REQUIRED)

set(Boost_NO_BOOST_CMAKE 1)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED COMPONENTS system thread serialization filesystem)

find_package(OpenSSL REQUIRED)

set(SOURCES
src/cpp/common/py_monero_common.cpp
src/cpp/daemon/py_monero_daemon_model.cpp
Expand Down Expand Up @@ -59,8 +71,8 @@ target_link_libraries(monero PRIVATE
Boost::serialization
Boost::filesystem

ssl
crypto
OpenSSL::SSL
OpenSSL::Crypto
)

if (WIN32)
Expand All @@ -70,3 +82,5 @@ if (WIN32)
bcrypt
)
endif()

install(TARGETS monero DESTINATION .)
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

[![Build Debian Packages](https://github.com/everoddandeven/monero-python/actions/workflows/build-deb.yml/badge.svg)](https://github.com/everoddandeven/monero-python/actions/workflows/build-deb.yml)
[![Build Windows Package](https://github.com/everoddandeven/monero-python/actions/workflows/build-windows.yml/badge.svg?branch=main)](https://github.com/everoddandeven/monero-python/actions/workflows/build-windows.yml)
[![Build MacOS](https://github.com/everoddandeven/monero-python/actions/workflows/build-macos.yml/badge.svg)](https://github.com/everoddandeven/monero-python/actions/workflows/build-macos.yml)

[![Matrix](https://img.shields.io/badge/matrix-monero--python-blue?logo=matrix)](https://matrix.to/#/#monero-python:monero.social)

> [!WARNING]
>
Expand Down
27 changes: 25 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
[project]
name = "monero"
version = "0.0.1"
description = "A Python library for using Monero"
authors = [
{ name = "everoddandeven", email = "everoddandeven@protonmail.com" }
]
license = { text = "MIT" }
readme = "README.md"
requires-python = ">=3.8"
dependencies = [
"pybind11>=2.12"
]

[build-system]
requires = ["setuptools>=61", "pybind11>=2.12"]
build-backend = "setuptools.build_meta"
requires = [
"scikit-build-core>=0.5",
"pybind11>=2.12",
"cmake>=3.20",
"ninja"
]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
cmake.verbose = true
cmake.build-type = "Release"
59 changes: 3 additions & 56 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,56 +1,5 @@
import pybind11
import sys
import os

from setuptools import setup
from pathlib import Path
from pybind11.setup_helpers import Pybind11Extension, build_ext

coverage = os.environ.get("COVERAGE") == "1"
this_dir = Path(__file__).parent.resolve()
extra_compile_args: list[str] = ['/std:c++17'] if sys.platform == "win32" else ['-std=c++17']
extra_link_args: list[str] = []

if coverage:
extra_compile_args += ['-O0', '-g', '--coverage']
extra_link_args += ['--coverage']

ext_modules = [
Pybind11Extension(
'monero',
[
'src/cpp/common/py_monero_common.cpp',
'src/cpp/daemon/py_monero_daemon_model.cpp',
'src/cpp/daemon/py_monero_daemon_rpc.cpp',
'src/cpp/wallet/py_monero_wallet_model.cpp',
'src/cpp/wallet/py_monero_wallet.cpp',
'src/cpp/wallet/py_monero_wallet_rpc.cpp',
'src/cpp/utils/py_monero_utils.cpp',
'src/cpp/py_monero.cpp'
],
include_dirs=[
pybind11.get_include(),
str(this_dir / 'external' / 'monero-cpp' / 'src'),
str(this_dir / 'external' / 'monero-cpp' / 'external' / 'monero-project' / 'src'),
str(this_dir / 'external' / 'monero-cpp' / 'external' / 'monero-project' / 'contrib' / 'epee' / 'include'),
str(this_dir / 'external' / 'monero-cpp' / 'external' / 'monero-project' / 'external'),
str(this_dir / 'external' / 'monero-cpp' / 'external' / 'monero-project' / 'external' / 'easylogging++'),
str(this_dir / 'external' / 'monero-cpp' / 'external' / 'monero-project' / 'external' / 'rapidjson' / 'include'),
str(this_dir / 'src' / 'cpp'),
str(this_dir / 'src' / 'cpp' / 'common'),
str(this_dir / 'src' / 'cpp' / 'daemon'),
str(this_dir / 'src' / 'cpp' / 'wallet'),
str(this_dir / 'src' / 'cpp' / 'utils')
],
library_dirs=[
str(this_dir / 'external' / 'monero-cpp' / 'build')
],
libraries=['monero-cpp'],
language='c++',
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args
),
]
# setup.py
from skbuild import setup

setup(
name='monero',
Expand All @@ -60,12 +9,10 @@
maintainer='everoddandeven',
maintainer_email='everoddandeven@protonmail.com',
license="MIT",
packages=["monero"],
url='https://github.com/everoddandeven/monero-python',
download_url="https://github.com/everoddandeven/monero-python/releases",
description='A Python library for using Monero.',
long_description='Python bindings for monero-cpp.',
keywords=["monero", "monero-python", "python", "bindings", "pybind11"],
ext_modules=ext_modules,
install_requires=['pybind11>=2.12.0'],
cmdclass={"build_ext": build_ext}
)
2 changes: 1 addition & 1 deletion src/cpp/daemon/py_monero_daemon_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class PyMoneroDaemonRpc : public PyMoneroDaemon {
std::shared_ptr<PyMoneroDaemonUpdateCheckResult> check_for_update() override;
std::shared_ptr<PyMoneroDaemonUpdateDownloadResult> download_update(const std::string& path = "") override;
void stop() override;
std::shared_ptr<monero::monero_block_header> wait_for_next_block_header();
std::shared_ptr<monero::monero_block_header> wait_for_next_block_header() override;
static void check_response_status(const std::shared_ptr<PyMoneroPathResponse>& response);
static void check_response_status(const std::shared_ptr<PyMoneroJsonResponse>& response);

Expand Down
34 changes: 23 additions & 11 deletions src/cpp/py_monero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1575,10 +1575,10 @@ PYBIND11_MODULE(monero, m) {
MONERO_CATCH_AND_RETHROW(self.is_view_only());
})
.def("set_connection_manager", [](PyMoneroWallet& self, const std::shared_ptr<PyMoneroConnectionManager> &connection_manager) {
MONERO_CATCH_AND_RETHROW(self.set_connection_manager(connection_manager));
throw PyMoneroError("MoneroWallet.set_connection_manager(): not supported");
}, py::arg("connection_manager"))
.def("get_connection_manager", [](PyMoneroWallet& self) {
MONERO_CATCH_AND_RETHROW(self.get_connection_manager());
throw PyMoneroError("MoneroWallet.get_connection_manager(): not supported");
})
.def("set_daemon_connection", [](PyMoneroWallet& self, const boost::optional<monero::monero_rpc_connection>& connection) {
MONERO_CATCH_AND_RETHROW(self.set_daemon_connection(connection));
Expand Down Expand Up @@ -1967,17 +1967,17 @@ PYBIND11_MODULE(monero, m) {
.def("delete_address_book_entry", [](PyMoneroWallet& self, uint64_t index) {
MONERO_CATCH_AND_RETHROW(self.delete_address_book_entry(index));
}, py::arg("index"))
.def("tag_accounts", [](PyMoneroWallet& self, const std::string& tag, const std::vector<uint32_t>& account_indices) {
MONERO_CATCH_AND_RETHROW(self.tag_accounts(tag, account_indices));
.def("tag_accounts", [](monero::monero_wallet& self, const std::string& tag, const std::vector<uint32_t>& account_indices) {
throw PyMoneroError("MoneroWallet.tag_accounts(): not supported");
}, py::arg("tag"), py::arg("account_indices"))
.def("untag_accounts", [](PyMoneroWallet& self, const std::vector<uint32_t>& account_indices) {
MONERO_CATCH_AND_RETHROW(self.untag_accounts(account_indices));
.def("untag_accounts", [](monero::monero_wallet& self, const std::vector<uint32_t>& account_indices) {
throw PyMoneroError("MoneroWallet.untag_accounts(): not supported");
}, py::arg("account_indices"))
.def("get_account_tags", [](PyMoneroWallet& self) {
MONERO_CATCH_AND_RETHROW(self.get_account_tags());
.def("get_account_tags", [](monero::monero_wallet& self) {
throw PyMoneroError("MoneroWallet.get_account_tags(): not supported");
})
.def("set_account_tag_label", [](PyMoneroWallet& self, const std::string& tag, const std::string& label) {
MONERO_CATCH_AND_RETHROW(self.set_account_tag_label(tag, label));
.def("set_account_tag_label", [](monero::monero_wallet& self, const std::string& tag, const std::string& label) {
throw PyMoneroError("MoneroWallet.set_account_tag_label(): not supported");
}, py::arg("tag"), py::arg("label"))
.def("set_account_label", [](PyMoneroWallet& self, uint32_t account_idx, const std::string& label) {
MONERO_CATCH_AND_RETHROW(self.set_subaddress_label(account_idx, 0, label));
Expand Down Expand Up @@ -2195,7 +2195,19 @@ PYBIND11_MODULE(monero, m) {
}, py::arg("connection"), py::arg("is_trusted"), py::arg("ssl_options"))
.def("stop", [](PyMoneroWalletRpc& self) {
MONERO_CATCH_AND_RETHROW(self.stop());
});
})
.def("tag_accounts", [](PyMoneroWalletRpc& self, const std::string& tag, const std::vector<uint32_t>& account_indices) {
MONERO_CATCH_AND_RETHROW(self.tag_accounts(tag, account_indices));
}, py::arg("tag"), py::arg("account_indices"))
.def("untag_accounts", [](PyMoneroWalletRpc& self, const std::vector<uint32_t>& account_indices) {
MONERO_CATCH_AND_RETHROW(self.untag_accounts(account_indices));
}, py::arg("account_indices"))
.def("get_account_tags", [](PyMoneroWalletRpc& self) {
MONERO_CATCH_AND_RETHROW(self.get_account_tags());
})
.def("set_account_tag_label", [](PyMoneroWalletRpc& self, const std::string& tag, const std::string& label) {
MONERO_CATCH_AND_RETHROW(self.set_account_tag_label(tag, label));
}, py::arg("tag"), py::arg("label"));

// monero_utils
py_monero_utils
Expand Down
Loading
Loading