Add hive votes to voters_info struct + fix get_voters function
This commit is contained in:
parent
49e07d4f32
commit
9db2f1c513
3 changed files with 181 additions and 171 deletions
|
|
@ -2218,165 +2218,173 @@ vector<account_object> database_api_impl::get_voters_by_id(const vote_id_type &v
|
|||
voters_info database_api_impl::get_voters(const string &account_name_or_id) const {
|
||||
voters_info result;
|
||||
|
||||
////! Find account name
|
||||
//bool owner_account_found = false;
|
||||
//std::string owner_account_id;
|
||||
//
|
||||
////! Check if we have account by name
|
||||
//const auto &account_object = get_account_by_name(account_name_or_id);
|
||||
//if (account_object) {
|
||||
// //! It is account
|
||||
// owner_account_id = object_id_to_string(account_object->get_id());
|
||||
// owner_account_found = true;
|
||||
//} else {
|
||||
// //! Check if we have account id
|
||||
// const auto &account_id = maybe_id<account_id_type>(account_name_or_id);
|
||||
// if (account_id) {
|
||||
// //! It may be account id
|
||||
// const auto &account_objects = get_accounts({account_name_or_id});
|
||||
// if (!account_objects.empty()) {
|
||||
// const auto &account_object = account_objects.front();
|
||||
// if (account_object) {
|
||||
// //! It is account object
|
||||
// owner_account_id = object_id_to_string(account_object->get_id());
|
||||
// owner_account_found = true;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// //! Check if we have committee member id
|
||||
// const auto &committee_member_id = maybe_id<committee_member_id_type>(account_name_or_id);
|
||||
// if (committee_member_id) {
|
||||
// //! It may be committee member id
|
||||
// const auto &committee_member_objects = get_committee_members({*committee_member_id});
|
||||
// if (!committee_member_objects.empty()) {
|
||||
// const auto &committee_member_object = committee_member_objects.front();
|
||||
// if (committee_member_object) {
|
||||
// //! It is committee member object
|
||||
// owner_account_id = object_id_to_string(committee_member_object->committee_member_account);
|
||||
// owner_account_found = true;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// //! Check if we have witness id
|
||||
// const auto &witness_id = maybe_id<witness_id_type>(account_name_or_id);
|
||||
// if (witness_id) {
|
||||
// //! It may be witness id
|
||||
// const auto &witness_objects = get_witnesses({*witness_id});
|
||||
// if (!witness_objects.empty()) {
|
||||
// const auto &witness_object = witness_objects.front();
|
||||
// if (witness_object) {
|
||||
// //! It is witness object
|
||||
// owner_account_id = object_id_to_string(witness_object->witness_account);
|
||||
// owner_account_found = true;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// //! Check if we have worker id
|
||||
// const auto &worker_id = maybe_id<worker_id_type>(account_name_or_id);
|
||||
// if (worker_id) {
|
||||
// //! It may be worker id
|
||||
// const auto &worker_objects = get_workers({*worker_id});
|
||||
// if (!worker_objects.empty()) {
|
||||
// const auto &worker_object = worker_objects.front();
|
||||
// if (worker_object) {
|
||||
// //! It is worker object
|
||||
// owner_account_id = object_id_to_string(worker_object->worker_account);
|
||||
// owner_account_found = true;
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// //! Check if we have son id
|
||||
// const auto &son_id = maybe_id<son_id_type>(account_name_or_id);
|
||||
// if (son_id) {
|
||||
// //! It may be son id
|
||||
// const auto &son_objects = get_sons({*son_id});
|
||||
// if (!son_objects.empty()) {
|
||||
// const auto &son_object = son_objects.front();
|
||||
// if (son_object) {
|
||||
// //! It is son object
|
||||
// owner_account_id = object_id_to_string(son_object->son_account);
|
||||
// owner_account_found = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
////! We didn't find who it was
|
||||
//if (!owner_account_found)
|
||||
// FC_THROW_EXCEPTION(database_query_exception, "Wrong account_name_or_id: ${account_name_or_id}", ("account_name_or_id", account_name_or_id));
|
||||
//
|
||||
////! Fill voters_info
|
||||
//const auto &committee_member_object = get_committee_member_by_account(owner_account_id);
|
||||
//const auto &witness_object = get_witness_by_account(owner_account_id);
|
||||
//const auto &worker_objects = get_workers_by_account(owner_account_id);
|
||||
//const auto &son_object = get_son_by_account(owner_account_id);
|
||||
//
|
||||
////! Info for committee member voters
|
||||
//if (committee_member_object) {
|
||||
// const auto &committee_member_voters = get_voters_by_id(committee_member_object->vote_id);
|
||||
// voters_info_object voters_for_committee_member;
|
||||
// voters_for_committee_member.vote_id = committee_member_object->vote_id;
|
||||
// voters_for_committee_member.voters.reserve(committee_member_voters.size());
|
||||
// for (const auto &voter : committee_member_voters) {
|
||||
// voters_for_committee_member.voters.emplace_back(voter.get_id());
|
||||
// }
|
||||
// result.voters_for_committee_member = std::move(voters_for_committee_member);
|
||||
//}
|
||||
//
|
||||
////! Info for witness voters
|
||||
//if (witness_object) {
|
||||
// const auto &witness_voters = get_voters_by_id(witness_object->vote_id);
|
||||
// voters_info_object voters_for_witness;
|
||||
// voters_for_witness.vote_id = witness_object->vote_id;
|
||||
// voters_for_witness.voters.reserve(witness_voters.size());
|
||||
// for (const auto &voter : witness_voters) {
|
||||
// voters_for_witness.voters.emplace_back(voter.get_id());
|
||||
// }
|
||||
// result.voters_for_witness = std::move(voters_for_witness);
|
||||
//}
|
||||
//
|
||||
////! Info for worker voters
|
||||
//if (!worker_objects.empty()) {
|
||||
// vector<voters_info_object> voters_for_workers(worker_objects.size());
|
||||
// vector<voters_info_object> voters_against_workers(worker_objects.size());
|
||||
// for (const auto &worker_object : worker_objects) {
|
||||
// voters_info_object voters_for_worker;
|
||||
// const auto &for_worker_voters = get_voters_by_id(worker_object.vote_for);
|
||||
// voters_for_worker.vote_id = worker_object.vote_for;
|
||||
// voters_for_worker.voters.reserve(for_worker_voters.size());
|
||||
// for (const auto &voter : for_worker_voters) {
|
||||
// voters_for_worker.voters.emplace_back(voter.get_id());
|
||||
// }
|
||||
// voters_for_workers.emplace_back(std::move(voters_for_worker));
|
||||
//
|
||||
// voters_info_object voters_against_worker;
|
||||
// const auto &against_worker_voters = get_voters_by_id(worker_object.vote_against);
|
||||
// voters_against_worker.vote_id = worker_object.vote_against;
|
||||
// voters_against_worker.voters.reserve(against_worker_voters.size());
|
||||
// for (const auto &voter : against_worker_voters) {
|
||||
// voters_against_worker.voters.emplace_back(voter.get_id());
|
||||
// }
|
||||
// voters_against_workers.emplace_back(std::move(voters_against_worker));
|
||||
// }
|
||||
// result.voters_for_workers = std::move(voters_for_workers);
|
||||
// result.voters_against_workers = std::move(voters_against_workers);
|
||||
//}
|
||||
//
|
||||
////! Info for son voters
|
||||
//if (son_object) {
|
||||
// const auto &son_voters = get_voters_by_id(son_object->vote_id);
|
||||
// voters_info_object voters_for_son;
|
||||
// voters_for_son.vote_id = son_object->vote_id;
|
||||
// voters_for_son.voters.reserve(son_voters.size());
|
||||
// for (const auto &voter : son_voters) {
|
||||
// voters_for_son.voters.emplace_back(voter.get_id());
|
||||
// }
|
||||
// result.voters_for_son = std::move(voters_for_son);
|
||||
//}
|
||||
//! Find account name
|
||||
bool owner_account_found = false;
|
||||
std::string owner_account_id;
|
||||
|
||||
//! Check if we have account by name
|
||||
const auto &account_object = get_account_by_name(account_name_or_id);
|
||||
if (account_object) {
|
||||
//! It is account
|
||||
owner_account_id = object_id_to_string(account_object->get_id());
|
||||
owner_account_found = true;
|
||||
} else {
|
||||
//! Check if we have account id
|
||||
const auto &account_id = maybe_id<account_id_type>(account_name_or_id);
|
||||
if (account_id) {
|
||||
//! It may be account id
|
||||
const auto &account_objects = get_accounts({account_name_or_id});
|
||||
if (!account_objects.empty()) {
|
||||
const auto &account_object = account_objects.front();
|
||||
if (account_object) {
|
||||
//! It is account object
|
||||
owner_account_id = object_id_to_string(account_object->get_id());
|
||||
owner_account_found = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//! Check if we have committee member id
|
||||
const auto &committee_member_id = maybe_id<committee_member_id_type>(account_name_or_id);
|
||||
if (committee_member_id) {
|
||||
//! It may be committee member id
|
||||
const auto &committee_member_objects = get_committee_members({*committee_member_id});
|
||||
if (!committee_member_objects.empty()) {
|
||||
const auto &committee_member_object = committee_member_objects.front();
|
||||
if (committee_member_object) {
|
||||
//! It is committee member object
|
||||
owner_account_id = object_id_to_string(committee_member_object->committee_member_account);
|
||||
owner_account_found = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//! Check if we have witness id
|
||||
const auto &witness_id = maybe_id<witness_id_type>(account_name_or_id);
|
||||
if (witness_id) {
|
||||
//! It may be witness id
|
||||
const auto &witness_objects = get_witnesses({*witness_id});
|
||||
if (!witness_objects.empty()) {
|
||||
const auto &witness_object = witness_objects.front();
|
||||
if (witness_object) {
|
||||
//! It is witness object
|
||||
owner_account_id = object_id_to_string(witness_object->witness_account);
|
||||
owner_account_found = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//! Check if we have worker id
|
||||
const auto &worker_id = maybe_id<worker_id_type>(account_name_or_id);
|
||||
if (worker_id) {
|
||||
//! It may be worker id
|
||||
const auto &worker_objects = get_workers({*worker_id});
|
||||
if (!worker_objects.empty()) {
|
||||
const auto &worker_object = worker_objects.front();
|
||||
if (worker_object) {
|
||||
//! It is worker object
|
||||
owner_account_id = object_id_to_string(worker_object->worker_account);
|
||||
owner_account_found = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//! Check if we have son id
|
||||
const auto &son_id = maybe_id<son_id_type>(account_name_or_id);
|
||||
if (son_id) {
|
||||
//! It may be son id
|
||||
const auto &son_objects = get_sons({*son_id});
|
||||
if (!son_objects.empty()) {
|
||||
const auto &son_object = son_objects.front();
|
||||
if (son_object) {
|
||||
//! It is son object
|
||||
owner_account_id = object_id_to_string(son_object->son_account);
|
||||
owner_account_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//! We didn't find who it was
|
||||
if (!owner_account_found)
|
||||
FC_THROW_EXCEPTION(database_query_exception, "Wrong account_name_or_id: ${account_name_or_id}", ("account_name_or_id", account_name_or_id));
|
||||
|
||||
//! Fill voters_info
|
||||
const auto &committee_member_object = get_committee_member_by_account(owner_account_id);
|
||||
const auto &witness_object = get_witness_by_account(owner_account_id);
|
||||
const auto &worker_objects = get_workers_by_account(owner_account_id);
|
||||
const auto &son_object = get_son_by_account(owner_account_id);
|
||||
|
||||
//! Info for committee member voters
|
||||
if (committee_member_object) {
|
||||
const auto &committee_member_voters = get_voters_by_id(committee_member_object->vote_id);
|
||||
voters_info_object voters_for_committee_member;
|
||||
voters_for_committee_member.vote_id = committee_member_object->vote_id;
|
||||
voters_for_committee_member.voters.reserve(committee_member_voters.size());
|
||||
for (const auto &voter : committee_member_voters) {
|
||||
voters_for_committee_member.voters.emplace_back(voter.get_id());
|
||||
}
|
||||
result.voters_for_committee_member = std::move(voters_for_committee_member);
|
||||
}
|
||||
|
||||
//! Info for witness voters
|
||||
if (witness_object) {
|
||||
const auto &witness_voters = get_voters_by_id(witness_object->vote_id);
|
||||
voters_info_object voters_for_witness;
|
||||
voters_for_witness.vote_id = witness_object->vote_id;
|
||||
voters_for_witness.voters.reserve(witness_voters.size());
|
||||
for (const auto &voter : witness_voters) {
|
||||
voters_for_witness.voters.emplace_back(voter.get_id());
|
||||
}
|
||||
result.voters_for_witness = std::move(voters_for_witness);
|
||||
}
|
||||
|
||||
//! Info for worker voters
|
||||
if (!worker_objects.empty()) {
|
||||
vector<voters_info_object> voters_for_workers(worker_objects.size());
|
||||
vector<voters_info_object> voters_against_workers(worker_objects.size());
|
||||
for (const auto &worker_object : worker_objects) {
|
||||
voters_info_object voters_for_worker;
|
||||
const auto &for_worker_voters = get_voters_by_id(worker_object.vote_for);
|
||||
voters_for_worker.vote_id = worker_object.vote_for;
|
||||
voters_for_worker.voters.reserve(for_worker_voters.size());
|
||||
for (const auto &voter : for_worker_voters) {
|
||||
voters_for_worker.voters.emplace_back(voter.get_id());
|
||||
}
|
||||
voters_for_workers.emplace_back(std::move(voters_for_worker));
|
||||
|
||||
voters_info_object voters_against_worker;
|
||||
const auto &against_worker_voters = get_voters_by_id(worker_object.vote_against);
|
||||
voters_against_worker.vote_id = worker_object.vote_against;
|
||||
voters_against_worker.voters.reserve(against_worker_voters.size());
|
||||
for (const auto &voter : against_worker_voters) {
|
||||
voters_against_worker.voters.emplace_back(voter.get_id());
|
||||
}
|
||||
voters_against_workers.emplace_back(std::move(voters_against_worker));
|
||||
}
|
||||
result.voters_for_workers = std::move(voters_for_workers);
|
||||
result.voters_against_workers = std::move(voters_against_workers);
|
||||
}
|
||||
|
||||
//! Info for son voters
|
||||
if (son_object) {
|
||||
const auto &son_bitcoin_voters = get_voters_by_id(son_object->vote_id_bitcoin);
|
||||
voters_info_object voters_for_bitcoin_son;
|
||||
voters_for_bitcoin_son.vote_id = son_object->vote_id_bitcoin;
|
||||
voters_for_bitcoin_son.voters.reserve(son_bitcoin_voters.size());
|
||||
for (const auto &voter : son_bitcoin_voters) {
|
||||
voters_for_bitcoin_son.voters.emplace_back(voter.get_id());
|
||||
}
|
||||
const auto &son_hive_voters = get_voters_by_id(son_object->vote_id_hive);
|
||||
voters_info_object voters_for_hive_son;
|
||||
voters_for_hive_son.vote_id = son_object->vote_id_hive;
|
||||
voters_for_hive_son.voters.reserve(son_hive_voters.size());
|
||||
for (const auto &voter : son_hive_voters) {
|
||||
voters_for_hive_son.voters.emplace_back(voter.get_id());
|
||||
}
|
||||
result.voters_for_bitcoin_son = std::move(voters_for_bitcoin_son);
|
||||
result.voters_for_hive_son = std::move(voters_for_hive_son);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ namespace graphene { namespace chain {
|
|||
optional<voters_info_object> voters_for_witness;
|
||||
optional<vector<voters_info_object> > voters_for_workers;
|
||||
optional<vector<voters_info_object> > voters_against_workers;
|
||||
optional<voters_info_object> voters_for_son;
|
||||
optional<voters_info_object> voters_for_bitcoin_son;
|
||||
optional<voters_info_object> voters_for_hive_son;
|
||||
};
|
||||
|
||||
} } // graphene::chain
|
||||
|
|
@ -37,4 +38,5 @@ FC_REFLECT( graphene::chain::voters_info,
|
|||
(voters_for_witness)
|
||||
(voters_for_workers)
|
||||
(voters_against_workers)
|
||||
(voters_for_son) )
|
||||
(voters_for_bitcoin_son)
|
||||
(voters_for_hive_son))
|
||||
|
|
@ -256,15 +256,15 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
|
||||
//! Check son1account voters
|
||||
auto voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->voters.size(), 1);
|
||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_son->voters[0].instance, nathan_account_object.id.instance());
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_bitcoin_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_bitcoin_son->voters.size(), 1);
|
||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_bitcoin_son->voters[0].instance, nathan_account_object.id.instance());
|
||||
|
||||
//! Check son2account voters
|
||||
auto voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->voters.size(), 1);
|
||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_son->voters[0].instance, nathan_account_object.id.instance());
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_bitcoin_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_bitcoin_son->voters.size(), 1);
|
||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_bitcoin_son->voters[0].instance, nathan_account_object.id.instance());
|
||||
|
||||
//! Check votes of nathan
|
||||
auto nathan_votes = con.wallet_api_ptr->get_votes("nathan");
|
||||
|
|
@ -285,8 +285,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
|
||||
//! Check son1account voters
|
||||
voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->voters.size(), 0);
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_bitcoin_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_bitcoin_son->voters.size(), 0);
|
||||
|
||||
//! Check votes of nathan
|
||||
nathan_votes = con.wallet_api_ptr->get_votes("nathan");
|
||||
|
|
@ -306,8 +306,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
|
||||
//! Check son2account voters
|
||||
voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->voters.size(), 0);
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_bitcoin_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_bitcoin_son->voters.size(), 0);
|
||||
|
||||
//! Check votes of nathan
|
||||
nathan_votes = con.wallet_api_ptr->get_votes("nathan");
|
||||
|
|
|
|||
Loading…
Reference in a new issue