Monero
node_rpc_proxy.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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"
37 #include "wallet_rpc_helpers.h"
38 
39 namespace tools
40 {
41 
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 
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) {
69  if (res.top_hash != m_rpc_payment_state.top_hash)
70  {
71  m_rpc_payment_state.top_hash = res.top_hash;
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 
82  boost::recursive_mutex &m_daemon_rpc_mutex;
84  bool m_offline;
85 
91  std::vector<uint64_t> m_dynamic_base_fee_estimate_vector;
109  std::vector<std::pair<uint8_t, uint64_t>> m_daemon_hard_forks;
110 };
111 
112 }
const char * res
Definition: hmac_keccak.cpp:42
uint64_t m_rpc_payment_credits_per_hash_found
Definition: node_rpc_proxy.h:100
const uint32_t T[512]
Definition: groestl_tables.h:36
Definition: mining.py:1
cryptonote::blobdata m_rpc_payment_blob
Definition: node_rpc_proxy.h:101
uint64_t m_adjusted_time
Definition: node_rpc_proxy.h:93
crypto::secret_key m_client_id_secret_key
Definition: node_rpc_proxy.h:83
uint64_t m_rpc_payment_height
Definition: node_rpc_proxy.h:102
boost::optional< std::string > get_block_weight_limit(uint64_t &block_weight_limit)
Definition: node_rpc_proxy.cpp:200
#define CORE_RPC_STATUS_PAYMENT_REQUIRED
Definition: core_rpc_server_commands_defs.h:81
boost::optional< std::string > get_adjusted_time(uint64_t &adjusted_time)
Definition: node_rpc_proxy.cpp:209
Definition: wallet_rpc_helpers.h:49
Definition: node_rpc_proxy.h:42
uint64_t m_rpc_payment_seed_height
Definition: node_rpc_proxy.h:103
boost::optional< std::string > get_info()
Definition: node_rpc_proxy.cpp:138
uint64_t m_rpc_payment_diff
Definition: node_rpc_proxy.h:99
boost::optional< std::string > get_block_header_by_height(uint64_t height, cryptonote::block_header_response &block_header)
Definition: node_rpc_proxy.cpp:425
std::vector< uint64_t > m_dynamic_base_fee_estimate_vector
Definition: node_rpc_proxy.h:91
uint64_t m_earliest_height[256]
Definition: node_rpc_proxy.h:87
unsigned char uint8_t
Definition: stdint.h:124
void handle_payment_changes(const T &res, std::true_type)
Definition: node_rpc_proxy.h:66
void set_client_secret_key(const crypto::secret_key &skey)
Definition: node_rpc_proxy.h:47
uint32_t m_rpc_version
Definition: node_rpc_proxy.h:94
#define CORE_RPC_STATUS_OK
Definition: core_rpc_server_commands_defs.h:78
bool_constant< true > true_type
Definition: gtest-port.h:2210
uint64_t m_dynamic_base_fee_estimate_cached_height
Definition: node_rpc_proxy.h:89
rpc_payment_state_t & m_rpc_payment_state
Definition: node_rpc_proxy.h:81
uint64_t m_target_height
Definition: node_rpc_proxy.h:95
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)
Definition: node_rpc_proxy.cpp:395
uint64_t m_fee_quantization_mask
Definition: node_rpc_proxy.h:92
unsigned int uint32_t
Definition: stdint.h:126
Various Tools.
Definition: apply_permutation.h:39
boost::optional< std::string > get_fee_quantization_mask(uint64_t &fee_quantization_mask)
Definition: node_rpc_proxy.cpp:290
uint64_t m_dynamic_base_fee_estimate
Definition: node_rpc_proxy.h:88
time_t m_get_info_time
Definition: node_rpc_proxy.h:97
epee::net_utils::http::abstract_http_client & m_http_client
Definition: node_rpc_proxy.h:80
unsigned __int64 uint64_t
Definition: stdint.h:136
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)
Definition: node_rpc_proxy.cpp:329
void set_offline(bool offline)
Definition: node_rpc_proxy.h:49
uint64_t credits
Definition: wallet_rpc_helpers.h:51
std::string top_hash
Definition: wallet_rpc_helpers.h:54
Definition: misc_language.h:103
version
Supported socks variants.
Definition: socks.h:57
boost::optional< std::string > get_height(uint64_t &height)
Definition: node_rpc_proxy.cpp:168
diff
Definition: gen_wide_data.py:42
boost::optional< std::string > get_earliest_height(uint8_t version, uint64_t &earliest_height)
Definition: node_rpc_proxy.cpp:218
std::string blobdata
Definition: blobdatatype.h:39
NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, rpc_payment_state_t &rpc_payment_state, boost::recursive_mutex &mutex)
Definition: node_rpc_proxy.cpp:56
boost::optional< std::string > get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee)
Definition: node_rpc_proxy.cpp:280
void invalidate()
Definition: node_rpc_proxy.cpp:65
uint64_t m_dynamic_base_fee_estimate_grace_blocks
Definition: node_rpc_proxy.h:90
crypto::hash m_rpc_payment_seed_hash
Definition: node_rpc_proxy.h:104
bool stale
Definition: wallet_rpc_helpers.h:55
boost::optional< std::string > get_dynamic_base_fee_estimate_2021_scaling(uint64_t grace_blocks, std::vector< uint64_t > &fees)
Definition: node_rpc_proxy.cpp:244
crypto::hash m_rpc_payment_next_seed_hash
Definition: node_rpc_proxy.h:105
time_t m_height_time
Definition: node_rpc_proxy.h:107
std::vector< std::pair< uint8_t, uint64_t > > m_daemon_hard_forks
Definition: node_rpc_proxy.h:109
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)
Definition: node_rpc_proxy.cpp:93
uint64_t m_block_weight_limit
Definition: node_rpc_proxy.h:96
time_t m_target_height_time
Definition: node_rpc_proxy.h:108
uint64_t m_height
Definition: node_rpc_proxy.h:86
bool_constant< false > false_type
Definition: gtest-port.h:2209
static boost::multiprecision::uint128_t fees
Definition: blockchain_stats.cpp:58
bool m_offline
Definition: node_rpc_proxy.h:84
POD_CLASS hash
Definition: hash.h:49
Definition: abstract_http_client.h:61
time_t m_rpc_payment_info_time
Definition: node_rpc_proxy.h:98
Definition: core_rpc_server_commands_defs.h:1166
void handle_payment_changes(const T &res, std::false_type)
Definition: node_rpc_proxy.h:75
boost::recursive_mutex & m_daemon_rpc_mutex
Definition: node_rpc_proxy.h:82
static uint64_t h
Definition: blockchain_stats.cpp:55
uint32_t m_rpc_payment_cookie
Definition: node_rpc_proxy.h:106
void set_height(uint64_t h)
Definition: node_rpc_proxy.cpp:132
boost::optional< std::string > get_target_height(uint64_t &height)
Definition: node_rpc_proxy.cpp:184