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
487 changes: 304 additions & 183 deletions src/cpp/common/py_monero_common.cpp

Large diffs are not rendered by default.

345 changes: 148 additions & 197 deletions src/cpp/common/py_monero_common.h

Large diffs are not rendered by default.

211 changes: 126 additions & 85 deletions src/cpp/daemon/py_monero_daemon.h

Large diffs are not rendered by default.

570 changes: 396 additions & 174 deletions src/cpp/daemon/py_monero_daemon_model.cpp

Large diffs are not rendered by default.

445 changes: 253 additions & 192 deletions src/cpp/daemon/py_monero_daemon_model.h

Large diffs are not rendered by default.

514 changes: 317 additions & 197 deletions src/cpp/daemon/py_monero_daemon_rpc.cpp

Large diffs are not rendered by default.

144 changes: 97 additions & 47 deletions src/cpp/daemon/py_monero_daemon_rpc.h
Original file line number Diff line number Diff line change
@@ -1,40 +1,89 @@
/**
* Copyright (c) everoddandeven
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Parts of this file are originally copyright (c) 2025-2026 woodser
*
* Parts of this file are originally copyright (c) 2014-2019, The Monero Project
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* All rights reserved.
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
*/
#pragma once

#include "py_monero_daemon.h"

class PyMoneroDaemonPoller: public PyThreadPoller {
public:

PyMoneroDaemonPoller(PyMoneroDaemon* daemon, uint64_t poll_period_ms = 5000);

void poll() override;

private:
PyMoneroDaemon* m_daemon;
std::shared_ptr<monero::monero_block_header> m_last_header;
class monero_daemon_poller;

void announce_block_header(const std::shared_ptr<monero::monero_block_header>& header);
};

