aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/daemon_handler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc/daemon_handler.cpp')
-rw-r--r--src/rpc/daemon_handler.cpp47
1 files changed, 37 insertions, 10 deletions
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index 871f7d368..540afe6b9 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -263,20 +263,43 @@ namespace rpc
void DaemonHandler::handle(const SendRawTx::Request& req, SendRawTx::Response& res)
{
- auto tx_blob = cryptonote::tx_to_blob(req.tx);
+ handleTxBlob(cryptonote::tx_to_blob(req.tx), req.relay, res);
+ }
+
+ void DaemonHandler::handle(const SendRawTxHex::Request& req, SendRawTxHex::Response& res)
+ {
+ std::string tx_blob;
+ if(!epee::string_tools::parse_hexstr_to_binbuff(req.tx_as_hex, tx_blob))
+ {
+ MERROR("[SendRawTxHex]: Failed to parse tx from hexbuff: " << req.tx_as_hex);
+ res.status = Message::STATUS_FAILED;
+ res.error_details = "Invalid hex";
+ return;
+ }
+ handleTxBlob(tx_blob, req.relay, res);
+ }
+
+ void DaemonHandler::handleTxBlob(const std::string& tx_blob, bool relay, SendRawTx::Response& res)
+ {
+ if (!m_p2p.get_payload_object().is_synchronized())
+ {
+ res.status = Message::STATUS_FAILED;
+ res.error_details = "Not ready to accept transactions; try again later";
+ return;
+ }
cryptonote_connection_context fake_context = AUTO_VAL_INIT(fake_context);
tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- if(!m_core.handle_incoming_tx(tx_blob, tvc, false, false, !req.relay) || tvc.m_verifivation_failed)
+ if(!m_core.handle_incoming_tx(tx_blob, tvc, false, false, !relay) || tvc.m_verifivation_failed)
{
if (tvc.m_verifivation_failed)
{
- LOG_PRINT_L0("[on_send_raw_tx]: tx verification failed");
+ MERROR("[SendRawTx]: tx verification failed");
}
else
{
- LOG_PRINT_L0("[on_send_raw_tx]: Failed to process tx");
+ MERROR("[SendRawTx]: Failed to process tx");
}
res.status = Message::STATUS_FAILED;
res.error_details = "";
@@ -328,9 +351,9 @@ namespace rpc
return;
}
- if(!tvc.m_should_be_relayed || !req.relay)
+ if(!tvc.m_should_be_relayed || !relay)
{
- LOG_PRINT_L0("[on_send_raw_tx]: tx accepted, but not relayed");
+ MERROR("[SendRawTx]: tx accepted, but not relayed");
res.error_details = "Not relayed";
res.relayed = false;
res.status = Message::STATUS_OK;
@@ -413,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();
@@ -434,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();
@@ -803,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;
}
@@ -830,6 +856,7 @@ namespace rpc
REQ_RESP_TYPES_MACRO(request_type, KeyImagesSpent, req_json, resp_message, handle);
REQ_RESP_TYPES_MACRO(request_type, GetTxGlobalOutputIndices, req_json, resp_message, handle);
REQ_RESP_TYPES_MACRO(request_type, SendRawTx, req_json, resp_message, handle);
+ REQ_RESP_TYPES_MACRO(request_type, SendRawTxHex, req_json, resp_message, handle);
REQ_RESP_TYPES_MACRO(request_type, GetInfo, req_json, resp_message, handle);
REQ_RESP_TYPES_MACRO(request_type, StartMining, req_json, resp_message, handle);
REQ_RESP_TYPES_MACRO(request_type, StopMining, req_json, resp_message, handle);