From c8a9c86ca6ac2dbbafa687dd0476820a26e7c0d7 Mon Sep 17 00:00:00 2001 From: SynaptiCAD User Date: Fri, 24 Mar 2017 00:09:43 -0400 Subject: [PATCH] cancel all unmatched bets on betting market when it is resolved --- libraries/chain/db_bet.cpp | 10 +++++++++- .../include/graphene/chain/betting_market_object.hpp | 5 ++++- libraries/chain/include/graphene/chain/database.hpp | 1 + libraries/fc | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_bet.cpp b/libraries/chain/db_bet.cpp index f6ae85b8..d0c02e3a 100644 --- a/libraries/chain/db_bet.cpp +++ b/libraries/chain/db_bet.cpp @@ -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().indices().get(); + 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().indices().get(); auto position_itr = index.lower_bound(std::make_tuple(betting_market.id)); while (position_itr != index.end() && diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp index add736ec..11112793 100644 --- a/libraries/chain/include/graphene/chain/betting_market_object.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -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, member< object, object_id_type, &object::id > >, - ordered_unique< tag, identity, compare_bet_by_odds > > > bet_object_multi_index_type; + ordered_unique< tag, identity, compare_bet_by_odds >, + ordered_non_unique< tag, member< bet_object, betting_market_id_type, &bet_object::betting_market_id > > + > > bet_object_multi_index_type; typedef generic_index bet_object_index; diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 6b0a9823..e1f4ae43 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -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); /** diff --git a/libraries/fc b/libraries/fc index 9d408aa5..57d14c7d 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 9d408aa53267834542279490eac4c25878107967 +Subproject commit 57d14c7de849c567d753fc5cab5465d68602ff95