32 #include <boost/preprocessor/stringize.hpp>
57 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY
58 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "daemon.rpc"
60 #define MAX_RESTRICTED_FAKE_OUTS_COUNT 40
61 #define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT 5000
63 #define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION (3 * 86400)
67 void add_reason(
std::string &reasons,
const char *reason)
76 return (
value + quantum - 1) / quantum * quantum;
81 sdiff = (difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
83 stop64 = ((difficulty >> 64) & 0xffffffffffffffff).convert_to<
uint64_t>();
87 #define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION (3 * 86400)
103 core_rpc_server::core_rpc_server(
112 const boost::program_options::variables_map& vm
113 ,
const bool restricted
117 m_restricted = restricted;
125 if (!m_bootstrap_daemon_address.empty())
128 const auto loc = bootstrap_daemon_login.find(
':');
129 if (!bootstrap_daemon_login.empty() && loc != std::string::npos)
132 login.
username = bootstrap_daemon_login.substr(0, loc);
133 login.
password = bootstrap_daemon_login.substr(loc + 1);
140 m_should_use_bootstrap_daemon =
true;
144 m_should_use_bootstrap_daemon =
false;
146 m_was_bootstrap_ever_used =
false;
148 boost::optional<epee::net_utils::http::login> http_login{};
150 if (rpc_config->login)
151 http_login.emplace(
std::move(rpc_config->login->username),
std::move(rpc_config->login->password).password());
159 bool core_rpc_server::check_core_ready()
167 #define CHECK_CORE_READY() do { if(!check_core_ready()){res.status = CORE_RPC_STATUS_BUSY;return true;} } while(0)
174 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_HEIGHT>(invoke_http_mode::JON,
"/getheight", req,
res, r))
189 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_INFO>(invoke_http_mode::JON,
"/getinfo", req,
res, r))
191 res.bootstrap_daemon_address = m_bootstrap_daemon_address;
194 ++
res.height_without_bootstrap;
195 res.was_bootstrap_ever_used =
true;
199 const bool restricted = m_restricted && ctx;
213 res.incoming_connections_count = restricted ? 0 : (total_conn -
res.outgoing_connections_count);
222 res.nettype = net_type ==
MAINNET ?
"mainnet" : net_type ==
TESTNET ?
"testnet" : net_type ==
STAGENET ?
"stagenet" :
"fakechain";
224 res.cumulative_difficulty,
res.wide_cumulative_difficulty,
res.cumulative_difficulty_top64);
228 res.free_space = restricted ? std::numeric_limits<uint64_t>::max() : m_core.
get_free_space();
230 res.bootstrap_daemon_address = restricted ?
"" : m_bootstrap_daemon_address;
231 res.height_without_bootstrap = restricted ? 0 :
res.height;
233 res.was_bootstrap_ever_used =
false;
236 boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
237 res.was_bootstrap_ever_used = m_was_bootstrap_ever_used;
241 res.database_size = round_up(
res.database_size, 5ull* 1024 * 1024 * 1024);
285 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCKS_FAST>(invoke_http_mode::BIN,
"/getblocks.bin", req,
res,
r))
291 std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> >
297 res.status =
"Failed";
301 size_t pruned_size = 0, unpruned_size = 0, ntxes = 0;
304 res.blocks.reserve(bs.size());
305 res.output_indices.reserve(bs.size());
311 res.blocks.resize(
res.blocks.size()+1);
312 res.blocks.back().block = bd.first.first;
313 pruned_size += bd.first.first.size();
314 unpruned_size += bd.first.first.size();
316 ntxes += bd.second.size();
317 res.output_indices.back().indices.reserve(1 + bd.second.size());
320 res.blocks.back().txs.reserve(bd.second.size());
323 for (std::vector<std::pair<crypto::hash, cryptonote::blobdata>>::iterator i = bd.second.begin(); i != bd.second.end(); ++i)
325 unpruned_size += i->second.size();
328 i->second.shrink_to_fit();
329 pruned_size +=
res.blocks.back().txs.back().size();
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)
337 std::vector<std::vector<uint64_t>> indices;
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);
342 res.status =
"Failed";
345 if (indices.size() != n_txes_to_lookup ||
res.output_indices.back().indices.size() != (req.no_miner_tx ? 1 : 0))
347 res.status =
"Failed";
350 for (
size_t i = 0; i < indices.size(); ++i)
351 res.output_indices.back().indices.push_back({
std::move(indices[i])});
356 MDEBUG(
"on_get_blocks: " << bs.size() <<
" blocks, " << ntxes <<
" txes, pruned size " << pruned_size <<
", unpruned size " << unpruned_size);
364 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_ALT_BLOCKS_HASHES>(invoke_http_mode::JON,
"/get_alt_blocks_hashes", req,
res,
r))
367 std::vector<block> blks;
369 if(!m_core.get_alternative_blocks(blks))
371 res.status =
"Failed";
375 res.blks_hashes.reserve(blks.size());
377 for (
auto const& blk: blks)
382 MDEBUG(
"on_get_alt_blocks_hashes: " << blks.size() <<
" blocks " );
391 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCKS_BY_HEIGHT>(invoke_http_mode::BIN,
"/getblocks_by_height.bin", req,
res,
r))
394 res.status =
"Failed";
396 res.blocks.reserve(req.heights.size());
402 blk = m_core.get_blockchain_storage().get_db().get_block_from_height(
height);
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);
425 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_HASHES_FAST>(invoke_http_mode::BIN,
"/gethashes.bin", req,
res,
r))
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))
431 res.status =
"Failed";
443 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUTS_BIN>(invoke_http_mode::BIN,
"/get_outs.bin", req,
res,
r))
446 res.status =
"Failed";
448 const bool restricted = m_restricted && ctx;
453 res.status =
"Too many outs requested";
458 if(!m_core.get_outs(req,
res))
471 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUTS>(invoke_http_mode::JON,
"/get_outs", req,
res,
r))
474 res.status =
"Failed";
476 const bool restricted = m_restricted && ctx;
481 res.status =
"Too many outs requested";
487 req_bin.outputs = req.outputs;
488 req_bin.get_txid = req.get_txid;
490 if(!m_core.get_outs(req_bin, res_bin))
496 for (
const auto &i: res_bin.outs)
502 outkey.unlocked = i.unlocked;
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))
518 bool r = m_core.get_tx_outputs_gindexs(req.txid,
res.o_indexes);
521 res.status =
"Failed";
525 LOG_PRINT_L2(
"COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES: [" <<
res.o_indexes.size() <<
"]");
533 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTIONS>(invoke_http_mode::JON,
"/gettransactions", req,
res, ok))
536 std::vector<crypto::hash> vh;
537 for(
const auto& tx_hex_str: req.txs_hashes)
542 res.status =
"Failed to parse hex representation of transaction hash";
547 res.status =
"Failed, size of data mismatch";
550 vh.push_back(*
reinterpret_cast<const crypto::hash*
>(b.data()));
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);
557 res.status =
"Failed";
560 LOG_PRINT_L2(
"Found " << txs.size() <<
"/" << vh.size() <<
" transactions on the blockchain");
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())
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);
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;
579 if (std::find(missed_txs.begin(), missed_txs.end(), h) == missed_txs.end())
581 if (txs.size() == txs_processed)
583 res.status =
"Failed: internal error - txs is empty";
587 if (std::get<0>(txs[txs_processed]) != h)
589 res.status =
"Failed: tx hash mismatch";
592 sorted_txs.push_back(
std::move(txs[txs_processed]));
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())
600 res.status =
"Failed to parse and validate tx from blob";
603 std::stringstream ss;
608 res.status =
"Failed to serialize transaction base";
614 missed_txs.erase(std::find(missed_txs.begin(), missed_txs.end(), h));
615 pool_tx_hashes.insert(h);
617 for (
const auto &ti: pool_tx_info)
619 if (ti.id_hash == hash_string)
621 per_tx_pool_tx_info.insert(std::make_pair(h, ti));
630 LOG_PRINT_L2(
"Found " << found_in_pool <<
"/" << vh.size() <<
" transactions in the pool");
633 std::vector<std::string>::const_iterator txhi = req.txs_hashes.begin();
634 std::vector<crypto::hash>::const_iterator vhi = vh.begin();
643 if (req.split || req.prune || std::get<3>(tx).empty())
649 if (req.decode_as_json)
653 if (req.prune || std::get<3>(tx).empty())
656 tx_data = std::get<1>(tx);
664 res.status =
"Failed to parse and validate pruned tx from blob";
671 tx_data = std::get<1>(tx) + std::get<3>(tx);
678 res.status =
"Failed to parse and validate tx from blob";
689 if (req.decode_as_json)
698 res.status =
"Failed to parse and validate tx from blob";
703 e.
in_pool = pool_tx_hashes.find(tx_hash) != pool_tx_hashes.end();
707 auto it = per_tx_pool_tx_info.find(tx_hash);
708 if (it != per_tx_pool_tx_info.end())
712 e.
relayed = it->second.relayed;
716 MERROR(
"Failed to determine pool info for " << tx_hash);
724 e.
block_height = m_core.get_blockchain_storage().get_db().get_tx_block_height(tx_hash);
732 if (req.decode_as_json)
736 if (pool_tx_hashes.find(tx_hash) == pool_tx_hashes.end())
741 res.status =
"Failed";
747 for(
const auto& miss_tx: missed_txs)
752 LOG_PRINT_L2(
res.txs.size() <<
" transactions found, " <<
res.missed_tx.size() <<
" not found");
761 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_IS_KEY_IMAGE_SPENT>(invoke_http_mode::JON,
"/is_key_image_spent", req,
res, ok))
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)
772 res.status =
"Failed to parse hex representation of key image";
777 res.status =
"Failed, size of data mismatch";
781 std::vector<bool> spent_status;
782 bool r = m_core.are_key_images_spent(key_images, spent_status);
785 res.status =
"Failed";
788 res.spent_status.clear();
789 for (
size_t n = 0; n < spent_status.size(); ++n)
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);
798 res.status =
"Failed";
801 for (std::vector<cryptonote::spent_key_image_info>::const_iterator i = ki.begin(); i != ki.end(); ++i)
808 for (
size_t n = 0; n <
res.spent_status.size(); ++n)
812 if (key_images[n] == spent_key_image)
830 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_SEND_RAW_TX>(invoke_http_mode::JON,
"/sendrawtransaction", req,
res, ok))
838 LOG_PRINT_L0(
"[on_send_raw_tx]: Failed to parse tx from hexbuff: " << req.tx_as_hex);
839 res.status =
"Failed";
845 res.status =
"Failed";
846 res.reason =
"Sanity check failed";
847 res.sanity_check_failed =
true;
850 res.sanity_check_failed =
false;
854 if(!m_core.handle_incoming_tx(tx_blob, tvc,
false,
false, req.do_not_relay) || tvc.
m_verification_failed)
856 res.status =
"Failed";
859 add_reason(reason,
"bad ring size");
861 add_reason(reason,
"double spend");
863 add_reason(reason,
"utxo has been spent already or doesn't exist");
865 add_reason(reason,
"invalid input");
867 add_reason(reason,
"invalid output");
869 add_reason(reason,
"too big");
871 add_reason(reason,
"overspend");
873 add_reason(reason,
"fee too low");
875 add_reason(reason,
"tx is not ringct");
876 const std::string punctuation = reason.empty() ?
"" :
": ";
879 LOG_PRINT_L0(
"[on_send_raw_tx]: tx verification failed" << punctuation << reason);
883 LOG_PRINT_L0(
"[on_send_raw_tx]: Failed to process tx" << punctuation << reason);
890 LOG_PRINT_L0(
"[on_send_raw_tx]: tx accepted, but not relayed");
891 res.reason =
"Not relayed";
892 res.not_relayed =
true;
898 r.txs.push_back(tx_blob);
899 m_core.get_protocol()->relay_transactions(
r, fake_context);
912 res.status =
"Failed, wrong address";
916 if (
info.is_subaddress)
918 res.status =
"Mining to subaddress isn't supported yet";
923 unsigned int concurrency_count = boost::thread::hardware_concurrency() * 4;
926 if(concurrency_count == 0)
928 concurrency_count = 257;
933 if(req.threads_count > concurrency_count)
935 res.status =
"Failed, too many threads relative to CPU cores.";
943 res.status =
"Already mining";
946 if(!
miner.
start(
info.address,
static_cast<size_t>(req.threads_count), req.do_background_mining, req.ignore_battery))
948 res.status =
"Failed, mining not started";
962 res.status =
"Mining never started";
968 res.status =
"Failed, mining not stopped";
980 const miner& lMiner = m_core.get_miner();
983 store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(),
res.difficulty,
res.wide_difficulty,
res.difficulty_top64);
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;
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;
1003 if (
res.is_background_mining_enabled)
1018 if( !m_core.get_blockchain_storage().store_blockchain() )
1020 res.status =
"Error while storing blockchain";
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);
1034 res.white_list.reserve(white_list.size());
1035 for (
auto & entry : white_list)
1041 res.white_list.emplace_back(entry.id, entry.adr.str(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1044 res.gray_list.reserve(gray_list.size());
1045 for (
auto & entry : gray_list)
1051 res.gray_list.emplace_back(entry.id, entry.adr.str(), entry.last_seen, entry.pruning_seed, entry.rpc_port);
1061 if(m_core.get_miner().is_mining())
1063 m_core.get_miner().do_print_hashrate(req.visible);
1078 res.status =
"Error: log level not valid";
1099 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL>(invoke_http_mode::JON,
"/get_transaction_pool", req,
res,
r))
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);
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))
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);
1129 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_HASHES>(invoke_http_mode::JON,
"/get_transaction_pool_hashes", req,
res,
r))
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());
1147 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_STATS>(invoke_http_mode::JON,
"/get_transaction_pool_stats", req,
res,
r))
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);
1162 m_p2p.send_stop_signal();
1171 boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1172 if (m_should_use_bootstrap_daemon)
1174 res.status =
"This command is unsupported for bootstrap daemon";
1178 res.count = m_core.get_current_blockchain_height();
1187 boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1188 if (m_should_use_bootstrap_daemon)
1190 res =
"This command is unsupported for bootstrap daemon";
1197 error_resp.
message =
"Wrong parameters, expected height";
1201 if(m_core.get_current_blockchain_height() <= h)
1214 const void*
buf = start_buff;
1215 const void* end=(
const char*)
buf+
buflen;
1220 return (
const char*)
buf - (
const char*)start_buff;
1222 buflen = (
const char*)end - (
const char*)
buf;
1231 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GETBLOCKTEMPLATE>(invoke_http_mode::JON_RPC,
"getblocktemplate", req,
res,
r))
1234 if(!check_core_ready())
1237 error_resp.
message =
"Core is busy";
1241 if(req.reserve_size > 255)
1244 error_resp.
message =
"Too big reserved size, maximum 255";
1253 error_resp.
message =
"Failed to parse wallet address";
1256 if (
info.is_subaddress)
1259 error_resp.
message =
"Mining to subaddress is not supported yet";
1265 blob_reserve.resize(req.reserve_size, 0);
1268 if (!req.prev_block.empty())
1273 error_resp.
message =
"Invalid prev_block";
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))
1280 error_resp.
message =
"Internal error: failed to create block template";
1281 LOG_ERROR(
"Failed to create block template");
1284 store_difficulty(wdiff,
res.difficulty,
res.wide_difficulty,
res.difficulty_top64);
1290 error_resp.
message =
"Internal error: failed to create block template";
1291 LOG_ERROR(
"Failed to get tx pub key in coinbase extra");
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)
1298 error_resp.
message =
"Internal error: failed to create block template";
1299 LOG_ERROR(
"Failed to find tx pub key in blockblob");
1302 if (req.reserve_size)
1303 res.reserved_offset +=
sizeof(tx_pub_key) + 2;
1305 res.reserved_offset = 0;
1306 if(
res.reserved_offset + req.reserve_size > block_blob.size())
1309 error_resp.
message =
"Internal error: failed to create block template";
1310 LOG_ERROR(
"Failed to calculate offset for ");
1325 boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1326 if (m_should_use_bootstrap_daemon)
1328 res.status =
"This command is unsupported for bootstrap daemon";
1336 error_resp.
message =
"Wrong param";
1343 error_resp.
message =
"Wrong block blob";
1353 error_resp.
message =
"Wrong block blob";
1359 if(!m_core.check_incoming_block_size(blockblob))
1362 error_resp.
message =
"Block bloc size is too big, rejecting block";
1367 if(!m_core.handle_block_found(b, bvc))
1370 error_resp.
message =
"Block not accepted";
1388 error_resp.
message =
"Regtest required when generating blocks";
1397 template_req.reserve_size = 1;
1398 template_req.wallet_address = req.wallet_address;
1399 template_req.prev_block = req.prev_block;
1400 submit_req.push_back(boost::value_initialized<std::string>());
1401 res.height = m_core.get_blockchain_storage().get_current_blockchain_height();
1403 for(
size_t i = 0; i < req.amount_of_blocks; i++)
1405 bool r = on_getblocktemplate(template_req, template_res, error_resp, ctx);
1406 res.status = template_res.status;
1407 template_req.prev_block.clear();
1409 if (!
r)
return false;
1415 error_resp.
message =
"Wrong block blob";
1422 error_resp.
message =
"Wrong block blob";
1425 b.
nonce = req.starting_nonce;
1429 r = on_submitblock(submit_req, submit_res, error_resp, ctx);
1430 res.status = submit_res.status;
1432 if (!
r)
return false;
1435 template_req.prev_block =
res.blocks.back();
1436 res.height = template_res.height;
1442 uint64_t core_rpc_server::get_block_reward(
const block& blk)
1447 reward += out.amount;
1455 response.major_version = blk.major_version;
1456 response.minor_version = blk.minor_version;
1457 response.timestamp = blk.timestamp;
1460 response.orphan_status = orphan_status;
1462 response.depth = m_core.get_current_blockchain_height() -
height - 1;
1464 store_difficulty(m_core.get_blockchain_storage().block_difficulty(
height),
1466 store_difficulty(m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(
height),
1469 response.block_size =
response.block_weight = m_core.get_blockchain_storage().get_db().get_block_weight(
height);
1470 response.num_txes = blk.tx_hashes.size();
1472 response.long_term_weight = m_core.get_blockchain_storage().get_db().get_block_long_term_weight(
height);
1477 template <
typename COMMAND_TYPE>
1478 bool core_rpc_server::use_bootstrap_daemon_if_necessary(
const invoke_http_mode &mode,
const std::string &command_name,
const typename COMMAND_TYPE::request& req,
typename COMMAND_TYPE::response&
res,
bool &
r)
1480 res.untrusted =
false;
1481 if (m_bootstrap_daemon_address.empty())
1484 boost::unique_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
1485 if (!m_should_use_bootstrap_daemon)
1487 MINFO(
"The local daemon is fully synced. Not switching back to the bootstrap daemon");
1491 auto current_time = std::chrono::system_clock::now();
1492 if (current_time - m_bootstrap_height_check_time > std::chrono::seconds(30))
1494 m_bootstrap_height_check_time = current_time;
1498 m_core.get_blockchain_top(top_height, top_hash);
1507 m_should_use_bootstrap_daemon = ok && top_height + 10 < getheight_res.height;
1508 MINFO((m_should_use_bootstrap_daemon ?
"Using" :
"Not using") <<
" the bootstrap daemon (our height: " << top_height <<
", bootstrap daemon's height: " << getheight_res.height <<
")");
1510 if (!m_should_use_bootstrap_daemon)
1513 if (mode == invoke_http_mode::JON)
1517 else if (mode == invoke_http_mode::BIN)
1521 else if (mode == invoke_http_mode::JON_RPC)
1527 json_req.
method = command_name;
1535 MERROR(
"Unknown invoke_http_mode: " << mode);
1538 m_was_bootstrap_ever_used =
true;
1540 res.untrusted =
true;
1548 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_LAST_BLOCK_HEADER>(invoke_http_mode::JON_RPC,
"getlastblockheader", req,
res,
r))
1554 m_core.get_blockchain_top(last_block_height, last_block_hash);
1556 bool have_last_block = m_core.get_block_by_hash(last_block_hash, last_block);
1557 if (!have_last_block)
1560 error_resp.
message =
"Internal error: can't get last block.";
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)
1568 error_resp.
message =
"Internal error: can't produce valid response.";
1579 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH>(invoke_http_mode::JON_RPC,
"getblockheaderbyhash", req,
res,
r))
1587 error_resp.
message =
"Failed to parse hex representation of block hash. Hex = " + req.hash +
'.';
1591 bool orphan =
false;
1592 bool have_block = m_core.get_block_by_hash(block_hash, blk, &orphan);
1596 error_resp.
message =
"Internal error: can't get block by hash. Hash = " + req.hash +
'.';
1602 error_resp.
message =
"Internal error: coinbase transaction in the block has the wrong type";
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)
1611 error_resp.
message =
"Internal error: can't produce valid response.";
1622 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADERS_RANGE>(invoke_http_mode::JON_RPC,
"getblockheadersrange", req,
res,
r))
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)
1629 error_resp.
message =
"Invalid start/end heights.";
1632 for (
uint64_t h = req.start_height; h <= req.end_height; ++h)
1634 crypto::hash block_hash = m_core.get_block_id_by_height(h);
1636 bool have_block = m_core.get_block_by_hash(block_hash, blk);
1646 error_resp.
message =
"Internal error: coinbase transaction in the block has the wrong type";
1650 if (block_height != h)
1653 error_resp.
message =
"Internal error: coinbase transaction in the block has the wrong height";
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)
1662 error_resp.
message =
"Internal error: can't produce valid response.";
1674 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT>(invoke_http_mode::JON_RPC,
"getblockheaderbyheight", req,
res,
r))
1677 if(m_core.get_current_blockchain_height() <= req.height)
1683 crypto::hash block_hash = m_core.get_block_id_by_height(req.height);
1685 bool have_block = m_core.get_block_by_hash(block_hash, blk);
1689 error_resp.
message =
"Internal error: can't get block by height. Height = " +
std::to_string(req.height) +
'.';
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)
1697 error_resp.
message =
"Internal error: can't produce valid response.";
1708 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BLOCK>(invoke_http_mode::JON_RPC,
"getblock", req,
res,
r))
1712 if (!req.hash.empty())
1718 error_resp.
message =
"Failed to parse hex representation of block hash. Hex = " + req.hash +
'.';
1724 if(m_core.get_current_blockchain_height() <= req.height)
1730 block_hash = m_core.get_block_id_by_height(req.height);
1733 bool orphan =
false;
1734 bool have_block = m_core.get_block_by_hash(block_hash, blk, &orphan);
1738 error_resp.
message =
"Internal error: can't get block by hash. Hash = " + req.hash +
'.';
1744 error_resp.
message =
"Internal error: coinbase transaction in the block has the wrong type";
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)
1753 error_resp.
message =
"Internal error: can't produce valid response.";
1757 for (
size_t n = 0; n < blk.
tx_hashes.size(); ++n)
1774 if (req.etn_address.empty())
1776 res.status =
"Failed: Request attribute <etn_address> is mandatory.";
1783 res.status =
"Failed: can't parse address from <etn_address> = " + req.etn_address;
1787 res.balance = m_core.get_balance(addr_info);
1798 if (req.etn_address.empty())
1800 res.status =
"Failed: Request attribute <etn_address> is mandatory.";
1807 res.status =
"Failed: can't parse address from <etn_address> = " + req.etn_address;
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)
1816 res.next_out_id = outs.at(outs.size() - 1).out_id;
1817 res.last_page =
false;
1822 res.last_page =
true;
1832 catch(
const std::exception& e)
1845 res.connections = m_p2p.get_payload_object().get_connections();
1854 return on_get_info(req,
res, ctx);
1861 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_HARD_FORK_INFO>(invoke_http_mode::JON_RPC,
"hard_fork_info", req,
res,
r))
1864 const Blockchain &blockchain = m_core.get_blockchain_storage();
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)
1881 if (i->second > now) {
1889 res.bans.push_back(b);
1901 for (
auto i = req.bans.begin(); i != req.bans.end(); ++i)
1904 if (!i->host.empty())
1910 error_resp.
message =
"Unsupported host type";
1920 if (i->seconds < -1) {
1922 error_resp.
message =
"Please pick a value for seconds >= -1";
1924 }
else if (i->seconds == -1) {
1925 m_p2p.block_host(na,
uint32_t(std::numeric_limits<time_t>::max()));
1927 m_p2p.block_host(na,
uint32_t(i->seconds));
1931 m_p2p.unblock_host(na);
1944 bool failed =
false;
1945 std::vector<crypto::hash> txids;
1946 if (req.txids.empty())
1948 std::vector<transaction> pool_txs;
1949 bool r = m_core.get_pool_transactions(pool_txs);
1952 res.status =
"Failed to get txpool contents";
1955 for (
const auto &tx: pool_txs)
1962 for (
const auto &str: req.txids)
1972 txids.push_back(txid);
1976 if (!m_core.get_blockchain_storage().flush_txes_from_pool(txids))
1978 res.status =
"Failed to remove one or more tx(es)";
1985 res.status =
"Failed to parse txid";
1987 res.status =
"Failed to parse some of the txids";
1999 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_HISTOGRAM>(invoke_http_mode::JON_RPC,
"get_output_histogram", req,
res,
r))
2002 const bool restricted = m_restricted && ctx;
2005 res.status =
"Recent cutoff is too old";
2009 std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> histogram;
2012 histogram = m_core.get_blockchain_storage().get_output_histogram(req.amounts, req.unlocked, req.recent_cutoff, req.min_count);
2014 catch (
const std::exception &e)
2016 res.status =
"Failed to get output histogram";
2020 res.histogram.clear();
2021 res.histogram.reserve(histogram.size());
2022 for (
const auto &i: histogram)
2024 if (std::get<0>(i.second) >= req.min_count && (std::get<0>(i.second) <= req.max_count || req.max_count == 0))
2036 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_VERSION>(invoke_http_mode::JON_RPC,
"get_version", req,
res,
r))
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;
2058 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_BASE_FEE_ESTIMATE>(invoke_http_mode::JON_RPC,
"get_fee_estimate", req,
res,
r))
2061 res.fee = m_core.get_blockchain_storage().get_dynamic_base_fee_estimate(req.grace_blocks);
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)
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());
2081 if (i.first.height < i.second.size())
2083 res.status =
"Error finding alternate chain attachment point";
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; }
2095 res.status =
"Error retrieving alternate chains";
2104 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_LIMIT>(invoke_http_mode::JON,
"/get_limit", req,
res,
r))
2119 if (req.limit_down > 0)
2123 else if (req.limit_down < 0)
2125 if (req.limit_down != -1)
2133 if (req.limit_up > 0)
2137 else if (req.limit_up < 0)
2139 if (req.limit_up != -1)
2156 m_p2p.change_max_out_public_peers(req.out_peers);
2164 m_p2p.change_max_in_public_peers(req.in_peers);
2172 m_p2p.set_save_graph(
true);
2180 m_p2p.set_save_graph(
false);
2189 if (m_core.offline())
2191 res.status =
"Daemon is running offline";
2195 static const char software[] =
"electroneum";
2197 static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG);
2198 static const char subdir[] =
"cli";
2200 static const char buildtag[] =
"source";
2201 static const char subdir[] =
"source";
2203 LOG_PRINT_L0(req.command <<
" for software: " << software <<
"; buildtag: " << buildtag <<
"; subdir:" << subdir);
2204 if (req.command !=
"check" && req.command !=
"download" && req.command !=
"update")
2206 res.status =
std::string(
"unknown command: '") + req.command +
"'";
2213 res.status =
"Error checking for updates";
2227 if (req.command ==
"check")
2233 boost::filesystem::path path;
2234 if (req.path.empty())
2237 const char *slash = strrchr(
res.auto_uri.c_str(),
'/');
2239 filename = slash + 1;
2253 MDEBUG(
"We don't have that file already, downloading");
2256 MERROR(
"Failed to download " <<
res.auto_uri);
2261 MERROR(
"Failed to hash " << path);
2266 MERROR(
"Download from " <<
res.auto_uri <<
" does not match the expected hash");
2269 MINFO(
"New version downloaded to " << path);
2273 MDEBUG(
"We already have " << path <<
" with expected hash");
2275 res.path = path.string();
2277 if (req.command ==
"download")
2283 res.status =
"'update' not implemented yet";
2291 m_core.get_blockchain_storage().pop_blocks(req.nblocks);
2293 res.height = m_core.get_current_blockchain_height();
2303 bool failed =
false;
2305 for (
const auto &str: req.txids)
2310 if (!
res.status.empty())
res.status +=
", ";
2318 bool r = m_core.get_pool_transaction(txid, txblob);
2323 r.txs.push_back(txblob);
2324 m_core.get_protocol()->relay_transactions(
r, fake_context);
2329 if (!
res.status.empty())
res.status +=
", ";
2330 res.status +=
std::string(
"transaction not found in pool: ") + str;
2350 m_core.get_blockchain_top(
res.height, top_hash);
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;
2355 for (
const auto &c: m_p2p.get_payload_object().get_connections())
2356 res.peers.push_back({c});
2362 for (
const auto &c: m_p2p.get_payload_object().get_connections())
2363 if (c.connection_id == span_connection_id)
2378 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG>(invoke_http_mode::JON_RPC,
"get_txpool_backlog", req,
res,
r))
2381 if (!m_core.get_txpool_backlog(
res.backlog))
2384 error_resp.
message =
"Failed to get txpool backlog";
2394 if(!m_core.set_validator_key(req.validator_key)) {
2396 error_resp.
message =
"Failed to set Validator Key. Wrong format.";
2407 std::vector<std::string> v = m_core.generate_ed25519_keypair();
2410 error_resp.
message =
"Failed to generate ED25519-Donna keypair.";
2414 res.privateKey = v[0];
2415 res.publicKey = v[1];
2425 std::string v = m_core.sign_message(boost::algorithm::unhex(req.privateKey), req.message);
2429 error_resp.
message =
"Failed to sign message.";
2435 catch(
const std::exception &e)
2438 error_resp.
message =
"Failed to sign message. Please check that you are using a valid private key.";
2449 if(!req.blob.empty()) {
2461 if(m_core.get_protocol()->relay_emergency_validator_list(arg,
context)){
2480 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::JON_RPC,
"get_output_distribution", req,
res,
r))
2486 const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1);
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());
2493 error_resp.
message =
"Failed to get output distribution";
2497 res.distributions.push_back({
std::move(*data), amount,
"", req.binary, req.compress});
2500 catch (
const std::exception &e)
2503 error_resp.
message =
"Failed to get output distribution";
2516 if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_OUTPUT_DISTRIBUTION>(invoke_http_mode::BIN,
"/get_output_distribution.bin", req,
res,
r))
2519 res.status =
"Failed";
2523 res.status =
"Binary only call";
2529 const uint64_t req_to_height = req.to_height ? req.to_height : (m_core.get_current_blockchain_height() - 1);
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());
2535 res.status =
"Failed to get output distribution";
2539 res.distributions.push_back({
std::move(*data), amount,
"", req.binary, req.compress});
2542 catch (
const std::exception &e)
2544 res.status =
"Failed to get output distribution";
2556 if (!(req.check ? m_core.check_blockchain_pruning() : m_core.prune_blockchain()))
2559 error_resp.
message = req.check ?
"Failed to check blockchain pruning" :
"Failed to prune blockchain";
2562 res.pruning_seed = m_core.get_blockchain_pruning_seed();
2563 res.pruned =
res.pruning_seed != 0;
2565 catch (
const std::exception &e)
2568 error_resp.
message =
"Failed to prune blockchain";
2580 ,
"Port for RPC server"
2584 if (testnet_stagenet[0] && defaulted)
2586 else if (testnet_stagenet[1] && defaulted)
2593 "rpc-restricted-bind-port"
2594 ,
"Port for restricted RPC server"
2600 ,
"Restrict RPC to view only commands and do not return privacy sensitive data in RPC calls"
2605 "bootstrap-daemon-address"
2606 ,
"URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced"
2611 "bootstrap-daemon-login"
2612 ,
"Specify username:password for the bootstrap daemon login"
virtual uint64_t get_database_size() const =0
get disk space requirements
virtual difficulty_type get_block_cumulative_difficulty(const uint64_t &height) const =0
fetch a block's cumulative difficulty
uint8_t get_current_hard_fork_version() const
gets the current hardfork version in use/voted for
HardFork::State get_hard_fork_state() const
gets the hardfork voting state object
uint64_t get_current_cumulative_block_weight_median() const
gets the block weight median based on recent blocks (same window as for the limit)
uint64_t get_current_cumulative_block_weight_limit() const
gets the block weight limit based on recent blocks
difficulty_type get_difficulty_for_next_block()
returns the difficulty target the next block to be added must meet
uint8_t get_next_hard_fork_version() const
returns the next hardfork version
uint64_t get_difficulty_target() const
get difficulty target based on chain and hardfork version
static uint64_t get_fee_quantization_mask()
get fee quantization mask
const BlockchainDB & get_db() const
get a reference to the BlockchainDB in use by Blockchain
size_t get_alternative_blocks_count() const
returns the number of alternative blocks stored
size_t get_total_transactions() const
gets the total number of transactions on the main chain
bool get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
get information about hardfork voting for a version
float get_speed(const boost::uuids::uuid &connection_id) const
bool foreach(std::function< bool(const span &)> f) const
std::string get_overview(uint64_t blockchain_height) const
bool on_get_outs_bin(const COMMAND_RPC_GET_OUTPUTS_BIN::request &req, COMMAND_RPC_GET_OUTPUTS_BIN::response &res, const connection_context *ctx=NULL)
bool on_out_peers(const COMMAND_RPC_OUT_PEERS::request &req, COMMAND_RPC_OUT_PEERS::response &res, const connection_context *ctx=NULL)
bool on_get_base_fee_estimate(const COMMAND_RPC_GET_BASE_FEE_ESTIMATE::request &req, COMMAND_RPC_GET_BASE_FEE_ESTIMATE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_mining_status(const COMMAND_RPC_MINING_STATUS::request &req, COMMAND_RPC_MINING_STATUS::response &res, const connection_context *ctx=NULL)
bool on_prune_blockchain(const COMMAND_RPC_PRUNE_BLOCKCHAIN::request &req, COMMAND_RPC_PRUNE_BLOCKCHAIN::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request &req, COMMAND_RPC_GET_TRANSACTIONS::response &res, const connection_context *ctx=NULL)
bool on_get_info(const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, const connection_context *ctx=NULL)
bool on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request &req, COMMAND_RPC_STOP_DAEMON::response &res, const connection_context *ctx=NULL)
bool on_start_save_graph(const COMMAND_RPC_START_SAVE_GRAPH::request &req, COMMAND_RPC_START_SAVE_GRAPH::response &res, const connection_context *ctx=NULL)
bool on_get_coinbase_tx_sum(const COMMAND_RPC_GET_COINBASE_TX_SUM::request &req, COMMAND_RPC_GET_COINBASE_TX_SUM::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request &req, COMMAND_RPC_GET_HEIGHT::response &res, const connection_context *ctx=NULL)
bool on_hard_fork_info(const COMMAND_RPC_HARD_FORK_INFO::request &req, COMMAND_RPC_HARD_FORK_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_pop_blocks(const COMMAND_RPC_POP_BLOCKS::request &req, COMMAND_RPC_POP_BLOCKS::response &res, const connection_context *ctx=NULL)
bool on_get_output_distribution(const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_set_log_categories(const COMMAND_RPC_SET_LOG_CATEGORIES::request &req, COMMAND_RPC_SET_LOG_CATEGORIES::response &res, const connection_context *ctx=NULL)
bool on_get_block_header_by_hash(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_address_batch_history(const COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::request &req, COMMAND_RPC_GET_ADDRESS_BATCH_HISTORY::response &res, const connection_context *ctx=NULL)
bool on_save_bc(const COMMAND_RPC_SAVE_BC::request &req, COMMAND_RPC_SAVE_BC::response &res, const connection_context *ctx=NULL)
bool on_relay_tx(const COMMAND_RPC_RELAY_TX::request &req, COMMAND_RPC_RELAY_TX::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_outs(const COMMAND_RPC_GET_OUTPUTS::request &req, COMMAND_RPC_GET_OUTPUTS::response &res, const connection_context *ctx=NULL)
bool on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request &req, COMMAND_RPC_GET_PEER_LIST::response &res, const connection_context *ctx=NULL)
bool on_set_limit(const COMMAND_RPC_SET_LIMIT::request &req, COMMAND_RPC_SET_LIMIT::response &res, const connection_context *ctx=NULL)
bool on_get_info_json(const COMMAND_RPC_GET_INFO::request &req, COMMAND_RPC_GET_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_submitblock(const COMMAND_RPC_SUBMITBLOCK::request &req, COMMAND_RPC_SUBMITBLOCK::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response &res, const connection_context *ctx=NULL)
bool on_get_limit(const COMMAND_RPC_GET_LIMIT::request &req, COMMAND_RPC_GET_LIMIT::response &res, const connection_context *ctx=NULL)
bool on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request &req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_stop_mining(const COMMAND_RPC_STOP_MINING::request &req, COMMAND_RPC_STOP_MINING::response &res, const connection_context *ctx=NULL)
bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request &req, COMMAND_RPC_SEND_RAW_TX::response &res, const connection_context *ctx=NULL)
bool on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request &req, COMMAND_RPC_SET_LOG_HASH_RATE::response &res, const connection_context *ctx=NULL)
bool on_get_balance(const COMMAND_RPC_GET_BALANCE::request &req, COMMAND_RPC_GET_BALANCE::response &res, const connection_context *ctx=NULL)
bool on_inject_emergency_vlist(const COMMAND_RPC_INJECT_EMERGENCY_VLIST::request &req, COMMAND_RPC_INJECT_EMERGENCY_VLIST::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_net_stats(const COMMAND_RPC_GET_NET_STATS::request &req, COMMAND_RPC_GET_NET_STATS::response &res, const connection_context *ctx=NULL)
bool on_sync_info(const COMMAND_RPC_SYNC_INFO::request &req, COMMAND_RPC_SYNC_INFO::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request &req, COMMAND_RPC_GET_TRANSACTION_POOL::response &res, const connection_context *ctx=NULL)
bool on_get_alt_blocks_hashes(const COMMAND_RPC_GET_ALT_BLOCKS_HASHES::request &req, COMMAND_RPC_GET_ALT_BLOCKS_HASHES::response &res, const connection_context *ctx=NULL)
bool on_get_block(const COMMAND_RPC_GET_BLOCK::request &req, COMMAND_RPC_GET_BLOCK::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_set_validator_key(const COMMAND_RPC_SET_VALIDATOR_KEY::request &req, COMMAND_RPC_SET_VALIDATOR_KEY::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_sign_message(const COMMAND_RPC_SIGN_MESSAGE::request &req, COMMAND_RPC_SIGN_MESSAGE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_output_distribution_bin(const COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::request &req, COMMAND_RPC_GET_OUTPUT_DISTRIBUTION::response &res, const connection_context *ctx=NULL)
bool on_get_version(const COMMAND_RPC_GET_VERSION::request &req, COMMAND_RPC_GET_VERSION::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_block_headers_range(const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request &req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_getblocktemplate(const COMMAND_RPC_GETBLOCKTEMPLATE::request &req, COMMAND_RPC_GETBLOCKTEMPLATE::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_transaction_pool_hashes(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES::response &res, const connection_context *ctx=NULL)
bool on_set_bans(const COMMAND_RPC_SETBANS::request &req, COMMAND_RPC_SETBANS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_txpool_backlog(const COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool init(const boost::program_options::variables_map &vm, const bool restricted, const std::string &port)
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_address
bool on_get_transaction_pool_hashes_bin(const COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN::response &res, const connection_context *ctx=NULL)
bool on_start_mining(const COMMAND_RPC_START_MINING::request &req, COMMAND_RPC_START_MINING::response &res, const connection_context *ctx=NULL)
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request &req, COMMAND_RPC_SET_LOG_LEVEL::response &res, const connection_context *ctx=NULL)
bool on_update(const COMMAND_RPC_UPDATE::request &req, COMMAND_RPC_UPDATE::response &res, const connection_context *ctx=NULL)
bool on_get_output_histogram(const COMMAND_RPC_GET_OUTPUT_HISTOGRAM::request &req, COMMAND_RPC_GET_OUTPUT_HISTOGRAM::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
network_type nettype() const
bool on_get_transaction_pool_stats(const COMMAND_RPC_GET_TRANSACTION_POOL_STATS::request &req, COMMAND_RPC_GET_TRANSACTION_POOL_STATS::response &res, const connection_context *ctx=NULL)
static const command_line::arg_descriptor< std::string > arg_bootstrap_daemon_login
bool on_get_alternate_chains(const COMMAND_RPC_GET_ALTERNATE_CHAINS::request &req, COMMAND_RPC_GET_ALTERNATE_CHAINS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request &req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response &res, const connection_context *ctx=NULL)
bool on_generate_ed25519_keypair(const COMMAND_RPC_GENERATE_ED25519_KEYPAIR::request &req, COMMAND_RPC_GENERATE_ED25519_KEYPAIR::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
static const command_line::arg_descriptor< std::string, false, true, 2 > arg_rpc_bind_port
bool on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request &req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response &res, const connection_context *ctx=NULL)
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request &req, COMMAND_RPC_GETBLOCKCOUNT::response &res, const connection_context *ctx=NULL)
bool on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request &req, COMMAND_RPC_GET_HASHES_FAST::response &res, const connection_context *ctx=NULL)
bool on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request &req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_stop_save_graph(const COMMAND_RPC_STOP_SAVE_GRAPH::request &req, COMMAND_RPC_STOP_SAVE_GRAPH::response &res, const connection_context *ctx=NULL)
bool on_flush_txpool(const COMMAND_RPC_FLUSH_TRANSACTION_POOL::request &req, COMMAND_RPC_FLUSH_TRANSACTION_POOL::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_in_peers(const COMMAND_RPC_IN_PEERS::request &req, COMMAND_RPC_IN_PEERS::response &res, const connection_context *ctx=NULL)
bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request &req, COMMAND_RPC_GET_CONNECTIONS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request &req, COMMAND_RPC_GETBLOCKHASH::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
bool on_get_bans(const COMMAND_RPC_GETBANS::request &req, COMMAND_RPC_GETBANS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
static const command_line::arg_descriptor< std::string > arg_rpc_restricted_bind_port
static const command_line::arg_descriptor< bool > arg_restricted_rpc
bool on_generateblocks(const COMMAND_RPC_GENERATEBLOCKS::request &req, COMMAND_RPC_GENERATEBLOCKS::response &res, epee::json_rpc::error &error_resp, const connection_context *ctx=NULL)
handles core cryptonote functionality
size_t get_pool_transactions_count() const
get the total number of transactions in the pool
void get_blockchain_top(uint64_t &height, crypto::hash &top_id) const
get the hash and height of the most recent block
uint64_t get_free_space() const
get free disk space on the blockchain partition
bool is_update_available() const
check whether an update is known to be available or not
Blockchain & get_blockchain_storage()
gets the Blockchain instance
bool offline() const
get whether the core is running offline
std::time_t get_start_time() const
gets start_time
uint64_t get_target_blockchain_height() const
gets the target blockchain height
const account_public_address & get_mining_address() const
uint64_t get_block_reward() const
uint64_t get_min_idle_seconds() const
uint64_t get_speed() const
uint32_t get_threads_count() const
bool get_ignore_battery() const
bool get_is_background_mining_enabled() const
static bool find_nonce_for_given_block(block &bl, const difficulty_type &diffic, uint64_t height)
uint8_t get_idle_threshold() const
bool start(const account_public_address &adr, size_t threads_count, bool do_background=false, bool ignore_battery=false)
uint8_t get_mining_target() const
pruned_transaction(transaction &tx)
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)
std::vector< txin_v > vin
std::vector< tx_out > vout
long get_connections_count() const
bool init(std::function< void(size_t, uint8_t *)> rng, const std::string &bind_port="0", const std::string &bind_ip="0.0.0.0", std::vector< std::string > access_control_origins=std::vector< std::string >(), boost::optional< net_utils::http::login > user=boost::none, net_utils::ssl_options_t ssl_options=net_utils::ssl_support_t::e_ssl_support_autodetect)
net_utils::boosted_tcp_server< net_utils::http::http_custom_handler< epee::net_utils::connection_context_base > > m_net_server
static void set_rate_down_limit(uint64_t limit)
static uint64_t get_rate_up_limit()
static void set_rate_up_limit(uint64_t limit)
static uint64_t get_rate_down_limit()
bool set_server(const std::string &address, boost::optional< login > user, ssl_options_t ssl_options=ssl_support_t::e_ssl_support_autodetect)
virtual void get_stats(uint64_t &total_packets, uint64_t &total_bytes) const =0
static constexpr address_type get_type_id() noexcept
constexpr uint16_t port() const noexcept
constexpr uint32_t ip() const noexcept
static boost::mutex m_lock_get_global_throttle_in
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
static boost::mutex m_lock_get_global_throttle_out
Non-owning sequence of data. Does not deep copy.
constexpr std::size_t size() const noexcept
#define MAX_RESTRICTED_GLOBAL_FAKE_OUTS_COUNT
#define OUTPUT_HISTOGRAM_RECENT_CUTOFF_RESTRICTION
#define CHECK_CORE_READY()
#define CORE_RPC_STATUS_NOT_MINING
#define CORE_RPC_STATUS_OK
#define CORE_RPC_ERROR_CODE_WRONG_WALLET_ADDRESS
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB_SIZE
#define CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB
#define CORE_RPC_ERROR_CODE_CORE_BUSY
#define CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT
#define CORE_RPC_ERROR_CODE_REGTEST_REQUIRED
#define CORE_RPC_ERROR_CODE_WRONG_PARAM
#define CORE_RPC_ERROR_CODE_MINING_TO_SUBADDRESS
#define CORE_RPC_ERROR_CODE_INTERNAL_ERROR
#define CORE_RPC_ERROR_CODE_TOO_BIG_RESERVE_SIZE
#define CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED
bool parse_hash256(const std::string &str_hash, crypto::hash &hash)
#define DIFFICULTY_TARGET
#define DIFFICULTY_TARGET_V6
#define COMMAND_RPC_GET_BLOCKS_FAST_MAX_COUNT
void * memcpy(void *a, const void *b, size_t c)
std::string mlog_get_categories()
void mlog_set_log(const char *log)
void mlog_set_log_level(int level)
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
uint16_t const RPC_DEFAULT_PORT
uint16_t const RPC_DEFAULT_PORT
uint16_t const RPC_DEFAULT_PORT
const crypto::public_key null_pkey
void rand(size_t N, uint8_t *bytes)
Holds cryptonote related classes and helpers.
std::string obj_to_json_str(T &obj)
boost::multiprecision::uint128_t difficulty_type
bool get_block_reward(size_t median_weight, size_t current_block_weight, uint64_t already_generated_coins, uint64_t &reward, uint8_t version, uint64_t current_block_height, network_type nettype)
blobdata get_block_hashing_blob(const block &b)
bool get_block_hash(const block &b, crypto::hash &res)
bool get_account_address_from_str(address_parse_info &info, network_type nettype, std::string const &str)
bool parse_and_validate_block_from_blob(const blobdata &b_blob, block &b, crypto::hash *block_hash)
const command_line::arg_descriptor< bool, false > arg_testnet_on
crypto::public_key get_tx_pub_key_from_extra(const std::vector< uint8_t > &tx_extra, size_t pk_index)
std::string get_account_address_as_str(network_type nettype, bool subaddress, account_public_address const &adr)
bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
crypto::hash get_transaction_hash(const transaction &t)
size_t slow_memmem(const void *start_buff, size_t buflen, const void *pat, size_t patlen)
blobdata block_to_blob(const block &b)
const command_line::arg_descriptor< bool, false > arg_stagenet_on
bool get_block_longhash(const block &b, crypto::hash &res, uint64_t height)
blobdata tx_to_blob(const transaction &tx)
bool parse_and_validate_tx_from_blob(const blobdata &tx_blob, transaction &tx)
std::string hex(difficulty_type v)
bool parse_and_validate_tx_base_from_blob(const blobdata &tx_blob, transaction &tx)
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
void init_options(boost::program_options::options_description &hidden_options, boost::program_options::options_description &normal_options)
epee::misc_utils::struct_init< response_t > response
bool invoke_http_json(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
std::string to_string(t_connection_type type)
bool invoke_http_bin(const boost::string_ref uri, const t_request &out_struct, t_response &result_struct, t_transport &transport, std::chrono::milliseconds timeout=std::chrono::seconds(15), const boost::string_ref method="GET")
@ e_ssl_support_autodetect
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
boost::variant< uint64_t, uint32_t, uint16_t, uint8_t, int64_t, int32_t, int16_t, int8_t, double, bool, std::string, section, array_entry > storage_entry
version
Supported socks variants.
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
expect< epee::net_utils::network_address > get_network_address(const boost::string_ref address, const std::uint16_t default_port)
const T & move(const T &t)
#define LOG_ERROR_CCONTEXT(message)
#define LOG_PRINT_CCONTEXT_L0(message)
const GenericPointer< typename T::ValueType > T2 value
#define BEGIN_SERIALIZE_OBJECT()
begins the environment of the DSL \detailed for described the serialization of an object
#define END_SERIALIZE()
self-explanatory
boost::endian::big_uint16_t port
boost::endian::big_uint32_t ip
unsigned __int64 uint64_t
std::string prunable_as_hex
std::string prunable_hash
std::vector< uint64_t > output_indices
bool nonexistent_utxo_seen
std::string pruned_as_hex
std::list< std::string > request
std::vector< uint64_t > request
std::vector< std::string > request
std::vector< crypto::hash > tx_hashes
static boost::optional< rpc_args > process(const boost::program_options::variables_map &vm, const bool any_cert_option=false)
static void init_options(boost::program_options::options_description &desc, const bool any_cert_option=false)
bool m_verification_failed
epee::serialization::storage_entry id
#define CRITICAL_REGION_LOCAL(x)
const char *const ELECTRONEUM_VERSION
const char *const ELECTRONEUM_RELEASE_NAME
const char *const ELECTRONEUM_VERSION_FULL
const char *const ELECTRONEUM_VERSION_TAG