Skip to content

Commit

Permalink
Merge branch 'feature/260-voting-info' into feature/270-funtions-unif…
Browse files Browse the repository at this point in the history
…ied-form
  • Loading branch information
Vlad Dobromyslov committed Feb 7, 2022
2 parents 494482e + 6bcea17 commit 694ad96
Show file tree
Hide file tree
Showing 8 changed files with 646 additions and 32 deletions.
361 changes: 340 additions & 21 deletions libraries/app/database_api.cpp

Large diffs are not rendered by default.

70 changes: 65 additions & 5 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#include <graphene/chain/custom_permission_object.hpp>
#include <graphene/chain/nft_object.hpp>
#include <graphene/chain/offer_object.hpp>
#include <graphene/chain/votes_info.hpp>
#include <graphene/chain/voters_info.hpp>

#include <graphene/market_history/market_history_plugin.hpp>

Expand Down Expand Up @@ -619,7 +621,14 @@ class database_api {
* @param account The ID of the account whose SON should be retrieved
* @return The SON object, or null if the account does not have a SON
*/
fc::optional<son_object> get_son_by_account(account_id_type account) const;
fc::optional<son_object> get_son_by_account_id(account_id_type account) const;

/**
* @brief Get the SON owned by a given account
* @param account The ID of the account whose SON should be retrieved
* @return The SON object, or null if the account does not have a SON
*/
fc::optional<son_object> get_son_by_account(const std::string account_id_or_name) const;

/**
* @brief Get names and IDs for registered SONs
Expand Down Expand Up @@ -698,14 +707,25 @@ class database_api {
*/
uint64_t get_sidechain_addresses_count() const;

/// WORKERS
/////////////
// Workers //
/////////////

/**
* @brief Get a list of workers by ID
* @param worker_ids IDs of the workers to retrieve
* @return The workers corresponding to the provided IDs
*
* This function has semantics identical to @ref get_objects
*/
vector<optional<worker_object>> get_workers(const vector<worker_id_type> &worker_ids) const;

/**
* @brief Return the worker objects associated with this account.
* @param account_id_or_name The ID or name of the account whose worker should be retrieved
* @return The worker object or null if the account does not have a worker
*/
vector<worker_object> get_workers_by_account(const std::string account_id_or_name) const;
fc::optional<worker_object> get_worker_by_account(const std::string account_id_or_name) const;

///////////
// Votes //
Expand All @@ -721,6 +741,39 @@ class database_api {
*/
vector<variant> lookup_vote_ids(const vector<vote_id_type> &votes) const;

/**
* @brief Get a list of vote_id_type that ID votes for
* @param account_name_or_id ID or name of the account to get votes for
* @return The list of vote_id_type ID votes for
*
*/
vector<vote_id_type> get_votes_ids(const string &account_name_or_id) const;

/**
* @brief Return the objects account_name_or_id votes for
* @param account_name_or_id ID or name of the account to get votes for
* @return The votes_info account_name_or_id votes for
*
*/
votes_info get_votes(const string &account_name_or_id) const;

/**
*
* @brief Get a list of accounts that votes for vote_id
* @param vote_id We search accounts that vote for this ID
* @return The accounts that votes for provided ID
*
*/
vector<account_object> get_voters_by_id(const vote_id_type &vote_id) const;

/**
* @brief Return the accounts that votes for account_name_or_id
* @param account_name_or_id ID or name of the account to get voters for
* @return The voters_info for account_name_or_id
*
*/
voters_info get_voters(const string &account_name_or_id) const;

////////////////////////////
// Authority / validation //
////////////////////////////
Expand Down Expand Up @@ -1044,6 +1097,7 @@ FC_API(graphene::app::database_api,

// SON members
(get_sons)
(get_son_by_account_id)
(get_son_by_account)
(lookup_son_accounts)
(get_son_count)
Expand All @@ -1060,10 +1114,16 @@ FC_API(graphene::app::database_api,
(get_sidechain_address_by_account_and_sidechain)
(get_sidechain_addresses_count)

// workers
(get_workers_by_account)
// Workers
(get_workers)
(get_worker_by_account)

// Votes
(lookup_vote_ids)
(get_votes_ids)
(get_votes)
(get_voters_by_id)
(get_voters)

// Authority / validation
(get_transaction_hex)
Expand Down
40 changes: 40 additions & 0 deletions libraries/chain/include/graphene/chain/voters_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <graphene/chain/protocol/vote.hpp>

namespace graphene { namespace chain {

/**
* @class voters_info_object
* @ingroup object
*/
struct voters_info_object {
vote_id_type vote_id;
vector<account_id_type> voters;
};

/**
* @class voters_info
* @brief tracks information about a voters info
* @ingroup object
*/
struct voters_info {
voters_info_object voters_for_committee_member;
voters_info_object voters_for_witness;
voters_info_object voters_for_worker;
voters_info_object voters_against_worker;
voters_info_object voters_for_son;
};

} } // graphene::chain

FC_REFLECT( graphene::chain::voters_info_object,
(vote_id)
(voters) )

FC_REFLECT( graphene::chain::voters_info,
(voters_for_committee_member)
(voters_for_witness)
(voters_for_worker)
(voters_against_worker)
(voters_for_son) )
48 changes: 48 additions & 0 deletions libraries/chain/include/graphene/chain/votes_info.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#pragma once

#include <graphene/chain/protocol/vote.hpp>

namespace graphene { namespace chain {

/**
* @class votes_info_object
* @tparam IdType id type of the object
* @ingroup object
*/
template<typename IdType>
struct votes_info_object {
votes_info_object() = default;
votes_info_object(const vote_id_type& vote_id_, uint64_t id_)
: vote_id{vote_id_}
, id{id_}
{}

vote_id_type vote_id;
IdType id;
};

/**
* @class votes_info
* @brief tracks information about a votes info
* @ingroup object
*/
struct votes_info {
vector< votes_info_object<committee_member_id_type> > votes_for_committee_members;
vector< votes_info_object<witness_id_type> > votes_for_witnesses;
vector< votes_info_object<worker_id_type> > votes_for_workers;
vector< votes_info_object<worker_id_type> > votes_against_workers;
vector< votes_info_object<son_id_type> > votes_for_sons;
};

} } // graphene::chain

FC_REFLECT_TEMPLATE( (typename IdType), graphene::chain::votes_info_object<IdType>,
(vote_id)
(id) )

FC_REFLECT( graphene::chain::votes_info,
(votes_for_committee_members)
(votes_for_witnesses)
(votes_for_workers)
(votes_against_workers)
(votes_for_sons) )
38 changes: 37 additions & 1 deletion libraries/wallet/include/graphene/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2487,9 +2487,41 @@ class wallet_api
bool broadcast = false,
bool to_temp = false );


std::map<string,std::function<string(fc::variant,const fc::variants&)>> get_result_formatters() const;

/**
* @brief Get a list of vote_id_type that ID votes for
* @param account_name_or_id ID or name of the account to get votes for
* @return The list of vote_id_type ID votes for
*
*/
vector<vote_id_type> get_votes_ids(const string &account_name_or_id) const;

/**
* @brief Return the objects account_name_or_id votes for
* @param account_name_or_id ID or name of the account to get votes for
* @return The votes_info account_name_or_id votes for
*
*/
votes_info get_votes(const string &account_name_or_id) const;

/**
* @brief Get a list of accounts that votes for vote_id
* @param vote_id We search accounts that vote for this ID
* @return The accounts that votes for provided ID
*
*/
vector<account_object> get_voters_by_id(const vote_id_type &vote_id) const;

/**
* @brief Return the accounts that votes for account_name_or_id
* @param account_name_or_id ID or name of the account to get voters for
* @return The voters_info for account_name_or_id
*
*/
voters_info get_voters(const string &account_name_or_id) const;


fc::signal<void(bool)> lock_changed;
std::shared_ptr<detail::wallet_api_impl> my;
void encrypt_keys();
Expand Down Expand Up @@ -2795,4 +2827,8 @@ FC_API( graphene::wallet::wallet_api,
(get_custom_account_authorities_by_permission_id)
(get_custom_account_authorities_by_permission_name)
(get_active_custom_account_authorities_by_operation)
(get_votes_ids)
(get_votes)
(get_voters_by_id)
(get_voters)
)
66 changes: 61 additions & 5 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ class wallet_api_impl
try
{
account_id_type owner_account_id = get_account_id(owner_account);
fc::optional<son_object> son = _remote_db->get_son_by_account(owner_account_id);
fc::optional<son_object> son = _remote_db->get_son_by_account_id(owner_account_id);
if (son)
return *son;
else
Expand Down Expand Up @@ -2075,7 +2075,7 @@ class wallet_api_impl
son_create_op.pay_vb = pay_vb_id;
son_create_op.sidechain_public_keys = sidechain_public_keys;

if (_remote_db->get_son_by_account(son_create_op.owner_account))
if (_remote_db->get_son_by_account_id(son_create_op.owner_account))
FC_THROW("Account ${owner_account} is already a SON", ("owner_account", owner_account));

signed_transaction tx;
Expand Down Expand Up @@ -2712,7 +2712,7 @@ class wallet_api_impl

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(son_account_id);
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));
if (approve)
Expand Down Expand Up @@ -2756,7 +2756,7 @@ class wallet_api_impl
for (const std::string& son : sons_to_approve)
{
account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(son_owner_account_id);
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));
auto insert_result = voting_account_object.options.votes.insert(son_obj->vote_id);
Expand All @@ -2766,7 +2766,7 @@ class wallet_api_impl
for (const std::string& son : sons_to_reject)
{
account_id_type son_owner_account_id = get_account_id(son);
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(son_owner_account_id);
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));
unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->vote_id);
Expand Down Expand Up @@ -4082,6 +4082,42 @@ class wallet_api_impl
return it->second;
}

