Electroneum
daemonize::t_rpc_command_executor Class Referencefinal

#include <rpc_command_executor.h>

Public Member Functions

 t_rpc_command_executor (uint32_t ip, uint16_t port, const boost::optional< tools::login > &user, const epee::net_utils::ssl_options_t &ssl_options, bool is_rpc=true, cryptonote::core_rpc_server *rpc_server=NULL)
 
 ~t_rpc_command_executor ()
 
bool print_peer_list (bool white=true, bool gray=true, size_t limit=0)
 
bool print_peer_list_stats ()
 
bool save_blockchain ()
 
bool show_hash_rate ()
 
bool hide_hash_rate ()
 
bool show_difficulty ()
 
bool show_status ()
 
bool print_connections ()
 
bool print_blockchain_info (uint64_t start_block_index, uint64_t end_block_index)
 
bool set_log_level (int8_t level)
 
bool set_log_categories (const std::string &categories)
 
bool print_height ()
 
bool print_block_by_hash (crypto::hash block_hash, bool include_hex)
 
bool print_block_by_height (uint64_t height, bool include_hex)
 
bool print_transaction (crypto::hash transaction_hash, bool include_hex, bool include_json)
 
bool is_key_image_spent (const crypto::key_image &ki)
 
bool print_transaction_pool_long ()
 
bool print_transaction_pool_short ()
 
bool print_transaction_pool_stats ()
 
bool start_mining (cryptonote::account_public_address address, uint64_t num_threads, cryptonote::network_type nettype, bool do_background_mining=false, bool ignore_battery=false)
 
bool stop_mining ()
 
bool mining_status ()
 
bool stop_daemon ()
 
bool print_status ()
 
bool get_limit ()
 
bool get_limit_up ()
 
bool get_limit_down ()
 
bool set_limit (int64_t limit_down, int64_t limit_up)
 
bool out_peers (uint64_t limit)
 
bool in_peers (uint64_t limit)
 
bool start_save_graph ()
 
bool stop_save_graph ()
 
bool hard_fork_info (uint8_t version)
 
bool print_bans ()
 
bool ban (const std::string &ip, time_t seconds)
 
bool unban (const std::string &ip)
 
bool flush_txpool (const std::string &txid)
 
bool output_histogram (const std::vector< uint64_t > &amounts, uint64_t min_count, uint64_t max_count)
 
bool print_coinbase_tx_sum (uint64_t height, uint64_t count)
 
bool alt_chain_info (const std::string &tip)
 
bool print_blockchain_dynamic_stats (uint64_t nblocks)
 
bool update (const std::string &command)
 
bool relay_tx (const std::string &txid)
 
bool sync_info ()
 
bool pop_blocks (uint64_t num_blocks)
 
bool prune_blockchain ()
 
bool check_blockchain_pruning ()
 
bool print_net_stats ()
 
bool set_validator_key (const std::string &key)
 
bool generate_ed25519_keypair ()
 
bool sign_message (const std::string privateKey, const std::string message)
 

Detailed Description

Definition at line 55 of file rpc_command_executor.h.

Constructor & Destructor Documentation

◆ t_rpc_command_executor()

daemonize::t_rpc_command_executor::t_rpc_command_executor ( uint32_t  ip,
uint16_t  port,
const boost::optional< tools::login > &  user,
const epee::net_utils::ssl_options_t ssl_options,
bool  is_rpc = true,
cryptonote::core_rpc_server rpc_server = NULL 
)

Definition at line 127 of file rpc_command_executor.cpp.

135  : m_rpc_client(NULL), m_rpc_server(rpc_server)
136 {
137  if (is_rpc)
138  {
139  boost::optional<epee::net_utils::http::login> http_login{};
140  if (login)
141  http_login.emplace(login->username, login->password.password());
142  m_rpc_client = new tools::t_rpc_client(ip, port, std::move(http_login), ssl_options);
143  }
144  else
145  {
146  if (rpc_server == NULL)
147  {
148  throw std::runtime_error("If not calling commands via RPC, rpc_server pointer must be non-null");
149  }
150  }
151 
152  m_is_rpc = is_rpc;
153 }
const T & move(const T &t)
Definition: gtest-port.h:1317
boost::endian::big_uint16_t port
Definition: socks.cpp:60
boost::endian::big_uint32_t ip
Definition: socks.cpp:61
Here is the call graph for this function:

◆ ~t_rpc_command_executor()

daemonize::t_rpc_command_executor::~t_rpc_command_executor ( )

Definition at line 155 of file rpc_command_executor.cpp.

156 {
157  if (m_rpc_client != NULL)
158  {
159  delete m_rpc_client;
160  }
161 }

Member Function Documentation

◆ alt_chain_info()

bool daemonize::t_rpc_command_executor::alt_chain_info ( const std::string &  tip)

Definition at line 1825 of file rpc_command_executor.cpp.

