Scorum
post_bet_evalulator.cpp
Go to the documentation of this file.
2 
7 
9 
11 
14 
17 
18 #include <scorum/utils/range/unwrap_ref_wrapper_adaptor.hpp>
19 
20 #include <boost/range/algorithm/transform.hpp>
21 
22 namespace scorum {
23 namespace chain {
24 post_bet_evaluator::post_bet_evaluator(data_service_factory_i& services,
30  : evaluator_impl<data_service_factory_i, post_bet_evaluator>(services)
31  , _betting_matcher(betting_matcher)
32  , _betting_svc(betting_service)
33  , _game_dba(game_dba)
34  , _account_dba(account_dba)
35  , _uuid_hist_dba(uuid_hist_dba)
36 {
37 }
38 
40 {
41  FC_ASSERT(_game_dba.is_exists_by<by_uuid>(op.game_uuid), "Game with uuid ${1} doesn't exist", ("1", op.game_uuid));
42  FC_ASSERT(!_uuid_hist_dba.is_exists_by<by_uuid>(op.uuid), "Bet with uuid ${1} already exists", ("1", op.uuid));
43 
44  auto game = _game_dba.get_by<by_uuid>(op.game_uuid);
45 
46  FC_ASSERT(is_belong_markets(op.wincase, game.markets), "Wincase '${w}' doesn't belong to game markets",
47  ("w", op.wincase));
48 
49  FC_ASSERT(game.status != game_status::finished, "Cannot post bet for game that is finished");
50  FC_ASSERT(game.status == game_status::created || op.live, "Cannot create non-live bet after game was started");
51 
52  FC_ASSERT(_account_dba.is_exists_by<by_name>(op.better), "Account \"${1}\" must exist.", ("1", op.better));
53 
55  const auto kind = op.live //
58 
59  const auto& bet = _betting_svc.create_pending_bet(op.better, op.stake, odds, op.wincase, game.uuid, op.uuid, kind);
60 
61  auto bets_to_cancel = _betting_matcher.match(bet);
62 
63  _betting_svc.cancel_pending_bets(utils::unwrap_ref_wrapper(bets_to_cancel));
64 }
65 }
66 }
bool is_exists_by(const Key &arg) const
post_bet_evaluator(data_service_factory_i &, betting_matcher_i &, betting_service_i &, dba::db_accessor< game_object > &, dba::db_accessor< account_object > &, dba::db_accessor< bet_uuid_history_object > &)
void do_apply(const operation_type &op)
bool is_belong_markets(const wincase_type &wincase, const T &markets)
Definition: market.hpp:148
Definition: asset.cpp:15
virtual std::vector< std::reference_wrapper< const pending_bet_object > > match(const pending_bet_object &bet1)=0
virtual const pending_bet_object & create_pending_bet(const account_name_type &better, const protocol::asset &stake, protocol::odds odds, const protocol::wincase_type &wincase, uuid_type game_uuid, uuid_type bet_uuid, pending_bet_kind kind)=0
virtual void cancel_pending_bets(uuid_type game_uuid)=0
bool live
is this bet is active in live
uuid_type game_uuid
Universal Unique Identifier which is specified during game creation.
account_name_type better
owner for new bet
uuid_type uuid
Universal Unique Identifier which is unique for each bet.
odds_input odds
odds - rational coefficient that define potential result (p). p = odds * stake