diff options
author | luigi1111 <luigi1111w@gmail.com> | 2024-07-16 18:58:08 -0400 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2024-07-16 18:58:08 -0400 |
commit | 8dbbc478047b4b036cdd722d67f90313550bb8d7 (patch) | |
tree | c5bf2046da95fa723844e298271cba80ddcc84c9 | |
parent | Merge pull request #9370 (diff) | |
parent | wallet2: move get_rpc_status func to RPC server definition file (diff) | |
download | monero-8dbbc478047b4b036cdd722d67f90313550bb8d7.tar.xz |
Merge pull request #9379
6c28bdb wallet2: move get_rpc_status func to RPC server definition file (j-berman)
-rw-r--r-- | src/rpc/core_rpc_server_commands_defs.h | 13 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 35 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 1 |
3 files changed, 25 insertions, 24 deletions
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 1c33a5446..80c9cc766 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -80,6 +80,19 @@ namespace cryptonote #define CORE_RPC_STATUS_NOT_MINING "NOT MINING" #define CORE_RPC_STATUS_PAYMENT_REQUIRED "PAYMENT REQUIRED" +inline const std::string get_rpc_status(const bool trusted_daemon, const std::string &s) +{ + if (trusted_daemon) + return s; + if (s == CORE_RPC_STATUS_OK) + return s; + if (s == CORE_RPC_STATUS_BUSY) + return s; + if (s == CORE_RPC_STATUS_PAYMENT_REQUIRED) + return s; + return "<error>"; +} + // When making *any* change here, bump minor // If the change is incompatible, then bump major and set minor to 0 // This ensures CORE_RPC_VERSION always increases, that every change diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 769d4bb7b..0f5aaae69 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3111,7 +3111,7 @@ void wallet2::process_pool_info_extent(const cryptonote::COMMAND_RPC_GET_BLOCKS_ { read_pool_txs(req_t, resp_t, r, res.remaining_added_pool_txids, added_pool_txs); if (!r || resp_t.status != CORE_RPC_STATUS_OK) - LOG_PRINT_L0("Error calling gettransactions daemon RPC: r " << r << ", status " << get_rpc_status(resp_t.status)); + LOG_PRINT_L0("Error calling gettransactions daemon RPC: r " << r << ", status " << get_rpc_status(m_trusted_daemon, resp_t.status)); } ); } @@ -3138,7 +3138,7 @@ void wallet2::pull_blocks(bool first, bool try_incremental, uint64_t start_heigh { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = net_utils::invoke_http_bin("/getblocks.bin", req, res, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, res, "getblocks.bin", error::get_blocks_error, get_rpc_status(res.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, res, "getblocks.bin", error::get_blocks_error, get_rpc_status(m_trusted_daemon, res.status)); THROW_WALLET_EXCEPTION_IF(res.blocks.size() != res.output_indices.size(), error::wallet_internal_error, "mismatched blocks (" + boost::lexical_cast<std::string>(res.blocks.size()) + ") and output_indices (" + boost::lexical_cast<std::string>(res.output_indices.size()) + ") sizes from daemon"); @@ -3183,7 +3183,7 @@ void wallet2::pull_hashes(uint64_t start_height, uint64_t &blocks_start_height, { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = net_utils::invoke_http_bin("/gethashes.bin", req, res, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, res, "gethashes.bin", error::get_hashes_error, get_rpc_status(res.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, res, "gethashes.bin", error::get_hashes_error, get_rpc_status(m_trusted_daemon, res.status)); } blocks_start_height = res.start_height; @@ -3702,7 +3702,7 @@ void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction, { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = net_utils::invoke_http_bin("/getblocks.bin", req, res, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, res, "getblocks.bin", error::get_blocks_error, get_rpc_status(res.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, res, "getblocks.bin", error::get_blocks_error, get_rpc_status(m_trusted_daemon, res.status)); } m_pool_info_query_time = res.daemon_time; @@ -3787,7 +3787,7 @@ void wallet2::update_pool_state_by_pool_query(std::vector<std::tuple<cryptonote: { read_pool_txs(req_t, resp_t, r, txids, process_txs); if (!r || resp_t.status != CORE_RPC_STATUS_OK) - LOG_PRINT_L0("Error calling gettransactions daemon RPC: r " << r << ", status " << get_rpc_status(resp_t.status)); + LOG_PRINT_L0("Error calling gettransactions daemon RPC: r " << r << ", status " << get_rpc_status(m_trusted_daemon, resp_t.status)); } ); @@ -7201,7 +7201,7 @@ void wallet2::rescan_spent() { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = epee::net_utils::invoke_http_json("/is_key_image_spent", req, daemon_resp, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, daemon_resp, "is_key_image_spent", error::is_key_image_spent_error, get_rpc_status(daemon_resp.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, daemon_resp, "is_key_image_spent", error::is_key_image_spent_error, get_rpc_status(m_trusted_daemon, daemon_resp.status)); THROW_WALLET_EXCEPTION_IF(daemon_resp.spent_status.size() != n_outputs, error::wallet_internal_error, "daemon returned wrong response for is_key_image_spent, wrong amounts count = " + std::to_string(daemon_resp.spent_status.size()) + ", expected " + std::to_string(n_outputs)); @@ -7531,7 +7531,7 @@ void wallet2::commit_tx(pending_tx& ptx) { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = epee::net_utils::invoke_http_json("/sendrawtransaction", req, daemon_send_resp, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, daemon_send_resp, "sendrawtransaction", error::tx_rejected, ptx.tx, get_rpc_status(daemon_send_resp.status), get_text_reason(daemon_send_resp)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, daemon_send_resp, "sendrawtransaction", error::tx_rejected, ptx.tx, get_rpc_status(m_trusted_daemon, daemon_send_resp.status), get_text_reason(daemon_send_resp)); } // sanity checks @@ -8671,7 +8671,7 @@ uint32_t wallet2::adjust_priority(uint32_t priority) { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = net_utils::invoke_http_json_rpc("/json_rpc", "getblockheadersrange", getbh_req, getbh_res, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, getbh_res, "getblockheadersrange", error::get_blocks_error, get_rpc_status(getbh_res.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, getbh_res, "getblockheadersrange", error::get_blocks_error, get_rpc_status(m_trusted_daemon, getbh_res.status)); } if (getbh_res.headers.size() != N) @@ -9169,7 +9169,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>> { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_output_histogram", req_t, resp_t, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, resp_t, "get_output_histogram", error::get_histogram_error, get_rpc_status(resp_t.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, resp_t, "get_output_histogram", error::get_histogram_error, get_rpc_status(m_trusted_daemon, resp_t.status)); } } @@ -9193,7 +9193,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>> { const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = net_utils::invoke_http_json_rpc("/json_rpc", "get_output_distribution", req_t, resp_t, *m_http_client, rpc_timeout * 1000); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, resp_t, "get_output_distribution", error::get_output_distribution, get_rpc_status(resp_t.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, resp_t, "get_output_distribution", error::get_output_distribution, get_rpc_status(m_trusted_daemon, resp_t.status)); } // check we got all data @@ -9600,7 +9600,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>> const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex}; bool r = epee::net_utils::invoke_http_bin("/get_outs.bin", chunk_req, chunk_daemon_resp, *m_http_client, rpc_timeout); - THROW_ON_RPC_RESPONSE_ERROR(r, {}, chunk_daemon_resp, "get_outs.bin", error::get_outs_error, get_rpc_status(chunk_daemon_resp.status)); + THROW_ON_RPC_RESPONSE_ERROR(r, {}, chunk_daemon_resp, "get_outs.bin", error::get_outs_error, get_rpc_status(m_trusted_daemon, chunk_daemon_resp.status)); THROW_WALLET_EXCEPTION_IF(chunk_daemon_resp.outs.size() != chunk_req.outputs.size(), error::wallet_internal_error, "daemon returned wrong response for get_outs.bin, wrong amounts count = " + std::to_string(chunk_daemon_resp.outs.size()) + ", expected " + std::to_string(chunk_req.outputs.size())); @@ -15126,7 +15126,7 @@ uint64_t wallet2::get_blockchain_height_by_date(uint16_t year, uint8_t month, ui else if (res.status == CORE_RPC_STATUS_BUSY) oss << "daemon is busy"; else - oss << get_rpc_status(res.status); + oss << get_rpc_status(m_trusted_daemon, res.status); throw std::runtime_error(oss.str()); } cryptonote::block blk_min, blk_mid, blk_max; @@ -15328,17 +15328,6 @@ void wallet2::on_device_progress(const hw::device_progress& event) m_callback->on_device_progress(event); } //---------------------------------------------------------------------------------------------------- -std::string wallet2::get_rpc_status(const std::string &s) const -{ - if (m_trusted_daemon) - return s; - if (s == CORE_RPC_STATUS_OK) - return s; - if (s == CORE_RPC_STATUS_BUSY || s == CORE_RPC_STATUS_PAYMENT_REQUIRED) - return s; - return "<error>"; -} -//---------------------------------------------------------------------------------------------------- void wallet2::throw_on_rpc_response_error(bool r, const epee::json_rpc::error &error, const std::string &status, const char *method) const { // Treat all RPC payment access errors the same, whether payment is actually required or not diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index e86ea0c79..e2ccdf9da 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1911,7 +1911,6 @@ private: boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device); void on_device_progress(const hw::device_progress& event); - std::string get_rpc_status(const std::string &s) const; void throw_on_rpc_response_error(bool r, const epee::json_rpc::error &error, const std::string &status, const char *method) const; bool should_expand(const cryptonote::subaddress_index &index) const; |