adding api to query vote objects by id
This commit is contained in:
parent
4e1f38d8d9
commit
80602a1f7b
5 changed files with 58 additions and 0 deletions
|
|
@ -417,6 +417,44 @@ namespace graphene { namespace app {
|
||||||
return *itr;
|
return *itr;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
vector<variant> database_api::lookup_vote_ids( const vector<vote_id_type>& votes )const
|
||||||
|
{
|
||||||
|
FC_ASSERT( votes.size() < 100, "Only 100 votes can be queried at a time" );
|
||||||
|
|
||||||
|
const auto& witness_idx = _db.get_index_type<witness_index>().indices().get<by_vote_id>();
|
||||||
|
const auto& committee_idx = _db.get_index_type<committee_member_index>().indices().get<by_vote_id>();
|
||||||
|
|
||||||
|
vector<variant> result;
|
||||||
|
result.reserve( votes.size() );
|
||||||
|
for( auto id : votes )
|
||||||
|
{
|
||||||
|
switch( id.type() )
|
||||||
|
{
|
||||||
|
case vote_id_type::committee:
|
||||||
|
{
|
||||||
|
auto itr = committee_idx.find( id );
|
||||||
|
if( itr != committee_idx.end() )
|
||||||
|
result.emplace_back( variant( *itr ) );
|
||||||
|
else
|
||||||
|
result.emplace_back( variant() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case vote_id_type::witness:
|
||||||
|
{
|
||||||
|
auto itr = witness_idx.find( id );
|
||||||
|
if( itr != witness_idx.end() )
|
||||||
|
result.emplace_back( variant( *itr ) );
|
||||||
|
else
|
||||||
|
result.emplace_back( variant() );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case vote_id_type::worker:
|
||||||
|
break;
|
||||||
|
case vote_id_type::VOTE_TYPE_COUNT: break; // supress unused enum value warnings
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t database_api::get_witness_count()const
|
uint64_t database_api::get_witness_count()const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,16 @@ namespace graphene { namespace app {
|
||||||
*/
|
*/
|
||||||
fc::optional<witness_object> get_witness_by_account(account_id_type account)const;
|
fc::optional<witness_object> get_witness_by_account(account_id_type account)const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Given a set of votes, return the objects they are voting for.
|
||||||
|
*
|
||||||
|
* This will be a mixture of committee_member_object, witness_objects, and worker_objects
|
||||||
|
*
|
||||||
|
* The results will be in the same order as the votes. Null will be returned for
|
||||||
|
* any vote ids that are not found.
|
||||||
|
*/
|
||||||
|
vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the total number of witnesses registered with the blockchain
|
* @brief Get the total number of witnesses registered with the blockchain
|
||||||
*/
|
*/
|
||||||
|
|
@ -558,6 +568,7 @@ FC_API(graphene::app::database_api,
|
||||||
(get_witnesses)
|
(get_witnesses)
|
||||||
(get_committee_members)
|
(get_committee_members)
|
||||||
(get_witness_by_account)
|
(get_witness_by_account)
|
||||||
|
(lookup_vote_ids)
|
||||||
(get_witness_count)
|
(get_witness_count)
|
||||||
(lookup_witness_accounts)
|
(lookup_witness_accounts)
|
||||||
(lookup_committee_member_accounts)
|
(lookup_committee_member_accounts)
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ namespace graphene { namespace chain {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_account;
|
struct by_account;
|
||||||
|
struct by_vote_id;
|
||||||
using committee_member_multi_index_type = multi_index_container<
|
using committee_member_multi_index_type = multi_index_container<
|
||||||
committee_member_object,
|
committee_member_object,
|
||||||
indexed_by<
|
indexed_by<
|
||||||
|
|
@ -56,6 +57,9 @@ namespace graphene { namespace chain {
|
||||||
>,
|
>,
|
||||||
hashed_unique< tag<by_account>,
|
hashed_unique< tag<by_account>,
|
||||||
member<committee_member_object, account_id_type, &committee_member_object::committee_member_account>
|
member<committee_member_object, account_id_type, &committee_member_object::committee_member_account>
|
||||||
|
>,
|
||||||
|
hashed_unique< tag<by_vote_id>,
|
||||||
|
member<committee_member_object, vote_id_type, &committee_member_object::vote_id>
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ struct vote_id_type
|
||||||
/// Lower 8 bits are type; upper 24 bits are instance
|
/// Lower 8 bits are type; upper 24 bits are instance
|
||||||
uint32_t content;
|
uint32_t content;
|
||||||
|
|
||||||
|
friend size_t hash_value( vote_id_type v ) { return std::hash<uint32_t>()(v.content); }
|
||||||
enum vote_type
|
enum vote_type
|
||||||
{
|
{
|
||||||
committee,
|
committee,
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ namespace graphene { namespace chain {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_account;
|
struct by_account;
|
||||||
|
struct by_vote_id;
|
||||||
using witness_multi_index_type = multi_index_container<
|
using witness_multi_index_type = multi_index_container<
|
||||||
witness_object,
|
witness_object,
|
||||||
indexed_by<
|
indexed_by<
|
||||||
|
|
@ -51,6 +52,9 @@ namespace graphene { namespace chain {
|
||||||
>,
|
>,
|
||||||
hashed_unique< tag<by_account>,
|
hashed_unique< tag<by_account>,
|
||||||
member<witness_object, account_id_type, &witness_object::witness_account>
|
member<witness_object, account_id_type, &witness_object::witness_account>
|
||||||
|
>,
|
||||||
|
hashed_unique< tag<by_vote_id>,
|
||||||
|
member<witness_object, vote_id_type, &witness_object::vote_id>
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue