cancel all unmatched bets on betting market when it is resolved

This commit is contained in:
SynaptiCAD User 2017-03-24 00:09:43 -04:00
parent 784b11059f
commit c8a9c86ca6
4 changed files with 15 additions and 3 deletions

View file

@ -19,10 +19,18 @@ void database::cancel_bet( const bet_object& bet, bool create_virtual_op )
remove(bet);
}
void database::cancel_all_unmatched_bets_on_betting_market(const betting_market_object& betting_market)
{
auto& bet_index = get_index_type<bet_object_index>().indices().get<by_betting_market>();
for (const bet_object& bet : bet_index)
cancel_bet(bet, true);
}
void database::resolve_betting_market(const betting_market_object& betting_market,
betting_market_resolution_type resolution)
{
// TODO: cancel all unmatched bets on the books for this market
cancel_all_unmatched_bets_on_betting_market(betting_market);
auto& index = get_index_type<betting_market_position_index>().indices().get<by_bettor_betting_market>();
auto position_itr = index.lower_bound(std::make_tuple(betting_market.id));
while (position_itr != index.end() &&

View file

@ -226,11 +226,14 @@ struct compare_bet_by_odds {
};
struct by_odds {};
struct by_betting_market {};
typedef multi_index_container<
bet_object,
indexed_by<
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
ordered_unique< tag<by_odds>, identity<bet_object>, compare_bet_by_odds > > > bet_object_multi_index_type;
ordered_unique< tag<by_odds>, identity<bet_object>, compare_bet_by_odds >,
ordered_non_unique< tag<by_betting_market>, member< bet_object, betting_market_id_type, &bet_object::betting_market_id > >
> > bet_object_multi_index_type;
typedef generic_index<bet_object, bet_object_multi_index_type> bet_object_index;

View file

@ -365,6 +365,7 @@ namespace graphene { namespace chain {
/// @{ @group Betting Market Helpers
void cancel_bet(const bet_object& bet, bool create_virtual_op = true);
void cancel_all_unmatched_bets_on_betting_market(const betting_market_object& betting_market);
void resolve_betting_market(const betting_market_object& betting_market,
betting_market_resolution_type resolution);
/**

@ -1 +1 @@
Subproject commit 9d408aa53267834542279490eac4c25878107967
Subproject commit 57d14c7de849c567d753fc5cab5465d68602ff95