Electroneum
cryptonote::core_rpc_server Class Reference

#include <core_rpc_server.h>

Inheritance diagram for cryptonote::core_rpc_server:
Collaboration diagram for cryptonote::core_rpc_server:

Public Types

typedef epee::net_utils::connection_context_base connection_context
 

Public Member Functions

 core_rpc_server (core &cr, nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > > &p2p)
 
bool init (const boost::program_options::variables_map &vm, const bool restricted, const std::string &port)
 
network_type nettype () const
 
 CHAIN_HTTP_TO_MAP2 (connection_context)
 
bool on_get_height (const COMMAND_RPC_GET_HEIGHT::request &req, COMMAND_RPC_GET_HEIGHT::response &res, const connection_context *ctx=NULL)
 
bool on_get_blocks (const COMMAND_RPC_GET_BLOCKS_FAST::request &req, COMMAND_RPC_GET_BLOCKS_FAST::response &res, const connection_context *ctx=NULL)
 
bool on_get_alt_blocks_hashes (const COMMAND_RPC_GET_ALT_BLOCKS_HASHES::request &req, COMMAND_RPC_GET_ALT_BLOCKS_HASHES::response &res, const connection_context *ctx=NULL)
 
bool on_get_blocks_by_height (const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response &res, const connection_context *ctx=NULL)
 
bool on_get_hashes (const COMMAND_RPC_GET_HASHES_FAST::request &req, COMMAND_RPC_GET_HASHES_FAST::response &res, const connection_context *ctx=NULL)
 
bool on_get_transactions (const COMMAND_RPC_GET_TRANSACTIONS::request &req, COMMAND_RPC_GET_TRANSACTIONS::response &res, const connection_context *ctx=NULL)
 
bool on_is_key_image_spent (const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request &req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response &res, const connection_context *ctx=NULL)
 
bool on_get_indexes (const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request &req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response &res, const connection_context *ctx=NULL)
 
bool on_send_raw_tx (const COMMAND_RPC_SEND_RAW_TX::request &req, COMMAND_RPC_SEND_RAW_TX::response &res, const connection_context *ctx=NULL)
 
bool on_start_mining (const COMMAND_RPC_START_MINING::request &req, COMMAND_RPC_START_MINING::response &res, const connection_context *ctx=NULL)
 
bool on_stop_mining (const COMMAND_RPC_STOP_MINING::request &req, COMMAND_RPC_STOP_MINING::response &res, const connection_context *ctx=NULL)
 
bool on_mining_status (const COMMAND_RPC_MINING_STATUS::request &req, COMMAND_RPC_MINING_STATUS::response &res, const connection_context *ctx=NULL)
 
bool on_get_outs_bin (const COMMAND_RPC_GET_OUTPUTS_BIN::request &req, COMMAND_RPC_GET_OUTPUTS_BIN::response &res, const connection_context *ctx=NULL)
 
bool on_get_outs (const COMMAND_RPC_GET_OUTPUTS::request &req, COMMAND_RPC_GET_OUTPUTS::response &res, const connection_context *ctx=NULL)
 
bool on_get_info (const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, const connection_context *ctx=NULL)
 
bool on_get_net_stats (const COMMAND_RPC_GET_NET_STATS::request &req, COMMAND_RPC_GET_NET_STATS::response &res, const connection_context *ctx=NULL)
 
bool on_save_bc (const COMMAND_RPC_SAVE_BC::request &req, COMMAND_RPC_SAVE_BC::response &res, const connection_context *ctx=NULL)
 
bool on_get_peer_list (const COMMAND_RPC_GET_PEER_LIST::request &req, COMMAND_RPC_GET_PEER_LIST::response &res, const connection_context *ctx=NULL)
 
bool on_set_log_hash_rate (const COMMAND_RPC_SET_LOG_HASH_RATE::request &req, COMMAND_RPC_SET_LOG_HASH_RATE::response &res, const connection_context *ctx=NULL)
 
bool on_set_log_level (const COMMAND_RPC_SET_LOG_LEVEL::request &req, COMMAND_RPC_SET_LOG_LEVEL::response &res, const connection_context *ctx=NULL)
 
bool on_set_log_categories (const COMMAND_RPC_SET_LOG_CATEGORIES::request &req, COMMAND_RPC_SET_LOG_CATEGORIES::response &res, const connection_context *ctx=NULL)
 
bool on_get_transaction_pool (const COMMAND_RPC_GET_TRANSACTION_POOL::request &req, COMMAND_RPC_GET_TRANSACTION_POOL::response &res, const connection_context *ctx=NULL)
 
bool on_get_transaction_pool_hashes_bin (const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::response &res, const connection_context *ctx=NULL)
 
bool on_get_transaction_pool_hashes (const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response &res, const connection_context *ctx=NULL)
 
bool on_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)
 
bool on_stop_daemon (const COMMAND_RPC_STOP_DAEMON::request &req, COMMAND_RPC_STOP_DAEMON::response &res, const connection_context *ctx=NULL)
 
bool on_get_limit (const COMMAND_RPC_GET_LIMIT::request &req, COMMAND_RPC_GET_LIMIT::response &res, const connection_context *ctx=NULL)
 
bool on_set_limit (const COMMAND_RPC_SET_LIMIT::request &req, COMMAND_RPC_SET_LIMIT::response &res, const connection_context *ctx=NULL)
 
bool on_out_peers (const COMMAND_RPC_OUT_PEERS::request &req, COMMAND_RPC_OUT_PEERS::response &res, const connection_context *ctx=NULL)
 
bool on_in_peers (const COMMAND_RPC_IN_PEERS::request &req, COMMAND_RPC_IN_PEERS::response &res, const connection_context *ctx=NULL)
 
bool on_start_save_graph (const COMMAND_RPC_START_SAVE_GRAPH::request &req, COMMAND_RPC_START_SAVE_GRAPH::response &res, const connection_context *ctx=NULL)
 
bool on_stop_save_graph (const COMMAND_RPC_STOP_SAVE_GRAPH::request &req, COMMAND_RPC_STOP_SAVE_GRAPH::response &res, const connection_context *ctx=NULL)
 
bool on_update (const COMMAND_RPC_UPDATE::request &req, COMMAND_RPC_UPDATE::response &res, const connection_context *ctx=NULL)
 
bool on_get_output_distribution_bin (const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, const connection_context *ctx=NULL)
 
bool on_pop_blocks (const COMMAND_RPC_POP_BLOCKS::request &req, COMMAND_RPC_POP_BLOCKS::response &res, const connection_context *ctx=NULL)
 
bool on_get_balance (const COMMAND_RPC_GET_BALANCE::request &req, COMMAND_RPC_GET_BALANCE::response &res, const connection_context *ctx=NULL)
 
bool on_get_address_batch_history (const COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::request &req, COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::response &res, const connection_context *ctx=NULL)
 
bool on_getblockcount (const COMMAND_RPC_GETBLOCKCOUNT::request &req, COMMAND_RPC_GETBLOCKCOUNT::response &res, const connection_context *ctx=NULL)
 
