Monero C++ Library
Loading...
Searching...
No Matches
monero_daemon_rpc.h
1
54#pragma once
55
56#include "monero_daemon.h"
57
61namespace monero {
62
63 // forward declaration of internal daemon poller
65
69 class monero_daemon_rpc : public monero_daemon {
70 public:
71
75 ~monero_daemon_rpc() override;
76 monero_daemon_rpc(const std::shared_ptr<monero_rpc_connection>& rpc);
77 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 = "", const boost::optional<uint32_t>& timeout = boost::none);
78
84 std::shared_ptr<monero_rpc_connection> get_rpc_connection() const;
85
91 bool is_connected();
92
98 void set_poll_period_in_ms(uint64_t period_ms);
99
103 std::set<monero_daemon_listener*> get_listeners() override;
104 void add_listener(monero_daemon_listener &listener) override;
105 void remove_listener(monero_daemon_listener &listener) override;
106 void remove_listeners() override;
107 monero_version get_version() override;
108 bool is_trusted() override;
109 uint64_t get_height() override;
110 std::string get_block_hash(uint64_t height) override;
111 std::shared_ptr<monero_block_template> get_block_template(const std::string& wallet_address, const boost::optional<int>& reserve_size = boost::none) override;
112 std::shared_ptr<monero_block_header> get_last_block_header() override;
113 std::shared_ptr<monero_block_header> get_block_header_by_hash(const std::string& hash) override;
114 std::shared_ptr<monero_block_header> get_block_header_by_height(uint64_t height) override;
115 std::vector<std::shared_ptr<monero_block_header>> get_block_headers_by_range(uint64_t start_height, uint64_t end_height) override;
116 std::shared_ptr<monero_block> get_block_by_hash(const std::string& hash) override;
117 std::vector<std::shared_ptr<monero_block>> get_blocks_by_hash(const std::vector<std::string>& block_hashes, uint64_t start_height, bool prune) override;
118 std::shared_ptr<monero_block> get_block_by_height(uint64_t height) override;
119 std::vector<std::shared_ptr<monero_block>> get_blocks_by_height(const std::vector<uint64_t>& heights) override;
120 std::vector<std::shared_ptr<monero_block>> get_blocks_by_range(boost::optional<uint64_t> start_height, boost::optional<uint64_t> end_height) override;
121 std::vector<std::shared_ptr<monero_block>> get_blocks_by_range_chunked(boost::optional<uint64_t> start_height, boost::optional<uint64_t> end_height, boost::optional<uint64_t> max_chunk_size) override;
122 std::vector<std::string> get_block_hashes(const std::vector<std::string>& block_hashes, uint64_t start_height) override;
123 std::vector<std::shared_ptr<monero_tx>> get_txs(const std::vector<std::string>& tx_hashes, bool prune = false) override;
124 std::vector<std::string> get_tx_hexes(const std::vector<std::string>& tx_hashes, bool prune = false) override;
125 std::shared_ptr<monero_miner_tx_sum> get_miner_tx_sum(uint64_t height, uint64_t num_blocks) override;
126 std::shared_ptr<monero_fee_estimate> get_fee_estimate(uint64_t grace_blocks = 0) override;
127 std::shared_ptr<monero_submit_tx_result> submit_tx_hex(const std::string& tx_hex, bool do_not_relay = false) override;
128 void relay_txs_by_hash(const std::vector<std::string>& tx_hashes) override;
129 std::shared_ptr<monero_tx_pool_stats> get_tx_pool_stats() override;
130 std::vector<std::shared_ptr<monero_tx>> get_tx_pool() override;
131 std::vector<std::string> get_tx_pool_hashes() override;
132 void flush_tx_pool(const std::vector<std::string> &hashes) override;
133 void flush_tx_pool() override;
134 void flush_tx_pool(const std::string &hash) override;
135 std::vector<monero_key_image_spent_status> get_key_image_spent_statuses(const std::vector<std::string>& key_images) override;
136 std::vector<std::shared_ptr<monero_output>> get_outputs(const std::vector<monero_output>& outputs) override;
137 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;
138 std::vector<std::shared_ptr<monero_output_distribution_entry>> get_output_distribution(const std::vector<uint64_t>& amounts, const boost::optional<bool>& is_cumulative = boost::none, const boost::optional<uint64_t>& start_height = boost::none, const boost::optional<uint64_t>& end_height = boost::none) override;
139 std::shared_ptr<monero_daemon_info> get_info() override;
140 std::shared_ptr<monero_daemon_sync_info> get_sync_info() override;
141 std::shared_ptr<monero_hard_fork_info> get_hard_fork_info() override;
142 std::vector<std::shared_ptr<monero_alt_chain>> get_alt_chains() override;
143 std::vector<std::string> get_alt_block_hashes() override;
144 int get_download_limit() override;
145 int set_download_limit(int limit) override;
146 int reset_download_limit() override;
147 int get_upload_limit() override;
148 int set_upload_limit(int limit) override;
149 int reset_upload_limit() override;
150 std::vector<std::shared_ptr<monero_peer>> get_peers() override;
151 std::vector<std::shared_ptr<monero_peer>> get_known_peers() override;
152 void set_outgoing_peer_limit(int limit) override;
153 void set_incoming_peer_limit(int limit) override;
154 std::vector<std::shared_ptr<monero_ban>> get_peer_bans() override;
155 void set_peer_bans(const std::vector<std::shared_ptr<monero_ban>>& bans) override;
156 void start_mining(const std::string &address, boost::optional<uint64_t> num_threads, boost::optional<bool> background_mining, boost::optional<bool> ignore_battery) override;
157 void stop_mining() override;
158 std::shared_ptr<monero_mining_status> get_mining_status() override;
159 std::shared_ptr<monero_generate_blocks_result> generate_blocks(const std::string& wallet_address, uint64_t num_blocks, const boost::optional<std::string>& prev_block_hash = boost::none, const boost::optional<uint32_t>& starting_nonce = boost::none) override;
160 void submit_blocks(const std::vector<std::string>& block_blobs) override;
161 std::shared_ptr<monero_prune_result> prune_blockchain(bool check) override;
162 std::shared_ptr<monero_daemon_update_check_result> check_for_update() override;
163 std::shared_ptr<monero_daemon_update_download_result> download_update(const std::string& path = "") override;
164 void stop() override;
165 std::shared_ptr<monero_block_header> wait_for_next_block_header() override;
166
167 // --------------------------------- PRIVATE --------------------------------
168
169 private:
170 friend class monero_daemon_poller;
171 mutable boost::recursive_mutex m_listeners_mutex;
172 std::set<monero_daemon_listener*> m_listeners;
173 std::shared_ptr<monero_rpc_connection> m_rpc;
174 boost::mutex m_poller_mutex;
175 std::unique_ptr<monero_daemon_poller> m_poller;
176
177 // header_cache is scoped to a single get_blocks_by_range_chunked() call (see below) rather than
178 // stored as a member: it only helps avoid re-fetching a header already seen earlier in that one
179 // chunking pass, and keeping it as instance state would let it grow unbounded over the connection's
180 // lifetime and serve stale headers across reorgs on later calls
181 std::vector<std::shared_ptr<monero_block>> get_max_blocks(boost::optional<uint64_t> start_height, boost::optional<uint64_t> max_height, boost::optional<uint64_t> chunk_size, std::unordered_map<uint64_t, std::shared_ptr<monero_block_header>>& header_cache);
182 std::shared_ptr<monero_block_header> get_block_header_by_height_cached(uint64_t height, uint64_t max_height, std::unordered_map<uint64_t, std::shared_ptr<monero_block_header>>& header_cache);
183 std::shared_ptr<monero_bandwidth_limits> get_bandwidth_limits();
184 std::shared_ptr<monero_bandwidth_limits> set_bandwidth_limits(int up, int down);
185 void refresh_listening();
186 void wait_for_listener_callbacks_idle();
187 };
188
189}
Definition monero_daemon.h:66
Definition monero_daemon_rpc.cpp:68
std::vector< std::string > get_tx_pool_hashes() override
Definition monero_daemon_rpc.cpp:527
void start_mining(const std::string &address, boost::optional< uint64_t > num_threads, boost::optional< bool > background_mining, boost::optional< bool > ignore_battery) override
Definition monero_daemon_rpc.cpp:723
std::vector< std::shared_ptr< monero_block > > get_blocks_by_hash(const std::vector< std::string > &block_hashes, uint64_t start_height, bool prune) override
Definition monero_daemon_rpc.cpp:328
std::shared_ptr< monero_daemon_info > get_info() override
Definition monero_daemon_rpc.cpp:587
void flush_tx_pool() override
Definition monero_daemon_rpc.cpp:542
std::vector< std::shared_ptr< monero_block > > get_blocks_by_range(boost::optional< uint64_t > start_height, boost::optional< uint64_t > end_height) override
Definition monero_daemon_rpc.cpp:354
std::vector< std::shared_ptr< monero_peer > > get_known_peers() override
Definition monero_daemon_rpc.cpp:681
std::shared_ptr< monero_block_template > get_block_template(const std::string &wallet_address, const boost::optional< int > &reserve_size=boost::none) override
Definition monero_daemon_rpc.cpp:253
std::shared_ptr< monero_prune_result > prune_blockchain(bool check) override
Definition monero_daemon_rpc.cpp:767
void set_peer_bans(const std::vector< std::shared_ptr< monero_ban > > &bans) override
Definition monero_daemon_rpc.cpp:716
std::vector< std::shared_ptr< monero_output > > get_outputs(const std::vector< monero_output > &outputs) override
Definition monero_daemon_rpc.cpp:563
void remove_listeners() override
Definition monero_daemon_rpc.cpp:188
std::vector< std::shared_ptr< monero_alt_chain > > get_alt_chains() override
Definition monero_daemon_rpc.cpp:611
std::shared_ptr< monero_block_header > get_block_header_by_hash(const std::string &hash) override
Definition monero_daemon_rpc.cpp:271
std::vector< std::shared_ptr< monero_output_distribution_entry > > get_output_distribution(const std::vector< uint64_t > &amounts, const boost::optional< bool > &is_cumulative=boost::none, const boost::optional< uint64_t > &start_height=boost::none, const boost::optional< uint64_t > &end_height=boost::none) override
Definition monero_daemon_rpc.cpp:577
std::set< monero_daemon_listener * > get_listeners() override
Definition monero_daemon_rpc.cpp:166
std::shared_ptr< monero_daemon_sync_info > get_sync_info() override
Definition monero_daemon_rpc.cpp:595
void relay_txs_by_hash(const std::vector< std::string > &tx_hashes) override
Definition monero_daemon_rpc.cpp:504
std::shared_ptr< monero_daemon_update_check_result > check_for_update() override
Definition monero_daemon_rpc.cpp:777
std::shared_ptr< monero_block_header > wait_for_next_block_header() override
Definition monero_daemon_rpc.cpp:803
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
Definition monero_daemon_rpc.cpp:567
std::shared_ptr< monero_daemon_update_download_result > download_update(const std::string &path="") override
Definition monero_daemon_rpc.cpp:787
std::vector< monero_key_image_spent_status > get_key_image_spent_statuses(const std::vector< std::string > &key_images) override
Definition monero_daemon_rpc.cpp:553
int set_upload_limit(int limit) override
Definition monero_daemon_rpc.cpp:657
void set_outgoing_peer_limit(int limit) override
Definition monero_daemon_rpc.cpp:689
std::vector< std::shared_ptr< monero_tx > > get_txs(const std::vector< std::string > &tx_hashes, bool prune=false) override
Definition monero_daemon_rpc.cpp:435
std::vector< std::string > get_alt_block_hashes() override
Definition monero_daemon_rpc.cpp:619
int get_download_limit() override
Definition monero_daemon_rpc.cpp:627
std::shared_ptr< monero_block_header > get_last_block_header() override
Definition monero_daemon_rpc.cpp:263
void stop() override
Definition monero_daemon_rpc.cpp:797
std::shared_ptr< monero_miner_tx_sum > get_miner_tx_sum(uint64_t height, uint64_t num_blocks) override
Definition monero_daemon_rpc.cpp:469
void set_poll_period_in_ms(uint64_t period_ms)
Definition monero_daemon_rpc.cpp:130
std::shared_ptr< monero_generate_blocks_result > generate_blocks(const std::string &wallet_address, uint64_t num_blocks, const boost::optional< std::string > &prev_block_hash=boost::none, const boost::optional< uint32_t > &starting_nonce=boost::none) override
Definition monero_daemon_rpc.cpp:747
std::vector< std::shared_ptr< monero_block > > get_blocks_by_height(const std::vector< uint64_t > &heights) override
Definition monero_daemon_rpc.cpp:341
int get_upload_limit() override
Definition monero_daemon_rpc.cpp:650
bool is_trusted() override
Definition monero_daemon_rpc.cpp:230
std::shared_ptr< monero_rpc_connection > get_rpc_connection() const
Definition monero_daemon_rpc.cpp:207
std::vector< std::shared_ptr< monero_tx > > get_tx_pool() override
Definition monero_daemon_rpc.cpp:519
void set_incoming_peer_limit(int limit) override
Definition monero_daemon_rpc.cpp:698
int set_download_limit(int limit) override
Definition monero_daemon_rpc.cpp:634
std::shared_ptr< monero_tx_pool_stats > get_tx_pool_stats() override
Definition monero_daemon_rpc.cpp:511
std::string get_block_hash(uint64_t height) override
Definition monero_daemon_rpc.cpp:247
std::vector< std::shared_ptr< monero_block > > get_blocks_by_range_chunked(boost::optional< uint64_t > start_height, boost::optional< uint64_t > end_height, boost::optional< uint64_t > max_chunk_size) override
Definition monero_daemon_rpc.cpp:367
bool is_connected()
Definition monero_daemon_rpc.cpp:212
std::shared_ptr< monero_block > get_block_by_hash(const std::string &hash) override
Definition monero_daemon_rpc.cpp:298
std::vector< std::shared_ptr< monero_block_header > > get_block_headers_by_range(uint64_t start_height, uint64_t end_height) override
Definition monero_daemon_rpc.cpp:289
std::vector< std::shared_ptr< monero_peer > > get_peers() override
Definition monero_daemon_rpc.cpp:673
void remove_listener(monero_daemon_listener &listener) override
Definition monero_daemon_rpc.cpp:179
std::shared_ptr< monero_hard_fork_info > get_hard_fork_info() override
Definition monero_daemon_rpc.cpp:603
void add_listener(monero_daemon_listener &listener) override
Definition monero_daemon_rpc.cpp:171
monero_version get_version() override
Definition monero_daemon_rpc.cpp:222
std::vector< std::string > get_tx_hexes(const std::vector< std::string > &tx_hashes, bool prune=false) override
Definition monero_daemon_rpc.cpp:454
void submit_blocks(const std::vector< std::string > &block_blobs) override
Definition monero_daemon_rpc.cpp:759
void stop_mining() override
Definition monero_daemon_rpc.cpp:732
std::shared_ptr< monero_block_header > get_block_header_by_height(uint64_t height) override
Definition monero_daemon_rpc.cpp:280
std::vector< std::shared_ptr< monero_ban > > get_peer_bans() override
Definition monero_daemon_rpc.cpp:707
std::shared_ptr< monero_block > get_block_by_height(uint64_t height) override
Definition monero_daemon_rpc.cpp:332
std::shared_ptr< monero_submit_tx_result > submit_tx_hex(const std::string &tx_hex, bool do_not_relay=false) override
Definition monero_daemon_rpc.cpp:487
uint64_t get_height() override
Definition monero_daemon_rpc.cpp:238
std::shared_ptr< monero_fee_estimate > get_fee_estimate(uint64_t grace_blocks=0) override
Definition monero_daemon_rpc.cpp:478
int reset_download_limit() override
Definition monero_daemon_rpc.cpp:643
~monero_daemon_rpc() override
Definition monero_daemon_rpc.cpp:888
std::shared_ptr< monero_mining_status > get_mining_status() override
Definition monero_daemon_rpc.cpp:738
std::vector< std::string > get_block_hashes(const std::vector< std::string > &block_hashes, uint64_t start_height) override
Definition monero_daemon_rpc.cpp:431
int reset_upload_limit() override
Definition monero_daemon_rpc.cpp:666
Definition monero_daemon.h:83
Definition monero_error.h:61
Definition monero_daemon_model.h:140