#319 vote id type as map

This commit is contained in:
Vlad Dobromyslov 2022-03-18 21:47:19 +00:00 committed by serkixenos
parent 1ec31b06f1
commit 37fdcd7dea
10 changed files with 139 additions and 187 deletions

View file

@ -2138,13 +2138,22 @@ 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_bitcoin_ids = get_votes_objects<son_index, by_vote_id_bitcoin>(votes_ids, 5); const auto son_ids = [this, &votes_ids]()
const auto &son_hive_ids = get_votes_objects<son_index, by_vote_id_hive>(votes_ids, 5); {
flat_map<sidechain_type, vector<variant> > son_ids;
const auto son_bitcoin_ids = get_votes_objects<son_index, by_vote_id_bitcoin>(votes_ids, 5);
if (!son_bitcoin_ids.empty())
son_ids[sidechain_type::bitcoin] = std::move(son_bitcoin_ids);
const auto son_hive_ids = get_votes_objects<son_index, by_vote_id_hive>(votes_ids, 5);
if (!son_hive_ids.empty())
son_ids[sidechain_type::hive] = std::move(son_hive_ids);
return son_ids;
}();
//! Fill votes info //! Fill votes info
if (!committee_ids.empty()) { if (!committee_ids.empty()) {
@ -2187,24 +2196,19 @@ 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_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()); for(const auto& son_sidechain_ids : son_ids)
for (const auto &son : son_bitcoin_ids) { {
const auto &son_obj = son.as<son_object>(6); const auto& sidechain = son_sidechain_ids.first;
votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id_bitcoin, son_obj.id}); const auto& sidechain_ids = son_sidechain_ids.second;
votes_for_sons[sidechain].reserve(sidechain_ids.size());
for (const auto &son : sidechain_ids) {
const auto &son_obj = son.as<son_object>(6);
votes_for_sons[sidechain].emplace_back(votes_info_object{son_obj.get_sidechain_vote_id(sidechain), son_obj.id});
}
} }
result.votes_for_bitcoin_sons = std::move(votes_for_sons); result.votes_for_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;
@ -2376,22 +2380,18 @@ voters_info database_api_impl::get_voters(const string &account_name_or_id) cons
//! Info for son voters //! Info for son voters
if (son_object) { if (son_object) {
const auto &son_bitcoin_voters = get_voters_by_id(son_object->vote_id_bitcoin); flat_map<sidechain_type, voters_info_object> voters_for_son;
voters_info_object voters_for_bitcoin_son; for (const auto& vote_id : son_object->sidechain_vote_ids) {
voters_for_bitcoin_son.vote_id = son_object->vote_id_bitcoin; const auto &son_voters = get_voters_by_id(vote_id.second);
voters_for_bitcoin_son.voters.reserve(son_bitcoin_voters.size()); voters_info_object voters_for_sidechain_son;
for (const auto &voter : son_bitcoin_voters) { voters_for_sidechain_son.vote_id = vote_id.second;
voters_for_bitcoin_son.voters.emplace_back(voter.get_id()); voters_for_sidechain_son.voters.reserve(son_voters.size());
for (const auto &voter : son_voters) {
voters_for_sidechain_son.voters.emplace_back(voter.get_id());
}
voters_for_son[vote_id.first] = std::move(voters_for_sidechain_son);
} }
const auto &son_hive_voters = get_voters_by_id(son_object->vote_id_hive); result.voters_for_son = std::move(voters_for_son);
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;

View file

@ -92,33 +92,15 @@ vector<std::reference_wrapper<const son_object>> database::sort_votable_objects<
count = std::min(count, refs.size()); count = std::min(count, refs.size());
std::partial_sort(refs.begin(), refs.begin() + count, refs.end(), std::partial_sort(refs.begin(), refs.begin() + count, refs.end(),
[this, sidechain](const son_object& a, const son_object& b)->bool { [this, sidechain](const son_object& a, const son_object& b)->bool {
share_type oa_vote = 0; FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
share_type ob_vote = 0;
switch (sidechain) { const share_type oa_vote = _vote_tally_buffer[a.get_sidechain_vote_id(sidechain)];
case sidechain_type::bitcoin: const share_type ob_vote = _vote_tally_buffer[b.get_sidechain_vote_id(sidechain)];
oa_vote = _vote_tally_buffer[a.vote_id_bitcoin];
ob_vote = _vote_tally_buffer[b.vote_id_bitcoin];
break;
case sidechain_type::hive:
oa_vote = _vote_tally_buffer[a.vote_id_hive];
ob_vote = _vote_tally_buffer[b.vote_id_hive];
break;
default:
FC_THROW("Unexpected sidechain type");
};
if( oa_vote != ob_vote ) if( oa_vote != ob_vote )
return oa_vote > ob_vote; return oa_vote > ob_vote;
switch (sidechain) { return a.get_sidechain_vote_id(sidechain) < b.get_sidechain_vote_id(sidechain);
case sidechain_type::bitcoin:
return a.vote_id_bitcoin < b.vote_id_bitcoin;
case sidechain_type::hive:
return a.vote_id_hive < b.vote_id_hive;
default:
FC_THROW("Unexpected sidechain type");
};
return 0;
}); });
refs.resize(count, refs.front()); refs.resize(count, refs.front());
@ -209,8 +191,10 @@ void database::pay_sons()
uint64_t total_votes = 0; uint64_t total_votes = 0;
for( const son_object& son : sons ) for( const son_object& son : sons )
{ {
total_votes += _vote_tally_buffer[son.vote_id_bitcoin]; for(const auto& vote_id : son.sidechain_vote_ids)
total_votes += _vote_tally_buffer[son.vote_id_hive]; {
total_votes += _vote_tally_buffer[vote_id.second];
}
} }
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0); int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
auto get_weight = [&bits_to_drop]( uint64_t son_votes ) { auto get_weight = [&bits_to_drop]( uint64_t son_votes ) {
@ -229,11 +213,16 @@ void database::pay_sons()
const son_statistics_object& s = static_cast<const son_statistics_object&>(o); const son_statistics_object& s = static_cast<const son_statistics_object&>(o);
const auto& idx = get_index_type<son_index>().indices().get<by_id>(); const auto& idx = get_index_type<son_index>().indices().get<by_id>();
auto son_obj = idx.find( s.owner ); auto son_obj = idx.find( s.owner );
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id_bitcoin]) + uint16_t son_weight = 0;
get_weight(_vote_tally_buffer[son_obj->vote_id_hive]); if( now >= HARDFORK_SON2_TIME ) {
if( now < HARDFORK_SON2_TIME ) { for (const auto& vote_id : son_obj->sidechain_vote_ids) {
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_bitcoin]) + son_weight += get_weight(_vote_tally_buffer[vote_id.second]);
get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_hive]); }
}
else {
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[vote_id.second]);
}
} }
uint64_t txs_signed = 0; uint64_t txs_signed = 0;
for (const auto &ts : s.txs_signed) { for (const auto &ts : s.txs_signed) {
@ -253,11 +242,16 @@ void database::pay_sons()
if(txs_signed > 0){ if(txs_signed > 0){
const auto& idx = get_index_type<son_index>().indices().get<by_id>(); const auto& idx = get_index_type<son_index>().indices().get<by_id>();
auto son_obj = idx.find( s.owner ); auto son_obj = idx.find( s.owner );
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id_bitcoin]) + uint16_t son_weight = 0;
get_weight(_vote_tally_buffer[son_obj->vote_id_hive]); if( now >= HARDFORK_SON2_TIME ) {
if( now < HARDFORK_SON2_TIME ) { for (const auto& vote_id : son_obj->sidechain_vote_ids) {
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_bitcoin]) + son_weight += get_weight(_vote_tally_buffer[vote_id.second]);
get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_hive]); }
}
else {
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
son_weight += get_weight_before_son2_hf(_vote_tally_buffer[vote_id.second]);
}
} }
share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed; share_type pay = (txs_signed * son_weight * son_budget.value)/weighted_total_txs_signed;
modify( *son_obj, [&]( son_object& _son_obj) modify( *son_obj, [&]( son_object& _son_obj)
@ -722,7 +716,8 @@ void database::update_active_sons()
}); });
} }
modify( son, [local_vote_buffer_ref]( son_object& obj ){ modify( son, [local_vote_buffer_ref]( son_object& obj ){
obj.total_votes = local_vote_buffer_ref[obj.vote_id_bitcoin]; //! FIXME - only bitcoin_vote_id ???
obj.total_votes = local_vote_buffer_ref[obj.get_bitcoin_vote_id()];
if(obj.status == son_status::request_maintenance) if(obj.status == son_status::request_maintenance)
obj.status = son_status::in_maintenance; obj.status = son_status::in_maintenance;
}); });

View file

@ -31,7 +31,7 @@ namespace graphene { namespace chain {
time_point_sec expires; time_point_sec expires;
sidechain_address_object() : sidechain_address_object() :
sidechain(sidechain_type::bitcoin), sidechain(sidechain_type::bitcoin), //! FIXME - bitcoin ???
deposit_public_key(""), deposit_public_key(""),
deposit_address(""), deposit_address(""),
withdraw_public_key(""), withdraw_public_key(""),

View file

@ -16,9 +16,9 @@ enum class sidechain_type {
} } } }
FC_REFLECT_ENUM(graphene::chain::sidechain_type, FC_REFLECT_ENUM(graphene::chain::sidechain_type,
(unknown) (unknown)
(bitcoin) (bitcoin)
(ethereum) (ethereum)
(eos) (eos)
(hive) (hive)
(peerplays) ) (peerplays) )

View file

@ -64,8 +64,7 @@ namespace graphene { namespace chain {
static const uint8_t type_id = son_object_type; static const uint8_t type_id = son_object_type;
account_id_type son_account; account_id_type son_account;
vote_id_type vote_id_bitcoin; flat_map<sidechain_type, vote_id_type> sidechain_vote_ids;
vote_id_type vote_id_hive;
uint64_t total_votes = 0; uint64_t total_votes = 0;
string url; string url;
vesting_balance_id_type deposit; vesting_balance_id_type deposit;
@ -79,8 +78,9 @@ namespace graphene { namespace chain {
bool has_valid_config()const; bool has_valid_config()const;
bool has_valid_config(time_point_sec head_block_time)const; bool has_valid_config(time_point_sec head_block_time)const;
inline vote_id_type get_vote_id_bitcoin() const { return vote_id_bitcoin; } inline vote_id_type get_sidechain_vote_id(sidechain_type sidechain) const { return sidechain_vote_ids.at(sidechain); }
inline vote_id_type get_vote_id_hive() const { return vote_id_hive; } inline vote_id_type get_bitcoin_vote_id() const { return get_sidechain_vote_id(sidechain_type::bitcoin); }
inline vote_id_type get_hive_vote_id() const { return get_sidechain_vote_id(sidechain_type::hive); }
}; };
struct by_account; struct by_account;
@ -96,10 +96,10 @@ namespace graphene { namespace chain {
member<son_object, account_id_type, &son_object::son_account> member<son_object, account_id_type, &son_object::son_account>
>, >,
ordered_unique< tag<by_vote_id_bitcoin>, ordered_unique< tag<by_vote_id_bitcoin>,
const_mem_fun<son_object, vote_id_type, &son_object::get_vote_id_bitcoin> const_mem_fun<son_object, vote_id_type, &son_object::get_bitcoin_vote_id>
>, >,
ordered_unique< tag<by_vote_id_hive>, ordered_unique< tag<by_vote_id_hive>,
const_mem_fun<son_object, vote_id_type, &son_object::get_vote_id_hive> const_mem_fun<son_object, vote_id_type, &son_object::get_hive_vote_id>
> >
> >
>; >;
@ -125,8 +125,7 @@ FC_REFLECT_ENUM(graphene::chain::son_status, (inactive)(active)(request_maintena
FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object), FC_REFLECT_DERIVED( graphene::chain::son_object, (graphene::db::object),
(son_account) (son_account)
(vote_id_bitcoin) (sidechain_vote_ids)
(vote_id_hive)
(total_votes) (total_votes)
(url) (url)
(deposit) (deposit)

View file

@ -19,12 +19,11 @@ namespace graphene { namespace chain {
* @ingroup object * @ingroup object
*/ */
struct voters_info { struct voters_info {
optional<voters_info_object> voters_for_committee_member; optional<voters_info_object> voters_for_committee_member;
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_bitcoin_son; optional<flat_map<sidechain_type, voters_info_object> > voters_for_son;
optional<voters_info_object> voters_for_hive_son;
}; };
} } // graphene::chain } } // graphene::chain
@ -38,5 +37,4 @@ 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_bitcoin_son) (voters_for_son))
(voters_for_hive_son))

View file

@ -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))

View file

@ -47,8 +47,8 @@ object_id_type create_son_evaluator::do_apply(const son_create_operation& op)
const auto& new_son_object = db().create<son_object>( [&]( son_object& obj ){ const auto& new_son_object = db().create<son_object>( [&]( son_object& obj ){
obj.son_account = op.owner_account; obj.son_account = op.owner_account;
obj.vote_id_bitcoin = vote_id_bitcoin; obj.sidechain_vote_ids[sidechain_type::bitcoin] = vote_id_bitcoin;
obj.vote_id_hive = vote_id_hive; obj.sidechain_vote_ids[sidechain_type::hive] = vote_id_hive;
obj.url = op.url; obj.url = op.url;
obj.deposit = op.deposit; obj.deposit = op.deposit;
obj.signing_key = op.signing_key; obj.signing_key = op.signing_key;

View file

@ -2757,30 +2757,18 @@ public:
account_object voting_account_object = get_account(voting_account); account_object voting_account_object = get_account(voting_account);
account_id_type son_account_id = get_account_id(son); account_id_type son_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_account_id); fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_account_id);
if (!son_obj) FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
FC_THROW("Account ${son} is not registered as a son", ("son", son)); FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
vote_id_type sidechain_vote_id;
switch (sidechain) {
case sidechain_type::bitcoin:
sidechain_vote_id = son_obj->vote_id_bitcoin;
break;
case sidechain_type::hive:
sidechain_vote_id = son_obj->vote_id_hive;
break;
default:
FC_THROW("Invalid sidechain type");
};
if (approve) if (approve)
{ {
auto insert_result = voting_account_object.options.votes.insert(sidechain_vote_id); auto insert_result = voting_account_object.options.votes.insert(son_obj->get_sidechain_vote_id(sidechain));
if (!insert_result.second) if (!insert_result.second)
FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain)); FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
} }
else else
{ {
unsigned votes_removed = voting_account_object.options.votes.erase(sidechain_vote_id); unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->get_sidechain_vote_id(sidechain));
if (!votes_removed) if (!votes_removed)
FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain)); FC_THROW("Account ${account} has already unvoted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
} }
@ -2815,20 +2803,10 @@ public:
{ {
account_id_type son_owner_account_id = get_account_id(son); account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id); fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
if (!son_obj) FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
FC_THROW("Account ${son} is not registered as a SON", ("son", son)); FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
vote_id_type sidechain_vote_id;
switch (sidechain) { auto insert_result = voting_account_object.options.votes.insert(son_obj->get_sidechain_vote_id(sidechain));
case sidechain_type::bitcoin:
sidechain_vote_id = son_obj->vote_id_bitcoin;
break;
case sidechain_type::hive:
sidechain_vote_id = son_obj->vote_id_hive;
break;
default:
FC_THROW("Invalid sidechain type");
};
auto insert_result = voting_account_object.options.votes.insert(sidechain_vote_id);
if (!insert_result.second) if (!insert_result.second)
FC_THROW("Account ${account} was already voting for SON ${son}", ("account", voting_account)("son", son)); FC_THROW("Account ${account} was already voting for SON ${son}", ("account", voting_account)("son", son));
} }
@ -2836,20 +2814,10 @@ public:
{ {
account_id_type son_owner_account_id = get_account_id(son); account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id); fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
if (!son_obj) FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
FC_THROW("Account ${son} is not registered as a SON", ("son", son)); FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
vote_id_type sidechain_vote_id;
switch (sidechain) { unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->get_sidechain_vote_id(sidechain));
case sidechain_type::bitcoin:
sidechain_vote_id = son_obj->vote_id_bitcoin;
break;
case sidechain_type::hive:
sidechain_vote_id = son_obj->vote_id_hive;
break;
default:
FC_THROW("Invalid sidechain type");
};
unsigned votes_removed = voting_account_object.options.votes.erase(sidechain_vote_id);
if (!votes_removed) if (!votes_removed)
FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son)); FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son));
} }