bool on_getblockhash (const COMMAND_RPC_GETBLOCKHASH::request &req, COMMAND_RPC_GETBLOCKHASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_getblocktemplate (const COMMAND_RPC_GETBLOCKTEMPLATE::request &req, COMMAND_RPC_GETBLOCKTEMPLATE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_submitblock (const COMMAND_RPC_SUBMITBLOCK::request &req, COMMAND_RPC_SUBMITBLOCK::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_generateblocks (const COMMAND_RPC_GENERATEBLOCKS::request &req, COMMAND_RPC_GENERATEBLOCKS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_last_block_header (const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request &req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_block_header_by_hash (const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_block_header_by_height (const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_block_headers_range (const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request &req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_block (const COMMAND_RPC_GET_BLOCK::request &req, COMMAND_RPC_GET_BLOCK::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_connections (const COMMAND_RPC_GET_CONNECTIONS::request &req, COMMAND_RPC_GET_CONNECTIONS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_info_json (const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_hard_fork_info (const COMMAND_RPC_HARD_FORK_INFO::request &req, COMMAND_RPC_HARD_FORK_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_set_bans (const COMMAND_RPC_SETBANS::request &req, COMMAND_RPC_SETBANS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_bans (const COMMAND_RPC_GETBANS::request &req, COMMAND_RPC_GETBANS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_flush_txpool (const COMMAND_RPC_FLUSH_TRANSACTION_POOL::request &req, COMMAND_RPC_FLUSH_TRANSACTION_POOL::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_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)
 
bool on_get_version (const COMMAND_RPC_GET_VERSION::request &req, COMMAND_RPC_GET_VERSION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_coinbase_tx_sum (const COMMAND_RPC_GET_COINBASE_TX_SUM::request &req, COMMAND_RPC_GET_COINBASE_TX_SUM::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_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_alternate_chains (const COMMAND_RPC_GET_ALTERNATE_CHAINS::request &req, COMMAND_RPC_GET_ALTERNATE_CHAINS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_relay_tx (const COMMAND_RPC_RELAY_TX::request &req, COMMAND_RPC_RELAY_TX::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_sync_info (const COMMAND_RPC_SYNC_INFO::request &req, COMMAND_RPC_SYNC_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_txpool_backlog (const COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_get_output_distribution (const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_prune_blockchain (const COMMAND_RPC_PRUNE_BLOCKCHAIN::request &req, COMMAND_RPC_PRUNE_BLOCKCHAIN::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_set_validator_key (const COMMAND_RPC_SET_VALIDATOR_KEY::request &req, COMMAND_RPC_SET_VALIDATOR_KEY::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_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)
 
bool on_sign_message (const COMMAND_RPC_SIGN_MESSAGE::request &req, COMMAND_RPC_SIGN_MESSAGE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
bool on_inject_emergency_vlist (const COMMAND_RPC_INJECT_EMERGENCY_VLIST::request &req, COMMAND_RPC_INJECT_EMERGENCY_VLIST::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
 
- Public Member Functions inherited from epee::http_server_impl_base< core_rpc_server >
 http_server_impl_base ()
 
 http_server_impl_base (boost::asio::io_service &external_io_service)
 
bool init (std::function< void(size_t, uint8_t *)> rng, const std::string &bind_port="0", const std::string &bind_ip="0.0.0.0", std::vector< std::string > access_control_origins=std::vector< std::string >(), boost::optional< net_utils::http::login > user=boost::none, net_utils::ssl_options_t ssl_options=net_utils::ssl_support_t::e_ssl_support_autodetect)
 
bool run (size_t threads_count, bool wait=true)
 
bool deinit ()
 
bool timed_wait_server_stop (uint64_t ms)
 
bool send_stop_signal ()
 
int get_binded_port ()
 
long get_connections_count () const
 
- Public Member Functions inherited from epee::net_utils::http::i_http_server_handler< epee::net_utils::connection_context_base >
virtual ~i_http_server_handler ()
 
virtual bool handle_http_request (const http_request_info &query_info, http_response_info &response, epee::net_utils::connection_context_base &m_conn_context)=0
 
virtual bool init_server_thread ()
 
virtual bool deinit_server_thread ()
 

Static Public Member Functions

static void init_options (boost::program_options::options_description &desc)
 

Static Public Attributes

static const command_line::arg_descriptor< boolarg_public_node
 
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
 
static const command_line::arg_descriptor< std::string > arg_rpc_restricted_bind_port
 
static const command_line::arg_descriptor< boolarg_restricted_rpc
 
static const command_line::arg_descriptor< std::string > arg_rpc_ssl
 
static const command_line::arg_descriptor< std::string > arg_rpc_ssl_private_key
 
static const command_line::arg_descriptor< std::string > arg_rpc_ssl_certificate
 
static const command_line::arg_descriptor< std::string > arg_rpc_ssl_ca_certificates
 
static const command_line::arg_descriptor< std::vector< std::string > > arg_rpc_ssl_allowed_fingerprints
 
static const command_line::arg_descriptor< boolarg_rpc_ssl_allow_any_cert
 
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_address
 
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_login
 

Additional Inherited Members

- Protected Attributes inherited from epee::http_server_impl_base< core_rpc_server >
net_utils::boosted_tcp_server< net_utils::http::http_custom_handler< epee::net_utils::connection_context_base > > m_net_server
 

Detailed Description

Definition at line 56 of file core_rpc_server.h.

Member Typedef Documentation

◆ connection_context

Constructor & Destructor Documentation

◆ core_rpc_server()

cryptonote::core_rpc_server::core_rpc_server ( core cr,
nodetool::node_server< cryptonote::t_cryptonote_protocol_handler< cryptonote::core > > &  p2p 
)

Definition at line 103 of file core_rpc_server.cpp.

107  : m_core(cr)
108  , m_p2p(p2p)
109  {}

Member Function Documentation

◆ CHAIN_HTTP_TO_MAP2()

cryptonote::core_rpc_server::CHAIN_HTTP_TO_MAP2 ( connection_context  )

◆ init()

bool cryptonote::core_rpc_server::init ( const boost::program_options::variables_map &  vm,
const bool  restricted,
const std::string &  port 
)

Definition at line 111 of file core_rpc_server.cpp.

116  {
117  m_restricted = restricted;
118  m_net_server.set_threads_prefix("RPC");
119 
120  auto rpc_config = cryptonote::rpc_args::process(vm, true);
121  if (!rpc_config)
122  return false;
123 
124  m_bootstrap_daemon_address = command_line::get_arg(vm, arg_bootstrap_daemon_address);
125  if (!m_bootstrap_daemon_address.empty())
126  {
127  const std::string &bootstrap_daemon_login = command_line::get_arg(vm, arg_bootstrap_daemon_login);
128  const auto loc = bootstrap_daemon_login.find(':');
129  if (!bootstrap_daemon_login.empty() && loc != std::string::npos)
130  {
132  login.username = bootstrap_daemon_login.substr(0, loc);
133  login.password = bootstrap_daemon_login.substr(loc + 1);
134  m_http_client.set_server(m_bootstrap_daemon_address, login, epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
135  }
136  else
137  {
138  m_http_client.set_server(m_bootstrap_daemon_address, boost::none, epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
139  }
140  m_should_use_bootstrap_daemon = true;
141  }
142  else
143  {
144  m_should_use_bootstrap_daemon = false;
145  }
146  m_was_bootstrap_ever_used = false;
147 
148  boost::optional<epee::net_utils::http::login> http_login{};
149 
150  if (rpc_config->login)
151  http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password());
152 
153  auto rng = [](size_t len, uint8_t *ptr){ return crypto::rand(len, ptr); };
155  rng, std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login), std::move(rpc_config->ssl_options)
156  );
157  }
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_address
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_login
bool init(std::function< void(size_t, uint8_t *)> rng, const std::string &bind_port="0", const std::string &bind_ip="0.0.0.0", std::vector< std::string > access_control_origins=std::vector< std::string >(), boost::optional< net_utils::http::login > user=boost::none, net_utils::ssl_options_t ssl_options=net_utils::ssl_support_t::e_ssl_support_autodetect)
net_utils::boosted_tcp_server< net_utils::http::http_custom_handler< epee::net_utils::connection_context_base > > m_net_server
bool set_server(const std::string &address, boost::optional< login > user, ssl_options_t ssl_options=ssl_support_t::e_ssl_support_autodetect)
Definition: http_client.h:302
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
Definition: command_line.h:271
void rand(size_t N, uint8_t *bytes)
Definition: crypto.h:207
::std::string string
Definition: gtest-port.h:1097
const T & move(const T &t)
Definition: gtest-port.h:1317
boost::endian::big_uint16_t port
Definition: socks.cpp:60
unsigned char uint8_t
Definition: stdint.h:124
static boost::optional< rpc_args > process(const boost::program_options::variables_map &vm, const bool any_cert_option=false)
Definition: rpc_args.cpp:125
wipeable_string password
Definition: http_auth.h:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_options()

void cryptonote::core_rpc_server::init_options ( boost::program_options::options_description &  desc)
static

Definition at line 93 of file core_rpc_server.cpp.

94  {
101  }
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
static const command_line::arg_descriptor< std::string > arg_rpc_restricted_bind_port
static const command_line::arg_descriptor< bool > arg_restricted_rpc
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Definition: command_line.h:188
static void init_options(boost::program_options::options_description &desc, const bool any_cert_option=false)
Definition: rpc_args.cpp:108
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nettype()

network_type cryptonote::core_rpc_server::nettype ( ) const
inline

Definition at line 86 of file core_rpc_server.h.

86 { return m_core.get_nettype(); }
network_type get_nettype() const
get the network type we're on
Here is the caller graph for this function:

◆ on_flush_txpool()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1940 of file core_rpc_server.cpp.

1941  {
1943 
1944  bool failed = false;
1945  std::vector<crypto::hash> txids;
1946  if (req.txids.empty())
1947  {
1948  std::vector<transaction> pool_txs;
1949  bool r = m_core.get_pool_transactions(pool_txs);
1950  if (!r)
1951  {
1952  res.status = "Failed to get txpool contents";
1953  return true;
1954  }
1955  for (const auto &tx: pool_txs)
1956  {
1957  txids.push_back(cryptonote::get_transaction_hash(tx));
1958  }
1959  }
1960  else
1961  {
1962  for (const auto &str: req.txids)
1963  {
1964  cryptonote::blobdata txid_data;
1965  if(!epee::string_tools::parse_hexstr_to_binbuff(str, txid_data))
1966  {
1967  failed = true;
1968  }
1969  else
1970  {
1971  crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
1972  txids.push_back(txid);
1973  }
1974  }
1975  }
1976  if (!m_core.get_blockchain_storage().flush_txes_from_pool(txids))
1977  {
1978  res.status = "Failed to remove one or more tx(es)";
1979  return false;
1980  }
1981 
1982  if (failed)
1983  {
1984  if (txids.empty())
1985  res.status = "Failed to parse txid";
1986  else
1987  res.status = "Failed to parse some of the txids";
1988  return false;
1989  }
1990 
1991  res.status = CORE_RPC_STATUS_OK;
1992  return true;
1993  }
bool flush_txes_from_pool(const std::vector< crypto::hash > &txids)
remove transactions from the transaction pool (if present)
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)
Blockchain & get_blockchain_storage()
gets the Blockchain instance
bool get_pool_transactions(std::vector< transaction > &txs, bool include_unrelayed_txes=true) const
get a list of all transactions in the pool
#define CORE_RPC_STATUS_OK
const char * res
Definition: hmac_keccak.cpp:41
POD_CLASS hash
Definition: hash.h:50
crypto::hash get_transaction_hash(const transaction &t)
std::string blobdata
Definition: blobdatatype.h:39
bool parse_hexstr_to_binbuff(const epee::span< const char > s, epee::span< char > &res)
Definition: string_tools.h:92
#define PERF_TIMER(name)
Definition: perf_timer.h:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_generate_ed25519_keypair()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2405 of file core_rpc_server.cpp.

2406  {
2407  std::vector<std::string> v = m_core.generate_ed25519_keypair();
2408  if(v.size() == 0) {
2410  error_resp.message = "Failed to generate ED25519-Donna keypair.";
2411  return false;
2412  }
2413 
2414  res.privateKey = v[0];
2415  res.publicKey = v[1];
2416 
2417  res.status = CORE_RPC_STATUS_OK;
2418  return true;
2419  }
std::vector< std::string > generate_ed25519_keypair()
#define CORE_RPC_ERROR_CODE_INTERNAL_ERROR
Here is the caller graph for this function:

◆ on_generateblocks()

bool cryptonote::core_rpc_server::on_generateblocks ( const COMMAND_RPC_GENERATEBLOCKS::request req,
COMMAND_RPC_GENERATEBLOCKS::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1377 of file core_rpc_server.cpp.

1378  {
1380 
1381  CHECK_CORE_READY();
1382 
1383  res.status = CORE_RPC_STATUS_OK;
1384 
1385  if(m_core.get_nettype() != FAKECHAIN)
1386  {
1388  error_resp.message = "Regtest required when generating blocks";
1389  return false;
1390  }
1391 
1396 
1397  template_req.reserve_size = 1;
1398  template_req.wallet_address = req.wallet_address;
1399  template_req.prev_block = req.prev_block;
1400  submit_req.push_back(boost::value_initialized<std::string>());
1402 
1403  for(size_t i = 0; i < req.amount_of_blocks; i++)
1404  {
1405  bool r = on_getblocktemplate(template_req, template_res, error_resp, ctx);
1406  res.status = template_res.status;
1407  template_req.prev_block.clear();
1408 
1409  if (!r) return false;
1410 
1411  blobdata blockblob;
1412  if(!string_tools::parse_hexstr_to_binbuff(template_res.blocktemplate_blob, blockblob))
1413  {
1415  error_resp.message = "Wrong block blob";
1416  return false;
1417  }
1418  block b;
1419  if(!parse_and_validate_block_from_blob(blockblob, b))
1420  {
1422  error_resp.message = "Wrong block blob";
1423  return false;
1424  }
1425  b.nonce = req.starting_nonce;
1426  miner::find_nonce_for_given_block(b, template_res.difficulty, template_res.height);
1427 
1428  submit_req.front() = string_tools::buff_to_hex_nodelimer(block_to_blob(b));
1429  r = on_submitblock(submit_req, submit_res, error_resp, ctx);
1430  res.status = submit_res.status;
1431 
1432  if (!r) return false;
1433 
1434  res.blocks.push_back(epee::string_tools::pod_to_hex(get_block_hash(b)));
1435  template_req.prev_block = res.blocks.back();
1436  res.height = template_res.height;
1437  }
1438 
1439  return true;
1440  }
uint64_t get_current_blockchain_height() const
get the current height of the blockchain
Definition: blockchain.cpp:319
bool on_submitblock(const COMMAND_RPC_SUBMITBLOCK::request &req, COMMAND_RPC_SUBMITBLOCK::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_getblocktemplate(const COMMAND_RPC_GETBLOCKTEMPLATE::request &req, COMMAND_RPC_GETBLOCKTEMPLATE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_generateblocks(const COMMAND_RPC_GENERATEBLOCKS::request &req, COMMAND_RPC_GENERATEBLOCKS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
static bool find_nonce_for_given_block(block &bl, const difficulty_type &diffic, uint64_t height)
Definition: miner.cpp:471
#define CHECK_CORE_READY()
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB
#define CORE_RPC_ERROR_CODE_REGTEST_REQUIRED
bool get_block_hash(const block &b, crypto::hash &res)
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash *block_hash)
blobdata block_to_blob(const block &b)
std::string pod_to_hex(const t_pod_type &s)
Definition: string_tools.h:317
std::string buff_to_hex_nodelimer(const std::string &src)
Definition: string_tools.h:87
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:

◆ on_get_address_batch_history()

bool cryptonote::core_rpc_server::on_get_address_batch_history ( const COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::request req,
COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::response res,
const connection_context ctx = NULL 
)

Definition at line 1793 of file core_rpc_server.cpp.

1794  {
1796  CHECK_CORE_READY();
1797 
1798  if (req.etn_address.empty())
1799  {
1800  res.status = "Failed: Request attribute <etn_address> is mandatory.";
1801  return true;
1802  }
1803 
1804  address_parse_info addr_info;
1805  if(!get_account_address_from_str(addr_info, nettype(), req.etn_address))
1806  {
1807  res.status = "Failed: can't parse address from <etn_address> = " + req.etn_address;
1808  return true;
1809  }
1810 
1811  try
1812  {
1813  std::vector<address_outputs> outs = m_core.get_address_batch_history(addr_info, req.start_out_id, req.batch_size, req.desc);
1814  if(!outs.empty() && outs.size() > req.batch_size)
1815  {
1816  res.next_out_id = outs.at(outs.size() - 1).out_id;
1817  res.last_page = false;
1818  outs.pop_back();
1819  }
1820  else
1821  {
1822  res.last_page = true;
1823  }
1824 
1825  for(auto out: outs)
1826  {
1827  res.txs.push_back(epee::string_tools::pod_to_hex(out.tx_hash));
1828  }
1829 
1830  res.status = "OK";
1831  }
1832  catch(const std::exception& e)
1833  {
1834  res.status = "Failed: " + std::string(e.what());
1835  return true;
1836  }
1837 
1838  return true;
1839  }
bool on_get_address_batch_history(const COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::request &req, COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::response &res, const connection_context *ctx=NULL)
network_type nettype() const
std::vector< address_outputs > get_address_batch_history(const address_parse_info &addr, const uint64_t &start_tx_id=0, const uint64_t &batch_size=100, bool desc=false)
bool get_account_address_from_str(address_parse_info &info, network_type nettype, std::string const &str)
Here is the call graph for this function:

◆ on_get_alt_blocks_hashes()

bool cryptonote::core_rpc_server::on_get_alt_blocks_hashes ( const COMMAND_RPC_GET_ALT_BLOCKS_HASHES::request req,
COMMAND_RPC_GET_ALT_BLOCKS_HASHES::response res,
const connection_context ctx = NULL 
)

Definition at line 360 of file core_rpc_server.cpp.

361  {
363  bool r;
364  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_ALT_BLOCKS_HASHES>(invoke_http_mode::JON, "/get_alt_blocks_hashes", req, res, r))
365  return r;
366 
367  std::vector<block> blks;
368 
369  if(!m_core.get_alternative_blocks(blks))
370  {
371  res.status = "Failed";
372  return false;
373  }
374 
375  res.blks_hashes.reserve(blks.size());
376 
377  for (auto const& blk: blks)
378  {
379  res.blks_hashes.push_back(epee::string_tools::pod_to_hex(get_block_hash(blk)));
380  }
381 
382  MDEBUG("on_get_alt_blocks_hashes: " << blks.size() << " blocks " );
383  res.status = CORE_RPC_STATUS_OK;
384  return true;
385  }
bool on_get_alt_blocks_hashes(const COMMAND_RPC_GET_ALT_BLOCKS_HASHES::request &req, COMMAND_RPC_GET_ALT_BLOCKS_HASHES::response &res, const connection_context *ctx=NULL)
bool get_alternative_blocks(std::vector< block > &blocks) const
compiles a list of all blocks stored as alternative chains
#define MDEBUG(x)
Definition: misc_log_ex.h:76
Here is the call graph for this function:

◆ on_get_alternate_chains()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2067 of file core_rpc_server.cpp.

2068  {
2070  try
2071  {
2072  std::list<std::pair<Blockchain::block_extended_info, std::vector<crypto::hash>>> chains = m_core.get_blockchain_storage().get_alternative_chains();
2073  for (const auto &i: chains)
2074  {
2075  difficulty_type wdiff = i.first.cumulative_difficulty;
2076  res.chains.push_back(COMMAND_RPC_GET_ALTERNATE_CHAINS::chain_info{epee::string_tools::pod_to_hex(get_block_hash(i.first.bl)), i.first.height, i.second.size(), 0, "", 0, {}, std::string()});
2077  store_difficulty(wdiff, res.chains.back().difficulty, res.chains.back().wide_difficulty, res.chains.back().difficulty_top64);
2078  res.chains.back().block_hashes.reserve(i.second.size());
2079  for (const crypto::hash &block_id: i.second)
2080  res.chains.back().block_hashes.push_back(epee::string_tools::pod_to_hex(block_id));
2081  if (i.first.height < i.second.size())
2082  {
2083  res.status = "Error finding alternate chain attachment point";
2084  return true;
2085  }
2086  cryptonote::block main_chain_parent_block;
2087  try { main_chain_parent_block = m_core.get_blockchain_storage().get_db().get_block_from_height(i.first.height - i.second.size()); }
2088  catch (const std::exception &e) { res.status = "Error finding alternate chain attachment point"; return true; }
2089  res.chains.back().main_chain_parent_block = epee::string_tools::pod_to_hex(get_block_hash(main_chain_parent_block));
2090  }
2091  res.status = CORE_RPC_STATUS_OK;
2092  }
2093  catch (...)
2094  {
2095  res.status = "Error retrieving alternate chains";
2096  }
2097  return true;
2098  }
virtual block get_block_from_height(const uint64_t &height) const
fetch a block by height
std::list< std::pair< block_extended_info, std::vector< crypto::hash > > > get_alternative_chains() const
returns a set of known alternate chains
const BlockchainDB & get_db() const
get a reference to the BlockchainDB in use by Blockchain
Definition: blockchain.h:953
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)
boost::multiprecision::uint128_t difficulty_type
Definition: difficulty.h:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_balance()

bool cryptonote::core_rpc_server::on_get_balance ( const COMMAND_RPC_GET_BALANCE::request req,
COMMAND_RPC_GET_BALANCE::response res,
const connection_context ctx = NULL 
)

Definition at line 1768 of file core_rpc_server.cpp.

1769  {
1771 
1772  CHECK_CORE_READY();
1773 
1774  if (req.etn_address.empty())
1775  {
1776  res.status = "Failed: Request attribute <etn_address> is mandatory.";
1777  return true;
1778  }
1779 
1780  address_parse_info addr_info;
1781  if(!get_account_address_from_str(addr_info, nettype(), req.etn_address))
1782  {
1783  res.status = "Failed: can't parse address from <etn_address> = " + req.etn_address;
1784  return true;
1785  }
1786 
1787  res.balance = m_core.get_balance(addr_info);
1788  res.status = "OK";
1789 
1790  return true;
1791  }
bool on_get_balance(const COMMAND_RPC_GET_BALANCE::request &req, COMMAND_RPC_GET_BALANCE::response &res, const connection_context *ctx=NULL)
uint64_t get_balance(const address_parse_info &addr)
Here is the call graph for this function:

◆ on_get_bans()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1873 of file core_rpc_server.cpp.

1874  {
1876 
1877  auto now = time(nullptr);
1878  std::map<std::string, time_t> blocked_hosts = m_p2p.get_blocked_hosts();
1879  for (std::map<std::string, time_t>::const_iterator i = blocked_hosts.begin(); i != blocked_hosts.end(); ++i)
1880  {
1881  if (i->second > now) {
1882  COMMAND_RPC_GETBANS::ban b;
1883  b.host = i->first;
1884  b.ip = 0;
1885  uint32_t ip;
1887  b.ip = ip;
1888  b.seconds = i->second - now;
1889  res.bans.push_back(b);
1890  }
1891  }
1892 
1893  res.status = CORE_RPC_STATUS_OK;
1894  return true;
1895  }
time_t time
Definition: blockchain.cpp:93
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)
virtual std::map< std::string, time_t > get_blocked_hosts()
Definition: net_node.h:252
bool get_ip_int32_from_string(uint32_t &ip, const std::string &ip_str)
boost::endian::big_uint32_t ip
Definition: socks.cpp:61
unsigned int uint32_t
Definition: stdint.h:126
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_base_fee_estimate()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2054 of file core_rpc_server.cpp.

2055  {
2057  bool r;
2058  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BASE_FEE_ESTIMATE>(invoke_http_mode::JON_RPC, "get_fee_estimate", req, res, r))
2059  return r;
2060 
2061  res.fee = m_core.get_blockchain_storage().get_dynamic_base_fee_estimate(req.grace_blocks);
2062  res.quantization_mask = Blockchain::get_fee_quantization_mask();
2063  res.status = CORE_RPC_STATUS_OK;
2064  return true;
2065  }
uint64_t get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
get dynamic per kB or byte fee estimate for the next few blocks
static uint64_t get_fee_quantization_mask()
get fee quantization mask
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_block()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1704 of file core_rpc_server.cpp.

1705  {
1707  bool r;
1708  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK>(invoke_http_mode::JON_RPC, "getblock", req, res, r))
1709  return r;
1710 
1711  crypto::hash block_hash;
1712  if (!req.hash.empty())
1713  {
1714  bool hash_parsed = parse_hash256(req.hash, block_hash);
1715  if(!hash_parsed)
1716  {
1718  error_resp.message = "Failed to parse hex representation of block hash. Hex = " + req.hash + '.';
1719  return false;
1720  }
1721  }
1722  else
1723  {
1724  if(m_core.get_current_blockchain_height() <= req.height)
1725  {
1727  error_resp.message = std::string("Requested block height: ") + std::to_string(req.height) + " greater than current top block height: " + std::to_string(m_core.get_current_blockchain_height() - 1);
1728  return false;
1729  }
1730  block_hash = m_core.get_block_id_by_height(req.height);
1731  }
1732  block blk;
1733  bool orphan = false;
1734  bool have_block = m_core.get_block_by_hash(block_hash, blk, &orphan);
1735  if (!have_block)
1736  {
1738  error_resp.message = "Internal error: can't get block by hash. Hash = " + req.hash + '.';
1739  return false;
1740  }
1741  if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
1742  {
1744  error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
1745  return false;
1746  }
1747  uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
1748  const bool restricted = m_restricted && ctx;
1749  bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header, req.fill_pow_hash && !restricted);
1750  if (!response_filled)
1751  {
1753  error_resp.message = "Internal error: can't produce valid response.";
1754  return false;
1755  }
1757  for (size_t n = 0; n < blk.tx_hashes.size(); ++n)
1758  {
1759  res.tx_hashes.push_back(epee::string_tools::pod_to_hex(blk.tx_hashes[n]));
1760  }
1762  res.json = obj_to_json_str(blk);
1763  res.status = CORE_RPC_STATUS_OK;
1764 
1765  return true;
1766  }
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)
uint64_t get_current_blockchain_height() const
get the current height of the blockchain
crypto::hash get_block_id_by_height(uint64_t height) const
gets a block's hash given a height
bool get_block_by_hash(const crypto::hash &h, block &blk, bool *orphan=NULL) const
gets the block with a given hash
#define CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT
#define CORE_RPC_ERROR_CODE_WRONG_PARAM
bool parse_hash256(const std::string &str_hash, crypto::hash &hash)
std::string obj_to_json_str(T &obj)
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
std::string to_string(t_connection_type type)
unsigned __int64 uint64_t
Definition: stdint.h:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_block_header_by_hash()

bool cryptonote::core_rpc_server::on_get_block_header_by_hash ( const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request req,
COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1575 of file core_rpc_server.cpp.

1576  {
1578  bool r;
1579  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH>(invoke_http_mode::JON_RPC, "getblockheaderbyhash", req, res, r))
1580  return r;
1581 
1582  crypto::hash block_hash;
1583  bool hash_parsed = parse_hash256(req.hash, block_hash);
1584  if(!hash_parsed)
1585  {
1587  error_resp.message = "Failed to parse hex representation of block hash. Hex = " + req.hash + '.';
1588  return false;
1589  }
1590  block blk;
1591  bool orphan = false;
1592  bool have_block = m_core.get_block_by_hash(block_hash, blk, &orphan);
1593  if (!have_block)
1594  {
1596  error_resp.message = "Internal error: can't get block by hash. Hash = " + req.hash + '.';
1597  return false;
1598  }
1599  if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
1600  {
1602  error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
1603  return false;
1604  }
1605  uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
1606  const bool restricted = m_restricted && ctx;
1607  bool response_filled = fill_block_header_response(blk, orphan, block_height, block_hash, res.block_header, req.fill_pow_hash && !restricted);
1608  if (!response_filled)
1609  {
1611  error_resp.message = "Internal error: can't produce valid response.";
1612  return false;
1613  }
1614  res.status = CORE_RPC_STATUS_OK;
1615  return true;
1616  }
bool on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
Here is the call graph for this function:

◆ on_get_block_header_by_height()

bool cryptonote::core_rpc_server::on_get_block_header_by_height ( const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request req,
COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1670 of file core_rpc_server.cpp.

1671  {
1673  bool r;
1674  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT>(invoke_http_mode::JON_RPC, "getblockheaderbyheight", req, res, r))
1675  return r;
1676 
1677  if(m_core.get_current_blockchain_height() <= req.height)
1678  {
1680  error_resp.message = std::string("Requested block height: ") + std::to_string(req.height) + " greater than current top block height: " + std::to_string(m_core.get_current_blockchain_height() - 1);
1681  return false;
1682  }
1683  crypto::hash block_hash = m_core.get_block_id_by_height(req.height);
1684  block blk;
1685  bool have_block = m_core.get_block_by_hash(block_hash, blk);
1686  if (!have_block)
1687  {
1689  error_resp.message = "Internal error: can't get block by height. Height = " + std::to_string(req.height) + '.';
1690  return false;
1691  }
1692  const bool restricted = m_restricted && ctx;
1693  bool response_filled = fill_block_header_response(blk, false, req.height, block_hash, res.block_header, req.fill_pow_hash && !restricted);
1694  if (!response_filled)
1695  {
1697  error_resp.message = "Internal error: can't produce valid response.";
1698  return false;
1699  }
1700  res.status = CORE_RPC_STATUS_OK;
1701  return true;
1702  }
bool on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
Here is the call graph for this function:

◆ on_get_block_headers_range()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1618 of file core_rpc_server.cpp.

1619  {
1621  bool r;
1622  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADERS_RANGE>(invoke_http_mode::JON_RPC, "getblockheadersrange", req, res, r))
1623  return r;
1624 
1625  const uint64_t bc_height = m_core.get_current_blockchain_height();
1626  if (req.start_height >= bc_height || req.end_height >= bc_height || req.start_height > req.end_height)
1627  {
1629  error_resp.message = "Invalid start/end heights.";
1630  return false;
1631  }
1632  for (uint64_t h = req.start_height; h <= req.end_height; ++h)
1633  {
1634  crypto::hash block_hash = m_core.get_block_id_by_height(h);
1635  block blk;
1636  bool have_block = m_core.get_block_by_hash(block_hash, blk);
1637  if (!have_block)
1638  {
1640  error_resp.message = "Internal error: can't get block by height. Height = " + boost::lexical_cast<std::string>(h) + ". Hash = " + epee::string_tools::pod_to_hex(block_hash) + '.';
1641  return false;
1642  }
1643  if (blk.miner_tx.vin.size() != 1 || blk.miner_tx.vin.front().type() != typeid(txin_gen))
1644  {
1646  error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
1647  return false;
1648  }
1649  uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
1650  if (block_height != h)
1651  {
1653  error_resp.message = "Internal error: coinbase transaction in the block has the wrong height";
1654  return false;
1655  }
1656  res.headers.push_back(block_header_response());
1657  const bool restricted = m_restricted && ctx;
1658  bool response_filled = fill_block_header_response(blk, false, block_height, block_hash, res.headers.back(), req.fill_pow_hash && !restricted);
1659  if (!response_filled)
1660  {
1662  error_resp.message = "Internal error: can't produce valid response.";
1663  return false;
1664  }
1665  }
1666  res.status = CORE_RPC_STATUS_OK;
1667  return true;
1668  }
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)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_blocks()

bool cryptonote::core_rpc_server::on_get_blocks ( const COMMAND_RPC_GET_BLOCKS_FAST::request req,
COMMAND_RPC_GET_BLOCKS_FAST::response res,
const connection_context ctx = NULL 
)

Definition at line 281 of file core_rpc_server.cpp.

282  {
284  bool r;
285  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCKS_FAST>(invoke_http_mode::BIN, "/getblocks.bin", req, res, r))
286  return r;
287 
288  //Vector of pairs where each pair is: item#1) pair<block blob, hash> item#2)vector of pairs of <tx hash, tx blob>
289  std::vector<
290  std::pair<
291  std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> >
292  >
293  > bs;
294 
295  if(!m_core.find_blockchain_supplement(req.start_height, req.block_ids, bs, res.current_height, res.start_height, req.prune, !req.no_miner_tx, COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT))
296  {
297  res.status = "Failed";
298  return false;
299  }
300 
301  size_t pruned_size = 0, unpruned_size = 0, ntxes = 0;
302 
303  // Preallocate space in the RPC result
304  res.blocks.reserve(bs.size());
305  res.output_indices.reserve(bs.size());
306 
307  // Loop over all of the block data and populate the rpc response
308  uint64_t height_counter = res.start_height;
309  for(auto& bd: bs)
310  {
311  res.blocks.resize(res.blocks.size()+1);
312  res.blocks.back().block = bd.first.first; // add block hash to response
313  pruned_size += bd.first.first.size();
314  unpruned_size += bd.first.first.size();
315  res.output_indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices());
316  ntxes += bd.second.size();
317  res.output_indices.back().indices.reserve(1 + bd.second.size());
318  if (req.no_miner_tx)
319  res.output_indices.back().indices.push_back(COMMAND_RPC_GET_BLOCKS_FAST::tx_output_indices());
320  res.blocks.back().txs.reserve(bd.second.size());
321 
322  //go over the transactions in bs first
323  for (std::vector<std::pair<crypto::hash, cryptonote::blobdata>>::iterator i = bd.second.begin(); i != bd.second.end(); ++i)
324  {
325  unpruned_size += i->second.size();
326  res.blocks.back().txs.push_back(std::move(i->second)); //add a tx blob to rpc response
327  i->second.clear();
328  i->second.shrink_to_fit();
329  pruned_size += res.blocks.back().txs.back().size();
330  }
331 
332  //no need to look up indexes for v2+ txes
333  auto v10_height = nettype() == cryptonote::network_type::MAINNET ? 1175315 : 1165235;
334  const size_t n_txes_to_lookup = height_counter >= v10_height ? 0 : (bd.second.size() + (req.no_miner_tx ? 0 : 1));
335  if (n_txes_to_lookup > 0)
336  {
337  std::vector<std::vector<uint64_t>> indices;
338  //either pass the first tx hash or the block hash depending on whether it was a miner tx or not
339  bool r = m_core.get_tx_outputs_gindexs(req.no_miner_tx ? bd.second.front().first : bd.first.second, n_txes_to_lookup, indices);
340  if (!r)
341  {
342  res.status = "Failed";
343  return false;
344  }
345  if (indices.size() != n_txes_to_lookup || res.output_indices.back().indices.size() != (req.no_miner_tx ? 1 : 0))
346  {
347  res.status = "Failed";
348  return false;
349  }
350  for (size_t i = 0; i < indices.size(); ++i)
351  res.output_indices.back().indices.push_back({std::move(indices[i])});
352  }
353  ++height_counter;
354  }
355 
356  MDEBUG("on_get_blocks: " << bs.size() << " blocks, " << ntxes << " txes, pruned size " << pruned_size << ", unpruned size " << unpruned_size);
357  res.status = CORE_RPC_STATUS_OK;
358  return true;
359  }
bool on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request &req, COMMAND_RPC_GET_BLOCKS_FAST::response &res, const connection_context *ctx=NULL)
bool find_blockchain_supplement(const std::list< crypto::hash > &qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request &resp) const
get recent block hashes for a foreign chain
bool get_tx_outputs_gindexs(const crypto::hash &tx_id, std::vector< uint64_t > &indexs) const
gets the global indices for outputs from a given transaction
#define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT
std::vector< tx_output_indices > block_output_indices
std::vector< uint64_t > tx_output_indices
Here is the call graph for this function:

◆ on_get_blocks_by_height()

bool cryptonote::core_rpc_server::on_get_blocks_by_height ( const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request req,
COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response res,
const connection_context ctx = NULL 
)

Definition at line 387 of file core_rpc_server.cpp.

388  {
390  bool r;
391  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCKS_BY_HEIGHT>(invoke_http_mode::BIN, "/getblocks_by_height.bin", req, res, r))
392  return r;
393 
394  res.status = "Failed";
395  res.blocks.clear();
396  res.blocks.reserve(req.heights.size());
397  for (uint64_t height : req.heights)
398  {
399  block blk;
400  try
401  {
403  }
404  catch (...)
405  {
406  res.status = "Error retrieving block at height " + std::to_string(height);
407  return true;
408  }
409  std::vector<transaction> txs;
410  std::vector<crypto::hash> missed_txs;
411  m_core.get_transactions(blk.tx_hashes, txs, missed_txs);
412  res.blocks.resize(res.blocks.size() + 1);
413  res.blocks.back().block = block_to_blob(blk);
414  for (auto& tx : txs)
415  res.blocks.back().txs.push_back(tx_to_blob(tx));
416  }
417  res.status = CORE_RPC_STATUS_OK;
418  return true;
419  }
uint64_t height
Definition: blockchain.cpp:91
bool on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response &res, const connection_context *ctx=NULL)
bool get_transactions(const std::vector< crypto::hash > &txs_ids, std::vector< cryptonote::blobdata > &txs, std::vector< crypto::hash > &missed_txs) const
blobdata tx_to_blob(const transaction &tx)
Here is the call graph for this function:

◆ on_get_coinbase_tx_sum()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2044 of file core_rpc_server.cpp.

2045  {
2047  std::pair<uint64_t, uint64_t> amounts = m_core.get_coinbase_tx_sum(req.height, req.count);
2048  res.emission_amount = amounts.first;
2049  res.fee_amount = amounts.second;
2050  res.status = CORE_RPC_STATUS_OK;
2051  return true;
2052  }
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)
std::pair< uint64_t, uint64_t > get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
get the sum of coinbase tx amounts between blocks
Here is the caller graph for this function:

◆ on_get_connections()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1841 of file core_rpc_server.cpp.

1842  {
1844 
1845  res.connections = m_p2p.get_payload_object().get_connections();
1846 
1847  res.status = CORE_RPC_STATUS_OK;
1848 
1849  return true;
1850  }
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::list< connection_info > get_connections()
t_payload_net_handler & get_payload_object()
Here is the caller graph for this function:

◆ on_get_hashes()

bool cryptonote::core_rpc_server::on_get_hashes ( const COMMAND_RPC_GET_HASHES_FAST::request req,
COMMAND_RPC_GET_HASHES_FAST::response res,
const connection_context ctx = NULL 
)

Definition at line 421 of file core_rpc_server.cpp.

422  {
424  bool r;
425  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_HASHES_FAST>(invoke_http_mode::BIN, "/gethashes.bin", req, res, r))
426  return r;
427 
428  res.start_height = req.start_height;
429  if(!m_core.get_blockchain_storage().find_blockchain_supplement(req.block_ids, res.m_block_ids, res.start_height, res.current_height, false))
430  {
431  res.status = "Failed";
432  return false;
433  }
434 
435  res.status = CORE_RPC_STATUS_OK;
436  return true;
437  }
bool find_blockchain_supplement(const std::list< crypto::hash > &qblock_ids, std::vector< crypto::hash > &hashes, uint64_t &start_height, uint64_t &current_height, bool clip_pruned) const
get recent block hashes for a foreign chain
bool on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request &req, COMMAND_RPC_GET_HASHES_FAST::response &res, const connection_context *ctx=NULL)

◆ on_get_height()

bool cryptonote::core_rpc_server::on_get_height ( const COMMAND_RPC_GET_HEIGHT::request req,
COMMAND_RPC_GET_HEIGHT::response res,
const connection_context ctx = NULL 
)

Definition at line 170 of file core_rpc_server.cpp.

171  {
173  bool r;
174  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_HEIGHT>(invoke_http_mode::JON, "/getheight", req, res, r))
175  return r;
176 
178  m_core.get_blockchain_top(res.height, hash);
179  ++res.height; // block height to chain height
181  res.status = CORE_RPC_STATUS_OK;
182  return true;
183  }
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request &req, COMMAND_RPC_GET_HEIGHT::response &res, const connection_context *ctx=NULL)
void get_blockchain_top(uint64_t &height, crypto::hash &top_id) const
get the hash and height of the most recent block
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_indexes()

bool cryptonote::core_rpc_server::on_get_indexes ( const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request req,
COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response res,
const connection_context ctx = NULL 
)

Definition at line 511 of file core_rpc_server.cpp.

512  {
514  bool ok;
515  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES>(invoke_http_mode::BIN, "/get_o_indexes.bin", req, res, ok))
516  return ok;
517 
518  bool r = m_core.get_tx_outputs_gindexs(req.txid, res.o_indexes);
519  if(!r)
520  {
521  res.status = "Failed";
522  return true;
523  }
524  res.status = CORE_RPC_STATUS_OK;
525  LOG_PRINT_L2("COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES: [" << res.o_indexes.size() << "]");
526  return true;
527  }
bool on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request &req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response &res, const connection_context *ctx=NULL)
#define LOG_PRINT_L2(x)
Definition: misc_log_ex.h:101

◆ on_get_info()

bool cryptonote::core_rpc_server::on_get_info ( const COMMAND_RPC_GET_INFO::request req,
COMMAND_RPC_GET_INFO::response res,
const connection_context ctx = NULL 
)

Definition at line 185 of file core_rpc_server.cpp.

186  {
188  bool r;
189  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_INFO>(invoke_http_mode::JON, "/getinfo", req, res, r))
190  {
191  res.bootstrap_daemon_address = m_bootstrap_daemon_address;
192  crypto::hash top_hash;
193  m_core.get_blockchain_top(res.height_without_bootstrap, top_hash);
194  ++res.height_without_bootstrap; // turn top block height into blockchain height
195  res.was_bootstrap_ever_used = true;
196  return r;
197  }
198 
199  const bool restricted = m_restricted && ctx;
200 
201  crypto::hash top_hash;
202  m_core.get_blockchain_top(res.height, top_hash);
203  ++res.height; // turn top block height into blockchain height
204  res.top_block_hash = string_tools::pod_to_hex(top_hash);
205  res.target_height = m_core.get_target_blockchain_height();
206  store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64);
208  res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase
209  res.tx_pool_size = m_core.get_pool_transactions_count();
210  res.alt_blocks_count = restricted ? 0 : m_core.get_blockchain_storage().get_alternative_blocks_count();
211  uint64_t total_conn = restricted ? 0 : m_p2p.get_public_connections_count();
212  res.outgoing_connections_count = restricted ? 0 : m_p2p.get_public_outgoing_connections_count();
213  res.incoming_connections_count = restricted ? 0 : (total_conn - res.outgoing_connections_count);
214  res.rpc_connections_count = restricted ? 0 : get_connections_count();
215  res.white_peerlist_size = restricted ? 0 : m_p2p.get_public_white_peers_count();
216  res.grey_peerlist_size = restricted ? 0 : m_p2p.get_public_gray_peers_count();
217 
218  cryptonote::network_type net_type = nettype();
219  res.mainnet = net_type == MAINNET;
220  res.testnet = net_type == TESTNET;
221  res.stagenet = net_type == STAGENET;
222  res.nettype = net_type == MAINNET ? "mainnet" : net_type == TESTNET ? "testnet" : net_type == STAGENET ? "stagenet" : "fakechain";
223  store_difficulty(m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1),
224  res.cumulative_difficulty, res.wide_cumulative_difficulty, res.cumulative_difficulty_top64);
225  res.block_size_limit = res.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
226  res.block_size_median = res.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
227  res.start_time = restricted ? 0 : (uint64_t)m_core.get_start_time();
228  res.free_space = restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
229  res.offline = m_core.offline();
230  res.bootstrap_daemon_address = restricted ? "" : m_bootstrap_daemon_address;
231  res.height_without_bootstrap = restricted ? 0 : res.height;
232  if (restricted)
233  res.was_bootstrap_ever_used = false;
234  else
235  {
236  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
237  res.was_bootstrap_ever_used = m_was_bootstrap_ever_used;
238  }
239  res.database_size = m_core.get_blockchain_storage().get_db().get_database_size();
240  if (restricted)
241  res.database_size = round_up(res.database_size, 5ull* 1024 * 1024 * 1024);
242  res.update_available = restricted ? false : m_core.is_update_available();
243  res.version = restricted ? "" : ELECTRONEUM_VERSION;
244 
245  res.status = CORE_RPC_STATUS_OK;
246 
247  res.daemon_release_name = ELECTRONEUM_RELEASE_NAME;
248  res.daemon_version = ELECTRONEUM_VERSION;
249  res.daemon_version_full = ELECTRONEUM_VERSION_FULL;
250  res.daemon_version_tag = ELECTRONEUM_VERSION_TAG;
251  return true;
252  }
virtual uint64_t get_database_size() const =0
get disk space requirements
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t &height) const =0
fetch a block's cumulative difficulty
uint64_t get_current_cumulative_block_weight_median() const
gets the block weight median based on recent blocks (same window as for the limit)
uint64_t get_current_cumulative_block_weight_limit() const
gets the block weight limit based on recent blocks
difficulty_type get_difficulty_for_next_block()
returns the difficulty target the next block to be added must meet
Definition: blockchain.cpp:857
uint64_t get_difficulty_target() const
get difficulty target based on chain and hardfork version
size_t get_alternative_blocks_count() const
returns the number of alternative blocks stored
size_t get_total_transactions() const
gets the total number of transactions on the main chain
bool on_get_info(const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, const connection_context *ctx=NULL)
size_t get_pool_transactions_count() const
get the total number of transactions in the pool
bool is_update_available() const
check whether an update is known to be available or not
bool offline() const
get whether the core is running offline
std::time_t get_start_time() const
gets start_time
uint64_t get_target_blockchain_height() const
gets the target blockchain height
size_t get_public_white_peers_count()
virtual uint64_t get_public_connections_count()
size_t get_public_outgoing_connections_count()
size_t get_public_gray_peers_count()
#define false
Definition: stdbool.h:38
const char *const ELECTRONEUM_VERSION
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL
const char *const ELECTRONEUM_VERSION_TAG
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_info_json()

