Monero
Loading...
Searching...
No Matches
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
39namespace tools
40{
41
43{
44public:
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
65private:
66 template<typename T> void handle_payment_changes(const T &res, std::true_type) {
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
77private:
78 boost::optional<std::string> get_info();
79
82 boost::recursive_mutex &m_daemon_rpc_mutex;
85
109 std::vector<std::pair<uint8_t, uint64_t>> m_daemon_hard_forks;
110};
111
112}
static boost::multiprecision::uint128_t fees
Definition blockchain_stats.cpp:58
static uint64_t h
Definition blockchain_stats.cpp:55
Definition abstract_http_client.h:62
std::vector< std::pair< uint8_t, uint64_t > > m_daemon_hard_forks
Definition node_rpc_proxy.h:109
time_t m_target_height_time
Definition node_rpc_proxy.h:108
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
cryptonote::blobdata m_rpc_payment_blob
Definition node_rpc_proxy.h:101
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 handle_payment_changes(const T &res, std::true_type)
Definition node_rpc_proxy.h:66
uint64_t m_rpc_payment_credits_per_hash_found
Definition node_rpc_proxy.h:100
boost::optional< std::string > get_target_height(uint64_t &height)
Definition node_rpc_proxy.cpp:184
uint64_t m_dynamic_base_fee_estimate_cached_height
Definition node_rpc_proxy.h:89
uint64_t m_target_height
Definition node_rpc_proxy.h:95
uint32_t m_rpc_version
Definition node_rpc_proxy.h:94
crypto::hash m_rpc_payment_next_seed_hash
Definition node_rpc_proxy.h:105
epee::net_utils::http::abstract_http_client & m_http_client
Definition node_rpc_proxy.h:80
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
void set_height(uint64_t h)
Definition node_rpc_proxy.cpp:132
boost::recursive_mutex & m_daemon_rpc_mutex
Definition node_rpc_proxy.h:82
std::vector< uint64_t > m_dynamic_base_fee_estimate_vector
Definition node_rpc_proxy.h:91
boost::optional< std::string > get_fee_quantization_mask(uint64_t &fee_quantization_mask)
Definition node_rpc_proxy.cpp:290
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
uint64_t m_rpc_payment_height
Definition node_rpc_proxy.h:102
uint64_t m_dynamic_base_fee_estimate
Definition node_rpc_proxy.h:88
boost::optional< std::string > get_adjusted_time(uint64_t &adjusted_time)
Definition node_rpc_proxy.cpp:209
boost::optional< std::string > get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee)
Definition node_rpc_proxy.cpp:280
uint64_t m_fee_quantization_mask
Definition node_rpc_proxy.h:92
bool m_offline
Definition node_rpc_proxy.h:84
uint64_t m_block_weight_limit
Definition node_rpc_proxy.h:96
boost::optional< std::string > get_height(uint64_t &height)
Definition node_rpc_proxy.cpp:168
void invalidate()
Definition node_rpc_proxy.cpp:65
void set_client_secret_key(const crypto::secret_key &skey)
Definition node_rpc_proxy.h:47
void handle_payment_changes(const T &res, std::false_type)
Definition node_rpc_proxy.h:75
boost::optional< std::string > get_earliest_height(uint8_t version, uint64_t &earliest_height)
Definition node_rpc_proxy.cpp:218
crypto::secret_key m_client_id_secret_key
Definition node_rpc_proxy.h:83
uint64_t m_rpc_payment_seed_height
Definition node_rpc_proxy.h:103
time_t m_height_time
Definition node_rpc_proxy.h:107
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_earliest_height[256]
Definition node_rpc_proxy.h:87
rpc_payment_state_t & m_rpc_payment_state
Definition node_rpc_proxy.h:81
uint64_t m_rpc_payment_diff
Definition node_rpc_proxy.h:99
time_t m_get_info_time
Definition node_rpc_proxy.h:97
void set_offline(bool offline)
Definition node_rpc_proxy.h:49
boost::optional< std::string > get_info()
Definition node_rpc_proxy.cpp:138
time_t m_rpc_payment_info_time
Definition node_rpc_proxy.h:98
crypto::hash m_rpc_payment_seed_hash
Definition node_rpc_proxy.h:104
uint64_t m_adjusted_time
Definition node_rpc_proxy.h:93
boost::optional< std::string > get_block_header_by_height(uint64_t height, cryptonote::block_header_response &block_header)
Definition node_rpc_proxy.cpp:425
uint64_t m_dynamic_base_fee_estimate_grace_blocks
Definition node_rpc_proxy.h:90
boost::optional< std::string > get_block_weight_limit(uint64_t &block_weight_limit)
Definition node_rpc_proxy.cpp:200
uint64_t m_height
Definition node_rpc_proxy.h:86
uint32_t m_rpc_payment_cookie
Definition node_rpc_proxy.h:106
#define CORE_RPC_STATUS_PAYMENT_REQUIRED
Definition core_rpc_server_commands_defs.h:81
#define CORE_RPC_STATUS_OK
Definition core_rpc_server_commands_defs.h:78
const char * res
Definition hmac_keccak.cpp:42
static int version
Definition mdb_load.c:29
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition crypto.h:72
POD_CLASS hash
Definition hash.h:49
std::string blobdata
Definition blobdatatype.h:39
Definition mining.py:1
Various Tools.
Definition apply_permutation.h:40
unsigned int uint32_t
Definition stdint.h:126
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
epee::misc_utils::struct_init< response_t > response
Definition core_rpc_server_commands_defs.h:453
epee::misc_utils::struct_init< request_t > request
Definition core_rpc_server_commands_defs.h:390
Definition core_rpc_server_commands_defs.h:1167
Definition wallet_rpc_helpers.h:50
#define T(x)