diff options
Diffstat (limited to 'src')
-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 c634b8957..def1f3804 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 9b09d0920..64868153e 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3029,7 +3029,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)); } ); } @@ -3056,7 +3056,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"); @@ -3101,7 +3101,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; @@ -3602,7 +3602,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; @@ -3687,7 +3687,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)); } ); @@ -6688,7 +6688,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)); @@ -7018,7 +7018,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 @@ -8158,7 +8158,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) @@ -8628,7 +8628,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)); } } @@ -8652,7 +8652,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 @@ -9059,7 +9059,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())); @@ -14178,7 +14178,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; @@ -14380,17 +14380,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 5f2f0e0c4..a89d2b856 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1771,7 +1771,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; |