Monero
node_rpc_proxy.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2020, 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 "include_base_utils.h"
34 #include "net/abstract_http_client.h"
36 #include "wallet_rpc_helpers.h"
37 
38 namespace tools
39 {
40 
42 {
43 public:
44  NodeRPCProxy(epee::net_utils::http::abstract_http_client &http_client, rpc_payment_state_t &rpc_payment_state, boost::recursive_mutex &mutex);
45 
47  void invalidate();
48  void set_offline(bool offline) { m_offline = offline; }
49 
50  boost::optional<std::string> get_rpc_version(uint32_t &version);
51  boost::optional<std::string> get_height(uint64_t &height);
52  void set_height(uint64_t h);
53  boost::optional<std::string> get_target_height(uint64_t &height);
54  boost::optional<std::string> get_block_weight_limit(uint64_t &block_weight_limit);
55  boost::optional<std::string> get_adjusted_time(uint64_t &adjusted_time);
56  boost::optional<std::string> get_earliest_height(uint8_t version, uint64_t &earliest_height);
57  boost::optional<std::string> get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee);
58  boost::optional<std::string> get_fee_quantization_mask(uint64_t &fee_quantization_mask);
59  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);
60 
61 private:
62  template<typename T> void handle_payment_changes(const T &res, std::true_type) {
63  if (res.status == CORE_RPC_STATUS_OK || res.status == CORE_RPC_STATUS_PAYMENT_REQUIRED)
64  m_rpc_payment_state.credits = res.credits;
65  if (res.top_hash != m_rpc_payment_state.top_hash)
66  {
67  m_rpc_payment_state.top_hash = res.top_hash;
69  }
70  }
71  template<typename T> void handle_payment_changes(const T &res, std::false_type) {}
72 
73 private:
74  boost::optional<std::string> get_info();
75 
76  epee::net_utils::http::abstract_http_client &m_http_client;
78  boost::recursive_mutex &m_daemon_rpc_mutex;
80  bool m_offline;
81 
82  uint64_t m_height;
83  uint64_t m_earliest_height[256];
88  uint64_t m_adjusted_time;
89  uint32_t m_rpc_version;
90  uint64_t m_target_height;
103 };
104 
105 }
Definition: node_rpc_proxy.h:42
cryptonote::blobdata m_rpc_payment_blob
Definition: node_rpc_proxy.h:96
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:285
void handle_payment_changes(const T &res, std::true_type)
Definition: node_rpc_proxy.h:62
uint64_t m_rpc_payment_credits_per_hash_found
Definition: node_rpc_proxy.h:95
boost::optional< std::string > get_target_height(uint64_t &height)
Definition: node_rpc_proxy.cpp:158
uint64_t m_dynamic_base_fee_estimate_cached_height
Definition: node_rpc_proxy.h:85
uint64_t m_target_height
Definition: node_rpc_proxy.h:90
uint32_t m_rpc_version
Definition: node_rpc_proxy.h:89
crypto::hash m_rpc_payment_next_seed_hash
Definition: node_rpc_proxy.h:100
epee::net_utils::http::abstract_http_client & m_http_client
Definition: node_rpc_proxy.h:76
void set_height(uint64_t h)
Definition: node_rpc_proxy.cpp:107
boost::recursive_mutex & m_daemon_rpc_mutex
Definition: node_rpc_proxy.h:78
boost::optional< std::string > get_fee_quantization_mask(uint64_t &fee_quantization_mask)
Definition: node_rpc_proxy.cpp:246
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:54
uint64_t m_rpc_payment_height
Definition: node_rpc_proxy.h:97
uint64_t m_dynamic_base_fee_estimate
Definition: node_rpc_proxy.h:84
boost::optional< std::string > get_adjusted_time(uint64_t &adjusted_time)
Definition: node_rpc_proxy.cpp:176
boost::optional< std::string > get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee)
Definition: node_rpc_proxy.cpp:211
uint64_t m_fee_quantization_mask
Definition: node_rpc_proxy.h:87
bool m_offline
Definition: node_rpc_proxy.h:80
uint64_t m_block_weight_limit
Definition: node_rpc_proxy.h:91
boost::optional< std::string > get_height(uint64_t &height)
Definition: node_rpc_proxy.cpp:142
void invalidate()
Definition: node_rpc_proxy.cpp:63
void set_client_secret_key(const crypto::secret_key &skey)
Definition: node_rpc_proxy.h:46
void handle_payment_changes(const T &res, std::false_type)
Definition: node_rpc_proxy.h:71
boost::optional< std::string > get_earliest_height(uint8_t version, uint64_t &earliest_height)
Definition: node_rpc_proxy.cpp:185
crypto::secret_key m_client_id_secret_key
Definition: node_rpc_proxy.h:79
uint64_t m_rpc_payment_seed_height
Definition: node_rpc_proxy.h:98
time_t m_height_time
Definition: node_rpc_proxy.h:102
uint64_t m_earliest_height[256]
Definition: node_rpc_proxy.h:83
rpc_payment_state_t & m_rpc_payment_state
Definition: node_rpc_proxy.h:77
uint64_t m_rpc_payment_diff
Definition: node_rpc_proxy.h:94
time_t m_get_info_time
Definition: node_rpc_proxy.h:92
void set_offline(bool offline)
Definition: node_rpc_proxy.h:48
boost::optional< std::string > get_info()
Definition: node_rpc_proxy.cpp:113
time_t m_rpc_payment_info_time
Definition: node_rpc_proxy.h:93
crypto::hash m_rpc_payment_seed_hash
Definition: node_rpc_proxy.h:99
boost::optional< std::string > get_rpc_version(uint32_t &version)
Definition: node_rpc_proxy.cpp:88
uint64_t m_adjusted_time
Definition: node_rpc_proxy.h:88
uint64_t m_dynamic_base_fee_estimate_grace_blocks
Definition: node_rpc_proxy.h:86
boost::optional< std::string > get_block_weight_limit(uint64_t &block_weight_limit)
Definition: node_rpc_proxy.cpp:167
uint64_t m_height
Definition: node_rpc_proxy.h:82
uint32_t m_rpc_payment_cookie
Definition: node_rpc_proxy.h:101
#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 uint32_t T[512]
Definition: groestl_tables.h:36
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
Definition: crypto.h:67
POD_CLASS hash
Definition: hash.h:48
std::string blobdata
Definition: blobdatatype.h:39
version
Supported socks variants.
Definition: socks.h:58
char true_type
Definition: sfinae_helpers.h:39
Various Tools.
Definition: apply_permutation.h:40
Definition: wallet_rpc_helpers.h:49
std::string top_hash
Definition: wallet_rpc_helpers.h:53
uint64_t credits
Definition: wallet_rpc_helpers.h:50
bool stale
Definition: wallet_rpc_helpers.h:54