bool cryptonote::core_rpc_server::on_get_info_json ( const COMMAND_RPC_GET_INFO::request req,
COMMAND_RPC_GET_INFO::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1852 of file core_rpc_server.cpp.

1853  {
1854  return on_get_info(req, res, ctx);
1855  }

◆ on_get_last_block_header()

bool cryptonote::core_rpc_server::on_get_last_block_header ( const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request req,
COMMAND_RPC_GET_LAST_BLOCK_HEADER::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1544 of file core_rpc_server.cpp.

1545  {
1547  bool r;
1548  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_LAST_BLOCK_HEADER>(invoke_http_mode::JON_RPC, "getlastblockheader", req, res, r))
1549  return r;
1550 
1551  CHECK_CORE_READY();
1552  uint64_t last_block_height;
1553  crypto::hash last_block_hash;
1554  m_core.get_blockchain_top(last_block_height, last_block_hash);
1555  block last_block;
1556  bool have_last_block = m_core.get_block_by_hash(last_block_hash, last_block);
1557  if (!have_last_block)
1558  {
1560  error_resp.message = "Internal error: can't get last block.";
1561  return false;
1562  }
1563  const bool restricted = m_restricted && ctx;
1564  bool response_filled = fill_block_header_response(last_block, false, last_block_height, last_block_hash, res.block_header, req.fill_pow_hash && !restricted);
1565  if (!response_filled)
1566  {
1568  error_resp.message = "Internal error: can't produce valid response.";
1569  return false;
1570  }
1571  res.status = CORE_RPC_STATUS_OK;
1572  return true;
1573  }
bool on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request &req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)

