From c025f639d7e9f3479438dde8be217f762ec6ac67 Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Sat, 19 Oct 2019 10:58:56 +0530 Subject: [PATCH 1/3] Fixed few error messages --- libraries/chain/vesting_balance_evaluator.cpp | 2 +- .../wallet/include/graphene/wallet/wallet.hpp | 7 +++ libraries/wallet/wallet.cpp | 60 ++++++++++++++++--- 3 files changed, 61 insertions(+), 8 deletions(-) diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 22cf544f..9630d011 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -145,7 +145,7 @@ 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 ), "GPOS Vested Balance cannont be withdrwan during the locking period", ("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 ); */ diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 8a15fec0..fed7d55d 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -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) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index b6aa2cbf..75c47d8a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1720,6 +1720,42 @@ public: FC_CAPTURE_AND_RETHROW( (owner_account) ) } + bool is_witness(string owner_account) + { + try + { + fc::optional witness_id = maybe_id(owner_account); + if (witness_id) + { + std::vector ids_to_get; + ids_to_get.push_back(*witness_id); + std::vector> 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 = _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 @@ -2013,9 +2049,14 @@ public: 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 (is_witness(account_name)) + { + witness_object wit = get_witness( account_name ); + FC_ASSERT( wit.pay_vb ); + vbid = wit.pay_vb; + } + else + FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); } } @@ -2080,7 +2121,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 +2162,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 +2173,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 +4114,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); From 0800e2bc6710cd67394943812fbddf29e88cee91 Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Sat, 19 Oct 2019 16:38:12 +0530 Subject: [PATCH 2/3] error message corrections at other places --- .../include/graphene/chain/protocol/vesting.hpp | 10 ++++++++++ libraries/chain/vesting_balance_evaluator.cpp | 3 ++- libraries/wallet/wallet.cpp | 13 +++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp index ac995aaf..2a861b2a 100644 --- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp +++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp @@ -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 */ diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 9630d011..9f42d4ff 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -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 ), "GPOS Vested Balance cannont be withdrwan during the locking period", ("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 ); */ diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 75c47d8a..c7e605cc 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2005,9 +2005,14 @@ public: fc::optional vbid = maybe_id(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 ); @@ -2052,7 +2057,7 @@ public: if (is_witness(account_name)) { witness_object wit = get_witness( account_name ); - FC_ASSERT( wit.pay_vb ); + FC_ASSERT( wit.pay_vb, "Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); vbid = wit.pay_vb; } else From 69630183f961c3489128478acb066d7a9c5a022f Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Thu, 24 Oct 2019 19:24:09 +0530 Subject: [PATCH 3/3] removed witness check --- libraries/wallet/wallet.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index c7e605cc..0e4f3198 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2052,17 +2052,8 @@ public: acct_id = get_account( account_name ).id; vbos = _remote_db->get_vesting_balances( *acct_id ); - if( vbos.size() == 0 ) - { - if (is_witness(account_name)) - { - witness_object wit = get_witness( account_name ); - FC_ASSERT( wit.pay_vb, "Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); - vbid = wit.pay_vb; - } - else - FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name)); - } + 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