aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/CMakeLists.txt4
-rw-r--r--src/rpc/core_rpc_server.cpp99
-rw-r--r--src/rpc/core_rpc_server.h6
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h12
4 files changed, 82 insertions, 39 deletions
diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt
index 1716da75b..050b5e569 100644
--- a/src/rpc/CMakeLists.txt
+++ b/src/rpc/CMakeLists.txt
@@ -36,9 +36,9 @@ set(rpc_private_headers
core_rpc_server_commands_defs.h
core_rpc_server_error_codes.h)
-bitmonero_private_headers(rpc
+monero_private_headers(rpc
${rpc_private_headers})
-bitmonero_add_library(rpc
+monero_add_library(rpc
${rpc_sources}
${rpc_headers}
${rpc_private_headers})
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index f6431a018..76ffd9334 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -830,19 +830,19 @@ namespace cryptonote
return reward;
}
//------------------------------------------------------------------------------------------------------------------------------
- bool core_rpc_server::fill_block_header_responce(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_responce& responce)
+ bool core_rpc_server::fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response)
{
- responce.major_version = blk.major_version;
- responce.minor_version = blk.minor_version;
- responce.timestamp = blk.timestamp;
- responce.prev_hash = string_tools::pod_to_hex(blk.prev_id);
- responce.nonce = blk.nonce;
- responce.orphan_status = orphan_status;
- responce.height = height;
- responce.depth = m_core.get_current_blockchain_height() - height - 1;
- responce.hash = string_tools::pod_to_hex(hash);
- responce.difficulty = m_core.get_blockchain_storage().block_difficulty(height);
- responce.reward = get_block_reward(blk);
+ response.major_version = blk.major_version;
+ response.minor_version = blk.minor_version;
+ response.timestamp = blk.timestamp;
+ response.prev_hash = string_tools::pod_to_hex(blk.prev_id);
+ response.nonce = blk.nonce;
+ response.orphan_status = orphan_status;
+ 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.reward = get_block_reward(blk);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -871,8 +871,8 @@ namespace cryptonote
error_resp.message = "Internal error: can't get last block.";
return false;
}
- bool responce_filled = fill_block_header_responce(last_block, false, last_block_height, last_block_hash, res.block_header);
- if (!responce_filled)
+ bool response_filled = fill_block_header_response(last_block, false, last_block_height, last_block_hash, res.block_header);
+ if (!response_filled)
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: can't produce valid response.";
@@ -912,8 +912,8 @@ namespace cryptonote
return false;
}
uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
- bool responce_filled = fill_block_header_responce(blk, false, block_height, block_hash, res.block_header);
- if (!responce_filled)
+ bool response_filled = fill_block_header_response(blk, false, block_height, block_hash, res.block_header);
+ if (!response_filled)
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: can't produce valid response.";
@@ -923,6 +923,57 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_get_block_headers_range(const COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::request& req, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE::response& res, epee::json_rpc::error& error_resp){
+ if(!check_core_busy())
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
+ error_resp.message = "Core is busy.";
+ return false;
+ }
+ const uint64_t bc_height = m_core.get_current_blockchain_height();
+ if (req.start_height >= bc_height || req.end_height >= bc_height || req.start_height > req.end_height)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT;
+ error_resp.message = "Invalid start/end heights.";
+ return false;
+ }
+ for (uint64_t h = req.start_height; h <= req.end_height; ++h)
+ {
+ crypto::hash block_hash = m_core.get_block_id_by_height(h);
+ block blk;
+ bool have_block = m_core.get_block_by_hash(block_hash, blk);
+ if (!have_block)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Internal error: can't get block by height. Height = " + boost::lexical_cast<std::string>(h) + ". Hash = " + epee::string_tools::pod_to_hex(block_hash) + '.';
+ return false;
+ }
+ if (blk.miner_tx.vin.front().type() != typeid(txin_gen))
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Internal error: coinbase transaction in the block has the wrong type";
+ return false;
+ }
+ uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
+ if (block_height != h)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Internal error: coinbase transaction in the block has the wrong height";
+ return false;
+ }
+ res.headers.push_back(block_header_responce());
+ bool responce_filled = fill_block_header_responce(blk, false, block_height, block_hash, res.headers.back());
+ if (!responce_filled)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Internal error: can't produce valid response.";
+ return false;
+ }
+ }
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_block_header_by_height(const COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT::response& res, epee::json_rpc::error& error_resp){
if(!check_core_busy())
{
@@ -945,8 +996,8 @@ namespace cryptonote
error_resp.message = "Internal error: can't get block by height. Height = " + std::to_string(req.height) + '.';
return false;
}
- bool responce_filled = fill_block_header_responce(blk, false, req.height, block_hash, res.block_header);
- if (!responce_filled)
+ bool response_filled = fill_block_header_response(blk, false, req.height, block_hash, res.block_header);
+ if (!response_filled)
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: can't produce valid response.";
@@ -999,8 +1050,8 @@ namespace cryptonote
return false;
}
uint64_t block_height = boost::get<txin_gen>(blk.miner_tx.vin.front()).height;
- bool responce_filled = fill_block_header_responce(blk, false, block_height, block_hash, res.block_header);
- if (!responce_filled)
+ bool response_filled = fill_block_header_response(blk, false, block_height, block_hash, res.block_header);
+ if (!response_filled)
{
error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
error_resp.message = "Internal error: can't produce valid response.";
@@ -1215,14 +1266,6 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
- bool core_rpc_server::on_fast_exit(const COMMAND_RPC_FAST_EXIT::request& req, COMMAND_RPC_FAST_EXIT::response& res)
- {
- cryptonote::core::set_fast_exit();
- m_p2p.deinit();
- m_core.deinit();
- return true;
- }
- //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res)
{
// TODO
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 9885aa0ff..68da59f6b 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -94,7 +94,6 @@ namespace cryptonote
MAP_URI_AUTO_JON2("/get_transaction_pool", on_get_transaction_pool, COMMAND_RPC_GET_TRANSACTION_POOL)
MAP_URI_AUTO_JON2_IF("/stop_daemon", on_stop_daemon, COMMAND_RPC_STOP_DAEMON, !m_restricted)
MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO)
- MAP_URI_AUTO_JON2_IF("/fast_exit", on_fast_exit, COMMAND_RPC_FAST_EXIT, !m_restricted)
MAP_URI_AUTO_JON2_IF("/out_peers", on_out_peers, COMMAND_RPC_OUT_PEERS, !m_restricted)
MAP_URI_AUTO_JON2_IF("/start_save_graph", on_start_save_graph, COMMAND_RPC_START_SAVE_GRAPH, !m_restricted)
MAP_URI_AUTO_JON2_IF("/stop_save_graph", on_stop_save_graph, COMMAND_RPC_STOP_SAVE_GRAPH, !m_restricted)
@@ -106,6 +105,7 @@ namespace cryptonote
MAP_JON_RPC_WE("getlastblockheader", on_get_last_block_header, COMMAND_RPC_GET_LAST_BLOCK_HEADER)
MAP_JON_RPC_WE("getblockheaderbyhash", on_get_block_header_by_hash, COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH)
MAP_JON_RPC_WE("getblockheaderbyheight", on_get_block_header_by_height, COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT)
+ MAP_JON_RPC_WE("getblockheadersrange", on_get_block_headers_range, COMMAND_RPC_GET_BLOCK_HEADERS_RANGE)
MAP_JON_RPC_WE("getblock", on_get_block, COMMAND_RPC_GET_BLOCK)
MAP_JON_RPC_WE_IF("get_connections", on_get_connections, COMMAND_RPC_GET_CONNECTIONS, !m_restricted)
MAP_JON_RPC_WE("get_info", on_get_info_json, COMMAND_RPC_GET_INFO)
@@ -138,7 +138,6 @@ namespace cryptonote
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res);
bool on_get_transaction_pool(const COMMAND_RPC_GET_TRANSACTION_POOL::request& req, COMMAND_RPC_GET_TRANSACTION_POOL::response& res);
bool on_stop_daemon(const COMMAND_RPC_STOP_DAEMON::request& req, COMMAND_RPC_STOP_DAEMON::response& res);
- bool on_fast_exit(const COMMAND_RPC_FAST_EXIT::request& req, COMMAND_RPC_FAST_EXIT::response& res);
bool on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res);
bool on_start_save_graph(const COMMAND_RPC_START_SAVE_GRAPH::request& req, COMMAND_RPC_START_SAVE_GRAPH::response& res);
bool on_stop_save_graph(const COMMAND_RPC_STOP_SAVE_GRAPH::request& req, COMMAND_RPC_STOP_SAVE_GRAPH::response& res);
@@ -151,6 +150,7 @@ namespace cryptonote
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);
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);
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);
+ 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);
bool on_get_block(const COMMAND_RPC_GET_BLOCK::request& req, COMMAND_RPC_GET_BLOCK::response& res, epee::json_rpc::error& error_resp);
bool on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp);
bool on_get_info_json(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, epee::json_rpc::error& error_resp);
@@ -172,7 +172,7 @@ private:
//utils
uint64_t get_block_reward(const block& blk);
- bool fill_block_header_responce(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_responce& responce);
+ bool fill_block_header_response(const block& blk, bool orphan_status, uint64_t height, const crypto::hash& hash, block_header_response& response);
core& m_core;
nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<cryptonote::core> >& m_p2p;
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 8cba53943..dd2116e51 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -631,7 +631,7 @@ namespace cryptonote
};
};
- struct block_header_responce
+ struct block_header_response
{
uint8_t major_version;
uint8_t minor_version;
@@ -671,7 +671,7 @@ namespace cryptonote
struct response
{
std::string status;
- block_header_responce block_header;
+ block_header_response block_header;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(block_header)
@@ -695,7 +695,7 @@ namespace cryptonote
struct response
{
std::string status;
- block_header_responce block_header;
+ block_header_response block_header;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(block_header)
@@ -719,7 +719,7 @@ namespace cryptonote
struct response
{
std::string status;
- block_header_responce block_header;
+ block_header_response block_header;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(block_header)
@@ -745,7 +745,7 @@ namespace cryptonote
struct response
{
std::string status;
- block_header_responce block_header;
+ block_header_response block_header;
std::vector<std::string> tx_hashes;
std::string blob;
std::string json;
@@ -940,7 +940,7 @@ namespace cryptonote
struct response
{
std::string status;
- std::vector<block_header_responce> headers;
+ std::vector<block_header_response> headers;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)