#339 refactor sidechain type #677

Merged
vampik merged 27 commits from feature/339-refactor-sidechain_type into feature/son-for-hive-voting 2022-04-12 16:39:05 +00:00
Showing only changes of commit b09c22b224 - Show all commits

View file

@ -310,22 +310,22 @@ const son_object peerplays_sidechain_plugin_impl::get_son_object(son_id_type son
return *son_obj;
}
//! Fixme - do we need to provide sidechain_type as param for this function?
bool peerplays_sidechain_plugin_impl::is_active_son(son_id_type son_id) {
const auto &idx = plugin.database().get_index_type<chain::son_index>().indices().get<by_id>();
auto son_obj = idx.find(son_id);
if (son_obj == idx.end())
return false;
//! Fixme - now only bitcoin, fix according to sidechain_type
const chain::global_property_object &gpo = plugin.database().get_global_properties();
vector<son_id_type> active_son_ids;
active_son_ids.reserve(gpo.active_sons.at(sidechain_type::bitcoin).size());
std::transform(gpo.active_sons.at(sidechain_type::bitcoin).cbegin(), gpo.active_sons.at(sidechain_type::bitcoin).cend(),
std::inserter(active_son_ids, active_son_ids.end()),
[](const son_info &swi) {
return swi.son_id;
});
set<son_id_type> active_son_ids;
for(const auto& active_sidechain_type : active_sidechain_types) {
std::transform(gpo.active_sons.at(active_sidechain_type).cbegin(), gpo.active_sons.at(active_sidechain_type).cend(),
std::inserter(active_son_ids, active_son_ids.end()),
[](const son_info &swi) {
return swi.son_id;
});
}
auto it = std::find(active_son_ids.begin(), active_son_ids.end(), son_id);
@ -456,9 +456,13 @@ void peerplays_sidechain_plugin_impl::schedule_son_processing() {
}
void peerplays_sidechain_plugin_impl::son_processing() {
//! Fixme - here we must check size for every sidechain
if (plugin.database().get_global_properties().active_sons.at(sidechain_type::bitcoin).size() <= 0 &&
plugin.database().get_global_properties().active_sons.at(sidechain_type::hive).size() <= 0) {
//! Check whether we have active SONs
bool have_active_sons = false;
for(const auto& active_sidechain_type : active_sidechain_types) {
if(plugin.database().get_global_properties().active_sons.at(active_sidechain_type).size() >= 0)
have_active_sons = true;
}
if (!have_active_sons) {
return;
}