1
0
Fork 0
forked from lthn/blockchain

wallet: improved error handling for accept_ionic_swap_proposal (+ overall error handling for wallet)

This commit is contained in:
sowle 2023-10-06 20:58:17 +02:00
parent 21718b01b9
commit d33cfe7259
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
3 changed files with 11 additions and 12 deletions

View file

@ -62,9 +62,7 @@ namespace ph = boost::placeholders;
} \
catch (const tools::error::not_enough_money& e) \
{ \
fail_msg_writer() << "not enough money to transfer, available only " << print_money(e.available()) << \
", transaction amount " << print_money(e.tx_amount() + e.fee()) << " = " << print_money(e.tx_amount()) << \
" + " << print_money(e.fee()) << " (fee)"; \
fail_msg_writer() << "not enough money to transfer, " << e.to_string(); \
} \
catch (const tools::error::not_enough_outs_to_mix& e) \
{ \

View file

@ -5603,7 +5603,7 @@ bool wallet2::accept_ionic_swap_proposal(const wallet_public::ionic_swap_proposa
{
if (balances[item.asset_id].unlocked < item.amount)
{
return false;
WLT_THROW_IF_FALSE_WALLET_EX_MES(false, error::not_enough_money, "", balances[item.asset_id].unlocked, item.amount, 0 /*fee*/, item.asset_id);
}
if (item.asset_id == currency::native_coin_asset_id)
{
@ -5618,7 +5618,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)
{
return false;
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);
}
}

View file

@ -9,6 +9,7 @@
#include <stdexcept>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>
#include "currency_core/currency_format_utils.h"
#include "rpc/core_rpc_server_commands_defs.h"
@ -70,10 +71,10 @@ namespace tools
std::string to_string() const
{
std::ostringstream ss;
ss << m_loc << ':' << typeid(*this).name();
ss << m_loc << '[' << boost::replace_all_copy(std::string(typeid(*this).name()), "struct ", "");
if (!m_error_code.empty())
ss << "[" << m_error_code << "]";
ss << ": " << Base::what();
ss << "] " << Base::what();
return ss.str();
}
@ -350,7 +351,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)
: transfer_error(std::move(loc), "NOT_ENOUGH_MONEY")
: transfer_error(std::move(loc), "")
, m_available(availbable)
, m_tx_amount(tx_amount)
, m_fee(fee)
@ -366,11 +367,11 @@ namespace tools
{
std::ostringstream ss;
ss << transfer_error::to_string() <<
", available = " << currency::print_money(m_available) <<
", tx_amount = " << currency::print_money(m_tx_amount) <<
", fee = " << currency::print_money(m_fee);
"available: " << currency::print_money_brief(m_available) <<
", required: " << currency::print_money_brief(m_tx_amount + m_fee) <<
" = " << currency::print_money_brief(m_tx_amount) << " + " << currency::print_money_brief(m_fee) << " (fee)";
if (m_asset_id != currency::native_coin_asset_id)
ss << ", asset_id = " << m_asset_id;
ss << ", asset_id: " << m_asset_id;
return ss.str();
}