aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/core_rpc_server.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-10-13 21:37:35 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-10-13 21:37:35 +0100
commitca23c0e5c8fc1320a7172cd88e14298c8ad3171c (patch)
tree658fae53437fc62c11428cf6187d9125a9219e8d /src/rpc/core_rpc_server.cpp
parentMerge pull request #427 (diff)
downloadmonero-ca23c0e5c8fc1320a7172cd88e14298c8ad3171c.tar.xz
core_rpc_server: add a getblock RPC command, and fix print_block
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r--src/rpc/core_rpc_server.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index f9ff632ac..248ba17ac 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -772,6 +772,66 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_get_block(const COMMAND_RPC_GET_BLOCK::request& req, COMMAND_RPC_GET_BLOCK::response& res, epee::json_rpc::error& error_resp){
+ if(!check_core_busy())
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
+ error_resp.message = "Core is busy.";
+ return false;
+ }
+ crypto::hash block_hash;
+ if (!req.hash.empty())
+ {
+ bool hash_parsed = parse_hash256(req.hash, block_hash);
+ if(!hash_parsed)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
+ error_resp.message = "Failed to parse hex representation of block hash. Hex = " + req.hash + '.';
+ return false;
+ }
+ }
+ else
+ {
+ if(m_core.get_current_blockchain_height() <= req.height)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_TOO_BIG_HEIGHT;
+ error_resp.message = std::string("To big height: ") + std::to_string(req.height) + ", current blockchain height = " + std::to_string(m_core.get_current_blockchain_height());
+ return false;
+ }
+ block_hash = m_core.get_block_id_by_height(req.height);
+ }
+ 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 hash. Hash = " + req.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;
+ bool responce_filled = fill_block_header_responce(blk, false, block_height, block_hash, res.block_header);
+ if (!responce_filled)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Internal error: can't produce valid response.";
+ return false;
+ }
+ for (size_t n = 0; n < blk.tx_hashes.size(); ++n)
+ {
+ res.tx_hashes.push_back(epee::string_tools::pod_to_hex(blk.tx_hashes[n]));
+ }
+ res.blob = t_serializable_object_to_blob(blk);
+ res.json = obj_to_json_str(blk);
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_connections(const COMMAND_RPC_GET_CONNECTIONS::request& req, COMMAND_RPC_GET_CONNECTIONS::response& res, epee::json_rpc::error& error_resp)
{
if(!check_core_busy())