1826 {
1831  epee::json_rpc::error error_resp;
1832 
1833  std::string fail_message = "Unsuccessful";
1834 
1835  if (m_is_rpc)
1836  {
1837  if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
1838  {
1839  return true;
1840  }
1841  if (!m_rpc_client->json_rpc_request(req, res, "get_alternate_chains", fail_message.c_str()))
1842  {
1843  return true;
1844  }
1845  }
1846  else
1847  {
1848  if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
1849  {
1850  tools::fail_msg_writer() << make_error(fail_message, ires.status);
1851  return true;
1852  }
1853  if (!m_rpc_server->on_get_alternate_chains(req, res, error_resp))
1854  {
1855  tools::fail_msg_writer() << make_error(fail_message, res.status);
1856  return true;
1857  }
1858  }
1859 
1860  if (tip.empty())
1861  {
1862  tools::msg_writer() << boost::lexical_cast<std::string>(res.chains.size()) << " alternate chains found:";
1863  for (const auto &chain: res.chains)
1864  {
1865  uint64_t start_height = (chain.height - chain.length + 1);
1866  tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)
1867  << " deep), diff " << chain.difficulty << ": " << chain.block_hash;
1868  }
1869  }
1870  else
1871  {
1872  const auto i = std::find_if(res.chains.begin(), res.chains.end(), [&tip](cryptonote::COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info &info){ return info.block_hash == tip; });
1873  if (i != res.chains.end())
1874  {
1875  const auto &chain = *i;
1876  tools::success_msg_writer() << "Found alternate chain with tip " << tip;
1877  uint64_t start_height = (chain.height - chain.length + 1);
1878  tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)
1879  << " deep), diff " << chain.difficulty << ":";
1880  for (const std::string &block_id: chain.block_hashes)
1881  tools::msg_writer() << " " << block_id;
1882  tools::msg_writer() << "Chain parent on main chain: " << chain.main_chain_parent_block;
1883  }
1884  else
1885  tools::fail_msg_writer() << "Block hash " << tip << " is not the tip of any known alternate chain";
1886  }
1887  return true;
1888 }
bool on_get_info(const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, const connection_context *ctx=NULL)
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 json_rpc_request(T_req &req, T_res &res, std::string const &method_name, std::string const &fail_msg)
Definition: rpc_client.h:91
bool rpc_request(T_req &req, T_res &res, std::string const &relative_url, std::string const &fail_msg)
Definition: rpc_client.h:119
#define CORE_RPC_STATUS_OK
const char * res
Definition: hmac_keccak.cpp:41
::std::string string
Definition: gtest-port.h:1097
scoped_message_writer fail_msg_writer()
scoped_message_writer msg_writer(epee::console_colors color=epee::console_color_default)
scoped_message_writer success_msg_writer(bool color=true)
for(i=1;i< 1;++i) fe_sq(t0
CXA_THROW_INFO_T * info
Definition: stack_trace.cpp:91
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ban()

bool daemonize::t_rpc_command_executor::ban ( const std::string &  ip,
time_t  seconds 
)

Definition at line 1649 of file rpc_command_executor.cpp.

1650 {
1653  std::string fail_message = "Unsuccessful";
1654  epee::json_rpc::error error_resp;
1655 
1658  {
1659  tools::fail_msg_writer() << "Invalid IP";
1660  return true;
1661  }
1662  ban.ban = true;
1663  ban.seconds = seconds;
1664  req.bans.push_back(ban);
1665 
1666  if (m_is_rpc)
1667  {
1668  if (!m_rpc_client->json_rpc_request(req, res, "set_bans", fail_message.c_str()))
1669  {
1670  return true;
1671  }
1672  }
1673  else
1674  {
1675  if (!m_rpc_server->on_set_bans(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1676  {
1677  tools::fail_msg_writer() << make_error(fail_message, res.status);
1678  return true;
1679  }
1680  }
1681 
1682  return true;
1683 }
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 ban(const std::string &ip, time_t seconds)
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_blockchain_pruning()

bool daemonize::t_rpc_command_executor::check_blockchain_pruning ( )

Definition at line 2240 of file rpc_command_executor.cpp.

2241 {
2244  std::string fail_message = "Unsuccessful";
2245  epee::json_rpc::error error_resp;
2246 
2247  req.check = true;
2248 
2249  if (m_is_rpc)
2250  {
2251  if (!m_rpc_client->json_rpc_request(req, res, "prune_blockchain", fail_message.c_str()))
2252  {
2253  return true;
2254  }
2255  }
2256  else
2257  {
2258  if (!m_rpc_server->on_prune_blockchain(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2259  {
2260  tools::fail_msg_writer() << make_error(fail_message, res.status);
2261  return true;
2262  }
2263  }
2264 
2265  if (res.pruning_seed)
2266  {
2267  tools::success_msg_writer() << "Blockchain is pruned";
2268  }
2269  else
2270  {
2271  tools::success_msg_writer() << "Blockchain is not pruned";
2272  }
2273  return true;
2274 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flush_txpool()

bool daemonize::t_rpc_command_executor::flush_txpool ( const std::string &  txid)

Definition at line 1721 of file rpc_command_executor.cpp.

1722 {
1725  std::string fail_message = "Unsuccessful";
1726  epee::json_rpc::error error_resp;
1727 
1728  if (!txid.empty())
1729  req.txids.push_back(txid);
1730 
1731  if (m_is_rpc)
1732  {
1733  if (!m_rpc_client->json_rpc_request(req, res, "flush_txpool", fail_message.c_str()))
1734  {
1735  return true;
1736  }
1737  }
1738  else
1739  {
1740  if (!m_rpc_server->on_flush_txpool(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1741  {
1742  tools::fail_msg_writer() << make_error(fail_message, res.status);
1743  return true;
1744  }
1745  }
1746 
1747  tools::success_msg_writer() << "Pool successfully flushed";
1748  return true;
1749 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ generate_ed25519_keypair()

bool daemonize::t_rpc_command_executor::generate_ed25519_keypair ( )

Definition at line 2276 of file rpc_command_executor.cpp.

2276  {
2279  std::string fail_message = "Unsuccessful";
2280  epee::json_rpc::error error_resp;
2281 
2282  if (m_is_rpc) {
2283  if (!m_rpc_client->json_rpc_request(req, res, "generate_ed25519_keypair", fail_message.c_str())) {
2284  return true;
2285  }
2286  } else {
2287  if (!m_rpc_server->on_generate_ed25519_keypair(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2288  {
2289  tools::fail_msg_writer() << make_error(fail_message, res.status);
2290  return true;
2291  }
2292  }
2293 
2294  tools::success_msg_writer() << "Private Key:" << res.privateKey;
2295  tools::success_msg_writer() << "Public Key:" << res.publicKey;
2296  return true;
2297 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_limit()

bool daemonize::t_rpc_command_executor::get_limit ( )

Definition at line 1354 of file rpc_command_executor.cpp.

1355 {
1358 
1359  std::string failure_message = "Couldn't get limit";
1360 
1361  if (m_is_rpc)
1362  {
1363  if (!m_rpc_client->rpc_request(req, res, "/get_limit", failure_message.c_str()))
1364  {
1365  return true;
1366  }
1367  }
1368  else
1369  {
1370  if (!m_rpc_server->on_get_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1371  {
1372  tools::fail_msg_writer() << make_error(failure_message, res.status);
1373  return true;
1374  }
1375  }
1376 
1377  tools::msg_writer() << "limit-down is " << res.limit_down << " kB/s";
1378  tools::msg_writer() << "limit-up is " << res.limit_up << " kB/s";
1379  return true;
1380 }
bool on_get_limit(const COMMAND_RPC_GET_LIMIT::request &req, COMMAND_RPC_GET_LIMIT::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_limit_down()

bool daemonize::t_rpc_command_executor::get_limit_down ( )

Definition at line 1440 of file rpc_command_executor.cpp.

1441 {
1444 
1445  std::string failure_message = "Couldn't get limit";
1446 
1447  if (m_is_rpc)
1448  {
1449  if (!m_rpc_client->rpc_request(req, res, "/get_limit", failure_message.c_str()))
1450  {
1451  return true;
1452  }
1453  }
1454  else
1455  {
1456  if (!m_rpc_server->on_get_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1457  {
1458  tools::fail_msg_writer() << make_error(failure_message, res.status);
1459  return true;
1460  }
1461  }
1462 
1463  tools::msg_writer() << "limit-down is " << res.limit_down << " kB/s";
1464  return true;
1465 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_limit_up()

bool daemonize::t_rpc_command_executor::get_limit_up ( )

Definition at line 1413 of file rpc_command_executor.cpp.

1414 {
1417 
1418  std::string failure_message = "Couldn't get limit";
1419 
1420  if (m_is_rpc)
1421  {
1422  if (!m_rpc_client->rpc_request(req, res, "/get_limit", failure_message.c_str()))
1423  {
1424  return true;
1425  }
1426  }
1427  else
1428  {
1429  if (!m_rpc_server->on_get_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1430  {
1431  tools::fail_msg_writer() << make_error(failure_message, res.status);
1432  return true;
1433  }
1434  }
1435 
1436  tools::msg_writer() << "limit-up is " << res.limit_up << " kB/s";
1437  return true;
1438 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hard_fork_info()

bool daemonize::t_rpc_command_executor::hard_fork_info ( uint8_t  version)

Definition at line 1584 of file rpc_command_executor.cpp.

1585 {
1588  std::string fail_message = "Unsuccessful";
1589  epee::json_rpc::error error_resp;
1590 
1591  req.version = version;
1592 
1593  if (m_is_rpc)
1594  {
1595  if (!m_rpc_client->json_rpc_request(req, res, "hard_fork_info", fail_message.c_str()))
1596  {
1597  return true;
1598  }
1599  }
1600  else
1601  {
1602  if (!m_rpc_server->on_hard_fork_info(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1603  {
1604  tools::fail_msg_writer() << make_error(fail_message, res.status);
1605  return true;
1606  }
1607  }
1608 
1609  version = version > 0 ? version : res.voting;
1610  tools::msg_writer() << "version " << (uint32_t)version << " " << (res.enabled ? "enabled" : "not enabled") <<
1611  ", " << res.votes << "/" << res.window << " votes, threshold " << res.threshold;
1612  tools::msg_writer() << "current version " << (uint32_t)res.version << ", voting for version " << (uint32_t)res.voting;
1613 
1614  return true;
1615 }
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)
version
Supported socks variants.
Definition: socks.h:58
unsigned int uint32_t
Definition: stdint.h:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hide_hash_rate()

bool daemonize::t_rpc_command_executor::hide_hash_rate ( )

Definition at line 289 of file rpc_command_executor.cpp.

289  {
292  req.visible = false;
293 
294  std::string fail_message = "Unsuccessful";
295 
296  if (m_is_rpc)
297  {
298  if (!m_rpc_client->rpc_request(req, res, "/set_log_hash_rate", fail_message.c_str()))
299  {
300  return true;
301  }
302  }
303  else
304  {
305  if (!m_rpc_server->on_set_log_hash_rate(req, res) || res.status != CORE_RPC_STATUS_OK)
306  {
307  tools::fail_msg_writer() << make_error(fail_message, res.status);
308  return true;
309  }
310  }
311 
312  tools::success_msg_writer() << "Hash rate logging is off";
313 
314  return true;
315 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ in_peers()

bool daemonize::t_rpc_command_executor::in_peers ( uint64_t  limit)

Definition at line 1499 of file rpc_command_executor.cpp.

1500 {
1503 
1504  epee::json_rpc::error error_resp;
1505 
1506  req.in_peers = limit;
1507 
1508  std::string fail_message = "Unsuccessful";
1509 
1510  if (m_is_rpc)
1511  {
1512  if (!m_rpc_client->rpc_request(req, res, "/in_peers", fail_message.c_str()))
1513  {
1514  return true;
1515  }
1516  }
1517  else
1518  {
1519  if (!m_rpc_server->on_in_peers(req, res) || res.status != CORE_RPC_STATUS_OK)
1520  {
1521  tools::fail_msg_writer() << make_error(fail_message, res.status);
1522  return true;
1523  }
1524  }
1525 
1526  tools::msg_writer() << "Max number of in peers set to " << limit << std::endl;
1527 
1528  return true;
1529 }
bool on_in_peers(const COMMAND_RPC_IN_PEERS::request &req, COMMAND_RPC_IN_PEERS::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_key_image_spent()

bool daemonize::t_rpc_command_executor::is_key_image_spent ( const crypto::key_image ki)

Definition at line 981 of file rpc_command_executor.cpp.

981  {
984 
985  std::string fail_message = "Problem checking key image";
986 
987  req.key_images.push_back(epee::string_tools::pod_to_hex(ki));
988  if (m_is_rpc)
989  {
990  if (!m_rpc_client->rpc_request(req, res, "/is_key_image_spent", fail_message.c_str()))
991  {
992  return true;
993  }
994  }
995  else
996  {
997  if (!m_rpc_server->on_is_key_image_spent(req, res) || res.status != CORE_RPC_STATUS_OK)
998  {
999  tools::fail_msg_writer() << make_error(fail_message, res.status);
1000  return true;
1001  }
1002  }
1003 
1004  if (1 == res.spent_status.size())
1005  {
1006  // first as hex
1007  tools::success_msg_writer() << ki << ": " << (res.spent_status.front() ? "spent" : "unspent") << (res.spent_status.front() == cryptonote::COMMAND_RPC_IS_KEY_IMAGE_SPENT::SPENT_IN_POOL ? " (in pool)" : "");
1008  }
1009  else
1010  {
1011  tools::fail_msg_writer() << "key image status could not be determined" << std::endl;
1012  }
1013 
1014  return true;
1015 }
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)
std::string pod_to_hex(const t_pod_type &s)
Definition: string_tools.h:317
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mining_status()

bool daemonize::t_rpc_command_executor::mining_status ( )

Definition at line 492 of file rpc_command_executor.cpp.

492  {
495  epee::json_rpc::error error_resp;
496  bool has_mining_info = true;
497 
498  std::string fail_message = "Problem fetching info";
499 
500  bool mining_busy = false;
501  if (m_is_rpc)
502  {
503  // mining info is only available non unrestricted RPC mode
504  has_mining_info = m_rpc_client->rpc_request(mreq, mres, "/mining_status", fail_message.c_str());
505  }
506  else
507  {
508  if (!m_rpc_server->on_mining_status(mreq, mres))
509  {
510  tools::fail_msg_writer() << fail_message.c_str();
511  return true;
512  }
513 
514  if (mres.status == CORE_RPC_STATUS_BUSY)
515  {
516  mining_busy = true;
517  }
518  else if (mres.status != CORE_RPC_STATUS_OK)
519  {
520  tools::fail_msg_writer() << make_error(fail_message, mres.status);
521  return true;
522  }
523  }
524 
525  if (!has_mining_info)
526  {
527  tools::fail_msg_writer() << "Mining info unavailable";
528  return true;
529  }
530 
531  if (mining_busy || !mres.active)
532  {
533  tools::msg_writer() << "Not currently mining";
534  }
535  else
536  {
537  tools::msg_writer() << "Mining at " << get_mining_speed(mres.speed) << " with " << mres.threads_count << " threads";
538  }
539 
540  if (mres.active || mres.is_background_mining_enabled)
541  {
542  tools::msg_writer() << "PoW algorithm: " << mres.pow_algorithm;
543  tools::msg_writer() << "Mining address: " << mres.address;
544  }
545 
546  if (mres.is_background_mining_enabled)
547  {
548  tools::msg_writer() << "Smart mining enabled:";
549  tools::msg_writer() << " Target: " << (unsigned)mres.bg_target << "% CPU";
550  tools::msg_writer() << " Idle threshold: " << (unsigned)mres.bg_idle_threshold << "% CPU";
551  tools::msg_writer() << " Min idle time: " << (unsigned)mres.bg_min_idle_seconds << " seconds";
552  tools::msg_writer() << " Ignore battery: " << (mres.bg_ignore_battery ? "yes" : "no");
553  }
554 
555  if (!mining_busy && mres.active && mres.speed > 0 && mres.block_target > 0 && mres.difficulty > 0)
556  {
557  double ratio = mres.speed * mres.block_target / (double)mres.difficulty;
558  uint64_t daily = 86400ull / mres.block_target * mres.block_reward * ratio;
559  uint64_t monthly = 86400ull / mres.block_target * 30.5 * mres.block_reward * ratio;
560  uint64_t yearly = 86400ull / mres.block_target * 356 * mres.block_reward * ratio;
561  tools::msg_writer() << "Expected: " << cryptonote::print_etn(daily) << " etn daily, "
562  << cryptonote::print_etn(monthly) << " etn monthly, " << cryptonote::print_etn(yearly) << " yearly";
563  }
564 
565  return true;
566 }
bool on_mining_status(const COMMAND_RPC_MINING_STATUS::request &req, COMMAND_RPC_MINING_STATUS::response &res, const connection_context *ctx=NULL)
#define CORE_RPC_STATUS_BUSY
std::string print_etn(uint64_t amount, unsigned int decimal_point)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ out_peers()

bool daemonize::t_rpc_command_executor::out_peers ( uint64_t  limit)

Definition at line 1467 of file rpc_command_executor.cpp.

1468 {
1471 
1472  epee::json_rpc::error error_resp;
1473 
1474  req.out_peers = limit;
1475 
1476  std::string fail_message = "Unsuccessful";
1477 
1478  if (m_is_rpc)
1479  {
1480  if (!m_rpc_client->rpc_request(req, res, "/out_peers", fail_message.c_str()))
1481  {
1482  return true;
1483  }
1484  }
1485  else
1486  {
1487  if (!m_rpc_server->on_out_peers(req, res) || res.status != CORE_RPC_STATUS_OK)
1488  {
1489  tools::fail_msg_writer() << make_error(fail_message, res.status);
1490  return true;
1491  }
1492  }
1493 
1494  tools::msg_writer() << "Max number of out peers set to " << limit << std::endl;
1495 
1496  return true;
1497 }
bool on_out_peers(const COMMAND_RPC_OUT_PEERS::request &req, COMMAND_RPC_OUT_PEERS::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ output_histogram()

bool daemonize::t_rpc_command_executor::output_histogram ( const std::vector< uint64_t > &  amounts,
uint64_t  min_count,
uint64_t  max_count 
)

Definition at line 1751 of file rpc_command_executor.cpp.

1752 {
1755  std::string fail_message = "Unsuccessful";
1756  epee::json_rpc::error error_resp;
1757 
1758  req.amounts = amounts;
1759  req.min_count = min_count;
1760  req.max_count = max_count;
1761  req.unlocked = false;
1762  req.recent_cutoff = 0;
1763 
1764  if (m_is_rpc)
1765  {
1766  if (!m_rpc_client->json_rpc_request(req, res, "get_output_histogram", fail_message.c_str()))
1767  {
1768  return true;
1769  }
1770  }
1771  else
1772  {
1773  if (!m_rpc_server->on_get_output_histogram(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1774  {
1775  tools::fail_msg_writer() << make_error(fail_message, res.status);
1776  return true;
1777  }
1778  }
1779 
1780  std::sort(res.histogram.begin(), res.histogram.end(),
1781  [](const cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry &e1, const cryptonote::COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry &e2)->bool { return e1.total_instances < e2.total_instances; });
1782  for (const auto &e: res.histogram)
1783  {
1784  tools::msg_writer() << e.total_instances << " " << cryptonote::print_etn(e.amount);
1785  }
1786 
1787  return true;
1788 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_blocks()

bool daemonize::t_rpc_command_executor::pop_blocks ( uint64_t  num_blocks)

Definition at line 2160 of file rpc_command_executor.cpp.

2161 {
2164  std::string fail_message = "pop_blocks failed";
2165 
2166  req.nblocks = num_blocks;
2167  if (m_is_rpc)
2168  {
2169  if (!m_rpc_client->rpc_request(req, res, "/pop_blocks", fail_message.c_str()))
2170  {
2171  return true;
2172  }
2173  }
2174  else
2175  {
2176  if (!m_rpc_server->on_pop_blocks(req, res) || res.status != CORE_RPC_STATUS_OK)
2177  {
2178  tools::fail_msg_writer() << make_error(fail_message, res.status);
2179  return true;
2180  }
2181  }
2182  tools::success_msg_writer() << "new height: " << res.height;
2183 
2184  return true;
2185 }
uint64_t num_blocks(const std::vector< test_event_entry > &events)
Definition: chaingen.cpp:1044
bool on_pop_blocks(const COMMAND_RPC_POP_BLOCKS::request &req, COMMAND_RPC_POP_BLOCKS::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_bans()

bool daemonize::t_rpc_command_executor::print_bans ( )

Definition at line 1617 of file rpc_command_executor.cpp.

1618 {
1621  std::string fail_message = "Unsuccessful";
1622  epee::json_rpc::error error_resp;
1623 
1624  if (m_is_rpc)
1625  {
1626  if (!m_rpc_client->json_rpc_request(req, res, "get_bans", fail_message.c_str()))
1627  {
1628  return true;
1629  }
1630  }
1631  else
1632  {
1633  if (!m_rpc_server->on_get_bans(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1634  {
1635  tools::fail_msg_writer() << make_error(fail_message, res.status);
1636  return true;
1637  }
1638  }
1639 
1640  for (auto i = res.bans.begin(); i != res.bans.end(); ++i)
1641  {
1642  tools::msg_writer() << epee::string_tools::get_ip_string_from_int32(i->ip) << " banned for " << i->seconds << " seconds";
1643  }
1644 
1645  return true;
1646 }
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)
std::string get_ip_string_from_int32(uint32_t ip)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_block_by_hash()

bool daemonize::t_rpc_command_executor::print_block_by_hash ( crypto::hash  block_hash,
bool  include_hex 
)

Definition at line 819 of file rpc_command_executor.cpp.

819  {
822  epee::json_rpc::error error_resp;
823 
824  req.hash = epee::string_tools::pod_to_hex(block_hash);
825  req.fill_pow_hash = true;
826 
827  std::string fail_message = "Unsuccessful";
828 
829  if (m_is_rpc)
830  {
831  if (!m_rpc_client->json_rpc_request(req, res, "getblock", fail_message.c_str()))
832  {
833  return true;
834  }
835  }
836  else
837  {
838  if (!m_rpc_server->on_get_block(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
839  {
840  tools::fail_msg_writer() << make_error(fail_message, res.status);
841  return true;
842  }
843  }
844 
845  if (include_hex)
846  tools::success_msg_writer() << res.blob << std::endl;
847  print_block_header(res.block_header);
848  tools::success_msg_writer() << res.json << ENDL;
849 
850  return true;
851 }
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)
#define ENDL
Definition: misc_log_ex.h:149
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_block_by_height()

bool daemonize::t_rpc_command_executor::print_block_by_height ( uint64_t  height,
bool  include_hex 
)

Definition at line 853 of file rpc_command_executor.cpp.

853  {
856  epee::json_rpc::error error_resp;
857 
858  req.height = height;
859  req.fill_pow_hash = true;
860 
861  std::string fail_message = "Unsuccessful";
862 
863  if (m_is_rpc)
864  {
865  if (!m_rpc_client->json_rpc_request(req, res, "getblock", fail_message.c_str()))
866  {
867  return true;
868  }
869  }
870  else
871  {
872  if (!m_rpc_server->on_get_block(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
873  {
874  tools::fail_msg_writer() << make_error(fail_message, res.status);
875  return true;
876  }
877  }
878 
879  if (include_hex)
880  tools::success_msg_writer() << res.blob << std::endl;
881  print_block_header(res.block_header);
882  tools::success_msg_writer() << res.json << ENDL;
883 
884  return true;
885 }
uint64_t height
Definition: blockchain.cpp:91
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_blockchain_dynamic_stats()

bool daemonize::t_rpc_command_executor::print_blockchain_dynamic_stats ( uint64_t  nblocks)

Definition at line 1890 of file rpc_command_executor.cpp.

1891 {
1900  epee::json_rpc::error error_resp;
1901 
1902  std::string fail_message = "Problem fetching info";
1903 
1904  fereq.grace_blocks = 0;
1905  hfreq.version = HF_VERSION_PER_BYTE_FEE;
1906  if (m_is_rpc)
1907  {
1908  if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
1909  {
1910  return true;
1911  }
1912  if (!m_rpc_client->json_rpc_request(fereq, feres, "get_fee_estimate", fail_message.c_str()))
1913  {
1914  return true;
1915  }
1916  if (!m_rpc_client->json_rpc_request(hfreq, hfres, "hard_fork_info", fail_message.c_str()))
1917  {
1918  return true;
1919  }
1920  }
1921  else
1922  {
1923  if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
1924  {
1925  tools::fail_msg_writer() << make_error(fail_message, ires.status);
1926  return true;
1927  }
1928  if (!m_rpc_server->on_get_base_fee_estimate(fereq, feres, error_resp) || feres.status != CORE_RPC_STATUS_OK)
1929  {
1930  tools::fail_msg_writer() << make_error(fail_message, feres.status);
1931  return true;
1932  }
1933  if (!m_rpc_server->on_hard_fork_info(hfreq, hfres, error_resp) || hfres.status != CORE_RPC_STATUS_OK)
1934  {
1935  tools::fail_msg_writer() << make_error(fail_message, hfres.status);
1936  return true;
1937  }
1938  }
1939 
1940  tools::msg_writer() << "Height: " << ires.height << ", diff " << ires.difficulty << ", cum. diff " << ires.cumulative_difficulty
1941  << ", target " << ires.target << " sec" << ", dyn fee " << cryptonote::print_etn(feres.fee) << "/" << (hfres.enabled ? "byte" : "kB");
1942 
1943  if (nblocks > 0)
1944  {
1945  if (nblocks > ires.height)
1946  nblocks = ires.height;
1947 
1948  bhreq.start_height = ires.height - nblocks;
1949  bhreq.end_height = ires.height - 1;
1950  bhreq.fill_pow_hash = false;
1951  if (m_is_rpc)
1952  {
1953  if (!m_rpc_client->json_rpc_request(bhreq, bhres, "getblockheadersrange", fail_message.c_str()))
1954  {
1955  return true;
1956  }
1957  }
1958  else
1959  {
1960  if (!m_rpc_server->on_get_block_headers_range(bhreq, bhres, error_resp) || bhres.status != CORE_RPC_STATUS_OK)
1961  {
1962  tools::fail_msg_writer() << make_error(fail_message, bhres.status);
1963  return true;
1964  }
1965  }
1966 
1967  double avgdiff = 0;
1968  double avgnumtxes = 0;
1969  double avgreward = 0;
1970  std::vector<uint64_t> weights;
1971  weights.reserve(nblocks);
1972  uint64_t earliest = std::numeric_limits<uint64_t>::max(), latest = 0;
1973  std::vector<unsigned> major_versions(256, 0), minor_versions(256, 0);
1974  for (const auto &bhr: bhres.headers)
1975  {
1976  avgdiff += bhr.difficulty;
1977  avgnumtxes += bhr.num_txes;
1978  avgreward += bhr.reward;
1979  weights.push_back(bhr.block_weight);
1980  static_assert(sizeof(bhr.major_version) == 1, "major_version expected to be uint8_t");
1981  static_assert(sizeof(bhr.minor_version) == 1, "major_version expected to be uint8_t");
1982  major_versions[(unsigned)bhr.major_version]++;
1983  minor_versions[(unsigned)bhr.minor_version]++;
1984  earliest = std::min(earliest, bhr.timestamp);
1985  latest = std::max(latest, bhr.timestamp);
1986  }
1987  avgdiff /= nblocks;
1988  avgnumtxes /= nblocks;
1989  avgreward /= nblocks;
1990  uint64_t median_block_weight = epee::misc_utils::median(weights);
1991  tools::msg_writer() << "Last " << nblocks << ": avg. diff " << (uint64_t)avgdiff << ", " << (latest - earliest) / nblocks << " avg sec/block, avg num txes " << avgnumtxes
1992  << ", avg. reward " << cryptonote::print_etn(avgreward) << ", median block weight " << median_block_weight;
1993 
1994  unsigned int max_major = 256, max_minor = 256;
1995  while (max_major > 0 && !major_versions[--max_major]);
1996  while (max_minor > 0 && !minor_versions[--max_minor]);
1997  std::string s = "";
1998  for (unsigned n = 0; n <= max_major; ++n)
1999  if (major_versions[n])
2000  s += (s.empty() ? "" : ", ") + boost::lexical_cast<std::string>(major_versions[n]) + std::string(" v") + boost::lexical_cast<std::string>(n);
2001  tools::msg_writer() << "Block versions: " << s;
2002  s = "";
2003  for (unsigned n = 0; n <= max_minor; ++n)
2004  if (minor_versions[n])
2005  s += (s.empty() ? "" : ", ") + boost::lexical_cast<std::string>(minor_versions[n]) + std::string(" v") + boost::lexical_cast<std::string>(n);
2006  tools::msg_writer() << "Voting for: " << s;
2007  }
2008  return true;
2009 }
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_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)
#define HF_VERSION_PER_BYTE_FEE
type_vec_type median(std::vector< type_vec_type > &v)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_blockchain_info()

bool daemonize::t_rpc_command_executor::print_blockchain_info ( uint64_t  start_block_index,
uint64_t  end_block_index 
)

Definition at line 692 of file rpc_command_executor.cpp.

692  {
695  epee::json_rpc::error error_resp;
696 
697  req.start_height = start_block_index;
698  req.end_height = end_block_index;
699  req.fill_pow_hash = false;
700 
701  std::string fail_message = "Unsuccessful";
702 
703  if (m_is_rpc)
704  {
705  if (!m_rpc_client->json_rpc_request(req, res, "getblockheadersrange", fail_message.c_str()))
706  {
707  return true;
708  }
709  }
710  else
711  {
712  if (!m_rpc_server->on_get_block_headers_range(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
713  {
714  tools::fail_msg_writer() << make_error(fail_message, res.status);
715  return true;
716  }
717  }
718 
719  bool first = true;
720  for (auto & header : res.headers)
721  {
722  if (!first)
723  tools::msg_writer() << "" << std::endl;
725  << "height: " << header.height << ", timestamp: " << header.timestamp << " (" << tools::get_human_readable_timestamp(header.timestamp) << ")"
726  << ", size: " << header.block_size << ", weight: " << header.block_weight << " (long term " << header.long_term_weight << "), transactions: " << header.num_txes << std::endl
727  << "major version: " << (unsigned)header.major_version << ", minor version: " << (unsigned)header.minor_version << std::endl
728  << "block id: " << header.hash << ", previous block id: " << header.prev_hash << std::endl
729  << "difficulty: " << header.difficulty << ", nonce " << header.nonce << ", reward " << cryptonote::print_etn(header.reward) << std::endl;
730  first = false;
731  }
732 
733  return true;
734 }
std::string get_human_readable_timestamp(uint64_t ts)
Definition: util.cpp:1077
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_coinbase_tx_sum()

bool daemonize::t_rpc_command_executor::print_coinbase_tx_sum ( uint64_t  height,
uint64_t  count 
)

Definition at line 1790 of file rpc_command_executor.cpp.

1791 {
1794  epee::json_rpc::error error_resp;
1795 
1796  req.height = height;
1797  req.count = count;
1798 
1799  std::string fail_message = "Unsuccessful";
1800 
1801  if (m_is_rpc)
1802  {
1803  if (!m_rpc_client->json_rpc_request(req, res, "get_coinbase_tx_sum", fail_message.c_str()))
1804  {
1805  return true;
1806  }
1807  }
1808  else
1809  {
1810  if (!m_rpc_server->on_get_coinbase_tx_sum(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1811  {
1812  tools::fail_msg_writer() << make_error(fail_message, res.status);
1813  return true;
1814  }
1815  }
1816 
1817  tools::msg_writer() << "Sum of coinbase transactions between block heights ["
1818  << height << ", " << (height + count) << ") is "
1819  << cryptonote::print_etn(res.emission_amount + res.fee_amount) << " "
1820  << "consisting of " << cryptonote::print_etn(res.emission_amount)
1821  << " in emissions, and " << cryptonote::print_etn(res.fee_amount) << " in fees";
1822  return true;
1823 }
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)
mdb_size_t count(MDB_cursor *cur)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_connections()

bool daemonize::t_rpc_command_executor::print_connections ( )

Definition at line 568 of file rpc_command_executor.cpp.

568  {
571  epee::json_rpc::error error_resp;
572 
573  std::string fail_message = "Unsuccessful";
574 
575  if (m_is_rpc)
576  {
577  if (!m_rpc_client->json_rpc_request(req, res, "get_connections", fail_message.c_str()))
578  {
579  return true;
580  }
581  }
582  else
583  {
584  if (!m_rpc_server->on_get_connections(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
585  {
586  tools::fail_msg_writer() << make_error(fail_message, res.status);
587  return true;
588  }
589  }
590 
591  tools::msg_writer() << std::setw(30) << std::left << "Remote Host"
592  << std::setw(6) << "SSL"
593  << std::setw(20) << "Peer id"
594  << std::setw(20) << "Support Flags"
595  << std::setw(30) << "Recv/Sent (inactive,sec)"
596  << std::setw(25) << "State"
597  << std::setw(20) << "Livetime(sec)"
598  << std::setw(12) << "Down (kB/s)"
599  << std::setw(14) << "Down(now)"
600  << std::setw(10) << "Up (kB/s)"
601  << std::setw(13) << "Up(now)"
602  << std::endl;
603 
604  for (auto & info : res.connections)
605  {
606  std::string address = info.incoming ? "INC " : "OUT ";
607  address += info.ip + ":" + info.port;
608  //std::string in_out = info.incoming ? "INC " : "OUT ";
610  //<< std::setw(30) << std::left << in_out
611  << std::setw(30) << std::left << address
612  << std::setw(6) << (info.ssl ? "yes" : "no")
613  << std::setw(20) << epee::string_tools::pad_string(info.peer_id, 16, '0', true)
614  << std::setw(20) << info.support_flags
615  << std::setw(30) << std::to_string(info.recv_count) + "(" + std::to_string(info.recv_idle_time) + ")/" + std::to_string(info.send_count) + "(" + std::to_string(info.send_idle_time) + ")"
616  << std::setw(25) << info.state
617  << std::setw(20) << info.live_time
618  << std::setw(12) << info.avg_download
619  << std::setw(14) << info.current_download
620  << std::setw(10) << info.avg_upload
621  << std::setw(13) << info.current_upload
622 
623  << std::left << (info.localhost ? "[LOCALHOST]" : "")
624  << std::left << (info.local_ip ? "[LAN]" : "");
625  //tools::msg_writer() << boost::format("%-25s peer_id: %-25s %s") % address % info.peer_id % in_out;
626 
627  }
628 
629  return true;
630 }
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)
std::string to_string(t_connection_type type)
std::string pad_string(std::string s, size_t n, char c=' ', bool prepend=false)
Definition: string_tools.h:304
const char * address
Definition: multisig.cpp:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_height()

bool daemonize::t_rpc_command_executor::print_height ( )

Definition at line 792 of file rpc_command_executor.cpp.

792  {
795 
796  std::string fail_message = "Unsuccessful";
797 
798  if (m_is_rpc)
799  {
800  if (!m_rpc_client->rpc_request(req, res, "/getheight", fail_message.c_str()))
801  {
802  return true;
803  }
804  }
805  else
806  {
807  if (!m_rpc_server->on_get_height(req, res) || res.status != CORE_RPC_STATUS_OK)
808  {
809  tools::fail_msg_writer() << make_error(fail_message, res.status);
810  return true;
811  }
812  }
813 
814  tools::success_msg_writer() << boost::lexical_cast<std::string>(res.height);
815 
816  return true;
817 }
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request &req, COMMAND_RPC_GET_HEIGHT::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_net_stats()

bool daemonize::t_rpc_command_executor::print_net_stats ( )

Definition at line 632 of file rpc_command_executor.cpp.

633 {
638 
639  std::string fail_message = "Unsuccessful";
640 
641  if (m_is_rpc)
642  {
643  if (!m_rpc_client->json_rpc_request(net_stats_req, net_stats_res, "get_net_stats", fail_message.c_str()))
644  {
645  return true;
646  }
647  if (!m_rpc_client->json_rpc_request(limit_req, limit_res, "get_limit", fail_message.c_str()))
648  {
649  return true;
650  }
651  }
652  else
653  {
654  if (!m_rpc_server->on_get_net_stats(net_stats_req, net_stats_res) || net_stats_res.status != CORE_RPC_STATUS_OK)
655  {
656  tools::fail_msg_writer() << make_error(fail_message, net_stats_res.status);
657  return true;
658  }
659  if (!m_rpc_server->on_get_limit(limit_req, limit_res) || limit_res.status != CORE_RPC_STATUS_OK)
660  {
661  tools::fail_msg_writer() << make_error(fail_message, limit_res.status);
662  return true;
663  }
664  }
665 
666  uint64_t seconds = (uint64_t)time(NULL) - net_stats_res.start_time;
667  uint64_t average = seconds > 0 ? net_stats_res.total_bytes_in / seconds : 0;
668  uint64_t limit = limit_res.limit_down * 1024; // convert to bytes, as limits are always kB/s
669  double percent = (double)average / (double)limit * 100.0;
670  tools::success_msg_writer() << boost::format("Received %u bytes (%s) in %u packets, average %s/s = %.2f%% of the limit of %s/s")
671  % net_stats_res.total_bytes_in
672  % tools::get_human_readable_bytes(net_stats_res.total_bytes_in)
673  % net_stats_res.total_packets_in
675  % percent
677 
678  average = seconds > 0 ? net_stats_res.total_bytes_out / seconds : 0;
679  limit = limit_res.limit_up * 1024;
680  percent = (double)average / (double)limit * 100.0;
681  tools::success_msg_writer() << boost::format("Sent %u bytes (%s) in %u packets, average %s/s = %.2f%% of the limit of %s/s")
682  % net_stats_res.total_bytes_out
683  % tools::get_human_readable_bytes(net_stats_res.total_bytes_out)
684  % net_stats_res.total_packets_out
686  % percent
688 
689  return true;
690 }
time_t time
Definition: blockchain.cpp:93
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)
std::string get_human_readable_bytes(uint64_t bytes)
Definition: util.cpp:1089
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_peer_list()

bool daemonize::t_rpc_command_executor::print_peer_list ( bool  white = true,
bool  gray = true,
size_t  limit = 0 
)

Definition at line 163 of file rpc_command_executor.cpp.

163  {
166 
167  std::string failure_message = "Couldn't retrieve peer list";
168  if (m_is_rpc)
169  {
170  if (!m_rpc_client->rpc_request(req, res, "/get_peer_list", failure_message.c_str()))
171  {
172  return false;
173  }
174  }
175  else
176  {
177  if (!m_rpc_server->on_get_peer_list(req, res) || res.status != CORE_RPC_STATUS_OK)
178  {
179  tools::fail_msg_writer() << failure_message;
180  return false;
181  }
182  }
183 
184  if (white)
185  {
186  auto peer = res.white_list.cbegin();
187  const auto end = limit ? peer + std::min(limit, res.white_list.size()) : res.white_list.cend();
188  for (; peer != end; ++peer)
189  {
190  print_peer("white", *peer);
191  }
192  }
193 
194  if (gray)
195  {
196  auto peer = res.gray_list.cbegin();
197  const auto end = limit ? peer + std::min(limit, res.gray_list.size()) : res.gray_list.cend();
198  for (; peer != end; ++peer)
199  {
200  print_peer("gray", *peer);
201  }
202  }
203 
204  return true;
205 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_peer_list_stats()

bool daemonize::t_rpc_command_executor::print_peer_list_stats ( )

Definition at line 207 of file rpc_command_executor.cpp.

207  {
210 
211  std::string failure_message = "Couldn't retrieve peer list";
212  if (m_is_rpc)
213  {
214  if (!m_rpc_client->rpc_request(req, res, "/get_peer_list", failure_message.c_str()))
215  {
216  return false;
217  }
218  }
219  else
220  {
221  if (!m_rpc_server->on_get_peer_list(req, res) || res.status != CORE_RPC_STATUS_OK)
222  {
223  tools::fail_msg_writer() << failure_message;
224  return false;
225  }
226  }
227 
229  << "White list size: " << res.white_list.size() << "/" << P2P_LOCAL_WHITE_PEERLIST_LIMIT << " (" << res.white_list.size() * 100.0 / P2P_LOCAL_WHITE_PEERLIST_LIMIT << "%)" << std::endl
230  << "Gray list size: " << res.gray_list.size() << "/" << P2P_LOCAL_GRAY_PEERLIST_LIMIT << " (" << res.gray_list.size() * 100.0 / P2P_LOCAL_GRAY_PEERLIST_LIMIT << "%)";
231 
232  return true;
233 }
#define P2P_LOCAL_GRAY_PEERLIST_LIMIT
#define P2P_LOCAL_WHITE_PEERLIST_LIMIT
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_status()

bool daemonize::t_rpc_command_executor::print_status ( )

Definition at line 1334 of file rpc_command_executor.cpp.

1335 {
1336  if (!m_is_rpc)
1337  {
1338  tools::success_msg_writer() << "print_status makes no sense in interactive mode";
1339  return true;
1340  }
1341 
1342  bool daemon_is_alive = m_rpc_client->check_connection();
1343 
1344  if(daemon_is_alive) {
1345  tools::success_msg_writer() << "electroneumd is running";
1346  }
1347  else {
1348  tools::fail_msg_writer() << "electroneumd is NOT running";
1349  }
1350 
1351  return true;
1352 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_transaction()

bool daemonize::t_rpc_command_executor::print_transaction ( crypto::hash  transaction_hash,
bool  include_hex,
bool  include_json 
)

Definition at line 887 of file rpc_command_executor.cpp.

889  {
892 
893  std::string fail_message = "Problem fetching transaction";
894 
895  req.txs_hashes.push_back(epee::string_tools::pod_to_hex(transaction_hash));
896  req.decode_as_json = false;
897  req.split = true;
898  req.prune = false;
899  if (m_is_rpc)
900  {
901  if (!m_rpc_client->rpc_request(req, res, "/gettransactions", fail_message.c_str()))
902  {
903  return true;
904  }
905  }
906  else
907  {
908  if (!m_rpc_server->on_get_transactions(req, res) || res.status != CORE_RPC_STATUS_OK)
909  {
910  tools::fail_msg_writer() << make_error(fail_message, res.status);
911  return true;
912  }
913  }
914 
915  if (1 == res.txs.size() || 1 == res.txs_as_hex.size())
916  {
917  if (1 == res.txs.size())
918  {
919  // only available for new style answers
920  if (res.txs.front().in_pool)
921  tools::success_msg_writer() << "Found in pool";
922  else
923  tools::success_msg_writer() << "Found in blockchain at height " << res.txs.front().block_height << (res.txs.front().prunable_as_hex.empty() ? " (pruned)" : "");
924  }
925 
926  const std::string &as_hex = (1 == res.txs.size()) ? res.txs.front().as_hex : res.txs_as_hex.front();
927  const std::string &pruned_as_hex = (1 == res.txs.size()) ? res.txs.front().pruned_as_hex : "";
928  const std::string &prunable_as_hex = (1 == res.txs.size()) ? res.txs.front().prunable_as_hex : "";
929  // Print raw hex if requested
930  if (include_hex)
931  {
932  if (!as_hex.empty())
933  {
934  tools::success_msg_writer() << as_hex << std::endl;
935  }
936  else
937  {
938  std::string output = pruned_as_hex + prunable_as_hex;
939  tools::success_msg_writer() << output << std::endl;
940  }
941  }
942 
943  // Print json if requested
944  if (include_json)
945  {
946  crypto::hash tx_hash, tx_prefix_hash;
949  std::string source = as_hex.empty() ? pruned_as_hex + prunable_as_hex : as_hex;
950  bool pruned = !pruned_as_hex.empty() && prunable_as_hex.empty();
952  {
953  tools::fail_msg_writer() << "Failed to parse tx to get json format";
954  }
955  else
956  {
957  bool ret;
958  if (pruned)
960  else
962  if (!ret)
963  {
964  tools::fail_msg_writer() << "Failed to parse tx blob to get json format";
965  }
966  else
967  {
969  }
970  }
971  }
972  }
973  else
974  {
975  tools::fail_msg_writer() << "Transaction wasn't found: " << transaction_hash << std::endl;
976  }
977 
978  return true;
979 }
bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request &req, COMMAND_RPC_GET_TRANSACTIONS::response &res, const connection_context *ctx=NULL)
POD_CLASS hash
Definition: hash.h:50
std::string obj_to_json_str(T &obj)
std::string blobdata
Definition: blobdatatype.h:39
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
bool parse_and_validate_tx_base_from_blob(const blobdata &tx_blob, transaction &tx)
bool parse_hexstr_to_binbuff(const epee::span< const char > s, epee::span< char > &res)
Definition: string_tools.h:92
const CharType(& source)[N]
Definition: pointer.h:1147
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_transaction_pool_long()

bool daemonize::t_rpc_command_executor::print_transaction_pool_long ( )

Definition at line 1017 of file rpc_command_executor.cpp.

1017  {
1020 
1021  std::string fail_message = "Problem fetching transaction pool";
1022 
1023  if (m_is_rpc)
1024  {
1025  if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool", fail_message.c_str()))
1026  {
1027  return true;
1028  }
1029  }
1030  else
1031  {
1032  if (!m_rpc_server->on_get_transaction_pool(req, res) || res.status != CORE_RPC_STATUS_OK)
1033  {
1034  tools::fail_msg_writer() << make_error(fail_message, res.status);
1035  return true;
1036  }
1037  }
1038 
1039  if (res.transactions.empty() && res.spent_key_images.empty())
1040  {
1041  tools::msg_writer() << "Pool is empty" << std::endl;
1042  }
1043  if (! res.transactions.empty())
1044  {
1045  const time_t now = time(NULL);
1046  tools::msg_writer() << "Transactions: ";
1047  for (auto & tx_info : res.transactions)
1048  {
1049  tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
1050  << tx_info.tx_json << std::endl
1051  << "blob_size: " << tx_info.blob_size << std::endl
1052  << "weight: " << tx_info.weight << std::endl
1053  << "fee: " << cryptonote::print_etn(tx_info.fee) << std::endl
1054  << "fee/byte: " << cryptonote::print_etn(tx_info.fee / (double)tx_info.weight) << std::endl
1055  << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
1056  << "relayed: " << [&](const cryptonote::tx_info &tx_info)->std::string { if (!tx_info.relayed) return "no"; return boost::lexical_cast<std::string>(tx_info.last_relayed_time) + " (" + get_human_time_ago(tx_info.last_relayed_time, now) + ")"; } (tx_info) << std::endl
1057  << "do_not_relay: " << (tx_info.do_not_relay ? 'T' : 'F') << std::endl
1058  << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
1059  << "double_spend_seen: " << (tx_info.double_spend_seen ? 'T' : 'F') << std::endl
1060  << "nonexistent_utxo_seen: " << (tx_info.nonexistent_utxo_seen ? 'T' : 'F') << std::endl
1061  << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
1062  << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
1063  << "last_failed_height: " << tx_info.last_failed_height << std::endl
1064  << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
1065  }
1066  }
1067  if (! res.spent_key_images.empty())
1068  {
1069  tools::msg_writer() << ""; // one newline
1070  tools::msg_writer() << "Spent key images: ";
1071  for (const cryptonote::spent_key_image_info& kinfo : res.spent_key_images)
1072  {
1073  tools::msg_writer() << "key image: " << kinfo.id_hash;
1074  if (kinfo.txs_hashes.size() == 1)
1075  {
1076  tools::msg_writer() << " tx: " << kinfo.txs_hashes[0];
1077  }
1078  else if (kinfo.txs_hashes.size() == 0)
1079  {
1080  tools::msg_writer() << " WARNING: spent key image has no txs associated";
1081  }
1082  else
1083  {
1084  tools::msg_writer() << " NOTE: key image for multiple txs: " << kinfo.txs_hashes.size();
1085  for (const std::string& tx_id : kinfo.txs_hashes)
1086  {
1087  tools::msg_writer() << " tx: " << tx_id;
1088  }
1089  }
1090  }
1091  if (res.transactions.empty())
1092  {
1093  tools::msg_writer() << "WARNING: Inconsistent pool state - no transactions";
1094  }
1095  }
1096 
1097  return true;
1098 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_transaction_pool_short()

bool daemonize::t_rpc_command_executor::print_transaction_pool_short ( )

Definition at line 1100 of file rpc_command_executor.cpp.

1100  {
1103 
1104  std::string fail_message = "Problem fetching transaction pool";
1105 
1106  if (m_is_rpc)
1107  {
1108  if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool", fail_message.c_str()))
1109  {
1110  return true;
1111  }
1112  }
1113  else
1114  {
1115  if (!m_rpc_server->on_get_transaction_pool(req, res) || res.status != CORE_RPC_STATUS_OK)
1116  {
1117  tools::fail_msg_writer() << make_error(fail_message, res.status);
1118  return true;
1119  }
1120  }
1121 
1122  if (res.transactions.empty())
1123  {
1124  tools::msg_writer() << "Pool is empty" << std::endl;
1125  }
1126  else
1127  {
1128  const time_t now = time(NULL);
1129  for (auto & tx_info : res.transactions)
1130  {
1131  tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
1132  << "blob_size: " << tx_info.blob_size << std::endl
1133  << "weight: " << tx_info.weight << std::endl
1134  << "fee: " << cryptonote::print_etn(tx_info.fee) << std::endl
1135  << "fee/byte: " << cryptonote::print_etn(tx_info.fee / (double)tx_info.weight) << std::endl
1136  << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
1137  << "relayed: " << [&](const cryptonote::tx_info &tx_info)->std::string { if (!tx_info.relayed) return "no"; return boost::lexical_cast<std::string>(tx_info.last_relayed_time) + " (" + get_human_time_ago(tx_info.last_relayed_time, now) + ")"; } (tx_info) << std::endl
1138  << "do_not_relay: " << (tx_info.do_not_relay ? 'T' : 'F') << std::endl
1139  << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
1140  << "double_spend_seen: " << (tx_info.double_spend_seen ? 'T' : 'F') << std::endl
1141  << "nonexistent_utxo_seen: " << (tx_info.nonexistent_utxo_seen ? 'T' : 'F') << std::endl
1142  << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
1143  << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
1144  << "last_failed_height: " << tx_info.last_failed_height << std::endl
1145  << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
1146  }
1147  }
1148 
1149  return true;
1150 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_transaction_pool_stats()

bool daemonize::t_rpc_command_executor::print_transaction_pool_stats ( )

Definition at line 1152 of file rpc_command_executor.cpp.

1152  {
1157 
1158  std::string fail_message = "Problem fetching transaction pool stats";
1159 
1160  if (m_is_rpc)
1161  {
1162  if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool_stats", fail_message.c_str()))
1163  {
1164  return true;
1165  }
1166  if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
1167  {
1168  return true;
1169  }
1170  }
1171  else
1172  {
1173  res.pool_stats = {};
1174  if (!m_rpc_server->on_get_transaction_pool_stats(req, res) || res.status != CORE_RPC_STATUS_OK)
1175  {
1176  tools::fail_msg_writer() << make_error(fail_message, res.status);
1177  return true;
1178  }
1179  if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
1180  {
1181  tools::fail_msg_writer() << make_error(fail_message, ires.status);
1182  return true;
1183  }
1184  }
1185 
1186  size_t n_transactions = res.pool_stats.txs_total;
1187  const uint64_t now = time(NULL);
1188  size_t avg_bytes = n_transactions ? res.pool_stats.bytes_total / n_transactions : 0;
1189 
1190  std::string backlog_message;
1191  const uint64_t full_reward_zone = ires.block_weight_limit / 2;
1192  if (res.pool_stats.bytes_total <= full_reward_zone)
1193  {
1194  backlog_message = "no backlog";
1195  }
1196  else
1197  {
1198  uint64_t backlog = (res.pool_stats.bytes_total + full_reward_zone - 1) / full_reward_zone;
1199  backlog_message = (boost::format("estimated %u block (%u minutes) backlog") % backlog % (backlog * DIFFICULTY_TARGET_V6 / 60)).str();
1200  }
1201 
1202  tools::msg_writer() << n_transactions << " tx(es), " << res.pool_stats.bytes_total << " bytes total (min " << res.pool_stats.bytes_min << ", max " << res.pool_stats.bytes_max << ", avg " << avg_bytes << ", median " << res.pool_stats.bytes_med << ")" << std::endl
1203  << "fees " << cryptonote::print_etn(res.pool_stats.fee_total) << " (avg " << cryptonote::print_etn(n_transactions ? res.pool_stats.fee_total / n_transactions : 0) << " per tx" << ", " << cryptonote::print_etn(res.pool_stats.bytes_total ? res.pool_stats.fee_total / res.pool_stats.bytes_total : 0) << " per byte)" << std::endl
1204  << res.pool_stats.num_double_spends << " double spends, " << res.pool_stats.num_not_relayed << " not relayed, " << res.pool_stats.num_failing << " failing, " << res.pool_stats.num_10m << " older than 10 minutes (oldest " << (res.pool_stats.oldest == 0 ? "-" : get_human_time_ago(res.pool_stats.oldest, now)) << "), " << backlog_message;
1205 
1206  if (n_transactions > 1 && res.pool_stats.histo.size())
1207  {
1208  std::vector<uint64_t> times;
1209  uint64_t numer;
1210  size_t i, n = res.pool_stats.histo.size(), denom;
1211  times.resize(n);
1212  if (res.pool_stats.histo_98pc)
1213  {
1214  numer = res.pool_stats.histo_98pc;
1215  denom = n-1;
1216  for (i=0; i<denom; i++)
1217  times[i] = i * numer / denom;
1218  times[i] = now - res.pool_stats.oldest;
1219  } else
1220  {
1221  numer = now - res.pool_stats.oldest;
1222  denom = n;
1223  for (i=0; i<denom; i++)
1224  times[i] = i * numer / denom;
1225  }
1226  tools::msg_writer() << " Age Txes Bytes";
1227  for (i=0; i<n; i++)
1228  {
1229  tools::msg_writer() << get_time_hms(times[i]) << std::setw(8) << res.pool_stats.histo[i].txs << std::setw(12) << res.pool_stats.histo[i].bytes;
1230  }
1231  }
1233 
1234  return true;
1235 }
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)
#define DIFFICULTY_TARGET_V6
Here is the call graph for this function:
Here is the caller graph for this function:

◆ prune_blockchain()

bool daemonize::t_rpc_command_executor::prune_blockchain ( )

Definition at line 2211 of file rpc_command_executor.cpp.

2212 {
2215  std::string fail_message = "Unsuccessful";
2216  epee::json_rpc::error error_resp;
2217 
2218  req.check = false;
2219 
2220  if (m_is_rpc)
2221  {
2222  if (!m_rpc_client->json_rpc_request(req, res, "prune_blockchain", fail_message.c_str()))
2223  {
2224  return true;
2225  }
2226  }
2227  else
2228  {
2229  if (!m_rpc_server->on_prune_blockchain(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2230  {
2231  tools::fail_msg_writer() << make_error(fail_message, res.status);
2232  return true;
2233  }
2234  }
2235 
2236  tools::success_msg_writer() << "Blockchain pruned";
2237  return true;
2238 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ relay_tx()

bool daemonize::t_rpc_command_executor::relay_tx ( const std::string &  txid)

Definition at line 2063 of file rpc_command_executor.cpp.

2064 {
2067  std::string fail_message = "Unsuccessful";
2068  epee::json_rpc::error error_resp;
2069 
2070  req.txids.push_back(txid);
2071 
2072  if (m_is_rpc)
2073  {
2074  if (!m_rpc_client->json_rpc_request(req, res, "relay_tx", fail_message.c_str()))
2075  {
2076  return true;
2077  }
2078  }
2079  else
2080  {
2081  if (!m_rpc_server->on_relay_tx(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2082  {
2083  tools::fail_msg_writer() << make_error(fail_message, res.status);
2084  return true;
2085  }
2086  }
2087 
2088  tools::success_msg_writer() << "Transaction successfully relayed";
2089  return true;
2090 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_blockchain()

bool daemonize::t_rpc_command_executor::save_blockchain ( )

Definition at line 235 of file rpc_command_executor.cpp.

235  {
238 
239  std::string fail_message = "Couldn't save blockchain";
240 
241  if (m_is_rpc)
242  {
243  if (!m_rpc_client->rpc_request(req, res, "/save_bc", fail_message.c_str()))
244  {
245  return true;
246  }
247  }
248  else
249  {
250  if (!m_rpc_server->on_save_bc(req, res) || res.status != CORE_RPC_STATUS_OK)
251  {
252  tools::fail_msg_writer() << make_error(fail_message, res.status);
253  return true;
254  }
255  }
256 
257  tools::success_msg_writer() << "Blockchain saved";
258 
259  return true;
260 }
bool on_save_bc(const COMMAND_RPC_SAVE_BC::request &req, COMMAND_RPC_SAVE_BC::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_limit()

bool daemonize::t_rpc_command_executor::set_limit ( int64_t  limit_down,
int64_t  limit_up 
)

Definition at line 1382 of file rpc_command_executor.cpp.

1383 {
1386 
1387  req.limit_down = limit_down;
1388  req.limit_up = limit_up;
1389 
1390  std::string failure_message = "Couldn't set limit";
1391 
1392  if (m_is_rpc)
1393  {
1394  if (!m_rpc_client->rpc_request(req, res, "/set_limit", failure_message.c_str()))
1395  {
1396  return true;
1397  }
1398  }
1399  else
1400  {
1401  if (!m_rpc_server->on_set_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1402  {
1403  tools::fail_msg_writer() << make_error(failure_message, res.status);
1404  return true;
1405  }
1406  }
1407 
1408  tools::msg_writer() << "Set limit-down to " << res.limit_down << " kB/s";
1409  tools::msg_writer() << "Set limit-up to " << res.limit_up << " kB/s";
1410  return true;
1411 }
bool on_set_limit(const COMMAND_RPC_SET_LIMIT::request &req, COMMAND_RPC_SET_LIMIT::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_log_categories()

bool daemonize::t_rpc_command_executor::set_log_categories ( const std::string &  categories)

Definition at line 764 of file rpc_command_executor.cpp.

764  {
767  req.categories = categories;
768 
769  std::string fail_message = "Unsuccessful";
770 
771  if (m_is_rpc)
772  {
773  if (!m_rpc_client->rpc_request(req, res, "/set_log_categories", fail_message.c_str()))
774  {
775  return true;
776  }
777  }
778  else
779  {
780  if (!m_rpc_server->on_set_log_categories(req, res) || res.status != CORE_RPC_STATUS_OK)
781  {
782  tools::fail_msg_writer() << make_error(fail_message, res.status);
783  return true;
784  }
785  }
786 
787  tools::success_msg_writer() << "Log categories are now " << res.categories;
788 
789  return true;
790 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_log_level()

bool daemonize::t_rpc_command_executor::set_log_level ( int8_t  level)

Definition at line 736 of file rpc_command_executor.cpp.

736  {
739  req.level = level;
740 
741  std::string fail_message = "Unsuccessful";
742 
743  if (m_is_rpc)
744  {
745  if (!m_rpc_client->rpc_request(req, res, "/set_log_level", fail_message.c_str()))
746  {
747  return true;
748  }
749  }
750  else
751  {
752  if (!m_rpc_server->on_set_log_level(req, res) || res.status != CORE_RPC_STATUS_OK)
753  {
754  tools::fail_msg_writer() << make_error(fail_message, res.status);
755  return true;
756  }
757  }
758 
759  tools::success_msg_writer() << "Log level is now " << std::to_string(level);
760 
761  return true;
762 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_validator_key()

bool daemonize::t_rpc_command_executor::set_validator_key ( const std::string &  key)

Definition at line 2187 of file rpc_command_executor.cpp.

2187  {
2190  std::string fail_message = "Unsuccessful";
2191  epee::json_rpc::error error_resp;
2192 
2193  req.validator_key = key;
2194 
2195  if (m_is_rpc) {
2196  if (!m_rpc_client->json_rpc_request(req, res, "set_validator_key", fail_message.c_str())) {
2197  return true;
2198  }
2199  } else {
2200  if (!m_rpc_server->on_set_validator_key(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2201  {
2202  tools::fail_msg_writer() << make_error(fail_message, res.status);
2203  return true;
2204  }
2205  }
2206 
2207  tools::success_msg_writer() << "Validator Key successfully set";
2208  return true;
2209 }
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)
const char * key
Definition: hmac_keccak.cpp:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ show_difficulty()

bool daemonize::t_rpc_command_executor::show_difficulty ( )

Definition at line 317 of file rpc_command_executor.cpp.

317  {
320 
321  std::string fail_message = "Problem fetching info";
322 
323  if (m_is_rpc)
324  {
325  if (!m_rpc_client->rpc_request(req, res, "/getinfo", fail_message.c_str()))
326  {
327  return true;
328  }
329  }
330  else
331  {
332  if (!m_rpc_server->on_get_info(req, res) || res.status != CORE_RPC_STATUS_OK)
333  {
334  tools::fail_msg_writer() << make_error(fail_message.c_str(), res.status);
335  return true;
336  }
337  }
338 
339  tools::success_msg_writer() << "BH: " << res.height
340  << ", TH: " << res.top_block_hash
341  << ", DIFF: " << res.difficulty
342  << ", HR: " << res.difficulty / res.target << " H/s";
343 
344  return true;
345 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ show_hash_rate()

bool daemonize::t_rpc_command_executor::show_hash_rate ( )

Definition at line 262 of file rpc_command_executor.cpp.

262  {
265  req.visible = true;
266 
267  std::string fail_message = "Unsuccessful";
268 
269  if (m_is_rpc)
270  {
271  if (!m_rpc_client->rpc_request(req, res, "/set_log_hash_rate", fail_message.c_str()))
272  {
273  return true;
274  }
275  }
276  else
277  {
278  if (!m_rpc_server->on_set_log_hash_rate(req, res) || res.status != CORE_RPC_STATUS_OK)
279  {
280  tools::fail_msg_writer() << make_error(fail_message, res.status);
281  }
282  }
283 
284  tools::success_msg_writer() << "Hash rate logging is on";
285 
286  return true;
287 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ show_status()

bool daemonize::t_rpc_command_executor::show_status ( )

Definition at line 389 of file rpc_command_executor.cpp.

389  {
396  epee::json_rpc::error error_resp;
397  bool has_mining_info = true;
398 
399  std::string fail_message = "Problem fetching info";
400 
401  hfreq.version = 0;
402  bool mining_busy = false;
403  if (m_is_rpc)
404  {
405  if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
406  {
407  return true;
408  }
409  if (!m_rpc_client->json_rpc_request(hfreq, hfres, "hard_fork_info", fail_message.c_str()))
410  {
411  return true;
412  }
413  // mining info is only available non unrestricted RPC mode
414  has_mining_info = m_rpc_client->rpc_request(mreq, mres, "/mining_status", fail_message.c_str());
415  }
416  else
417  {
418  if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
419  {
420  tools::fail_msg_writer() << make_error(fail_message, ires.status);
421  return true;
422  }
423  if (!m_rpc_server->on_hard_fork_info(hfreq, hfres, error_resp) || hfres.status != CORE_RPC_STATUS_OK)
424  {
425  tools::fail_msg_writer() << make_error(fail_message, hfres.status);
426  return true;
427  }
428  if (!m_rpc_server->on_mining_status(mreq, mres))
429  {
430  tools::fail_msg_writer() << fail_message.c_str();
431  return true;
432  }
433 
434  if (mres.status == CORE_RPC_STATUS_BUSY)
435  {
436  mining_busy = true;
437  }
438  else if (mres.status != CORE_RPC_STATUS_OK)
439  {
440  tools::fail_msg_writer() << make_error(fail_message, mres.status);
441  return true;
442  }
443  }
444 
445  std::time_t uptime = std::time(nullptr) - ires.start_time;
446  uint64_t net_height = ires.target_height > ires.height ? ires.target_height : ires.height;
447  std::string bootstrap_msg;
448  if (ires.was_bootstrap_ever_used)
449  {
450  bootstrap_msg = ", bootstrapping from " + ires.bootstrap_daemon_address;
451  if (ires.untrusted)
452  {
453  bootstrap_msg += (boost::format(", local height: %llu (%.1f%%)") % ires.height_without_bootstrap % get_sync_percentage(ires.height_without_bootstrap, net_height)).str();
454  }
455  else
456  {
457  bootstrap_msg += " was used before";
458  }
459  }
460 
461  std::stringstream str;
462  str << boost::format("Height: %llu/%llu (%.1f%%) on %s%s, %s, net hash %s, v%u%s, %u(out)+%u(in) connections")
463  % (unsigned long long)ires.height
464  % (unsigned long long)net_height
465  % get_sync_percentage(ires)
466  % (ires.testnet ? "testnet" : ires.stagenet ? "stagenet" : "mainnet")
467  % bootstrap_msg
468  % (!has_mining_info ? "mining info unavailable" : mining_busy ? "syncing" : mres.active ? ( ( mres.is_background_mining_enabled ? "smart " : "" ) + std::string("mining at ") + get_mining_speed(mres.speed)) : "not mining")
469  % get_mining_speed(ires.difficulty / ires.target)
470  % (unsigned)hfres.version
471  % get_fork_extra_info(hfres.earliest_height, net_height, ires.target)
472  % (unsigned)ires.outgoing_connections_count
473  % (unsigned)ires.incoming_connections_count
474  ;
475 
476  // restricted RPC does not disclose start time
477  if (ires.start_time)
478  {
479  str << boost::format(", uptime %ud %uh %um %us")
480  % (unsigned int)floor(uptime / 60.0 / 60.0 / 24.0)
481  % (unsigned int)floor(fmod((uptime / 60.0 / 60.0), 24.0))
482  % (unsigned int)floor(fmod((uptime / 60.0), 60.0))
483  % (unsigned int)fmod(uptime, 60.0)
484  ;
485  }
486 
487  tools::success_msg_writer() << str.str();
488 
489  return true;
490 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sign_message()

bool daemonize::t_rpc_command_executor::sign_message ( const std::string  privateKey,
const std::string  message 
)

Definition at line 2299 of file rpc_command_executor.cpp.

2299  {
2302  std::string fail_message = "Unsuccessful";
2303  epee::json_rpc::error error_resp;
2304 
2305  req.privateKey = privateKey;
2306  req.message = message;
2307 
2308  if (m_is_rpc) {
2309  if (!m_rpc_client->json_rpc_request(req, res, "sign_message", fail_message.c_str())) {
2310  return true;
2311  }
2312  } else {
2313  if (!m_rpc_server->on_sign_message(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2314  {
2315  tools::fail_msg_writer() << make_error(fail_message, res.status);
2316  return true;
2317  }
2318  }
2319 
2320  tools::success_msg_writer() << "Signature: " << res.signature;
2321  return true;
2322 }
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)
std::string privateKey
std::string message("Message requiring signing")
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_mining()

bool daemonize::t_rpc_command_executor::start_mining ( cryptonote::account_public_address  address,
uint64_t  num_threads,
cryptonote::network_type  nettype,
bool  do_background_mining = false,
bool  ignore_battery = false 
)

Definition at line 1237 of file rpc_command_executor.cpp.

1237  {
1240  req.miner_address = cryptonote::get_account_address_as_str(nettype, false, address);
1241  req.threads_count = num_threads;
1242  req.do_background_mining = do_background_mining;
1243  req.ignore_battery = ignore_battery;
1244 
1245  std::string fail_message = "Mining did not start";
1246 
1247  if (m_is_rpc)
1248  {
1249  if (m_rpc_client->rpc_request(req, res, "/start_mining", fail_message.c_str()))
1250  {
1251  tools::success_msg_writer() << "Mining started";
1252  }
1253  }
1254  else
1255  {
1256  if (!m_rpc_server->on_start_mining(req, res) || res.status != CORE_RPC_STATUS_OK)
1257  {
1258  tools::fail_msg_writer() << make_error(fail_message, res.status);
1259  return true;
1260  }
1261  }
1262 
1263  return true;
1264 }
bool on_start_mining(const COMMAND_RPC_START_MINING::request &req, COMMAND_RPC_START_MINING::response &res, const connection_context *ctx=NULL)
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_save_graph()

bool daemonize::t_rpc_command_executor::start_save_graph ( )

Definition at line 1531 of file rpc_command_executor.cpp.

1532 {
1535  std::string fail_message = "Unsuccessful";
1536 
1537  if (m_is_rpc)
1538  {
1539  if (!m_rpc_client->rpc_request(req, res, "/start_save_graph", fail_message.c_str()))
1540  {
1541  return true;
1542  }
1543  }
1544 
1545  else
1546  {
1547  if (!m_rpc_server->on_start_save_graph(req, res) || res.status != CORE_RPC_STATUS_OK)
1548  {
1549  tools::fail_msg_writer() << make_error(fail_message, res.status);
1550  return true;
1551  }
1552  }
1553 
1554  tools::success_msg_writer() << "Saving graph is now on";
1555  return true;
1556 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_daemon()

bool daemonize::t_rpc_command_executor::stop_daemon ( )

Definition at line 1292 of file rpc_command_executor.cpp.

1293 {
1296 
1297 //# ifdef WIN32
1298 // // Stop via service API
1299 // // TODO - this is only temporary! Get rid of hard-coded constants!
1300 // bool ok = windows::stop_service("Electroneum Daemon");
1301 // ok = windows::uninstall_service("Electroneum Daemon");
1302 // //bool ok = windows::stop_service(SERVICE_NAME);
1303 // //ok = windows::uninstall_service(SERVICE_NAME);
1304 // if (ok)
1305 // {
1306 // return true;
1307 // }
1308 //# endif
1309 
1310  // Stop via RPC
1311  std::string fail_message = "Daemon did not stop";
1312 
1313  if (m_is_rpc)
1314  {
1315  if(!m_rpc_client->rpc_request(req, res, "/stop_daemon", fail_message.c_str()))
1316  {
1317  return true;
1318  }
1319  }
1320  else
1321  {
1322  if (!m_rpc_server->on_stop_daemon(req, res) || res.status != CORE_RPC_STATUS_OK)
1323  {
1324  tools::fail_msg_writer() << make_error(fail_message, res.status);
1325  return true;
1326  }
1327  }
1328 
1329  tools::success_msg_writer() << "Stop signal sent";
1330 
1331  return true;
1332 }
bool on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request &req, COMMAND_RPC_STOP_DAEMON::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_mining()

bool daemonize::t_rpc_command_executor::stop_mining ( )

Definition at line 1266 of file rpc_command_executor.cpp.

1266  {
1269 
1270  std::string fail_message = "Mining did not stop";
1271 
1272  if (m_is_rpc)
1273  {
1274  if (!m_rpc_client->rpc_request(req, res, "/stop_mining", fail_message.c_str()))
1275  {
1276  return true;
1277  }
1278  }
1279  else
1280  {
1281  if (!m_rpc_server->on_stop_mining(req, res) || res.status != CORE_RPC_STATUS_OK)
1282  {
1283  tools::fail_msg_writer() << make_error(fail_message, res.status);
1284  return true;
1285  }
1286  }
1287 
1288  tools::success_msg_writer() << "Mining stopped";
1289  return true;
1290 }
bool on_stop_mining(const COMMAND_RPC_STOP_MINING::request &req, COMMAND_RPC_STOP_MINING::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_save_graph()

bool daemonize::t_rpc_command_executor::stop_save_graph ( )

Definition at line 1558 of file rpc_command_executor.cpp.

1559 {
1562  std::string fail_message = "Unsuccessful";
1563 
1564  if (m_is_rpc)
1565  {
1566  if (!m_rpc_client->rpc_request(req, res, "/stop_save_graph", fail_message.c_str()))
1567  {
1568  return true;
1569  }
1570  }
1571 
1572  else
1573  {
1574  if (!m_rpc_server->on_stop_save_graph(req, res) || res.status != CORE_RPC_STATUS_OK)
1575  {
1576  tools::fail_msg_writer() << make_error(fail_message, res.status);
1577  return true;
1578  }
1579  }
1580  tools::success_msg_writer() << "Saving graph is now off";
1581  return true;
1582 }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sync_info()

bool daemonize::t_rpc_command_executor::sync_info ( )

Definition at line 2092 of file rpc_command_executor.cpp.

2093 {
2096  std::string fail_message = "Unsuccessful";
2097  epee::json_rpc::error error_resp;
2098 
2099  if (m_is_rpc)
2100  {
2101  if (!m_rpc_client->json_rpc_request(req, res, "sync_info", fail_message.c_str()))
2102  {
2103  return true;
2104  }
2105  }
2106  else
2107  {
2108  if (!m_rpc_server->on_sync_info(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2109  {
2110  tools::fail_msg_writer() << make_error(fail_message, res.status);
2111  return true;
2112  }
2113  }
2114 
2115  uint64_t target = res.target_height < res.height ? res.height : res.target_height;
2116  tools::success_msg_writer() << "Height: " << res.height << ", target: " << target << " (" << (100.0 * res.height / target) << "%)";
2117  uint64_t current_download = 0;
2118  for (const auto &p: res.peers)
2119  current_download += p.info.current_download;
2120  tools::success_msg_writer() << "Downloading at " << current_download << " kB/s";
2121  if (res.next_needed_pruning_seed)
2122  tools::success_msg_writer() << "Next needed pruning seed: " << res.next_needed_pruning_seed;
2123 
2124  tools::success_msg_writer() << std::to_string(res.peers.size()) << " peers";
2125  for (const auto &p: res.peers)
2126  {
2127  std::string address = epee::string_tools::pad_string(p.info.address, 24);
2128  uint64_t nblocks = 0, size = 0;
2129  for (const auto &s: res.spans)
2130  if (s.connection_id == p.info.connection_id)
2131  nblocks += s.nblocks, size += s.size;
2132  tools::success_msg_writer() << address << " " << epee::string_tools::pad_string(p.info.peer_id, 16, '0', true) << " " <<
2133  epee::string_tools::pad_string(p.info.state, 16) << " " <<
2134  epee::string_tools::pad_string(epee::string_tools::to_string_hex(p.info.pruning_seed), 8) << " " << p.info.height << " " <<
2135  p.info.current_download << " kB/s, " << nblocks << " blocks / " << size/1e6 << " MB queued";
2136  }
2137 
2138  uint64_t total_size = 0;
2139  for (const auto &s: res.spans)
2140  total_size += s.size;
2141  tools::success_msg_writer() << std::to_string(res.spans.size()) << " spans, " << total_size/1e6 << " MB";
2142  tools::success_msg_writer() << res.overview;
2143  for (const auto &s: res.spans)
2144  {
2145  std::string address = epee::string_tools::pad_string(s.remote_address, 24);
2146  std::string pruning_seed = epee::string_tools::to_string_hex(tools::get_pruning_seed(s.start_block_height, std::numeric_limits<uint64_t>::max(), CRYPTONOTE_PRUNING_LOG_STRIPES));
2147  if (s.size == 0)
2148  {
2149  tools::success_msg_writer() << address << " " << s.nblocks << "/" << pruning_seed << " (" << s.start_block_height << " - " << (s.start_block_height + s.nblocks - 1) << ") -";
2150  }
2151  else
2152  {
2153  tools::success_msg_writer() << address << " " << s.nblocks << "/" << pruning_seed << " (" << s.start_block_height << " - " << (s.start_block_height + s.nblocks - 1) << ", " << (uint64_t)(s.size/1e3) << " kB) " << (unsigned)(s.rate/1e3) << " kB/s (" << s.speed/100.0f << ")";
2154  }
2155  }
2156 
2157  return true;
2158 }
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)
#define CRYPTONOTE_PRUNING_LOG_STRIPES
std::string to_string_hex(uint32_t val)
Definition: string_tools.h:211
uint32_t get_pruning_seed(uint64_t block_height, uint64_t blockchain_height, uint32_t log_stripes)
Definition: pruning.cpp:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unban()

bool daemonize::t_rpc_command_executor::unban ( const std::string &  ip)

Definition at line 1685 of file rpc_command_executor.cpp.

1686 {
1689  std::string fail_message = "Unsuccessful";
1690  epee::json_rpc::error error_resp;
1691 
1694  {
1695  tools::fail_msg_writer() << "Invalid IP";
1696  return true;
1697  }
1698  ban.ban = false;
1699  ban.seconds = 0;
1700  req.bans.push_back(ban);
1701 
1702  if (m_is_rpc)
1703  {
1704  if (!m_rpc_client->json_rpc_request(req, res, "set_bans", fail_message.c_str()))
1705  {
1706  return true;
1707  }
1708  }
1709  else
1710  {
1711  if (!m_rpc_server->on_set_bans(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1712  {
1713  tools::fail_msg_writer() << make_error(fail_message, res.status);
1714  return true;
1715  }
1716  }
1717 
1718  return true;
1719 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update()

bool daemonize::t_rpc_command_executor::update ( const std::string &  command)

Definition at line 2011 of file rpc_command_executor.cpp.

2012 {
2015  epee::json_rpc::error error_resp;
2016 
2017  std::string fail_message = "Problem fetching info";
2018 
2019  req.command = command;
2020  if (m_is_rpc)
2021  {
2022  LOG_PRINT_L0("is rpc");
2023  if (!m_rpc_client->rpc_request(req, res, "/update", fail_message.c_str()))
2024  {
2025  LOG_PRINT_L0("update command failed");
2026  return true;
2027  }
2028  }
2029  else
2030  {
2031  LOG_PRINT_L0("not rpc");
2032  if (!m_rpc_server->on_update(req, res) || res.status != CORE_RPC_STATUS_OK)
2033  {
2034  LOG_PRINT_L0("rpc error");
2035  tools::fail_msg_writer() << make_error(fail_message, res.status);
2036  return true;
2037  }
2038  }
2039 
2040  if (!res.update)
2041  {
2042  LOG_PRINT_L0("no update");
2043  tools::msg_writer() << "No update available";
2044  return true;
2045  }
2046 
2047  tools::msg_writer() << "Update available: v" << res.version << ": " << res.user_uri << ", hash " << res.hash;
2048  if (command == "check")
2049  return true;
2050 
2051  if (!res.path.empty())
2052  tools::msg_writer() << "Update downloaded to: " << res.path;
2053  else
2054  tools::msg_writer() << "Update download failed: " << res.status;
2055  if (command == "download")
2056  return true;
2057 
2058  tools::msg_writer() << "'update' not implemented yet";
2059 
2060  return true;
2061 }
bool on_update(const COMMAND_RPC_UPDATE::request &req, COMMAND_RPC_UPDATE::response &res, const connection_context *ctx=NULL)
#define LOG_PRINT_L0(x)
Definition: misc_log_ex.h:99
Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: