Scorum
market.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <fc/static_variant.hpp>
6 
7 #include <boost/range/algorithm/transform.hpp>
8 
9 namespace scorum {
10 namespace protocol {
11 
12 template <market_kind kind, typename tag = void> struct over_under_market
13 {
14  int16_t threshold;
15 
16  template <bool site> using wincase = over_under_wincase<site, kind, tag>;
19  static constexpr market_kind kind_v = kind;
20 
21  bool has_trd_state() const
22  {
23  return threshold % SCORUM_BETTING_THRESHOLD_FACTOR == 0;
24  }
25 };
26 
27 template <market_kind kind, typename tag = void> struct score_yes_no_market
28 {
29  uint16_t home;
30  uint16_t away;
31 
32  template <bool site> using wincase = score_yes_no_wincase<site, kind, tag>;
33  using yes = wincase<true>;
34  using no = wincase<false>;
35  static constexpr market_kind kind_v = kind;
36 
37  bool has_trd_state() const
38  {
39  return false;
40  }
41 };
42 
43 template <market_kind kind, typename tag = void> struct yes_no_market
44 {
45  template <bool site> using wincase = yes_no_wincase<site, kind, tag>;
46  using yes = wincase<true>;
47  using no = wincase<false>;
48  static constexpr market_kind kind_v = kind;
49 
50  bool has_trd_state() const
51  {
52  return false;
53  }
54 };
55 
56 struct home_tag;
57 struct away_tag;
58 struct draw_tag;
59 struct both_tag;
60 
64 
66 
68 
73 
77 
79 
82 
83 using market_type = fc::static_variant<result_home,
86  round_home,
87  handicap,
92  goal_home,
93  goal_both,
94  goal_away,
95  total,
98 
99 using wincase_type = fc::static_variant<result_home::yes,
123  total::over,
124  total::under,
129 
130 std::pair<wincase_type, wincase_type> create_wincases(const market_type& market);
132 market_type create_market(const wincase_type& wincase);
133 bool has_trd_state(const market_type& market);
134 bool match_wincases(const wincase_type& lhs, const wincase_type& rhs);
135 
137 
138 template <typename T> std::set<market_kind> get_markets_kind(const T& markets)
139 {
140  std::set<market_kind> actual_markets;
141  boost::transform(markets, std::inserter(actual_markets, actual_markets.begin()), [](const market_type& m) {
142  return m.visit([&](const auto& market_impl) { return market_impl.kind_v; });
143  });
144 
145  return actual_markets;
146 }
147 
148 template <typename T> bool is_belong_markets(const wincase_type& wincase, const T& markets)
149 {
150  const auto wincase_market = create_market(wincase);
151 
152  for (const auto& market : markets)
153  {
154  if (wincase_market == market)
155  return true;
156  }
157 
158  return false;
159 }
160 
161 } // namespace protocol
162 } // namespace scorum
163 
166 
167 namespace fc {
170 
171 template <> void to_variant(const wincase_type& wincase, fc::variant& variant);
172 template <> void from_variant(const fc::variant& variant, wincase_type& wincase);
173 
174 template <> void to_variant(const market_type& market, fc::variant& var);
175 template <> void from_variant(const fc::variant& var, market_type& market);
176 }
177 
178 FC_REFLECT_EMPTY(scorum::protocol::result_home)
179 FC_REFLECT_EMPTY(scorum::protocol::result_draw)
180 FC_REFLECT_EMPTY(scorum::protocol::result_away)
181 FC_REFLECT_EMPTY(scorum::protocol::round_home)
183 FC_REFLECT_EMPTY(scorum::protocol::correct_score_home)
184 FC_REFLECT_EMPTY(scorum::protocol::correct_score_draw)
185 FC_REFLECT_EMPTY(scorum::protocol::correct_score_away)
187 FC_REFLECT_EMPTY(scorum::protocol::goal_home)
188 FC_REFLECT_EMPTY(scorum::protocol::goal_both)
189 FC_REFLECT_EMPTY(scorum::protocol::goal_away)
193 
194 FC_REFLECT_EMPTY(scorum::protocol::result_home::yes)
195 FC_REFLECT_EMPTY(scorum::protocol::result_home::no)
196 FC_REFLECT_EMPTY(scorum::protocol::result_draw::yes)
197 FC_REFLECT_EMPTY(scorum::protocol::result_draw::no)
198 FC_REFLECT_EMPTY(scorum::protocol::result_away::yes)
199 FC_REFLECT_EMPTY(scorum::protocol::result_away::no)
200 FC_REFLECT_EMPTY(scorum::protocol::round_home::yes)
201 FC_REFLECT_EMPTY(scorum::protocol::round_home::no)
212 FC_REFLECT_EMPTY(scorum::protocol::goal_home::yes)
213 FC_REFLECT_EMPTY(scorum::protocol::goal_home::no)
214 FC_REFLECT_EMPTY(scorum::protocol::goal_both::yes)
215 FC_REFLECT_EMPTY(scorum::protocol::goal_both::no)
216 FC_REFLECT_EMPTY(scorum::protocol::goal_away::yes)
217 FC_REFLECT_EMPTY(scorum::protocol::goal_away::no)
FC_REFLECT(appender_args,(appender)(stream)) FC_REFLECT_DERIVED(file_appender_args
Definition: game.cpp:4
void to_variant(const game_type &game, fc::variant &var)
Definition: game.cpp:8
void from_variant(const fc::variant &var, game_type &game)
Definition: game.cpp:12
@ market
Rate limiting for all other actions.
yes_no_market< market_kind::result, away_tag > result_away
Definition: market.hpp:63
yes_no_market< market_kind::correct_score, away_tag > correct_score_away
Definition: market.hpp:71
market_type create_market(const wincase_type &wincase)
Definition: market.cpp:56
over_under_market< market_kind::total_goals, home_tag > total_goals_home
Definition: market.hpp:80
yes_no_market< market_kind::goal, home_tag > goal_home
Definition: market.hpp:74
market_kind get_market_kind(const wincase_type &wincase)
Definition: market.cpp:78
yes_no_market< market_kind::goal, away_tag > goal_away
Definition: market.hpp:76
wincase_type create_opposite(const wincase_type &wincase)
Definition: market.cpp:61
score_yes_no_market< market_kind::correct_score > correct_score
Definition: market.hpp:72
yes_no_market< market_kind::result, home_tag > result_home
Definition: market.hpp:61
fc::static_variant< result_home::yes, result_home::no, result_draw::yes, result_draw::no, result_away::yes, result_away::no, round_home::yes, round_home::no, handicap::over, handicap::under, correct_score_home::yes, correct_score_home::no, correct_score_draw::yes, correct_score_draw::no, correct_score_away::yes, correct_score_away::no, correct_score::yes, correct_score::no, goal_home::yes, goal_home::no, goal_both::yes, goal_both::no, goal_away::yes, goal_away::no, total::over, total::under, total_goals_home::over, total_goals_home::under, total_goals_away::over, total_goals_away::under > wincase_type
Definition: market.hpp:128
yes_no_market< market_kind::result, draw_tag > result_draw
Definition: market.hpp:62
over_under_market< market_kind::total > total
Definition: market.hpp:78
yes_no_market< market_kind::goal, both_tag > goal_both
Definition: market.hpp:75
yes_no_market< market_kind::round > round_home
Definition: market.hpp:65
std::set< market_kind > get_markets_kind(const T &markets)
Definition: market.hpp:138
bool has_trd_state(const market_type &market)
Definition: market.cpp:66
bool match_wincases(const wincase_type &lhs, const wincase_type &rhs)
Definition: market.cpp:71
std::pair< wincase_type, wincase_type > create_wincases(const market_type &market)
Definition: market.cpp:51
bool is_belong_markets(const wincase_type &wincase, const T &markets)
Definition: market.hpp:148
fc::static_variant< result_home, result_draw, result_away, round_home, handicap, correct_score_home, correct_score_draw, correct_score_away, correct_score, goal_home, goal_both, goal_away, total, total_goals_home, total_goals_away > market_type
Definition: market.hpp:97
yes_no_market< market_kind::correct_score, draw_tag > correct_score_draw
Definition: market.hpp:70
over_under_market< market_kind::handicap > handicap
Definition: market.hpp:67
yes_no_market< market_kind::correct_score, home_tag > correct_score_home
Definition: market.hpp:69
Definition: asset.cpp:15
static constexpr market_kind kind_v
Definition: market.hpp:19
static constexpr market_kind kind_v
Definition: market.hpp:35
static constexpr market_kind kind_v
Definition: market.hpp:48