Scorum
game.cpp
Go to the documentation of this file.
6 #include <boost/lambda/lambda.hpp>
7 
8 namespace scorum {
9 namespace chain {
10 
12  : base_service_type(db)
13  , _dprops_service(db.dynamic_global_property_service())
14  , _betting_props_service(db.betting_property_service())
15  , _uuid_hist_dba(db.get_dba<game_uuid_history_object>())
16 {
17 }
18 
20  const std::string& json_metadata,
21  fc::time_point_sec start,
22  uint32_t auto_resolve_delay_sec,
23  const game_type& game,
24  const fc::flat_set<market_type>& markets)
25 {
26  _uuid_hist_dba.create([&](game_uuid_history_object& o) { o.uuid = uuid; });
27 
29  obj.uuid = uuid;
30 #ifndef IS_LOW_MEM
31  fc::from_string(obj.json_metadata, json_metadata);
32 #endif
33  obj.start_time = start;
34  obj.auto_resolve_time = start + auto_resolve_delay_sec;
35  obj.original_start_time = start;
36  obj.last_update = _dprops_service.head_block_time();
37  obj.game = game;
39 
40  for (const auto& m : markets)
41  obj.markets.emplace(m);
42  });
43 }
44 
45 void dbs_game::finish(const game_object& game, const fc::flat_set<wincase_type>& wincases)
46 {
47  update(game, [&](game_object& g) {
48  if (g.status == game_status::started)
49  g.bets_resolve_time = _dprops_service.head_block_time() + _betting_props_service.get().resolve_delay_sec;
51  g.last_update = _dprops_service.head_block_time();
52  g.auto_resolve_time = fc::time_point_sec::maximum();
53 
54  g.results.clear();
55  for (const auto& w : wincases)
56  g.results.emplace(w);
57  });
58 }
59 
60 void dbs_game::update_markets(const game_object& game, const fc::flat_set<market_type>& markets)
61 {
62  update(game, [&](game_object& g) {
63  g.markets.clear();
64  for (const auto& m : markets)
65  g.markets.emplace(m);
66  });
67 }
68 
69 bool dbs_game::is_exists(int64_t game_id) const
70 {
71  return find_by<by_id>(game_id) != nullptr;
72 }
73 
74 bool dbs_game::is_exists(const uuid_type& uuid) const
75 {
76  return find_by<by_uuid>(uuid) != nullptr;
77 }
78 
79 const game_object& dbs_game::get_game(int64_t game_id) const
80 {
81  return get_by<by_id>(game_id);
82 }
83 
84 const game_object& dbs_game::get_game(const uuid_type& uuid) const
85 {
86  return get_by<by_uuid>(uuid);
87 }
88 
89 std::vector<dbs_game::object_cref_type> dbs_game::get_games(fc::time_point_sec start) const
90 {
91  return get_range_by<by_start_time>(::boost::multi_index::unbounded,
92  ::boost::lambda::_1 <= std::make_tuple(start, ALL_IDS));
93 }
94 
95 } // namespace scorum
96 } // namespace chain
tracks the blockchain state in an extensible manner
Definition: database.hpp:52
virtual void finish(const game_object &game, const fc::flat_set< wincase_type > &wincases) override
Definition: game.cpp:45
dbs_game(database &db)
Definition: game.cpp:11
virtual const game_object & create_game(const uuid_type &uuid, const std::string &json_metadata, fc::time_point_sec start, uint32_t auto_resolve_delay_sec, const game_type &game, const fc::flat_set< market_type > &markets) override
Definition: game.cpp:19
virtual std::vector< object_cref_type > get_games(fc::time_point_sec start) const override
Definition: game.cpp:89
virtual const game_object & get_game(int64_t game_id) const override
Definition: game.cpp:79
virtual void update_markets(const game_object &game, const fc::flat_set< market_type > &markets) override
Definition: game.cpp:60
virtual const object_type & create(const modifier_type &modifier) override
virtual void update(const modifier_type &modifier) override
fc::shared_string json_metadata
Definition: game_object.hpp:50
time_point_sec bets_resolve_time
Definition: game_object.hpp:54
fc::shared_flat_set< wincase_type > results
Definition: game_object.hpp:61
time_point_sec original_start_time
Definition: game_object.hpp:52
time_point_sec auto_resolve_time
Definition: game_object.hpp:55
time_point_sec last_update
Definition: game_object.hpp:53
fc::shared_flat_set< market_type > markets
Definition: game_object.hpp:60
const unbounded_placeholder unbounded
fc::static_variant< soccer_game, hockey_game > game_type
Definition: game.hpp:14
Definition: asset.cpp:15
boost::uuids::uuid uuid_type
Definition: types.hpp:53
#define ALL_IDS
virtual const object_type & get() const =0
virtual fc::time_point_sec head_block_time() const =0