Electroneum
node_rpc_proxy.h
Go to the documentation of this file.
1 // Copyright (c) 2017-2020, The Electroneum Project
2 // Copyright (c) 2017-2019, The Monero Project
3 //
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without modification, are
7 // permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this list of
10 // conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
13 // of conditions and the following disclaimer in the documentation and/or other
14 // materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its contributors may be
17 // used to endorse or promote products derived from this software without specific
18 // prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
28 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30 #pragma once
31 
32 #include <string>
33 #include <boost/thread/mutex.hpp>
34 #include "include_base_utils.h"
35 #include "net/http_client.h"
36 
37 namespace tools
38 {
39 
41 {
42 public:
43  NodeRPCProxy(epee::net_utils::http::http_simple_client &http_client, boost::recursive_mutex &mutex);
44 
45  void invalidate();
46  void set_offline(bool offline) { m_offline = offline; }
47 
48  boost::optional<std::string> get_rpc_version(uint32_t &version) const;
49  boost::optional<std::string> get_height(uint64_t &height) const;
50  void set_height(uint64_t h);
51  boost::optional<std::string> get_target_height(uint64_t &height) const;
52  boost::optional<std::string> get_block_weight_limit(uint64_t &block_weight_limit) const;
53  boost::optional<std::string> get_earliest_height(uint8_t version, uint64_t &earliest_height) const;
54  boost::optional<std::string> get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee) const;
55  boost::optional<std::string> get_fee_quantization_mask(uint64_t &fee_quantization_mask) const;
56 
57 private:
58  boost::optional<std::string> get_info() const;
59 
60  epee::net_utils::http::http_simple_client &m_http_client;
61  boost::recursive_mutex &m_daemon_rpc_mutex;
62  bool m_offline;
63 
64  mutable uint64_t m_height;
65  mutable uint64_t m_earliest_height[256];
66  mutable uint64_t m_dynamic_base_fee_estimate;
69  mutable uint64_t m_fee_quantization_mask;
70  mutable uint32_t m_rpc_version;
71  mutable uint64_t m_target_height;
72  mutable uint64_t m_block_weight_limit;
73  mutable time_t m_get_info_time;
74 };
75 
76 }
uint64_t height
Definition: blockchain.cpp:91
uint8_t version
Definition: blockchain.cpp:90
Definition: node_rpc_proxy.h:41
boost::optional< std::string > get_target_height(uint64_t &height) const
Definition: node_rpc_proxy.cpp:123
uint64_t m_dynamic_base_fee_estimate_cached_height
Definition: node_rpc_proxy.h:67
uint64_t m_target_height
Definition: node_rpc_proxy.h:71
boost::optional< std::string > get_rpc_version(uint32_t &version) const
Definition: node_rpc_proxy.cpp:64
uint32_t m_rpc_version
Definition: node_rpc_proxy.h:70
boost::optional< std::string > get_earliest_height(uint8_t version, uint64_t &earliest_height) const
Definition: node_rpc_proxy.cpp:141
boost::optional< std::string > get_fee_quantization_mask(uint64_t &fee_quantization_mask) const
Definition: node_rpc_proxy.cpp:196
void set_height(uint64_t h)
Definition: node_rpc_proxy.cpp:84
boost::recursive_mutex & m_daemon_rpc_mutex
Definition: node_rpc_proxy.h:61
boost::optional< std::string > get_height(uint64_t &height) const
Definition: node_rpc_proxy.cpp:114
uint64_t m_dynamic_base_fee_estimate
Definition: node_rpc_proxy.h:66
uint64_t m_fee_quantization_mask
Definition: node_rpc_proxy.h:69
bool m_offline
Definition: node_rpc_proxy.h:62
uint64_t m_block_weight_limit
Definition: node_rpc_proxy.h:72
boost::optional< std::string > get_dynamic_base_fee_estimate(uint64_t grace_blocks, uint64_t &fee) const
Definition: node_rpc_proxy.cpp:164
void invalidate()
Definition: node_rpc_proxy.cpp:49
epee::net_utils::http::http_simple_client & m_http_client
Definition: node_rpc_proxy.h:60
boost::optional< std::string > get_block_weight_limit(uint64_t &block_weight_limit) const
Definition: node_rpc_proxy.cpp:132
boost::optional< std::string > get_info() const
Definition: node_rpc_proxy.cpp:89
uint64_t m_earliest_height[256]
Definition: node_rpc_proxy.h:65
time_t m_get_info_time
Definition: node_rpc_proxy.h:73
void set_offline(bool offline)
Definition: node_rpc_proxy.h:46
uint64_t m_dynamic_base_fee_estimate_grace_blocks
Definition: node_rpc_proxy.h:68
NodeRPCProxy(epee::net_utils::http::http_simple_client &http_client, boost::recursive_mutex &mutex)
Definition: node_rpc_proxy.cpp:41
uint64_t m_height
Definition: node_rpc_proxy.h:64
Various Tools.
Definition: apply_permutation.h:40