View file

@ -257,31 +257,29 @@ 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_bitcoin_son); BOOST_REQUIRE(voters_for_son1account.voters_for_son);
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_bitcoin_son->voters.size(), 1); BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->at(sidechain_type::bitcoin).voters.size(), 1);
BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_bitcoin_son->voters[0].instance, nathan_account_object.id.instance()); BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_son->at(sidechain_type::bitcoin).voters[0].instance, nathan_account_object.id.instance());
BOOST_REQUIRE(voters_for_son1account.voters_for_hive_son); BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->at(sidechain_type::hive).voters.size(), 1);
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_hive_son->voters.size(), 1); BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_son->at(sidechain_type::hive).voters[0].instance, nathan_account_object.id.instance());
BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_hive_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_bitcoin_son); BOOST_REQUIRE(voters_for_son2account.voters_for_son);
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_bitcoin_son->voters.size(), 1); BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->at(sidechain_type::bitcoin).voters.size(), 1);
BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_bitcoin_son->voters[0].instance, nathan_account_object.id.instance()); BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_son->at(sidechain_type::bitcoin).voters[0].instance, nathan_account_object.id.instance());
BOOST_REQUIRE(voters_for_son2account.voters_for_hive_son); BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->at(sidechain_type::hive).voters.size(), 1);
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_hive_son->voters.size(), 1); BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_son->at(sidechain_type::hive).voters[0].instance, nathan_account_object.id.instance());
BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_hive_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");
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");
@ -296,19 +294,17 @@ 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_bitcoin_son); BOOST_REQUIRE(voters_for_son1account.voters_for_son);
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_bitcoin_son->voters.size(), 0); BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->at(sidechain_type::bitcoin).voters.size(), 0);
BOOST_REQUIRE(voters_for_son1account.voters_for_hive_son); BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->at(sidechain_type::hive).voters.size(), 0);
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_hive_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");
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");
@ -323,15 +319,13 @@ 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_bitcoin_son); BOOST_REQUIRE(voters_for_son2account.voters_for_son);
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_bitcoin_son->voters.size(), 0); BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->at(sidechain_type::bitcoin).voters.size(), 0);
BOOST_REQUIRE(voters_for_son2account.voters_for_hive_son); BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->at(sidechain_type::hive).voters.size(), 0);
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_hive_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");
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");