Electroneum
Loading...
Searching...
No Matches
cryptonote::rpc::RpcHandler Class Referenceabstract

#include <rpc_handler.h>

Inheritance diagram for cryptonote::rpc::RpcHandler:

Public Member Functions

 RpcHandler ()
virtual ~RpcHandler ()
virtual std::string handle (const std::string &request)=0

Static Public Member Functions

static boost::optional< output_distribution_dataget_output_distribution (const std::function< bool(uint64_t, uint64_t, uint64_t, uint64_t &, std::vector< uint64_t > &, uint64_t &)> &f, uint64_t amount, uint64_t from_height, uint64_t to_height, const std::function< crypto::hash(uint64_t)> &get_hash, bool cumulative, uint64_t blockchain_height)

Detailed Description

Definition at line 51 of file rpc_handler.h.

Constructor & Destructor Documentation

◆ RpcHandler()

cryptonote::rpc::RpcHandler::RpcHandler ( )
inline

Definition at line 54 of file rpc_handler.h.

54{ }

◆ ~RpcHandler()

virtual cryptonote::rpc::RpcHandler::~RpcHandler ( )
inlinevirtual

Definition at line 55 of file rpc_handler.h.

55{ }

Member Function Documentation

◆ get_output_distribution()

boost::optional< output_distribution_data > cryptonote::rpc::RpcHandler::get_output_distribution ( const std::function< bool(uint64_t, uint64_t, uint64_t, uint64_t &, std::vector< uint64_t > &, uint64_t &)> & f,
uint64_t amount,
uint64_t from_height,
uint64_t to_height,
const std::function< crypto::hash(uint64_t)> & get_hash,
bool cumulative,
uint64_t blockchain_height )
static

Definition at line 29 of file rpc_handler.cpp.

30 {
31 static struct D
32 {
33 boost::mutex mutex;
34 std::vector<std::uint64_t> cached_distribution;
35 std::uint64_t cached_from, cached_to, cached_start_height, cached_base;
36 crypto::hash cached_m10_hash;
37 crypto::hash cached_top_hash;
38 bool cached;
39 D(): cached_from(0), cached_to(0), cached_start_height(0), cached_base(0), cached_m10_hash(crypto::null_hash), cached_top_hash(crypto::null_hash), cached(false) {}
40 } d;
41 const boost::unique_lock<boost::mutex> lock(d.mutex);
42
43 crypto::hash top_hash = crypto::null_hash;
44 if (d.cached_to < blockchain_height)
45 top_hash = get_hash(d.cached_to);
46 if (d.cached && amount == 0 && d.cached_from == from_height && d.cached_to == to_height && d.cached_top_hash == top_hash)
47 return process_distribution(cumulative, d.cached_start_height, d.cached_distribution, d.cached_base);
48
49 std::vector<std::uint64_t> distribution;
50 std::uint64_t start_height, base;
51
52 // see if we can extend the cache - a common case
53 bool can_extend = d.cached && amount == 0 && d.cached_from == from_height && to_height > d.cached_to && top_hash == d.cached_top_hash;
54 if (!can_extend)
55 {
56 // we kept track of the hash 10 blocks below, if it exists, so if it matches,
57 // we can still pop the last 10 cached slots and try again
58 if (d.cached && amount == 0 && d.cached_from == from_height && d.cached_to - d.cached_from >= 10 && to_height > d.cached_to - 10)
59 {
60 crypto::hash hash10 = get_hash(d.cached_to - 10);
61 if (hash10 == d.cached_m10_hash)
62 {
63 d.cached_to -= 10;
64 d.cached_top_hash = hash10;
65 d.cached_m10_hash = crypto::null_hash;
66 d.cached_distribution.resize(d.cached_distribution.size() - 10);
67 can_extend = true;
68 }
69 }
70 }
71 if (can_extend)
72 {
73 std::vector<std::uint64_t> new_distribution;
74 if (!f(amount, d.cached_to + 1, to_height, start_height, new_distribution, base))
75 return boost::none;
76 distribution = d.cached_distribution;
77 distribution.reserve(distribution.size() + new_distribution.size());
78 for (const auto &e: new_distribution)
79 distribution.push_back(e);
80 start_height = d.cached_start_height;
81 base = d.cached_base;
82 }
83 else
84 {
85 if (!f(amount, from_height, to_height, start_height, distribution, base))
86 return boost::none;
87 }
88
89 if (to_height > 0 && to_height >= from_height)
90 {
91 const std::uint64_t offset = std::max(from_height, start_height);
92 if (offset <= to_height && to_height - offset + 1 < distribution.size())
93 distribution.resize(to_height - offset + 1);
94 }
95
96 if (amount == 0)
97 {
98 d.cached_from = from_height;
99 d.cached_to = to_height;
100 d.cached_top_hash = get_hash(d.cached_to);
101 d.cached_m10_hash = d.cached_to >= 10 ? get_hash(d.cached_to - 10) : crypto::null_hash;
102 d.cached_distribution = distribution;
103 d.cached_start_height = start_height;
104 d.cached_base = base;
105 d.cached = true;
106 }
107
108 return process_distribution(cumulative, start_height, std::move(distribution), base);
109 }
POD_CLASS hash
Definition hash.h:50
#define false
Here is the caller graph for this function:

◆ handle()

virtual std::string cryptonote::rpc::RpcHandler::handle ( const std::string & request)
pure virtual

The documentation for this class was generated from the following files:
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/rpc/rpc_handler.h
  • /home/abuild/rpmbuild/BUILD/electroneum-5.1.3.1-build/electroneum-5.1.3.1/src/rpc/rpc_handler.cpp