#319 - votes_info: son info as map
This commit is contained in:
parent
0d094c2104
commit
a60a4d4495
3 changed files with 34 additions and 39 deletions
|
|
@ -2187,24 +2187,23 @@ votes_info database_api_impl::get_votes(const string &account_name_or_id) const
|
||||||
result.votes_against_workers = std::move(votes_against_workers);
|
result.votes_against_workers = std::move(votes_against_workers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!son_bitcoin_ids.empty()) {
|
if (!son_bitcoin_ids.empty() || !son_hive_ids.empty()) {
|
||||||
vector<votes_info_object> votes_for_sons;
|
flat_map<sidechain_type, vector< votes_info_object > > votes_for_sons;
|
||||||
votes_for_sons.reserve(son_bitcoin_ids.size());
|
if(!son_bitcoin_ids.empty()) {
|
||||||
for (const auto &son : son_bitcoin_ids) {
|
votes_for_sons[sidechain_type::bitcoin].reserve(son_bitcoin_ids.size());
|
||||||
const auto &son_obj = son.as<son_object>(6);
|
for (const auto &son : son_bitcoin_ids) {
|
||||||
votes_for_sons.emplace_back(votes_info_object{son_obj.get_bitcoin_vote_id(), son_obj.id});
|
const auto &son_obj = son.as<son_object>(6);
|
||||||
|
votes_for_sons[sidechain_type::bitcoin].emplace_back(votes_info_object{son_obj.get_bitcoin_vote_id(), son_obj.id});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
result.votes_for_bitcoin_sons = std::move(votes_for_sons);
|
if(!son_hive_ids.empty()) {
|
||||||
}
|
votes_for_sons[sidechain_type::hive].reserve(son_hive_ids.size());
|
||||||
|
for (const auto &son : son_hive_ids) {
|
||||||
if (!son_hive_ids.empty()) {
|
const auto &son_obj = son.as<son_object>(6);
|
||||||
vector<votes_info_object> votes_for_sons;
|
votes_for_sons[sidechain_type::hive].emplace_back(votes_info_object{son_obj.get_bitcoin_vote_id(), son_obj.id});
|
||||||
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.get_hive_vote_id(), son_obj.id});
|
|
||||||
}
|
}
|
||||||
result.votes_for_hive_sons = std::move(votes_for_sons);
|
result.votes_for_sons = std::move(votes_for_sons);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,11 @@ namespace graphene { namespace chain {
|
||||||
* @ingroup object
|
* @ingroup object
|
||||||
*/
|
*/
|
||||||
struct votes_info {
|
struct votes_info {
|
||||||
optional< vector< votes_info_object > > votes_for_committee_members;
|
optional< vector< votes_info_object > > votes_for_committee_members;
|
||||||
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_bitcoin_sons;
|
optional< flat_map<sidechain_type, vector< votes_info_object > > > votes_for_sons;
|
||||||
optional< vector< votes_info_object > > votes_for_hive_sons;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
@ -38,5 +37,4 @@ 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_bitcoin_sons)
|
(votes_for_sons))
|
||||||
(votes_for_hive_sons))
|
|
||||||
|
|
@ -273,13 +273,13 @@ 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_bitcoin_sons);
|
BOOST_REQUIRE(nathan_votes.votes_for_sons);
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->size(), 2);
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::bitcoin).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_sons->at(sidechain_type::bitcoin).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());
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::bitcoin).at(1).id.instance(), son2_obj.id.instance());
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_hive_sons->size(), 2);
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).size(), 2);
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_hive_sons->at(0).id.instance(), son1_obj.id.instance());
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).at(0).id.instance(), son1_obj.id.instance());
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_hive_sons->at(1).id.instance(), son2_obj.id.instance());
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).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");
|
||||||
|
|
@ -300,12 +300,11 @@ 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_bitcoin_sons);
|
BOOST_REQUIRE(nathan_votes.votes_for_sons);
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->size(), 1);
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::bitcoin).size(), 1);
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->at(0).id.instance(), son2_obj.id.instance());
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::bitcoin).at(0).id.instance(), son2_obj.id.instance());
|
||||||
BOOST_REQUIRE(nathan_votes.votes_for_hive_sons);
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).size(), 1);
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_hive_sons->size(), 1);
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).at(0).id.instance(), son2_obj.id.instance());
|
||||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_hive_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");
|
||||||
|
|
@ -326,8 +325,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_bitcoin_sons.valid());
|
BOOST_CHECK(!nathan_votes.votes_for_sons.valid());
|
||||||
BOOST_CHECK(!nathan_votes.votes_for_hive_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");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue