forked from lthn/blockchain
wallet: minor refactoring for tx_too_big and other for clearness
This commit is contained in:
parent
712f66d3ee
commit
fe98c140ac
3 changed files with 25 additions and 60 deletions
|
|
@ -87,9 +87,7 @@ namespace ph = boost::placeholders;
|
|||
} \
|
||||
catch (const tools::error::tx_too_big& e) \
|
||||
{ \
|
||||
currency::transaction tx = e.tx(); \
|
||||
fail_msg_writer() << "transaction " << get_transaction_hash(e.tx()) << " is too big. Transaction size: " << \
|
||||
get_object_blobsize(e.tx()) << " bytes, transaction size limit: " << e.tx_size_limit() << " bytes. Try to separate this payment into few smaller transfers."; \
|
||||
fail_msg_writer() << "transaction is too big. " << e.get_message() << " Try to split this payment into a few smaller transfers."; \
|
||||
} \
|
||||
catch (const tools::error::zero_destination&) \
|
||||
{ \
|
||||
|
|
|
|||
|
|
@ -6265,7 +6265,7 @@ bool wallet2::accept_ionic_swap_proposal(const wallet_public::ionic_swap_proposa
|
|||
{
|
||||
if (balances[item.asset_id].unlocked < item.amount)
|
||||
{
|
||||
WLT_THROW_IF_FALSE_WALLET_EX_MES(false, error::not_enough_money, "", balances[item.asset_id].unlocked, item.amount, 0 /*fee*/, item.asset_id, get_asset_decimal_point(item.asset_id));
|
||||
THROW_IF_FALSE_WALLET_EX(false, error::not_enough_money, balances[item.asset_id].unlocked, item.amount, 0 /*fee*/, item.asset_id, get_asset_decimal_point(item.asset_id));
|
||||
}
|
||||
if (item.asset_id == currency::native_coin_asset_id)
|
||||
{
|
||||
|
|
@ -6280,7 +6280,7 @@ bool wallet2::accept_ionic_swap_proposal(const wallet_public::ionic_swap_proposa
|
|||
additional_fee = m_core_runtime_config.tx_default_fee - msc.proposal_info.fee_paid_by_a;
|
||||
if (balances[currency::native_coin_asset_id].unlocked < additional_fee + native_amount_required)
|
||||
{
|
||||
WLT_THROW_IF_FALSE_WALLET_EX_MES(false, error::not_enough_money, "", balances[currency::native_coin_asset_id].unlocked, native_amount_required, additional_fee, currency::native_coin_asset_id);
|
||||
THROW_IF_FALSE_WALLET_EX(false, error::not_enough_money, balances[currency::native_coin_asset_id].unlocked, native_amount_required, additional_fee, currency::native_coin_asset_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -7128,9 +7128,9 @@ bool wallet2::select_indices_for_transfer(assets_selection_context& needed_money
|
|||
WLT_LOG_L1("select_indices_for_transfer: unknown asset id: " << asset_id);
|
||||
|
||||
auto asset_cache_it = m_found_free_amounts.find(asset_id);
|
||||
WLT_THROW_IF_FALSE_WALLET_EX_MES(asset_cache_it != m_found_free_amounts.end(), error::not_enough_money, "", item.second.found_amount, item.second.needed_amount, 0, asset_id, asset_info.decimal_point);
|
||||
THROW_IF_FALSE_WALLET_EX(asset_cache_it != m_found_free_amounts.end(), error::not_enough_money, item.second.found_amount, item.second.needed_amount, (uint64_t)0, asset_id, asset_info.decimal_point);
|
||||
item.second.found_amount = select_indices_for_transfer(selected_indexes, asset_cache_it->second, item.second.needed_amount, fake_outputs_count, asset_id, asset_info.decimal_point);
|
||||
WLT_THROW_IF_FALSE_WALLET_EX_MES(item.second.found_amount >= item.second.needed_amount, error::not_enough_money, "", item.second.found_amount, item.second.needed_amount, 0, asset_id, asset_info.decimal_point);
|
||||
THROW_IF_FALSE_WALLET_EX(item.second.found_amount >= item.second.needed_amount, error::not_enough_money, item.second.found_amount, item.second.needed_amount, (uint64_t)0, asset_id, asset_info.decimal_point);
|
||||
}
|
||||
if (m_current_context.pconstruct_tx_param && m_current_context.pconstruct_tx_param->need_at_least_1_zc)
|
||||
{
|
||||
|
|
@ -7661,12 +7661,14 @@ void wallet2::finalize_transaction(currency::finalize_tx_param& ftp, currency::f
|
|||
// broadcasting tx without secret key storing is forbidden to avoid lost key issues
|
||||
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(!broadcast_tx || store_tx_secret_key, "finalize_tx is requested to broadcast a tx without storing the key");
|
||||
|
||||
THROW_IF_FALSE_WALLET_EX_MES(ftp.sources.size() <= CURRENCY_TX_MAX_ALLOWED_INPUTS, error::tx_too_big, "Too many inputs: " << ftp.sources.size() << ", maximum allowed is " << CURRENCY_TX_MAX_ALLOWED_INPUTS << ".");
|
||||
|
||||
bool r = currency::construct_tx(m_account.get_keys(),
|
||||
ftp, result);
|
||||
//TIME_MEASURE_FINISH_MS(construct_tx_time);
|
||||
THROW_IF_FALSE_WALLET_EX(r, error::tx_not_constructed, ftp.sources, ftp.prepared_destinations, ftp.unlock_time);
|
||||
uint64_t effective_fee = 0;
|
||||
THROW_IF_FALSE_WALLET_CMN_ERR_EX(!get_tx_fee(result.tx, effective_fee) || effective_fee <= WALLET_TX_MAX_ALLOWED_FEE, "tx fee is WAY too big: " << print_money_brief(effective_fee) << ", max allowed is " << print_money_brief(WALLET_TX_MAX_ALLOWED_FEE));
|
||||
THROW_IF_FALSE_WALLET_CMN_ERR_EX(!get_tx_fee(result.tx, effective_fee) || effective_fee <= WALLET_TX_MAX_ALLOWED_FEE, "tx fee is WAY too big: " << print_money_brief(effective_fee) << ", maximum allowed is " << print_money_brief(WALLET_TX_MAX_ALLOWED_FEE) << ".");
|
||||
|
||||
//TIME_MEASURE_START_MS(sign_ms_input_time);
|
||||
if (ftp.multisig_id != currency::null_hash)
|
||||
|
|
@ -7683,7 +7685,7 @@ void wallet2::finalize_transaction(currency::finalize_tx_param& ftp, currency::f
|
|||
//TIME_MEASURE_FINISH_MS(sign_ms_input_time);
|
||||
|
||||
size_t tx_blob_size = tx_to_blob(result.tx).size();
|
||||
THROW_IF_FALSE_WALLET_EX(tx_blob_size < CURRENCY_MAX_TRANSACTION_BLOB_SIZE, error::tx_too_big, result.tx, m_upper_transaction_size_limit);
|
||||
THROW_IF_FALSE_WALLET_EX_MES(tx_blob_size < CURRENCY_MAX_TRANSACTION_BLOB_SIZE, error::tx_too_big, "Transaction size: " << tx_blob_size << " bytes, transaction size limit: " << CURRENCY_MAX_TRANSACTION_BLOB_SIZE << " bytes.");
|
||||
|
||||
if (store_tx_secret_key)
|
||||
m_tx_keys.insert(std::make_pair(get_transaction_hash(result.tx), result.one_time_key));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2024 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor Project
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
|
|
@ -350,7 +350,7 @@ namespace tools
|
|||
//----------------------------------------------------------------------------------------------------
|
||||
struct not_enough_money : public transfer_error
|
||||
{
|
||||
not_enough_money(std::string&& loc, uint64_t availbable, uint64_t tx_amount, uint64_t fee, const crypto::public_key& asset_id, size_t decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT)
|
||||
not_enough_money(std::string&& loc, uint64_t availbable, uint64_t tx_amount, uint64_t fee, const crypto::public_key& asset_id, uint8_t decimal_point = CURRENCY_DISPLAY_DECIMAL_POINT)
|
||||
: transfer_error(std::move(loc), "")
|
||||
, m_available(availbable)
|
||||
, m_tx_amount(tx_amount)
|
||||
|
|
@ -381,12 +381,13 @@ namespace tools
|
|||
uint64_t m_tx_amount;
|
||||
uint64_t m_fee;
|
||||
crypto::public_key m_asset_id;
|
||||
size_t m_decimal_point;
|
||||
uint8_t m_decimal_point;
|
||||
};
|
||||
|
||||
struct no_zc_inputs : public transfer_error
|
||||
{
|
||||
no_zc_inputs(const std::string& /*v*/): transfer_error(std::string(""), API_RETURN_CODE_MISSING_ZC_INPUTS)
|
||||
no_zc_inputs(std::string&& loc, const std::string&)
|
||||
: transfer_error(std::move(loc), API_RETURN_CODE_MISSING_ZC_INPUTS)
|
||||
{}
|
||||
|
||||
virtual const char* what() const noexcept
|
||||
|
|
@ -566,34 +567,25 @@ namespace tools
|
|||
//----------------------------------------------------------------------------------------------------
|
||||
struct tx_too_big : public transfer_error
|
||||
{
|
||||
explicit tx_too_big(std::string&& loc, const currency::transaction& tx, uint64_t tx_size_limit)
|
||||
: transfer_error(std::move(loc), "transaction is too big")
|
||||
, m_tx(tx)
|
||||
, m_tx_size_limit(tx_size_limit)
|
||||
explicit tx_too_big(std::string&& loc, const std::string& message)
|
||||
: transfer_error(std::move(loc), API_RETURN_CODE_TX_IS_TOO_BIG)
|
||||
, m_message(message)
|
||||
{
|
||||
}
|
||||
|
||||
const currency::transaction& tx() const { return m_tx; }
|
||||
uint64_t tx_size_limit() const { return m_tx_size_limit; }
|
||||
const std::string get_message() const { return m_message; }
|
||||
|
||||
// TODO the following overrides need to be redesigned (seems to be necessary for API, consider writing API tests and then refactor this) -- sowle
|
||||
std::string to_string() const
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss << API_RETURN_CODE_TX_IS_TOO_BIG;
|
||||
//currency::transaction tx = m_tx;
|
||||
//ss << transfer_error::to_string() <<
|
||||
// ", tx_size_limit = " << m_tx_size_limit <<
|
||||
// ", tx size = " << get_object_blobsize(m_tx) <<
|
||||
// ", tx:\n" << currency::obj_to_json_str(tx);
|
||||
return ss.str();
|
||||
return API_RETURN_CODE_TX_IS_TOO_BIG;
|
||||
}
|
||||
virtual const char* what() const noexcept
|
||||
{
|
||||
return API_RETURN_CODE_TX_IS_TOO_BIG;
|
||||
}
|
||||
private:
|
||||
currency::transaction m_tx;
|
||||
uint64_t m_tx_size_limit;
|
||||
std::string m_message;
|
||||
};
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
struct zero_destination : public transfer_error
|
||||
|
|
@ -668,8 +660,6 @@ namespace tools
|
|||
};
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
#if !defined(_MSC_VER)
|
||||
|
||||
template<typename TException, typename... TArgs>
|
||||
void throw_wallet_ex(std::string&& loc, const TArgs&... args)
|
||||
{
|
||||
|
|
@ -677,31 +667,6 @@ namespace tools
|
|||
LOG_PRINT_L0(e.to_string());
|
||||
throw e;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
|
||||
|
||||
template<typename TException>
|
||||
void throw_wallet_ex(std::string&& loc)
|
||||
{
|
||||
TException e(std::move(loc));
|
||||
LOG_PRINT_L0(e.to_string());
|
||||
throw e;
|
||||
}
|
||||
|
||||
#define GEN_throw_wallet_ex(z, n, data) \
|
||||
template<typename TException, BOOST_PP_ENUM_PARAMS(n, typename TArg)> \
|
||||
void throw_wallet_ex(std::string&& loc, BOOST_PP_ENUM_BINARY_PARAMS(n, const TArg, &arg)) \
|
||||
{ \
|
||||
TException e(std::move(loc), BOOST_PP_ENUM_PARAMS(n, arg)); \
|
||||
LOG_PRINT_L0(e.to_string()); \
|
||||
throw e; \
|
||||
}
|
||||
|
||||
BOOST_PP_REPEAT_FROM_TO(1, 6, GEN_throw_wallet_ex, ~)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -739,14 +704,14 @@ if (!(cond))
|
|||
}
|
||||
|
||||
|
||||
#define THROW_IF_FALSE_WALLET_EX_MES(cond, err_type, mess, ...) \
|
||||
#define THROW_IF_FALSE_WALLET_EX_MES(cond, err_type, mes, ...) \
|
||||
if (!(cond)) \
|
||||
{ \
|
||||
exception_handler(); \
|
||||
std::stringstream ss; \
|
||||
ss << std::endl << mess; \
|
||||
LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type); \
|
||||
tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)) + ss.str(), ## __VA_ARGS__); \
|
||||
ss << mes; \
|
||||
LOG_ERROR(#cond << ". THROW EXCEPTION: " << #err_type << " : " << ss.str()); \
|
||||
tools::error::throw_wallet_ex<err_type>(std::string(__FILE__ ":" STRINGIZE(__LINE__)), ss.str(), ## __VA_ARGS__); \
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue