get_tournaments and get_tournaments_by_state method added

This commit is contained in:
kstdl 2017-02-20 18:09:37 +03:00
parent 4674fc53ab
commit 895fbec5bc
8 changed files with 670 additions and 504 deletions

2
.gitmodules vendored
View file

@ -4,5 +4,5 @@
ignore = dirty
[submodule "libraries/fc"]
path = libraries/fc
url = git@git.syncad.com:blocktrades/fc.git
url = git@gitlab.pixelplex.by:595_peerplays/fc.git
ignore = dirty

File diff suppressed because it is too large Load diff

View file

@ -143,6 +143,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
// Tournaments
vector<tournament_object> get_tournaments_in_state(tournament_state state, uint32_t limit) const;
vector<tournament_object> get_tournaments(tournament_id_type stop, unsigned limit, tournament_id_type start);
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;
@ -1788,6 +1790,54 @@ vector<tournament_object> database_api_impl::get_tournaments_in_state(tournament
return result;
}
vector<tournament_object> database_api::get_tournaments(tournament_id_type stop,
unsigned limit,
tournament_id_type start)
{
return my->get_tournaments(stop, limit, start);
}
vector<tournament_object> database_api_impl::get_tournaments(tournament_id_type stop,
unsigned limit,
tournament_id_type start)
{
vector<tournament_object> result;
const auto& tournament_idx = _db.get_index_type<tournament_index>().indices().get<by_id>();
for (auto elem: tournament_idx) {
if( ( (elem.get_id().instance.value <= start.instance.value) || start == tournament_id_type()) &&
( (elem.get_id().instance.value >= stop.instance.value) || stop == tournament_id_type()))
result.push_back( elem );
}
return result;
}
vector<tournament_object> database_api::get_tournaments_by_state(tournament_id_type stop,
unsigned limit,
tournament_id_type start,
tournament_state state)
{
return my->get_tournaments_by_state(stop, limit, start, state);
}
vector<tournament_object> database_api_impl::get_tournaments_by_state(tournament_id_type stop,
unsigned limit,
tournament_id_type start,
tournament_state state)
{
vector<tournament_object> result;
const auto& tournament_idx = _db.get_index_type<tournament_index>().indices().get<by_id>();
for (auto elem: tournament_idx) {
if( ( (elem.get_id().instance.value <= start.instance.value) || start == tournament_id_type()) &&
( (elem.get_id().instance.value >= stop.instance.value) || stop == tournament_id_type()) &&
elem.get_state() == state )
result.push_back( elem );
}
return result;
}
vector<tournament_id_type> database_api::get_registered_tournaments(account_id_type account_filter, uint32_t limit) const
{
return my->get_registered_tournaments(account_filter, limit);

View file

@ -564,6 +564,15 @@ class database_api
*/
vector<tournament_object> get_tournaments_in_state(tournament_state state, uint32_t limit) const;
vector<tournament_object> get_tournaments(tournament_id_type stop = tournament_id_type(),
unsigned limit = 100,
tournament_id_type start = tournament_id_type());
vector<tournament_object> get_tournaments_by_state(tournament_id_type stop = tournament_id_type(),
unsigned limit = 100,
tournament_id_type start = tournament_id_type(),
tournament_state state = tournament_state::accepting_registrations);
/**
* @return the list of tournaments that a given account is registered to play in
*/
@ -674,5 +683,7 @@ FC_API(graphene::app::database_api,
// Tournaments
(get_tournaments_in_state)
(get_tournaments_by_state)
(get_tournaments )
(get_registered_tournaments)
)

View file

@ -23,7 +23,7 @@
*/
#pragma once
#define GRAPHENE_SYMBOL "TEST"
#define GRAPHENE_SYMBOL "TESTPLAYS"
#define GRAPHENE_ADDRESS_PREFIX "TEST"
#define GRAPHENE_MIN_ACCOUNT_NAME_LENGTH 1

View file

@ -64,6 +64,7 @@ namespace graphene { namespace chain {
~tournament_object();
tournament_object& operator=(const tournament_object& rhs);
tournament_id_type get_id() const { return id; };
/// the account that created this tournament
account_id_type creator;

View file

@ -1502,6 +1502,15 @@ class wallet_api
*/
vector<tournament_object> get_upcoming_tournaments(uint32_t limit);
vector<tournament_object> get_tournaments(tournament_id_type stop,
unsigned limit,
tournament_id_type start);
vector<tournament_object> get_tournaments_by_state(tournament_id_type stop,
unsigned limit,
tournament_id_type start,
tournament_state state);
/** Get specific information about a tournament
* @param tournament_id the ID of the tournament
*/
@ -1723,6 +1732,8 @@ FC_API( graphene::wallet::wallet_api,
(tournament_join)
(rps_throw)
(get_upcoming_tournaments)
(get_tournaments)
(get_tournaments_by_state)
(get_tournament)
(get_order_book)
)

View file

@ -2466,7 +2466,7 @@ public:
}
return ss.str();
};
m["get_upcoming_tournaments"] = [this](variant result, const fc::variants& a)
m["get_upcoming_tournaments"] = m["get_tournaments"] = m["get_tournaments_by_state"] = [this](variant result, const fc::variants& a)
{
const vector<tournament_object> tournaments = result.as<vector<tournament_object> >();
std::stringstream ss;
@ -4857,6 +4857,18 @@ vector<tournament_object> wallet_api::get_upcoming_tournaments(uint32_t limit)
{
return my->_remote_db->get_tournaments_in_state(tournament_state::accepting_registrations, limit);
}
vector<tournament_object> wallet_api::get_tournaments(tournament_id_type stop,
unsigned limit,
tournament_id_type start) {
return my->_remote_db->get_tournaments(stop, limit, start);
}
vector<tournament_object> wallet_api::get_tournaments_by_state(tournament_id_type stop,
unsigned limit,
tournament_id_type start,
tournament_state state) {
return my->_remote_db->get_tournaments_by_state(stop, limit, start, state);
}
tournament_object wallet_api::get_tournament(tournament_id_type id)
{