◆ on_get_limit()

bool cryptonote::core_rpc_server::on_get_limit ( const COMMAND_RPC_GET_LIMIT::request req,
COMMAND_RPC_GET_LIMIT::response res,
const connection_context ctx = NULL 
)

Definition at line 2100 of file core_rpc_server.cpp.

2101  {
2103  bool r;
2104  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_LIMIT>(invoke_http_mode::JON, "/get_limit", req, res, r))
2105  return r;
2106 
2109  res.status = CORE_RPC_STATUS_OK;
2110  return true;
2111  }
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:

◆ on_get_net_stats()

bool cryptonote::core_rpc_server::on_get_net_stats ( const COMMAND_RPC_GET_NET_STATS::request req,
COMMAND_RPC_GET_NET_STATS::response res,
const connection_context ctx = NULL 
)

Definition at line 254 of file core_rpc_server.cpp.

255  {
257  // No bootstrap daemon check: Only ever get stats about local server
258  res.start_time = (uint64_t)m_core.get_start_time();
259  {
262  }
263  {
266  }
267  res.status = CORE_RPC_STATUS_OK;
268  return true;
269  }
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)
virtual void get_stats(uint64_t &total_packets, uint64_t &total_bytes) const =0
static i_network_throttle & get_global_throttle_in()
singleton ; for friend class ; caller MUST use proper locks! like m_lock_get_global_throttle_in
static i_network_throttle & get_global_throttle_out()
ditto ; use lock ... use m_lock_get_global_throttle_out obviously
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_output_distribution()

bool cryptonote::core_rpc_server::on_get_output_distribution ( const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request req,
COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 2476 of file core_rpc_server.cpp.

2477  {
2479  bool r;
2480  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::JON_RPC, "get_output_distribution", req, res, r))
2481  return r;
2482 
2483  try
2484  {
2485  // 0 is placeholder for the whole chain
2486  const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1);
2487  for (uint64_t amount: req.amounts)
2488  {
2489  auto data = rpc::RpcHandler::get_output_distribution([this](uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) { return m_core.get_output_distribution(amount, from, to, start_height, distribution, base); }, amount, req.from_height, req_to_height, [this](uint64_t height) { return m_core.get_blockchain_storage().get_db().get_block_hash_from_height(height); }, req.cumulative, m_core.get_current_blockchain_height());
2490  if (!data)
2491  {
2493  error_resp.message = "Failed to get output distribution";
2494  return false;
2495  }
2496 
2497  res.distributions.push_back({std::move(*data), amount, "", req.binary, req.compress});
2498  }
2499  }
2500  catch (const std::exception &e)
2501  {
2503  error_resp.message = "Failed to get output distribution";
2504  return false;
2505  }
2506 
2507  res.status = CORE_RPC_STATUS_OK;
2508  return true;
2509  }
virtual crypto::hash get_block_hash_from_height(const uint64_t &height) const =0
fetch a block's hash
bool on_get_output_distribution(const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, uint64_t &start_height, std::vector< uint64_t > &distribution, uint64_t &base) const
gets per block distribution of outputs of a given amount
static boost::optional< output_distribution_data > get_output_distribution(const std::function< bool(uint64_t, uint64_t, uint64_t, uint64_t &, std::vector< uint64_t > &, uint64_t &)> &f, uint64_t amount, uint64_t from_height, uint64_t to_height, const std::function< crypto::hash(uint64_t)> &get_hash, bool cumulative, uint64_t blockchain_height)
Definition: rpc_handler.cpp:29
Here is the call graph for this function:

◆ on_get_output_distribution_bin()

bool cryptonote::core_rpc_server::on_get_output_distribution_bin ( const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request req,
COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response res,
const connection_context ctx = NULL 
)

Definition at line 2511 of file core_rpc_server.cpp.

2512  {
2514 
2515  bool r;
2516  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::BIN, "/get_output_distribution.bin", req, res, r))
2517  return r;
2518 
2519  res.status = "Failed";
2520 
2521  if (!req.binary)
2522  {
2523  res.status = "Binary only call";
2524  return false;
2525  }
2526  try
2527  {
2528  // 0 is placeholder for the whole chain
2529  const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1);
2530  for (uint64_t amount: req.amounts)
2531  {
2532  auto data = rpc::RpcHandler::get_output_distribution([this](uint64_t amount, uint64_t from, uint64_t to, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) { return m_core.get_output_distribution(amount, from, to, start_height, distribution, base); }, amount, req.from_height, req_to_height, [this](uint64_t height) { return m_core.get_blockchain_storage().get_db().get_block_hash_from_height(height); }, req.cumulative, m_core.get_current_blockchain_height());
2533  if (!data)
2534  {
2535  res.status = "Failed to get output distribution";
2536  return false;
2537  }
2538 
2539  res.distributions.push_back({std::move(*data), amount, "", req.binary, req.compress});
2540  }
2541  }
2542  catch (const std::exception &e)
2543  {
2544  res.status = "Failed to get output distribution";
2545  return false;
2546  }
2547 
2548  res.status = CORE_RPC_STATUS_OK;
2549  return true;
2550  }
bool on_get_output_distribution_bin(const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, const connection_context *ctx=NULL)
Here is the call graph for this function:

◆ on_get_output_histogram()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1995 of file core_rpc_server.cpp.

1996  {
1998  bool r;
1999  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_HISTOGRAM>(invoke_http_mode::JON_RPC, "get_output_histogram", req, res, r))
2000  return r;
2001 
2002  const bool restricted = m_restricted && ctx;
2003  if (restricted && req.recent_cutoff > 0 && req.recent_cutoff < (uint64_t)time(NULL) - OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION)
2004  {
2005  res.status = "Recent cutoff is too old";
2006  return true;
2007  }
2008 
2009  std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> histogram;
2010  try
2011  {
2012  histogram = m_core.get_blockchain_storage().get_output_histogram(req.amounts, req.unlocked, req.recent_cutoff, req.min_count);
2013  }
2014  catch (const std::exception &e)
2015  {
2016  res.status = "Failed to get output histogram";
2017  return true;
2018  }
2019 
2020  res.histogram.clear();
2021  res.histogram.reserve(histogram.size());
2022  for (const auto &i: histogram)
2023  {
2024  if (std::get<0>(i.second) >= req.min_count && (std::get<0>(i.second) <= req.max_count || req.max_count == 0))
2025  res.histogram.push_back(COMMAND_RPC_GET_OUTPUT_HISTOGRAM::entry(i.first, std::get<0>(i.second), std::get<1>(i.second), std::get<2>(i.second)));
2026  }
2027 
2028  res.status = CORE_RPC_STATUS_OK;
2029  return true;
2030  }
std::map< uint64_t, std::tuple< uint64_t, uint64_t, uint64_t > > get_output_histogram(const std::vector< uint64_t > &amounts, bool unlocked, uint64_t recent_cutoff, uint64_t min_count=0) const
return a histogram of outputs on the blockchain
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)
#define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION
Here is the caller graph for this function:

◆ on_get_outs()

bool cryptonote::core_rpc_server::on_get_outs ( const COMMAND_RPC_GET_OUTPUTS::request req,
COMMAND_RPC_GET_OUTPUTS::response res,
const connection_context ctx = NULL 
)

Definition at line 467 of file core_rpc_server.cpp.

468  {
470  bool r;
471  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUTS>(invoke_http_mode::JON, "/get_outs", req, res, r))
472  return r;
473 
474  res.status = "Failed";
475 
476  const bool restricted = m_restricted && ctx;
477  if (restricted)
478  {
479  if (req.outputs.size() > MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT)
480  {
481  res.status = "Too many outs requested";
482  return true;
483  }
484  }
485 
487  req_bin.outputs = req.outputs;
488  req_bin.get_txid = req.get_txid;
490  if(!m_core.get_outs(req_bin, res_bin))
491  {
492  return true;
493  }
494 
495  // convert to text
496  for (const auto &i: res_bin.outs)
497  {
501  outkey.mask = epee::string_tools::pod_to_hex(i.mask);
502  outkey.unlocked = i.unlocked;
503  outkey.height = i.height;
504  outkey.txid = epee::string_tools::pod_to_hex(i.txid);
505  }
506 
507  res.status = CORE_RPC_STATUS_OK;
508  return true;
509  }
bool on_get_outs(const COMMAND_RPC_GET_OUTPUTS::request &req, COMMAND_RPC_GET_OUTPUTS::response &res, const connection_context *ctx=NULL)
bool get_outs(const COMMAND_RPC_GET_OUTPUTS_BIN::request &req, COMMAND_RPC_GET_OUTPUTS_BIN::response &res) const
gets specific outputs to mix with
#define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT
struct cryptonote::outkey outkey
Here is the call graph for this function:

