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 database_api_impl::get_voters(const string &account_name_or_id) const {
|
||||||
voters_info result;
|
voters_info result;
|
||||||
|
|
||||||
////! Find account name
|
//! Find account name
|
||||||
//bool owner_account_found = false;
|
bool owner_account_found = false;
|
||||||
//std::string owner_account_id;
|
std::string owner_account_id;
|
||||||
//
|
|
||||||
////! Check if we have account by name
|
//! Check if we have account by name
|
||||||
//const auto &account_object = get_account_by_name(account_name_or_id);
|
const auto &account_object = get_account_by_name(account_name_or_id);
|
||||||
//if (account_object) {
|
if (account_object) {
|
||||||
// //! It is account
|
//! It is account
|
||||||
// owner_account_id = object_id_to_string(account_object->get_id());
|
owner_account_id = object_id_to_string(account_object->get_id());
|
||||||
// owner_account_found = true;
|
owner_account_found = true;
|
||||||
//} else {
|
} else {
|
||||||
// //! Check if we have account id
|
//! Check if we have account id
|
||||||
// const auto &account_id = maybe_id<account_id_type>(account_name_or_id);
|
const auto &account_id = maybe_id<account_id_type>(account_name_or_id);
|
||||||
// if (account_id) {
|
if (account_id) {
|
||||||
// //! It may be account id
|
//! It may be account id
|
||||||
// const auto &account_objects = get_accounts({account_name_or_id});
|
const auto &account_objects = get_accounts({account_name_or_id});
|
||||||
// if (!account_objects.empty()) {
|
if (!account_objects.empty()) {
|
||||||
// const auto &account_object = account_objects.front();
|
const auto &account_object = account_objects.front();
|
||||||
// if (account_object) {
|
if (account_object) {
|
||||||
// //! It is account object
|
//! It is account object
|
||||||
// owner_account_id = object_id_to_string(account_object->get_id());
|
owner_account_id = object_id_to_string(account_object->get_id());
|
||||||
// owner_account_found = true;
|
owner_account_found = true;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// //! Check if we have committee member id
|
//! Check if we have committee member id
|
||||||
// const auto &committee_member_id = maybe_id<committee_member_id_type>(account_name_or_id);
|
const auto &committee_member_id = maybe_id<committee_member_id_type>(account_name_or_id);
|
||||||
// if (committee_member_id) {
|
if (committee_member_id) {
|
||||||
// //! It may be committee member id
|
//! It may be committee member id
|
||||||
// const auto &committee_member_objects = get_committee_members({*committee_member_id});
|
const auto &committee_member_objects = get_committee_members({*committee_member_id});
|
||||||
// if (!committee_member_objects.empty()) {
|
if (!committee_member_objects.empty()) {
|
||||||
// const auto &committee_member_object = committee_member_objects.front();
|
const auto &committee_member_object = committee_member_objects.front();
|
||||||
// if (committee_member_object) {
|
if (committee_member_object) {
|
||||||
// //! It is committee member object
|
//! It is committee member object
|
||||||
// owner_account_id = object_id_to_string(committee_member_object->committee_member_account);
|
owner_account_id = object_id_to_string(committee_member_object->committee_member_account);
|
||||||
// owner_account_found = true;
|
owner_account_found = true;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// //! Check if we have witness id
|
//! Check if we have witness id
|
||||||
// const auto &witness_id = maybe_id<witness_id_type>(account_name_or_id);
|
const auto &witness_id = maybe_id<witness_id_type>(account_name_or_id);
|
||||||
// if (witness_id) {
|
if (witness_id) {
|
||||||
// //! It may be witness id
|
//! It may be witness id
|
||||||
// const auto &witness_objects = get_witnesses({*witness_id});
|
const auto &witness_objects = get_witnesses({*witness_id});
|
||||||
// if (!witness_objects.empty()) {
|
if (!witness_objects.empty()) {
|
||||||
// const auto &witness_object = witness_objects.front();
|
const auto &witness_object = witness_objects.front();
|
||||||
// if (witness_object) {
|
if (witness_object) {
|
||||||
// //! It is witness object
|
//! It is witness object
|
||||||
// owner_account_id = object_id_to_string(witness_object->witness_account);
|
owner_account_id = object_id_to_string(witness_object->witness_account);
|
||||||
// owner_account_found = true;
|
owner_account_found = true;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// //! Check if we have worker id
|
//! Check if we have worker id
|
||||||
// const auto &worker_id = maybe_id<worker_id_type>(account_name_or_id);
|
const auto &worker_id = maybe_id<worker_id_type>(account_name_or_id);
|
||||||
// if (worker_id) {
|
if (worker_id) {
|
||||||
// //! It may be worker id
|
//! It may be worker id
|
||||||
// const auto &worker_objects = get_workers({*worker_id});
|
const auto &worker_objects = get_workers({*worker_id});
|
||||||
// if (!worker_objects.empty()) {
|
if (!worker_objects.empty()) {
|
||||||
// const auto &worker_object = worker_objects.front();
|
const auto &worker_object = worker_objects.front();
|
||||||
// if (worker_object) {
|
if (worker_object) {
|
||||||
// //! It is worker object
|
//! It is worker object
|
||||||
// owner_account_id = object_id_to_string(worker_object->worker_account);
|
owner_account_id = object_id_to_string(worker_object->worker_account);
|
||||||
// owner_account_found = true;
|
owner_account_found = true;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// } else {
|
} else {
|
||||||
// //! Check if we have son id
|
//! Check if we have son id
|
||||||
// const auto &son_id = maybe_id<son_id_type>(account_name_or_id);
|
const auto &son_id = maybe_id<son_id_type>(account_name_or_id);
|
||||||
// if (son_id) {
|
if (son_id) {
|
||||||
// //! It may be son id
|
//! It may be son id
|
||||||
// const auto &son_objects = get_sons({*son_id});
|
const auto &son_objects = get_sons({*son_id});
|
||||||
// if (!son_objects.empty()) {
|
if (!son_objects.empty()) {
|
||||||
// const auto &son_object = son_objects.front();
|
const auto &son_object = son_objects.front();
|
||||||
// if (son_object) {
|
if (son_object) {
|
||||||
// //! It is son object
|
//! It is son object
|
||||||
// owner_account_id = object_id_to_string(son_object->son_account);
|
owner_account_id = object_id_to_string(son_object->son_account);
|
||||||
// owner_account_found = true;
|
owner_account_found = true;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
////! We didn't find who it was
|
//! We didn't find who it was
|
||||||
//if (!owner_account_found)
|
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));
|
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
|
//! Fill voters_info
|
||||||
//const auto &committee_member_object = get_committee_member_by_account(owner_account_id);
|
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 &witness_object = get_witness_by_account(owner_account_id);
|
||||||
//const auto &worker_objects = get_workers_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);
|
const auto &son_object = get_son_by_account(owner_account_id);
|
||||||
//
|
|
||||||
////! Info for committee member voters
|
//! Info for committee member voters
|
||||||
//if (committee_member_object) {
|
if (committee_member_object) {
|
||||||
// const auto &committee_member_voters = get_voters_by_id(committee_member_object->vote_id);
|
const auto &committee_member_voters = get_voters_by_id(committee_member_object->vote_id);
|
||||||
// voters_info_object voters_for_committee_member;
|
voters_info_object voters_for_committee_member;
|
||||||
// voters_for_committee_member.vote_id = committee_member_object->vote_id;
|
voters_for_committee_member.vote_id = committee_member_object->vote_id;
|
||||||
// voters_for_committee_member.voters.reserve(committee_member_voters.size());
|
voters_for_committee_member.voters.reserve(committee_member_voters.size());
|
||||||
// for (const auto &voter : committee_member_voters) {
|
for (const auto &voter : committee_member_voters) {
|
||||||
// voters_for_committee_member.voters.emplace_back(voter.get_id());
|
voters_for_committee_member.voters.emplace_back(voter.get_id());
|
||||||
// }
|
}
|
||||||
// result.voters_for_committee_member = std::move(voters_for_committee_member);
|
result.voters_for_committee_member = std::move(voters_for_committee_member);
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
////! Info for witness voters
|
//! Info for witness voters
|
||||||
//if (witness_object) {
|
if (witness_object) {
|
||||||
// const auto &witness_voters = get_voters_by_id(witness_object->vote_id);
|
const auto &witness_voters = get_voters_by_id(witness_object->vote_id);
|
||||||
// voters_info_object voters_for_witness;
|
voters_info_object voters_for_witness;
|
||||||
// voters_for_witness.vote_id = witness_object->vote_id;
|
voters_for_witness.vote_id = witness_object->vote_id;
|
||||||
// voters_for_witness.voters.reserve(witness_voters.size());
|
voters_for_witness.voters.reserve(witness_voters.size());
|
||||||
// for (const auto &voter : witness_voters) {
|
for (const auto &voter : witness_voters) {
|
||||||
// voters_for_witness.voters.emplace_back(voter.get_id());
|
voters_for_witness.voters.emplace_back(voter.get_id());
|
||||||
// }
|
}
|
||||||
// result.voters_for_witness = std::move(voters_for_witness);
|
result.voters_for_witness = std::move(voters_for_witness);
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
////! Info for worker voters
|
//! Info for worker voters
|
||||||
//if (!worker_objects.empty()) {
|
if (!worker_objects.empty()) {
|
||||||
// vector<voters_info_object> voters_for_workers(worker_objects.size());
|
vector<voters_info_object> voters_for_workers(worker_objects.size());
|
||||||
// vector<voters_info_object> voters_against_workers(worker_objects.size());
|
vector<voters_info_object> voters_against_workers(worker_objects.size());
|
||||||
// for (const auto &worker_object : worker_objects) {
|
for (const auto &worker_object : worker_objects) {
|
||||||
// voters_info_object voters_for_worker;
|
voters_info_object voters_for_worker;
|
||||||
// const auto &for_worker_voters = get_voters_by_id(worker_object.vote_for);
|
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.vote_id = worker_object.vote_for;
|
||||||
// voters_for_worker.voters.reserve(for_worker_voters.size());
|
voters_for_worker.voters.reserve(for_worker_voters.size());
|
||||||
// for (const auto &voter : for_worker_voters) {
|
for (const auto &voter : for_worker_voters) {
|
||||||
// voters_for_worker.voters.emplace_back(voter.get_id());
|
voters_for_worker.voters.emplace_back(voter.get_id());
|
||||||
// }
|
}
|
||||||
// voters_for_workers.emplace_back(std::move(voters_for_worker));
|
voters_for_workers.emplace_back(std::move(voters_for_worker));
|
||||||
//
|
|
||||||
// voters_info_object voters_against_worker;
|
voters_info_object voters_against_worker;
|
||||||
// const auto &against_worker_voters = get_voters_by_id(worker_object.vote_against);
|
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.vote_id = worker_object.vote_against;
|
||||||
// voters_against_worker.voters.reserve(against_worker_voters.size());
|
voters_against_worker.voters.reserve(against_worker_voters.size());
|
||||||
// for (const auto &voter : against_worker_voters) {
|
for (const auto &voter : against_worker_voters) {
|
||||||
// voters_against_worker.voters.emplace_back(voter.get_id());
|
voters_against_worker.voters.emplace_back(voter.get_id());
|
||||||
// }
|
}
|
||||||
// voters_against_workers.emplace_back(std::move(voters_against_worker));
|
voters_against_workers.emplace_back(std::move(voters_against_worker));
|
||||||
// }
|
}
|
||||||
// result.voters_for_workers = std::move(voters_for_workers);
|
result.voters_for_workers = std::move(voters_for_workers);
|
||||||
// result.voters_against_workers = std::move(voters_against_workers);
|
result.voters_against_workers = std::move(voters_against_workers);
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
////! Info for son voters
|
//! Info for son voters
|
||||||
//if (son_object) {
|
if (son_object) {
|
||||||
// const auto &son_voters = get_voters_by_id(son_object->vote_id);
|
const auto &son_bitcoin_voters = get_voters_by_id(son_object->vote_id_bitcoin);
|
||||||
// voters_info_object voters_for_son;
|
voters_info_object voters_for_bitcoin_son;
|
||||||
// voters_for_son.vote_id = son_object->vote_id;
|
voters_for_bitcoin_son.vote_id = son_object->vote_id_bitcoin;
|
||||||
// voters_for_son.voters.reserve(son_voters.size());
|
voters_for_bitcoin_son.voters.reserve(son_bitcoin_voters.size());
|
||||||
// for (const auto &voter : son_voters) {
|
for (const auto &voter : son_bitcoin_voters) {
|
||||||
// voters_for_son.voters.emplace_back(voter.get_id());
|
voters_for_bitcoin_son.voters.emplace_back(voter.get_id());
|
||||||
// }
|
}
|
||||||
// result.voters_for_son = std::move(voters_for_son);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@ namespace graphene { namespace chain {
|
||||||
optional<voters_info_object> voters_for_witness;
|
optional<voters_info_object> voters_for_witness;
|
||||||
optional<vector<voters_info_object> > voters_for_workers;
|
optional<vector<voters_info_object> > voters_for_workers;
|
||||||
optional<vector<voters_info_object> > voters_against_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
|
} } // graphene::chain
|
||||||
|
|
@ -37,4 +38,5 @@ FC_REFLECT( graphene::chain::voters_info,
|
||||||
(voters_for_witness)
|
(voters_for_witness)
|
||||||
(voters_for_workers)
|
(voters_for_workers)
|
||||||
(voters_against_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
|
//! Check son1account voters
|
||||||
auto voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
auto voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
||||||
BOOST_REQUIRE(voters_for_son1account.voters_for_son);
|
BOOST_REQUIRE(voters_for_son1account.voters_for_bitcoin_son);
|
||||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->voters.size(), 1);
|
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_bitcoin_son->voters.size(), 1);
|
||||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_son->voters[0].instance, nathan_account_object.id.instance());
|
BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_bitcoin_son->voters[0].instance, nathan_account_object.id.instance());
|
||||||
|
|
||||||
//! Check son2account voters
|
//! Check son2account voters
|
||||||
auto voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
auto voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
||||||
BOOST_REQUIRE(voters_for_son2account.voters_for_son);
|
BOOST_REQUIRE(voters_for_son2account.voters_for_bitcoin_son);
|
||||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->voters.size(), 1);
|
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_bitcoin_son->voters.size(), 1);
|
||||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_son->voters[0].instance, nathan_account_object.id.instance());
|
BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_bitcoin_son->voters[0].instance, nathan_account_object.id.instance());
|
||||||
|
|
||||||
//! 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");
|
||||||
|
|
@ -285,8 +285,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
||||||
|
|
||||||
//! Check son1account voters
|
//! Check son1account voters
|
||||||
voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
||||||
BOOST_REQUIRE(voters_for_son1account.voters_for_son);
|
BOOST_REQUIRE(voters_for_son1account.voters_for_bitcoin_son);
|
||||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->voters.size(), 0);
|
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_bitcoin_son->voters.size(), 0);
|
||||||
|
|
||||||
//! 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");
|
||||||
|
|
@ -306,8 +306,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
||||||
|
|
||||||
//! Check son2account voters
|
//! Check son2account voters
|
||||||
voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
||||||
BOOST_REQUIRE(voters_for_son2account.voters_for_son);
|
BOOST_REQUIRE(voters_for_son2account.voters_for_bitcoin_son);
|
||||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->voters.size(), 0);
|
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_bitcoin_son->voters.size(), 0);
|
||||||
|
|
||||||
//! 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");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue