aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/core_rpc_server.cpp214
-rw-r--r--src/rpc/core_rpc_server.h4
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h348
-rw-r--r--src/rpc/daemon_handler.cpp9
-rw-r--r--src/rpc/message_data_structs.h4
5 files changed, 187 insertions, 392 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 56b0361a7..161ad2951 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -70,6 +70,13 @@ namespace
{
return (value + quantum - 1) / quantum * quantum;
}
+
+ void store_difficulty(cryptonote::difficulty_type difficulty, uint64_t &sdiff, std::string &swdiff, uint64_t &stop64)
+ {
+ sdiff = (difficulty << 64 >> 64).convert_to<uint64_t>();
+ swdiff = difficulty.convert_to<std::string>();
+ stop64 = (difficulty >> 64).convert_to<uint64_t>();
+ }
}
namespace cryptonote
@@ -84,7 +91,7 @@ namespace cryptonote
command_line::add_arg(desc, arg_rpc_ssl);
command_line::add_arg(desc, arg_rpc_ssl_private_key);
command_line::add_arg(desc, arg_rpc_ssl_certificate);
- command_line::add_arg(desc, arg_rpc_ssl_allowed_certificates);
+ command_line::add_arg(desc, arg_rpc_ssl_ca_certificates);
command_line::add_arg(desc, arg_rpc_ssl_allowed_fingerprints);
command_line::add_arg(desc, arg_rpc_ssl_allow_any_cert);
command_line::add_arg(desc, arg_bootstrap_daemon_address);
@@ -142,36 +149,38 @@ namespace cryptonote
if (rpc_config->login)
http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password());
- epee::net_utils::ssl_support_t ssl_support;
- const std::string ssl = command_line::get_arg(vm, arg_rpc_ssl);
- if (!epee::net_utils::ssl_support_from_string(ssl_support, ssl))
+ epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect;
+ if (command_line::get_arg(vm, arg_rpc_ssl_allow_any_cert))
+ ssl_options.verification = epee::net_utils::ssl_verification_t::none;
+ else
{
- MFATAL("Invalid RPC SSL support: " << ssl);
- return false;
+ std::string ssl_ca_path = command_line::get_arg(vm, arg_rpc_ssl_ca_certificates);
+ const std::vector<std::string> ssl_allowed_fingerprint_strings = command_line::get_arg(vm, arg_rpc_ssl_allowed_fingerprints);
+ std::vector<std::vector<uint8_t>> ssl_allowed_fingerprints{ ssl_allowed_fingerprint_strings.size() };
+ std::transform(ssl_allowed_fingerprint_strings.begin(), ssl_allowed_fingerprint_strings.end(), ssl_allowed_fingerprints.begin(), epee::from_hex::vector);
+
+ if (!ssl_ca_path.empty() || !ssl_allowed_fingerprints.empty())
+ ssl_options = epee::net_utils::ssl_options_t{std::move(ssl_allowed_fingerprints), std::move(ssl_ca_path)};
}
- const std::string ssl_private_key = command_line::get_arg(vm, arg_rpc_ssl_private_key);
- const std::string ssl_certificate = command_line::get_arg(vm, arg_rpc_ssl_certificate);
- const std::vector<std::string> ssl_allowed_certificate_paths = command_line::get_arg(vm, arg_rpc_ssl_allowed_certificates);
- std::list<std::string> ssl_allowed_certificates;
- for (const std::string &path: ssl_allowed_certificate_paths)
+
+ ssl_options.auth = epee::net_utils::ssl_authentication_t{
+ command_line::get_arg(vm, arg_rpc_ssl_private_key), command_line::get_arg(vm, arg_rpc_ssl_certificate)
+ };
+
+ // user specified CA file or fingeprints implies enabled SSL by default
+ if (ssl_options.verification != epee::net_utils::ssl_verification_t::user_certificates || !command_line::is_arg_defaulted(vm, arg_rpc_ssl))
{
- ssl_allowed_certificates.push_back({});
- if (!epee::file_io_utils::load_file_to_string(path, ssl_allowed_certificates.back()))
+ const std::string ssl = command_line::get_arg(vm, arg_rpc_ssl);
+ if (!epee::net_utils::ssl_support_from_string(ssl_options.support, ssl))
{
- MERROR("Failed to load certificate: " << path);
- ssl_allowed_certificates.back() = std::string();
+ MFATAL("Invalid RPC SSL support: " << ssl);
+ return false;
}
}
- const std::vector<std::string> ssl_allowed_fingerprint_strings = command_line::get_arg(vm, arg_rpc_ssl_allowed_fingerprints);
- std::vector<std::vector<uint8_t>> ssl_allowed_fingerprints{ ssl_allowed_fingerprint_strings.size() };
- std::transform(ssl_allowed_fingerprint_strings.begin(), ssl_allowed_fingerprint_strings.end(), ssl_allowed_fingerprints.begin(), epee::from_hex::vector);
- const bool ssl_allow_any_cert = command_line::get_arg(vm, arg_rpc_ssl_allow_any_cert);
-
auto rng = [](size_t len, uint8_t *ptr){ return crypto::rand(len, ptr); };
return epee::http_server_impl_base<core_rpc_server, connection_context>::init(
- rng, std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login),
- ssl_support, std::make_pair(ssl_private_key, ssl_certificate), std::move(ssl_allowed_certificates), std::move(ssl_allowed_fingerprints), ssl_allow_any_cert
+ rng, std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login), std::move(ssl_options)
);
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -219,7 +228,7 @@ namespace cryptonote
++res.height; // turn top block height into blockchain height
res.top_block_hash = string_tools::pod_to_hex(top_hash);
res.target_height = m_core.get_target_blockchain_height();
- res.difficulty = m_core.get_blockchain_storage().get_difficulty_for_next_block();
+ store_difficulty(m_core.get_blockchain_storage().get_difficulty_for_next_block(), res.difficulty, res.wide_difficulty, res.difficulty_top64);
res.target = m_core.get_blockchain_storage().get_difficulty_target();
res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase
res.tx_pool_size = m_core.get_pool_transactions_count();
@@ -236,10 +245,10 @@ namespace cryptonote
res.testnet = net_type == TESTNET;
res.stagenet = net_type == STAGENET;
res.nettype = net_type == MAINNET ? "mainnet" : net_type == TESTNET ? "testnet" : net_type == STAGENET ? "stagenet" : "fakechain";
- res.cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1);
+ store_difficulty(m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1),
+ res.cumulative_difficulty, res.wide_cumulative_difficulty, res.cumulative_difficulty_top64);
res.block_size_limit = res.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
res.block_size_median = res.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
- res.status = CORE_RPC_STATUS_OK;
res.start_time = restricted ? 0 : (uint64_t)m_core.get_start_time();
res.free_space = restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
res.offline = m_core.offline();
@@ -257,6 +266,25 @@ namespace cryptonote
res.database_size = round_up(res.database_size, 5ull* 1024 * 1024 * 1024);
res.update_available = restricted ? false : m_core.is_update_available();
res.version = restricted ? "" : MONERO_VERSION;
+
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool 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)
+ {
+ PERF_TIMER(on_get_net_stats);
+ // No bootstrap daemon check: Only ever get stats about local server
+ res.start_time = (uint64_t)m_core.get_start_time();
+ {
+ CRITICAL_REGION_LOCAL(epee::net_utils::network_throttle_manager::m_lock_get_global_throttle_in);
+ epee::net_utils::network_throttle_manager::get_global_throttle_in().get_stats(res.total_packets_in, res.total_bytes_in);
+ }
+ {
+ CRITICAL_REGION_LOCAL(epee::net_utils::network_throttle_manager::m_lock_get_global_throttle_out);
+ epee::net_utils::network_throttle_manager::get_global_throttle_out().get_stats(res.total_packets_out, res.total_bytes_out);
+ }
+ res.status = CORE_RPC_STATUS_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -621,30 +649,61 @@ namespace cryptonote
e.prunable_hash = epee::string_tools::pod_to_hex(std::get<2>(tx));
if (req.split || req.prune || std::get<3>(tx).empty())
{
+ // use splitted form with pruned and prunable (filled only when prune=false and the daemon has it), leaving as_hex as empty
e.pruned_as_hex = string_tools::buff_to_hex_nodelimer(std::get<1>(tx));
if (!req.prune)
e.prunable_as_hex = string_tools::buff_to_hex_nodelimer(std::get<3>(tx));
- }
- else
- {
- cryptonote::blobdata tx_data;
- if (req.prune)
- tx_data = std::get<1>(tx);
- else
- tx_data = std::get<1>(tx) + std::get<3>(tx);
- e.as_hex = string_tools::buff_to_hex_nodelimer(tx_data);
- if (req.decode_as_json && !tx_data.empty())
+ if (req.decode_as_json)
{
+ cryptonote::blobdata tx_data;
cryptonote::transaction t;
- if (cryptonote::parse_and_validate_tx_from_blob(tx_data, t))
+ if (req.prune || std::get<3>(tx).empty())
{
- if (req.prune)
+ // decode pruned tx to JSON
+ tx_data = std::get<1>(tx);
+ if (cryptonote::parse_and_validate_tx_base_from_blob(tx_data, t))
{
pruned_transaction pruned_tx{t};
e.as_json = obj_to_json_str(pruned_tx);
}
else
+ {
+ res.status = "Failed to parse and validate pruned tx from blob";
+ return true;
+ }
+ }
+ else
+ {
+ // decode full tx to JSON
+ tx_data = std::get<1>(tx) + std::get<3>(tx);
+ if (cryptonote::parse_and_validate_tx_from_blob(tx_data, t))
+ {
e.as_json = obj_to_json_str(t);
+ }
+ else
+ {
+ res.status = "Failed to parse and validate tx from blob";
+ return true;
+ }
+ }
+ }
+ }
+ else
+ {
+ // use non-splitted form, leaving pruned_as_hex and prunable_as_hex as empty
+ cryptonote::blobdata tx_data = std::get<1>(tx) + std::get<3>(tx);
+ e.as_hex = string_tools::buff_to_hex_nodelimer(tx_data);
+ if (req.decode_as_json)
+ {
+ cryptonote::transaction t;
+ if (cryptonote::parse_and_validate_tx_from_blob(tx_data, t))
+ {
+ e.as_json = obj_to_json_str(t);
+ }
+ else
+ {
+ res.status = "Failed to parse and validate tx from blob";
+ return true;
}
}
}
@@ -1196,13 +1255,15 @@ namespace cryptonote
block b;
cryptonote::blobdata blob_reserve;
blob_reserve.resize(req.reserve_size, 0);
- if(!m_core.get_block_template(b, info.address, res.difficulty, res.height, res.expected_reward, blob_reserve))
+ cryptonote::difficulty_type wdiff;
+ if(!m_core.get_block_template(b, info.address, wdiff, res.height, res.expected_reward, blob_reserve))
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: failed to create block template";
LOG_ERROR("Failed to create block template");
return false;
}
+ store_difficulty(wdiff, res.difficulty, res.wide_difficulty, res.difficulty_top64);
blobdata block_blob = t_serializable_object_to_blob(b);
crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(b.miner_tx);
if(tx_pub_key == crypto::null_pkey)
@@ -1375,13 +1436,16 @@ namespace cryptonote
response.height = height;
response.depth = m_core.get_current_blockchain_height() - height - 1;
response.hash = string_tools::pod_to_hex(hash);
- response.difficulty = m_core.get_blockchain_storage().block_difficulty(height);
- response.cumulative_difficulty = response.block_weight = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(height);
+ store_difficulty(m_core.get_blockchain_storage().block_difficulty(height),
+ response.difficulty, response.wide_difficulty, response.difficulty_top64);
+ store_difficulty(m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(height),
+ response.cumulative_difficulty, response.wide_cumulative_difficulty, response.cumulative_difficulty_top64);
response.reward = get_block_reward(blk);
response.block_size = response.block_weight = m_core.get_blockchain_storage().get_db().get_block_weight(height);
response.num_txes = blk.tx_hashes.size();
response.pow_hash = fill_pow_hash ? string_tools::pod_to_hex(get_block_longhash(blk, height)) : "";
response.long_term_weight = m_core.get_blockchain_storage().get_db().get_block_long_term_weight(height);
+ response.miner_tx_hash = string_tools::pod_to_hex(cryptonote::get_transaction_hash(blk.miner_tx));
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -1688,63 +1752,7 @@ namespace cryptonote
//------------------------------------------------------------------------------------------------------------------------------
bool 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)
{
- PERF_TIMER(on_get_info_json);
- bool r;
- if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_GET_INFO>(invoke_http_mode::JON_RPC, "get_info", req, res, r))
- {
- res.bootstrap_daemon_address = m_bootstrap_daemon_address;
- crypto::hash top_hash;
- m_core.get_blockchain_top(res.height_without_bootstrap, top_hash);
- ++res.height_without_bootstrap; // turn top block height into blockchain height
- res.was_bootstrap_ever_used = true;
- return r;
- }
-
- const bool restricted = m_restricted && ctx;
-
- crypto::hash top_hash;
- m_core.get_blockchain_top(res.height, top_hash);
- ++res.height; // turn top block height into blockchain height
- res.top_block_hash = string_tools::pod_to_hex(top_hash);
- res.target_height = m_core.get_target_blockchain_height();
- res.difficulty = m_core.get_blockchain_storage().get_difficulty_for_next_block();
- res.target = m_core.get_blockchain_storage().get_current_hard_fork_version() < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2;
- res.tx_count = m_core.get_blockchain_storage().get_total_transactions() - res.height; //without coinbase
- res.tx_pool_size = m_core.get_pool_transactions_count();
- res.alt_blocks_count = restricted ? 0 : m_core.get_blockchain_storage().get_alternative_blocks_count();
- uint64_t total_conn = restricted ? 0 : m_p2p.get_public_connections_count();
- res.outgoing_connections_count = restricted ? 0 : m_p2p.get_public_outgoing_connections_count();
- res.incoming_connections_count = restricted ? 0 : (total_conn - res.outgoing_connections_count);
- res.rpc_connections_count = restricted ? 0 : get_connections_count();
- res.white_peerlist_size = restricted ? 0 : m_p2p.get_public_white_peers_count();
- res.grey_peerlist_size = restricted ? 0 : m_p2p.get_public_gray_peers_count();
-
- cryptonote::network_type net_type = nettype();
- res.mainnet = net_type == MAINNET;
- res.testnet = net_type == TESTNET;
- res.stagenet = net_type == STAGENET;
- res.nettype = net_type == MAINNET ? "mainnet" : net_type == TESTNET ? "testnet" : net_type == STAGENET ? "stagenet" : "fakechain";
-
- res.cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.height - 1);
- res.block_size_limit = res.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
- res.block_size_median = res.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
- res.status = CORE_RPC_STATUS_OK;
- res.start_time = restricted ? 0 : (uint64_t)m_core.get_start_time();
- res.free_space = restricted ? std::numeric_limits<uint64_t>::max() : m_core.get_free_space();
- res.offline = m_core.offline();
- res.bootstrap_daemon_address = restricted ? "" : m_bootstrap_daemon_address;
- res.height_without_bootstrap = restricted ? 0 : res.height;
- if (restricted)
- res.was_bootstrap_ever_used = false;
- else
- {
- boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
- res.was_bootstrap_ever_used = m_was_bootstrap_ever_used;
- }
- res.database_size = restricted ? 0 : m_core.get_blockchain_storage().get_db().get_database_size();
- res.update_available = restricted ? false : m_core.is_update_available();
- res.version = restricted ? "" : MONERO_VERSION;
- return true;
+ return on_get_info(req, res, ctx);
}
//------------------------------------------------------------------------------------------------------------------------------
bool 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)
@@ -1947,7 +1955,9 @@ namespace cryptonote
std::list<std::pair<Blockchain::block_extended_info, std::vector<crypto::hash>>> chains = m_core.get_blockchain_storage().get_alternative_chains();
for (const auto &i: chains)
{
- 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(), i.first.cumulative_difficulty, {}, std::string()});
+ difficulty_type wdiff = i.first.cumulative_difficulty;
+ 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()});
+ store_difficulty(wdiff, res.chains.back().difficulty, res.chains.back().wide_difficulty, res.chains.back().difficulty_top64);
res.chains.back().block_hashes.reserve(i.second.size());
for (const crypto::hash &block_id: i.second)
res.chains.back().block_hashes.push_back(epee::string_tools::pod_to_hex(block_id));
@@ -2400,9 +2410,9 @@ namespace cryptonote
, ""
};
- const command_line::arg_descriptor<std::vector<std::string>> core_rpc_server::arg_rpc_ssl_allowed_certificates = {
- "rpc-ssl-allowed-certificates"
- , "List of paths to PEM format certificates of allowed peers (all allowed if empty)"
+ const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_ssl_ca_certificates = {
+ "rpc-ssl-ca-certificates"
+ , "Path to file containing concatenated PEM format certificate(s) to replace system CA(s)."
};
const command_line::arg_descriptor<std::vector<std::string>> core_rpc_server::arg_rpc_ssl_allowed_fingerprints = {
@@ -2412,7 +2422,7 @@ namespace cryptonote
const command_line::arg_descriptor<bool> core_rpc_server::arg_rpc_ssl_allow_any_cert = {
"rpc-ssl-allow-any-cert"
- , "Allow any peer certificate, rather than just those on the allowed list"
+ , "Allow any peer certificate"
, false
};
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index fe066b31b..a42ca2494 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -60,7 +60,7 @@ namespace cryptonote
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::vector<std::string>> arg_rpc_ssl_allowed_certificates;
+ 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<bool> arg_rpc_ssl_allow_any_cert;
static const command_line::arg_descriptor<std::string> arg_bootstrap_daemon_address;
@@ -115,6 +115,7 @@ namespace cryptonote
MAP_URI_AUTO_JON2_IF("/stop_daemon", on_stop_daemon, COMMAND_RPC_STOP_DAEMON, !m_restricted)
MAP_URI_AUTO_JON2("/get_info", on_get_info, COMMAND_RPC_GET_INFO)
MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO)
+ MAP_URI_AUTO_JON2_IF("/get_net_stats", on_get_net_stats, COMMAND_RPC_GET_NET_STATS, !m_restricted)
MAP_URI_AUTO_JON2("/get_limit", on_get_limit, COMMAND_RPC_GET_LIMIT)
MAP_URI_AUTO_JON2_IF("/set_limit", on_set_limit, COMMAND_RPC_SET_LIMIT, !m_restricted)
MAP_URI_AUTO_JON2_IF("/out_peers", on_out_peers, COMMAND_RPC_OUT_PEERS, !m_restricted)
@@ -179,6 +180,7 @@ namespace cryptonote
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);
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index f65c7c8dd..1f14267f6 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -84,7 +84,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 2
-#define CORE_RPC_VERSION_MINOR 4
+#define CORE_RPC_VERSION_MINOR 5
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@@ -252,223 +252,6 @@ namespace cryptonote
};
//-----------------------------------------------
- struct COMMAND_RPC_GET_ADDRESS_TXS
- {
- struct request_t
- {
- std::string address;
- std::string view_key;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(address)
- KV_SERIALIZE(view_key)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
- struct spent_output {
- uint64_t amount;
- std::string key_image;
- std::string tx_pub_key;
- uint64_t out_index;
- uint32_t mixin;
-
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(amount)
- KV_SERIALIZE(key_image)
- KV_SERIALIZE(tx_pub_key)
- KV_SERIALIZE(out_index)
- KV_SERIALIZE(mixin)
- END_KV_SERIALIZE_MAP()
- };
-
- struct transaction
- {
- uint64_t id;
- std::string hash;
- uint64_t timestamp;
- uint64_t total_received;
- uint64_t total_sent;
- uint64_t unlock_time;
- uint64_t height;
- std::list<spent_output> spent_outputs;
- std::string payment_id;
- bool coinbase;
- bool mempool;
- uint32_t mixin;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(id)
- KV_SERIALIZE(hash)
- KV_SERIALIZE(timestamp)
- KV_SERIALIZE(total_received)
- KV_SERIALIZE(total_sent)
- KV_SERIALIZE(unlock_time)
- KV_SERIALIZE(height)
- KV_SERIALIZE(spent_outputs)
- KV_SERIALIZE(payment_id)
- KV_SERIALIZE(coinbase)
- KV_SERIALIZE(mempool)
- KV_SERIALIZE(mixin)
- END_KV_SERIALIZE_MAP()
- };
-
-
- struct response_t
- {
- //std::list<std::string> txs_as_json;
- uint64_t total_received;
- uint64_t total_received_unlocked = 0; // OpenMonero only
- uint64_t scanned_height;
- std::vector<transaction> transactions;
- uint64_t blockchain_height;
- uint64_t scanned_block_height;
- std::string status;
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(total_received)
- KV_SERIALIZE(total_received_unlocked)
- KV_SERIALIZE(scanned_height)
- KV_SERIALIZE(transactions)
- KV_SERIALIZE(blockchain_height)
- KV_SERIALIZE(scanned_block_height)
- KV_SERIALIZE(status)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
-
- //-----------------------------------------------
- struct COMMAND_RPC_GET_ADDRESS_INFO
- {
- struct request_t
- {
- std::string address;
- std::string view_key;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(address)
- KV_SERIALIZE(view_key)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
- struct spent_output
- {
- uint64_t amount;
- std::string key_image;
- std::string tx_pub_key;
- uint64_t out_index;
- uint32_t mixin;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(amount)
- KV_SERIALIZE(key_image)
- KV_SERIALIZE(tx_pub_key)
- KV_SERIALIZE(out_index)
- KV_SERIALIZE(mixin)
- END_KV_SERIALIZE_MAP()
- };
-
- struct response_t
- {
- uint64_t locked_funds;
- uint64_t total_received;
- uint64_t total_sent;
- uint64_t scanned_height;
- uint64_t scanned_block_height;
- uint64_t start_height;
- uint64_t transaction_height;
- uint64_t blockchain_height;
- std::list<spent_output> spent_outputs;
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(locked_funds)
- KV_SERIALIZE(total_received)
- KV_SERIALIZE(total_sent)
- KV_SERIALIZE(scanned_height)
- KV_SERIALIZE(scanned_block_height)
- KV_SERIALIZE(start_height)
- KV_SERIALIZE(transaction_height)
- KV_SERIALIZE(blockchain_height)
- KV_SERIALIZE(spent_outputs)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
-
- //-----------------------------------------------
- struct COMMAND_RPC_GET_UNSPENT_OUTS
- {
- struct request_t
- {
- std::string amount;
- std::string address;
- std::string view_key;
- // OpenMonero specific
- uint64_t mixin;
- bool use_dust;
- std::string dust_threshold;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(amount)
- KV_SERIALIZE(address)
- KV_SERIALIZE(view_key)
- KV_SERIALIZE(mixin)
- KV_SERIALIZE(use_dust)
- KV_SERIALIZE(dust_threshold)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
-
- struct output {
- uint64_t amount;
- std::string public_key;
- uint64_t index;
- uint64_t global_index;
- std::string rct;
- std::string tx_hash;
- std::string tx_pub_key;
- std::string tx_prefix_hash;
- std::vector<std::string> spend_key_images;
- uint64_t timestamp;
- uint64_t height;
-
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(amount)
- KV_SERIALIZE(public_key)
- KV_SERIALIZE(index)
- KV_SERIALIZE(global_index)
- KV_SERIALIZE(rct)
- KV_SERIALIZE(tx_hash)
- KV_SERIALIZE(tx_pub_key)
- KV_SERIALIZE(tx_prefix_hash)
- KV_SERIALIZE(spend_key_images)
- KV_SERIALIZE(timestamp)
- KV_SERIALIZE(height)
- END_KV_SERIALIZE_MAP()
- };
-
- struct response_t
- {
- uint64_t amount;
- std::list<output> outputs;
- uint64_t per_kb_fee;
- std::string status;
- std::string reason;
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(amount)
- KV_SERIALIZE(outputs)
- KV_SERIALIZE(per_kb_fee)
- KV_SERIALIZE(status)
- KV_SERIALIZE(reason)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
-
- //-----------------------------------------------
struct COMMAND_RPC_GET_RANDOM_OUTS
{
struct request_t
@@ -548,72 +331,6 @@ namespace cryptonote
typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
- struct COMMAND_RPC_LOGIN
- {
- struct request_t
- {
- std::string address;
- std::string view_key;
- bool create_account;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(address)
- KV_SERIALIZE(view_key)
- KV_SERIALIZE(create_account)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
- struct response_t
- {
- std::string status;
- std::string reason;
- bool new_address;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(status)
- KV_SERIALIZE(reason)
- KV_SERIALIZE(new_address)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
- //-----------------------------------------------
- struct COMMAND_RPC_IMPORT_WALLET_REQUEST
- {
- struct request_t
- {
- std::string address;
- std::string view_key;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(address)
- KV_SERIALIZE(view_key)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
- struct response_t
- {
- std::string payment_id;
- uint64_t import_fee;
- bool new_request;
- bool request_fulfilled;
- std::string payment_address;
- std::string status;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(payment_id)
- KV_SERIALIZE(import_fee)
- KV_SERIALIZE(new_request)
- KV_SERIALIZE(request_fulfilled)
- KV_SERIALIZE(payment_address)
- KV_SERIALIZE(status)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
- //-----------------------------------------------
struct COMMAND_RPC_GET_TRANSACTIONS
{
struct request_t
@@ -943,6 +660,8 @@ namespace cryptonote
uint64_t height;
uint64_t target_height;
uint64_t difficulty;
+ std::string wide_difficulty;
+ uint64_t difficulty_top64;
uint64_t target;
uint64_t tx_count;
uint64_t tx_pool_size;
@@ -958,6 +677,8 @@ namespace cryptonote
std::string nettype;
std::string top_block_hash;
uint64_t cumulative_difficulty;
+ std::string wide_cumulative_difficulty;
+ uint64_t cumulative_difficulty_top64;
uint64_t block_size_limit;
uint64_t block_weight_limit;
uint64_t block_size_median;
@@ -978,6 +699,8 @@ namespace cryptonote
KV_SERIALIZE(height)
KV_SERIALIZE(target_height)
KV_SERIALIZE(difficulty)
+ KV_SERIALIZE(wide_difficulty)
+ KV_SERIALIZE(difficulty_top64)
KV_SERIALIZE(target)
KV_SERIALIZE(tx_count)
KV_SERIALIZE(tx_pool_size)
@@ -993,6 +716,8 @@ namespace cryptonote
KV_SERIALIZE(nettype)
KV_SERIALIZE(top_block_hash)
KV_SERIALIZE(cumulative_difficulty)
+ KV_SERIALIZE(wide_cumulative_difficulty)
+ KV_SERIALIZE(cumulative_difficulty_top64)
KV_SERIALIZE(block_size_limit)
KV_SERIALIZE_OPT(block_weight_limit, (uint64_t)0)
KV_SERIALIZE(block_size_median)
@@ -1014,6 +739,39 @@ namespace cryptonote
//-----------------------------------------------
+ struct COMMAND_RPC_GET_NET_STATS
+ {
+ struct request_t
+ {
+
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+
+ struct response_t
+ {
+ std::string status;
+ uint64_t start_time;
+ uint64_t total_packets_in;
+ uint64_t total_bytes_in;
+ uint64_t total_packets_out;
+ uint64_t total_bytes_out;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ KV_SERIALIZE(start_time)
+ KV_SERIALIZE(total_packets_in)
+ KV_SERIALIZE(total_bytes_in)
+ KV_SERIALIZE(total_packets_out)
+ KV_SERIALIZE(total_bytes_out)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
+
+ //-----------------------------------------------
struct COMMAND_RPC_STOP_MINING
{
struct request_t
@@ -1149,6 +907,8 @@ namespace cryptonote
struct response_t
{
uint64_t difficulty;
+ std::string wide_difficulty;
+ uint64_t difficulty_top64;
uint64_t height;
uint64_t reserved_offset;
uint64_t expected_reward;
@@ -1160,6 +920,8 @@ namespace cryptonote
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(difficulty)
+ KV_SERIALIZE(wide_difficulty)
+ KV_SERIALIZE(difficulty_top64)
KV_SERIALIZE(height)
KV_SERIALIZE(reserved_offset)
KV_SERIALIZE(expected_reward)
@@ -1226,14 +988,19 @@ namespace cryptonote
uint64_t height;
uint64_t depth;
std::string hash;
- difficulty_type difficulty;
- difficulty_type cumulative_difficulty;
+ uint64_t difficulty;
+ std::string wide_difficulty;
+ uint64_t difficulty_top64;
+ uint64_t cumulative_difficulty;
+ std::string wide_cumulative_difficulty;
+ uint64_t cumulative_difficulty_top64;
uint64_t reward;
uint64_t block_size;
uint64_t block_weight;
uint64_t num_txes;
std::string pow_hash;
uint64_t long_term_weight;
+ std::string miner_tx_hash;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(major_version)
@@ -1246,13 +1013,18 @@ namespace cryptonote
KV_SERIALIZE(depth)
KV_SERIALIZE(hash)
KV_SERIALIZE(difficulty)
+ KV_SERIALIZE(wide_difficulty)
+ KV_SERIALIZE(difficulty_top64)
KV_SERIALIZE(cumulative_difficulty)
+ KV_SERIALIZE(wide_cumulative_difficulty)
+ KV_SERIALIZE(cumulative_difficulty_top64)
KV_SERIALIZE(reward)
KV_SERIALIZE(block_size)
KV_SERIALIZE_OPT(block_weight, (uint64_t)0)
KV_SERIALIZE(num_txes)
KV_SERIALIZE(pow_hash)
KV_SERIALIZE_OPT(long_term_weight, (uint64_t)0)
+ KV_SERIALIZE(miner_tx_hash)
END_KV_SERIALIZE_MAP()
};
@@ -2248,6 +2020,8 @@ namespace cryptonote
uint64_t height;
uint64_t length;
uint64_t difficulty;
+ std::string wide_difficulty;
+ uint64_t difficulty_top64;
std::vector<std::string> block_hashes;
std::string main_chain_parent_block;
@@ -2256,6 +2030,8 @@ namespace cryptonote
KV_SERIALIZE(height)
KV_SERIALIZE(length)
KV_SERIALIZE(difficulty)
+ KV_SERIALIZE(wide_difficulty)
+ KV_SERIALIZE(difficulty_top64)
KV_SERIALIZE(block_hashes)
KV_SERIALIZE(main_chain_parent_block)
END_KV_SERIALIZE_MAP()
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index bde2339bc..540afe6b9 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -436,7 +436,8 @@ namespace rpc
auto& chain = m_core.get_blockchain_storage();
- res.info.difficulty = chain.get_difficulty_for_next_block();
+ res.info.wide_difficulty = chain.get_difficulty_for_next_block();
+ res.info.difficulty = (res.info.wide_difficulty << 64 >> 64).convert_to<uint64_t>();
res.info.target = chain.get_difficulty_target();
@@ -457,7 +458,8 @@ namespace rpc
res.info.mainnet = m_core.get_nettype() == MAINNET;
res.info.testnet = m_core.get_nettype() == TESTNET;
res.info.stagenet = m_core.get_nettype() == STAGENET;
- res.info.cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.info.height - 1);
+ res.info.wide_cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.info.height - 1);
+ res.info.cumulative_difficulty = (res.info.wide_cumulative_difficulty << 64 >> 64).convert_to<uint64_t>();
res.info.block_size_limit = res.info.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
res.info.block_size_median = res.info.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
res.info.start_time = (uint64_t)m_core.get_start_time();
@@ -826,7 +828,8 @@ namespace rpc
header.reward += out.amount;
}
- header.difficulty = m_core.get_blockchain_storage().block_difficulty(header.height);
+ header.wide_difficulty = m_core.get_blockchain_storage().block_difficulty(header.height);
+ header.difficulty = (header.wide_difficulty << 64 >> 64).convert_to<uint64_t>();
return true;
}
diff --git a/src/rpc/message_data_structs.h b/src/rpc/message_data_structs.h
index 26c5038f6..2a43811cf 100644
--- a/src/rpc/message_data_structs.h
+++ b/src/rpc/message_data_structs.h
@@ -30,6 +30,7 @@
#include "crypto/hash.h"
#include "cryptonote_basic/cryptonote_basic.h"
+#include "cryptonote_basic/difficulty.h"
#include "ringct/rctSigs.h"
#include "rpc/rpc_handler.h"
@@ -165,6 +166,7 @@ namespace rpc
uint64_t height;
uint64_t depth;
crypto::hash hash;
+ cryptonote::difficulty_type wide_difficulty;
uint64_t difficulty;
uint64_t reward;
};
@@ -173,6 +175,7 @@ namespace rpc
{
uint64_t height;
uint64_t target_height;
+ cryptonote::difficulty_type wide_difficulty;
uint64_t difficulty;
uint64_t target;
uint64_t tx_count;
@@ -187,6 +190,7 @@ namespace rpc
bool stagenet;
std::string nettype;
crypto::hash top_block_hash;
+ cryptonote::difficulty_type wide_cumulative_difficulty;
uint64_t cumulative_difficulty;
uint64_t block_size_limit;
uint64_t block_weight_limit;