Scorum
update_game_markets_evaluator.cpp
Go to the documentation of this file.
7 #include <scorum/utils/range_adaptors.hpp>
8 
9 #include <boost/range/algorithm/sort.hpp>
10 #include <boost/range/algorithm/set_algorithm.hpp>
11 
14 
15 namespace scorum {
16 namespace chain {
17 
20  : evaluator_impl<data_service_factory_i, update_game_markets_evaluator>(services)
21  , _account_service(services.account_service())
22  , _betting_service(betting_service)
23  , _game_service(services.game_service())
24 {
25 }
26 
28 {
29  _account_service.check_account_existence(op.moderator);
30  FC_ASSERT(_betting_service.is_betting_moderator(op.moderator), "User ${u} isn't a betting moderator",
31  ("u", op.moderator));
32  FC_ASSERT(_game_service.is_exists(op.uuid), "Game with uuid '${g}' doesn't exist", ("g", op.uuid));
33 
34  const auto& game = _game_service.get_game(op.uuid);
35  FC_ASSERT(game.status != game_status::finished, "Cannot change the markets when game is finished");
36 
37  const fc::flat_set<market_type> set_of_markets(op.markets.begin(), op.markets.end());
38 
39  FC_ASSERT(set_of_markets.size() == op.markets.size(), "You provided duplicates in market list.",
40  ("input_markets", op.markets)("set_of_markets", set_of_markets));
41 
42  validate_game(game.game, set_of_markets);
43  validate_markets(set_of_markets);
44 
45  fc::flat_set<market_type> cancelled_markets;
46  boost::set_difference(game.markets, set_of_markets, std::inserter(cancelled_markets, cancelled_markets.end()));
47 
48  FC_ASSERT(game.status == game_status::created || cancelled_markets.empty(),
49  "Cannot cancel markets after game was started");
50 
51  _betting_service.cancel_bets(game.uuid, cancelled_markets);
52 
53  _game_service.update_markets(game, set_of_markets);
54 }
55 }
56 }
update_game_markets_evaluator(data_service_factory_i &services, betting_service_i &)
void validate_game(const game_type &game, const fc::flat_set< market_type > &markets)
void validate_markets(const fc::flat_set< market_type > &markets)
Definition: asset.cpp:15
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_bets(uuid_type game_uuid)=0
virtual const game_object & get_game(int64_t game_id) const =0
virtual void update_markets(const game_object &game, const fc::flat_set< market_type > &markets)=0
virtual bool is_exists(int64_t game_id) const =0
This operation updates game markets list.
uuid_type uuid
Universal Unique Identifier which is specified during game creation.
account_name_type moderator
moderator account name
std::vector< market_type > markets
list of markets