Scorum
update_game_start_time_evaluator.cpp
Go to the documentation of this file.
6 
8 
9 namespace scorum {
10 namespace chain {
12  data_service_factory_i& services,
15  : evaluator_impl<data_service_factory_i, update_game_start_time_evaluator>(services)
16  , _account_service(services.account_service())
17  , _dprops_service(services.dynamic_global_property_service())
18  , _betting_service(betting_service)
19  , _game_service(services.game_service())
20  , _virt_op_emitter(virt_op_emitter)
21 {
22 }
23 
25 {
26  FC_ASSERT(op.start_time > _dprops_service.head_block_time(), "Game should start after head block time");
27  _account_service.check_account_existence(op.moderator);
28 
29  FC_ASSERT(_betting_service.is_betting_moderator(op.moderator), "User ${u} isn't a betting moderator",
30  ("u", op.moderator));
31 
32  FC_ASSERT(_game_service.is_exists(op.uuid), "Game with uuid '${g}' doesn't exist", ("g", op.uuid));
33  const auto& game = _game_service.get_game(op.uuid);
34 
35  auto old_status = game.status;
36  FC_ASSERT(old_status == game_status::created || old_status == game_status::started,
37  "Cannot change the start time when game is finished");
38 
39  auto ordered_pair = std::minmax(game.original_start_time, op.start_time);
40  FC_ASSERT(ordered_pair.second - ordered_pair.first <= SCORUM_BETTING_START_TIME_DIFF_MAX,
41  "Cannot change start time more than ${1} seconds",
42  ("1", SCORUM_BETTING_START_TIME_DIFF_MAX.to_seconds()));
43 
44  _betting_service.cancel_bets(op.uuid, game.start_time);
45 
46  _game_service.update(game, [&](game_object& g) {
47  auto delta = op.start_time - g.start_time;
48  g.auto_resolve_time += delta;
49  g.start_time = op.start_time;
51  });
52 
53  if (old_status == game_status::started)
54  _virt_op_emitter.push_virtual_operation(
56 }
57 }
58 }
time_point_sec auto_resolve_time
Definition: game_object.hpp:55
update_game_start_time_evaluator(data_service_factory_i &, betting_service_i &, database_virtual_operations_emmiter_i &)
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 void update(const modifier_type &modifier)=0
virtual bool is_betting_moderator(const account_name_type &account_name) const =0
virtual void cancel_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 bool is_exists(int64_t game_id) const =0
This operation updates game start time.
account_name_type moderator
moderator account name
uuid_type uuid
Universal Unique Identifier which is specified during game creation.