◆ on_get_outs_bin()

bool cryptonote::core_rpc_server::on_get_outs_bin ( const COMMAND_RPC_GET_OUTPUTS_BIN::request req,
COMMAND_RPC_GET_OUTPUTS_BIN::response res,
const connection_context ctx = NULL 
)

Definition at line 439 of file core_rpc_server.cpp.

440  {
442  bool r;
443  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUTS_BIN>(invoke_http_mode::BIN, "/get_outs.bin", req, res, r))
444  return r;
445 
446  res.status = "Failed";
447 
448  const bool restricted = m_restricted && ctx;
449  if (restricted)
450  {
451  if (req.outputs.size() > MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT)
452  {
453  res.status = "Too many outs requested";
454  return true;
455  }
456  }
457 
458  if(!m_core.get_outs(req, res))
459  {
460  return true;
461  }
462 
463  res.status = CORE_RPC_STATUS_OK;
464  return true;
465  }
bool on_get_outs_bin(const COMMAND_RPC_GET_OUTPUTS_BIN::request &req, COMMAND_RPC_GET_OUTPUTS_BIN::response &res, const connection_context *ctx=NULL)

◆ on_get_peer_list()

bool cryptonote::core_rpc_server::on_get_peer_list ( const COMMAND_RPC_GET_PEER_LIST::request req,
COMMAND_RPC_GET_PEER_LIST::response res,
const connection_context ctx = NULL 
)

Definition at line 1027 of file core_rpc_server.cpp.

1028  {
1030  std::vector<nodetool::peerlist_entry> white_list;
1031  std::vector<nodetool::peerlist_entry> gray_list;
1032  m_p2p.get_public_peerlist(gray_list, white_list);
1033 
1034  res.white_list.reserve(white_list.size());
1035  for (auto & entry : white_list)
1036  {
1037  if (entry.adr.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
1038  res.white_list.emplace_back(entry.id, entry.adr.as<epee::net_utils::ipv4_network_address>().ip(),
1039  entry.adr.as<epee::net_utils::ipv4_network_address>().port(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1040  else
1041  res.white_list.emplace_back(entry.id, entry.adr.str(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1042  }
1043 
1044  res.gray_list.reserve(gray_list.size());
1045  for (auto & entry : gray_list)
1046  {
1047  if (entry.adr.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id())
1048  res.gray_list.emplace_back(entry.id, entry.adr.as<epee::net_utils::ipv4_network_address>().ip(),
1049  entry.adr.as<epee::net_utils::ipv4_network_address>().port(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1050  else
1051  res.gray_list.emplace_back(entry.id, entry.adr.str(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1052  }
1053 
1054  res.status = CORE_RPC_STATUS_OK;
1055  return true;
1056  }
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)
static constexpr address_type get_type_id() noexcept
constexpr uint16_t port() const noexcept
constexpr uint32_t ip() const noexcept
void get_public_peerlist(std::vector< peerlist_entry > &gray, std::vector< peerlist_entry > &white)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_transaction_pool()

bool cryptonote::core_rpc_server::on_get_transaction_pool ( const COMMAND_RPC_GET_TRANSACTION_POOL::request req,
COMMAND_RPC_GET_TRANSACTION_POOL::response res,
const connection_context ctx = NULL 
)

Definition at line 1095 of file core_rpc_server.cpp.

1096  {
1098  bool r;
1099  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL>(invoke_http_mode::JON, "/get_transaction_pool", req, res, r))
1100  return r;
1101 
1102  const bool restricted = m_restricted && ctx;
1103  const bool request_has_rpc_origin = ctx != NULL;
1104  m_core.get_pool_transactions_and_spent_keys_info(res.transactions, res.spent_key_images, !request_has_rpc_origin || !restricted);
1105  for (tx_info& txi : res.transactions)
1106  txi.tx_blob = epee::string_tools::buff_to_hex_nodelimer(txi.tx_blob);
1107  res.status = CORE_RPC_STATUS_OK;
1108  return true;
1109  }
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request &req, COMMAND_RPC_GET_TRANSACTION_POOL::response &res, const connection_context *ctx=NULL)
bool get_pool_transactions_and_spent_keys_info(std::vector< tx_info > &tx_infos, std::vector< spent_key_image_info > &key_image_infos, bool include_unrelayed_txes=true) const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_transaction_pool_hashes()

bool cryptonote::core_rpc_server::on_get_transaction_pool_hashes ( const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request req,
COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response res,
const connection_context ctx = NULL 
)

Definition at line 1125 of file core_rpc_server.cpp.

1126  {
1128  bool r;
1129  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_HASHES>(invoke_http_mode::JON, "/get_transaction_pool_hashes", req, res, r))
1130  return r;
1131 
1132  const bool restricted = m_restricted && ctx;
1133  const bool request_has_rpc_origin = ctx != NULL;
1134  std::vector<crypto::hash> tx_hashes;
1135  m_core.get_pool_transaction_hashes(tx_hashes, !request_has_rpc_origin || !restricted);
1136  res.tx_hashes.reserve(tx_hashes.size());
1137  for (const crypto::hash &tx_hash: tx_hashes)
1138  res.tx_hashes.push_back(epee::string_tools::pod_to_hex(tx_hash));
1139  res.status = CORE_RPC_STATUS_OK;
1140  return true;
1141  }
bool on_get_transaction_pool_hashes(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response &res, const connection_context *ctx=NULL)
bool get_pool_transaction_hashes(std::vector< crypto::hash > &txs, bool include_unrelayed_txes=true) const
get a list of all transactions in the pool
Here is the call graph for this function:

◆ on_get_transaction_pool_hashes_bin()

bool cryptonote::core_rpc_server::on_get_transaction_pool_hashes_bin ( const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::request req,
COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::response res,
const connection_context ctx = NULL 
)

Definition at line 1111 of file core_rpc_server.cpp.

1112  {
1114  bool r;
1115  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN>(invoke_http_mode::JON, "/get_transaction_pool_hashes.bin", req, res, r))
1116  return r;
1117 
1118  const bool restricted = m_restricted && ctx;
1119  const bool request_has_rpc_origin = ctx != NULL;
1120  m_core.get_pool_transaction_hashes(res.tx_hashes, !request_has_rpc_origin || !restricted);
1121  res.status = CORE_RPC_STATUS_OK;
1122  return true;
1123  }

◆ on_get_transaction_pool_stats()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1143 of file core_rpc_server.cpp.

1144  {
1146  bool r;
1147  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_STATS>(invoke_http_mode::JON, "/get_transaction_pool_stats", req, res, r))
1148  return r;
1149 
1150  const bool restricted = m_restricted && ctx;
1151  const bool request_has_rpc_origin = ctx != NULL;
1152  m_core.get_pool_transaction_stats(res.pool_stats, !request_has_rpc_origin || !restricted);
1153  res.status = CORE_RPC_STATUS_OK;
1154  return true;
1155  }
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)
bool get_pool_transaction_stats(struct txpool_stats &stats, bool include_unrelayed_txes=true) const
get a list of all transactions in the pool
Here is the caller graph for this function:

◆ on_get_transactions()

bool cryptonote::core_rpc_server::on_get_transactions ( const COMMAND_RPC_GET_TRANSACTIONS::request req,
COMMAND_RPC_GET_TRANSACTIONS::response res,
const connection_context ctx = NULL 
)

Definition at line 529 of file core_rpc_server.cpp.

530  {
532  bool ok;
533  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTIONS>(invoke_http_mode::JON, "/gettransactions", req, res, ok))
534  return ok;
535 
536  std::vector<crypto::hash> vh;
537  for(const auto& tx_hex_str: req.txs_hashes)
538  {
539  blobdata b;
540  if(!string_tools::parse_hexstr_to_binbuff(tx_hex_str, b))
541  {
542  res.status = "Failed to parse hex representation of transaction hash";
543  return true;
544  }
545  if(b.size() != sizeof(crypto::hash))
546  {
547  res.status = "Failed, size of data mismatch";
548  return true;
549  }
550  vh.push_back(*reinterpret_cast<const crypto::hash*>(b.data()));
551  }
552  std::vector<crypto::hash> missed_txs;
553  std::vector<std::tuple<crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata>> txs;
554  bool r = m_core.get_split_transactions_blobs(vh, txs, missed_txs);
555  if(!r)
556  {
557  res.status = "Failed";
558  return true;
559  }
560  LOG_PRINT_L2("Found " << txs.size() << "/" << vh.size() << " transactions on the blockchain");
561 
562  // try the pool for any missing txes
563  size_t found_in_pool = 0;
564  std::unordered_set<crypto::hash> pool_tx_hashes;
565  std::unordered_map<crypto::hash, tx_info> per_tx_pool_tx_info;
566  if (!missed_txs.empty())
567  {
568  std::vector<tx_info> pool_tx_info;
569  std::vector<spent_key_image_info> pool_key_image_info;
570  bool r = m_core.get_pool_transactions_and_spent_keys_info(pool_tx_info, pool_key_image_info);
571  if(r)
572  {
573  // sort to match original request
574  std::vector<std::tuple<crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata>> sorted_txs;
575  std::vector<tx_info>::const_iterator i;
576  unsigned txs_processed = 0;
577  for (const crypto::hash &h: vh)
578  {
579  if (std::find(missed_txs.begin(), missed_txs.end(), h) == missed_txs.end())
580  {
581  if (txs.size() == txs_processed)
582  {
583  res.status = "Failed: internal error - txs is empty";
584  return true;
585  }
586  // core returns the ones it finds in the right order
587  if (std::get<0>(txs[txs_processed]) != h)
588  {
589  res.status = "Failed: tx hash mismatch";
590  return true;
591  }
592  sorted_txs.push_back(std::move(txs[txs_processed]));
593  ++txs_processed;
594  }
595  else if ((i = std::find_if(pool_tx_info.begin(), pool_tx_info.end(), [h](const tx_info &txi) { return epee::string_tools::pod_to_hex(h) == txi.id_hash; })) != pool_tx_info.end())
596  {
598  if (!cryptonote::parse_and_validate_tx_from_blob(i->tx_blob, tx))
599  {
600  res.status = "Failed to parse and validate tx from blob";
601  return true;
602  }
603  std::stringstream ss;
604  binary_archive<true> ba(ss);
605  bool r = const_cast<cryptonote::transaction&>(tx).serialize_base(ba);
606  if (!r)
607  {
608  res.status = "Failed to serialize transaction base";
609  return true;
610  }
611  //TODO: Public
612  const cryptonote::blobdata pruned = ss.str();
613  sorted_txs.push_back(std::make_tuple(h, pruned, crypto::null_hash, std::string(i->tx_blob, pruned.size())));
614  missed_txs.erase(std::find(missed_txs.begin(), missed_txs.end(), h));
615  pool_tx_hashes.insert(h);
616  const std::string hash_string = epee::string_tools::pod_to_hex(h);
617  for (const auto &ti: pool_tx_info)
618  {
619  if (ti.id_hash == hash_string)
620  {
621  per_tx_pool_tx_info.insert(std::make_pair(h, ti));
622  break;
623  }
624  }
625  ++found_in_pool;
626  }
627  }
628  txs = sorted_txs;
629  }
630  LOG_PRINT_L2("Found " << found_in_pool << "/" << vh.size() << " transactions in the pool");
631  }
632 
633  std::vector<std::string>::const_iterator txhi = req.txs_hashes.begin();
634  std::vector<crypto::hash>::const_iterator vhi = vh.begin();
635  for(auto& tx: txs)
636  {
637  res.txs.push_back(COMMAND_RPC_GET_TRANSACTIONS::entry());
638  COMMAND_RPC_GET_TRANSACTIONS::entry &e = res.txs.back();
639 
640  crypto::hash tx_hash = *vhi++;
641  e.tx_hash = *txhi++;
642  e.prunable_hash = epee::string_tools::pod_to_hex(std::get<2>(tx));
643  if (req.split || req.prune || std::get<3>(tx).empty())
644  {
645  // use splitted form with pruned and prunable (filled only when prune=false and the daemon has it), leaving as_hex as empty
646  e.pruned_as_hex = string_tools::buff_to_hex_nodelimer(std::get<1>(tx));
647  if (!req.prune)
648  e.prunable_as_hex = string_tools::buff_to_hex_nodelimer(std::get<3>(tx));
649  if (req.decode_as_json)
650  {
651  cryptonote::blobdata tx_data;
653  if (req.prune || std::get<3>(tx).empty())
654  {
655  // decode pruned tx to JSON
656  tx_data = std::get<1>(tx);
658  {
659  pruned_transaction pruned_tx{t};
660  e.as_json = obj_to_json_str(pruned_tx);
661  }
662  else
663  {
664  res.status = "Failed to parse and validate pruned tx from blob";
665  return true;
666  }
667  }
668  else
669  {
670  // decode full tx to JSON
671  tx_data = std::get<1>(tx) + std::get<3>(tx);
673  {
674  e.as_json = obj_to_json_str(t);
675  }
676  else
677  {
678  res.status = "Failed to parse and validate tx from blob";
679  return true;
680  }
681  }
682  }
683  }
684  else
685  {
686  // use non-splitted form, leaving pruned_as_hex and prunable_as_hex as empty
687  cryptonote::blobdata tx_data = std::get<1>(tx) + std::get<3>(tx);
688  e.as_hex = string_tools::buff_to_hex_nodelimer(tx_data);
689  if (req.decode_as_json)
690  {
693  {
694  e.as_json = obj_to_json_str(t);
695  }
696  else
697  {
698  res.status = "Failed to parse and validate tx from blob";
699  return true;
700  }
701  }
702  }
703  e.in_pool = pool_tx_hashes.find(tx_hash) != pool_tx_hashes.end();
704  if (e.in_pool)
705  {
706  e.block_height = e.block_timestamp = std::numeric_limits<uint64_t>::max();
707  auto it = per_tx_pool_tx_info.find(tx_hash);
708  if (it != per_tx_pool_tx_info.end())
709  {
710  e.double_spend_seen = it->second.double_spend_seen;
711  e.nonexistent_utxo_seen = it->second.nonexistent_utxo_seen;
712  e.relayed = it->second.relayed;
713  }
714  else
715  {
716  MERROR("Failed to determine pool info for " << tx_hash);
717  e.double_spend_seen = false;
718  e.nonexistent_utxo_seen = false;
719  e.relayed = false;
720  }
721  }
722  else
723  {
724  e.block_height = m_core.get_blockchain_storage().get_db().get_tx_block_height(tx_hash);
725  e.block_timestamp = m_core.get_blockchain_storage().get_db().get_block_timestamp(e.block_height);
726  e.double_spend_seen = false;
727  e.relayed = false;
728  }
729 
730  // fill up old style responses too, in case an old wallet asks
731  res.txs_as_hex.push_back(e.as_hex);
732  if (req.decode_as_json)
733  res.txs_as_json.push_back(e.as_json);
734 
735  // output indices too if not in pool
736  if (pool_tx_hashes.find(tx_hash) == pool_tx_hashes.end())
737  {
738  bool r = m_core.get_tx_outputs_gindexs(tx_hash, e.output_indices);
739  if (!r)
740  {
741  res.status = "Failed";
742  return false;
743  }
744  }
745  }
746 
747  for(const auto& miss_tx: missed_txs)
748  {
749  res.missed_tx.push_back(string_tools::pod_to_hex(miss_tx));
750  }
751 
752  LOG_PRINT_L2(res.txs.size() << " transactions found, " << res.missed_tx.size() << " not found");
753  res.status = CORE_RPC_STATUS_OK;
754  return true;
755  }
virtual uint64_t get_tx_block_height(const crypto::hash &h) const =0
fetches the height of a transaction's block
virtual uint64_t get_block_timestamp(const uint64_t &height) const =0
fetch a block's timestamp
bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request &req, COMMAND_RPC_GET_TRANSACTIONS::response &res, const connection_context *ctx=NULL)
bool get_split_transactions_blobs(const std::vector< crypto::hash > &txs_ids, std::vector< std::tuple< crypto::hash, cryptonote::blobdata, crypto::hash, cryptonote::blobdata >> &txs, std::vector< crypto::hash > &missed_txs) const
#define MERROR(x)
Definition: misc_log_ex.h:73
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)
tuple make_tuple()
Definition: gtest-tuple.h:675
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_get_txpool_backlog()

