add api to query worker state
This commit is contained in:
parent
cf7a67ec76
commit
127ac7f3de
7 changed files with 54 additions and 6 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <graphene/time/time.hpp>
|
||||
|
||||
#include <graphene/utilities/key_conversion.hpp>
|
||||
#include <graphene/chain/worker_evaluator.hpp>
|
||||
|
||||
#include <fc/smart_ref_impl.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
|
|||
// Blinded balances
|
||||
vector<blinded_balance_object> get_blinded_balances( const flat_set<commitment_type>& commitments )const;
|
||||
|
||||
private:
|
||||
//private:
|
||||
template<typename T>
|
||||
void subscribe_to_item( const T& i )const
|
||||
{
|
||||
|
|
@ -960,6 +960,22 @@ vector<optional<witness_object>> database_api::get_witnesses(const vector<witnes
|
|||
return my->get_witnesses( witness_ids );
|
||||
}
|
||||
|
||||
vector<worker_object> database_api::get_workers_by_account(account_id_type account)const
|
||||
{
|
||||
const auto& idx = my->_db.get_index_type<worker_index>().indices().get<by_account>();
|
||||
auto itr = idx.find(account);
|
||||
vector<worker_object> result;
|
||||
|
||||
if( itr != idx.end() && itr->worker_account == account )
|
||||
{
|
||||
result.emplace_back( *itr );
|
||||
++itr;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
vector<optional<witness_object>> database_api_impl::get_witnesses(const vector<witness_id_type>& witness_ids)const
|
||||
{
|
||||
vector<optional<witness_object>> result; result.reserve(witness_ids.size());
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ namespace graphene { namespace app {
|
|||
|
||||
class application;
|
||||
|
||||
|
||||
/**
|
||||
* @brief The history_api class implements the RPC API for account history
|
||||
*
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <graphene/chain/market_evaluator.hpp>
|
||||
#include <graphene/chain/operation_history_object.hpp>
|
||||
#include <graphene/chain/proposal_object.hpp>
|
||||
#include <graphene/chain/worker_evaluator.hpp>
|
||||
#include <graphene/chain/witness_object.hpp>
|
||||
#include <graphene/chain/confidential_evaluator.hpp>
|
||||
|
||||
|
|
@ -373,6 +374,15 @@ class database_api
|
|||
*/
|
||||
map<string, committee_member_id_type> lookup_committee_member_accounts(const string& lower_bound_name, uint32_t limit)const;
|
||||
|
||||
|
||||
/// WORKERS
|
||||
|
||||
/**
|
||||
* Return the worker objects associated with this account.
|
||||
*/
|
||||
vector<worker_object> 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -86,10 +86,10 @@ struct worker_pay_visitor
|
|||
void database::update_worker_votes()
|
||||
{
|
||||
auto& idx = get_index_type<worker_index>();
|
||||
auto itr = idx.begin();
|
||||
while( itr != idx.end() )
|
||||
auto itr = idx.indices().get<by_account>().begin();
|
||||
while( itr != idx.indices().get<by_account>().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];
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<uint64_t>& 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_object> worker_index;
|
||||
|
||||
struct by_account;
|
||||
struct by_vote_for;
|
||||
struct by_vote_against;
|
||||
typedef multi_index_container<
|
||||
worker_object,
|
||||
indexed_by<
|
||||
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
||||
ordered_non_unique< tag<by_account>, member< worker_object, account_id_type, &worker_object::worker_account > >,
|
||||
ordered_unique< tag<by_vote_for>, member< worker_object, vote_id_type, &worker_object::vote_for > >,
|
||||
ordered_unique< tag<by_vote_against>, member< worker_object, vote_id_type, &worker_object::vote_against > >
|
||||
>
|
||||
> worker_object_multi_index_type;
|
||||
|
||||
//typedef flat_index<worker_object> worker_index;
|
||||
using worker_index = generic_index<worker_object, worker_object_multi_index_type>;
|
||||
|
||||
class worker_create_evaluator : public evaluator<worker_create_evaluator>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <graphene/delayed_node/delayed_node_plugin.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/worker_evaluator.hpp>
|
||||
#include <graphene/app/api.hpp>
|
||||
|
||||
#include <fc/network/http/websocket.hpp>
|
||||
|
|
@ -25,6 +26,7 @@
|
|||
#include <fc/api.hpp>
|
||||
#include <fc/smart_ref_impl.hpp>
|
||||
|
||||
|
||||
namespace graphene { namespace delayed_node {
|
||||
namespace bpo = boost::program_options;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue