Merge pull request #190 from peerplays-network/feature/BLOCKBACK-162

[BLOCKBACK-162] Error message correction
This commit is contained in:
Alfredo Garcia 2019-10-25 07:04:01 -03:00 committed by GitHub
commit ed49ab8eea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 14 deletions

View file

@ -28,6 +28,16 @@ namespace graphene { namespace chain {
enum class vesting_balance_type { normal, gpos };
inline std::string get_vesting_balance_type(vesting_balance_type type) {
switch (type) {
case vesting_balance_type::normal:
return "NORMAL";
case vesting_balance_type::gpos:
default:
return "GPOS";
}
}
struct linear_vesting_policy_initializer
{
/** while vesting begins on begin_timestamp, none may be claimed before vesting_cliff_seconds have passed */

View file

@ -145,7 +145,8 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan
const vesting_balance_object& vbo = op.vesting_balance( d );
FC_ASSERT( op.owner == vbo.owner, "", ("op.owner", op.owner)("vbo.owner", vbo.owner) );
FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "", ("now", now)("op", op)("vbo", vbo) );
FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "${balance_type} Vested Balance cannont be withdrwan during the locking period",
("balance_type", get_vesting_balance_type(vbo.balance_type))("now", now)("op", op)("vbo", vbo) );
assert( op.amount <= vbo.balance ); // is_withdraw_allowed should fail before this check is reached
/* const account_object& owner_account = op.owner( d ); */

View file

@ -1265,6 +1265,12 @@ class wallet_api
*/
witness_object get_witness(string owner_account);
/** Returns true if the account is witness, false otherwise
* @param owner_account the name or id of the witness account owner, or the id of the witness
* @returns true if account is witness, false otherwise
*/
bool is_witness(string owner_account);
/** Returns information about the given committee_member.
* @param owner_account the name or id of the committee_member account owner, or the id of the committee_member
* @returns the information about the committee_member stored in the block chain
@ -1969,6 +1975,7 @@ FC_API( graphene::wallet::wallet_api,
(whitelist_account)
(create_committee_member)
(get_witness)
(is_witness)
(get_committee_member)
(list_witnesses)
(list_committee_members)

View file

@ -1720,6 +1720,42 @@ public:
FC_CAPTURE_AND_RETHROW( (owner_account) )
}
bool is_witness(string owner_account)
{
try
{
fc::optional<witness_id_type> witness_id = maybe_id<witness_id_type>(owner_account);
if (witness_id)
{
std::vector<witness_id_type> ids_to_get;
ids_to_get.push_back(*witness_id);
std::vector<fc::optional<witness_object>> witness_objects = _remote_db->get_witnesses(ids_to_get);
if (witness_objects.front())
return true;
else
return false;
}
else
{
// then maybe it's the owner account
try
{
account_id_type owner_account_id = get_account_id(owner_account);
fc::optional<witness_object> witness = _remote_db->get_witness_by_account(owner_account_id);
if (witness)
return true;
else
return false;
}
catch (const fc::exception&)
{
return false;
}
}
}
FC_CAPTURE_AND_RETHROW( (owner_account) )
}
committee_member_object get_committee_member(string owner_account)
{
try
@ -1969,9 +2005,14 @@ public:
fc::optional<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(witness_name);
if( !vbid )
{
witness_object wit = get_witness( witness_name );
FC_ASSERT( wit.pay_vb );
vbid = wit.pay_vb;
if (is_witness(witness_name))
{
witness_object wit = get_witness( witness_name );
FC_ASSERT( wit.pay_vb, "Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", witness_name));
vbid = wit.pay_vb;
}
else
FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", witness_name));
}
vesting_balance_object vbo = get_object< vesting_balance_object >( *vbid );
@ -2011,12 +2052,8 @@ public:
acct_id = get_account( account_name ).id;
vbos = _remote_db->get_vesting_balances( *acct_id );
if( vbos.size() == 0 )
{
witness_object wit = get_witness( account_name );
FC_ASSERT( wit.pay_vb );
vbid = wit.pay_vb;
}
if( vbos.size() == 0 )
FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name));
}
//whether it is a witness or user, keep it in a container and iterate over to process all vesting balances and types
@ -2080,7 +2117,7 @@ public:
vbo_iter = std::find_if(vbo_info.begin(), vbo_info.end(), [](vesting_balance_object_with_info const& obj){return obj.balance_type == vesting_balance_type::gpos;});
if( vbo_info.size() == 0 || vbo_iter == vbo_info.end())
FC_THROW("Account *** ${account} *** have insufficient or 0 vested balance(GPOS) to vote", ("account", voting_account));
FC_THROW("Account ${account} has no core Token vested and thus she will not be allowed to vote for the committee member", ("account", voting_account));
account_object voting_account_object = get_account(voting_account);
account_id_type committee_member_owner_account_id = get_account_id(committee_member);
@ -2121,7 +2158,7 @@ public:
vbo_iter = std::find_if(vbo_info.begin(), vbo_info.end(), [](vesting_balance_object_with_info const& obj){return obj.balance_type == vesting_balance_type::gpos;});
if( vbo_info.size() == 0 || vbo_iter == vbo_info.end())
FC_THROW("Account *** ${account} *** have insufficient or 0 vested balance(GPOS) to vote", ("account", voting_account));
FC_THROW("Account ${account} has no core Token vested and thus she will not be allowed to vote for the witness", ("account", voting_account));
account_object voting_account_object = get_account(voting_account);
account_id_type witness_owner_account_id = get_account_id(witness);
@ -2132,13 +2169,13 @@ public:
{
auto insert_result = voting_account_object.options.votes.insert(witness_obj->vote_id);
if (!insert_result.second)
FC_THROW("Account ${account} was already voting for witness ${witness}", ("account", voting_account)("witness", witness));
FC_THROW("Account ${account} has already voted for witness ${witness}", ("account", voting_account)("witness", witness));
}
else
{
unsigned votes_removed = voting_account_object.options.votes.erase(witness_obj->vote_id);
if (!votes_removed)
FC_THROW("Account ${account} is already not voting for witness ${witness}", ("account", voting_account)("witness", witness));
FC_THROW("Account ${account} has not voted for witness ${witness}", ("account", voting_account)("witness", witness));
}
account_update_operation account_update_op;
account_update_op.account = voting_account_object.id;
@ -4073,6 +4110,11 @@ witness_object wallet_api::get_witness(string owner_account)
return my->get_witness(owner_account);
}
bool wallet_api::is_witness(string owner_account)
{
return my->is_witness(owner_account);
}
committee_member_object wallet_api::get_committee_member(string owner_account)
{
return my->get_committee_member(owner_account);