bool cryptonote::core_rpc_server::on_get_txpool_backlog ( const COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::request req,
COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 2374 of file core_rpc_server.cpp.

2375  {
2377  bool r;
2378  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG>(invoke_http_mode::JON_RPC, "get_txpool_backlog", req, res, r))
2379  return r;
2380 
2381  if (!m_core.get_txpool_backlog(res.backlog))
2382  {
2384  error_resp.message = "Failed to get txpool backlog";
2385  return false;
2386  }
2387 
2388  res.status = CORE_RPC_STATUS_OK;
2389  return true;
2390  }
bool on_get_txpool_backlog(const COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool get_txpool_backlog(std::vector< tx_backlog_entry > &backlog) const

◆ on_get_version()

bool cryptonote::core_rpc_server::on_get_version ( const COMMAND_RPC_GET_VERSION::request req,
COMMAND_RPC_GET_VERSION::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 2032 of file core_rpc_server.cpp.

2033  {
2035  bool r;
2036  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_VERSION>(invoke_http_mode::JON_RPC, "get_version", req, res, r))
2037  return r;
2038 
2039  res.version = CORE_RPC_VERSION;
2040  res.status = CORE_RPC_STATUS_OK;
2041  return true;
2042  }
bool on_get_version(const COMMAND_RPC_GET_VERSION::request &req, COMMAND_RPC_GET_VERSION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
#define CORE_RPC_VERSION

◆ on_getblockcount()

bool cryptonote::core_rpc_server::on_getblockcount ( const COMMAND_RPC_GETBLOCKCOUNT::request req,
COMMAND_RPC_GETBLOCKCOUNT::response res,
const connection_context ctx = NULL 
)

Definition at line 1167 of file core_rpc_server.cpp.

1168  {
1170  {
1171  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1172  if (m_should_use_bootstrap_daemon)
1173  {
1174  res.status = "This command is unsupported for bootstrap daemon";
1175  return false;
1176  }
1177  }
1178  res.count = m_core.get_current_blockchain_height();
1179  res.status = CORE_RPC_STATUS_OK;
1180  return true;
1181  }
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request &req, COMMAND_RPC_GETBLOCKCOUNT::response &res, const connection_context *ctx=NULL)

◆ on_getblockhash()

bool cryptonote::core_rpc_server::on_getblockhash ( const COMMAND_RPC_GETBLOCKHASH::request req,
COMMAND_RPC_GETBLOCKHASH::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1183 of file core_rpc_server.cpp.

1184  {
1186  {
1187  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1188  if (m_should_use_bootstrap_daemon)
1189  {
1190  res = "This command is unsupported for bootstrap daemon";
1191  return false;
1192  }
1193  }
1194  if(req.size() != 1)
1195  {
1197  error_resp.message = "Wrong parameters, expected height";
1198  return false;
1199  }
1200  uint64_t h = req[0];
1201  if(m_core.get_current_blockchain_height() <= h)
1202  {
1204  error_resp.message = std::string("Requested block height: ") + std::to_string(h) + " greater than current top block height: " + std::to_string(m_core.get_current_blockchain_height() - 1);
1205  }
1207  return true;
1208  }
bool on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request &req, COMMAND_RPC_GETBLOCKHASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
Here is the call graph for this function:

◆ on_getblocktemplate()

bool cryptonote::core_rpc_server::on_getblocktemplate ( const COMMAND_RPC_GETBLOCKTEMPLATE::request req,
COMMAND_RPC_GETBLOCKTEMPLATE::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1227 of file core_rpc_server.cpp.

1228  {
1230  bool r;
1231  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GETBLOCKTEMPLATE>(invoke_http_mode::JON_RPC, "getblocktemplate", req, res, r))
1232  return r;
1233 
1234  if(!check_core_ready())
1235  {
1236  error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
1237  error_resp.message = "Core is busy";
1238  return false;
1239  }
1240 
1241  if(req.reserve_size > 255)
1242  {
1244  error_resp.message = "Too big reserved size, maximum 255";
1245  return false;
1246  }
1247 
1249 
1250  if(!req.wallet_address.size() || !cryptonote::get_account_address_from_str(info, nettype(), req.wallet_address))
1251  {
1253  error_resp.message = "Failed to parse wallet address";
1254  return false;
1255  }
1256  if (info.is_subaddress)
1257  {
1259  error_resp.message = "Mining to subaddress is not supported yet";
1260  return false;
1261  }
1262 
1263  block b;
1264  cryptonote::blobdata blob_reserve;
1265  blob_reserve.resize(req.reserve_size, 0);
1267  crypto::hash prev_block;
1268  if (!req.prev_block.empty())
1269  {
1270  if (!epee::string_tools::hex_to_pod(req.prev_block, prev_block))
1271  {
1273  error_resp.message = "Invalid prev_block";
1274  return false;
1275  }
1276  }
1277  if(!m_core.get_block_template(b, req.prev_block.empty() ? NULL : &prev_block, info.address, wdiff, res.height, res.expected_reward, blob_reserve))
1278  {
1280  error_resp.message = "Internal error: failed to create block template";
1281  LOG_ERROR("Failed to create block template");
1282  return false;
1283  }
1284  store_difficulty(wdiff, res.difficulty, res.wide_difficulty, res.difficulty_top64);
1285  blobdata block_blob = t_serializable_object_to_blob(b);
1287  if(tx_pub_key == crypto::null_pkey)
1288  {
1290  error_resp.message = "Internal error: failed to create block template";
1291  LOG_ERROR("Failed to get tx pub key in coinbase extra");
1292  return false;
1293  }
1294  res.reserved_offset = slow_memmem((void*)block_blob.data(), block_blob.size(), &tx_pub_key, sizeof(tx_pub_key));
1295  if(!res.reserved_offset)
1296  {
1298  error_resp.message = "Internal error: failed to create block template";
1299  LOG_ERROR("Failed to find tx pub key in blockblob");
1300  return false;
1301  }
1302  if (req.reserve_size)
1303  res.reserved_offset += sizeof(tx_pub_key) + 2; //2 bytes: tag for TX_EXTRA_NONCE(1 byte), counter in TX_EXTRA_NONCE(1 byte)
1304  else
1305  res.reserved_offset = 0;
1306  if(res.reserved_offset + req.reserve_size > block_blob.size())
1307  {
1309  error_resp.message = "Internal error: failed to create block template";
1310  LOG_ERROR("Failed to calculate offset for ");
1311  return false;
1312  }
1313  blobdata hashing_blob = get_block_hashing_blob(b);
1314  res.prev_hash = string_tools::pod_to_hex(b.prev_id);
1315  res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob);
1316  res.blockhashing_blob = string_tools::buff_to_hex_nodelimer(hashing_blob);
1317  res.status = CORE_RPC_STATUS_OK;
1318  return true;
1319  }
virtual bool get_block_template(block &b, const account_public_address &adr, difficulty_type &diffic, uint64_t &height, uint64_t &expected_reward, const blobdata &ex_nonce)
creates a new block to mine against
#define CORE_RPC_ERROR_CODE_WRONG_WALLET_ADDRESS
#define CORE_RPC_ERROR_CODE_CORE_BUSY
#define CORE_RPC_ERROR_CODE_MINING_TO_SUBADDRESS
#define CORE_RPC_ERROR_CODE_TOO_BIG_RESERVE_SIZE
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
const crypto::public_key null_pkey
Definition: crypto.cpp:72
POD_CLASS public_key
Definition: crypto.h:76
blobdata get_block_hashing_blob(const block &b)
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
size_t slow_memmem(const void *start_buff, size_t buflen, const void *pat, size_t patlen)
bool hex_to_pod(const std::string &hex_str, t_pod_type &s)
Definition: string_tools.h:324
CXA_THROW_INFO_T * info
Definition: stack_trace.cpp:91
Here is the call graph for this function:

◆ on_hard_fork_info()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1857 of file core_rpc_server.cpp.

1858  {
1860  bool r;
1861  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_HARD_FORK_INFO>(invoke_http_mode::JON_RPC, "hard_fork_info", req, res, r))
1862  return r;
1863 
1864  const Blockchain &blockchain = m_core.get_blockchain_storage();
1865  uint8_t version = req.version > 0 ? req.version : blockchain.get_next_hard_fork_version();
1866  res.version = blockchain.get_current_hard_fork_version();
1867  res.enabled = blockchain.get_hard_fork_voting_info(version, res.window, res.votes, res.threshold, res.earliest_height, res.voting);
1868  res.state = blockchain.get_hard_fork_state();
1869  res.status = CORE_RPC_STATUS_OK;
1870  return true;
1871  }
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
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_in_peers()

bool cryptonote::core_rpc_server::on_in_peers ( const COMMAND_RPC_IN_PEERS::request req,
COMMAND_RPC_IN_PEERS::response res,
const connection_context ctx = NULL 
)

Definition at line 2161 of file core_rpc_server.cpp.

2162  {
2164  m_p2p.change_max_in_public_peers(req.in_peers);
2165  res.status = CORE_RPC_STATUS_OK;
2166  return true;
2167  }
bool on_in_peers(const COMMAND_RPC_IN_PEERS::request &req, COMMAND_RPC_IN_PEERS::response &res, const connection_context *ctx=NULL)
void change_max_in_public_peers(size_t count)
Here is the caller graph for this function:

◆ on_inject_emergency_vlist()

bool cryptonote::core_rpc_server::on_inject_emergency_vlist ( const COMMAND_RPC_INJECT_EMERGENCY_VLIST::request req,
COMMAND_RPC_INJECT_EMERGENCY_VLIST::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 2447 of file core_rpc_server.cpp.

2448  {
2449  if(!req.blob.empty()) {
2450 
2452  arg.serialized_v_list = electroneum::basic::store_t_to_json(req);
2453  cryptonote_connection_context context = boost::value_initialized<cryptonote_connection_context>();
2454 
2455 
2456  electroneum::basic::list_update_outcome update_outcome = m_core.set_validators_list(arg.serialized_v_list, true);
2459  LOG_PRINT_CCONTEXT_L0("Local list is a legitimate emergency list and will now be relayed.");
2460 
2462  LOG_PRINT_CCONTEXT_L0("List successfully deployed to peers via p2p.");
2463  return true;
2464  }
2465  }
2466  else {
2467  LOG_ERROR_CCONTEXT("Received incorrect emergency Validators List for relay.");
2468  return false;
2469  }
2470  }
2471 
2472  return false;
2473  }
i_cryptonote_protocol * get_protocol()
get the cryptonote protocol instance
electroneum::basic::list_update_outcome set_validators_list(std::string v_list, bool isEmergencyUpdate)
set the list of validators according to the serialized string passed in as parameter
#define AUTO_VAL_INIT(v)
Definition: misc_language.h:53
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
Definition: zmq.h:98
#define LOG_ERROR_CCONTEXT(message)
#define LOG_PRINT_CCONTEXT_L0(message)
epee::misc_utils::struct_init< request_t > request
virtual bool relay_emergency_validator_list(NOTIFY_EMERGENCY_VALIDATORS_LIST::request &arg, cryptonote_connection_context &exclude_context)=0
Here is the call graph for this function:

◆ on_is_key_image_spent()

bool cryptonote::core_rpc_server::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 
)

Definition at line 757 of file core_rpc_server.cpp.

758  {
760  bool ok;
761  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_IS_KEY_IMAGE_SPENT>(invoke_http_mode::JON, "/is_key_image_spent", req, res, ok))
762  return ok;
763 
764  const bool restricted = m_restricted && ctx;
765  const bool request_has_rpc_origin = ctx != NULL;
766  std::vector<crypto::key_image> key_images;
767  for(const auto& ki_hex_str: req.key_images)
768  {
769  blobdata b;
770  if(!string_tools::parse_hexstr_to_binbuff(ki_hex_str, b))
771  {
772  res.status = "Failed to parse hex representation of key image";
773  return true;
774  }
775  if(b.size() != sizeof(crypto::key_image))
776  {
777  res.status = "Failed, size of data mismatch";
778  }
779  key_images.push_back(*reinterpret_cast<const crypto::key_image*>(b.data()));
780  }
781  std::vector<bool> spent_status;
782  bool r = m_core.are_key_images_spent(key_images, spent_status);
783  if(!r)
784  {
785  res.status = "Failed";
786  return true;
787  }
788  res.spent_status.clear();
789  for (size_t n = 0; n < spent_status.size(); ++n)
791 
792  // check the pool too
793  std::vector<cryptonote::tx_info> txs;
794  std::vector<cryptonote::spent_key_image_info> ki;
795  r = m_core.get_pool_transactions_and_spent_keys_info(txs, ki, !request_has_rpc_origin || !restricted);
796  if(!r)
797  {
798  res.status = "Failed";
799  return true;
800  }
801  for (std::vector<cryptonote::spent_key_image_info>::const_iterator i = ki.begin(); i != ki.end(); ++i)
802  {
804  crypto::key_image spent_key_image;
805  if (parse_hash256(i->id_hash, hash))
806  {
807  memcpy(&spent_key_image, &hash, sizeof(hash)); // a bit dodgy, should be other parse functions somewhere
808  for (size_t n = 0; n < res.spent_status.size(); ++n)
809  {
810  if (res.spent_status[n] == COMMAND_RPC_IS_KEY_IMAGE_SPENT::UNSPENT)
811  {
812  if (key_images[n] == spent_key_image)
813  {
815  break;
816  }
817  }
818  }
819  }
820  }
821 
822  res.status = CORE_RPC_STATUS_OK;
823  return true;
824  }
bool on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request &req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response &res, const connection_context *ctx=NULL)
bool are_key_images_spent(const std::vector< crypto::key_image > &key_im, std::vector< bool > &spent) const
check if multiple key images are spent
void * memcpy(void *a, const void *b, size_t c)
POD_CLASS key_image
Definition: crypto.h:102
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_mining_status()

bool cryptonote::core_rpc_server::on_mining_status ( const COMMAND_RPC_MINING_STATUS::request req,
COMMAND_RPC_MINING_STATUS::response res,
const connection_context ctx = NULL 
)

Definition at line 976 of file core_rpc_server.cpp.

977  {
979 
980  const miner& lMiner = m_core.get_miner();
981  res.active = lMiner.is_mining();
982  res.is_background_mining_enabled = lMiner.get_is_background_mining_enabled();
983  store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64);
984 
986  if ( lMiner.is_mining() ) {
987  res.speed = lMiner.get_speed();
988  res.threads_count = lMiner.get_threads_count();
989  res.block_reward = lMiner.get_block_reward();
990  }
991  const account_public_address& lMiningAdr = lMiner.get_mining_address();
992  res.address = get_account_address_as_str(nettype(), false, lMiningAdr);
993  const uint8_t major_version = m_core.get_blockchain_storage().get_current_hard_fork_version();
994  const unsigned variant = major_version >= 7 ? major_version - 6 : 0;
995  switch (variant)
996  {
997  case 0: res.pow_algorithm = "Cryptonight"; break;
998  case 1: res.pow_algorithm = "CNv1 (Cryptonight variant 1)"; break;
999  case 2: case 3: res.pow_algorithm = "CNv2 (Cryptonight variant 2)"; break;
1000  case 4: case 5: res.pow_algorithm = "CNv4 (Cryptonight variant 4)"; break;
1001  default: res.pow_algorithm = "I'm not sure actually"; break;
1002  }
1003  if (res.is_background_mining_enabled)
1004  {
1005  res.bg_idle_threshold = lMiner.get_idle_threshold();
1006  res.bg_min_idle_seconds = lMiner.get_min_idle_seconds();
1007  res.bg_ignore_battery = lMiner.get_ignore_battery();
1008  res.bg_target = lMiner.get_mining_target();
1009  }
1010 
1011  res.status = CORE_RPC_STATUS_OK;
1012  return true;
1013  }
uint8_t get_current_hard_fork_version() const
gets the current hardfork version in use/voted for
Definition: blockchain.h:815
bool on_mining_status(const COMMAND_RPC_MINING_STATUS::request &req, COMMAND_RPC_MINING_STATUS::response &res, const connection_context *ctx=NULL)
miner & get_miner()
gets the miner instance
#define DIFFICULTY_TARGET
#define DIFFICULTY_TARGET_V6
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:

