forked from lthn/blockchain
fixed select_indices_for_transfer() + several improvements to decimal_point=0 support
This commit is contained in:
parent
8aa1654a3f
commit
3154c7b72d
5 changed files with 17 additions and 10 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
// Copyright (c) 2024, Zano Project
|
||||||
// Copyright (c) 2006-2017, Andrey N. Sabelnikov, www.sabelnikov.net
|
// Copyright (c) 2006-2017, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
@ -39,7 +40,8 @@ namespace epee
|
||||||
{
|
{
|
||||||
s.insert(0, decimal_point + 1 - s.size(), '0');
|
s.insert(0, decimal_point + 1 - s.size(), '0');
|
||||||
}
|
}
|
||||||
s.insert(s.size() - decimal_point, ".");
|
if (decimal_point > 0)
|
||||||
|
s.insert(s.size() - decimal_point, ".");
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -700,7 +700,7 @@ namespace currency
|
||||||
{
|
{
|
||||||
uint64_t total_max_supply = 0;
|
uint64_t total_max_supply = 0;
|
||||||
uint64_t current_supply = 0;
|
uint64_t current_supply = 0;
|
||||||
uint8_t decimal_point = 12;
|
uint8_t decimal_point = 0;
|
||||||
std::string ticker;
|
std::string ticker;
|
||||||
std::string full_name;
|
std::string full_name;
|
||||||
std::string meta_info;
|
std::string meta_info;
|
||||||
|
|
|
||||||
|
|
@ -3467,7 +3467,7 @@ namespace currency
|
||||||
uint64_t remainder = amount % coin;
|
uint64_t remainder = amount % coin;
|
||||||
amount /= coin;
|
amount /= coin;
|
||||||
if (remainder == 0)
|
if (remainder == 0)
|
||||||
return std::to_string(amount) + ".0";
|
return std::to_string(amount) + (decimal_point > 0 ? ".0" : "");
|
||||||
std::string r = std::to_string(remainder);
|
std::string r = std::to_string(remainder);
|
||||||
if (r.size() < decimal_point)
|
if (r.size() < decimal_point)
|
||||||
r.insert(0, decimal_point - r.size(), '0');
|
r.insert(0, decimal_point - r.size(), '0');
|
||||||
|
|
|
||||||
|
|
@ -610,20 +610,25 @@ namespace currency
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// outputs "1391306.970000000000"
|
// outputs "1391306.970000000000" (decimal_point = 12)
|
||||||
|
// outputs "1391306970000000000" (decimal_point = 0)
|
||||||
template<typename t_number>
|
template<typename t_number>
|
||||||
std::string print_fixed_decimal_point(t_number amount, size_t decimal_point)
|
std::string print_fixed_decimal_point(t_number amount, size_t decimal_point)
|
||||||
{
|
{
|
||||||
return epee::string_tools::print_fixed_decimal_point(amount, decimal_point);
|
return epee::string_tools::print_fixed_decimal_point(amount, decimal_point);
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// outputs "1391306.97 "
|
// outputs "1391306.97 " (decimal_point = 12)
|
||||||
|
// outputs "139130697 " (decimal_point = 0)
|
||||||
template<typename t_number>
|
template<typename t_number>
|
||||||
std::string print_fixed_decimal_point_with_trailing_spaces(t_number amount, size_t decimal_point)
|
std::string print_fixed_decimal_point_with_trailing_spaces(t_number amount, size_t decimal_point)
|
||||||
{
|
{
|
||||||
std::string s = epee::string_tools::print_fixed_decimal_point(amount, decimal_point);
|
std::string s = epee::string_tools::print_fixed_decimal_point(amount, decimal_point);
|
||||||
for(size_t n = s.size() - 1; n != 0 && s[n] == '0' && s[n-1] != '.'; --n)
|
if (s.find('.') != std::string::npos)
|
||||||
s[n] = ' ';
|
{
|
||||||
|
for(size_t n = s.size() - 1; n != 0 && s[n] == '0' && s[n-1] != '.'; --n)
|
||||||
|
s[n] = ' ';
|
||||||
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -3870,7 +3870,7 @@ size_t wallet2::get_asset_decimal_point(const crypto::public_key& asset_id) cons
|
||||||
if (it_own != m_own_asset_descriptors.end())
|
if (it_own != m_own_asset_descriptors.end())
|
||||||
return it_own->second.decimal_point;
|
return it_own->second.decimal_point;
|
||||||
|
|
||||||
return CURRENCY_DISPLAY_DECIMAL_POINT; // fallback to the default
|
return 0; // fallback to the 0 decimal point (raw numbers) as the default
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -7086,8 +7086,8 @@ bool wallet2::select_indices_for_transfer(assets_selection_context& needed_money
|
||||||
const crypto::public_key asset_id = item.first;
|
const crypto::public_key asset_id = item.first;
|
||||||
asset_descriptor_base asset_info{};
|
asset_descriptor_base asset_info{};
|
||||||
uint32_t asset_flags = 0;
|
uint32_t asset_flags = 0;
|
||||||
bool r = get_asset_info(asset_id, asset_info, asset_flags);
|
if (!get_asset_info(asset_id, asset_info, asset_flags))
|
||||||
WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(r, "got unknown asset id: " << asset_id);
|
WLT_LOG_L1("select_indices_for_transfer: unknown asset id: " << asset_id);
|
||||||
|
|
||||||
auto asset_cache_it = m_found_free_amounts.find(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);
|
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);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue