#319 FC_ASSERT instead of FC_THROW

This commit is contained in:
Vlad Dobromyslov 2022-03-16 19:29:44 +03:00
parent f98fb375cc
commit 43cfcd07b2
3 changed files with 10 additions and 17 deletions

View file

@ -92,8 +92,7 @@ vector<std::reference_wrapper<const son_object>> database::sort_votable_objects<
count = std::min(count, refs.size());
std::partial_sort(refs.begin(), refs.begin() + count, refs.end(),
[this, sidechain](const son_object& a, const son_object& b)->bool {
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
FC_THROW("Unexpected sidechain type");
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
const share_type oa_vote = _vote_tally_buffer[a.get_sidechain_vote_id(sidechain)];
const share_type ob_vote = _vote_tally_buffer[b.get_sidechain_vote_id(sidechain)];

View file

@ -15,9 +15,7 @@ inline size_t sidechain_type_to_size_t(sidechain_type sidechain){ return static_
inline sidechain_type size_t_to_sidechain_type(size_t sidechain)
{
if(sidechain >= static_cast<size_t>(sidechain_type::SIDECHAIN_TYPE_COUNT))
FC_THROW("Wrong sidechain_type: ${sidechain}", ("sidechain", sidechain));
FC_ASSERT(sidechain < static_cast<size_t>(sidechain_type::SIDECHAIN_TYPE_COUNT), "Wrong sidechain_type: ${sidechain}", ("sidechain", sidechain));
return static_cast<sidechain_type>(sidechain);
}

View file

@ -2757,10 +2757,8 @@ public:
account_object voting_account_object = get_account(voting_account);
account_id_type son_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_account_id);
if (!son_obj)
FC_THROW("Account ${son} is not registered as a son", ("son", son));
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
FC_THROW("Unexpected sidechain type");
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
if (approve)
{
@ -2805,10 +2803,9 @@ public:
{
account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
if (!son_obj)
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
FC_THROW("Unexpected sidechain type");
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
auto insert_result = voting_account_object.options.votes.insert(son_obj->get_sidechain_vote_id(sidechain));
if (!insert_result.second)
FC_THROW("Account ${account} was already voting for SON ${son}", ("account", voting_account)("son", son));
@ -2817,10 +2814,9 @@ public:
{
account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
if (!son_obj)
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
if(sidechain != sidechain_type::bitcoin && sidechain != sidechain_type::hive)
FC_THROW("Unexpected sidechain type");
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->get_sidechain_vote_id(sidechain));
if (!votes_removed)
FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son));