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
7 changes: 2 additions & 5 deletions src/cpp/common/py_monero_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,14 @@ rapidjson::Value monero_request_params::to_rapidjson_val(rapidjson::Document::Al

// --------------------------- MONERO RPC REQUEST ---------------------------

monero_rpc_request::monero_rpc_request(const std::string& method, const boost::optional<py::object>& params, bool json_rpc): m_params(std::make_shared<monero_request_params>(params)) {
m_method = method;
monero_rpc_request::monero_rpc_request(const std::string& method, const boost::optional<py::object>& params, bool json_rpc): m_method(method), m_params(std::make_shared<monero_request_params>(params)) {
if (json_rpc) {
m_id = "0";
m_version = "2.0";
}
}

monero_rpc_request::monero_rpc_request(const std::string& method, const std::shared_ptr<monero::serializable_struct>& params, bool json_rpc):
m_params(params) {
m_method = method;
monero_rpc_request::monero_rpc_request(const std::string& method, const std::shared_ptr<monero::serializable_struct>& params, bool json_rpc): m_method(method), m_params(params) {
if (params == nullptr) m_params = std::make_shared<monero_request_params>();
if (json_rpc) {
m_id = "0";
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/daemon/py_monero_daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class monero_daemon {
*/
virtual ~monero_daemon() {}
monero_daemon() { }
virtual void add_listener(const std::shared_ptr<monero_daemon_listener> &listener) { throw std::runtime_error("monero_daemon: not supported"); }
virtual void remove_listener(const std::shared_ptr<monero_daemon_listener> &listener) { throw std::runtime_error("monero_daemon: not supported"); }
virtual std::vector<std::shared_ptr<monero_daemon_listener>> get_listeners() { throw std::runtime_error("monero_daemon: not supported"); }
virtual void add_listener(monero_daemon_listener &listener) { throw std::runtime_error("monero_daemon: not supported"); }
virtual void remove_listener(monero_daemon_listener &listener) { throw std::runtime_error("monero_daemon: not supported"); }
virtual std::set<monero_daemon_listener*> get_listeners() { throw std::runtime_error("monero_daemon: not supported"); }
virtual void remove_listeners() { throw std::runtime_error("monero_daemon::remove_listeners(): not supported"); };
virtual monero::monero_version get_version() { throw std::runtime_error("monero_daemon: not supported"); }
virtual bool is_trusted() { throw std::runtime_error("monero_daemon: not supported"); }
Expand Down
385 changes: 373 additions & 12 deletions src/cpp/daemon/py_monero_daemon_model.cpp

Large diffs are not rendered by default.

72 changes: 40 additions & 32 deletions src/cpp/daemon/py_monero_daemon_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,15 @@ struct monero_rpc_payment_info : public monero::serializable_struct {
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_rpc_payment_info>& rpc_payment_info);
};

struct monero_alt_chain {
struct monero_alt_chain : public monero::serializable_struct {
public:
std::vector<std::string> m_block_hashes;
boost::optional<uint64_t> m_difficulty;
boost::optional<uint64_t> m_height;
boost::optional<uint64_t> m_length;
boost::optional<std::string> m_main_chain_parent_block_hash;

rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_alt_chain>& alt_chain);
};

Expand All @@ -131,15 +132,16 @@ struct monero_ban : public monero::serializable_struct {
static void from_property_tree(const boost::property_tree::ptree& node, std::vector<std::shared_ptr<monero_ban>>& bans);
};

struct monero_prune_result {
struct monero_prune_result : public monero::serializable_struct {
public:
boost::optional<bool> m_is_pruned;
boost::optional<int> m_pruning_seed;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_prune_result>& result);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_mining_status {
struct monero_mining_status : public monero::serializable_struct {
public:
boost::optional<bool> m_is_active;
boost::optional<bool> m_is_background;
Expand All @@ -148,46 +150,50 @@ struct monero_mining_status {
boost::optional<int> m_num_threads;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_mining_status>& status);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_miner_tx_sum {
struct monero_miner_tx_sum : public monero::serializable_struct {
public:
boost::optional<uint64_t> m_emission_sum;
boost::optional<uint64_t> m_fee_sum;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_miner_tx_sum>& sum);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_block_template {
struct monero_block_template : public monero::serializable_struct {
public:
boost::optional<std::string> m_block_template_blob;
boost::optional<std::string> m_block_hashing_blob;
boost::optional<std::string> m_prev_hash;
boost::optional<std::string> m_seed_hash;
boost::optional<std::string> m_next_seed_hash;
boost::optional<uint64_t> m_difficulty;
boost::optional<uint64_t> m_expected_reward;
boost::optional<uint64_t> m_height;
boost::optional<std::string> m_prev_hash;
boost::optional<uint64_t> m_reserved_offset;
boost::optional<uint64_t> m_seed_height;
boost::optional<std::string> m_seed_hash;
boost::optional<std::string> m_next_seed_hash;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_block_template>& tmplt);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_connection_span {
struct monero_connection_span : public monero::serializable_struct {
public:
boost::optional<std::string> m_connection_id;
boost::optional<uint64_t> m_num_blocks;
boost::optional<std::string> m_remote_address;
boost::optional<uint64_t> m_num_blocks;
boost::optional<uint64_t> m_rate;
boost::optional<uint64_t> m_speed;
boost::optional<uint64_t> m_size;
boost::optional<uint64_t> m_start_height;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_connection_span>& span);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_peer {
struct monero_peer : public monero::serializable_struct {
public:
boost::optional<std::string> m_id;
boost::optional<std::string> m_address;
Expand Down Expand Up @@ -218,45 +224,46 @@ struct monero_peer {

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_peer>& peer);
static void from_property_tree(const boost::property_tree::ptree& node, std::vector<std::shared_ptr<monero_peer>>& peers);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_submit_tx_result : public monero_rpc_payment_info {
public:
boost::optional<bool> m_has_invalid_input;
boost::optional<bool> m_has_invalid_output;
boost::optional<bool> m_has_too_few_outputs;
boost::optional<bool> m_is_good;
boost::optional<bool> m_is_relayed;
boost::optional<bool> m_is_double_spend;
boost::optional<bool> m_is_fee_too_low;
boost::optional<bool> m_is_mixin_too_low;
boost::optional<bool> m_has_invalid_input;
boost::optional<bool> m_has_invalid_output;
boost::optional<bool> m_has_too_few_outputs;
boost::optional<bool> m_is_overspend;
boost::optional<bool> m_is_too_big;
boost::optional<bool> m_sanity_check_failed;
boost::optional<std::string> m_reason;
boost::optional<uint64_t> m_credits;
boost::optional<std::string> m_top_block_hash;
boost::optional<bool> m_is_tx_extra_too_big;
boost::optional<bool> m_is_nonzero_unlock_time;
boost::optional<std::string> m_reason;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_submit_tx_result>& result);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_tx_backlog_entry {
// TODO
};

struct monero_output_distribution_entry {
struct monero_output_distribution_entry : public monero::serializable_struct {
public:
boost::optional<uint64_t> m_amount;
boost::optional<int> m_base;
std::vector<int> m_distribution;
boost::optional<uint64_t> m_start_height;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_distribution_entry>& entry);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_output_histogram_entry {
struct monero_output_histogram_entry : public monero::serializable_struct {
public:
boost::optional<uint64_t> m_amount;
boost::optional<uint64_t> m_num_instances;
Expand All @@ -265,6 +272,7 @@ struct monero_output_histogram_entry {

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_output_histogram_entry>& entry);
static void from_property_tree(const boost::property_tree::ptree& node, std::vector<std::shared_ptr<monero_output_histogram_entry>>& entries);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_tx_pool_stats : public monero::serializable_struct {
Expand All @@ -287,7 +295,7 @@ struct monero_tx_pool_stats : public monero::serializable_struct {
static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_tx_pool_stats>& stats);
};

struct monero_daemon_update_check_result {
struct monero_daemon_update_check_result : public monero::serializable_struct {
public:
boost::optional<bool> m_is_update_available;
boost::optional<std::string> m_version;
Expand All @@ -296,22 +304,25 @@ struct monero_daemon_update_check_result {
boost::optional<std::string> m_user_uri;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_daemon_update_check_result>& check);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_daemon_update_download_result : public monero_daemon_update_check_result {
public:
boost::optional<std::string> m_download_path;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_daemon_update_download_result>& check);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_fee_estimate {
struct monero_fee_estimate : public monero::serializable_struct {
public:
boost::optional<uint64_t> m_quantization_mask;
boost::optional<uint64_t> m_fee;
std::vector<uint64_t> m_fees;
boost::optional<uint64_t> m_quantization_mask;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_fee_estimate>& estimate);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_daemon_info : public monero_rpc_payment_info {
Expand Down Expand Up @@ -339,46 +350,43 @@ struct monero_daemon_info : public monero_rpc_payment_info {
boost::optional<uint64_t> m_adjusted_timestamp;
boost::optional<uint64_t> m_target;
boost::optional<uint64_t> m_target_height;
boost::optional<std::string> m_top_block_hash;
boost::optional<int> m_num_txs;
boost::optional<int> m_num_txs_pool;
boost::optional<bool> m_was_bootstrap_ever_used;
boost::optional<uint64_t> m_database_size;
boost::optional<bool> m_update_available;
boost::optional<uint64_t> m_credits;
boost::optional<bool> m_is_busy_syncing;
boost::optional<bool> m_is_synchronized;
boost::optional<bool> m_is_restricted;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_daemon_info>& info);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_daemon_sync_info : public monero_rpc_payment_info {
public:
boost::optional<std::string> m_overview;
boost::optional<uint64_t> m_height;
std::vector<monero_peer> m_peers;
std::vector<monero_connection_span> m_spans;
boost::optional<uint64_t> m_target_height;
boost::optional<int> m_next_needed_pruning_seed;
boost::optional<std::string> m_overview;
boost::optional<uint64_t> m_credits;
boost::optional<std::string> m_top_block_hash;
std::vector<monero_peer> m_peers;
std::vector<monero_connection_span> m_spans;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_daemon_sync_info>& info);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

struct monero_hard_fork_info : public monero_rpc_payment_info {
public:
boost::optional<uint64_t> m_earliest_height;
boost::optional<bool> m_is_enabled;
boost::optional<uint64_t> m_earliest_height;
boost::optional<int> m_state;
boost::optional<int> m_threshold;
boost::optional<int> m_version;
boost::optional<int> m_num_votes;
boost::optional<int> m_window;
boost::optional<int> m_voting;
boost::optional<uint64_t> m_credits;
boost::optional<std::string> m_top_block_hash;

static void from_property_tree(const boost::property_tree::ptree& node, const std::shared_ptr<monero_hard_fork_info>& info);
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};
19 changes: 9 additions & 10 deletions src/cpp/daemon/py_monero_daemon_rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ class monero_daemon_poller: public thread_poller {
std::shared_ptr<monero::monero_block_header> m_last_header;

void announce_block_header(const std::shared_ptr<monero::monero_block_header>& header) {
const auto& listeners = m_daemon->get_listeners();
for (const auto& listener : listeners) {
auto listeners = m_daemon->get_listeners();
for (auto& listener : listeners) {
try {
listener->on_block_header(header);

} catch (const std::exception& e) {
MERROR("Error calling listener on new block header: " << e.what());
}
Expand Down Expand Up @@ -128,20 +127,20 @@ monero_daemon_rpc::monero_daemon_rpc(const std::string& uri, const std::string&
if (!uri.empty()) m_rpc->check_connection();
}

std::vector<std::shared_ptr<monero_daemon_listener>> monero_daemon_rpc::get_listeners() {
std::set<monero_daemon_listener*> monero_daemon_rpc::get_listeners() {
boost::lock_guard<boost::recursive_mutex> lock(m_listeners_mutex);
return m_listeners;
}

void monero_daemon_rpc::add_listener(const std::shared_ptr<monero_daemon_listener> &listener) {
void monero_daemon_rpc::add_listener(monero_daemon_listener &listener) {
boost::lock_guard<boost::recursive_mutex> lock(m_listeners_mutex);
m_listeners.push_back(listener);
m_listeners.insert(&listener);
refresh_listening();
}

void monero_daemon_rpc::remove_listener(const std::shared_ptr<monero_daemon_listener> &listener) {
void monero_daemon_rpc::remove_listener(monero_daemon_listener &listener) {
boost::lock_guard<boost::recursive_mutex> lock(m_listeners_mutex);
m_listeners.erase(std::remove_if(m_listeners.begin(), m_listeners.end(), [&listener](std::shared_ptr<monero_daemon_listener> iter){ return iter == listener; }), m_listeners.end());
m_listeners.erase(&listener);
refresh_listening();
}

Expand Down Expand Up @@ -752,7 +751,7 @@ std::shared_ptr<monero::monero_block_header> monero_daemon_rpc::wait_for_next_bl
bool ready = false;

// create listener which notifies condition variable when block is added
auto block_listener = std::make_shared<block_notifier>(&temp, &cv, &ready);
block_notifier block_listener(&temp, &cv, &ready);

// register the listener
add_listener(block_listener);
Expand All @@ -765,7 +764,7 @@ std::shared_ptr<monero::monero_block_header> monero_daemon_rpc::wait_for_next_bl
remove_listener(block_listener);

// return last height
return block_listener->m_last_header;
return block_listener.m_last_header;
}

std::shared_ptr<monero_bandwidth_limits> monero_daemon_rpc::get_bandwidth_limits() {
Expand Down
8 changes: 4 additions & 4 deletions src/cpp/daemon/py_monero_daemon_rpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class monero_daemon_rpc : public monero_daemon {
/**
* 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;
std::set<monero_daemon_listener*> get_listeners() override;
void add_listener(monero_daemon_listener &listener) override;
void remove_listener(monero_daemon_listener &listener) override;
void remove_listeners() override;
std::shared_ptr<PyMoneroRpcConnection> get_rpc_connection() const;
bool is_connected();
Expand Down Expand Up @@ -142,7 +142,7 @@ class monero_daemon_rpc : public monero_daemon {
private:
friend class monero_daemon_poller;
mutable boost::recursive_mutex m_listeners_mutex;
std::vector<std::shared_ptr<monero_daemon_listener>> m_listeners;
std::set<monero_daemon_listener*> m_listeners;
std::shared_ptr<PyMoneroRpcConnection> m_rpc;
std::shared_ptr<monero_daemon_poller> m_poller;
std::unordered_map<uint64_t, std::shared_ptr<monero::monero_block_header>> m_cached_headers;
Expand Down
Loading
Loading