Merge branch 'feature/319-vote_id_type-as-map' into 'feature/son-for-hive-voting'
#319 vote id type as map See merge request PBSA/peerplays!86
This commit is contained in:
commit
197fcb0fe2
10 changed files with 139 additions and 187 deletions
|
|
@ -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 result;
|
||||
|
||||
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 &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 &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_hive_ids = get_votes_objects<son_index, by_vote_id_hive>(votes_ids, 5);
|
||||
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 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 against_worker_ids = get_votes_objects<worker_index, by_vote_against>(votes_ids);
|
||||
const auto son_ids = [this, &votes_ids]()
|
||||
{
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
if (!son_bitcoin_ids.empty()) {
|
||||
vector<votes_info_object> votes_for_sons;
|
||||
votes_for_sons.reserve(son_bitcoin_ids.size());
|
||||
for (const auto &son : son_bitcoin_ids) {
|
||||
const auto &son_obj = son.as<son_object>(6);
|
||||
votes_for_sons.emplace_back(votes_info_object{son_obj.vote_id_bitcoin, son_obj.id});
|
||||
if (!son_ids.empty()) {
|
||||
flat_map<sidechain_type, vector< votes_info_object > > votes_for_sons;
|
||||
for(const auto& son_sidechain_ids : son_ids)
|
||||
{
|
||||
const auto& sidechain = son_sidechain_ids.first;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
result.votes_for_sons = std::move(votes_for_sons);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -2376,22 +2380,18 @@ voters_info database_api_impl::get_voters(const string &account_name_or_id) cons
|
|||
|
||||
//! 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());
|
||||
flat_map<sidechain_type, voters_info_object> voters_for_son;
|
||||
for (const auto& vote_id : son_object->sidechain_vote_ids) {
|
||||
const auto &son_voters = get_voters_by_id(vote_id.second);
|
||||
voters_info_object voters_for_sidechain_son;
|
||||
voters_for_sidechain_son.vote_id = vote_id.second;
|
||||
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);
|
||||
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);
|
||||
result.voters_for_son = std::move(voters_for_son);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -92,33 +92,15 @@ vector<std::reference_wrapper<const son_object>> database::sort_votable_objects<
|
|||
count = std::min(count, refs.size());
|
||||
std::partial_sort(refs.begin(), refs.begin() + count, refs.end(),
|
||||
[this, sidechain](const son_object& a, const son_object& b)->bool {
|
||||
share_type oa_vote = 0;
|
||||
share_type ob_vote = 0;
|
||||
switch (sidechain) {
|
||||
case sidechain_type::bitcoin:
|
||||
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");
|
||||
};
|
||||
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
|
||||
|
||||
const share_type oa_vote = _vote_tally_buffer[a.get_sidechain_vote_id(sidechain)];
|
||||
const share_type ob_vote = _vote_tally_buffer[b.get_sidechain_vote_id(sidechain)];
|
||||
|
||||
if( oa_vote != ob_vote )
|
||||
return oa_vote > ob_vote;
|
||||
|
||||
switch (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;
|
||||
return a.get_sidechain_vote_id(sidechain) < b.get_sidechain_vote_id(sidechain);
|
||||
});
|
||||
|
||||
refs.resize(count, refs.front());
|
||||
|
|
@ -209,8 +191,10 @@ void database::pay_sons()
|
|||
uint64_t total_votes = 0;
|
||||
for( const son_object& son : sons )
|
||||
{
|
||||
total_votes += _vote_tally_buffer[son.vote_id_bitcoin];
|
||||
total_votes += _vote_tally_buffer[son.vote_id_hive];
|
||||
for(const auto& vote_id : son.sidechain_vote_ids)
|
||||
{
|
||||
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);
|
||||
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 auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
||||
auto son_obj = idx.find( s.owner );
|
||||
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
||||
get_weight(_vote_tally_buffer[son_obj->vote_id_hive]);
|
||||
if( now < HARDFORK_SON2_TIME ) {
|
||||
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
||||
get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_hive]);
|
||||
uint16_t son_weight = 0;
|
||||
if( now >= HARDFORK_SON2_TIME ) {
|
||||
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
|
||||
son_weight += get_weight(_vote_tally_buffer[vote_id.second]);
|
||||
}
|
||||
}
|
||||
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;
|
||||
for (const auto &ts : s.txs_signed) {
|
||||
|
|
@ -253,11 +242,16 @@ void database::pay_sons()
|
|||
if(txs_signed > 0){
|
||||
const auto& idx = get_index_type<son_index>().indices().get<by_id>();
|
||||
auto son_obj = idx.find( s.owner );
|
||||
auto son_weight = get_weight(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
||||
get_weight(_vote_tally_buffer[son_obj->vote_id_hive]);
|
||||
if( now < HARDFORK_SON2_TIME ) {
|
||||
son_weight = get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_bitcoin]) +
|
||||
get_weight_before_son2_hf(_vote_tally_buffer[son_obj->vote_id_hive]);
|
||||
uint16_t son_weight = 0;
|
||||
if( now >= HARDFORK_SON2_TIME ) {
|
||||
for (const auto& vote_id : son_obj->sidechain_vote_ids) {
|
||||
son_weight += get_weight(_vote_tally_buffer[vote_id.second]);
|
||||
}
|
||||
}
|
||||
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;
|
||||
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 ){
|
||||
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)
|
||||
obj.status = son_status::in_maintenance;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace graphene { namespace chain {
|
|||
time_point_sec expires;
|
||||
|
||||
sidechain_address_object() :
|
||||
sidechain(sidechain_type::bitcoin),
|
||||
sidechain(sidechain_type::bitcoin), //! FIXME - bitcoin ???
|
||||
deposit_public_key(""),
|
||||
deposit_address(""),
|
||||
withdraw_public_key(""),
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ enum class sidechain_type {
|
|||
} }
|
||||
|
||||
FC_REFLECT_ENUM(graphene::chain::sidechain_type,
|
||||
(unknown)
|
||||
(bitcoin)
|
||||
(ethereum)
|
||||
(eos)
|
||||
(hive)
|
||||
(peerplays) )
|
||||
(unknown)
|
||||
(bitcoin)
|
||||
(ethereum)
|
||||
(eos)
|
||||
(hive)
|
||||
(peerplays) )
|
||||
|
|
|
|||
|
|
@ -64,8 +64,7 @@ namespace graphene { namespace chain {
|
|||
static const uint8_t type_id = son_object_type;
|
||||
|
||||
account_id_type son_account;
|
||||
vote_id_type vote_id_bitcoin;
|
||||
vote_id_type vote_id_hive;
|
||||
flat_map<sidechain_type, vote_id_type> sidechain_vote_ids;
|
||||
uint64_t total_votes = 0;
|
||||
string url;
|
||||
vesting_balance_id_type deposit;
|
||||
|
|
@ -79,8 +78,9 @@ namespace graphene { namespace chain {
|
|||
bool has_valid_config()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_vote_id_hive() const { return vote_id_hive; }
|
||||
inline vote_id_type get_sidechain_vote_id(sidechain_type sidechain) const { return sidechain_vote_ids.at(sidechain); }
|
||||
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;
|
||||
|
|
@ -96,10 +96,10 @@ namespace graphene { namespace chain {
|
|||
member<son_object, account_id_type, &son_object::son_account>
|
||||
>,
|
||||
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>,
|
||||
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),
|
||||
(son_account)
|
||||
(vote_id_bitcoin)
|
||||
(vote_id_hive)
|
||||
(sidechain_vote_ids)
|
||||
(total_votes)
|
||||
(url)
|
||||
(deposit)
|
||||
|
|
|
|||
|
|
@ -19,12 +19,11 @@ namespace graphene { namespace chain {
|
|||
* @ingroup object
|
||||
*/
|
||||
struct voters_info {
|
||||
optional<voters_info_object> voters_for_committee_member;
|
||||
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_bitcoin_son;
|
||||
optional<voters_info_object> voters_for_hive_son;
|
||||
optional<voters_info_object> voters_for_committee_member;
|
||||
optional<voters_info_object> voters_for_witness;
|
||||
optional<vector<voters_info_object> > voters_for_workers;
|
||||
optional<vector<voters_info_object> > voters_against_workers;
|
||||
optional<flat_map<sidechain_type, voters_info_object> > voters_for_son;
|
||||
};
|
||||
|
||||
} } // graphene::chain
|
||||
|
|
@ -38,5 +37,4 @@ FC_REFLECT( graphene::chain::voters_info,
|
|||
(voters_for_witness)
|
||||
(voters_for_workers)
|
||||
(voters_against_workers)
|
||||
(voters_for_bitcoin_son)
|
||||
(voters_for_hive_son))
|
||||
(voters_for_son))
|
||||
|
|
@ -19,12 +19,11 @@ namespace graphene { namespace chain {
|
|||
* @ingroup object
|
||||
*/
|
||||
struct votes_info {
|
||||
optional< vector< votes_info_object > > votes_for_committee_members;
|
||||
optional< vector< votes_info_object > > votes_for_witnesses;
|
||||
optional< vector< votes_info_object > > votes_for_workers;
|
||||
optional< vector< votes_info_object > > votes_against_workers;
|
||||
optional< vector< votes_info_object > > votes_for_bitcoin_sons;
|
||||
optional< vector< votes_info_object > > votes_for_hive_sons;
|
||||
optional< vector< votes_info_object > > votes_for_committee_members;
|
||||
optional< vector< votes_info_object > > votes_for_witnesses;
|
||||
optional< vector< votes_info_object > > votes_for_workers;
|
||||
optional< vector< votes_info_object > > votes_against_workers;
|
||||
optional< flat_map<sidechain_type, vector< votes_info_object > > > votes_for_sons;
|
||||
};
|
||||
|
||||
} } // graphene::chain
|
||||
|
|
@ -38,5 +37,4 @@ FC_REFLECT( graphene::chain::votes_info,
|
|||
(votes_for_witnesses)
|
||||
(votes_for_workers)
|
||||
(votes_against_workers)
|
||||
(votes_for_bitcoin_sons)
|
||||
(votes_for_hive_sons))
|
||||
(votes_for_sons))
|
||||
|
|
@ -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 ){
|
||||
obj.son_account = op.owner_account;
|
||||
obj.vote_id_bitcoin = vote_id_bitcoin;
|
||||
obj.vote_id_hive = vote_id_hive;
|
||||
obj.sidechain_vote_ids[sidechain_type::bitcoin] = vote_id_bitcoin;
|
||||
obj.sidechain_vote_ids[sidechain_type::hive] = vote_id_hive;
|
||||
obj.url = op.url;
|
||||
obj.deposit = op.deposit;
|
||||
obj.signing_key = op.signing_key;
|
||||
|
|
|
|||
|
|
@ -2757,30 +2757,18 @@ public:
|
|||
account_object voting_account_object = get_account(voting_account);
|
||||
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);
|
||||
if (!son_obj)
|
||||
FC_THROW("Account ${son} is not registered as a son", ("son", son));
|
||||
|
||||
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");
|
||||
};
|
||||
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
|
||||
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
|
||||
|
||||
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)
|
||||
FC_THROW("Account ${account} has already voted for son ${son} for sidechain ${sidechain}", ("account", voting_account)("son", son)("sidechain", sidechain));
|
||||
}
|
||||
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)
|
||||
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);
|
||||
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
|
||||
if (!son_obj)
|
||||
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
|
||||
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");
|
||||
};
|
||||
auto insert_result = voting_account_object.options.votes.insert(sidechain_vote_id);
|
||||
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
|
||||
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
|
||||
|
||||
auto insert_result = voting_account_object.options.votes.insert(son_obj->get_sidechain_vote_id(sidechain));
|
||||
if (!insert_result.second)
|
||||
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);
|
||||
fc::optional<son_object> son_obj = _remote_db->get_son_by_account_id(son_owner_account_id);
|
||||
if (!son_obj)
|
||||
FC_THROW("Account ${son} is not registered as a SON", ("son", son));
|
||||
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");
|
||||
};
|
||||
unsigned votes_removed = voting_account_object.options.votes.erase(sidechain_vote_id);
|
||||
FC_ASSERT(son_obj, "Account ${son} is not registered as a son", ("son", son));
|
||||
FC_ASSERT(sidechain == sidechain_type::bitcoin || sidechain == sidechain_type::hive, "Unexpected sidechain type");
|
||||
|
||||
unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->get_sidechain_vote_id(sidechain));
|
||||
if (!votes_removed)
|
||||
FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -257,31 +257,29 @@ 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_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());
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_hive_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_hive_son->voters.size(), 1);
|
||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son1account.voters_for_hive_son->voters[0].instance, nathan_account_object.id.instance());
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_son);
|
||||
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_son->at(sidechain_type::bitcoin).voters[0].instance, nathan_account_object.id.instance());
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->at(sidechain_type::hive).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());
|
||||
|
||||
//! Check son2account voters
|
||||
auto voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
||||
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());
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_hive_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_hive_son->voters.size(), 1);
|
||||
BOOST_CHECK_EQUAL((uint32_t)voters_for_son2account.voters_for_hive_son->voters[0].instance, nathan_account_object.id.instance());
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_son);
|
||||
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_son->at(sidechain_type::bitcoin).voters[0].instance, nathan_account_object.id.instance());
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->at(sidechain_type::hive).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());
|
||||
|
||||
//! Check votes of nathan
|
||||
auto nathan_votes = con.wallet_api_ptr->get_votes("nathan");
|
||||
BOOST_REQUIRE(nathan_votes.votes_for_bitcoin_sons);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->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_bitcoin_sons->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_hive_sons->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_REQUIRE(nathan_votes.votes_for_sons);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::bitcoin).size(), 2);
|
||||
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_sons->at(sidechain_type::bitcoin).at(1).id.instance(), son2_obj.id.instance());
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).size(), 2);
|
||||
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_sons->at(sidechain_type::hive).at(1).id.instance(), son2_obj.id.instance());
|
||||
|
||||
// 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
|
||||
voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_bitcoin_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_bitcoin_son->voters.size(), 0);
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_hive_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_hive_son->voters.size(), 0);
|
||||
BOOST_REQUIRE(voters_for_son1account.voters_for_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->at(sidechain_type::bitcoin).voters.size(), 0);
|
||||
BOOST_CHECK_EQUAL(voters_for_son1account.voters_for_son->at(sidechain_type::hive).voters.size(), 0);
|
||||
|
||||
//! Check votes of nathan
|
||||
nathan_votes = con.wallet_api_ptr->get_votes("nathan");
|
||||
BOOST_REQUIRE(nathan_votes.votes_for_bitcoin_sons);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->size(), 1);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_bitcoin_sons->at(0).id.instance(), son2_obj.id.instance());
|
||||
BOOST_REQUIRE(nathan_votes.votes_for_hive_sons);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_hive_sons->size(), 1);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_hive_sons->at(0).id.instance(), son2_obj.id.instance());
|
||||
BOOST_REQUIRE(nathan_votes.votes_for_sons);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::bitcoin).size(), 1);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::bitcoin).at(0).id.instance(), son2_obj.id.instance());
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).size(), 1);
|
||||
BOOST_CHECK_EQUAL(nathan_votes.votes_for_sons->at(sidechain_type::hive).at(0).id.instance(), son2_obj.id.instance());
|
||||
|
||||
// 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
|
||||
voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_bitcoin_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_bitcoin_son->voters.size(), 0);
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_hive_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_hive_son->voters.size(), 0);
|
||||
BOOST_REQUIRE(voters_for_son2account.voters_for_son);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->at(sidechain_type::bitcoin).voters.size(), 0);
|
||||
BOOST_CHECK_EQUAL(voters_for_son2account.voters_for_son->at(sidechain_type::hive).voters.size(), 0);
|
||||
|
||||
//! Check votes of 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_hive_sons.valid());
|
||||
BOOST_CHECK(!nathan_votes.votes_for_sons.valid());
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
|
||||
|
|
|
|||
Loading…
Reference in a new issue