Electroneum
core_rpc_server.cpp
Go to the documentation of this file.
1 // Copyrights(c) 2017-2021, The Electroneum Project
2 // Copyrights(c) 2014-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 // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
31 
32 #include <boost/preprocessor/stringize.hpp>
33 #include "include_base_utils.h"
34 #include "string_tools.h"
35 using namespace epee;
36 
37 #include "core_rpc_server.h"
38 #include "common/command_line.h"
39 #include "common/updates.h"
40 #include "common/download.h"
41 #include "common/util.h"
42 #include "common/perf_timer.h"
47 #include "misc_language.h"
48 #include "net/parse.h"
50 #include "crypto/hash.h"
51 #include "rpc/rpc_args.h"
52 #include "rpc/rpc_handler.h"
54 #include "p2p/net_node.h"
55 #include "version.h"
56 
57 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
58 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "daemon.rpc"
59 
60 #define MAX_RESTRICTED_FAKE_OUTS_COUNT 40
61 #define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT 5000
62 
63 #define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION (3 * 86400) // 3 days max, the wallet requests 1.8 days
64 
65 namespace
66 {
67  void add_reason(std::string &reasons, const char *reason)
68  {
69  if (!reasons.empty())
70  reasons += ", ";
71  reasons += reason;
72  }
73 
74  uint64_t round_up(uint64_t value, uint64_t quantum)
75  {
76  return (value + quantum - 1) / quantum * quantum;
77  }
78 
79  void store_difficulty(cryptonote::difficulty_type difficulty, uint64_t &sdiff, std::string &swdiff, uint64_t &stop64)
80  {
81  sdiff = (difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
82  swdiff = cryptonote::hex(difficulty);
83  stop64 = ((difficulty >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
84  }
85 }
86 
87 #define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION (3 * 86400) // 3 days max, the wallet requests 1.8 days
88 
89 namespace cryptonote
90 {
91 
92  //-----------------------------------------------------------------------------------
93  void core_rpc_server::init_options(boost::program_options::options_description& desc)
94  {
95  command_line::add_arg(desc, arg_rpc_bind_port);
96  command_line::add_arg(desc, arg_rpc_restricted_bind_port);
97  command_line::add_arg(desc, arg_restricted_rpc);
98  command_line::add_arg(desc, arg_bootstrap_daemon_address);
99  command_line::add_arg(desc, arg_bootstrap_daemon_login);
101  }
102  //------------------------------------------------------------------------------------------------------------------------------
103  core_rpc_server::core_rpc_server(
104  core& cr
106  )
107  : m_core(cr)
108  , m_p2p(p2p)
109  {}
110  //------------------------------------------------------------------------------------------------------------------------------
112  const boost::program_options::variables_map& vm
113  , const bool restricted
114  , const std::string& port
115  )
116  {
117  m_restricted = restricted;
118  m_net_server.set_threads_prefix("RPC");
119 
120  auto rpc_config = cryptonote::rpc_args::process(vm, true);
121  if (!rpc_config)
122  return false;
123 
124  m_bootstrap_daemon_address = command_line::get_arg(vm, arg_bootstrap_daemon_address);
125  if (!m_bootstrap_daemon_address.empty())
126  {
127  const std::string &bootstrap_daemon_login = command_line::get_arg(vm, arg_bootstrap_daemon_login);
128  const auto loc = bootstrap_daemon_login.find(':');
129  if (!bootstrap_daemon_login.empty() && loc != std::string::npos)
130  {
132  login.username = bootstrap_daemon_login.substr(0, loc);
133  login.password = bootstrap_daemon_login.substr(loc + 1);
134  m_http_client.set_server(m_bootstrap_daemon_address, login, epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
135  }
136  else
137  {
138  m_http_client.set_server(m_bootstrap_daemon_address, boost::none, epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
139  }
140  m_should_use_bootstrap_daemon = true;
141  }
142  else
143  {
144  m_should_use_bootstrap_daemon = false;
145  }
146  m_was_bootstrap_ever_used = false;
147 
148  boost::optional<epee::net_utils::http::login> http_login{};
149 
150  if (rpc_config->login)
151  http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password());
152 
153  auto rng = [](size_t len, uint8_t *ptr){ return crypto::rand(len, ptr); };
155  rng, std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login), std::move(rpc_config->ssl_options)
156  );
157  }
158  //------------------------------------------------------------------------------------------------------------------------------
159  bool core_rpc_server::check_core_ready()
160  {
161  if(!m_p2p.get_payload_object().is_synchronized())
162  {
163  return false;
164  }
165  return true;
166  }
167 #define CHECK_CORE_READY() do { if(!check_core_ready()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0)
168 
169  //------------------------------------------------------------------------------------------------------------------------------
171  {
173  bool r;
174  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_HEIGHT>(invoke_http_mode::JON, "/getheight", req, res, r))
175  return r;
176 
178  m_core.get_blockchain_top(res.height, hash);
179  ++res.height; // block height to chain height
181  res.status = CORE_RPC_STATUS_OK;
182  return true;
183  }
184  //------------------------------------------------------------------------------------------------------------------------------
186  {
188  bool r;
189  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_INFO>(invoke_http_mode::JON, "/getinfo", req, res, r))
190  {
191  res.bootstrap_daemon_address = m_bootstrap_daemon_address;
192  crypto::hash top_hash;
193  m_core.get_blockchain_top(res.height_without_bootstrap, top_hash);
194  ++res.height_without_bootstrap; // turn top block height into blockchain height
195  res.was_bootstrap_ever_used = true;
196  return r;
197  }
198 
199  const bool restricted = m_restricted && ctx;
200 
201  crypto::hash top_hash;
202  m_core.get_blockchain_top(res.height, top_hash);
203  ++res.height; // turn top block height into blockchain height
204  res.top_block_hash = string_tools::pod_to_hex(top_hash);
205  res.target_height = m_core.get_target_blockchain_height();
206  store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64);
208  res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase
209  res.tx_pool_size = m_core.get_pool_transactions_count();
210  res.alt_blocks_count = restricted ? 0 : m_core.get_blockchain_storage().get_alternative_blocks_count();
211  uint64_t total_conn = restricted ? 0 : m_p2p.get_public_connections_count();
212  res.outgoing_connections_count = restricted ? 0 : m_p2p.get_public_outgoing_connections_count();
213  res.incoming_connections_count = restricted ? 0 : (total_conn - res.outgoing_connections_count);
214  res.rpc_connections_count = restricted ? 0 : get_connections_count();
215  res.white_peerlist_size = restricted ? 0 : m_p2p.get_public_white_peers_count();
216  res.grey_peerlist_size = restricted ? 0 : m_p2p.get_public_gray_peers_count();
217 
218  cryptonote::network_type net_type = nettype();
219  res.mainnet = net_type == MAINNET;
220  res.testnet = net_type == TESTNET;
221  res.stagenet = net_type == STAGENET;
222  res.nettype = net_type == MAINNET ? "mainnet" : net_type == TESTNET ? "testnet" : net_type == STAGENET ? "stagenet" : "fakechain";
223  store_difficulty(m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1),
224  res.cumulative_difficulty, res.wide_cumulative_difficulty, res.cumulative_difficulty_top64);
225  res.block_size_limit = res.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
226  res.block_size_median = res.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
227  res.start_time = restricted ? 0 : (uint64_t)m_core.get_start_time();
228  res.free_space = restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
229  res.offline = m_core.offline();
230  res.bootstrap_daemon_address = restricted ? "" : m_bootstrap_daemon_address;
231  res.height_without_bootstrap = restricted ? 0 : res.height;
232  if (restricted)
233  res.was_bootstrap_ever_used = false;
234  else
235  {
236  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
237  res.was_bootstrap_ever_used = m_was_bootstrap_ever_used;
238  }
239  res.database_size = m_core.get_blockchain_storage().get_db().get_database_size();
240  if (restricted)
241  res.database_size = round_up(res.database_size, 5ull* 1024 * 1024 * 1024);
242  res.update_available = restricted ? false : m_core.is_update_available();
243  res.version = restricted ? "" : ELECTRONEUM_VERSION;
244 
245  res.status = CORE_RPC_STATUS_OK;
246 
247  res.daemon_release_name = ELECTRONEUM_RELEASE_NAME;
248  res.daemon_version = ELECTRONEUM_VERSION;
249  res.daemon_version_full = ELECTRONEUM_VERSION_FULL;
250  res.daemon_version_tag = ELECTRONEUM_VERSION_TAG;
251  return true;
252  }
253  //------------------------------------------------------------------------------------------------------------------------------
255  {
257  // No bootstrap daemon check: Only ever get stats about local server
258  res.start_time = (uint64_t)m_core.get_start_time();
259  {
262  }
263  {
266  }
267  res.status = CORE_RPC_STATUS_OK;
268  return true;
269  }
270  //------------------------------------------------------------------------------------------------------------------------------
272  transaction& tx;
273  public:
276  bool r = tx.serialize_base(ar);
277  if (!r) return false;
278  END_SERIALIZE()
279  };
280  //------------------------------------------------------------------------------------------------------------------------------
282  {
283  PERF_TIMER(on_get_blocks);
284  bool r;
285  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCKS_FAST>(invoke_http_mode::BIN, "/getblocks.bin", req, res, r))
286  return r;
287 
288  //Vector of pairs where each pair is: item#1) pair<block blob, hash> item#2)vector of pairs of <tx hash, tx blob>
289  std::vector<
290  std::pair<
291  std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> >
292  >
293  > bs;
294 
295  if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, req.prune, !req.no_miner_tx, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
296  {
297  res.status = "Failed";
298  return false;
299  }
300 
301  size_t pruned_size = 0, unpruned_size = 0, ntxes = 0;
302 
303  // Preallocate space in the RPC result
304  res.blocks.reserve(bs.size());
305  res.output_indices.reserve(bs.size());
306 
307  // Loop over all of the block data and populate the rpc response
308  uint64_t height_counter = res.start_height;
309  for(auto& bd: bs)
310  {
311  res.blocks.resize(res.blocks.size()+1);
312  res.blocks.back().block = bd.first.first; // add block hash to response
313  pruned_size += bd.first.first.size();
314  unpruned_size += bd.first.first.size();
315  res.output_indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices());
316  ntxes += bd.second.size();
317  res.output_indices.back().indices.reserve(1 + bd.second.size());
318  if (req.no_miner_tx)
319  res.output_indices.back().indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::tx_output_indices());
320  res.blocks.back().txs.reserve(bd.second.size());
321 
322  //go over the transactions in bs first
323  for (std::vector<std::pair<crypto::hash, cryptonote::blobdata>>::iterator i = bd.second.begin(); i != bd.second.end(); ++i)
324  {
325  unpruned_size += i->second.size();
326  res.blocks.back().txs.push_back(std::move(i->second)); //add a tx blob to rpc response
327  i->second.clear();
328  i->second.shrink_to_fit();
329  pruned_size += res.blocks.back().txs.back().size();
330  }
331 
332  //no need to look up indexes for v2+ txes
333  auto v10_height = nettype() == cryptonote::network_type::MAINNET ? 1175315 : 1165235;
334  const size_t n_txes_to_lookup = height_counter >= v10_height ? 0 : (bd.second.size() + (req.no_miner_tx ? 0 : 1));
335  if (n_txes_to_lookup > 0)
336  {
337  std::vector<std::vector<uint64_t>> indices;
338  //either pass the first tx hash or the block hash depending on whether it was a miner tx or not
339  bool r = m_core.get_tx_outputs_gindexs(req.no_miner_tx ? bd.second.front().first : bd.first.second, n_txes_to_lookup, indices);
340  if (!r)
341  {
342  res.status = "Failed";
343  return false;
344  }
345  if (indices.size() != n_txes_to_lookup || res.output_indices.back().indices.size() != (req.no_miner_tx ? 1 : 0))
346  {
347  res.status = "Failed";
348  return false;
349  }
350  for (size_t i = 0; i < indices.size(); ++i)
351  res.output_indices.back().indices.push_back({std::move(indices[i])});
352  }
353  ++height_counter;
354  }
355 
356  MDEBUG("on_get_blocks: " << bs.size() << " blocks, " << ntxes << " txes, pruned size " << pruned_size << ", unpruned size " << unpruned_size);
357  res.status = CORE_RPC_STATUS_OK;
358  return true;
359  }
361  {
362  PERF_TIMER(on_get_alt_blocks_hashes);
363  bool r;
364  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_ALT_BLOCKS_HASHES>(invoke_http_mode::JON, "/get_alt_blocks_hashes", req, res, r))
365  return r;
366 
367  std::vector<block> blks;
368 
369  if(!m_core.get_alternative_blocks(blks))
370  {
371  res.status = "Failed";
372  return false;
373  }
374 
375  res.blks_hashes.reserve(blks.size());
376 
377  for (auto const& blk: blks)
378  {
379  res.blks_hashes.push_back(epee::string_tools::pod_to_hex(get_block_hash(blk)));
380  }
381 
382  MDEBUG("on_get_alt_blocks_hashes: " << blks.size() << " blocks " );
383  res.status = CORE_RPC_STATUS_OK;
384  return true;
385  }
386  //------------------------------------------------------------------------------------------------------------------------------
388  {
389  PERF_TIMER(on_get_blocks_by_height);
390  bool r;
391  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCKS_BY_HEIGHT>(invoke_http_mode::BIN, "/getblocks_by_height.bin", req, res, r))
392  return r;
393 
394  res.status = "Failed";
395  res.blocks.clear();
396  res.blocks.reserve(req.heights.size());
397  for (uint64_t height : req.heights)
398  {
399  block blk;
400  try
401  {
402  blk = m_core.get_blockchain_storage().get_db().get_block_from_height(height);
403  }
404  catch (...)
405  {
406  res.status = "Error retrieving block at height " + std::to_string(height);
407  return true;
408  }
409  std::vector<transaction> txs;
410  std::vector<crypto::hash> missed_txs;
411  m_core.get_transactions(blk.tx_hashes, txs, missed_txs);
412  res.blocks.resize(res.blocks.size() + 1);
413  res.blocks.back().block = block_to_blob(blk);
414  for (auto& tx : txs)
415  res.blocks.back().txs.push_back(tx_to_blob(tx));
416  }
417  res.status = CORE_RPC_STATUS_OK;
418  return true;
419  }
420  //------------------------------------------------------------------------------------------------------------------------------
422  {
423  PERF_TIMER(on_get_hashes);
424  bool r;
425  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_HASHES_FAST>(invoke_http_mode::BIN, "/gethashes.bin", req, res, r))
426  return r;
427 
428  res.start_height = req.start_height;
429  if(!m_core.get_blockchain_storage().find_blockchain_supplement(req.block_ids, res.m_block_ids, res.start_height, res.current_height, false))
430  {
431  res.status = "Failed";
432  return false;
433  }
434 
435  res.status = CORE_RPC_STATUS_OK;
436  return true;
437  }
438  //------------------------------------------------------------------------------------------------------------------------------
440  {
441  PERF_TIMER(on_get_outs_bin);
442  bool r;
443  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUTS_BIN>(invoke_http_mode::BIN, "/get_outs.bin", req, res, r))
444  return r;
445 
446  res.status = "Failed";
447 
448  const bool restricted = m_restricted && ctx;
449  if (restricted)
450  {
451  if (req.outputs.size() > MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT)
452  {
453  res.status = "Too many outs requested";
454  return true;
455  }
456  }
457 
458  if(!m_core.get_outs(req, res))
459  {
460  return true;
461  }
462 
463  res.status = CORE_RPC_STATUS_OK;
464  return true;
465  }
466  //------------------------------------------------------------------------------------------------------------------------------
468  {
469  PERF_TIMER(on_get_outs);
470  bool r;
471  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUTS>(invoke_http_mode::JON, "/get_outs", req, res, r))
472  return r;
473 
474  res.status = "Failed";
475 
476  const bool restricted = m_restricted && ctx;
477  if (restricted)
478  {
479  if (req.outputs.size() > MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT)
480  {
481  res.status = "Too many outs requested";
482  return true;
483  }
484  }
485 
487  req_bin.outputs = req.outputs;
488  req_bin.get_txid = req.get_txid;
490  if(!m_core.get_outs(req_bin, res_bin))
491  {
492  return true;
493  }
494 
495  // convert to text
496  for (const auto &i: res_bin.outs)
497  {
501  outkey.mask = epee::string_tools::pod_to_hex(i.mask);
502  outkey.unlocked = i.unlocked;
503  outkey.height = i.height;
504  outkey.txid = epee::string_tools::pod_to_hex(i.txid);
505  }
506 
507  res.status = CORE_RPC_STATUS_OK;
508  return true;
509  }
510  //------------------------------------------------------------------------------------------------------------------------------
512  {
513  PERF_TIMER(on_get_indexes);
514  bool ok;
515  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES>(invoke_http_mode::BIN, "/get_o_indexes.bin", req, res, ok))
516  return ok;
517 
518  bool r = m_core.get_tx_outputs_gindexs(req.txid, res.o_indexes);
519  if(!r)
520  {
521  res.status = "Failed";
522  return true;
523  }
524  res.status = CORE_RPC_STATUS_OK;
525  LOG_PRINT_L2("COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES: [" << res.o_indexes.size() << "]");
526  return true;
527  }
528  //------------------------------------------------------------------------------------------------------------------------------
530  {
531  PERF_TIMER(on_get_transactions);
532  bool ok;
533  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTIONS>(invoke_http_mode::JON, "/gettransactions", req, res, ok))
534  return ok;
535 
536  std::vector<crypto::hash> vh;
537  for(const auto& tx_hex_str: req.txs_hashes)
538  {
539  blobdata b;
540  if(!string_tools::parse_hexstr_to_binbuff(tx_hex_str, b))
541  {
542  res.status = "Failed to parse hex representation of transaction hash";
543  return true;
544  }
545  if(b.size() != sizeof(crypto::hash))
546  {
547  res.status = "Failed, size of data mismatch";
548  return true;
549  }
550  vh.push_back(*reinterpret_cast<const crypto::hash*>(b.data()));
551  }
552  std::vector<crypto::hash> missed_txs;
553  std::vector<std::tuple<crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata>> txs;
554  bool r = m_core.get_split_transactions_blobs(vh, txs, missed_txs);
555  if(!r)
556  {
557  res.status = "Failed";
558  return true;
559  }
560  LOG_PRINT_L2("Found " << txs.size() << "/" << vh.size() << " transactions on the blockchain");
561 
562  // try the pool for any missing txes
563  size_t found_in_pool = 0;
564  std::unordered_set<crypto::hash> pool_tx_hashes;
565  std::unordered_map<crypto::hash, tx_info> per_tx_pool_tx_info;
566  if (!missed_txs.empty())
567  {
568  std::vector<tx_info> pool_tx_info;
569  std::vector<spent_key_image_info> pool_key_image_info;
570  bool r = m_core.get_pool_transactions_and_spent_keys_info(pool_tx_info, pool_key_image_info);
571  if(r)
572  {
573  // sort to match original request
574  std::vector<std::tuple<crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata>> sorted_txs;
575  std::vector<tx_info>::const_iterator i;
576  unsigned txs_processed = 0;
577  for (const crypto::hash &h: vh)
578  {
579  if (std::find(missed_txs.begin(), missed_txs.end(), h) == missed_txs.end())
580  {
581  if (txs.size() == txs_processed)
582  {
583  res.status = "Failed: internal error - txs is empty";
584  return true;
585  }
586  // core returns the ones it finds in the right order
587  if (std::get<0>(txs[txs_processed]) != h)
588  {
589  res.status = "Failed: tx hash mismatch";
590  return true;
591  }
592  sorted_txs.push_back(std::move(txs[txs_processed]));
593  ++txs_processed;
594  }
595  else if ((i = std::find_if(pool_tx_info.begin(), pool_tx_info.end(), [h](const tx_info &txi) { return epee::string_tools::pod_to_hex(h) == txi.id_hash; })) != pool_tx_info.end())
596  {
598  if (!cryptonote::parse_and_validate_tx_from_blob(i->tx_blob, tx))
599  {
600  res.status = "Failed to parse and validate tx from blob";
601  return true;
602  }
603  std::stringstream ss;
604  binary_archive<true> ba(ss);
605  bool r = const_cast<cryptonote::transaction&>(tx).serialize_base(ba);
606  if (!r)
607  {
608  res.status = "Failed to serialize transaction base";
609  return true;
610  }
611  //TODO: Public
612  const cryptonote::blobdata pruned = ss.str();
613  sorted_txs.push_back(std::make_tuple(h, pruned, crypto::null_hash, std::string(i->tx_blob, pruned.size())));
614  missed_txs.erase(std::find(missed_txs.begin(), missed_txs.end(), h));
615  pool_tx_hashes.insert(h);
616  const std::string hash_string = epee::string_tools::pod_to_hex(h);
617  for (const auto &ti: pool_tx_info)
618  {
619  if (ti.id_hash == hash_string)
620  {
621  per_tx_pool_tx_info.insert(std::make_pair(h, ti));
622  break;
623  }
624  }
625  ++found_in_pool;
626  }
627  }
628  txs = sorted_txs;
629  }
630  LOG_PRINT_L2("Found " << found_in_pool << "/" << vh.size() << " transactions in the pool");
631  }
632 
633  std::vector<std::string>::const_iterator txhi = req.txs_hashes.begin();
634  std::vector<crypto::hash>::const_iterator vhi = vh.begin();
635  for(auto& tx: txs)
636  {
637  res.txs.push_back(COMMAND_RPC_GET_TRANSACTIONS::entry());
639 
640  crypto::hash tx_hash = *vhi++;
641  e.tx_hash = *txhi++;
642  e.prunable_hash = epee::string_tools::pod_to_hex(std::get<2>(tx));
643  if (req.split || req.prune || std::get<3>(tx).empty())
644  {
645  // use splitted form with pruned and prunable (filled only when prune=false and the daemon has it), leaving as_hex as empty
647  if (!req.prune)
649  if (req.decode_as_json)
650  {
651  cryptonote::blobdata tx_data;
653  if (req.prune || std::get<3>(tx).empty())
654  {
655  // decode pruned tx to JSON
656  tx_data = std::get<1>(tx);
658  {
659  pruned_transaction pruned_tx{t};
660  e.as_json = obj_to_json_str(pruned_tx);
661  }
662  else
663  {
664  res.status = "Failed to parse and validate pruned tx from blob";
665  return true;
666  }
667  }
668  else
669  {
670  // decode full tx to JSON
671  tx_data = std::get<1>(tx) + std::get<3>(tx);
673  {
674  e.as_json = obj_to_json_str(t);
675  }
676  else
677  {
678  res.status = "Failed to parse and validate tx from blob";
679  return true;
680  }
681  }
682  }
683  }
684  else
685  {
686  // use non-splitted form, leaving pruned_as_hex and prunable_as_hex as empty
687  cryptonote::blobdata tx_data = std::get<1>(tx) + std::get<3>(tx);
689  if (req.decode_as_json)
690  {
693  {
694  e.as_json = obj_to_json_str(t);
695  }
696  else
697  {
698  res.status = "Failed to parse and validate tx from blob";
699  return true;
700  }
701  }
702  }
703  e.in_pool = pool_tx_hashes.find(tx_hash) != pool_tx_hashes.end();
704  if (e.in_pool)
705  {
706  e.block_height = e.block_timestamp = std::numeric_limits<uint64_t>::max();
707  auto it = per_tx_pool_tx_info.find(tx_hash);
708  if (it != per_tx_pool_tx_info.end())
709  {
710  e.double_spend_seen = it->second.double_spend_seen;
711  e.nonexistent_utxo_seen = it->second.nonexistent_utxo_seen;
712  e.relayed = it->second.relayed;
713  }
714  else
715  {
716  MERROR("Failed to determine pool info for " << tx_hash);
717  e.double_spend_seen = false;
718  e.nonexistent_utxo_seen = false;
719  e.relayed = false;
720  }
721  }
722  else
723  {
724  e.block_height = m_core.get_blockchain_storage().get_db().get_tx_block_height(tx_hash);
725  e.block_timestamp = m_core.get_blockchain_storage().get_db().get_block_timestamp(e.block_height);
726  e.double_spend_seen = false;
727  e.relayed = false;
728  }
729 
730  // fill up old style responses too, in case an old wallet asks
731  res.txs_as_hex.push_back(e.as_hex);
732  if (req.decode_as_json)
733  res.txs_as_json.push_back(e.as_json);
734 
735  // output indices too if not in pool
736  if (pool_tx_hashes.find(tx_hash) == pool_tx_hashes.end())
737  {
738  bool r = m_core.get_tx_outputs_gindexs(tx_hash, e.output_indices);
739  if (!r)
740  {
741  res.status = "Failed";
742  return false;
743  }
744  }
745  }
746 
747  for(const auto& miss_tx: missed_txs)
748  {
749  res.missed_tx.push_back(string_tools::pod_to_hex(miss_tx));
750  }
751 
752  LOG_PRINT_L2(res.txs.size() << " transactions found, " << res.missed_tx.size() << " not found");
753  res.status = CORE_RPC_STATUS_OK;
754  return true;
755  }
756  //------------------------------------------------------------------------------------------------------------------------------
758  {
759  PERF_TIMER(on_is_key_image_spent);
760  bool ok;
761  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_IS_KEY_IMAGE_SPENT>(invoke_http_mode::JON, "/is_key_image_spent", req, res, ok))
762  return ok;
763 
764  const bool restricted = m_restricted && ctx;
765  const bool request_has_rpc_origin = ctx != NULL;
766  std::vector<crypto::key_image> key_images;
767  for(const auto& ki_hex_str: req.key_images)
768  {
769  blobdata b;
770  if(!string_tools::parse_hexstr_to_binbuff(ki_hex_str, b))
771  {
772  res.status = "Failed to parse hex representation of key image";
773  return true;
774  }
775  if(b.size() != sizeof(crypto::key_image))
776  {
777  res.status = "Failed, size of data mismatch";
778  }
779  key_images.push_back(*reinterpret_cast<const crypto::key_image*>(b.data()));
780  }
781  std::vector<bool> spent_status;
782  bool r = m_core.are_key_images_spent(key_images, spent_status);
783  if(!r)
784  {
785  res.status = "Failed";
786  return true;
787  }
788  res.spent_status.clear();
789  for (size_t n = 0; n < spent_status.size(); ++n)
791 
792  // check the pool too
793  std::vector<cryptonote::tx_info> txs;
794  std::vector<cryptonote::spent_key_image_info> ki;
795  r = m_core.get_pool_transactions_and_spent_keys_info(txs, ki, !request_has_rpc_origin || !restricted);
796  if(!r)
797  {
798  res.status = "Failed";
799  return true;
800  }
801  for (std::vector<cryptonote::spent_key_image_info>::const_iterator i = ki.begin(); i != ki.end(); ++i)
802  {
804  crypto::key_image spent_key_image;
805  if (parse_hash256(i->id_hash, hash))
806  {
807  memcpy(&spent_key_image, &hash, sizeof(hash)); // a bit dodgy, should be other parse functions somewhere
808  for (size_t n = 0; n < res.spent_status.size(); ++n)
809  {
810  if (res.spent_status[n] == COMMAND_RPC_IS_KEY_IMAGE_SPENT::UNSPENT)
811  {
812  if (key_images[n] == spent_key_image)
813  {
815  break;
816  }
817  }
818  }
819  }
820  }
821 
822  res.status = CORE_RPC_STATUS_OK;
823  return true;
824  }
825  //------------------------------------------------------------------------------------------------------------------------------
827  {
828  PERF_TIMER(on_send_raw_tx);
829  bool ok;
830  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_SEND_RAW_TX>(invoke_http_mode::JON, "/sendrawtransaction", req, res, ok))
831  return ok;
832 
834 
835  std::string tx_blob;
836  if(!string_tools::parse_hexstr_to_binbuff(req.tx_as_hex, tx_blob))
837  {
838  LOG_PRINT_L0("[on_send_raw_tx]: Failed to parse tx from hexbuff: " << req.tx_as_hex);
839  res.status = "Failed";
840  return true;
841  }
842 
843  if (req.do_sanity_checks && !cryptonote::tx_sanity_check(m_core.get_blockchain_storage(), tx_blob))
844  {
845  res.status = "Failed";
846  res.reason = "Sanity check failed";
847  res.sanity_check_failed = true;
848  return true;
849  }
850  res.sanity_check_failed = false;
851 
852  cryptonote_connection_context fake_context = AUTO_VAL_INIT(fake_context);
854  if(!m_core.handle_incoming_tx(tx_blob, tvc, false, false, req.do_not_relay) || tvc.m_verification_failed)
855  {
856  res.status = "Failed";
857  std::string reason = "";
858  if ((res.low_mixin = tvc.m_low_mixin))
859  add_reason(reason, "bad ring size");
860  if ((res.double_spend = tvc.m_double_spend))
861  add_reason(reason, "double spend");
862  if ((res.double_spend = tvc.m_utxo_nonexistent))
863  add_reason(reason, "utxo has been spent already or doesn't exist");
864  if ((res.invalid_input = tvc.m_invalid_input))
865  add_reason(reason, "invalid input");
866  if ((res.invalid_output = tvc.m_invalid_output))
867  add_reason(reason, "invalid output");
868  if ((res.too_big = tvc.m_too_big))
869  add_reason(reason, "too big");
870  if ((res.overspend = tvc.m_overspend))
871  add_reason(reason, "overspend");
872  if ((res.fee_too_low = tvc.m_fee_too_low))
873  add_reason(reason, "fee too low");
874  if ((res.not_rct = tvc.m_not_rct))
875  add_reason(reason, "tx is not ringct");
876  const std::string punctuation = reason.empty() ? "" : ": ";
877  if (tvc.m_verification_failed)
878  {
879  LOG_PRINT_L0("[on_send_raw_tx]: tx verification failed" << punctuation << reason);
880  }
881  else
882  {
883  LOG_PRINT_L0("[on_send_raw_tx]: Failed to process tx" << punctuation << reason);
884  }
885  return true;
886  }
887 
888  if(!tvc.m_should_be_relayed)
889  {
890  LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed");
891  res.reason = "Not relayed";
892  res.not_relayed = true;
893  res.status = CORE_RPC_STATUS_OK;
894  return true;
895  }
896 
898  r.txs.push_back(tx_blob);
899  m_core.get_protocol()->relay_transactions(r, fake_context);
900  //TODO: make sure that tx has reached other nodes here, probably wait to receive reflections from other nodes
901  res.status = CORE_RPC_STATUS_OK;
902  return true;
903  }
904  //------------------------------------------------------------------------------------------------------------------------------
906  {
907  PERF_TIMER(on_start_mining);
910  if(!get_account_address_from_str(info, nettype(), req.miner_address))
911  {
912  res.status = "Failed, wrong address";
913  LOG_PRINT_L0(res.status);
914  return true;
915  }
916  if (info.is_subaddress)
917  {
918  res.status = "Mining to subaddress isn't supported yet";
919  LOG_PRINT_L0(res.status);
920  return true;
921  }
922 
923  unsigned int concurrency_count = boost::thread::hardware_concurrency() * 4;
924 
925  // if we couldn't detect threads, set it to a ridiculously high number
926  if(concurrency_count == 0)
927  {
928  concurrency_count = 257;
929  }
930 
931  // if there are more threads requested than the hardware supports
932  // then we fail and log that.
933  if(req.threads_count > concurrency_count)
934  {
935  res.status = "Failed, too many threads relative to CPU cores.";
936  LOG_PRINT_L0(res.status);
937  return true;
938  }
939 
940  cryptonote::miner &miner= m_core.get_miner();
941  if (miner.is_mining())
942  {
943  res.status = "Already mining";
944  return true;
945  }
946  if(!miner.start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
947  {
948  res.status = "Failed, mining not started";
949  LOG_PRINT_L0(res.status);
950  return true;
951  }
952  res.status = CORE_RPC_STATUS_OK;
953  return true;
954  }
955  //------------------------------------------------------------------------------------------------------------------------------
957  {
958  PERF_TIMER(on_stop_mining);
959  cryptonote::miner &miner= m_core.get_miner();
960  if(!miner.is_mining())
961  {
962  res.status = "Mining never started";
963  LOG_PRINT_L0(res.status);
964  return true;
965  }
966  if(!miner.stop())
967  {
968  res.status = "Failed, mining not stopped";
969  LOG_PRINT_L0(res.status);
970  return true;
971  }
972  res.status = CORE_RPC_STATUS_OK;
973  return true;
974  }
975  //------------------------------------------------------------------------------------------------------------------------------
977  {
978  PERF_TIMER(on_mining_status);
979 
980  const miner& lMiner = m_core.get_miner();
981  res.active = lMiner.is_mining();
982  res.is_background_mining_enabled = lMiner.get_is_background_mining_enabled();
983  store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64);
984 
985  res.block_target = m_core.get_blockchain_storage().get_current_hard_fork_version() < 6 ? DIFFICULTY_TARGET : DIFFICULTY_TARGET_V6;
986  if ( lMiner.is_mining() ) {
987  res.speed = lMiner.get_speed();
988  res.threads_count = lMiner.get_threads_count();
989  res.block_reward = lMiner.get_block_reward();
990  }
991  const account_public_address& lMiningAdr = lMiner.get_mining_address();
992  res.address = get_account_address_as_str(nettype(), false, lMiningAdr);
993  const uint8_t major_version = m_core.get_blockchain_storage().get_current_hard_fork_version();
994  const unsigned variant = major_version >= 7 ? major_version - 6 : 0;
995  switch (variant)
996  {
997  case 0: res.pow_algorithm = "Cryptonight"; break;
998  case 1: res.pow_algorithm = "CNv1 (Cryptonight variant 1)"; break;
999  case 2: case 3: res.pow_algorithm = "CNv2 (Cryptonight variant 2)"; break;
1000  case 4: case 5: res.pow_algorithm = "CNv4 (Cryptonight variant 4)"; break;
1001  default: res.pow_algorithm = "I'm not sure actually"; break;
1002  }
1003  if (res.is_background_mining_enabled)
1004  {
1005  res.bg_idle_threshold = lMiner.get_idle_threshold();
1006  res.bg_min_idle_seconds = lMiner.get_min_idle_seconds();
1007  res.bg_ignore_battery = lMiner.get_ignore_battery();
1008  res.bg_target = lMiner.get_mining_target();
1009  }
1010 
1011  res.status = CORE_RPC_STATUS_OK;
1012  return true;
1013  }
1014  //------------------------------------------------------------------------------------------------------------------------------
1016  {
1017  PERF_TIMER(on_save_bc);
1018  if( !m_core.get_blockchain_storage().store_blockchain() )
1019  {
1020  res.status = "Error while storing blockchain";
1021  return true;
1022  }
1023  res.status = CORE_RPC_STATUS_OK;
1024  return true;
1025  }
1026  //------------------------------------------------------------------------------------------------------------------------------
1028  {
1029  PERF_TIMER(on_get_peer_list);
1030  std::vector<nodetool::peerlist_entry> white_list;
1031  std::vector<nodetool::peerlist_entry> gray_list;
1032  m_p2p.get_public_peerlist(gray_list, white_list);
1033 
1034  res.white_list.reserve(white_list.size());
1035  for (auto & entry : white_list)
1036  {
1037  if (entry.adr.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
1038  res.white_list.emplace_back(entry.id, entry.adr.as<epee::net_utils::ipv4_network_address>().ip(),
1039  entry.adr.as<epee::net_utils::ipv4_network_address>().port(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1040  else
1041  res.white_list.emplace_back(entry.id, entry.adr.str(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1042  }
1043 
1044  res.gray_list.reserve(gray_list.size());
1045  for (auto & entry : gray_list)
1046  {
1047  if (entry.adr.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
1048  res.gray_list.emplace_back(entry.id, entry.adr.as<epee::net_utils::ipv4_network_address>().ip(),
1049  entry.adr.as<epee::net_utils::ipv4_network_address>().port(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1050  else
1051  res.gray_list.emplace_back(entry.id, entry.adr.str(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1052  }
1053 
1054  res.status = CORE_RPC_STATUS_OK;
1055  return true;
1056  }
1057  //------------------------------------------------------------------------------------------------------------------------------
1059  {
1060  PERF_TIMER(on_set_log_hash_rate);
1061  if(m_core.get_miner().is_mining())
1062  {
1063  m_core.get_miner().do_print_hashrate(req.visible);
1064  res.status = CORE_RPC_STATUS_OK;
1065  }
1066  else
1067  {
1069  }
1070  return true;
1071  }
1072  //------------------------------------------------------------------------------------------------------------------------------
1074  {
1075  PERF_TIMER(on_set_log_level);
1076  if (req.level > 4)
1077  {
1078  res.status = "Error: log level not valid";
1079  return true;
1080  }
1081  mlog_set_log_level(req.level);
1082  res.status = CORE_RPC_STATUS_OK;
1083  return true;
1084  }
1085  //------------------------------------------------------------------------------------------------------------------------------
1087  {
1088  PERF_TIMER(on_set_log_categories);
1089  mlog_set_log(req.categories.c_str());
1090  res.categories = mlog_get_categories();
1091  res.status = CORE_RPC_STATUS_OK;
1092  return true;
1093  }
1094  //------------------------------------------------------------------------------------------------------------------------------
1096  {
1097  PERF_TIMER(on_get_transaction_pool);
1098  bool r;
1099  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL>(invoke_http_mode::JON, "/get_transaction_pool", req, res, r))
1100  return r;
1101 
1102  const bool restricted = m_restricted && ctx;
1103  const bool request_has_rpc_origin = ctx != NULL;
1104  m_core.get_pool_transactions_and_spent_keys_info(res.transactions, res.spent_key_images, !request_has_rpc_origin || !restricted);
1105  for (tx_info& txi : res.transactions)
1107  res.status = CORE_RPC_STATUS_OK;
1108  return true;
1109  }
1110  //------------------------------------------------------------------------------------------------------------------------------
1112  {
1113  PERF_TIMER(on_get_transaction_pool_hashes);
1114  bool r;
1115  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN>(invoke_http_mode::JON, "/get_transaction_pool_hashes.bin", req, res, r))
1116  return r;
1117 
1118  const bool restricted = m_restricted && ctx;
1119  const bool request_has_rpc_origin = ctx != NULL;
1120  m_core.get_pool_transaction_hashes(res.tx_hashes, !request_has_rpc_origin || !restricted);
1121  res.status = CORE_RPC_STATUS_OK;
1122  return true;
1123  }
1124  //------------------------------------------------------------------------------------------------------------------------------
1126  {
1127  PERF_TIMER(on_get_transaction_pool_hashes);
1128  bool r;
1129  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_HASHES>(invoke_http_mode::JON, "/get_transaction_pool_hashes", req, res, r))
1130  return r;
1131 
1132  const bool restricted = m_restricted && ctx;
1133  const bool request_has_rpc_origin = ctx != NULL;
1134  std::vector<crypto::hash> tx_hashes;
1135  m_core.get_pool_transaction_hashes(tx_hashes, !request_has_rpc_origin || !restricted);
1136  res.tx_hashes.reserve(tx_hashes.size());
1137  for (const crypto::hash &tx_hash: tx_hashes)
1138  res.tx_hashes.push_back(epee::string_tools::pod_to_hex(tx_hash));
1139  res.status = CORE_RPC_STATUS_OK;
1140  return true;
1141  }
1142  //------------------------------------------------------------------------------------------------------------------------------
1144  {
1145  PERF_TIMER(on_get_transaction_pool_stats);
1146  bool r;
1147  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_STATS>(invoke_http_mode::JON, "/get_transaction_pool_stats", req, res, r))
1148  return r;
1149 
1150  const bool restricted = m_restricted && ctx;
1151  const bool request_has_rpc_origin = ctx != NULL;
1152  m_core.get_pool_transaction_stats(res.pool_stats, !request_has_rpc_origin || !restricted);
1153  res.status = CORE_RPC_STATUS_OK;
1154  return true;
1155  }
1156  //------------------------------------------------------------------------------------------------------------------------------
1158  {
1159  PERF_TIMER(on_stop_daemon);
1160  // FIXME: replace back to original m_p2p.send_stop_signal() after
1161  // investigating why that isn't working quite right.
1162  m_p2p.send_stop_signal();
1163  res.status = CORE_RPC_STATUS_OK;
1164  return true;
1165  }
1166  //------------------------------------------------------------------------------------------------------------------------------
1168  {
1169  PERF_TIMER(on_getblockcount);
1170  {
1171  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1172  if (m_should_use_bootstrap_daemon)
1173  {
1174  res.status = "This command is unsupported for bootstrap daemon";
1175  return false;
1176  }
1177  }
1178  res.count = m_core.get_current_blockchain_height();
1179  res.status = CORE_RPC_STATUS_OK;
1180  return true;
1181  }
1182  //------------------------------------------------------------------------------------------------------------------------------
1184  {
1185  PERF_TIMER(on_getblockhash);
1186  {
1187  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1188  if (m_should_use_bootstrap_daemon)
1189  {
1190  res = "This command is unsupported for bootstrap daemon";
1191  return false;
1192  }
1193  }
1194  if(req.size() != 1)
1195  {
1197  error_resp.message = "Wrong parameters, expected height";
1198  return false;
1199  }
1200  uint64_t h = req[0];
1201  if(m_core.get_current_blockchain_height() <= h)
1202  {
1204  error_resp.message = std::string("Requested block height: ") + std::to_string(h) + " greater than current top block height: " + std::to_string(m_core.get_current_blockchain_height() - 1);
1205  }
1206  res = string_tools::pod_to_hex(m_core.get_block_id_by_height(h));
1207  return true;
1208  }
1209  //------------------------------------------------------------------------------------------------------------------------------
1210  // equivalent of strstr, but with arbitrary bytes (ie, NULs)
1211  // This does not differentiate between "not found" and "found at offset 0"
1212  size_t slow_memmem(const void* start_buff, size_t buflen,const void* pat,size_t patlen)
1213  {
1214  const void* buf = start_buff;
1215  const void* end=(const char*)buf+buflen;
1216  if (patlen > buflen || patlen == 0) return 0;
1217  while(buflen>0 && (buf=memchr(buf,((const char*)pat)[0],buflen-patlen+1)))
1218  {
1219  if(memcmp(buf,pat,patlen)==0)
1220  return (const char*)buf - (const char*)start_buff;
1221  buf=(const char*)buf+1;
1222  buflen = (const char*)end - (const char*)buf;
1223  }
1224  return 0;
1225  }
1226  //------------------------------------------------------------------------------------------------------------------------------
1228  {
1229  PERF_TIMER(on_getblocktemplate);
1230  bool r;
1231  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GETBLOCKTEMPLATE>(invoke_http_mode::JON_RPC, "getblocktemplate", req, res, r))
1232  return r;
1233 
1234  if(!check_core_ready())
1235  {
1236  error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
1237  error_resp.message = "Core is busy";
1238  return false;
1239  }
1240 
1241  if(req.reserve_size > 255)
1242  {
1244  error_resp.message = "Too big reserved size, maximum 255";
1245  return false;
1246  }
1247 
1249 
1250  if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(info, nettype(), req.wallet_address))
1251  {
1253  error_resp.message = "Failed to parse wallet address";
1254  return false;
1255  }
1256  if (info.is_subaddress)
1257  {
1259  error_resp.message = "Mining to subaddress is not supported yet";
1260  return false;
1261  }
1262 
1263  block b;
1264  cryptonote::blobdata blob_reserve;
1265  blob_reserve.resize(req.reserve_size, 0);
1267  crypto::hash prev_block;
1268  if (!req.prev_block.empty())
1269  {
1270  if (!epee::string_tools::hex_to_pod(req.prev_block, prev_block))
1271  {
1273  error_resp.message = "Invalid prev_block";
1274  return false;
1275  }
1276  }
1277  if(!m_core.get_block_template(b, req.prev_block.empty() ? NULL : &prev_block, info.address, wdiff, res.height, res.expected_reward, blob_reserve))
1278  {
1280  error_resp.message = "Internal error: failed to create block template";
1281  LOG_ERROR("Failed to create block template");
1282  return false;
1283  }
1284  store_difficulty(wdiff, res.difficulty, res.wide_difficulty, res.difficulty_top64);
1285  blobdata block_blob = t_serializable_object_to_blob(b);
1287  if(tx_pub_key == crypto::null_pkey)
1288  {
1290  error_resp.message = "Internal error: failed to create block template";
1291  LOG_ERROR("Failed to get tx pub key in coinbase extra");
1292  return false;
1293  }
1294  res.reserved_offset = slow_memmem((void*)block_blob.data(), block_blob.size(), &tx_pub_key, sizeof(tx_pub_key));
1295  if(!res.reserved_offset)
1296  {
1298  error_resp.message = "Internal error: failed to create block template";
1299  LOG_ERROR("Failed to find tx pub key in blockblob");
1300  return false;
1301  }
1302  if (req.reserve_size)
1303  res.reserved_offset += sizeof(tx_pub_key) + 2; //2 bytes: tag for TX_EXTRA_NONCE(1 byte), counter in TX_EXTRA_NONCE(1 byte)
1304  else
1305  res.reserved_offset = 0;
1306  if(res.reserved_offset + req.reserve_size > block_blob.size())
1307  {
1309  error_resp.message = "Internal error: failed to create block template";
1310  LOG_ERROR("Failed to calculate offset for ");
1311  return false;
1312  }
1313  blobdata hashing_blob = get_block_hashing_blob(b);
1314  res.prev_hash = string_tools::pod_to_hex(b.prev_id);
1315  res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob);
1316  res.blockhashing_blob = string_tools::buff_to_hex_nodelimer(hashing_blob);
1317  res.status = CORE_RPC_STATUS_OK;
1318  return true;
1319  }
1320  //------------------------------------------------------------------------------------------------------------------------------
1322  {
1323  PERF_TIMER(on_submitblock);
1324  {
1325  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1326  if (m_should_use_bootstrap_daemon)
1327  {
1328  res.status = "This command is unsupported for bootstrap daemon";
1329  return false;
1330  }
1331  }
1332  CHECK_CORE_READY();
1333  if(req.size()!=1)
1334  {
1336  error_resp.message = "Wrong param";
1337  return false;
1338  }
1339  blobdata blockblob;
1340  if(!string_tools::parse_hexstr_to_binbuff(req[0], blockblob))
1341  {
1343  error_resp.message = "Wrong block blob";
1344  return false;
1345  }
1346 
1347  // Fixing of high orphan issue for most pools
1348  // Thanks Boolberry!
1349  block b;
1350  if(!parse_and_validate_block_from_blob(blockblob, b))
1351  {
1353  error_resp.message = "Wrong block blob";
1354  return false;
1355  }
1356 
1357  // Fix from Boolberry neglects to check block
1358  // size, do that with the function below
1359  if(!m_core.check_incoming_block_size(blockblob))
1360  {
1362  error_resp.message = "Block bloc size is too big, rejecting block";
1363  return false;
1364  }
1365 
1367  if(!m_core.handle_block_found(b, bvc))
1368  {
1370  error_resp.message = "Block not accepted";
1371  return false;
1372  }
1373  res.status = CORE_RPC_STATUS_OK;
1374  return true;
1375  }
1376  //------------------------------------------------------------------------------------------------------------------------------
1378  {
1379  PERF_TIMER(on_generateblocks);
1380 
1381  CHECK_CORE_READY();
1382 
1383  res.status = CORE_RPC_STATUS_OK;
1384 
1385  if(m_core.get_nettype() != FAKECHAIN)
1386  {
1388  error_resp.message = "Regtest required when generating blocks";
1389  return false;
1390  }
1391 
1396 
1397  template_req.reserve_size = 1;
1398  template_req.wallet_address = req.wallet_address;
1399  template_req.prev_block = req.prev_block;
1400  submit_req.push_back(boost::value_initialized<std::string>());
1401  res.height = m_core.get_blockchain_storage().get_current_blockchain_height();
1402 
1403  for(size_t i = 0; i < req.amount_of_blocks; i++)
1404  {
1405  bool r = on_getblocktemplate(template_req, template_res, error_resp, ctx);
1406  res.status = template_res.status;
1407  template_req.prev_block.clear();
1408 
1409  if (!r) return false;
1410 
1411  blobdata blockblob;
1412  if(!string_tools::parse_hexstr_to_binbuff(template_res.blocktemplate_blob, blockblob))
1413  {
1415  error_resp.message = "Wrong block blob";
1416  return false;
1417  }
1418  block b;
1419  if(!parse_and_validate_block_from_blob(blockblob, b))
1420  {
1422  error_resp.message = "Wrong block blob";
1423  return false;
1424  }
1425  b.nonce = req.starting_nonce;
1426  miner::find_nonce_for_given_block(b, template_res.difficulty, template_res.height);
1427 
1428  submit_req.front() = string_tools::buff_to_hex_nodelimer(block_to_blob(b));
1429  r = on_submitblock(submit_req, submit_res, error_resp, ctx);
1430  res.status = submit_res.status;
1431 
1432  if (!r) return false;
1433 
1434  res.blocks.push_back(epee::string_tools::pod_to_hex(get_block_hash(b)));
1435  template_req.prev_block = res.blocks.back();
1436  res.height = template_res.height;
1437  }
1438 
1439  return true;
1440  }
1441  //------------------------------------------------------------------------------------------------------------------------------
1442  uint64_t core_rpc_server::get_block_reward(const block& blk)
1443  {
1444  uint64_t reward = 0;
1445  for(const tx_out& out: blk.miner_tx.vout)
1446  {
1447  reward += out.amount;
1448  }
1449  return reward;
1450  }
1451  //------------------------------------------------------------------------------------------------------------------------------
1452  bool core_rpc_server::fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response, bool fill_pow_hash)
1453  {
1454  PERF_TIMER(fill_block_header_response);
1455  response.major_version = blk.major_version;
1456  response.minor_version = blk.minor_version;
1457  response.timestamp = blk.timestamp;
1458  response.prev_hash = string_tools::pod_to_hex(blk.prev_id);
1459  response.nonce = blk.nonce;
1460  response.orphan_status = orphan_status;
1461  response.height = height;
1462  response.depth = m_core.get_current_blockchain_height() - height - 1;
1464  store_difficulty(m_core.get_blockchain_storage().block_difficulty(height),
1465  response.difficulty, response.wide_difficulty, response.difficulty_top64);
1466  store_difficulty(m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(height),
1467  response.cumulative_difficulty, response.wide_cumulative_difficulty, response.cumulative_difficulty_top64);
1468  response.reward = get_block_reward(blk);
1469  response.block_size = response.block_weight = m_core.get_blockchain_storage().get_db().get_block_weight(height);
1470  response.num_txes = blk.tx_hashes.size();
1471  response.pow_hash = fill_pow_hash ? string_tools::pod_to_hex(get_block_longhash(blk, height)) : "";
1472  response.long_term_weight = m_core.get_blockchain_storage().get_db().get_block_long_term_weight(height);
1474  return true;
1475  }
1476  //------------------------------------------------------------------------------------------------------------------------------
1477  template <typename COMMAND_TYPE>
1478  bool core_rpc_server::use_bootstrap_daemon_if_necessary(const invoke_http_mode &mode, const std::string &command_name, const typename COMMAND_TYPE::request& req, typename COMMAND_TYPE::response& res, bool &r)
1479  {
1480  res.untrusted = false;
1481  if (m_bootstrap_daemon_address.empty())
1482  return false;
1483 
1484  boost::unique_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1485  if (!m_should_use_bootstrap_daemon)
1486  {
1487  MINFO("The local daemon is fully synced. Not switching back to the bootstrap daemon");
1488  return false;
1489  }
1490 
1491  auto current_time = std::chrono::system_clock::now();
1492  if (current_time - m_bootstrap_height_check_time > std::chrono::seconds(30)) // update every 30s
1493  {
1494  m_bootstrap_height_check_time = current_time;
1495 
1496  uint64_t top_height;
1497  crypto::hash top_hash;
1498  m_core.get_blockchain_top(top_height, top_hash);
1499  ++top_height; // turn top block height into blockchain height
1500 
1501  // query bootstrap daemon's height
1504  bool ok = epee::net_utils::invoke_http_json("/getheight", getheight_req, getheight_res, m_http_client);
1505  ok = ok && getheight_res.status == CORE_RPC_STATUS_OK;
1506 
1507  m_should_use_bootstrap_daemon = ok && top_height + 10 < getheight_res.height;
1508  MINFO((m_should_use_bootstrap_daemon ? "Using" : "Not using") << " the bootstrap daemon (our height: " << top_height << ", bootstrap daemon's height: " << getheight_res.height << ")");
1509  }
1510  if (!m_should_use_bootstrap_daemon)
1511  return false;
1512 
1513  if (mode == invoke_http_mode::JON)
1514  {
1515  r = epee::net_utils::invoke_http_json(command_name, req, res, m_http_client);
1516  }
1517  else if (mode == invoke_http_mode::BIN)
1518  {
1519  r = epee::net_utils::invoke_http_bin(command_name, req, res, m_http_client);
1520  }
1521  else if (mode == invoke_http_mode::JON_RPC)
1522  {
1525  json_req.jsonrpc = "2.0";
1526  json_req.id = epee::serialization::storage_entry(0);
1527  json_req.method = command_name;
1528  json_req.params = req;
1529  r = net_utils::invoke_http_json("/json_rpc", json_req, json_resp, m_http_client);
1530  if (r)
1531  res = json_resp.result;
1532  }
1533  else
1534  {
1535  MERROR("Unknown invoke_http_mode: " << mode);
1536  return false;
1537  }
1538  m_was_bootstrap_ever_used = true;
1539  r = r && res.status == CORE_RPC_STATUS_OK;
1540  res.untrusted = true;
1541  return true;
1542  }
1543  //------------------------------------------------------------------------------------------------------------------------------
1545  {
1546  PERF_TIMER(on_get_last_block_header);
1547  bool r;
1548  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_LAST_BLOCK_HEADER>(invoke_http_mode::JON_RPC, "getlastblockheader", req, res, r))
1549  return r;
1550 
1551  CHECK_CORE_READY();
1552  uint64_t last_block_height;
1553  crypto::hash last_block_hash;
1554  m_core.get_blockchain_top(last_block_height, last_block_hash);
1555  block last_block;
1556  bool have_last_block = m_core.get_block_by_hash(last_block_hash, last_block);
1557  if (!have_last_block)
1558  {
1560  error_resp.message = "Internal error: can't get last block.";
1561  return false;
1562  }
1563  const bool restricted = m_restricted && ctx;
1564  bool response_filled = fill_block_header_response(last_block, false, last_block_height, last_block_hash, res.block_header, req.fill_pow_hash && !restricted);
1565  if (!response_filled)
1566  {
1568  error_resp.message = "Internal error: can't produce valid response.";
1569  return false;
1570  }
1571  res.status = CORE_RPC_STATUS_OK;
1572  return true;
1573  }
1574  //------------------------------------------------------------------------------------------------------------------------------
1576  {
1577  PERF_TIMER(on_get_block_header_by_hash);
1578  bool r;
1579  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH>(invoke_http_mode::JON_RPC, "getblockheaderbyhash", req, res, r))
1580  return r;
1581 
1582  crypto::hash block_hash;
1583  bool hash_parsed = parse_hash256(req.hash, block_hash);
1584  if(!hash_parsed)
1585  {
1587  error_resp.message = "Failed to parse hex representation of block hash. Hex = " + req.hash + '.';
1588  return false;
1589  }
1590  block blk;
1591  bool orphan = false;
1592  bool have_block = m_core.get_block_by_hash(block_hash, blk, &orphan);
1593  if (!have_block)
1594  {
1596  error_resp.message = "Internal error: can't get block by hash. Hash = " + req.hash + '.';
1597  return false;
1598  }
1599  if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
1600  {
1602  error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
1603  return false;
1604  }
1605  uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
1606  const bool restricted = m_restricted && ctx;
1607  bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header, req.fill_pow_hash && !restricted);
1608  if (!response_filled)
1609  {
1611  error_resp.message = "Internal error: can't produce valid response.";
1612  return false;
1613  }
1614  res.status = CORE_RPC_STATUS_OK;
1615  return true;
1616  }
1617  //------------------------------------------------------------------------------------------------------------------------------
1619  {
1620  PERF_TIMER(on_get_block_headers_range);
1621  bool r;
1622  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADERS_RANGE>(invoke_http_mode::JON_RPC, "getblockheadersrange", req, res, r))
1623  return r;
1624 
1625  const uint64_t bc_height = m_core.get_current_blockchain_height();
1626  if (req.start_height >= bc_height || req.end_height >= bc_height || req.start_height > req.end_height)
1627  {
1629  error_resp.message = "Invalid start/end heights.";
1630  return false;
1631  }
1632  for (uint64_t h = req.start_height; h <= req.end_height; ++h)
1633  {
1634  crypto::hash block_hash = m_core.get_block_id_by_height(h);
1635  block blk;
1636  bool have_block = m_core.get_block_by_hash(block_hash, blk);
1637  if (!have_block)
1638  {
1640  error_resp.message = "Internal error: can't get block by height. Height = " + boost::lexical_cast<std::string>(h) + ". Hash = " + epee::string_tools::pod_to_hex(block_hash) + '.';
1641  return false;
1642  }
1643  if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
1644  {
1646  error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
1647  return false;
1648  }
1649  uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
1650  if (block_height != h)
1651  {
1653  error_resp.message = "Internal error: coinbase transaction in the block has the wrong height";
1654  return false;
1655  }
1656  res.headers.push_back(block_header_response());
1657  const bool restricted = m_restricted && ctx;
1658  bool response_filled = fill_block_header_response(blk, false, block_height, block_hash, res.headers.back(), req.fill_pow_hash && !restricted);
1659  if (!response_filled)
1660  {
1662  error_resp.message = "Internal error: can't produce valid response.";
1663  return false;
1664  }
1665  }
1666  res.status = CORE_RPC_STATUS_OK;
1667  return true;
1668  }
1669  //------------------------------------------------------------------------------------------------------------------------------
1671  {
1672  PERF_TIMER(on_get_block_header_by_height);
1673  bool r;
1674  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT>(invoke_http_mode::JON_RPC, "getblockheaderbyheight", req, res, r))
1675  return r;
1676 
1677  if(m_core.get_current_blockchain_height() <= req.height)
1678  {
1680  error_resp.message = std::string("Requested block height: ") + std::to_string(req.height) + " greater than current top block height: " + std::to_string(m_core.get_current_blockchain_height() - 1);
1681  return false;
1682  }
1683  crypto::hash block_hash = m_core.get_block_id_by_height(req.height);
1684  block blk;
1685  bool have_block = m_core.get_block_by_hash(block_hash, blk);
1686  if (!have_block)
1687  {
1689  error_resp.message = "Internal error: can't get block by height. Height = " + std::to_string(req.height) + '.';
1690  return false;
1691  }
1692  const bool restricted = m_restricted && ctx;
1693  bool response_filled = fill_block_header_response(blk, false, req.height, block_hash, res.block_header, req.fill_pow_hash && !restricted);
1694  if (!response_filled)
1695  {
1697  error_resp.message = "Internal error: can't produce valid response.";
1698  return false;
1699  }
1700  res.status = CORE_RPC_STATUS_OK;
1701  return true;
1702  }
1703  //------------------------------------------------------------------------------------------------------------------------------
1705  {
1706  PERF_TIMER(on_get_block);
1707  bool r;
1708  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK>(invoke_http_mode::JON_RPC, "getblock", req, res, r))
1709  return r;
1710 
1711  crypto::hash block_hash;
1712  if (!req.hash.empty())
1713  {
1714  bool hash_parsed = parse_hash256(req.hash, block_hash);
1715  if(!hash_parsed)
1716  {
1718  error_resp.message = "Failed to parse hex representation of block hash. Hex = " + req.hash + '.';
1719  return false;
1720  }
1721  }
1722  else
1723  {
1724  if(m_core.get_current_blockchain_height() <= req.height)
1725  {
1727  error_resp.message = std::string("Requested block height: ") + std::to_string(req.height) + " greater than current top block height: " + std::to_string(m_core.get_current_blockchain_height() - 1);
1728  return false;
1729  }
1730  block_hash = m_core.get_block_id_by_height(req.height);
1731  }
1732  block blk;
1733  bool orphan = false;
1734  bool have_block = m_core.get_block_by_hash(block_hash, blk, &orphan);
1735  if (!have_block)
1736  {
1738  error_resp.message = "Internal error: can't get block by hash. Hash = " + req.hash + '.';
1739  return false;
1740  }
1741  if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
1742  {
1744  error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
1745  return false;
1746  }
1747  uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
1748  const bool restricted = m_restricted && ctx;
1749  bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header, req.fill_pow_hash && !restricted);
1750  if (!response_filled)
1751  {
1753  error_resp.message = "Internal error: can't produce valid response.";
1754  return false;
1755  }
1757  for (size_t n = 0; n < blk.tx_hashes.size(); ++n)
1758  {
1759  res.tx_hashes.push_back(epee::string_tools::pod_to_hex(blk.tx_hashes[n]));
1760  }
1762  res.json = obj_to_json_str(blk);
1763  res.status = CORE_RPC_STATUS_OK;
1764 
1765  return true;
1766  }
1767  //------------------------------------------------------------------------------------------------------------------------------
1769  {
1770  PERF_TIMER(on_get_balance);
1771 
1772  CHECK_CORE_READY();
1773 
1774  if (req.etn_address.empty())
1775  {
1776  res.status = "Failed: Request attribute <etn_address> is mandatory.";
1777  return true;
1778  }
1779 
1780  address_parse_info addr_info;
1781  if(!get_account_address_from_str(addr_info, nettype(), req.etn_address))
1782  {
1783  res.status = "Failed: can't parse address from <etn_address> = " + req.etn_address;
1784  return true;
1785  }
1786 
1787  res.balance = m_core.get_balance(addr_info);
1788  res.status = "OK";
1789 
1790  return true;
1791  }
1792  //------------------------------------------------------------------------------------------------------------------------------
1794  {
1795  PERF_TIMER(on_get_address_batch_history);
1796  CHECK_CORE_READY();
1797 
1798  if (req.etn_address.empty())
1799  {
1800  res.status = "Failed: Request attribute <etn_address> is mandatory.";
1801  return true;
1802  }
1803 
1804  address_parse_info addr_info;
1805  if(!get_account_address_from_str(addr_info, nettype(), req.etn_address))
1806  {
1807  res.status = "Failed: can't parse address from <etn_address> = " + req.etn_address;
1808  return true;
1809  }
1810 
1811  try
1812  {
1813  std::vector<address_outputs> outs = m_core.get_address_batch_history(addr_info, req.start_out_id, req.batch_size, req.desc);
1814  if(!outs.empty() && outs.size() > req.batch_size)
1815  {
1816  res.next_out_id = outs.at(outs.size() - 1).out_id;
1817  res.last_page = false;
1818  outs.pop_back();
1819  }
1820  else
1821  {
1822  res.last_page = true;
1823  }
1824 
1825  for(auto out: outs)
1826  {
1827  res.txs.push_back(epee::string_tools::pod_to_hex(out.tx_hash));
1828  }
1829 
1830  res.status = "OK";
1831  }
1832  catch(const std::exception& e)
1833  {
1834  res.status = "Failed: " + std::string(e.what());
1835  return true;
1836  }
1837 
1838  return true;
1839  }
1840  //------------------------------------------------------------------------------------------------------------------------------
1842  {
1843  PERF_TIMER(on_get_connections);
1844 
1845  res.connections = m_p2p.get_payload_object().get_connections();
1846 
1847  res.status = CORE_RPC_STATUS_OK;
1848 
1849  return true;
1850  }
1851  //------------------------------------------------------------------------------------------------------------------------------
1853  {
1854  return on_get_info(req, res, ctx);
1855  }
1856  //------------------------------------------------------------------------------------------------------------------------------
1858  {
1859  PERF_TIMER(on_hard_fork_info);
1860  bool r;
1861  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_HARD_FORK_INFO>(invoke_http_mode::JON_RPC, "hard_fork_info", req, res, r))
1862  return r;
1863 
1864  const Blockchain &blockchain = m_core.get_blockchain_storage();
1865  uint8_t version = req.version > 0 ? req.version : blockchain.get_next_hard_fork_version();
1866  res.version = blockchain.get_current_hard_fork_version();
1867  res.enabled = blockchain.get_hard_fork_voting_info(version, res.window, res.votes, res.threshold, res.earliest_height, res.voting);
1868  res.state = blockchain.get_hard_fork_state();
1869  res.status = CORE_RPC_STATUS_OK;
1870  return true;
1871  }
1872  //------------------------------------------------------------------------------------------------------------------------------
1874  {
1875  PERF_TIMER(on_get_bans);
1876 
1877  auto now = time(nullptr);
1878  std::map<std::string, time_t> blocked_hosts = m_p2p.get_blocked_hosts();
1879  for (std::map<std::string, time_t>::const_iterator i = blocked_hosts.begin(); i != blocked_hosts.end(); ++i)
1880  {
1881  if (i->second > now) {
1883  b.host = i->first;
1884  b.ip = 0;
1885  uint32_t ip;
1887  b.ip = ip;
1888  b.seconds = i->second - now;
1889  res.bans.push_back(b);
1890  }
1891  }
1892 
1893  res.status = CORE_RPC_STATUS_OK;
1894  return true;
1895  }
1896  //------------------------------------------------------------------------------------------------------------------------------
1898  {
1899  PERF_TIMER(on_set_bans);
1900 
1901  for (auto i = req.bans.begin(); i != req.bans.end(); ++i)
1902  {
1904  if (!i->host.empty())
1905  {
1906  auto na_parsed = net::get_network_address(i->host, 0);
1907  if (!na_parsed)
1908  {
1910  error_resp.message = "Unsupported host type";
1911  return false;
1912  }
1913  na = std::move(*na_parsed);
1914  }
1915  else
1916  {
1918  }
1919  if (i->ban) {
1920  if (i->seconds < -1) {
1922  error_resp.message = "Please pick a value for seconds >= -1";
1923  return false;
1924  } else if (i->seconds == -1) {
1925  m_p2p.block_host(na, uint32_t(std::numeric_limits<time_t>::max()));
1926  } else {
1927  m_p2p.block_host(na, uint32_t(i->seconds));
1928  }
1929  }
1930  else{
1931  m_p2p.unblock_host(na);
1932  }
1933 
1934  }
1935 
1936  res.status = CORE_RPC_STATUS_OK;
1937  return true;
1938  }
1939  //------------------------------------------------------------------------------------------------------------------------------
1941  {
1942  PERF_TIMER(on_flush_txpool);
1943 
1944  bool failed = false;
1945  std::vector<crypto::hash> txids;
1946  if (req.txids.empty())
1947  {
1948  std::vector<transaction> pool_txs;
1949  bool r = m_core.get_pool_transactions(pool_txs);
1950  if (!r)
1951  {
1952  res.status = "Failed to get txpool contents";
1953  return true;
1954  }
1955  for (const auto &tx: pool_txs)
1956  {
1957  txids.push_back(cryptonote::get_transaction_hash(tx));
1958  }
1959  }
1960  else
1961  {
1962  for (const auto &str: req.txids)
1963  {
1964  cryptonote::blobdata txid_data;
1965  if(!epee::string_tools::parse_hexstr_to_binbuff(str, txid_data))
1966  {
1967  failed = true;
1968  }
1969  else
1970  {
1971  crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
1972  txids.push_back(txid);
1973  }
1974  }
1975  }
1976  if (!m_core.get_blockchain_storage().flush_txes_from_pool(txids))
1977  {
1978  res.status = "Failed to remove one or more tx(es)";
1979  return false;
1980  }
1981 
1982  if (failed)
1983  {
1984  if (txids.empty())
1985  res.status = "Failed to parse txid";
1986  else
1987  res.status = "Failed to parse some of the txids";
1988  return false;
1989  }
1990 
1991  res.status = CORE_RPC_STATUS_OK;
1992  return true;
1993  }
1994  //------------------------------------------------------------------------------------------------------------------------------
1996  {
1997  PERF_TIMER(on_get_output_histogram);
1998  bool r;
1999  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_HISTOGRAM>(invoke_http_mode::JON_RPC, "get_output_histogram", req, res, r))
2000  return r;
2001 
2002  const bool restricted = m_restricted && ctx;
2003  if (restricted && req.recent_cutoff > 0 && req.recent_cutoff < (uint64_t)time(NULL) - OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION)
2004  {
2005  res.status = "Recent cutoff is too old";
2006  return true;
2007  }
2008 
2009  std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> histogram;
2010  try
2011  {
2012  histogram = m_core.get_blockchain_storage().get_output_histogram(req.amounts, req.unlocked, req.recent_cutoff, req.min_count);
2013  }
2014  catch (const std::exception &e)
2015  {
2016  res.status = "Failed to get output histogram";
2017  return true;
2018  }
2019 
2020  res.histogram.clear();
2021  res.histogram.reserve(histogram.size());
2022  for (const auto &i: histogram)
2023  {
2024  if (std::get<0>(i.second) >= req.min_count && (std::get<0>(i.second) <= req.max_count || req.max_count == 0))
2025  res.histogram.push_back(COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry(i.first, std::get<0>(i.second), std::get<1>(i.second), std::get<2>(i.second)));
2026  }
2027 
2028  res.status = CORE_RPC_STATUS_OK;
2029  return true;
2030  }
2031  //------------------------------------------------------------------------------------------------------------------------------
2033  {
2034  PERF_TIMER(on_get_version);
2035  bool r;
2036  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_VERSION>(invoke_http_mode::JON_RPC, "get_version", req, res, r))
2037  return r;
2038 
2039  res.version = CORE_RPC_VERSION;
2040  res.status = CORE_RPC_STATUS_OK;
2041  return true;
2042  }
2043  //------------------------------------------------------------------------------------------------------------------------------
2045  {
2046  PERF_TIMER(on_get_coinbase_tx_sum);
2047  std::pair<uint64_t, uint64_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
2048  res.emission_amount = amounts.first;
2049  res.fee_amount = amounts.second;
2050  res.status = CORE_RPC_STATUS_OK;
2051  return true;
2052  }
2053  //------------------------------------------------------------------------------------------------------------------------------
2055  {
2056  PERF_TIMER(on_get_base_fee_estimate);
2057  bool r;
2058  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BASE_FEE_ESTIMATE>(invoke_http_mode::JON_RPC, "get_fee_estimate", req, res, r))
2059  return r;
2060 
2061  res.fee = m_core.get_blockchain_storage().get_dynamic_base_fee_estimate(req.grace_blocks);
2062  res.quantization_mask = Blockchain::get_fee_quantization_mask();
2063  res.status = CORE_RPC_STATUS_OK;
2064  return true;
2065  }
2066  //------------------------------------------------------------------------------------------------------------------------------
2068  {
2069  PERF_TIMER(on_get_alternate_chains);
2070  try
2071  {
2072  std::list<std::pair<Blockchain::block_extended_info, std::vector<crypto::hash>>> chains = m_core.get_blockchain_storage().get_alternative_chains();
2073  for (const auto &i: chains)
2074  {
2075  difficulty_type wdiff = i.first.cumulative_difficulty;
2076  res.chains.push_back(COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info{epee::string_tools::pod_to_hex(get_block_hash(i.first.bl)), i.first.height, i.second.size(), 0, "", 0, {}, std::string()});
2077  store_difficulty(wdiff, res.chains.back().difficulty, res.chains.back().wide_difficulty, res.chains.back().difficulty_top64);
2078  res.chains.back().block_hashes.reserve(i.second.size());
2079  for (const crypto::hash &block_id: i.second)
2080  res.chains.back().block_hashes.push_back(epee::string_tools::pod_to_hex(block_id));
2081  if (i.first.height < i.second.size())
2082  {
2083  res.status = "Error finding alternate chain attachment point";
2084  return true;
2085  }
2086  cryptonote::block main_chain_parent_block;
2087  try { main_chain_parent_block = m_core.get_blockchain_storage().get_db().get_block_from_height(i.first.height - i.second.size()); }
2088  catch (const std::exception &e) { res.status = "Error finding alternate chain attachment point"; return true; }
2089  res.chains.back().main_chain_parent_block = epee::string_tools::pod_to_hex(get_block_hash(main_chain_parent_block));
2090  }
2091  res.status = CORE_RPC_STATUS_OK;
2092  }
2093  catch (...)
2094  {
2095  res.status = "Error retrieving alternate chains";
2096  }
2097  return true;
2098  }
2099  //------------------------------------------------------------------------------------------------------------------------------
2101  {
2102  PERF_TIMER(on_get_limit);
2103  bool r;
2104  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_LIMIT>(invoke_http_mode::JON, "/get_limit", req, res, r))
2105  return r;
2106 
2109  res.status = CORE_RPC_STATUS_OK;
2110  return true;
2111  }
2112  //------------------------------------------------------------------------------------------------------------------------------
2114  {
2115  PERF_TIMER(on_set_limit);
2116  // -1 = reset to default
2117  // 0 = do not modify
2118 
2119  if (req.limit_down > 0)
2120  {
2122  }
2123  else if (req.limit_down < 0)
2124  {
2125  if (req.limit_down != -1)
2126  {
2128  return false;
2129  }
2131  }
2132 
2133  if (req.limit_up > 0)
2134  {
2136  }
2137  else if (req.limit_up < 0)
2138  {
2139  if (req.limit_up != -1)
2140  {
2142  return false;
2143  }
2145  }
2146 
2149  res.status = CORE_RPC_STATUS_OK;
2150  return true;
2151  }
2152  //------------------------------------------------------------------------------------------------------------------------------
2154  {
2155  PERF_TIMER(on_out_peers);
2156  m_p2p.change_max_out_public_peers(req.out_peers);
2157  res.status = CORE_RPC_STATUS_OK;
2158  return true;
2159  }
2160  //------------------------------------------------------------------------------------------------------------------------------
2162  {
2163  PERF_TIMER(on_in_peers);
2164  m_p2p.change_max_in_public_peers(req.in_peers);
2165  res.status = CORE_RPC_STATUS_OK;
2166  return true;
2167  }
2168  //------------------------------------------------------------------------------------------------------------------------------
2170  {
2171  PERF_TIMER(on_start_save_graph);
2172  m_p2p.set_save_graph(true);
2173  res.status = CORE_RPC_STATUS_OK;
2174  return true;
2175  }
2176  //------------------------------------------------------------------------------------------------------------------------------
2178  {
2179  PERF_TIMER(on_stop_save_graph);
2180  m_p2p.set_save_graph(false);
2181  res.status = CORE_RPC_STATUS_OK;
2182  return true;
2183  }
2184  //------------------------------------------------------------------------------------------------------------------------------
2186  {
2187  PERF_TIMER(on_update);
2188 
2189  if (m_core.offline())
2190  {
2191  res.status = "Daemon is running offline";
2192  return true;
2193  }
2194 
2195  static const char software[] = "electroneum";
2196 #ifdef BUILD_TAG
2197  static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG);
2198  static const char subdir[] = "cli";
2199 #else
2200  static const char buildtag[] = "source";
2201  static const char subdir[] = "source";
2202 #endif
2203  LOG_PRINT_L0(req.command << " for software: " << software << "; buildtag: " << buildtag << "; subdir:" << subdir);
2204  if (req.command != "check" && req.command != "download" && req.command != "update")
2205  {
2206  res.status = std::string("unknown command: '") + req.command + "'";
2207  return true;
2208  }
2209 
2211  if (!tools::check_updates(software, buildtag, version, hash))
2212  {
2213  res.status = "Error checking for updates";
2214  return true;
2215  }
2216  if (tools::vercmp(version.c_str(), ELECTRONEUM_VERSION) <= 0)
2217  {
2218  res.update = false;
2219  res.status = CORE_RPC_STATUS_OK;
2220  return true;
2221  }
2222  res.update = true;
2223  res.version = version;
2224  res.user_uri = tools::get_update_url(software, subdir, buildtag, version, true);
2225  res.auto_uri = tools::get_update_url(software, subdir, buildtag, version, false);
2226  res.hash = hash;
2227  if (req.command == "check")
2228  {
2229  res.status = CORE_RPC_STATUS_OK;
2230  return true;
2231  }
2232 
2233  boost::filesystem::path path;
2234  if (req.path.empty())
2235  {
2236  std::string filename;
2237  const char *slash = strrchr(res.auto_uri.c_str(), '/');
2238  if (slash)
2239  filename = slash + 1;
2240  else
2241  filename = std::string(software) + "-update-" + version;
2243  path /= filename;
2244  }
2245  else
2246  {
2247  path = req.path;
2248  }
2249 
2250  crypto::hash file_hash;
2251  if (!tools::sha256sum(path.string(), file_hash) || (hash != epee::string_tools::pod_to_hex(file_hash)))
2252  {
2253  MDEBUG("We don't have that file already, downloading");
2254  if (!tools::download(path.string(), res.auto_uri))
2255  {
2256  MERROR("Failed to download " << res.auto_uri);
2257  return false;
2258  }
2259  if (!tools::sha256sum(path.string(), file_hash))
2260  {
2261  MERROR("Failed to hash " << path);
2262  return false;
2263  }
2264  if (hash != epee::string_tools::pod_to_hex(file_hash))
2265  {
2266  MERROR("Download from " << res.auto_uri << " does not match the expected hash");
2267  return false;
2268  }
2269  MINFO("New version downloaded to " << path);
2270  }
2271  else
2272  {
2273  MDEBUG("We already have " << path << " with expected hash");
2274  }
2275  res.path = path.string();
2276 
2277  if (req.command == "download")
2278  {
2279  res.status = CORE_RPC_STATUS_OK;
2280  return true;
2281  }
2282 
2283  res.status = "'update' not implemented yet";
2284  return true;
2285  }
2286  //------------------------------------------------------------------------------------------------------------------------------
2288  {
2289  PERF_TIMER(on_pop_blocks);
2290 
2291  m_core.get_blockchain_storage().pop_blocks(req.nblocks);
2292 
2293  res.height = m_core.get_current_blockchain_height();
2294  res.status = CORE_RPC_STATUS_OK;
2295 
2296  return true;
2297  }
2298  //------------------------------------------------------------------------------------------------------------------------------
2300  {
2301  PERF_TIMER(on_relay_tx);
2302 
2303  bool failed = false;
2304  res.status = "";
2305  for (const auto &str: req.txids)
2306  {
2307  cryptonote::blobdata txid_data;
2308  if(!epee::string_tools::parse_hexstr_to_binbuff(str, txid_data))
2309  {
2310  if (!res.status.empty()) res.status += ", ";
2311  res.status += std::string("invalid transaction id: ") + str;
2312  failed = true;
2313  continue;
2314  }
2315  crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
2316 
2317  cryptonote::blobdata txblob;
2318  bool r = m_core.get_pool_transaction(txid, txblob);
2319  if (r)
2320  {
2321  cryptonote_connection_context fake_context = AUTO_VAL_INIT(fake_context);
2323  r.txs.push_back(txblob);
2324  m_core.get_protocol()->relay_transactions(r, fake_context);
2325  //TODO: make sure that tx has reached other nodes here, probably wait to receive reflections from other nodes
2326  }
2327  else
2328  {
2329  if (!res.status.empty()) res.status += ", ";
2330  res.status += std::string("transaction not found in pool: ") + str;
2331  failed = true;
2332  continue;
2333  }
2334  }
2335 
2336  if (failed)
2337  {
2338  return false;
2339  }
2340 
2341  res.status = CORE_RPC_STATUS_OK;
2342  return true;
2343  }
2344  //------------------------------------------------------------------------------------------------------------------------------
2346  {
2347  PERF_TIMER(on_sync_info);
2348 
2349  crypto::hash top_hash;
2350  m_core.get_blockchain_top(res.height, top_hash);
2351  ++res.height; // turn top block height into blockchain height
2352  res.target_height = m_core.get_target_blockchain_height();
2353  res.next_needed_pruning_seed = m_p2p.get_payload_object().get_next_needed_pruning_stripe().second;
2354 
2355  for (const auto &c: m_p2p.get_payload_object().get_connections())
2356  res.peers.push_back({c});
2357  const cryptonote::block_queue &block_queue = m_p2p.get_payload_object().get_block_queue();
2359  const std::string span_connection_id = epee::string_tools::pod_to_hex(span.connection_id);
2360  uint32_t speed = (uint32_t)(100.0f * block_queue.get_speed(span.connection_id) + 0.5f);
2361  std::string address = "";
2362  for (const auto &c: m_p2p.get_payload_object().get_connections())
2363  if (c.connection_id == span_connection_id)
2364  address = c.address;
2365  res.spans.push_back({span.start_block_height, span.nblocks, span_connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, address});
2366  return true;
2367  });
2368  res.overview = block_queue.get_overview(res.height);
2369 
2370  res.status = CORE_RPC_STATUS_OK;
2371  return true;
2372  }
2373  //------------------------------------------------------------------------------------------------------------------------------
2375  {
2376  PERF_TIMER(on_get_txpool_backlog);
2377  bool r;
2378  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG>(invoke_http_mode::JON_RPC, "get_txpool_backlog", req, res, r))
2379  return r;
2380 
2381  if (!m_core.get_txpool_backlog(res.backlog))
2382  {
2384  error_resp.message = "Failed to get txpool backlog";
2385  return false;
2386  }
2387 
2388  res.status = CORE_RPC_STATUS_OK;
2389  return true;
2390  }
2391  //------------------------------------------------------------------------------------------------------------------------------
2393  {
2394  if(!m_core.set_validator_key(req.validator_key)) {
2396  error_resp.message = "Failed to set Validator Key. Wrong format.";
2397  return false;
2398  }
2399 
2400  res.status = CORE_RPC_STATUS_OK;
2401  return true;
2402  }
2403 
2404  //------------------------------------------------------------------------------------------------------------------------------
2406  {
2407  std::vector<std::string> v = m_core.generate_ed25519_keypair();
2408  if(v.size() == 0) {
2410  error_resp.message = "Failed to generate ED25519-Donna keypair.";
2411  return false;
2412  }
2413 
2414  res.privateKey = v[0];
2415  res.publicKey = v[1];
2416 
2417  res.status = CORE_RPC_STATUS_OK;
2418  return true;
2419  }
2420 
2421  //------------------------------------------------------------------------------------------------------------------------------
2423  {
2424  try {
2425  std::string v = m_core.sign_message(boost::algorithm::unhex(req.privateKey), req.message);
2426 
2427  if (v.empty()) {
2429  error_resp.message = "Failed to sign message.";
2430  return false;
2431  }
2432 
2433  res.signature = v;
2434  }
2435  catch(const std::exception &e)
2436  {
2438  error_resp.message = "Failed to sign message. Please check that you are using a valid private key.";
2439  return false;
2440  }
2441 
2442  res.status = CORE_RPC_STATUS_OK;
2443  return true;
2444  }
2445  //------------------------------------------------------------------------------------------------------------------------------
2446 
2448  {
2449  if(!req.blob.empty()) {
2450 
2452  arg.serialized_v_list = electroneum::basic::store_t_to_json(req);
2453  cryptonote_connection_context context = boost::value_initialized<cryptonote_connection_context>();
2454 
2455 
2456  electroneum::basic::list_update_outcome update_outcome = m_core.set_validators_list(arg.serialized_v_list, true);
2459  LOG_PRINT_CCONTEXT_L0("Local list is a legitimate emergency list and will now be relayed.");
2460 
2461  if(m_core.get_protocol()->relay_emergency_validator_list(arg, context)){
2462  LOG_PRINT_CCONTEXT_L0("List successfully deployed to peers via p2p.");
2463  return true;
2464  }
2465  }
2466  else {
2467  LOG_ERROR_CCONTEXT("Received incorrect emergency Validators List for relay.");
2468  return false;
2469  }
2470  }
2471 
2472  return false;
2473  }
2474 
2475  //------------------------------------------------------------------------------------------------------------------------------
2477  {
2478  PERF_TIMER(on_get_output_distribution);
2479  bool r;
2480  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::JON_RPC, "get_output_distribution", req, res, r))
2481  return r;
2482 
2483  try
2484  {
2485  // 0 is placeholder for the whole chain
2486  const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1);
2487  for (uint64_t amount: req.amounts)
2488  {
2489  auto data = rpc::RpcHandler::get_output_distribution([this](uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) { return m_core.get_output_distribution(amount, from, to, start_height, distribution, base); }, amount, req.from_height, req_to_height, [this](uint64_t height) { return m_core.get_blockchain_storage().get_db().get_block_hash_from_height(height); }, req.cumulative, m_core.get_current_blockchain_height());
2490  if (!data)
2491  {
2493  error_resp.message = "Failed to get output distribution";
2494  return false;
2495  }
2496 
2497  res.distributions.push_back({std::move(*data), amount, "", req.binary, req.compress});
2498  }
2499  }
2500  catch (const std::exception &e)
2501  {
2503  error_resp.message = "Failed to get output distribution";
2504  return false;
2505  }
2506 
2507  res.status = CORE_RPC_STATUS_OK;
2508  return true;
2509  }
2510  //------------------------------------------------------------------------------------------------------------------------------
2512  {
2513  PERF_TIMER(on_get_output_distribution_bin);
2514 
2515  bool r;
2516  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::BIN, "/get_output_distribution.bin", req, res, r))
2517  return r;
2518 
2519  res.status = "Failed";
2520 
2521  if (!req.binary)
2522  {
2523  res.status = "Binary only call";
2524  return false;
2525  }
2526  try
2527  {
2528  // 0 is placeholder for the whole chain
2529  const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1);
2530  for (uint64_t amount: req.amounts)
2531  {
2532  auto data = rpc::RpcHandler::get_output_distribution([this](uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) { return m_core.get_output_distribution(amount, from, to, start_height, distribution, base); }, amount, req.from_height, req_to_height, [this](uint64_t height) { return m_core.get_blockchain_storage().get_db().get_block_hash_from_height(height); }, req.cumulative, m_core.get_current_blockchain_height());
2533  if (!data)
2534  {
2535  res.status = "Failed to get output distribution";
2536  return false;
2537  }
2538 
2539  res.distributions.push_back({std::move(*data), amount, "", req.binary, req.compress});
2540  }
2541  }
2542  catch (const std::exception &e)
2543  {
2544  res.status = "Failed to get output distribution";
2545  return false;
2546  }
2547 
2548  res.status = CORE_RPC_STATUS_OK;
2549  return true;
2550  }
2551  //------------------------------------------------------------------------------------------------------------------------------
2553  {
2554  try
2555  {
2556  if (!(req.check ? m_core.check_blockchain_pruning() : m_core.prune_blockchain()))
2557  {
2559  error_resp.message = req.check ? "Failed to check blockchain pruning" : "Failed to prune blockchain";
2560  return false;
2561  }
2562  res.pruning_seed = m_core.get_blockchain_pruning_seed();
2563  res.pruned = res.pruning_seed != 0;
2564  }
2565  catch (const std::exception &e)
2566  {
2568  error_resp.message = "Failed to prune blockchain";
2569  return false;
2570  }
2571 
2572  res.status = CORE_RPC_STATUS_OK;
2573  return true;
2574  }
2575  //------------------------------------------------------------------------------------------------------------------------------
2576 
2577 
2579  "rpc-bind-port"
2580  , "Port for RPC server"
2583  , [](std::array<bool, 2> testnet_stagenet, bool defaulted, std::string val)->std::string {
2584  if (testnet_stagenet[0] && defaulted)
2586  else if (testnet_stagenet[1] && defaulted)
2588  return val;
2589  }
2590  };
2591 
2593  "rpc-restricted-bind-port"
2594  , "Port for restricted RPC server"
2595  , ""
2596  };
2597 
2599  "restricted-rpc"
2600  , "Restrict RPC to view only commands and do not return privacy sensitive data in RPC calls"
2601  , false
2602  };
2603 
2605  "bootstrap-daemon-address"
2606  , "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced"
2607  , ""
2608  };
2609 
2611  "bootstrap-daemon-login"
2612  , "Specify username:password for the bootstrap daemon login"
2613  , ""
2614  };
2615 } // namespace cryptonote
uint64_t height
Definition: blockchain.cpp:91
time_t time
Definition: blockchain.cpp:93
virtual uint64_t get_database_size() const =0
get disk space requirements
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t &height) const =0
fetch a block's cumulative difficulty
uint8_t get_current_hard_fork_version() const
gets the current hardfork version in use/voted for
Definition: blockchain.h:815
HardFork::State get_hard_fork_state() const
gets the hardfork voting state object
uint64_t get_current_cumulative_block_weight_median() const
gets the block weight median based on recent blocks (same window as for the limit)
uint64_t get_current_cumulative_block_weight_limit() const
gets the block weight limit based on recent blocks
difficulty_type get_difficulty_for_next_block()
returns the difficulty target the next block to be added must meet
Definition: blockchain.cpp:857
uint8_t get_next_hard_fork_version() const
returns the next hardfork version
Definition: blockchain.h:829
uint64_t get_difficulty_target() const
get difficulty target based on chain and hardfork version
static uint64_t get_fee_quantization_mask()
get fee quantization mask
const BlockchainDB & get_db() const
get a reference to the BlockchainDB in use by Blockchain
Definition: blockchain.h:953
size_t get_alternative_blocks_count() const
returns the number of alternative blocks stored
size_t get_total_transactions() const
gets the total number of transactions on the main chain
bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
get information about hardfork voting for a version
float get_speed(const boost::uuids::uuid &connection_id) const
bool foreach(std::function< bool(const span &)> f) const
std::string get_overview(uint64_t blockchain_height) const
bool on_get_outs_bin(const COMMAND_RPC_GET_OUTPUTS_BIN::request &req, COMMAND_RPC_GET_OUTPUTS_BIN::response &res, const connection_context *ctx=NULL)
bool on_out_peers(const COMMAND_RPC_OUT_PEERS::request &req, COMMAND_RPC_OUT_PEERS::response &res, const connection_context *ctx=NULL)
bool on_get_base_fee_estimate(const COMMAND_RPC_GET_BASE_FEE_ESTIMATE::request &req, COMMAND_RPC_GET_BASE_FEE_ESTIMATE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_mining_status(const COMMAND_RPC_MINING_STATUS::request &req, COMMAND_RPC_MINING_STATUS::response &res, const connection_context *ctx=NULL)
bool on_prune_blockchain(const COMMAND_RPC_PRUNE_BLOCKCHAIN::request &req, COMMAND_RPC_PRUNE_BLOCKCHAIN::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request &req, COMMAND_RPC_GET_TRANSACTIONS::response &res, const connection_context *ctx=NULL)
bool on_get_info(const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, const connection_context *ctx=NULL)
bool on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request &req, COMMAND_RPC_STOP_DAEMON::response &res, const connection_context *ctx=NULL)
bool on_start_save_graph(const COMMAND_RPC_START_SAVE_GRAPH::request &req, COMMAND_RPC_START_SAVE_GRAPH::response &res, const connection_context *ctx=NULL)
bool on_get_coinbase_tx_sum(const COMMAND_RPC_GET_COINBASE_TX_SUM::request &req, COMMAND_RPC_GET_COINBASE_TX_SUM::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request &req, COMMAND_RPC_GET_HEIGHT::response &res, const connection_context *ctx=NULL)
bool on_hard_fork_info(const COMMAND_RPC_HARD_FORK_INFO::request &req, COMMAND_RPC_HARD_FORK_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_pop_blocks(const COMMAND_RPC_POP_BLOCKS::request &req, COMMAND_RPC_POP_BLOCKS::response &res, const connection_context *ctx=NULL)
bool on_get_output_distribution(const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_set_log_categories(const COMMAND_RPC_SET_LOG_CATEGORIES::request &req, COMMAND_RPC_SET_LOG_CATEGORIES::response &res, const connection_context *ctx=NULL)
bool on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_address_batch_history(const COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::request &req, COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::response &res, const connection_context *ctx=NULL)
bool on_save_bc(const COMMAND_RPC_SAVE_BC::request &req, COMMAND_RPC_SAVE_BC::response &res, const connection_context *ctx=NULL)
bool on_relay_tx(const COMMAND_RPC_RELAY_TX::request &req, COMMAND_RPC_RELAY_TX::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_outs(const COMMAND_RPC_GET_OUTPUTS::request &req, COMMAND_RPC_GET_OUTPUTS::response &res, const connection_context *ctx=NULL)
bool on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request &req, COMMAND_RPC_GET_PEER_LIST::response &res, const connection_context *ctx=NULL)
bool on_set_limit(const COMMAND_RPC_SET_LIMIT::request &req, COMMAND_RPC_SET_LIMIT::response &res, const connection_context *ctx=NULL)
bool on_get_info_json(const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_submitblock(const COMMAND_RPC_SUBMITBLOCK::request &req, COMMAND_RPC_SUBMITBLOCK::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response &res, const connection_context *ctx=NULL)
bool on_get_limit(const COMMAND_RPC_GET_LIMIT::request &req, COMMAND_RPC_GET_LIMIT::response &res, const connection_context *ctx=NULL)
bool on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_stop_mining(const COMMAND_RPC_STOP_MINING::request &req, COMMAND_RPC_STOP_MINING::response &res, const connection_context *ctx=NULL)
bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request &req, COMMAND_RPC_SEND_RAW_TX::response &res, const connection_context *ctx=NULL)
bool on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request &req, COMMAND_RPC_SET_LOG_HASH_RATE::response &res, const connection_context *ctx=NULL)
bool on_get_balance(const COMMAND_RPC_GET_BALANCE::request &req, COMMAND_RPC_GET_BALANCE::response &res, const connection_context *ctx=NULL)
bool on_inject_emergency_vlist(const COMMAND_RPC_INJECT_EMERGENCY_VLIST::request &req, COMMAND_RPC_INJECT_EMERGENCY_VLIST::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_net_stats(const COMMAND_RPC_GET_NET_STATS::request &req, COMMAND_RPC_GET_NET_STATS::response &res, const connection_context *ctx=NULL)
bool on_sync_info(const COMMAND_RPC_SYNC_INFO::request &req, COMMAND_RPC_SYNC_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request &req, COMMAND_RPC_GET_TRANSACTION_POOL::response &res, const connection_context *ctx=NULL)
bool on_get_alt_blocks_hashes(const COMMAND_RPC_GET_ALT_BLOCKS_HASHES::request &req, COMMAND_RPC_GET_ALT_BLOCKS_HASHES::response &res, const connection_context *ctx=NULL)
bool on_get_block(const COMMAND_RPC_GET_BLOCK::request &req, COMMAND_RPC_GET_BLOCK::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_set_validator_key(const COMMAND_RPC_SET_VALIDATOR_KEY::request &req, COMMAND_RPC_SET_VALIDATOR_KEY::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_sign_message(const COMMAND_RPC_SIGN_MESSAGE::request &req, COMMAND_RPC_SIGN_MESSAGE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_output_distribution_bin(const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, const connection_context *ctx=NULL)
bool on_get_version(const COMMAND_RPC_GET_VERSION::request &req, COMMAND_RPC_GET_VERSION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_block_headers_range(const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request &req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_getblocktemplate(const COMMAND_RPC_GETBLOCKTEMPLATE::request &req, COMMAND_RPC_GETBLOCKTEMPLATE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_transaction_pool_hashes(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response &res, const connection_context *ctx=NULL)
bool on_set_bans(const COMMAND_RPC_SETBANS::request &req, COMMAND_RPC_SETBANS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_txpool_backlog(const COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool init(const boost::program_options::variables_map &vm, const bool restricted, const std::string &port)
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_address
bool on_get_transaction_pool_hashes_bin(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::response &res, const connection_context *ctx=NULL)
bool on_start_mining(const COMMAND_RPC_START_MINING::request &req, COMMAND_RPC_START_MINING::response &res, const connection_context *ctx=NULL)
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request &req, COMMAND_RPC_SET_LOG_LEVEL::response &res, const connection_context *ctx=NULL)
bool on_update(const COMMAND_RPC_UPDATE::request &req, COMMAND_RPC_UPDATE::response &res, const connection_context *ctx=NULL)
bool on_get_output_histogram(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request &req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
network_type nettype() const
bool on_get_transaction_pool_stats(const COMMAND_RPC_GET_TRANSACTION_POOL_STATS::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_STATS::response &res, const connection_context *ctx=NULL)
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_login
bool on_get_alternate_chains(const COMMAND_RPC_GET_ALTERNATE_CHAINS::request &req, COMMAND_RPC_GET_ALTERNATE_CHAINS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request &req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response &res, const connection_context *ctx=NULL)
bool on_generate_ed25519_keypair(const COMMAND_RPC_GENERATE_ED25519_KEYPAIR::request &req, COMMAND_RPC_GENERATE_ED25519_KEYPAIR::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
bool on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request &req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response &res, const connection_context *ctx=NULL)
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request &req, COMMAND_RPC_GETBLOCKCOUNT::response &res, const connection_context *ctx=NULL)
bool on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request &req, COMMAND_RPC_GET_HASHES_FAST::response &res, const connection_context *ctx=NULL)
bool on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request &req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_stop_save_graph(const COMMAND_RPC_STOP_SAVE_GRAPH::request &req, COMMAND_RPC_STOP_SAVE_GRAPH::response &res, const connection_context *ctx=NULL)
bool on_flush_txpool(const COMMAND_RPC_FLUSH_TRANSACTION_POOL::request &req, COMMAND_RPC_FLUSH_TRANSACTION_POOL::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_in_peers(const COMMAND_RPC_IN_PEERS::request &req, COMMAND_RPC_IN_PEERS::response &res, const connection_context *ctx=NULL)
bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request &req, COMMAND_RPC_GET_CONNECTIONS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request &req, COMMAND_RPC_GETBLOCKHASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_bans(const COMMAND_RPC_GETBANS::request &req, COMMAND_RPC_GETBANS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
static const command_line::arg_descriptor< std::string > arg_rpc_restricted_bind_port
static const command_line::arg_descriptor< bool > arg_restricted_rpc
bool on_generateblocks(const COMMAND_RPC_GENERATEBLOCKS::request &req, COMMAND_RPC_GENERATEBLOCKS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
handles core cryptonote functionality
size_t get_pool_transactions_count() const
get the total number of transactions in the pool
void get_blockchain_top(uint64_t &height, crypto::hash &top_id) const
get the hash and height of the most recent block
uint64_t get_free_space() const
get free disk space on the blockchain partition
bool is_update_available() const
check whether an update is known to be available or not
Blockchain & get_blockchain_storage()
gets the Blockchain instance
bool offline() const
get whether the core is running offline
std::time_t get_start_time() const
gets start_time
uint64_t get_target_blockchain_height() const
gets the target blockchain height
const account_public_address & get_mining_address() const
Definition: miner.cpp:357
bool is_mining() const
Definition: miner.cpp:352
uint64_t get_block_reward() const
Definition: miner.h:90
uint64_t get_min_idle_seconds() const
Definition: miner.cpp:632
uint64_t get_speed() const
Definition: miner.cpp:422
uint32_t get_threads_count() const
Definition: miner.cpp:362
bool get_ignore_battery() const
Definition: miner.cpp:609
bool get_is_background_mining_enabled() const
Definition: miner.cpp:604
static bool find_nonce_for_given_block(block &bl, const difficulty_type &diffic, uint64_t height)
Definition: miner.cpp:471
uint8_t get_idle_threshold() const
Definition: miner.cpp:645
bool start(const account_public_address &adr, size_t threads_count, bool do_background=false, bool ignore_battery=false)
Definition: miner.cpp:366
uint8_t get_mining_target() const
Definition: miner.cpp:658
static boost::optional< output_distribution_data > 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)
Definition: rpc_handler.cpp:29
bool init(std::function< void(size_t, uint8_t *)> rng, const std::string &bind_port="0", const std::string &bind_ip="0.0.0.0", std::vector< std::string > access_control_origins=std::vector< std::string >(), boost::optional< net_utils::http::login > user=boost::none, net_utils::ssl_options_t ssl_options=net_utils::ssl_support_t::e_ssl_support_autodetect)
net_utils::boosted_tcp_server< net_utils::http::http_custom_handler< epee::net_utils::connection_context_base > > m_net_server
static void set_rate_down_limit(uint64_t limit)
static void set_rate_up_limit(uint64_t limit)
bool set_server(const std::string &address, boost::optional< login > user, ssl_options_t ssl_options=ssl_support_t::e_ssl_support_autodetect)
Definition: http_client.h:302
virtual void get_stats(uint64_t &total_packets, uint64_t &total_bytes) const =0
static constexpr address_type get_type_id() noexcept
constexpr uint16_t port() const noexcept
constexpr uint32_t ip() const noexcept
static i_network_throttle & get_global_throttle_in()
singleton ; for friend class ; caller MUST use proper locks! like m_lock_get_global_throttle_in
static i_network_throttle & get_global_throttle_out()
ditto ; use lock ... use m_lock_get_global_throttle_out obviously
Non-owning sequence of data. Does not deep copy.
Definition: span.h:57
constexpr std::size_t size() const noexcept
Definition: span.h:111
size_t get_public_white_peers_count()
virtual uint64_t get_public_connections_count()
t_payload_net_handler & get_payload_object()
size_t get_public_outgoing_connections_count()
size_t get_public_gray_peers_count()
#define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT
#define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION
#define CHECK_CORE_READY()
#define CORE_RPC_STATUS_NOT_MINING
#define CORE_RPC_STATUS_OK
#define CORE_RPC_VERSION
#define CORE_RPC_ERROR_CODE_WRONG_WALLET_ADDRESS
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB_SIZE
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB
#define CORE_RPC_ERROR_CODE_CORE_BUSY
#define CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT
#define CORE_RPC_ERROR_CODE_REGTEST_REQUIRED
#define CORE_RPC_ERROR_CODE_WRONG_PARAM
#define CORE_RPC_ERROR_CODE_MINING_TO_SUBADDRESS
#define CORE_RPC_ERROR_CODE_INTERNAL_ERROR
#define CORE_RPC_ERROR_CODE_TOO_BIG_RESERVE_SIZE
#define CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED
bool parse_hash256(const std::string &str_hash, crypto::hash &hash)
#define DIFFICULTY_TARGET
#define DIFFICULTY_TARGET_V6
#define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT
void * memcpy(void *a, const void *b, size_t c)
const char * res
Definition: hmac_keccak.cpp:41
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
#define MERROR(x)
Definition: misc_log_ex.h:73
#define MDEBUG(x)
Definition: misc_log_ex.h:76
std::string mlog_get_categories()
Definition: mlog.cpp:276
void mlog_set_log(const char *log)
Definition: mlog.cpp:288
void mlog_set_log_level(int level)
Definition: mlog.cpp:282
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
#define MINFO(x)
Definition: misc_log_ex.h:75
#define LOG_PRINT_L2(x)
Definition: misc_log_ex.h:101
#define LOG_PRINT_L0(x)
Definition: misc_log_ex.h:99
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
uint16_t const RPC_DEFAULT_PORT
uint16_t const RPC_DEFAULT_PORT
uint16_t const RPC_DEFAULT_PORT
const crypto::public_key null_pkey
Definition: crypto.cpp:72
POD_CLASS public_key
Definition: crypto.h:76
void rand(size_t N, uint8_t *bytes)
Definition: crypto.h:207
POD_CLASS key_image
Definition: crypto.h:102
POD_CLASS hash
Definition: hash.h:50
Holds cryptonote related classes and helpers.
Definition: ban.cpp:40
std::string obj_to_json_str(T &obj)
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:43
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version, uint64_t current_block_height, network_type nettype)
blobdata get_block_hashing_blob(const block &b)
bool get_block_hash(const block &b, crypto::hash &res)
bool get_account_address_from_str(address_parse_info &info, network_type nettype, std::string const &str)
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash *block_hash)
const command_line::arg_descriptor< bool, false > arg_testnet_on
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
crypto::hash get_transaction_hash(const transaction &t)
size_t slow_memmem(const void *start_buff, size_t buflen, const void *pat, size_t patlen)
blobdata block_to_blob(const block &b)
const command_line::arg_descriptor< bool, false > arg_stagenet_on
bool get_block_longhash(const block &b, crypto::hash &res, uint64_t height)
blobdata tx_to_blob(const transaction &tx)
std::string blobdata
Definition: blobdatatype.h:39
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
std::string hex(difficulty_type v)
Definition: difficulty.cpp:254
bool parse_and_validate_tx_base_from_blob(const blobdata &tx_blob, transaction &tx)
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
void init_options(boost::program_options::options_description &hidden_options, boost::program_options::options_description &normal_options)
epee::misc_utils::struct_init< response_t > response
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
std::string to_string(t_connection_type type)
bool invoke_http_bin(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
boost::variant< uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry > storage_entry
bool parse_hexstr_to_binbuff(const epee::span< const char > s, epee::span< char > &res)
Definition: string_tools.h:92
std::string pod_to_hex(const t_pod_type &s)
Definition: string_tools.h:317
bool hex_to_pod(const std::string &hex_str, t_pod_type &s)
Definition: string_tools.h:324
std::string & get_current_module_folder()
Definition: string_tools.h:233
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
std::string buff_to_hex_nodelimer(const std::string &src)
Definition: string_tools.h:87
version
Supported socks variants.
Definition: socks.h:58
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
Definition: parse.cpp:38
const int64_t default_limit_up
Definition: net_node.h:481
const int64_t default_limit_down
Definition: net_node.h:482
tuple make_tuple()
Definition: gtest-tuple.h:675
::std::string string
Definition: gtest-port.h:1097
const T & move(const T &t)
Definition: gtest-port.h:1317
int vercmp(const char *v0, const char *v1)
Definition: util.cpp:915
bool sha256sum(const uint8_t *data, size_t len, crypto::hash &hash)
Definition: util.cpp:933
std::string get_update_url(const std::string &software, const std::string &subdir, const std::string &buildtag, const std::string &version, bool user)
Definition: updates.cpp:101
bool download(const std::string &path, const std::string &url, std::function< bool(const std::string &, const std::string &, size_t, ssize_t)> cb)
Definition: download.cpp:258
bool check_updates(const std::string &software, const std::string &buildtag, std::string &version, std::string &hash)
Definition: updates.cpp:41
#define LOG_ERROR_CCONTEXT(message)
#define LOG_PRINT_CCONTEXT_L0(message)
#define PERF_TIMER(name)
Definition: perf_timer.h:82
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL \detailed for described the serialization of an object
#define END_SERIALIZE()
self-explanatory
size_t patlen
Definition: slow_memmem.cpp:75
const char * pat
Definition: slow_memmem.cpp:76
size_t buflen
Definition: slow_memmem.cpp:73
const char * buf
Definition: slow_memmem.cpp:74
boost::endian::big_uint16_t port
Definition: socks.cpp:60
boost::endian::big_uint32_t ip
Definition: socks.cpp:61
CXA_THROW_INFO_T * info
Definition: stack_trace.cpp:91
int bool
Definition: stdbool.h:36
#define false
Definition: stdbool.h:38
unsigned int uint32_t
Definition: stdint.h:126
unsigned char uint8_t
Definition: stdint.h:124
unsigned __int64 uint64_t
Definition: stdint.h:136
std::vector< crypto::hash > tx_hashes
static boost::optional< rpc_args > process(const boost::program_options::variables_map &vm, const bool any_cert_option=false)
Definition: rpc_args.cpp:125
static void init_options(boost::program_options::options_description &desc, const bool any_cert_option=false)
Definition: rpc_args.cpp:108
epee::serialization::storage_entry id
wipeable_string password
Definition: http_auth.h:57
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
const char * address
Definition: multisig.cpp:37
const char *const ELECTRONEUM_VERSION
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL
const char *const ELECTRONEUM_VERSION_TAG