9 #include <boost/algorithm/cxx11/any_of.hpp>
10 #include <boost/range/adaptor/filtered.hpp>
11 #include <boost/range/algorithm/transform.hpp>
12 #include <boost/range/algorithm/set_algorithm.hpp>
20 , _account_service(services.account_service())
22 , _game_service(services.game_service())
23 , _dprops_service(services.dynamic_global_property_service())
24 , _virt_op_emitter(virt_op_emitter)
33 FC_ASSERT(_game_service.
is_exists(op.
uuid),
"Game with uuid '${g}' doesn't exist", (
"g", op.
uuid));
38 "Unable to post game results after bets were resolved");
40 const fc::flat_set<wincase_type> wincases(op.
wincases.begin(), op.
wincases.end());
42 for (
auto wincase : wincases)
44 FC_ASSERT(
is_belong_markets(wincase, game.markets),
"Wincase '${w}' doesn't belong to game markets",
48 validate_all_winners_present(game.markets, wincases);
49 validate_opposite_winners_absent(wincases);
53 auto old_status = game.status;
54 _game_service.
finish(game, wincases);
56 if (old_status == game_status::started)
61 void post_game_results_evaluator::validate_all_winners_present(
const fc::shared_flat_set<market_type>& markets,
62 const fc::flat_set<wincase_type>& winners)
const
64 using namespace boost::adaptors;
65 using namespace boost::algorithm;
67 for (
const auto&
market : markets | filtered([](
const auto& m) {
return !
has_trd_state(m); }))
69 market.visit([&](
const auto& m) {
71 auto exists = any_of(winners, [&](
const auto& w) {
return pair.first == w || pair.second == w; });
73 FC_ASSERT(exists,
"Wincase winners list do not contain neither '${1}' nor '${2}'",
74 (
"1", pair.first)(
"2", pair.second));
79 void post_game_results_evaluator::validate_opposite_winners_absent(
const fc::flat_set<wincase_type>& winners)
const
81 std::vector<wincase_type> opposite;
82 opposite.reserve(winners.size());
84 boost::transform(winners, std::back_inserter(opposite), [](
const auto& w) {
return create_opposite(w); });
86 std::vector<wincase_type> intersection;
87 intersection.reserve(winners.size());
89 boost::set_intersection(winners, opposite, std::back_inserter(intersection));
91 FC_ASSERT(intersection.empty(),
"You've provided opposite wincases from same market as winners");
void do_apply(const operation_type &op)
post_game_results_evaluator(data_service_factory_i &services, betting_service_i &betting_service, database_virtual_operations_emmiter_i &virt_op_emitter)
@ market
Rate limiting for all other actions.
wincase_type create_opposite(const wincase_type &wincase)
bool has_trd_state(const market_type &market)
std::pair< wincase_type, wincase_type > create_wincases(const market_type &market)
bool is_belong_markets(const wincase_type &wincase, const T &markets)
virtual void check_account_existence(const account_name_type &, const optional< const char * > &context_type_name=optional< const char * >()) const =0
virtual bool is_betting_moderator(const account_name_type &account_name) const =0
virtual void cancel_pending_bets(uuid_type game_uuid)=0
virtual void push_virtual_operation(const operation &op)=0
virtual fc::time_point_sec head_block_time() const =0
virtual const game_object & get_game(int64_t game_id) const =0
virtual void finish(const game_object &game, const fc::flat_set< wincase_type > &wincases)=0
virtual bool is_exists(int64_t game_id) const =0
With this operation moderator provides game results(wincases)
account_name_type moderator
moderator account name
uuid_type uuid
Universal Unique Identifier which is specified during game creation.
std::vector< wincase_type > wincases
list of wincases