diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 575269e4..199dae3f 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -2130,63 +2130,74 @@ vector database_api_impl::get_votes_ids(const string &account_name votes_info database_api_impl::get_votes(const string &account_name_or_id) const { votes_info result; - //const auto &votes_ids = get_votes_ids(account_name_or_id); - //const auto &committee_ids = get_votes_objects(votes_ids); - //const auto &witness_ids = get_votes_objects(votes_ids); - //const auto &for_worker_ids = get_votes_objects(votes_ids); - //const auto &against_worker_ids = get_votes_objects(votes_ids); - //const auto &son_ids = get_votes_objects(votes_ids, 5); + const auto &votes_ids = get_votes_ids(account_name_or_id); + const auto &committee_ids = get_votes_objects(votes_ids); + const auto &witness_ids = get_votes_objects(votes_ids); + const auto &for_worker_ids = get_votes_objects(votes_ids); + const auto &against_worker_ids = get_votes_objects(votes_ids); + const auto &son_bitcoin_ids = get_votes_objects(votes_ids, 5); + const auto &son_hive_ids = get_votes_objects(votes_ids, 5); - ////! Fill votes info - //if (!committee_ids.empty()) { - // vector votes_for_committee_members; - // votes_for_committee_members.reserve(committee_ids.size()); - // for (const auto &committee : committee_ids) { - // const auto &committee_obj = committee.as(2); - // votes_for_committee_members.emplace_back(votes_info_object{committee_obj.vote_id, committee_obj.id}); - // } - // result.votes_for_committee_members = std::move(votes_for_committee_members); - //} - // - //if (!witness_ids.empty()) { - // vector votes_for_witnesses; - // votes_for_witnesses.reserve(witness_ids.size()); - // for (const auto &witness : witness_ids) { - // const auto &witness_obj = witness.as(2); - // votes_for_witnesses.emplace_back(votes_info_object{witness_obj.vote_id, witness_obj.id}); - // } - // result.votes_for_witnesses = std::move(votes_for_witnesses); - //} - // - //if (!for_worker_ids.empty()) { - // vector votes_for_workers; - // votes_for_workers.reserve(for_worker_ids.size()); - // for (const auto &for_worker : for_worker_ids) { - // const auto &for_worker_obj = for_worker.as(2); - // votes_for_workers.emplace_back(votes_info_object{for_worker_obj.vote_for, for_worker_obj.id}); - // } - // result.votes_for_workers = std::move(votes_for_workers); - //} - // - //if (!against_worker_ids.empty()) { - // vector votes_against_workers; - // votes_against_workers.reserve(against_worker_ids.size()); - // for (const auto &against_worker : against_worker_ids) { - // const auto &against_worker_obj = against_worker.as(2); - // votes_against_workers.emplace_back(votes_info_object{against_worker_obj.vote_against, against_worker_obj.id}); - // } - // result.votes_against_workers = std::move(votes_against_workers); - //} - // - //if (!son_ids.empty()) { - // vector votes_for_sons; - // votes_for_sons.reserve(son_ids.size()); - // for (const auto &son : son_ids) { - // const auto &son_obj = son.as(6); - // votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id, son_obj.id}); - // } - // result.votes_for_sons = std::move(votes_for_sons); - //} + //! Fill votes info + if (!committee_ids.empty()) { + vector votes_for_committee_members; + votes_for_committee_members.reserve(committee_ids.size()); + for (const auto &committee : committee_ids) { + const auto &committee_obj = committee.as(2); + votes_for_committee_members.emplace_back(votes_info_object{committee_obj.vote_id, committee_obj.id}); + } + result.votes_for_committee_members = std::move(votes_for_committee_members); + } + + if (!witness_ids.empty()) { + vector votes_for_witnesses; + votes_for_witnesses.reserve(witness_ids.size()); + for (const auto &witness : witness_ids) { + const auto &witness_obj = witness.as(2); + votes_for_witnesses.emplace_back(votes_info_object{witness_obj.vote_id, witness_obj.id}); + } + result.votes_for_witnesses = std::move(votes_for_witnesses); + } + + if (!for_worker_ids.empty()) { + vector votes_for_workers; + votes_for_workers.reserve(for_worker_ids.size()); + for (const auto &for_worker : for_worker_ids) { + const auto &for_worker_obj = for_worker.as(2); + votes_for_workers.emplace_back(votes_info_object{for_worker_obj.vote_for, for_worker_obj.id}); + } + result.votes_for_workers = std::move(votes_for_workers); + } + + if (!against_worker_ids.empty()) { + vector votes_against_workers; + votes_against_workers.reserve(against_worker_ids.size()); + for (const auto &against_worker : against_worker_ids) { + const auto &against_worker_obj = against_worker.as(2); + votes_against_workers.emplace_back(votes_info_object{against_worker_obj.vote_against, against_worker_obj.id}); + } + result.votes_against_workers = std::move(votes_against_workers); + } + + if (!son_bitcoin_ids.empty()) { + vector votes_for_sons; + votes_for_sons.reserve(son_bitcoin_ids.size()); + for (const auto &son : son_bitcoin_ids) { + const auto &son_obj = son.as(6); + votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id_bitcoin, son_obj.id}); + } + result.votes_for_bitcoin_sons = std::move(votes_for_sons); + } + + if (!son_hive_ids.empty()) { + vector votes_for_sons; + votes_for_sons.reserve(son_hive_ids.size()); + for (const auto &son : son_hive_ids) { + const auto &son_obj = son.as(6); + votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id_hive, son_obj.id}); + } + result.votes_for_hive_sons = std::move(votes_for_sons); + } return result; } diff --git a/libraries/chain/include/graphene/chain/votes_info.hpp b/libraries/chain/include/graphene/chain/votes_info.hpp index 0a515589..af5e0631 100644 --- a/libraries/chain/include/graphene/chain/votes_info.hpp +++ b/libraries/chain/include/graphene/chain/votes_info.hpp @@ -23,7 +23,8 @@ namespace graphene { namespace chain { optional< vector< votes_info_object > > votes_for_witnesses; optional< vector< votes_info_object > > votes_for_workers; optional< vector< votes_info_object > > votes_against_workers; - optional< vector< votes_info_object > > votes_for_sons; + optional< vector< votes_info_object > > votes_for_bitcoin_sons; + optional< vector< votes_info_object > > votes_for_hive_sons; }; } } // graphene::chain @@ -37,4 +38,5 @@ FC_REFLECT( graphene::chain::votes_info, (votes_for_witnesses) (votes_for_workers) (votes_against_workers) - (votes_for_sons) ) \ No newline at end of file + (votes_for_bitcoin_sons) + (votes_for_hive_sons)) \ No newline at end of file diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index cfa1e699..a0567ce9 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -268,10 +268,10 @@ BOOST_AUTO_TEST_CASE( son_voting ) //! Check votes of nathan auto nathan_votes = con.wallet_api_ptr->get_votes("nathan"); - BOOST_REQUIRE(nathan_votes.votes_for_sons); - BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->size(), 2); - BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(0).id.instance(), son1_obj.id.instance()); - BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(1).id.instance(), son2_obj.id.instance()); + BOOST_REQUIRE(nathan_votes.votes_for_bitcoin_sons); + BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->size(), 2); + BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->at(0).id.instance(), son1_obj.id.instance()); + BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->at(1).id.instance(), son2_obj.id.instance()); // Withdraw vote for a son1account BOOST_TEST_MESSAGE("Withdraw vote for a son1account"); @@ -290,9 +290,9 @@ BOOST_AUTO_TEST_CASE( son_voting ) //! Check votes of nathan nathan_votes = con.wallet_api_ptr->get_votes("nathan"); - BOOST_REQUIRE(nathan_votes.votes_for_sons); - BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->size(), 1); - BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(0).id.instance(), son2_obj.id.instance()); + BOOST_REQUIRE(nathan_votes.votes_for_bitcoin_sons); + BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->size(), 1); + BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->at(0).id.instance(), son2_obj.id.instance()); // Withdraw vote for a son2account BOOST_TEST_MESSAGE("Withdraw vote for a son2account"); @@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE( son_voting ) //! Check votes of nathan nathan_votes = con.wallet_api_ptr->get_votes("nathan"); - BOOST_CHECK(!nathan_votes.votes_for_sons.valid()); + BOOST_CHECK(!nathan_votes.votes_for_bitcoin_sons.valid()); } catch( fc::exception& e ) { BOOST_TEST_MESSAGE("SON cli wallet tests exception");