mirror of
https://github.com/monero-project/monero.git
synced 2024-12-26 10:09:26 -05:00
wallet2: move wallet error on RPC resp handling to wallet_errors file
Co-authored-by: jeffro256 <jeffro256@tutanota.com>
This commit is contained in:
parent
893916ad09
commit
e866a192dd
@ -15328,22 +15328,6 @@ void wallet2::on_device_progress(const hw::device_progress& event)
|
|||||||
m_callback->on_device_progress(event);
|
m_callback->on_device_progress(event);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
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
|
|
||||||
THROW_WALLET_EXCEPTION_IF(error.code == CORE_RPC_ERROR_CODE_INVALID_CLIENT, tools::error::deprecated_rpc_access, method);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(error.code, tools::error::wallet_coded_rpc_error, method, error.code, get_rpc_server_error_message(error.code));
|
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, tools::error::no_connection_to_daemon, method);
|
|
||||||
// empty string -> not connection
|
|
||||||
THROW_WALLET_EXCEPTION_IF(status.empty(), tools::error::no_connection_to_daemon, method);
|
|
||||||
|
|
||||||
THROW_WALLET_EXCEPTION_IF(status == CORE_RPC_STATUS_BUSY, tools::error::daemon_busy, method);
|
|
||||||
THROW_WALLET_EXCEPTION_IF(status == CORE_RPC_STATUS_PAYMENT_REQUIRED, tools::error::deprecated_rpc_access, method);
|
|
||||||
// Deprecated RPC payment access endpoints would set status to "Client signature does not verify for <method>"
|
|
||||||
THROW_WALLET_EXCEPTION_IF(status.compare(0, 16, "Client signature") == 0, tools::error::deprecated_rpc_access, method);
|
|
||||||
}
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool wallet2::save_to_file(const std::string& path_to_file, const std::string& raw, bool is_printable) const
|
bool wallet2::save_to_file(const std::string& path_to_file, const std::string& raw, bool is_printable) const
|
||||||
{
|
{
|
||||||
if (is_printable || m_export_format == ExportFormat::Binary)
|
if (is_printable || m_export_format == ExportFormat::Binary)
|
||||||
|
@ -75,15 +75,6 @@
|
|||||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||||
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
|
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
|
||||||
|
|
||||||
#define THROW_ON_RPC_RESPONSE_ERROR(r, error, res, method, ...) \
|
|
||||||
do { \
|
|
||||||
throw_on_rpc_response_error(r, error, res.status, method); \
|
|
||||||
THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, ## __VA_ARGS__); \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
#define THROW_ON_RPC_RESPONSE_ERROR_GENERIC(r, err, res, method) \
|
|
||||||
THROW_ON_RPC_RESPONSE_ERROR(r, err, res, method, tools::error::wallet_generic_rpc_error, method, res.status)
|
|
||||||
|
|
||||||
class Serialization_portability_wallet_Test;
|
class Serialization_portability_wallet_Test;
|
||||||
class wallet_accessor_test;
|
class wallet_accessor_test;
|
||||||
namespace multisig { class multisig_account; }
|
namespace multisig { class multisig_account; }
|
||||||
@ -1911,8 +1902,6 @@ private:
|
|||||||
boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device);
|
boost::optional<epee::wipeable_string> on_device_passphrase_request(bool & on_device);
|
||||||
void on_device_progress(const hw::device_progress& event);
|
void on_device_progress(const hw::device_progress& event);
|
||||||
|
|
||||||
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;
|
bool should_expand(const cryptonote::subaddress_index &index) const;
|
||||||
bool spends_one_of_ours(const cryptonote::transaction &tx) const;
|
bool spends_one_of_ours(const cryptonote::transaction &tx) const;
|
||||||
|
|
||||||
|
@ -37,7 +37,9 @@
|
|||||||
|
|
||||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||||
#include "cryptonote_core/cryptonote_tx_utils.h"
|
#include "cryptonote_core/cryptonote_tx_utils.h"
|
||||||
|
#include "net/jsonrpc_structs.h"
|
||||||
#include "rpc/core_rpc_server_commands_defs.h"
|
#include "rpc/core_rpc_server_commands_defs.h"
|
||||||
|
#include "rpc/core_rpc_server_error_codes.h"
|
||||||
#include "include_base_utils.h"
|
#include "include_base_utils.h"
|
||||||
|
|
||||||
|
|
||||||
@ -1040,3 +1042,33 @@ namespace tools
|
|||||||
LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \
|
LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \
|
||||||
tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
|
tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ## __VA_ARGS__); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace tools
|
||||||
|
{
|
||||||
|
namespace error
|
||||||
|
{
|
||||||
|
inline void throw_on_rpc_response_error(bool r, const epee::json_rpc::error &error, const std::string &status, const char *method)
|
||||||
|
{
|
||||||
|
// Treat all RPC payment access errors the same, whether payment is actually required or not
|
||||||
|
THROW_WALLET_EXCEPTION_IF(error.code == CORE_RPC_ERROR_CODE_INVALID_CLIENT, tools::error::deprecated_rpc_access, method);
|
||||||
|
THROW_WALLET_EXCEPTION_IF(error.code, tools::error::wallet_coded_rpc_error, method, error.code, get_rpc_server_error_message(error.code));
|
||||||
|
THROW_WALLET_EXCEPTION_IF(!r, tools::error::no_connection_to_daemon, method);
|
||||||
|
// empty string -> not connection
|
||||||
|
THROW_WALLET_EXCEPTION_IF(status.empty(), tools::error::no_connection_to_daemon, method);
|
||||||
|
|
||||||
|
THROW_WALLET_EXCEPTION_IF(status == CORE_RPC_STATUS_BUSY, tools::error::daemon_busy, method);
|
||||||
|
THROW_WALLET_EXCEPTION_IF(status == CORE_RPC_STATUS_PAYMENT_REQUIRED, tools::error::deprecated_rpc_access, method);
|
||||||
|
// Deprecated RPC payment access endpoints would set status to "Client signature does not verify for <method>"
|
||||||
|
THROW_WALLET_EXCEPTION_IF(status.compare(0, 16, "Client signature") == 0, tools::error::deprecated_rpc_access, method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define THROW_ON_RPC_RESPONSE_ERROR(r, err, res, method, ...) \
|
||||||
|
do { \
|
||||||
|
tools::error::throw_on_rpc_response_error(r, err, res.status, method); \
|
||||||
|
THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, ## __VA_ARGS__); \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
#define THROW_ON_RPC_RESPONSE_ERROR_GENERIC(r, err, res, method) \
|
||||||
|
THROW_ON_RPC_RESPONSE_ERROR(r, err, res, method, tools::error::wallet_generic_rpc_error, method, res.status)
|
||||||
|
Loading…
Reference in New Issue
Block a user