| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#pragma once |
| 30 |
|
| 31 |
#include <string> |
| 32 |
#include <boost/thread/mutex.hpp> |
| 33 |
#include <boost/thread/recursive_mutex.hpp> |
| 34 |
#include "include_base_utils.h" |
| 35 |
#include "net/abstract_http_client.h" |
| 36 |
#include "rpc/core_rpc_server_commands_defs.h" |
| 37 |
#include "wallet_rpc_helpers.h" |
| 38 |
|
| 39 |
namespace tools |
| 40 |
{ |
| 41 |
|
| 42 |
class NodeRPCProxy |
| 43 |
{ |
| 44 |
public: |
| 45 |
NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, rpc_payment_state_t &rpc_payment_state, boost::recursive_mutex &mutex); |
| 46 |
|
| 47 |
void set_client_secret_key(const crypto::secret_key &skey) { m_client_id_secret_key = skey; } |
| 48 |
void invalidate(); |
| 49 |
void set_offline(bool offline) { m_offline = offline; } |
| 50 |
|
| 51 |
boost::optional<std::string> get_rpc_version(uint32_t &rpc_version, std::vector<std::pair<uint8_t, uint64_t>> &daemon_hard_forks, uint64_t &height, uint64_t &target_height); |
| 52 |
boost::optional<std::string> get_height(uint64_t &height); |
| 53 |
void set_height(uint64_t h); |
| 54 |
boost::optional<std::string> get_target_height(uint64_t &height); |
| 55 |
boost::optional<std::string> get_block_weight_limit(uint64_t &block_weight_limit); |
| 56 |
boost::optional<std::string> get_adjusted_time(uint64_t &adjusted_time); |
| 57 |
boost::optional<std::string> get_earliest_height(uint8_t version, uint64_t &earliest_height); |
| 58 |
boost::optional<std::string> get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee); |
| 59 |
boost::optional<std::string> get_dynamic_base_fee_estimate_2021_scaling(uint64_t grace_blocks, std::vector<uint64_t> &fees); |
| 60 |
boost::optional<std::string> get_fee_quantization_mask(uint64_t &fee_quantization_mask); |
| 61 |
boost::optional<std::string> get_rpc_payment_info(bool mining, bool &payment_required, uint64_t &credits, uint64_t &diff, uint64_t &credits_per_hash_found, cryptonote::blobdata &blob, uint64_t &height, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, uint32_t &cookie); |
| 62 |
boost::optional<std::string> get_transactions(const std::vector<crypto::hash> &txids, const std::function<void(const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request&, const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response&, bool)> &f); |
| 63 |
boost::optional<std::string> get_block_header_by_height(uint64_t height, cryptonote::block_header_response &block_header); |
| 64 |
|
| 65 |
private: |
| 66 |
template<typename T> void handle_payment_changes(const T &res, std::true_type) { |
| 67 |
if (res.status == CORE_RPC_STATUS_OK || res.status == CORE_RPC_STATUS_PAYMENT_REQUIRED) |
| 68 |
m_rpc_payment_state.credits = res.credits; |
| 69 |
if (res.top_hash != m_rpc_payment_state.top_hash) |
| 70 |
{ |
| 71 |
m_rpc_payment_state.top_hash = res.top_hash; |
| 72 |
m_rpc_payment_state.stale = true; |
| 73 |
} |
| 74 |
} |
| 75 |
template<typename T> void handle_payment_changes(const T &res, std::false_type) {} |
| 76 |
|
| 77 |
private: |
| 78 |
boost::optional<std::string> get_info(); |
| 79 |
|
| 80 |
epee::net_utils::http::abstract_http_client &m_http_client; |
| 81 |
rpc_payment_state_t &m_rpc_payment_state; |
| 82 |
boost::recursive_mutex &m_daemon_rpc_mutex; |
| 83 |
crypto::secret_key m_client_id_secret_key; |
| 84 |
bool m_offline; |
| 85 |
|
| 86 |
uint64_t m_height; |
| 87 |
uint64_t m_earliest_height[256]; |
| 88 |
uint64_t m_dynamic_base_fee_estimate; |
| 89 |
uint64_t m_dynamic_base_fee_estimate_cached_height; |
| 90 |
uint64_t m_dynamic_base_fee_estimate_grace_blocks; |
| 91 |
std::vector<uint64_t> m_dynamic_base_fee_estimate_vector; |
| 92 |
uint64_t m_fee_quantization_mask; |
| 93 |
uint64_t m_adjusted_time; |
| 94 |
uint32_t m_rpc_version; |
| 95 |
uint64_t m_target_height; |
| 96 |
uint64_t m_block_weight_limit; |
| 97 |
time_t m_get_info_time; |
| 98 |
time_t m_rpc_payment_info_time; |
| 99 |
uint64_t m_rpc_payment_diff; |
| 100 |
uint64_t m_rpc_payment_credits_per_hash_found; |
| 101 |
cryptonote::blobdata m_rpc_payment_blob; |
| 102 |
uint64_t m_rpc_payment_height; |
| 103 |
uint64_t m_rpc_payment_seed_height; |
| 104 |
crypto::hash m_rpc_payment_seed_hash; |
| 105 |
crypto::hash m_rpc_payment_next_seed_hash; |
| 106 |
uint32_t m_rpc_payment_cookie; |
| 107 |
time_t m_height_time; |
| 108 |
time_t m_target_height_time; |
| 109 |
std::vector<std::pair<uint8_t, uint64_t>> m_daemon_hard_forks; |
| 110 |
}; |
| 111 |
|
| 112 |
} |