◆ on_out_peers()

bool cryptonote::core_rpc_server::on_out_peers ( const COMMAND_RPC_OUT_PEERS::request req,
COMMAND_RPC_OUT_PEERS::response res,
const connection_context ctx = NULL 
)

Definition at line 2153 of file core_rpc_server.cpp.

2154  {
2156  m_p2p.change_max_out_public_peers(req.out_peers);
2157  res.status = CORE_RPC_STATUS_OK;
2158  return true;
2159  }
bool on_out_peers(const COMMAND_RPC_OUT_PEERS::request &req, COMMAND_RPC_OUT_PEERS::response &res, const connection_context *ctx=NULL)
void change_max_out_public_peers(size_t count)
Here is the caller graph for this function:

◆ on_pop_blocks()

bool cryptonote::core_rpc_server::on_pop_blocks ( const COMMAND_RPC_POP_BLOCKS::request req,
COMMAND_RPC_POP_BLOCKS::response res,
const connection_context ctx = NULL 
)

Definition at line 2287 of file core_rpc_server.cpp.

2288  {
2290 
2291  m_core.get_blockchain_storage().pop_blocks(req.nblocks);
2292 
2293  res.height = m_core.get_current_blockchain_height();
2294  res.status = CORE_RPC_STATUS_OK;
2295 
2296  return true;
2297  }
void pop_blocks(uint64_t nblocks)
removes blocks from the top of the blockchain
Definition: blockchain.cpp:586
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 caller graph for this function:

◆ on_prune_blockchain()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2552 of file core_rpc_server.cpp.

2553  {
2554  try
2555  {
2556  if (!(req.check ? m_core.check_blockchain_pruning() : m_core.prune_blockchain()))
2557  {
2559  error_resp.message = req.check ? "Failed to check blockchain pruning" : "Failed to prune blockchain";
2560  return false;
2561  }
2562  res.pruning_seed = m_core.get_blockchain_pruning_seed();
2563  res.pruned = res.pruning_seed != 0;
2564  }
2565  catch (const std::exception &e)
2566  {
2568  error_resp.message = "Failed to prune blockchain";
2569  return false;
2570  }
2571 
2572  res.status = CORE_RPC_STATUS_OK;
2573  return true;
2574  }
uint32_t get_blockchain_pruning_seed() const
get the blockchain pruning seed
bool check_blockchain_pruning()
checks the blockchain pruning if enabled
bool prune_blockchain(uint32_t pruning_seed=0)
prune the blockchain
Here is the caller graph for this function:

◆ on_relay_tx()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2299 of file core_rpc_server.cpp.

2300  {
2302 
2303  bool failed = false;
2304  res.status = "";
2305  for (const auto &str: req.txids)
2306  {
2307  cryptonote::blobdata txid_data;
2308  if(!epee::string_tools::parse_hexstr_to_binbuff(str, txid_data))
2309  {
2310  if (!res.status.empty()) res.status += ", ";
2311  res.status += std::string("invalid transaction id: ") + str;
2312  failed = true;
2313  continue;
2314  }
2315  crypto::hash txid = *reinterpret_cast<const crypto::hash*>(txid_data.data());
2316 
2317  cryptonote::blobdata txblob;
2318  bool r = m_core.get_pool_transaction(txid, txblob);
2319  if (r)
2320  {
2321  cryptonote_connection_context fake_context = AUTO_VAL_INIT(fake_context);
2323  r.txs.push_back(txblob);
2324  m_core.get_protocol()->relay_transactions(r, fake_context);
2325  //TODO: make sure that tx has reached other nodes here, probably wait to receive reflections from other nodes
2326  }
2327  else
2328  {
2329  if (!res.status.empty()) res.status += ", ";
2330  res.status += std::string("transaction not found in pool: ") + str;
2331  failed = true;
2332  continue;
2333  }
2334  }
2335 
2336  if (failed)
2337  {
2338  return false;
2339  }
2340 
2341  res.status = CORE_RPC_STATUS_OK;
2342  return true;
2343  }
bool on_relay_tx(const COMMAND_RPC_RELAY_TX::request &req, COMMAND_RPC_RELAY_TX::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool get_pool_transaction(const crypto::hash &id, cryptonote::blobdata &tx) const
get a specific transaction from the pool
epee::misc_utils::struct_init< request_t > request
virtual bool relay_transactions(NOTIFY_NEW_TRANSACTIONS::request &arg, cryptonote_connection_context &exclude_context)=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_save_bc()

bool cryptonote::core_rpc_server::on_save_bc ( const COMMAND_RPC_SAVE_BC::request req,
COMMAND_RPC_SAVE_BC::response res,
const connection_context ctx = NULL 
)

Definition at line 1015 of file core_rpc_server.cpp.

1016  {
1018  if( !m_core.get_blockchain_storage().store_blockchain() )
1019  {
1020  res.status = "Error while storing blockchain";
1021  return true;
1022  }
1023  res.status = CORE_RPC_STATUS_OK;
1024  return true;
1025  }
bool store_blockchain()
stores the blockchain
Definition: blockchain.cpp:516
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 caller graph for this function:

◆ on_send_raw_tx()

bool cryptonote::core_rpc_server::on_send_raw_tx ( const COMMAND_RPC_SEND_RAW_TX::request req,
COMMAND_RPC_SEND_RAW_TX::response res,
const connection_context ctx = NULL 
)

Definition at line 826 of file core_rpc_server.cpp.

827  {
829  bool ok;
830  if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_SEND_RAW_TX>(invoke_http_mode::JON, "/sendrawtransaction", req, res, ok))
831  return ok;
832 
834 
835  std::string tx_blob;
836  if(!string_tools::parse_hexstr_to_binbuff(req.tx_as_hex, tx_blob))
837  {
838  LOG_PRINT_L0("[on_send_raw_tx]: Failed to parse tx from hexbuff: " << req.tx_as_hex);
839  res.status = "Failed";
840  return true;
841  }
842 
843  if (req.do_sanity_checks && !cryptonote::tx_sanity_check(m_core.get_blockchain_storage(), tx_blob))
844  {
845  res.status = "Failed";
846  res.reason = "Sanity check failed";
847  res.sanity_check_failed = true;
848  return true;
849  }
850  res.sanity_check_failed = false;
851 
852  cryptonote_connection_context fake_context = AUTO_VAL_INIT(fake_context);
853  tx_verification_context tvc = AUTO_VAL_INIT(tvc);
854  if(!m_core.handle_incoming_tx(tx_blob, tvc, false, false, req.do_not_relay) || tvc.m_verification_failed)
855  {
856  res.status = "Failed";
857  std::string reason = "";
858  if ((res.low_mixin = tvc.m_low_mixin))
859  add_reason(reason, "bad ring size");
860  if ((res.double_spend = tvc.m_double_spend))
861  add_reason(reason, "double spend");
862  if ((res.double_spend = tvc.m_utxo_nonexistent))
863  add_reason(reason, "utxo has been spent already or doesn't exist");
864  if ((res.invalid_input = tvc.m_invalid_input))
865  add_reason(reason, "invalid input");
866  if ((res.invalid_output = tvc.m_invalid_output))
867  add_reason(reason, "invalid output");
868  if ((res.too_big = tvc.m_too_big))
869  add_reason(reason, "too big");
870  if ((res.overspend = tvc.m_overspend))
871  add_reason(reason, "overspend");
872  if ((res.fee_too_low = tvc.m_fee_too_low))
873  add_reason(reason, "fee too low");
874  if ((res.not_rct = tvc.m_not_rct))
875  add_reason(reason, "tx is not ringct");
876  const std::string punctuation = reason.empty() ? "" : ": ";
877  if (tvc.m_verification_failed)
878  {
879  LOG_PRINT_L0("[on_send_raw_tx]: tx verification failed" << punctuation << reason);
880  }
881  else
882  {
883  LOG_PRINT_L0("[on_send_raw_tx]: Failed to process tx" << punctuation << reason);
884  }
885  return true;
886  }
887 
888  if(!tvc.m_should_be_relayed)
889  {
890  LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed");
891  res.reason = "Not relayed";
892  res.not_relayed = true;
893  res.status = CORE_RPC_STATUS_OK;
894  return true;
895  }
896 
898  r.txs.push_back(tx_blob);
899  m_core.get_protocol()->relay_transactions(r, fake_context);
900  //TODO: make sure that tx has reached other nodes here, probably wait to receive reflections from other nodes
901  res.status = CORE_RPC_STATUS_OK;
902  return true;
903  }
bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request &req, COMMAND_RPC_SEND_RAW_TX::response &res, const connection_context *ctx=NULL)
bool handle_incoming_tx(const blobdata &tx_blob, tx_verification_context &tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
handles an incoming transaction
#define LOG_PRINT_L0(x)
Definition: misc_log_ex.h:99
bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_set_bans()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1897 of file core_rpc_server.cpp.

1898  {
1900 
1901  for (auto i = req.bans.begin(); i != req.bans.end(); ++i)
1902  {
1904  if (!i->host.empty())
1905  {
1906  auto na_parsed = net::get_network_address(i->host, 0);
1907  if (!na_parsed)
1908  {
1910  error_resp.message = "Unsupported host type";
1911  return false;
1912  }
1913  na = std::move(*na_parsed);
1914  }
1915  else
1916  {
1918  }
1919  if (i->ban) {
1920  if (i->seconds < -1) {
1922  error_resp.message = "Please pick a value for seconds >= -1";
1923  return false;
1924  } else if (i->seconds == -1) {
1925  m_p2p.block_host(na, uint32_t(std::numeric_limits<time_t>::max()));
1926  } else {
1927  m_p2p.block_host(na, uint32_t(i->seconds));
1928  }
1929  }
1930  else{
1931  m_p2p.unblock_host(na);
1932  }
1933 
1934  }
1935 
1936  res.status = CORE_RPC_STATUS_OK;
1937  return true;
1938  }
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)
virtual bool unblock_host(const epee::net_utils::network_address &address)
virtual bool block_host(const epee::net_utils::network_address &adress, time_t seconds=P2P_IP_BLOCKTIME)
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
Definition: parse.cpp:38
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_set_limit()

bool cryptonote::core_rpc_server::on_set_limit ( const COMMAND_RPC_SET_LIMIT::request req,
COMMAND_RPC_SET_LIMIT::response res,
const connection_context ctx = NULL 
)

Definition at line 2113 of file core_rpc_server.cpp.

2114  {
2116  // -1 = reset to default
2117  // 0 = do not modify
2118 
2119  if (req.limit_down > 0)
2120  {
2122  }
2123  else if (req.limit_down < 0)
2124  {
2125  if (req.limit_down != -1)
2126  {
2128  return false;
2129  }
2131  }
2132 
2133  if (req.limit_up > 0)
2134  {
2136  }
2137  else if (req.limit_up < 0)
2138  {
2139  if (req.limit_up != -1)
2140  {
2142  return false;
2143  }
2145  }
2146 
2149  res.status = CORE_RPC_STATUS_OK;
2150  return true;
2151  }
bool on_set_limit(const COMMAND_RPC_SET_LIMIT::request &req, COMMAND_RPC_SET_LIMIT::response &res, const connection_context *ctx=NULL)
static void set_rate_down_limit(uint64_t limit)
static void set_rate_up_limit(uint64_t limit)
const int64_t default_limit_up
Definition: net_node.h:481
const int64_t default_limit_down
Definition: net_node.h:482
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_set_log_categories()

bool cryptonote::core_rpc_server::on_set_log_categories ( const COMMAND_RPC_SET_LOG_CATEGORIES::request req,
COMMAND_RPC_SET_LOG_CATEGORIES::response res,
const connection_context ctx = NULL 
)

Definition at line 1086 of file core_rpc_server.cpp.

1087  {
1089  mlog_set_log(req.categories.c_str());
1090  res.categories = mlog_get_categories();
1091  res.status = CORE_RPC_STATUS_OK;
1092  return true;
1093  }
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)
std::string mlog_get_categories()
Definition: mlog.cpp:276
void mlog_set_log(const char *log)
Definition: mlog.cpp:288
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_set_log_hash_rate()

bool cryptonote::core_rpc_server::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 
)

Definition at line 1058 of file core_rpc_server.cpp.

1059  {
1061  if(m_core.get_miner().is_mining())
1062  {
1063  m_core.get_miner().do_print_hashrate(req.visible);
1064  res.status = CORE_RPC_STATUS_OK;
1065  }
1066  else
1067  {
1069  }
1070  return true;
1071  }
bool on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request &req, COMMAND_RPC_SET_LOG_HASH_RATE::response &res, const connection_context *ctx=NULL)
bool is_mining() const
Definition: miner.cpp:352
void do_print_hashrate(bool do_hr)
Definition: miner.cpp:198
#define CORE_RPC_STATUS_NOT_MINING
Here is the caller graph for this function:

◆ on_set_log_level()

bool cryptonote::core_rpc_server::on_set_log_level ( const COMMAND_RPC_SET_LOG_LEVEL::request req,
COMMAND_RPC_SET_LOG_LEVEL::response res,
const connection_context ctx = NULL 
)

Definition at line 1073 of file core_rpc_server.cpp.

1074  {
1076  if (req.level > 4)
1077  {
1078  res.status = "Error: log level not valid";
1079  return true;
1080  }
1081  mlog_set_log_level(req.level);
1082  res.status = CORE_RPC_STATUS_OK;
1083  return true;
1084  }
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)
void mlog_set_log_level(int level)
Definition: mlog.cpp:282
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_set_validator_key()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2392 of file core_rpc_server.cpp.

2393  {
2394  if(!m_core.set_validator_key(req.validator_key)) {
2396  error_resp.message = "Failed to set Validator Key. Wrong format.";
2397  return false;
2398  }
2399 
2400  res.status = CORE_RPC_STATUS_OK;
2401  return true;
2402  }
bool set_validator_key(std::string key)
set validator key
Here is the caller graph for this function:

◆ on_sign_message()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2422 of file core_rpc_server.cpp.

2423  {
2424  try {
2425  std::string v = m_core.sign_message(boost::algorithm::unhex(req.privateKey), req.message);
2426 
2427  if (v.empty()) {
2429  error_resp.message = "Failed to sign message.";
2430  return false;
2431  }
2432 
2433  res.signature = v;
2434  }
2435  catch(const std::exception &e)
2436  {
2438  error_resp.message = "Failed to sign message. Please check that you are using a valid private key.";
2439  return false;
2440  }
2441 
2442  res.status = CORE_RPC_STATUS_OK;
2443  return true;
2444  }
std::string sign_message(std::string sk, std::string msg)
Here is the caller graph for this function:

◆ on_start_mining()

bool cryptonote::core_rpc_server::on_start_mining ( const COMMAND_RPC_START_MINING::request req,
COMMAND_RPC_START_MINING::response res,
const connection_context ctx = NULL 
)

