diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 76caf599..e8a266c4 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -31,6 +31,7 @@ #include #include +#include #include diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 8b55561e..63b11a21 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -99,7 +99,7 @@ class database_api_impl : public std::enable_shared_from_this // Blinded balances vector get_blinded_balances( const flat_set& commitments )const; - private: + //private: template void subscribe_to_item( const T& i )const { @@ -960,6 +960,22 @@ vector> database_api::get_witnesses(const vectorget_witnesses( witness_ids ); } +vector database_api::get_workers_by_account(account_id_type account)const +{ + const auto& idx = my->_db.get_index_type().indices().get(); + auto itr = idx.find(account); + vector result; + + if( itr != idx.end() && itr->worker_account == account ) + { + result.emplace_back( *itr ); + ++itr; + } + + return result; +} + + vector> database_api_impl::get_witnesses(const vector& witness_ids)const { vector> result; result.reserve(witness_ids.size()); diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index c29be561..67d0cfe2 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -43,6 +43,7 @@ namespace graphene { namespace app { class application; + /** * @brief The history_api class implements the RPC API for account history * diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 8975fa1e..4aedd0ed 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -373,6 +374,15 @@ class database_api */ map lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const; + + /// WORKERS + + /** + * Return the worker objects associated with this account. + */ + vector get_workers_by_account(account_id_type account)const; + + /////////// // Votes // /////////// @@ -517,6 +527,8 @@ FC_API(graphene::app::database_api, (get_committee_member_by_account) (lookup_committee_member_accounts) + // workers + (get_workers_by_account) // Votes (lookup_vote_ids) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index dd87a9b4..cbe091ed 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -86,10 +86,10 @@ struct worker_pay_visitor void database::update_worker_votes() { auto& idx = get_index_type(); - auto itr = idx.begin(); - while( itr != idx.end() ) + auto itr = idx.indices().get().begin(); + while( itr != idx.indices().get().end() ) { - modify( **itr, [&]( worker_object& obj ){ + modify( *itr, [&]( worker_object& obj ){ obj.total_votes_for = _vote_tally_buffer[obj.vote_for]; obj.total_votes_against = _vote_tally_buffer[obj.vote_against]; }); diff --git a/libraries/chain/include/graphene/chain/worker_evaluator.hpp b/libraries/chain/include/graphene/chain/worker_evaluator.hpp index de32fa3a..5ea07106 100644 --- a/libraries/chain/include/graphene/chain/worker_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/worker_evaluator.hpp @@ -127,13 +127,29 @@ namespace graphene { namespace chain { bool is_active(fc::time_point_sec now)const { return now >= work_begin_date && now <= work_end_date; } + + /// TODO: remove unused argument share_type approving_stake(const vector& stake_vote_tallies)const { - return int64_t( total_votes_for ) - int64_t( total_votes_against );// stake_vote_tallies[vote_for] - stake_vote_tallies[vote_against]; + return int64_t( total_votes_for ) - int64_t( total_votes_against ); } }; - typedef flat_index worker_index; + struct by_account; + struct by_vote_for; + struct by_vote_against; + typedef multi_index_container< + worker_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > >, + ordered_non_unique< tag, member< worker_object, account_id_type, &worker_object::worker_account > >, + ordered_unique< tag, member< worker_object, vote_id_type, &worker_object::vote_for > >, + ordered_unique< tag, member< worker_object, vote_id_type, &worker_object::vote_against > > + > + > worker_object_multi_index_type; + + //typedef flat_index worker_index; + using worker_index = generic_index; class worker_create_evaluator : public evaluator { diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index be5cbe2a..208fa566 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -25,6 +26,7 @@ #include #include + namespace graphene { namespace delayed_node { namespace bpo = boost::program_options;