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.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index 871f7d368..84e227631 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -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;
@@ -830,6 +853,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);