Definition at line 905 of file core_rpc_server.cpp.

906  {
910  if(!get_account_address_from_str(info, nettype(), req.miner_address))
911  {
912  res.status = "Failed, wrong address";
913  LOG_PRINT_L0(res.status);
914  return true;
915  }
916  if (info.is_subaddress)
917  {
918  res.status = "Mining to subaddress isn't supported yet";
919  LOG_PRINT_L0(res.status);
920  return true;
921  }
922 
923  unsigned int concurrency_count = boost::thread::hardware_concurrency() * 4;
924 
925  // if we couldn't detect threads, set it to a ridiculously high number
926  if(concurrency_count == 0)
927  {
928  concurrency_count = 257;
929  }
930 
931  // if there are more threads requested than the hardware supports
932  // then we fail and log that.
933  if(req.threads_count > concurrency_count)
934  {
935  res.status = "Failed, too many threads relative to CPU cores.";
936  LOG_PRINT_L0(res.status);
937  return true;
938  }
939 
940  cryptonote::miner &miner= m_core.get_miner();
941  if (miner.is_mining())
942  {
943  res.status = "Already mining";
944  return true;
945  }
946  if(!miner.start(info.address, static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
947  {
948  res.status = "Failed, mining not started";
949  LOG_PRINT_L0(res.status);
950  return true;
951  }
952  res.status = CORE_RPC_STATUS_OK;
953  return true;
954  }
bool on_start_mining(const COMMAND_RPC_START_MINING::request &req, COMMAND_RPC_START_MINING::response &res, const connection_context *ctx=NULL)
bool start(const account_public_address &adr, size_t threads_count, bool do_background=false, bool ignore_battery=false)
Definition: miner.cpp:366
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_start_save_graph()

bool cryptonote::core_rpc_server::on_start_save_graph ( const COMMAND_RPC_START_SAVE_GRAPH::request req,
COMMAND_RPC_START_SAVE_GRAPH::response res,
const connection_context ctx = NULL 
)

Definition at line 2169 of file core_rpc_server.cpp.

2170  {
2172  m_p2p.set_save_graph(true);
2173  res.status = CORE_RPC_STATUS_OK;
2174  return true;
2175  }
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)
void set_save_graph(bool save_graph)
Definition: net_node.h:401
Here is the caller graph for this function:

◆ on_stop_daemon()

bool cryptonote::core_rpc_server::on_stop_daemon ( const COMMAND_RPC_STOP_DAEMON::request req,
COMMAND_RPC_STOP_DAEMON::response res,
const connection_context ctx = NULL 
)

Definition at line 1157 of file core_rpc_server.cpp.

1158  {
1160  // FIXME: replace back to original m_p2p.send_stop_signal() after
1161  // investigating why that isn't working quite right.
1162  m_p2p.send_stop_signal();
1163  res.status = CORE_RPC_STATUS_OK;
1164  return true;
1165  }
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 caller graph for this function:

◆ on_stop_mining()

bool cryptonote::core_rpc_server::on_stop_mining ( const COMMAND_RPC_STOP_MINING::request req,
COMMAND_RPC_STOP_MINING::response res,
const connection_context ctx = NULL 
)

Definition at line 956 of file core_rpc_server.cpp.

957  {
959  cryptonote::miner &miner= m_core.get_miner();
960  if(!miner.is_mining())
961  {
962  res.status = "Mining never started";
963  LOG_PRINT_L0(res.status);
964  return true;
965  }
966  if(!miner.stop())
967  {
968  res.status = "Failed, mining not stopped";
969  LOG_PRINT_L0(res.status);
970  return true;
971  }
972  res.status = CORE_RPC_STATUS_OK;
973  return true;
974  }
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:

◆ on_stop_save_graph()

bool cryptonote::core_rpc_server::on_stop_save_graph ( const COMMAND_RPC_STOP_SAVE_GRAPH::request req,
COMMAND_RPC_STOP_SAVE_GRAPH::response res,
const connection_context ctx = NULL 
)

Definition at line 2177 of file core_rpc_server.cpp.

2178  {
2180  m_p2p.set_save_graph(false);
2181  res.status = CORE_RPC_STATUS_OK;
2182  return true;
2183  }
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 caller graph for this function:

◆ on_submitblock()

bool cryptonote::core_rpc_server::on_submitblock ( const COMMAND_RPC_SUBMITBLOCK::request req,
COMMAND_RPC_SUBMITBLOCK::response res,
epee::json_rpc::error error_resp,
const connection_context ctx = NULL 
)

Definition at line 1321 of file core_rpc_server.cpp.

1322  {
1324  {
1325  boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1326  if (m_should_use_bootstrap_daemon)
1327  {
1328  res.status = "This command is unsupported for bootstrap daemon";
1329  return false;
1330  }
1331  }
1332  CHECK_CORE_READY();
1333  if(req.size()!=1)
1334  {
1336  error_resp.message = "Wrong param";
1337  return false;
1338  }
1339  blobdata blockblob;
1340  if(!string_tools::parse_hexstr_to_binbuff(req[0], blockblob))
1341  {
1343  error_resp.message = "Wrong block blob";
1344  return false;
1345  }
1346 
1347  // Fixing of high orphan issue for most pools
1348  // Thanks Boolberry!
1349  block b;
1350  if(!parse_and_validate_block_from_blob(blockblob, b))
1351  {
1353  error_resp.message = "Wrong block blob";
1354  return false;
1355  }
1356 
1357  // Fix from Boolberry neglects to check block
1358  // size, do that with the function below
1359  if(!m_core.check_incoming_block_size(blockblob))
1360  {
1362  error_resp.message = "Block bloc size is too big, rejecting block";
1363  return false;
1364  }
1365 
1366  block_verification_context bvc;
1367  if(!m_core.handle_block_found(b, bvc))
1368  {
1370  error_resp.message = "Block not accepted";
1371  return false;
1372  }
1373  res.status = CORE_RPC_STATUS_OK;
1374  return true;
1375  }
virtual bool handle_block_found(block &b, block_verification_context &bvc)
stores and relays a block found by a miner
bool check_incoming_block_size(const blobdata &block_blob) const
check the size of a block against the current maximum
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB_SIZE
#define CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED
Here is the call graph for this function:

◆ on_sync_info()

bool cryptonote::core_rpc_server::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 
)

Definition at line 2345 of file core_rpc_server.cpp.

2346  {
2348 
2349  crypto::hash top_hash;
2350  m_core.get_blockchain_top(res.height, top_hash);
2351  ++res.height; // turn top block height into blockchain height
2352  res.target_height = m_core.get_target_blockchain_height();
2353  res.next_needed_pruning_seed = m_p2p.get_payload_object().get_next_needed_pruning_stripe().second;
2354 
2355  for (const auto &c: m_p2p.get_payload_object().get_connections())
2356  res.peers.push_back({c});
2357  const cryptonote::block_queue &block_queue = m_p2p.get_payload_object().get_block_queue();
2358  block_queue.foreach([&](const cryptonote::block_queue::span &span) {
2359  const std::string span_connection_id = epee::string_tools::pod_to_hex(span.connection_id);
2360  uint32_t speed = (uint32_t)(100.0f * block_queue.get_speed(span.connection_id) + 0.5f);
2361  std::string address = "";
2362  for (const auto &c: m_p2p.get_payload_object().get_connections())
2363  if (c.connection_id == span_connection_id)
2364  address = c.address;
2365  res.spans.push_back({span.start_block_height, span.nblocks, span_connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, address});
2366  return true;
2367  });
2368  res.overview = block_queue.get_overview(res.height);
2369 
2370  res.status = CORE_RPC_STATUS_OK;
2371  return true;
2372  }
float get_speed(const boost::uuids::uuid &connection_id) const
bool foreach(std::function< bool(const span &)> f) const
std::string get_overview(uint64_t blockchain_height) const
bool on_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)
std::pair< uint32_t, uint32_t > get_next_needed_pruning_stripe() const
Non-owning sequence of data. Does not deep copy.
Definition: span.h:57
constexpr std::size_t size() const noexcept
Definition: span.h:111
const char * address
Definition: multisig.cpp:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_update()

bool cryptonote::core_rpc_server::on_update ( const COMMAND_RPC_UPDATE::request req,
COMMAND_RPC_UPDATE::response res,
const connection_context ctx = NULL 
)

Definition at line 2185 of file core_rpc_server.cpp.

2186  {
2188 
2189  if (m_core.offline())
2190  {
2191  res.status = "Daemon is running offline";
2192  return true;
2193  }
2194 
2195  static const char software[] = "electroneum";
2196 #ifdef BUILD_TAG
2197  static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG);
2198  static const char subdir[] = "cli";
2199 #else
2200  static const char buildtag[] = "source";
2201  static const char subdir[] = "source";
2202 #endif
2203  LOG_PRINT_L0(req.command << " for software: " << software << "; buildtag: " << buildtag << "; subdir:" << subdir);
2204  if (req.command != "check" && req.command != "download" && req.command != "update")
2205  {
2206  res.status = std::string("unknown command: '") + req.command + "'";
2207  return true;
2208  }
2209 
2211  if (!tools::check_updates(software, buildtag, version, hash))
2212  {
2213  res.status = "Error checking for updates";
2214  return true;
2215  }
2216  if (tools::vercmp(version.c_str(), ELECTRONEUM_VERSION) <= 0)
2217  {
2218  res.update = false;
2219  res.status = CORE_RPC_STATUS_OK;
2220  return true;
2221  }
2222  res.update = true;
2223  res.version = version;
2224  res.user_uri = tools::get_update_url(software, subdir, buildtag, version, true);
2225  res.auto_uri = tools::get_update_url(software, subdir, buildtag, version, false);
2226  res.hash = hash;
2227  if (req.command == "check")
2228  {
2229  res.status = CORE_RPC_STATUS_OK;
2230  return true;
2231  }
2232 
2233  boost::filesystem::path path;
2234  if (req.path.empty())
2235  {
2236  std::string filename;
2237  const char *slash = strrchr(res.auto_uri.c_str(), '/');
2238  if (slash)
2239  filename = slash + 1;
2240  else
2241  filename = std::string(software) + "-update-" + version;
2243  path /= filename;
2244  }
2245  else
2246  {
2247  path = req.path;
2248  }
2249 
2250  crypto::hash file_hash;
2251  if (!tools::sha256sum(path.string(), file_hash) || (hash != epee::string_tools::pod_to_hex(file_hash)))
2252  {
2253  MDEBUG("We don't have that file already, downloading");
2254  if (!tools::download(path.string(), res.auto_uri))
2255  {
2256  MERROR("Failed to download " << res.auto_uri);
2257  return false;
2258  }
2259  if (!tools::sha256sum(path.string(), file_hash))
2260  {
2261  MERROR("Failed to hash " << path);
2262  return false;
2263  }
2264  if (hash != epee::string_tools::pod_to_hex(file_hash))
2265  {
2266  MERROR("Download from " << res.auto_uri << " does not match the expected hash");
2267  return false;
2268  }
2269  MINFO("New version downloaded to " << path);
2270  }
2271  else
2272  {
2273  MDEBUG("We already have " << path << " with expected hash");
2274  }
2275  res.path = path.string();
2276 
2277  if (req.command == "download")
2278  {
2279  res.status = CORE_RPC_STATUS_OK;
2280  return true;
2281  }
2282 
2283  res.status = "'update' not implemented yet";
2284  return true;
2285  }
bool on_update(const COMMAND_RPC_UPDATE::request &req, COMMAND_RPC_UPDATE::response &res, const connection_context *ctx=NULL)
#define MINFO(x)
Definition: misc_log_ex.h:75
std::string & get_current_module_folder()
Definition: string_tools.h:233
int vercmp(const char *v0, const char *v1)
Definition: util.cpp:915
bool sha256sum(const uint8_t *data, size_t len, crypto::hash &hash)
Definition: util.cpp:933
std::string get_update_url(const std::string &software, const std::string &subdir, const std::string &buildtag, const std::string &version, bool user)
Definition: updates.cpp:101
bool download(const std::string &path, const std::string &url, std::function< bool(const std::string &, const std::string &, size_t, ssize_t)> cb)
Definition: download.cpp:258
bool check_updates(const std::string &software, const std::string &buildtag, std::string &version, std::string &hash)
Definition: updates.cpp:41
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ arg_bootstrap_daemon_address

const command_line::arg_descriptor< std::string > cryptonote::core_rpc_server::arg_bootstrap_daemon_address
static
Initial value:
= {
"bootstrap-daemon-address"
, "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced"
, ""
}

Definition at line 70 of file core_rpc_server.h.

◆ arg_bootstrap_daemon_login

const command_line::arg_descriptor< std::string > cryptonote::core_rpc_server::arg_bootstrap_daemon_login
static
Initial value:
= {
"bootstrap-daemon-login"
, "Specify username:password for the bootstrap daemon login"
, ""
}

Definition at line 71 of file core_rpc_server.h.

◆ arg_public_node

const command_line::arg_descriptor<bool> cryptonote::core_rpc_server::arg_public_node
static

Definition at line 60 of file core_rpc_server.h.

◆ arg_restricted_rpc

const command_line::arg_descriptor< bool > cryptonote::core_rpc_server::arg_restricted_rpc
static
Initial value:
= {
"restricted-rpc"
, "Restrict RPC to view only commands and do not return privacy sensitive data in RPC calls"
, false
}

Definition at line 63 of file core_rpc_server.h.

◆ arg_rpc_bind_port

const command_line::arg_descriptor< std::string, false, true, 2 > cryptonote::core_rpc_server::arg_rpc_bind_port
static
Initial value:
= {
"rpc-bind-port"
, "Port for RPC server"
, [](std::array<bool, 2> testnet_stagenet, bool defaulted, std::string val)->std::string {
if (testnet_stagenet[0] && defaulted)
else if (testnet_stagenet[1] && defaulted)
return val;
}
}
uint16_t const RPC_DEFAULT_PORT
uint16_t const RPC_DEFAULT_PORT
uint16_t const RPC_DEFAULT_PORT
const command_line::arg_descriptor< bool, false > arg_testnet_on
const command_line::arg_descriptor< bool, false > arg_stagenet_on

Definition at line 61 of file core_rpc_server.h.

◆ arg_rpc_restricted_bind_port

const command_line::arg_descriptor< std::string > cryptonote::core_rpc_server::arg_rpc_restricted_bind_port
static
Initial value:
= {
"rpc-restricted-bind-port"
, "Port for restricted RPC server"
, ""
}

Definition at line 62 of file core_rpc_server.h.

◆ arg_rpc_ssl

const command_line::arg_descriptor<std::string> cryptonote::core_rpc_server::arg_rpc_ssl
static

Definition at line 64 of file core_rpc_server.h.

◆ arg_rpc_ssl_allow_any_cert

const command_line::arg_descriptor<bool> cryptonote::core_rpc_server::arg_rpc_ssl_allow_any_cert
static

Definition at line 69 of file core_rpc_server.h.

◆ arg_rpc_ssl_allowed_fingerprints

const command_line::arg_descriptor<std::vector<std::string> > cryptonote::core_rpc_server::arg_rpc_ssl_allowed_fingerprints
static

Definition at line 68 of file core_rpc_server.h.

◆ arg_rpc_ssl_ca_certificates

const command_line::arg_descriptor<std::string> cryptonote::core_rpc_server::arg_rpc_ssl_ca_certificates
static

Definition at line 67 of file core_rpc_server.h.

◆ arg_rpc_ssl_certificate

const command_line::arg_descriptor<std::string> cryptonote::core_rpc_server::arg_rpc_ssl_certificate
static

Definition at line 66 of file core_rpc_server.h.

◆ arg_rpc_ssl_private_key

const command_line::arg_descriptor<std::string> cryptonote::core_rpc_server::arg_rpc_ssl_private_key
static

Definition at line 65 of file core_rpc_server.h.


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