#260 votes_info all members as optional
This commit is contained in:
parent
558e3c0045
commit
504680f727
4 changed files with 62 additions and 39 deletions
|
|
@ -2068,35 +2068,54 @@ votes_info database_api_impl::get_votes(const string &account_name_or_id) const
|
||||||
const auto& son_ids = get_votes_objects<son_index, by_vote_id>(votes_ids, 5);
|
const auto& son_ids = get_votes_objects<son_index, by_vote_id>(votes_ids, 5);
|
||||||
|
|
||||||
//! Fill votes info
|
//! Fill votes info
|
||||||
result.votes_for_committee_members.reserve(committee_ids.size());
|
if(!committee_ids.empty()) {
|
||||||
for(const auto& committee : committee_ids)
|
vector< votes_info_object<committee_member_id_type> > votes_for_committee_members;
|
||||||
{
|
votes_for_committee_members.reserve(committee_ids.size());
|
||||||
const auto& committee_obj = committee.as<committee_member_object>(2);
|
for (const auto &committee : committee_ids) {
|
||||||
result.votes_for_committee_members.emplace_back( votes_info_object<committee_member_id_type>{ committee_obj.vote_id, committee_obj.id.instance() } );
|
const auto &committee_obj = committee.as<committee_member_object>(2);
|
||||||
|
votes_for_committee_members.emplace_back(votes_info_object<committee_member_id_type>{committee_obj.vote_id, committee_obj.id.instance()});
|
||||||
|
}
|
||||||
|
result.votes_for_committee_members = std::move(votes_for_committee_members);
|
||||||
}
|
}
|
||||||
result.votes_for_witnesses.reserve(witness_ids.size());
|
|
||||||
for(const auto& witness : witness_ids)
|
if(!witness_ids.empty()) {
|
||||||
{
|
vector< votes_info_object<witness_id_type> > votes_for_witnesses;
|
||||||
const auto& witness_obj = witness.as<witness_object>(2);
|
votes_for_witnesses.reserve(witness_ids.size());
|
||||||
result.votes_for_witnesses.emplace_back( votes_info_object<witness_id_type>{ witness_obj.vote_id, witness_obj.id.instance() } );
|
for (const auto &witness : witness_ids) {
|
||||||
|
const auto &witness_obj = witness.as<witness_object>(2);
|
||||||
|
votes_for_witnesses.emplace_back(votes_info_object<witness_id_type>{witness_obj.vote_id, witness_obj.id.instance()});
|
||||||
|
}
|
||||||
|
result.votes_for_witnesses = std::move(votes_for_witnesses);
|
||||||
}
|
}
|
||||||
result.votes_for_workers.reserve(for_worker_ids.size());
|
|
||||||
for(const auto& for_worker : for_worker_ids)
|
if(!for_worker_ids.empty()) {
|
||||||
{
|
vector< votes_info_object<worker_id_type> > votes_for_workers;
|
||||||
const auto& for_worker_obj = for_worker.as<worker_object>(2);
|
votes_for_workers.reserve(for_worker_ids.size());
|
||||||
result.votes_for_workers.emplace_back( votes_info_object<worker_id_type>{ for_worker_obj.vote_for, for_worker_obj.id.instance() } );
|
for (const auto &for_worker : for_worker_ids) {
|
||||||
|
const auto &for_worker_obj = for_worker.as<worker_object>(2);
|
||||||
|
votes_for_workers.emplace_back(votes_info_object<worker_id_type>{for_worker_obj.vote_for, for_worker_obj.id.instance()});
|
||||||
|
}
|
||||||
|
result.votes_for_workers = std::move(votes_for_workers);
|
||||||
}
|
}
|
||||||
result.votes_against_workers.reserve(against_worker_ids.size());
|
|
||||||
for(const auto& against_worker : against_worker_ids)
|
if(!against_worker_ids.empty()) {
|
||||||
{
|
vector< votes_info_object<worker_id_type> > votes_against_workers;
|
||||||
const auto& against_worker_obj = against_worker.as<worker_object>(2);
|
votes_against_workers.reserve(against_worker_ids.size());
|
||||||
result.votes_against_workers.emplace_back( votes_info_object<worker_id_type>{ against_worker_obj.vote_against, against_worker_obj.id.instance() } );
|
for (const auto &against_worker : against_worker_ids) {
|
||||||
|
const auto &against_worker_obj = against_worker.as<worker_object>(2);
|
||||||
|
votes_against_workers.emplace_back(votes_info_object<worker_id_type>{against_worker_obj.vote_against, against_worker_obj.id.instance()});
|
||||||
|
}
|
||||||
|
result.votes_against_workers = std::move(votes_against_workers);
|
||||||
}
|
}
|
||||||
result.votes_for_sons.reserve(son_ids.size());
|
|
||||||
for(const auto& son : son_ids)
|
if(!son_ids.empty()) {
|
||||||
{
|
vector< votes_info_object<son_id_type> > votes_for_sons;
|
||||||
const auto& son_obj = son.as<son_object>(6);
|
votes_for_sons.reserve(son_ids.size());
|
||||||
result.votes_for_sons.emplace_back( votes_info_object<son_id_type>{ son_obj.vote_id, son_obj.id.instance() } );
|
for (const auto &son : son_ids) {
|
||||||
|
const auto &son_obj = son.as<son_object>(6);
|
||||||
|
votes_for_sons.emplace_back(votes_info_object<son_id_type>{son_obj.vote_id, son_obj.id.instance()});
|
||||||
|
}
|
||||||
|
result.votes_for_sons = std::move(votes_for_sons);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@ namespace graphene { namespace chain {
|
||||||
* @ingroup object
|
* @ingroup object
|
||||||
*/
|
*/
|
||||||
struct votes_info {
|
struct votes_info {
|
||||||
vector< votes_info_object<committee_member_id_type> > votes_for_committee_members;
|
optional< vector< votes_info_object<committee_member_id_type> > > votes_for_committee_members;
|
||||||
vector< votes_info_object<witness_id_type> > votes_for_witnesses;
|
optional< vector< votes_info_object<witness_id_type> > > votes_for_witnesses;
|
||||||
vector< votes_info_object<worker_id_type> > votes_for_workers;
|
optional< vector< votes_info_object<worker_id_type> > > votes_for_workers;
|
||||||
vector< votes_info_object<worker_id_type> > votes_against_workers;
|
optional< vector< votes_info_object<worker_id_type> > > votes_against_workers;
|
||||||
vector< votes_info_object<son_id_type> > votes_for_sons;
|
optional< vector< votes_info_object<son_id_type> > > votes_for_sons;
|
||||||
};
|
};
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
|
||||||
|
|
@ -261,9 +261,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_CHECK_EQUAL(nathan_votes.votes_for_sons.size(), 2);
|
BOOST_REQUIRE(nathan_votes.votes_for_sons);
|
||||||
BOOST_CHECK_EQUAL((uint32_t)nathan_votes.votes_for_sons[0].id.instance, son1_obj.id.instance());
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->size(), 2);
|
||||||
BOOST_CHECK_EQUAL((uint32_t)nathan_votes.votes_for_sons[1].id.instance, son2_obj.id.instance());
|
BOOST_CHECK_EQUAL((uint32_t)nathan_votes.votes_for_sons->at(0).id.instance, son1_obj.id.instance());
|
||||||
|
BOOST_CHECK_EQUAL((uint32_t)nathan_votes.votes_for_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");
|
||||||
|
|
@ -282,8 +283,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_CHECK_EQUAL(nathan_votes.votes_for_sons.size(), 1);
|
BOOST_REQUIRE(nathan_votes.votes_for_sons);
|
||||||
BOOST_CHECK_EQUAL((uint32_t)nathan_votes.votes_for_sons[0].id.instance, son2_obj.id.instance());
|
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->size(), 1);
|
||||||
|
BOOST_CHECK_EQUAL((uint32_t)nathan_votes.votes_for_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");
|
||||||
|
|
@ -302,7 +304,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_EQUAL(nathan_votes.votes_for_sons.size(), 0);
|
BOOST_CHECK(!nathan_votes.votes_for_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");
|
||||||
|
|
|
||||||
|
|
@ -330,8 +330,9 @@ BOOST_AUTO_TEST_CASE(track_votes_witnesses_enabled)
|
||||||
|
|
||||||
//! Check votes of account
|
//! Check votes of account
|
||||||
const auto account_votes = db_api1.get_votes("1.2.18");
|
const auto account_votes = db_api1.get_votes("1.2.18");
|
||||||
BOOST_CHECK_EQUAL(account_votes.votes_for_witnesses.size(), 1);
|
BOOST_REQUIRE(account_votes.votes_for_witnesses);
|
||||||
BOOST_CHECK_EQUAL((uint32_t)account_votes.votes_for_witnesses[0].id.instance, witness1_object->id.instance());
|
BOOST_CHECK_EQUAL(account_votes.votes_for_witnesses->size(), 1);
|
||||||
|
BOOST_CHECK_EQUAL((uint32_t)account_votes.votes_for_witnesses->at(0).id.instance, witness1_object->id.instance());
|
||||||
|
|
||||||
} FC_LOG_AND_RETHROW()
|
} FC_LOG_AND_RETHROW()
|
||||||
}
|
}
|
||||||
|
|
@ -520,7 +521,8 @@ BOOST_AUTO_TEST_CASE(track_votes_committee_enabled)
|
||||||
|
|
||||||
//! Check votes of account
|
//! Check votes of account
|
||||||
const auto account_votes = db_api1.get_votes("1.2.18");
|
const auto account_votes = db_api1.get_votes("1.2.18");
|
||||||
BOOST_CHECK_EQUAL((uint32_t)account_votes.votes_for_committee_members.back().id.instance, committee1_object->id.instance());
|
BOOST_REQUIRE(account_votes.votes_for_committee_members);
|
||||||
|
BOOST_CHECK_EQUAL((uint32_t)account_votes.votes_for_committee_members->back().id.instance, committee1_object->id.instance());
|
||||||
|
|
||||||
} FC_LOG_AND_RETHROW()
|
} FC_LOG_AND_RETHROW()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue