Electroneum
Loading...
Searching...
No Matches
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 is_public_output_spent (const cryptonote::txin_to_key_public &txin)
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}

◆ ~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 1865 of file rpc_command_executor.cpp.

1866{
1871 epee::json_rpc::error error_resp;
1872
1873 std::string fail_message = "Unsuccessful";
1874
1875 if (m_is_rpc)
1876 {
1877 if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
1878 {
1879 return true;
1880 }
1881 if (!m_rpc_client->json_rpc_request(req, res, "get_alternate_chains", fail_message.c_str()))
1882 {
1883 return true;
1884 }
1885 }
1886 else
1887 {
1888 if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
1889 {
1890 tools::fail_msg_writer() << make_error(fail_message, ires.status);
1891 return true;
1892 }
1893 if (!m_rpc_server->on_get_alternate_chains(req, res, error_resp))
1894 {
1895 tools::fail_msg_writer() << make_error(fail_message, res.status);
1896 return true;
1897 }
1898 }
1899
1900 if (tip.empty())
1901 {
1902 tools::msg_writer() << boost::lexical_cast<std::string>(res.chains.size()) << " alternate chains found:";
1903 for (const auto &chain: res.chains)
1904 {
1905 uint64_t start_height = (chain.height - chain.length + 1);
1906 tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)
1907 << " deep), diff " << chain.difficulty << ": " << chain.block_hash;
1908 }
1909 }
1910 else
1911 {
1912 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; });
1913 if (i != res.chains.end())
1914 {
1915 const auto &chain = *i;
1916 tools::success_msg_writer() << "Found alternate chain with tip " << tip;
1917 uint64_t start_height = (chain.height - chain.length + 1);
1918 tools::msg_writer() << chain.length << " blocks long, from height " << start_height << " (" << (ires.height - start_height - 1)
1919 << " deep), diff " << chain.difficulty << ":";
1920 for (const std::string &block_id: chain.block_hashes)
1921 tools::msg_writer() << " " << block_id;
1922 tools::msg_writer() << "Chain parent on main chain: " << chain.main_chain_parent_block;
1923 }
1924 else
1925 tools::fail_msg_writer() << "Block hash " << tip << " is not the tip of any known alternate chain";
1926 }
1927 return true;
1928}
#define CORE_RPC_STATUS_OK
const char * res
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)
CXA_THROW_INFO_T * info
unsigned __int64 uint64_t
Definition stdint.h:136
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ ban()

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

Definition at line 1689 of file rpc_command_executor.cpp.

1690{
1693 std::string fail_message = "Unsuccessful";
1694 epee::json_rpc::error error_resp;
1695
1696 cryptonote::COMMAND_RPC_SETBANS::ban ban;
1698 {
1699 tools::fail_msg_writer() << "Invalid IP";
1700 return true;
1701 }
1702 ban.ban = true;
1703 ban.seconds = seconds;
1704 req.bans.push_back(ban);
1705
1706 if (m_is_rpc)
1707 {
1708 if (!m_rpc_client->json_rpc_request(req, res, "set_bans", fail_message.c_str()))
1709 {
1710 return true;
1711 }
1712 }
1713 else
1714 {
1715 if (!m_rpc_server->on_set_bans(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1716 {
1717 tools::fail_msg_writer() << make_error(fail_message, res.status);
1718 return true;
1719 }
1720 }
1721
1722 return true;
1723}
bool ban(const std::string &ip, time_t seconds)
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
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 2280 of file rpc_command_executor.cpp.

2281{
2284 std::string fail_message = "Unsuccessful";
2285 epee::json_rpc::error error_resp;
2286
2287 req.check = true;
2288
2289 if (m_is_rpc)
2290 {
2291 if (!m_rpc_client->json_rpc_request(req, res, "prune_blockchain", fail_message.c_str()))
2292 {
2293 return true;
2294 }
2295 }
2296 else
2297 {
2298 if (!m_rpc_server->on_prune_blockchain(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2299 {
2300 tools::fail_msg_writer() << make_error(fail_message, res.status);
2301 return true;
2302 }
2303 }
2304
2305 if (res.pruning_seed)
2306 {
2307 tools::success_msg_writer() << "Blockchain is pruned";
2308 }
2309 else
2310 {
2311 tools::success_msg_writer() << "Blockchain is not pruned";
2312 }
2313 return true;
2314}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ flush_txpool()

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

Definition at line 1761 of file rpc_command_executor.cpp.

1762{
1765 std::string fail_message = "Unsuccessful";
1766 epee::json_rpc::error error_resp;
1767
1768 if (!txid.empty())
1769 req.txids.push_back(txid);
1770
1771 if (m_is_rpc)
1772 {
1773 if (!m_rpc_client->json_rpc_request(req, res, "flush_txpool", fail_message.c_str()))
1774 {
1775 return true;
1776 }
1777 }
1778 else
1779 {
1780 if (!m_rpc_server->on_flush_txpool(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1781 {
1782 tools::fail_msg_writer() << make_error(fail_message, res.status);
1783 return true;
1784 }
1785 }
1786
1787 tools::success_msg_writer() << "Pool successfully flushed";
1788 return true;
1789}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ generate_ed25519_keypair()

bool daemonize::t_rpc_command_executor::generate_ed25519_keypair ( )

Definition at line 2316 of file rpc_command_executor.cpp.

2316 {
2319 std::string fail_message = "Unsuccessful";
2320 epee::json_rpc::error error_resp;
2321
2322 if (m_is_rpc) {
2323 if (!m_rpc_client->json_rpc_request(req, res, "generate_ed25519_keypair", fail_message.c_str())) {
2324 return true;
2325 }
2326 } else {
2327 if (!m_rpc_server->on_generate_ed25519_keypair(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2328 {
2329 tools::fail_msg_writer() << make_error(fail_message, res.status);
2330 return true;
2331 }
2332 }
2333
2334 tools::success_msg_writer() << "Private Key:" << res.privateKey;
2335 tools::success_msg_writer() << "Public Key:" << res.publicKey;
2336 return true;
2337}
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ get_limit()

bool daemonize::t_rpc_command_executor::get_limit ( )

Definition at line 1394 of file rpc_command_executor.cpp.

1395{
1398
1399 std::string failure_message = "Couldn't get limit";
1400
1401 if (m_is_rpc)
1402 {
1403 if (!m_rpc_client->rpc_request(req, res, "/get_limit", failure_message.c_str()))
1404 {
1405 return true;
1406 }
1407 }
1408 else
1409 {
1410 if (!m_rpc_server->on_get_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1411 {
1412 tools::fail_msg_writer() << make_error(failure_message, res.status);
1413 return true;
1414 }
1415 }
1416
1417 tools::msg_writer() << "limit-down is " << res.limit_down << " kB/s";
1418 tools::msg_writer() << "limit-up is " << res.limit_up << " kB/s";
1419 return true;
1420}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ get_limit_down()

bool daemonize::t_rpc_command_executor::get_limit_down ( )

Definition at line 1480 of file rpc_command_executor.cpp.

1481{
1484
1485 std::string failure_message = "Couldn't get limit";
1486
1487 if (m_is_rpc)
1488 {
1489 if (!m_rpc_client->rpc_request(req, res, "/get_limit", failure_message.c_str()))
1490 {
1491 return true;
1492 }
1493 }
1494 else
1495 {
1496 if (!m_rpc_server->on_get_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1497 {
1498 tools::fail_msg_writer() << make_error(failure_message, res.status);
1499 return true;
1500 }
1501 }
1502
1503 tools::msg_writer() << "limit-down is " << res.limit_down << " kB/s";
1504 return true;
1505}
Here is the call graph for this function:

◆ get_limit_up()

bool daemonize::t_rpc_command_executor::get_limit_up ( )

Definition at line 1453 of file rpc_command_executor.cpp.

1454{
1457
1458 std::string failure_message = "Couldn't get limit";
1459
1460 if (m_is_rpc)
1461 {
1462 if (!m_rpc_client->rpc_request(req, res, "/get_limit", failure_message.c_str()))
1463 {
1464 return true;
1465 }
1466 }
1467 else
1468 {
1469 if (!m_rpc_server->on_get_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1470 {
1471 tools::fail_msg_writer() << make_error(failure_message, res.status);
1472 return true;
1473 }
1474 }
1475
1476 tools::msg_writer() << "limit-up is " << res.limit_up << " kB/s";
1477 return true;
1478}
Here is the call graph for this function:

◆ hard_fork_info()

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

Definition at line 1624 of file rpc_command_executor.cpp.

1625{
1628 std::string fail_message = "Unsuccessful";
1629 epee::json_rpc::error error_resp;
1630
1631 req.version = version;
1632
1633 if (m_is_rpc)
1634 {
1635 if (!m_rpc_client->json_rpc_request(req, res, "hard_fork_info", fail_message.c_str()))
1636 {
1637 return true;
1638 }
1639 }
1640 else
1641 {
1642 if (!m_rpc_server->on_hard_fork_info(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1643 {
1644 tools::fail_msg_writer() << make_error(fail_message, res.status);
1645 return true;
1646 }
1647 }
1648
1649 version = version > 0 ? version : res.voting;
1650 tools::msg_writer() << "version " << (uint32_t)version << " " << (res.enabled ? "enabled" : "not enabled") <<
1651 ", " << res.votes << "/" << res.window << " votes, threshold " << res.threshold;
1652 tools::msg_writer() << "current version " << (uint32_t)res.version << ", voting for version " << (uint32_t)res.voting;
1653
1654 return true;
1655}
uint8_t version
unsigned int uint32_t
Definition stdint.h:126
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ in_peers()

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

Definition at line 1539 of file rpc_command_executor.cpp.

1540{
1543
1544 epee::json_rpc::error error_resp;
1545
1546 req.in_peers = limit;
1547
1548 std::string fail_message = "Unsuccessful";
1549
1550 if (m_is_rpc)
1551 {
1552 if (!m_rpc_client->rpc_request(req, res, "/in_peers", fail_message.c_str()))
1553 {
1554 return true;
1555 }
1556 }
1557 else
1558 {
1559 if (!m_rpc_server->on_in_peers(req, res) || res.status != CORE_RPC_STATUS_OK)
1560 {
1561 tools::fail_msg_writer() << make_error(fail_message, res.status);
1562 return true;
1563 }
1564 }
1565
1566 tools::msg_writer() << "Max number of in peers set to " << limit << std::endl;
1567
1568 return true;
1569}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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::SPENT_STATUS::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}
std::string pod_to_hex(const t_pod_type &s)
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ is_public_output_spent()

bool daemonize::t_rpc_command_executor::is_public_output_spent ( const cryptonote::txin_to_key_public & txin)

Definition at line 1017 of file rpc_command_executor.cpp.

1017 {
1020
1021 std::string fail_message = "Problem checking public_output";
1022
1023 cryptonote::public_output po;
1026 po.amount = txin.amount;
1027 req.public_outputs.push_back(po);
1028 if (m_is_rpc)
1029 {
1030 if (!m_rpc_client->rpc_request(req, res, "/is_public_output_spent", fail_message.c_str()))
1031 {
1032 return true;
1033 }
1034 }
1035 else
1036 {
1037 if (!m_rpc_server->on_is_public_output_spent(req, res) || res.status != CORE_RPC_STATUS_OK)
1038 {
1039 tools::fail_msg_writer() << make_error(fail_message, res.status);
1040 return true;
1041 }
1042 }
1043
1044 if (1 == res.spent_status.size())
1045 {
1046 // first as hex
1047 tools::success_msg_writer() << "public output with hash: " << epee::string_tools::pod_to_hex(txin.tx_hash) << ", relative output index: " << txin.relative_offset << " and amount:" << txin.amount << " ------ " << (res.spent_status.front() ? "spent" : "unspent") << (res.spent_status.front() == cryptonote::SPENT_STATUS::SPENT_IN_POOL ? " (in pool)" : "");
1048 }
1049 else
1050 {
1051 tools::fail_msg_writer() << "public output status could not be determined" << std::endl;
1052 }
1053
1054 return true;
1055}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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}
#define CORE_RPC_STATUS_BUSY
std::string print_etn(uint64_t amount, unsigned int decimal_point)
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ out_peers()

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

Definition at line 1507 of file rpc_command_executor.cpp.

1508{
1511
1512 epee::json_rpc::error error_resp;
1513
1514 req.out_peers = limit;
1515
1516 std::string fail_message = "Unsuccessful";
1517
1518 if (m_is_rpc)
1519 {
1520 if (!m_rpc_client->rpc_request(req, res, "/out_peers", fail_message.c_str()))
1521 {
1522 return true;
1523 }
1524 }
1525 else
1526 {
1527 if (!m_rpc_server->on_out_peers(req, res) || res.status != CORE_RPC_STATUS_OK)
1528 {
1529 tools::fail_msg_writer() << make_error(fail_message, res.status);
1530 return true;
1531 }
1532 }
1533
1534 tools::msg_writer() << "Max number of out peers set to " << limit << std::endl;
1535
1536 return true;
1537}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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 1791 of file rpc_command_executor.cpp.

1792{
1795 std::string fail_message = "Unsuccessful";
1796 epee::json_rpc::error error_resp;
1797
1798 req.amounts = amounts;
1799 req.min_count = min_count;
1800 req.max_count = max_count;
1801 req.unlocked = false;
1802 req.recent_cutoff = 0;
1803
1804 if (m_is_rpc)
1805 {
1806 if (!m_rpc_client->json_rpc_request(req, res, "get_output_histogram", fail_message.c_str()))
1807 {
1808 return true;
1809 }
1810 }
1811 else
1812 {
1813 if (!m_rpc_server->on_get_output_histogram(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1814 {
1815 tools::fail_msg_writer() << make_error(fail_message, res.status);
1816 return true;
1817 }
1818 }
1819
1820 std::sort(res.histogram.begin(), res.histogram.end(),
1821 [](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; });
1822 for (const auto &e: res.histogram)
1823 {
1824 tools::msg_writer() << e.total_instances << " " << cryptonote::print_etn(e.amount);
1825 }
1826
1827 return true;
1828}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ pop_blocks()

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

Definition at line 2200 of file rpc_command_executor.cpp.

2201{
2204 std::string fail_message = "pop_blocks failed";
2205
2206 req.nblocks = num_blocks;
2207 if (m_is_rpc)
2208 {
2209 if (!m_rpc_client->rpc_request(req, res, "/pop_blocks", fail_message.c_str()))
2210 {
2211 return true;
2212 }
2213 }
2214 else
2215 {
2216 if (!m_rpc_server->on_pop_blocks(req, res) || res.status != CORE_RPC_STATUS_OK)
2217 {
2218 tools::fail_msg_writer() << make_error(fail_message, res.status);
2219 return true;
2220 }
2221 }
2222 tools::success_msg_writer() << "new height: " << res.height;
2223
2224 return true;
2225}
uint64_t num_blocks(const std::vector< test_event_entry > &events)
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ print_bans()

bool daemonize::t_rpc_command_executor::print_bans ( )

Definition at line 1657 of file rpc_command_executor.cpp.

1658{
1661 std::string fail_message = "Unsuccessful";
1662 epee::json_rpc::error error_resp;
1663
1664 if (m_is_rpc)
1665 {
1666 if (!m_rpc_client->json_rpc_request(req, res, "get_bans", fail_message.c_str()))
1667 {
1668 return true;
1669 }
1670 }
1671 else
1672 {
1673 if (!m_rpc_server->on_get_bans(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1674 {
1675 tools::fail_msg_writer() << make_error(fail_message, res.status);
1676 return true;
1677 }
1678 }
1679
1680 for (auto i = res.bans.begin(); i != res.bans.end(); ++i)
1681 {
1682 tools::msg_writer() << epee::string_tools::get_ip_string_from_int32(i->ip) << " banned for " << i->seconds << " seconds";
1683 }
1684
1685 return true;
1686}
std::string get_ip_string_from_int32(uint32_t ip)
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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);
849
850 return true;
851}
#define ENDL
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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);
883
884 return true;
885}
uint64_t height
Here is the call graph for this function:

◆ print_blockchain_dynamic_stats()

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

Definition at line 1930 of file rpc_command_executor.cpp.

1931{
1940 epee::json_rpc::error error_resp;
1941
1942 std::string fail_message = "Problem fetching info";
1943
1944 fereq.grace_blocks = 0;
1945 hfreq.version = HF_VERSION_PER_BYTE_FEE;
1946 if (m_is_rpc)
1947 {
1948 if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
1949 {
1950 return true;
1951 }
1952 if (!m_rpc_client->json_rpc_request(fereq, feres, "get_fee_estimate", fail_message.c_str()))
1953 {
1954 return true;
1955 }
1956 if (!m_rpc_client->json_rpc_request(hfreq, hfres, "hard_fork_info", fail_message.c_str()))
1957 {
1958 return true;
1959 }
1960 }
1961 else
1962 {
1963 if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
1964 {
1965 tools::fail_msg_writer() << make_error(fail_message, ires.status);
1966 return true;
1967 }
1968 if (!m_rpc_server->on_get_base_fee_estimate(fereq, feres, error_resp) || feres.status != CORE_RPC_STATUS_OK)
1969 {
1970 tools::fail_msg_writer() << make_error(fail_message, feres.status);
1971 return true;
1972 }
1973 if (!m_rpc_server->on_hard_fork_info(hfreq, hfres, error_resp) || hfres.status != CORE_RPC_STATUS_OK)
1974 {
1975 tools::fail_msg_writer() << make_error(fail_message, hfres.status);
1976 return true;
1977 }
1978 }
1979
1980 tools::msg_writer() << "Height: " << ires.height << ", diff " << ires.difficulty << ", cum. diff " << ires.cumulative_difficulty
1981 << ", target " << ires.target << " sec" << ", dyn fee " << cryptonote::print_etn(feres.fee) << "/" << (hfres.enabled ? "byte" : "kB");
1982
1983 if (nblocks > 0)
1984 {
1985 if (nblocks > ires.height)
1986 nblocks = ires.height;
1987
1988 bhreq.start_height = ires.height - nblocks;
1989 bhreq.end_height = ires.height - 1;
1990 bhreq.fill_pow_hash = false;
1991 if (m_is_rpc)
1992 {
1993 if (!m_rpc_client->json_rpc_request(bhreq, bhres, "getblockheadersrange", fail_message.c_str()))
1994 {
1995 return true;
1996 }
1997 }
1998 else
1999 {
2000 if (!m_rpc_server->on_get_block_headers_range(bhreq, bhres, error_resp) || bhres.status != CORE_RPC_STATUS_OK)
2001 {
2002 tools::fail_msg_writer() << make_error(fail_message, bhres.status);
2003 return true;
2004 }
2005 }
2006
2007 double avgdiff = 0;
2008 double avgnumtxes = 0;
2009 double avgreward = 0;
2010 std::vector<uint64_t> weights;
2011 weights.reserve(nblocks);
2012 uint64_t earliest = std::numeric_limits<uint64_t>::max(), latest = 0;
2013 std::vector<unsigned> major_versions(256, 0), minor_versions(256, 0);
2014 for (const auto &bhr: bhres.headers)
2015 {
2016 avgdiff += bhr.difficulty;
2017 avgnumtxes += bhr.num_txes;
2018 avgreward += bhr.reward;
2019 weights.push_back(bhr.block_weight);
2020 static_assert(sizeof(bhr.major_version) == 1, "major_version expected to be uint8_t");
2021 static_assert(sizeof(bhr.minor_version) == 1, "major_version expected to be uint8_t");
2022 major_versions[(unsigned)bhr.major_version]++;
2023 minor_versions[(unsigned)bhr.minor_version]++;
2024 earliest = std::min(earliest, bhr.timestamp);
2025 latest = std::max(latest, bhr.timestamp);
2026 }
2027 avgdiff /= nblocks;
2028 avgnumtxes /= nblocks;
2029 avgreward /= nblocks;
2030 uint64_t median_block_weight = epee::misc_utils::median(weights);
2031 tools::msg_writer() << "Last " << nblocks << ": avg. diff " << (uint64_t)avgdiff << ", " << (latest - earliest) / nblocks << " avg sec/block, avg num txes " << avgnumtxes
2032 << ", avg. reward " << cryptonote::print_etn(avgreward) << ", median block weight " << median_block_weight;
2033
2034 unsigned int max_major = 256, max_minor = 256;
2035 while (max_major > 0 && !major_versions[--max_major]);
2036 while (max_minor > 0 && !minor_versions[--max_minor]);
2037 std::string s = "";
2038 for (unsigned n = 0; n <= max_major; ++n)
2039 if (major_versions[n])
2040 s += (s.empty() ? "" : ", ") + boost::lexical_cast<std::string>(major_versions[n]) + std::string(" v") + boost::lexical_cast<std::string>(n);
2041 tools::msg_writer() << "Block versions: " << s;
2042 s = "";
2043 for (unsigned n = 0; n <= max_minor; ++n)
2044 if (minor_versions[n])
2045 s += (s.empty() ? "" : ", ") + boost::lexical_cast<std::string>(minor_versions[n]) + std::string(" v") + boost::lexical_cast<std::string>(n);
2046 tools::msg_writer() << "Voting for: " << s;
2047 }
2048 return true;
2049}
#define HF_VERSION_PER_BYTE_FEE
type_vec_type median(std::vector< type_vec_type > &v)
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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:

◆ print_coinbase_tx_sum()

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

Definition at line 1830 of file rpc_command_executor.cpp.

1831{
1834 epee::json_rpc::error error_resp;
1835
1836 req.height = height;
1837 req.count = count;
1838
1839 std::string fail_message = "Unsuccessful";
1840
1841 if (m_is_rpc)
1842 {
1843 if (!m_rpc_client->json_rpc_request(req, res, "get_coinbase_tx_sum", fail_message.c_str()))
1844 {
1845 return true;
1846 }
1847 }
1848 else
1849 {
1850 if (!m_rpc_server->on_get_coinbase_tx_sum(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1851 {
1852 tools::fail_msg_writer() << make_error(fail_message, res.status);
1853 return true;
1854 }
1855 }
1856
1857 tools::msg_writer() << "Sum of coinbase transactions between block heights ["
1858 << height << ", " << (height + count) << ") is "
1859 << cryptonote::print_etn(res.emission_amount + res.fee_amount) << " "
1860 << "consisting of " << cryptonote::print_etn(res.emission_amount)
1861 << " in emissions, and " << cryptonote::print_etn(res.fee_amount) << " in fees";
1862 return true;
1863}
mdb_size_t count(MDB_cursor *cur)
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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}
std::string pad_string(std::string s, size_t n, char c=' ', bool prepend=false)
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
const char * address
Definition multisig.cpp:37
Here is the call 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}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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
std::string get_human_readable_bytes(uint64_t bytes)
Definition util.cpp:1089
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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:

◆ print_status()

bool daemonize::t_rpc_command_executor::print_status ( )

Definition at line 1374 of file rpc_command_executor.cpp.

1375{
1376 if (!m_is_rpc)
1377 {
1378 tools::success_msg_writer() << "print_status makes no sense in interactive mode";
1379 return true;
1380 }
1381
1382 bool daemon_is_alive = m_rpc_client->check_connection();
1383
1384 if(daemon_is_alive) {
1385 tools::success_msg_writer() << "electroneumd is running";
1386 }
1387 else {
1388 tools::fail_msg_writer() << "electroneumd is NOT running";
1389 }
1390
1391 return true;
1392}
Here is the call 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;
947 cryptonote::transaction tx;
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}
POD_CLASS hash
Definition hash.h:50
std::string obj_to_json_str(T &obj)
std::string blobdata
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)
const CharType(& source)[N]
Definition pointer.h:1147
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ print_transaction_pool_long()

bool daemonize::t_rpc_command_executor::print_transaction_pool_long ( )

Definition at line 1057 of file rpc_command_executor.cpp.

1057 {
1060
1061 std::string fail_message = "Problem fetching transaction pool";
1062
1063 if (m_is_rpc)
1064 {
1065 if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool", fail_message.c_str()))
1066 {
1067 return true;
1068 }
1069 }
1070 else
1071 {
1072 if (!m_rpc_server->on_get_transaction_pool(req, res) || res.status != CORE_RPC_STATUS_OK)
1073 {
1074 tools::fail_msg_writer() << make_error(fail_message, res.status);
1075 return true;
1076 }
1077 }
1078
1079 if (res.transactions.empty() && res.spent_key_images.empty())
1080 {
1081 tools::msg_writer() << "Pool is empty" << std::endl;
1082 }
1083 if (! res.transactions.empty())
1084 {
1085 const time_t now = time(NULL);
1086 tools::msg_writer() << "Transactions: ";
1087 for (auto & tx_info : res.transactions)
1088 {
1089 tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
1090 << tx_info.tx_json << std::endl
1091 << "blob_size: " << tx_info.blob_size << std::endl
1092 << "weight: " << tx_info.weight << std::endl
1093 << "fee: " << cryptonote::print_etn(tx_info.fee) << std::endl
1094 << "fee/byte: " << cryptonote::print_etn(tx_info.fee / (double)tx_info.weight) << std::endl
1095 << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
1096 << "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
1097 << "do_not_relay: " << (tx_info.do_not_relay ? 'T' : 'F') << std::endl
1098 << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
1099 << "double_spend_seen: " << (tx_info.double_spend_seen ? 'T' : 'F') << std::endl
1100 << "nonexistent_utxo_seen: " << (tx_info.nonexistent_utxo_seen ? 'T' : 'F') << std::endl
1101 << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
1102 << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
1103 << "last_failed_height: " << tx_info.last_failed_height << std::endl
1104 << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
1105 }
1106 }
1107 if (! res.spent_key_images.empty())
1108 {
1109 tools::msg_writer() << ""; // one newline
1110 tools::msg_writer() << "Spent key images: ";
1111 for (const cryptonote::spent_key_image_info& kinfo : res.spent_key_images)
1112 {
1113 tools::msg_writer() << "key image: " << kinfo.id_hash;
1114 if (kinfo.txs_hashes.size() == 1)
1115 {
1116 tools::msg_writer() << " tx: " << kinfo.txs_hashes[0];
1117 }
1118 else if (kinfo.txs_hashes.size() == 0)
1119 {
1120 tools::msg_writer() << " WARNING: spent key image has no txs associated";
1121 }
1122 else
1123 {
1124 tools::msg_writer() << " NOTE: key image for multiple txs: " << kinfo.txs_hashes.size();
1125 for (const std::string& tx_id : kinfo.txs_hashes)
1126 {
1127 tools::msg_writer() << " tx: " << tx_id;
1128 }
1129 }
1130 }
1131 if (res.transactions.empty())
1132 {
1133 tools::msg_writer() << "WARNING: Inconsistent pool state - no transactions";
1134 }
1135 }
1136
1137 return true;
1138}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ print_transaction_pool_short()

bool daemonize::t_rpc_command_executor::print_transaction_pool_short ( )

Definition at line 1140 of file rpc_command_executor.cpp.

1140 {
1143
1144 std::string fail_message = "Problem fetching transaction pool";
1145
1146 if (m_is_rpc)
1147 {
1148 if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool", fail_message.c_str()))
1149 {
1150 return true;
1151 }
1152 }
1153 else
1154 {
1155 if (!m_rpc_server->on_get_transaction_pool(req, res) || res.status != CORE_RPC_STATUS_OK)
1156 {
1157 tools::fail_msg_writer() << make_error(fail_message, res.status);
1158 return true;
1159 }
1160 }
1161
1162 if (res.transactions.empty())
1163 {
1164 tools::msg_writer() << "Pool is empty" << std::endl;
1165 }
1166 else
1167 {
1168 const time_t now = time(NULL);
1169 for (auto & tx_info : res.transactions)
1170 {
1171 tools::msg_writer() << "id: " << tx_info.id_hash << std::endl
1172 << "blob_size: " << tx_info.blob_size << std::endl
1173 << "weight: " << tx_info.weight << std::endl
1174 << "fee: " << cryptonote::print_etn(tx_info.fee) << std::endl
1175 << "fee/byte: " << cryptonote::print_etn(tx_info.fee / (double)tx_info.weight) << std::endl
1176 << "receive_time: " << tx_info.receive_time << " (" << get_human_time_ago(tx_info.receive_time, now) << ")" << std::endl
1177 << "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
1178 << "do_not_relay: " << (tx_info.do_not_relay ? 'T' : 'F') << std::endl
1179 << "kept_by_block: " << (tx_info.kept_by_block ? 'T' : 'F') << std::endl
1180 << "double_spend_seen: " << (tx_info.double_spend_seen ? 'T' : 'F') << std::endl
1181 << "nonexistent_utxo_seen: " << (tx_info.nonexistent_utxo_seen ? 'T' : 'F') << std::endl
1182 << "max_used_block_height: " << tx_info.max_used_block_height << std::endl
1183 << "max_used_block_id: " << tx_info.max_used_block_id_hash << std::endl
1184 << "last_failed_height: " << tx_info.last_failed_height << std::endl
1185 << "last_failed_id: " << tx_info.last_failed_id_hash << std::endl;
1186 }
1187 }
1188
1189 return true;
1190}
Here is the call graph for this function:

◆ print_transaction_pool_stats()

bool daemonize::t_rpc_command_executor::print_transaction_pool_stats ( )

Definition at line 1192 of file rpc_command_executor.cpp.

1192 {
1197
1198 std::string fail_message = "Problem fetching transaction pool stats";
1199
1200 if (m_is_rpc)
1201 {
1202 if (!m_rpc_client->rpc_request(req, res, "/get_transaction_pool_stats", fail_message.c_str()))
1203 {
1204 return true;
1205 }
1206 if (!m_rpc_client->rpc_request(ireq, ires, "/getinfo", fail_message.c_str()))
1207 {
1208 return true;
1209 }
1210 }
1211 else
1212 {
1213 res.pool_stats = {};
1214 if (!m_rpc_server->on_get_transaction_pool_stats(req, res) || res.status != CORE_RPC_STATUS_OK)
1215 {
1216 tools::fail_msg_writer() << make_error(fail_message, res.status);
1217 return true;
1218 }
1219 if (!m_rpc_server->on_get_info(ireq, ires) || ires.status != CORE_RPC_STATUS_OK)
1220 {
1221 tools::fail_msg_writer() << make_error(fail_message, ires.status);
1222 return true;
1223 }
1224 }
1225
1226 size_t n_transactions = res.pool_stats.txs_total;
1227 const uint64_t now = time(NULL);
1228 size_t avg_bytes = n_transactions ? res.pool_stats.bytes_total / n_transactions : 0;
1229
1230 std::string backlog_message;
1231 const uint64_t full_reward_zone = ires.block_weight_limit / 2;
1232 if (res.pool_stats.bytes_total <= full_reward_zone)
1233 {
1234 backlog_message = "no backlog";
1235 }
1236 else
1237 {
1238 uint64_t backlog = (res.pool_stats.bytes_total + full_reward_zone - 1) / full_reward_zone;
1239 backlog_message = (boost::format("estimated %u block (%u minutes) backlog") % backlog % (backlog * DIFFICULTY_TARGET_V6 / 60)).str();
1240 }
1241
1242 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
1243 << "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
1244 << 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;
1245
1246 if (n_transactions > 1 && res.pool_stats.histo.size())
1247 {
1248 std::vector<uint64_t> times;
1249 uint64_t numer;
1250 size_t i, n = res.pool_stats.histo.size(), denom;
1251 times.resize(n);
1252 if (res.pool_stats.histo_98pc)
1253 {
1254 numer = res.pool_stats.histo_98pc;
1255 denom = n-1;
1256 for (i=0; i<denom; i++)
1257 times[i] = i * numer / denom;
1258 times[i] = now - res.pool_stats.oldest;
1259 } else
1260 {
1261 numer = now - res.pool_stats.oldest;
1262 denom = n;
1263 for (i=0; i<denom; i++)
1264 times[i] = i * numer / denom;
1265 }
1266 tools::msg_writer() << " Age Txes Bytes";
1267 for (i=0; i<n; i++)
1268 {
1269 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;
1270 }
1271 }
1273
1274 return true;
1275}
#define DIFFICULTY_TARGET_V6
Here is the call graph for this function:

◆ prune_blockchain()

bool daemonize::t_rpc_command_executor::prune_blockchain ( )

Definition at line 2251 of file rpc_command_executor.cpp.

2252{
2255 std::string fail_message = "Unsuccessful";
2256 epee::json_rpc::error error_resp;
2257
2258 req.check = false;
2259
2260 if (m_is_rpc)
2261 {
2262 if (!m_rpc_client->json_rpc_request(req, res, "prune_blockchain", fail_message.c_str()))
2263 {
2264 return true;
2265 }
2266 }
2267 else
2268 {
2269 if (!m_rpc_server->on_prune_blockchain(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2270 {
2271 tools::fail_msg_writer() << make_error(fail_message, res.status);
2272 return true;
2273 }
2274 }
2275
2276 tools::success_msg_writer() << "Blockchain pruned";
2277 return true;
2278}
Here is the call graph for this function:

◆ relay_tx()

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

Definition at line 2103 of file rpc_command_executor.cpp.

2104{
2107 std::string fail_message = "Unsuccessful";
2108 epee::json_rpc::error error_resp;
2109
2110 req.txids.push_back(txid);
2111
2112 if (m_is_rpc)
2113 {
2114 if (!m_rpc_client->json_rpc_request(req, res, "relay_tx", fail_message.c_str()))
2115 {
2116 return true;
2117 }
2118 }
2119 else
2120 {
2121 if (!m_rpc_server->on_relay_tx(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2122 {
2123 tools::fail_msg_writer() << make_error(fail_message, res.status);
2124 return true;
2125 }
2126 }
2127
2128 tools::success_msg_writer() << "Transaction successfully relayed";
2129 return true;
2130}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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 1422 of file rpc_command_executor.cpp.

1423{
1426
1427 req.limit_down = limit_down;
1428 req.limit_up = limit_up;
1429
1430 std::string failure_message = "Couldn't set limit";
1431
1432 if (m_is_rpc)
1433 {
1434 if (!m_rpc_client->rpc_request(req, res, "/set_limit", failure_message.c_str()))
1435 {
1436 return true;
1437 }
1438 }
1439 else
1440 {
1441 if (!m_rpc_server->on_set_limit(req, res) || res.status != CORE_RPC_STATUS_OK)
1442 {
1443 tools::fail_msg_writer() << make_error(failure_message, res.status);
1444 return true;
1445 }
1446 }
1447
1448 tools::msg_writer() << "Set limit-down to " << res.limit_down << " kB/s";
1449 tools::msg_writer() << "Set limit-up to " << res.limit_up << " kB/s";
1450 return true;
1451}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ set_validator_key()

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

Definition at line 2227 of file rpc_command_executor.cpp.

2227 {
2230 std::string fail_message = "Unsuccessful";
2231 epee::json_rpc::error error_resp;
2232
2233 req.validator_key = key;
2234
2235 if (m_is_rpc) {
2236 if (!m_rpc_client->json_rpc_request(req, res, "set_validator_key", fail_message.c_str())) {
2237 return true;
2238 }
2239 } else {
2240 if (!m_rpc_server->on_set_validator_key(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2241 {
2242 tools::fail_msg_writer() << make_error(fail_message, res.status);
2243 return true;
2244 }
2245 }
2246
2247 tools::success_msg_writer() << "Validator Key successfully set";
2248 return true;
2249}
const char * key
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call 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:

◆ 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:

◆ 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:

◆ sign_message()

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

Definition at line 2339 of file rpc_command_executor.cpp.

2339 {
2342 std::string fail_message = "Unsuccessful";
2343 epee::json_rpc::error error_resp;
2344
2345 req.privateKey = privateKey;
2346 req.message = message;
2347
2348 if (m_is_rpc) {
2349 if (!m_rpc_client->json_rpc_request(req, res, "sign_message", fail_message.c_str())) {
2350 return true;
2351 }
2352 } else {
2353 if (!m_rpc_server->on_sign_message(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2354 {
2355 tools::fail_msg_writer() << make_error(fail_message, res.status);
2356 return true;
2357 }
2358 }
2359
2360 tools::success_msg_writer() << "Signature: " << res.signature;
2361 return true;
2362}
std::string privateKey
std::string message("Message requiring signing")
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call 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 1277 of file rpc_command_executor.cpp.

1277 {
1280 req.miner_address = cryptonote::get_account_address_as_str(nettype, false, address);
1281 req.threads_count = num_threads;
1282 req.do_background_mining = do_background_mining;
1283 req.ignore_battery = ignore_battery;
1284
1285 std::string fail_message = "Mining did not start";
1286
1287 if (m_is_rpc)
1288 {
1289 if (m_rpc_client->rpc_request(req, res, "/start_mining", fail_message.c_str()))
1290 {
1291 tools::success_msg_writer() << "Mining started";
1292 }
1293 }
1294 else
1295 {
1296 if (!m_rpc_server->on_start_mining(req, res) || res.status != CORE_RPC_STATUS_OK)
1297 {
1298 tools::fail_msg_writer() << make_error(fail_message, res.status);
1299 return true;
1300 }
1301 }
1302
1303 return true;
1304}
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ start_save_graph()

bool daemonize::t_rpc_command_executor::start_save_graph ( )

Definition at line 1571 of file rpc_command_executor.cpp.

1572{
1575 std::string fail_message = "Unsuccessful";
1576
1577 if (m_is_rpc)
1578 {
1579 if (!m_rpc_client->rpc_request(req, res, "/start_save_graph", fail_message.c_str()))
1580 {
1581 return true;
1582 }
1583 }
1584
1585 else
1586 {
1587 if (!m_rpc_server->on_start_save_graph(req, res) || res.status != CORE_RPC_STATUS_OK)
1588 {
1589 tools::fail_msg_writer() << make_error(fail_message, res.status);
1590 return true;
1591 }
1592 }
1593
1594 tools::success_msg_writer() << "Saving graph is now on";
1595 return true;
1596}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ stop_daemon()

bool daemonize::t_rpc_command_executor::stop_daemon ( )

Definition at line 1332 of file rpc_command_executor.cpp.

1333{
1336
1337//# ifdef WIN32
1338// // Stop via service API
1339// // TODO - this is only temporary! Get rid of hard-coded constants!
1340// bool ok = windows::stop_service("Electroneum Daemon");
1341// ok = windows::uninstall_service("Electroneum Daemon");
1342// //bool ok = windows::stop_service(SERVICE_NAME);
1343// //ok = windows::uninstall_service(SERVICE_NAME);
1344// if (ok)
1345// {
1346// return true;
1347// }
1348//# endif
1349
1350 // Stop via RPC
1351 std::string fail_message = "Daemon did not stop";
1352
1353 if (m_is_rpc)
1354 {
1355 if(!m_rpc_client->rpc_request(req, res, "/stop_daemon", fail_message.c_str()))
1356 {
1357 return true;
1358 }
1359 }
1360 else
1361 {
1362 if (!m_rpc_server->on_stop_daemon(req, res) || res.status != CORE_RPC_STATUS_OK)
1363 {
1364 tools::fail_msg_writer() << make_error(fail_message, res.status);
1365 return true;
1366 }
1367 }
1368
1369 tools::success_msg_writer() << "Stop signal sent";
1370
1371 return true;
1372}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ stop_mining()

bool daemonize::t_rpc_command_executor::stop_mining ( )

Definition at line 1306 of file rpc_command_executor.cpp.

1306 {
1309
1310 std::string fail_message = "Mining did not stop";
1311
1312 if (m_is_rpc)
1313 {
1314 if (!m_rpc_client->rpc_request(req, res, "/stop_mining", fail_message.c_str()))
1315 {
1316 return true;
1317 }
1318 }
1319 else
1320 {
1321 if (!m_rpc_server->on_stop_mining(req, res) || res.status != CORE_RPC_STATUS_OK)
1322 {
1323 tools::fail_msg_writer() << make_error(fail_message, res.status);
1324 return true;
1325 }
1326 }
1327
1328 tools::success_msg_writer() << "Mining stopped";
1329 return true;
1330}
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ stop_save_graph()

bool daemonize::t_rpc_command_executor::stop_save_graph ( )

Definition at line 1598 of file rpc_command_executor.cpp.

1599{
1602 std::string fail_message = "Unsuccessful";
1603
1604 if (m_is_rpc)
1605 {
1606 if (!m_rpc_client->rpc_request(req, res, "/stop_save_graph", fail_message.c_str()))
1607 {
1608 return true;
1609 }
1610 }
1611
1612 else
1613 {
1614 if (!m_rpc_server->on_stop_save_graph(req, res) || res.status != CORE_RPC_STATUS_OK)
1615 {
1616 tools::fail_msg_writer() << make_error(fail_message, res.status);
1617 return true;
1618 }
1619 }
1620 tools::success_msg_writer() << "Saving graph is now off";
1621 return true;
1622}
epee::misc_utils::struct_init< request_t > request
epee::misc_utils::struct_init< response_t > response
Here is the call graph for this function:

◆ sync_info()

bool daemonize::t_rpc_command_executor::sync_info ( )

Definition at line 2132 of file rpc_command_executor.cpp.

2133{
2136 std::string fail_message = "Unsuccessful";
2137 epee::json_rpc::error error_resp;
2138
2139 if (m_is_rpc)
2140 {
2141 if (!m_rpc_client->json_rpc_request(req, res, "sync_info", fail_message.c_str()))
2142 {
2143 return true;
2144 }
2145 }
2146 else
2147 {
2148 if (!m_rpc_server->on_sync_info(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
2149 {
2150 tools::fail_msg_writer() << make_error(fail_message, res.status);
2151 return true;
2152 }
2153 }
2154
2155 uint64_t target = res.target_height < res.height ? res.height : res.target_height;
2156 tools::success_msg_writer() << "Height: " << res.height << ", target: " << target << " (" << (100.0 * res.height / target) << "%)";
2157 uint64_t current_download = 0;
2158 for (const auto &p: res.peers)
2159 current_download += p.info.current_download;
2160 tools::success_msg_writer() << "Downloading at " << current_download << " kB/s";
2161 if (res.next_needed_pruning_seed)
2162 tools::success_msg_writer() << "Next needed pruning seed: " << res.next_needed_pruning_seed;
2163
2164 tools::success_msg_writer() << std::to_string(res.peers.size()) << " peers";
2165 for (const auto &p: res.peers)
2166 {
2167 std::string address = epee::string_tools::pad_string(p.info.address, 24);
2168 uint64_t nblocks = 0, size = 0;
2169 for (const auto &s: res.spans)
2170 if (s.connection_id == p.info.connection_id)
2171 nblocks += s.nblocks, size += s.size;
2172 tools::success_msg_writer() << address << " " << epee::string_tools::pad_string(p.info.peer_id, 16, '0', true) << " " <<
2173 epee::string_tools::pad_string(p.info.state, 16) << " " <<
2174 epee::string_tools::pad_string(epee::string_tools::to_string_hex(p.info.pruning_seed), 8) << " " << p.info.height << " " <<
2175 p.info.current_download << " kB/s, " << nblocks << " blocks / " << size/1e6 << " MB queued";
2176 }
2177
2178 uint64_t total_size = 0;
2179 for (const auto &s: res.spans)
2180 total_size += s.size;
2181 tools::success_msg_writer() << std::to_string(res.spans.size()) << " spans, " << total_size/1e6 << " MB";
2182 tools::success_msg_writer() << res.overview;
2183 for (const auto &s: res.spans)
2184 {
2185 std::string address = epee::string_tools::pad_string(s.remote_address, 24);
2186 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));
2187 if (s.size == 0)
2188 {
2189 tools::success_msg_writer() << address << " " << s.nblocks << "/" << pruning_seed << " (" << s.start_block_height << " - " << (s.start_block_height + s.nblocks - 1) << ") -";
2190 }
2191 else
2192 {
2193 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 << ")";
2194 }
2195 }
2196
2197 return true;
2198}
#define CRYPTONOTE_PRUNING_LOG_STRIPES
std::string to_string_hex(uint32_t val)
uint32_t get_pruning_seed(uint64_t block_height, uint64_t blockchain_height, uint32_t log_stripes)
Definition pruning.cpp:61
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

◆ unban()

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

Definition at line 1725 of file rpc_command_executor.cpp.

1726{
1729 std::string fail_message = "Unsuccessful";
1730 epee::json_rpc::error error_resp;
1731
1732 cryptonote::COMMAND_RPC_SETBANS::ban ban;
1734 {
1735 tools::fail_msg_writer() << "Invalid IP";
1736 return true;
1737 }
1738 ban.ban = false;
1739 ban.seconds = 0;
1740 req.bans.push_back(ban);
1741
1742 if (m_is_rpc)
1743 {
1744 if (!m_rpc_client->json_rpc_request(req, res, "set_bans", fail_message.c_str()))
1745 {
1746 return true;
1747 }
1748 }
1749 else
1750 {
1751 if (!m_rpc_server->on_set_bans(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
1752 {
1753 tools::fail_msg_writer() << make_error(fail_message, res.status);
1754 return true;
1755 }
1756 }
1757
1758 return true;
1759}
Here is the call graph for this function:

◆ update()

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

Definition at line 2051 of file rpc_command_executor.cpp.

2052{
2055 epee::json_rpc::error error_resp;
2056
2057 std::string fail_message = "Problem fetching info";
2058
2059 req.command = command;
2060 if (m_is_rpc)
2061 {
2062 LOG_PRINT_L0("is rpc");
2063 if (!m_rpc_client->rpc_request(req, res, "/update", fail_message.c_str()))
2064 {
2065 LOG_PRINT_L0("update command failed");
2066 return true;
2067 }
2068 }
2069 else
2070 {
2071 LOG_PRINT_L0("not rpc");
2072 if (!m_rpc_server->on_update(req, res) || res.status != CORE_RPC_STATUS_OK)
2073 {
2074 LOG_PRINT_L0("rpc error");
2075 tools::fail_msg_writer() << make_error(fail_message, res.status);
2076 return true;
2077 }
2078 }
2079
2080 if (!res.update)
2081 {
2082 LOG_PRINT_L0("no update");
2083 tools::msg_writer() << "No update available";
2084 return true;
2085 }
2086
2087 tools::msg_writer() << "Update available: v" << res.version << ": " << res.user_uri << ", hash " << res.hash;
2088 if (command == "check")
2089 return true;
2090
2091 if (!res.path.empty())
2092 tools::msg_writer() << "Update downloaded to: " << res.path;
2093 else
2094 tools::msg_writer() << "Update download failed: " << res.status;
2095 if (command == "download")
2096 return true;
2097
2098 tools::msg_writer() << "'update' not implemented yet";
2099
2100 return true;
2101}
#define LOG_PRINT_L0(x)
Definition misc_log_ex.h:99
epee::misc_utils::struct_init< response_t > response
epee::misc_utils::struct_init< request_t > request
Here is the call graph for this function:

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