Add hive votes to votes_info struct + fix get_votes function

This commit is contained in:
Vlad Dobromyslov 2022-03-10 08:15:25 +03:00
parent e23da4ecdb
commit 49e07d4f32
3 changed files with 79 additions and 66 deletions

View file

@ -2130,63 +2130,74 @@ vector<vote_id_type> 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 database_api_impl::get_votes(const string &account_name_or_id) const {
votes_info result; votes_info result;
//const auto &votes_ids = get_votes_ids(account_name_or_id); const auto &votes_ids = get_votes_ids(account_name_or_id);
//const auto &committee_ids = get_votes_objects<committee_member_index, by_vote_id>(votes_ids); const auto &committee_ids = get_votes_objects<committee_member_index, by_vote_id>(votes_ids);
//const auto &witness_ids = get_votes_objects<witness_index, by_vote_id>(votes_ids); const auto &witness_ids = get_votes_objects<witness_index, by_vote_id>(votes_ids);
//const auto &for_worker_ids = get_votes_objects<worker_index, by_vote_for>(votes_ids); const auto &for_worker_ids = get_votes_objects<worker_index, by_vote_for>(votes_ids);
//const auto &against_worker_ids = get_votes_objects<worker_index, by_vote_against>(votes_ids); const auto &against_worker_ids = get_votes_objects<worker_index, by_vote_against>(votes_ids);
//const auto &son_ids = get_votes_objects<son_index, by_vote_id>(votes_ids, 5); const auto &son_bitcoin_ids = get_votes_objects<son_index, by_vote_id_bitcoin>(votes_ids, 5);
const auto &son_hive_ids = get_votes_objects<son_index, by_vote_id_hive>(votes_ids, 5);
////! Fill votes info //! Fill votes info
//if (!committee_ids.empty()) { if (!committee_ids.empty()) {
// vector<votes_info_object> votes_for_committee_members; vector<votes_info_object> votes_for_committee_members;
// votes_for_committee_members.reserve(committee_ids.size()); votes_for_committee_members.reserve(committee_ids.size());
// for (const auto &committee : committee_ids) { for (const auto &committee : committee_ids) {
// const auto &committee_obj = committee.as<committee_member_object>(2); const auto &committee_obj = committee.as<committee_member_object>(2);
// votes_for_committee_members.emplace_back(votes_info_object{committee_obj.vote_id, committee_obj.id}); 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); result.votes_for_committee_members = std::move(votes_for_committee_members);
//} }
//
//if (!witness_ids.empty()) { if (!witness_ids.empty()) {
// vector<votes_info_object> votes_for_witnesses; vector<votes_info_object> votes_for_witnesses;
// votes_for_witnesses.reserve(witness_ids.size()); votes_for_witnesses.reserve(witness_ids.size());
// for (const auto &witness : witness_ids) { for (const auto &witness : witness_ids) {
// const auto &witness_obj = witness.as<witness_object>(2); const auto &witness_obj = witness.as<witness_object>(2);
// votes_for_witnesses.emplace_back(votes_info_object{witness_obj.vote_id, witness_obj.id}); votes_for_witnesses.emplace_back(votes_info_object{witness_obj.vote_id, witness_obj.id});
// } }
// result.votes_for_witnesses = std::move(votes_for_witnesses); result.votes_for_witnesses = std::move(votes_for_witnesses);
//} }
//
//if (!for_worker_ids.empty()) { if (!for_worker_ids.empty()) {
// vector<votes_info_object> votes_for_workers; vector<votes_info_object> votes_for_workers;
// votes_for_workers.reserve(for_worker_ids.size()); votes_for_workers.reserve(for_worker_ids.size());
// for (const auto &for_worker : for_worker_ids) { for (const auto &for_worker : for_worker_ids) {
// const auto &for_worker_obj = for_worker.as<worker_object>(2); const auto &for_worker_obj = for_worker.as<worker_object>(2);
// votes_for_workers.emplace_back(votes_info_object{for_worker_obj.vote_for, for_worker_obj.id}); 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); result.votes_for_workers = std::move(votes_for_workers);
//} }
//
//if (!against_worker_ids.empty()) { if (!against_worker_ids.empty()) {
// vector<votes_info_object> votes_against_workers; vector<votes_info_object> votes_against_workers;
// votes_against_workers.reserve(against_worker_ids.size()); votes_against_workers.reserve(against_worker_ids.size());
// for (const auto &against_worker : against_worker_ids) { for (const auto &against_worker : against_worker_ids) {
// const auto &against_worker_obj = against_worker.as<worker_object>(2); const auto &against_worker_obj = against_worker.as<worker_object>(2);
// votes_against_workers.emplace_back(votes_info_object{against_worker_obj.vote_against, against_worker_obj.id}); 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); result.votes_against_workers = std::move(votes_against_workers);
//} }
//
//if (!son_ids.empty()) { if (!son_bitcoin_ids.empty()) {
// vector<votes_info_object> votes_for_sons; vector<votes_info_object> votes_for_sons;
// votes_for_sons.reserve(son_ids.size()); votes_for_sons.reserve(son_bitcoin_ids.size());
// for (const auto &son : son_ids) { for (const auto &son : son_bitcoin_ids) {
// const auto &son_obj = son.as<son_object>(6); const auto &son_obj = son.as<son_object>(6);
// votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id, son_obj.id}); votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id_bitcoin, son_obj.id});
// } }
// result.votes_for_sons = std::move(votes_for_sons); result.votes_for_bitcoin_sons = std::move(votes_for_sons);
//} }
if (!son_hive_ids.empty()) {
vector<votes_info_object> votes_for_sons;
votes_for_sons.reserve(son_hive_ids.size());
for (const auto &son : son_hive_ids) {
const auto &son_obj = son.as<son_object>(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; return result;
} }

View file

@ -23,7 +23,8 @@ namespace graphene { namespace chain {
optional< vector< votes_info_object > > votes_for_witnesses; optional< vector< votes_info_object > > votes_for_witnesses;
optional< vector< votes_info_object > > votes_for_workers; optional< vector< votes_info_object > > votes_for_workers;
optional< vector< votes_info_object > > votes_against_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 } } // graphene::chain
@ -37,4 +38,5 @@ FC_REFLECT( graphene::chain::votes_info,
(votes_for_witnesses) (votes_for_witnesses)
(votes_for_workers) (votes_for_workers)
(votes_against_workers) (votes_against_workers)
(votes_for_sons) ) (votes_for_bitcoin_sons)
(votes_for_hive_sons))

View file

@ -268,10 +268,10 @@ BOOST_AUTO_TEST_CASE( son_voting )
//! Check votes of nathan //! Check votes of nathan
auto nathan_votes = con.wallet_api_ptr->get_votes("nathan"); auto nathan_votes = con.wallet_api_ptr->get_votes("nathan");
BOOST_REQUIRE(nathan_votes.votes_for_sons); BOOST_REQUIRE(nathan_votes.votes_for_bitcoin_sons);
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->size(), 2); BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_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_bitcoin_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_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->at(1).id.instance(), son2_obj.id.instance());
// Withdraw vote for a son1account // Withdraw vote for a son1account
BOOST_TEST_MESSAGE("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 //! Check votes of nathan
nathan_votes = con.wallet_api_ptr->get_votes("nathan"); nathan_votes = con.wallet_api_ptr->get_votes("nathan");
BOOST_REQUIRE(nathan_votes.votes_for_sons); BOOST_REQUIRE(nathan_votes.votes_for_bitcoin_sons);
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->size(), 1); BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->size(), 1);
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(0).id.instance(), son2_obj.id.instance()); BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->at(0).id.instance(), son2_obj.id.instance());
// Withdraw vote for a son2account // Withdraw vote for a son2account
BOOST_TEST_MESSAGE("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 //! Check votes of nathan
nathan_votes = con.wallet_api_ptr->get_votes("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 ) { } catch( fc::exception& e ) {
BOOST_TEST_MESSAGE("SON cli wallet tests exception"); BOOST_TEST_MESSAGE("SON cli wallet tests exception");