class PyMoneroDaemonRpc : public PyMoneroDaemon {
/**
* Implements a Monero daemon using monerod-rpc.
*/
class monero_daemon_rpc : public monero_daemon {
public:

~PyMoneroDaemonRpc();
PyMoneroDaemonRpc(const std::shared_ptr<PyMoneroRpcConnection>& rpc);
PyMoneroDaemonRpc(const std::string& uri, const std::string& username = "", const std::string& password = "", const std::string& proxy_uri = "", const std::string& zmq_uri = "", uint64_t timeout = 20000);
/**
* Destruct the daemon.
*/
~monero_daemon_rpc() override;
monero_daemon_rpc(const std::shared_ptr<PyMoneroRpcConnection>& rpc);
monero_daemon_rpc(const std::string& uri, const std::string& username = "", const std::string& password = "", const std::string& proxy_uri = "", const std::string& zmq_uri = "", uint64_t timeout = 20000);

std::vector<std::shared_ptr<PyMoneroDaemonListener>> get_listeners() override;
void add_listener(const std::shared_ptr<PyMoneroDaemonListener> &listener) override;
void remove_listener(const std::shared_ptr<PyMoneroDaemonListener> &listener) override;
/**
* Supported daemon methods.
*/
std::vector<std::shared_ptr<monero_daemon_listener>> get_listeners() override;
void add_listener(const std::shared_ptr<monero_daemon_listener> &listener) override;
void remove_listener(const std::shared_ptr<monero_daemon_listener> &listener) override;
void remove_listeners() override;
std::shared_ptr<PyMoneroRpcConnection> get_rpc_connection() const;
bool is_connected();
monero::monero_version get_version() override;
bool is_trusted() override;
uint64_t get_height() override;
std::string get_block_hash(uint64_t height) override;
std::shared_ptr<PyMoneroBlockTemplate> get_block_template(const std::string& wallet_address, int reserve_size) override;
std::shared_ptr<PyMoneroBlockTemplate> get_block_template(const std::string& wallet_address) override;
std::shared_ptr<monero_block_template> get_block_template(const std::string& wallet_address, const boost::optional<int>& reserve_size = boost::none) override;
std::shared_ptr<monero::monero_block_header> get_last_block_header() override;
std::shared_ptr<monero::monero_block_header> get_block_header_by_hash(const std::string& hash) override;
std::shared_ptr<monero::monero_block_header> get_block_header_by_height(uint64_t height) override;
Expand All @@ -48,59 +97,60 @@ class PyMoneroDaemonRpc : public PyMoneroDaemon {
std::vector<std::string> get_block_hashes(const std::vector<std::string>& block_hashes, uint64_t start_height) override;
std::vector<std::shared_ptr<monero::monero_tx>> get_txs(const std::vector<std::string>& tx_hashes, bool prune = false) override;
std::vector<std::string> get_tx_hexes(const std::vector<std::string>& tx_hashes, bool prune = false) override;
std::shared_ptr<PyMoneroMinerTxSum> get_miner_tx_sum(uint64_t height, uint64_t num_blocks) override;
std::shared_ptr<PyMoneroFeeEstimate> get_fee_estimate(uint64_t grace_blocks = 0) override;
std::shared_ptr<PyMoneroSubmitTxResult> submit_tx_hex(const std::string& tx_hex, bool do_not_relay = false) override;
std::shared_ptr<monero_miner_tx_sum> get_miner_tx_sum(uint64_t height, uint64_t num_blocks) override;
std::shared_ptr<monero_fee_estimate> get_fee_estimate(uint64_t grace_blocks = 0) override;
std::shared_ptr<monero_submit_tx_result> submit_tx_hex(const std::string& tx_hex, bool do_not_relay = false) override;
void relay_txs_by_hash(const std::vector<std::string>& tx_hashes) override;
std::shared_ptr<PyMoneroTxPoolStats> get_tx_pool_stats() override;
std::shared_ptr<monero_tx_pool_stats> get_tx_pool_stats() override;
std::vector<std::shared_ptr<monero::monero_tx>> get_tx_pool() override;
std::vector<std::string> get_tx_pool_hashes() override;
void flush_tx_pool(const std::vector<std::string> &hashes) override;
void flush_tx_pool() override;
void flush_tx_pool(const std::string &hash) override;
std::vector<PyMoneroKeyImageSpentStatus> get_key_image_spent_statuses(const std::vector<std::string>& key_images) override;
std::vector<monero_key_image_spent_status> get_key_image_spent_statuses(const std::vector<std::string>& key_images) override;
std::vector<std::shared_ptr<monero::monero_output>> get_outputs(const std::vector<monero::monero_output>& outputs) override;
std::vector<std::shared_ptr<PyMoneroOutputHistogramEntry>> get_output_histogram(const std::vector<uint64_t>& amounts, const boost::optional<int>& min_count, const boost::optional<int>& max_count, const boost::optional<bool>& is_unlocked, const boost::optional<int>& recent_cutoff) override;
std::shared_ptr<PyMoneroDaemonInfo> get_info() override;
std::shared_ptr<PyMoneroDaemonSyncInfo> get_sync_info() override;
std::shared_ptr<PyMoneroHardForkInfo> get_hard_fork_info() override;
std::vector<std::shared_ptr<PyMoneroAltChain>> get_alt_chains() override;
std::vector<std::shared_ptr<monero_output_histogram_entry>> get_output_histogram(const std::vector<uint64_t>& amounts, const boost::optional<int>& min_count, const boost::optional<int>& max_count, const boost::optional<bool>& is_unlocked, const boost::optional<int>& recent_cutoff) override;
std::shared_ptr<monero_daemon_info> get_info() override;
std::shared_ptr<monero_daemon_sync_info> get_sync_info() override;
std::shared_ptr<monero_hard_fork_info> get_hard_fork_info() override;
std::vector<std::shared_ptr<monero_alt_chain>> get_alt_chains() override;
std::vector<std::string> get_alt_block_hashes() override;
int get_download_limit() override;
int set_download_limit(int limit) override;
int reset_download_limit() override;
int get_upload_limit() override;
int set_upload_limit(int limit) override;
int reset_upload_limit() override;
std::vector<std::shared_ptr<PyMoneroPeer>> get_peers() override;
std::vector<std::shared_ptr<PyMoneroPeer>> get_known_peers() override;
std::vector<std::shared_ptr<monero_peer>> get_peers() override;
std::vector<std::shared_ptr<monero_peer>> get_known_peers() override;
void set_outgoing_peer_limit(int limit) override;
void set_incoming_peer_limit(int limit) override;
std::vector<std::shared_ptr<PyMoneroBan>> get_peer_bans() override;
void set_peer_bans(const std::vector<std::shared_ptr<PyMoneroBan>>& bans) override;
std::vector<std::shared_ptr<monero_ban>> get_peer_bans() override;
void set_peer_bans(const std::vector<std::shared_ptr<monero_ban>>& bans) override;
void start_mining(const std::string &address, int num_threads, bool is_background, bool ignore_battery) override;
void stop_mining() override;
std::shared_ptr<PyMoneroMiningStatus> get_mining_status() override;
std::shared_ptr<monero_mining_status> get_mining_status() override;
void submit_blocks(const std::vector<std::string>& block_blobs) override;
std::shared_ptr<PyMoneroPruneResult> prune_blockchain(bool check) override;
std::shared_ptr<PyMoneroDaemonUpdateCheckResult> check_for_update() override;
std::shared_ptr<PyMoneroDaemonUpdateDownloadResult> download_update(const std::string& path = "") override;
std::shared_ptr<monero_prune_result> prune_blockchain(bool check) override;
std::shared_ptr<monero_daemon_update_check_result> check_for_update() override;
std::shared_ptr<monero_daemon_update_download_result> download_update(const std::string& path = "") override;
void stop() override;
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);

protected:
// --------------------------------- PRIVATE --------------------------------

private:
friend class monero_daemon_poller;
mutable boost::recursive_mutex m_listeners_mutex;
std::vector<std::shared_ptr<PyMoneroDaemonListener>> m_listeners;
std::vector<std::shared_ptr<monero_daemon_listener>> m_listeners;
std::shared_ptr<PyMoneroRpcConnection> m_rpc;
std::shared_ptr<PyMoneroDaemonPoller> m_poller;
std::shared_ptr<monero_daemon_poller> m_poller;
std::unordered_map<uint64_t, std::shared_ptr<monero::monero_block_header>> m_cached_headers;

std::vector<std::shared_ptr<monero::monero_block>> get_max_blocks(boost::optional<uint64_t> start_height, boost::optional<uint64_t> max_height, boost::optional<uint64_t> chunk_size);
std::shared_ptr<monero::monero_block_header> get_block_header_by_height_cached(uint64_t height, uint64_t max_height);
std::shared_ptr<PyMoneroBandwithLimits> get_bandwidth_limits();
std::shared_ptr<PyMoneroBandwithLimits> set_bandwidth_limits(int up, int down);
std::shared_ptr<monero_bandwith_limits_params> get_bandwidth_limits();
std::shared_ptr<monero_bandwith_limits_params> set_bandwidth_limits(int up, int down);
void refresh_listening();
static void check_response_status(const boost::property_tree::ptree& node);
};
Loading
Loading