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
93 changes: 0 additions & 93 deletions src/cpp/daemon/py_monero_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,6 @@ void PyMoneroDaemonRpc::stop() {
check_response_status(response);
}

void PyMoneroDaemonRpc::stop_process() {
if (m_child_process && m_child_process->running()) {
m_child_process->terminate();
}
if (m_output_thread.joinable()) {
m_output_thread.join();
}
}

std::shared_ptr<monero::monero_block_header> PyMoneroDaemonRpc::wait_for_next_block_header() {
// use mutex and condition variable to wait for block
boost::mutex temp;
Expand Down Expand Up @@ -798,89 +789,5 @@ void PyMoneroDaemonRpc::check_response_status(std::shared_ptr<PyMoneroJsonRespon
check_response_status(node);
}

PyMoneroDaemonRpc::PyMoneroDaemonRpc(const std::vector<std::string>& cmd) {
if (cmd.empty()) throw PyMoneroError("Must provide at least a path to monerod");
boost::process::environment env = boost::this_process::environment();
env["LANG"] = "en_US.UTF-8";

m_child_process = std::make_unique<boost::process::child>(
boost::process::exe = cmd[0],
boost::process::args = std::vector<std::string>(cmd.begin() + 1, cmd.end()),
boost::process::std_out > m_out_pipe,
boost::process::std_err > m_err_pipe,
env
);

std::istream& out_stream = m_out_pipe;
std::istream& err_straem = m_err_pipe;
std::ostringstream captured_output;
std::string line;
std::string uri_;
std::string username_;
std::string password_;
std::string zmq_uri_;
bool started = false;

while (std::getline(out_stream, line)) {
std::cerr << "[monero-rpc] " << line << std::endl;
captured_output << line << "\n";

std::string uri;
std::regex re("Binding on ([0-9.]+).*:(\\d+)");
std::smatch match;
if (std::regex_search(line, match, re) && match.size() >= 3) {
std::string host = match[1];
std::string port = match[2];
bool ssl = false;

auto it = std::find(cmd.begin(), cmd.end(), "--rpc-ssl");
if (it != cmd.end() && it + 1 != cmd.end()) {
ssl = (it[1] == "enabled");
}

uri_ = (ssl ? "https://" : "http://") + host + ":" + port;
}

if (line.find("Starting p2p net loop") != std::string::npos) {
m_output_thread = std::thread([this]() {
std::istream& out_stream_bg = m_out_pipe;
std::string line_bg;
while (std::getline(out_stream_bg, line_bg)) {
std::cerr << "[monero-rpc] " << line_bg << std::endl;
}
});
started = true;
break;
}
}

if (!started) {
if (std::getline(err_straem, line)) {
captured_output << line << "\n";
}

throw PyMoneroError("Failed to start monerod:\n" + captured_output.str());
}

auto it = std::find(cmd.begin(), cmd.end(), "--rpc-login");
if (it != cmd.end() && it + 1 != cmd.end()) {
std::string login = *(it + 1);
auto sep = login.find(':');
if (sep != std::string::npos) {
username_ = login.substr(0, sep);
password_ = login.substr(sep + 1);
}
}

it = std::find(cmd.begin(), cmd.end(), "--zmq-pub");
if (it != cmd.end() && it + 1 != cmd.end()) {
zmq_uri_ = *(it + 1);
}

m_rpc = std::make_shared<PyMoneroRpcConnection>(uri_, username_, password_, zmq_uri_);
if (!m_rpc->m_uri->empty()) m_rpc->check_connection();
}

PyMoneroDaemonRpc::~PyMoneroDaemonRpc() {
stop_process();
}
7 changes: 0 additions & 7 deletions src/cpp/daemon/py_monero_daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ class PyMoneroDaemonRpc : public PyMoneroDaemonDefault {
if (!uri.empty()) m_rpc->check_connection();
}

PyMoneroDaemonRpc(const std::vector<std::string>& cmd);

~PyMoneroDaemonRpc();

std::shared_ptr<PyMoneroRpcConnection> get_rpc_connection() const;
Expand Down Expand Up @@ -236,18 +234,13 @@ class PyMoneroDaemonRpc : public PyMoneroDaemonDefault {
std::shared_ptr<PyMoneroDaemonUpdateDownloadResult> download_update(const std::string& path) override;
std::shared_ptr<PyMoneroDaemonUpdateDownloadResult> download_update() override;
void stop() override;
void stop_process();
std::shared_ptr<monero::monero_block_header> wait_for_next_block_header();
static void check_response_status(std::shared_ptr<PyMoneroPathResponse> response);
static void check_response_status(std::shared_ptr<PyMoneroJsonResponse> response);

protected:
std::shared_ptr<PyMoneroRpcConnection> m_rpc;
std::shared_ptr<PyMoneroDaemonPoller> m_poller;
std::unique_ptr<boost::process::child> m_child_process;
boost::process::ipstream m_out_pipe;
boost::process::ipstream m_err_pipe;
std::thread m_output_thread;

std::shared_ptr<PyMoneroBandwithLimits> get_bandwidth_limits();
std::shared_ptr<PyMoneroBandwithLimits> set_bandwidth_limits(int up, int down);
Expand Down
9 changes: 4 additions & 5 deletions src/cpp/daemon/py_monero_daemon_model.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <boost/process.hpp>
#include <boost/asio.hpp>
#include <iostream>
#include <sstream>
Expand Down Expand Up @@ -980,10 +979,10 @@ class PyMoneroConnectionManagerListener : public monero_connection_manager_liste
public:
void on_connection_changed(std::shared_ptr<PyMoneroRpcConnection> &connection) override {
PYBIND11_OVERRIDE_PURE(
void, // Return type
monero_connection_manager_listener, // C++ base class
on_connection_changed, // Method name
connection // Arguments
void,
monero_connection_manager_listener,
on_connection_changed,
connection
);
}
};
Expand Down
8 changes: 0 additions & 8 deletions src/cpp/py_monero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,17 +1417,13 @@ PYBIND11_MODULE(monero, m) {
// monero_daemon_rpc
py_monero_daemon_rpc
.def(py::init<>())
.def(py::init<const std::vector<std::string>&>(), py::arg("cmd"))
.def(py::init<std::shared_ptr<PyMoneroRpcConnection>>(), py::arg("rpc"))
.def(py::init<std::string&, std::string&, std::string&>(), py::arg("uri"), py::arg("username") = "", py::arg("password") = "")
.def("get_rpc_connection", [](const PyMoneroDaemonRpc& self) {
MONERO_CATCH_AND_RETHROW(self.get_rpc_connection());
})
.def("is_connected", [](PyMoneroDaemonRpc& self) {
MONERO_CATCH_AND_RETHROW(self.is_connected());
})
.def("stop_process", [](PyMoneroDaemonRpc& self) {
MONERO_CATCH_AND_RETHROW(self.stop_process());
});

// monero_wallet
Expand Down Expand Up @@ -2024,12 +2020,8 @@ PYBIND11_MODULE(monero, m) {

// monero_wallet_rpc
py_monero_wallet_rpc
.def(py::init<const std::vector<std::string>&>(), py::arg("cmd"))
.def(py::init<std::shared_ptr<PyMoneroRpcConnection>>(), py::arg("rpc_connection"))
.def(py::init<const std::string&, const std::string&, const std::string&>(), py::arg("uri") = "", py::arg("username") = "", py::arg("password") = "")
.def("stop_process", [](PyMoneroWalletRpc& self) {
MONERO_CATCH_AND_RETHROW(self.stop_process());
})
.def("create_wallet", [](PyMoneroWalletRpc& self, const std::shared_ptr<PyMoneroWalletConfig> config) {
try {
self.create_wallet(config);
Expand Down
94 changes: 0 additions & 94 deletions src/cpp/wallet/py_monero_wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,92 +338,7 @@ bool PyMoneroWalletPoller::check_for_changed_balances() {
return false;
}

PyMoneroWalletRpc::PyMoneroWalletRpc(const std::vector<std::string>& cmd) {
if (cmd.empty()) throw std::runtime_error("Must provide at least a path to monerod");
boost::process::environment env = boost::this_process::environment();
env["LANG"] = "en_US.UTF-8";

m_child_process = std::make_unique<boost::process::child>(
boost::process::exe = cmd[0],
boost::process::args = std::vector<std::string>(cmd.begin() + 1, cmd.end()),
boost::process::std_out > m_out_pipe,
boost::process::std_err > m_err_pipe,
env
);

std::istream& out_stream = m_out_pipe;
std::istream& err_straem = m_err_pipe;
std::ostringstream captured_output;
std::string line;
std::string uri_;
std::string username_;
std::string password_;
std::string zmq_uri_;
bool started = false;

while (std::getline(out_stream, line)) {
std::cerr << "[wallet-rpc] " << line << std::endl;
captured_output << line << "\n";

std::string uri;
std::regex re("Binding on ([0-9.]+).*:(\\d+)");
std::smatch match;
if (std::regex_search(line, match, re) && match.size() >= 3) {
std::string host = match[1];
std::string port = match[2];
bool ssl = false;

auto it = std::find(cmd.begin(), cmd.end(), "--rpc-ssl");
if (it != cmd.end() && it + 1 != cmd.end()) {
ssl = (it[1] == "enabled");
}

uri_ = (ssl ? "https://" : "http://") + host + ":" + port;
}

if (line.find("Starting wallet RPC server") != std::string::npos) {
m_output_thread = std::thread([this]() {
std::istream& out_stream_bg = m_out_pipe;
std::string line_bg;
while (std::getline(out_stream_bg, line_bg)) {
std::cerr << "[wallet-rpc] " << line_bg << std::endl;
}
});
started = true;
break;
}
}

if (!started) {
if (std::getline(err_straem, line)) {
captured_output << line << "\n";
}

throw PyMoneroError("Failed to start monero-wallet-rpc:\n" + captured_output.str());
}

auto it = std::find(cmd.begin(), cmd.end(), "--rpc-login");
if (it != cmd.end() && it + 1 != cmd.end()) {
std::string login = *(it + 1);
auto sep = login.find(':');
if (sep != std::string::npos) {
username_ = login.substr(0, sep);
password_ = login.substr(sep + 1);
}
}

it = std::find(cmd.begin(), cmd.end(), "--zmq-pub");
if (it != cmd.end() && it + 1 != cmd.end()) {
zmq_uri_ = *(it + 1);
}

// Init addressCache, ecc.
m_rpc = std::make_shared<PyMoneroRpcConnection>(uri_, username_, password_, zmq_uri_);
if (!m_rpc->m_uri->empty()) m_rpc->check_connection();
}

PyMoneroWalletRpc::~PyMoneroWalletRpc() {
stop_process();
}

boost::optional<monero::monero_rpc_connection> PyMoneroWalletRpc::get_rpc_connection() const {
Expand Down Expand Up @@ -516,15 +431,6 @@ void PyMoneroWalletRpc::stop() {
std::shared_ptr<PyMoneroJsonResponse> response = m_rpc->send_json_request(request);
}

void PyMoneroWalletRpc::stop_process() {
if (m_child_process && m_child_process->running()) {
m_child_process->terminate();
}
if (m_output_thread.joinable()) {
m_output_thread.join();
}
}

bool PyMoneroWalletRpc::is_view_only() const {
try {
std::string key = "mnemonic";
Expand Down
7 changes: 0 additions & 7 deletions src/cpp/wallet/py_monero_wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ class PyMoneroWalletRpc : public PyMoneroWallet {
if (!m_rpc->m_uri->empty()) m_rpc->check_connection();
}

PyMoneroWalletRpc(const std::vector<std::string>& cmd);

~PyMoneroWalletRpc();

PyMoneroWalletRpc* open_wallet(const std::shared_ptr<PyMoneroWalletConfig> &config);
Expand All @@ -645,7 +643,6 @@ class PyMoneroWalletRpc : public PyMoneroWallet {
boost::optional<monero::monero_rpc_connection> get_rpc_connection() const;
std::vector<std::string> get_seed_languages() const;
void stop();
void stop_process();
bool is_view_only() const override;
boost::optional<monero::monero_rpc_connection> get_daemon_connection() const override;
void set_daemon_connection(const boost::optional<monero_rpc_connection>& connection, bool is_trusted, const boost::optional<std::shared_ptr<PyMoneroSslOptions>> ssl_options);
Expand Down Expand Up @@ -752,10 +749,6 @@ class PyMoneroWalletRpc : public PyMoneroWallet {
protected:
inline static const uint64_t DEFAULT_SYNC_PERIOD_IN_MS = 20000;
boost::optional<uint64_t> m_sync_period_in_ms;
std::unique_ptr<boost::process::child> m_child_process;
boost::process::ipstream m_out_pipe;
boost::process::ipstream m_err_pipe;
std::thread m_output_thread;
std::string m_path = "";
std::shared_ptr<PyMoneroRpcConnection> m_rpc;
std::shared_ptr<PyMoneroRpcConnection> m_daemon_connection;
Expand Down
13 changes: 0 additions & 13 deletions src/python/monero_daemon_rpc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ class MoneroDaemonRpc(MoneroDaemonDefault):
:param str password: Authentication password for daemon RPC.
"""
...
@typing.overload
def __init__(self, cmd: list[str]) -> None:
"""
Initialize a Monero daemon RPC process.

:param list[str] cmd: command.
"""
...
def get_rpc_connection(self) -> MoneroRpcConnection:
"""
Get the daemon's RPC connection.
Expand All @@ -51,9 +43,4 @@ class MoneroDaemonRpc(MoneroDaemonDefault):

:return bool: true if the client is connected to the daemon, false otherwise
"""
...
def stop_process(self) -> None:
"""
Stop Monero daemon RPC process.
"""
...
13 changes: 0 additions & 13 deletions src/python/monero_wallet_rpc.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ class MoneroWalletRpc(MoneroWallet):
:param str password: Authentication connection password.
"""
...
@typing.overload
def __init__(self, cmd: list[str]) -> None:
"""
Initialize a Monero wallet RPC process.

:param list[str]: Command list
"""
...
def create_wallet(self, config: MoneroWalletConfig) -> MoneroWalletRpc:
"""
Create and open a wallet on the monero-wallet-rpc server.
Expand Down Expand Up @@ -81,11 +73,6 @@ class MoneroWalletRpc(MoneroWallet):
:return MoneroWalletRpc: this wallet client
"""
...
def stop_process(self) -> None:
"""
Stop wallet RPC process.
"""
...
def stop(self) -> None:
"""
Save and close the current wallet and stop the RPC server.
Expand Down
Loading