vector<vote_id_type> get_votes_ids(const string &account_name_or_id) const
{
try
{
return _remote_db->get_votes_ids(account_name_or_id);
}
FC_CAPTURE_AND_RETHROW( (account_name_or_id) )
}

votes_info get_votes(const string &account_name_or_id) const
{
try
{
return _remote_db->get_votes(account_name_or_id);
}
FC_CAPTURE_AND_RETHROW( (account_name_or_id) )
}

vector<account_object> get_voters_by_id(const vote_id_type &vote_id) const
{
try
{
return _remote_db->get_voters_by_id(vote_id);
}
FC_CAPTURE_AND_RETHROW( (vote_id) )
}

voters_info get_voters(const string &account_name_or_id) const
{
try
{
return _remote_db->get_voters(account_name_or_id);
}
FC_CAPTURE_AND_RETHROW( (account_name_or_id) )
}

string _wallet_filename;
wallet_data _wallet;

Expand Down Expand Up @@ -7583,6 +7619,26 @@ std::vector<matched_bet_object> wallet_api::get_all_matched_bets_for_bettor(acco
return( my->_remote_bookie->get_all_matched_bets_for_bettor(bettor_id, start, limit) );
}

vector<vote_id_type> wallet_api::get_votes_ids(const string &account_name_or_id) const
{
return my->get_votes_ids(account_name_or_id);
}

votes_info wallet_api::get_votes(const string &account_name_or_id) const
{
return my->get_votes(account_name_or_id);
}

vector<account_object> wallet_api::get_voters_by_id(const vote_id_type &vote_id) const
{
return my->get_voters_by_id(vote_id);
}

voters_info wallet_api::get_voters(const string &account_name_or_id) const
{
return my->get_voters(account_name_or_id);
}

// default ctor necessary for FC_REFLECT
signed_block_with_info::signed_block_with_info( const signed_block& block )
: signed_block( block )
Expand Down
Loading

0 comments on commit 694ad96

Please sign in to comment.