From 6fd234519741c217c97ca0bf9b526ad31da60248 Mon Sep 17 00:00:00 2001 From: aiwe Date: Wed, 27 Dec 2023 12:35:42 -0600 Subject: [PATCH] Change error handling in /sendrawtransaction --- src/Rpc/RpcServer.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Rpc/RpcServer.cpp b/src/Rpc/RpcServer.cpp index f6b2d9ffbe..2fda2758b0 100755 --- a/src/Rpc/RpcServer.cpp +++ b/src/Rpc/RpcServer.cpp @@ -2211,8 +2211,7 @@ bool RpcServer::on_send_raw_transaction(const COMMAND_RPC_SEND_RAW_TRANSACTION:: if (!Common::fromHex(req.tx_as_hex, tx_blob)) { logger(Logging::INFO) << "[on_send_raw_tx]: Failed to parse transaction from hexbuff: " << req.tx_as_hex; - res.status = "Failed"; - return true; + throw JsonRpc::JsonRpcError{ CORE_RPC_ERROR_CODE_WRONG_PARAM, "Failed to parse transaction from hexbuff" }; } Crypto::Hash transactionHash = Crypto::cn_fast_hash(tx_blob.data(), tx_blob.size()); @@ -2222,15 +2221,13 @@ bool RpcServer::on_send_raw_transaction(const COMMAND_RPC_SEND_RAW_TRANSACTION:: if (!m_core.handle_incoming_tx(tx_blob, tvc, false)) { logger(Logging::INFO) << "[on_send_raw_tx]: Failed to process tx"; - res.status = "Failed"; - return true; + throw JsonRpc::JsonRpcError{ CORE_RPC_ERROR_CODE_INTERNAL_ERROR, "Failed to process tx" }; } if (tvc.m_verification_failed) { - logger(Logging::INFO) << "[on_send_raw_tx]: transaction verification failed"; - res.status = "Failed"; - return true; + logger(Logging::INFO) << "[on_send_raw_tx]: Transaction verification failed"; + throw JsonRpc::JsonRpcError{ CORE_RPC_ERROR_CODE_WRONG_PARAM, "Transaction verification failed" }; } if (!tvc.m_should_be_relayed)