Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge gpos to develop #186

Merged
merged 23 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c35a88b
Merge pull request #37 from peerplays-network/feature/SONs-base
pbattu123 Aug 20, 2019
8613bab
issue - 154: Don't allow to vote when vesting balance is 0
pbattu123 Aug 29, 2019
2a3d8a4
changes to withdraw_vesting feature(for both cdd and GPOS)
pbattu123 Sep 20, 2019
b358241
Comments update
pbattu123 Sep 20, 2019
8e1c038
update to GPOS hardfork ref
pbattu123 Sep 20, 2019
9ec835b
Merge pull request #95 from peerplays-network/issue-154
pbattu123 Sep 21, 2019
79dc2f4
Merge pull request #141 from peerplays-network/BLOCKBACK-153
pbattu123 Sep 21, 2019
4a72f94
fix for get_vesting_balance API call
pbattu123 Sep 21, 2019
a7df686
braces update
pbattu123 Sep 21, 2019
af47ed0
Merge pull request #143 from peerplays-network/issue/154-fix
pbattu123 Sep 22, 2019
db01f31
Create .gitlab-ci.yml
Sep 25, 2019
7fae375
fixing build errors (#150)
bobinson Sep 26, 2019
f1eb625
Changes to compiple with GCC 7(Ubuntu 18.04)
pbattu123 Sep 30, 2019
d65f20a
changes to have separate methods and single withdrawl fee for multipl…
pbattu123 Oct 3, 2019
c73d0a3
163-fix, Return only non-zero vesting balances
pbattu123 Oct 4, 2019
3f6b7ab
Merge pull request #164 from peerplays-network/jira-163-fix
pbattu123 Oct 6, 2019
d5dffa6
Merge pull request #163 from peerplays-network/153/fix-add-on
pbattu123 Oct 6, 2019
0dc551b
Merge branch 'qa_gpos_18.04' into develop_gpos
oxarbitrage Oct 16, 2019
152c793
Revert "Revert "GPOS protocol""
oxarbitrage Oct 16, 2019
803ef15
add new line needed to gpos hardfork file
oxarbitrage Oct 16, 2019
76557b4
comment temporally cli_vote_for_2_witnesses until refactor or delete
oxarbitrage Oct 16, 2019
60f4999
fix gpos tests
oxarbitrage Oct 16, 2019
37292ae
fix gitlab-ci conflict
oxarbitrage Oct 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test:
- ./tests/cli_test
tags:
- builder

code_quality:
stage: test
image: docker:stable
Expand Down
54 changes: 53 additions & 1 deletion libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
vector<tournament_object> get_tournaments_by_state(tournament_id_type stop, unsigned limit, tournament_id_type start, tournament_state state);
vector<tournament_id_type> get_registered_tournaments(account_id_type account_filter, uint32_t limit) const;

// gpos
gpos_info get_gpos_info(const account_id_type account) const;

//private:
template<typename T>
Expand Down Expand Up @@ -934,7 +936,8 @@ vector<vesting_balance_object> database_api_impl::get_vesting_balances( account_
auto vesting_range = _db.get_index_type<vesting_balance_index>().indices().get<by_account>().equal_range(account_id);
std::for_each(vesting_range.first, vesting_range.second,
[&result](const vesting_balance_object& balance) {
result.emplace_back(balance);
if(balance.balance.amount > 0)
result.emplace_back(balance);
});
return result;
}
Expand Down Expand Up @@ -2130,6 +2133,55 @@ vector<tournament_id_type> database_api_impl::get_registered_tournaments(account
return tournament_ids;
}

//////////////////////////////////////////////////////////////////////
// //
// GPOS methods //
// //
//////////////////////////////////////////////////////////////////////

graphene::app::gpos_info database_api::get_gpos_info(const account_id_type account) const
{
return my->get_gpos_info(account);

}
graphene::app::gpos_info database_api_impl::get_gpos_info(const account_id_type account) const
{
gpos_info result;
result.vesting_factor = _db.calculate_vesting_factor(account(_db));

const auto& dividend_data = asset_id_type()(_db).dividend_data(_db);
const account_object& dividend_distribution_account = dividend_data.dividend_distribution_account(_db);
result.award = _db.get_balance(dividend_distribution_account, asset_id_type()(_db));

share_type total_amount;
auto balance_type = vesting_balance_type::gpos;
#ifdef USE_VESTING_OBJECT_BY_ASSET_BALANCE_INDEX
// get only once a collection of accounts that hold nonzero vesting balances of the dividend asset
auto vesting_balances_begin =
vesting_index.indices().get<by_asset_balance>().lower_bound(boost::make_tuple(asset_id_type(), balance_type));
auto vesting_balances_end =
vesting_index.indices().get<by_asset_balance>().upper_bound(boost::make_tuple(asset_id_type(), balance_type, share_type()));

for (const vesting_balance_object& vesting_balance_obj : boost::make_iterator_range(vesting_balances_begin, vesting_balances_end))
{
total_amount += vesting_balance_obj.balance.amount;
}
#else
const vesting_balance_index& vesting_index = _db.get_index_type<vesting_balance_index>();
const auto& vesting_balances = vesting_index.indices().get<by_id>();
for (const vesting_balance_object& vesting_balance_obj : vesting_balances)
{
if (vesting_balance_obj.balance.asset_id == asset_id_type() && vesting_balance_obj.balance_type == balance_type)
{
total_amount += vesting_balance_obj.balance.amount;
}
}
#endif

result.total_amount = total_amount;
return result;
}

//////////////////////////////////////////////////////////////////////
// //
// Private methods //
Expand Down
23 changes: 22 additions & 1 deletion libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ struct market_trade
double value;
};

struct gpos_info {
double vesting_factor;
asset award;
share_type total_amount;
};

/**
* @brief The database_api class implements the RPC API for the chain database.
*
Expand Down Expand Up @@ -673,7 +679,17 @@ class database_api
*/
vector<tournament_id_type> get_registered_tournaments(account_id_type account_filter, uint32_t limit) const;

private:
//////////
// GPOS //
//////////
/**
* @return account and network GPOS information
*/
gpos_info get_gpos_info(const account_id_type account) const;



private:
std::shared_ptr< database_api_impl > my;
};

Expand All @@ -684,6 +700,8 @@ FC_REFLECT( graphene::app::order_book, (base)(quote)(bids)(asks) );
FC_REFLECT( graphene::app::market_ticker, (base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume) );
FC_REFLECT( graphene::app::market_volume, (base)(quote)(base_volume)(quote_volume) );
FC_REFLECT( graphene::app::market_trade, (date)(price)(amount)(value) );
FC_REFLECT( graphene::app::gpos_info, (vesting_factor)(award)(total_amount) );


FC_API(graphene::app::database_api,
// Objects
Expand Down Expand Up @@ -801,4 +819,7 @@ FC_API(graphene::app::database_api,
(get_tournaments_by_state)
(get_tournaments )
(get_registered_tournaments)

// gpos
(get_gpos_info)
)
Loading