From a2b83c668f6d3bb5dbed65e83c221695b8b7bf1d Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Thu, 10 Aug 2017 21:29:26 +0200 Subject: [PATCH] added delay_bets to betting_market_group_object, live_betting_delay_time to chain parametrs . --- libraries/chain/betting_market_evaluator.cpp | 17 ++++++++++++++-- .../graphene/chain/betting_market_object.hpp | 4 +++- .../chain/include/graphene/chain/config.hpp | 1 + .../chain/protocol/betting_market.hpp | 4 +++- .../chain/protocol/chain_parameters.hpp | 4 +++- tests/betting/betting_tests.cpp | 20 +++++++++++++------ tests/common/database_fixture.cpp | 7 +++++-- tests/common/database_fixture.hpp | 3 ++- 8 files changed, 46 insertions(+), 14 deletions(-) diff --git a/libraries/chain/betting_market_evaluator.cpp b/libraries/chain/betting_market_evaluator.cpp index 1114ef33..5dbe31c0 100644 --- a/libraries/chain/betting_market_evaluator.cpp +++ b/libraries/chain/betting_market_evaluator.cpp @@ -112,6 +112,7 @@ object_id_type betting_market_group_create_evaluator::do_apply(const betting_mar betting_market_group_obj.description = op.description; betting_market_group_obj.asset_id = op.asset_id; betting_market_group_obj.frozen = false; + betting_market_group_obj.delay_bets = false; }); return new_betting_market_group.id; } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -119,7 +120,11 @@ object_id_type betting_market_group_create_evaluator::do_apply(const betting_mar void_result betting_market_group_update_evaluator::do_evaluate(const betting_market_group_update_operation& op) { try { FC_ASSERT(trx_state->_is_proposed_trx); - FC_ASSERT(op.new_event_id.valid() || op.new_description.valid() || op.new_rules_id.valid() || op.freeze.valid(), "nothing to change"); + FC_ASSERT(op.new_event_id.valid() || + op.new_description.valid() || + op.new_rules_id.valid() || + op.freeze.valid() || + op.delay_bets.valid(), "nothing to change"); // the event_id in the operation can be a relative id. If it is, // resolve it and verify that it is truly an event @@ -157,6 +162,11 @@ void_result betting_market_group_update_evaluator::do_evaluate(const betting_mar FC_ASSERT(_betting_market_group->frozen != *op.freeze, "freeze would not change the state of the betting market group"); } + if (op.delay_bets.valid()) + { + const auto& _betting_market_group = &op.betting_market_group_id(db()); + FC_ASSERT(_betting_market_group->delay_bets != *op.delay_bets, "delay_bets would not change the state of the betting market group"); + } return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -175,6 +185,8 @@ void_result betting_market_group_update_evaluator::do_apply(const betting_market bmgo.rules_id = rules_id; if( op.freeze.valid() ) bmgo.frozen = *op.freeze; + if( op.delay_bets.valid() ) + bmgo.delay_bets = *op.delay_bets; }); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -306,7 +318,8 @@ object_id_type bet_place_evaluator::do_apply(const bet_place_operation& op) d.adjust_balance(fee_paying_account->id, -op.amount_to_bet); - bool bet_matched = d.place_bet(new_bet); + //bool bet_matched = + d.place_bet(new_bet); return new_bet_id; } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp index 2f8c97c5..29b7e7ad 100644 --- a/libraries/chain/include/graphene/chain/betting_market_object.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -65,6 +65,8 @@ class betting_market_group_object : public graphene::db::abstract_object< bettin share_type total_matched_bets_amount; bool frozen; + + bool delay_bets; }; class betting_market_object : public graphene::db::abstract_object< betting_market_object > @@ -447,7 +449,7 @@ typedef generic_index freeze; + optional delay_bets; + extensions_type extensions; account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } @@ -386,7 +388,7 @@ FC_REFLECT( graphene::chain::betting_market_group_create_operation, FC_REFLECT( graphene::chain::betting_market_group_update_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::betting_market_group_update_operation, - (fee)(betting_market_group_id)(new_description)(new_event_id)(new_rules_id)(freeze)(extensions) ) + (fee)(betting_market_group_id)(new_description)(new_event_id)(new_rules_id)(freeze)(delay_bets)(extensions) ) FC_REFLECT( graphene::chain::betting_market_create_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::betting_market_create_operation, diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index e2dfd3a6..a0445a3f 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -73,7 +73,8 @@ namespace graphene { namespace chain { bet_multiplier_type min_bet_multiplier = GRAPHENE_DEFAULT_MIN_BET_MULTIPLIER; bet_multiplier_type max_bet_multiplier = GRAPHENE_DEFAULT_MAX_BET_MULTIPLIER; flat_map permitted_betting_odds_increments = GRAPHENE_DEFAULT_PERMITTED_BETTING_ODDS_INCREMENTS; - //uint8_t witness_schedule_algorithm = GRAPHENE_WITNESS_SHUFFLED_ALGORITHM; ///< 0 shuffled, 1 scheduled + uint16_t live_betting_delay_time = GRAPHENE_DEFAULT_LIVE_BETTING_DELAY_TIME; ///< delayed bets + //uint8_t witness_schedule_algorithm = GRAPHENE_WITNESS_SHUFFLED_ALGORITHM; ///< 0 shuffled, 1 scheduled uint8_t witness_schedule_algorithm = GRAPHENE_WITNESS_SCHEDULED_ALGORITHM; ///< 0 shuffled, 1 scheduled /* rps tournament parameters constraints */ uint32_t min_round_delay = TOURNAMENT_MIN_ROUND_DELAY; ///< miniaml delay between games @@ -131,6 +132,7 @@ FC_REFLECT( graphene::chain::chain_parameters, (betting_rake_fee_percentage) (permitted_betting_odds_increments) (witness_schedule_algorithm) + (live_betting_delay_time) (min_round_delay) (max_round_delay) (min_time_per_commit_move) diff --git a/tests/betting/betting_tests.cpp b/tests/betting/betting_tests.cpp index ace12a87..2c298a43 100644 --- a/tests/betting/betting_tests.cpp +++ b/tests/betting/betting_tests.cpp @@ -783,12 +783,12 @@ BOOST_AUTO_TEST_CASE(betting_market_group_update_test) const betting_market_rules_object& new_betting_market_rules = create_betting_market_rules({{"en", "NHL Rules v2.0"}}, {{"en", "The winner will be the team with the most points at the end of the game. The team with fewer points will not be the winner."}}); fc::optional new_rule = new_betting_market_rules.id; - fc::optional freeze; + fc::optional empty_bool; - update_betting_market_group(moneyline_betting_markets.id, new_desc, empty_object_id, empty_object_id, freeze); - update_betting_market_group(moneyline_betting_markets.id, dempty, new_event, empty_object_id, freeze); - update_betting_market_group(moneyline_betting_markets.id, dempty, empty_object_id, new_rule, freeze); - update_betting_market_group(moneyline_betting_markets.id, new_desc, new_event, new_rule, freeze); + update_betting_market_group(moneyline_betting_markets.id, new_desc, empty_object_id, empty_object_id, empty_bool, empty_bool); + update_betting_market_group(moneyline_betting_markets.id, dempty, new_event, empty_object_id, empty_bool, empty_bool); + update_betting_market_group(moneyline_betting_markets.id, dempty, empty_object_id, new_rule, empty_bool, empty_bool); + update_betting_market_group(moneyline_betting_markets.id, new_desc, new_event, new_rule, empty_bool, empty_bool); transfer(account_id_type(), bob_id, asset(10000000)); place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); @@ -1038,10 +1038,18 @@ BOOST_AUTO_TEST_CASE( wimbledon_2017_gentelmen_singles_final_test ) BOOST_TEST_MESSAGE("federer_wins_final_market " << fc::variant(federer_wins_final_market.id).as()); BOOST_TEST_MESSAGE("cilic_wins_final_market " << fc::variant(cilic_wins_final_market.id).as()); + betting_market_group_id_type moneyline_cilic_vs_federer_id = moneyline_cilic_vs_federer.id; + fc::optional empty_str; + fc::optional empty_obj; + fc::optional empty_bool; + fc::optional true_bool = true; + update_betting_market_group(moneyline_cilic_vs_federer_id, empty_str, + empty_obj, empty_obj, + empty_bool, true_bool); + place_bet(alice_id, cilic_wins_final_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); place_bet(bob_id, cilic_wins_final_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); - betting_market_group_id_type moneyline_cilic_vs_federer_id = moneyline_cilic_vs_federer.id; auto cilic_wins_final_market_id = cilic_wins_final_market.id; auto federer_wins_final_market_id = federer_wins_final_market.id; diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 403feaed..e3766b6f 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -1359,7 +1359,9 @@ void database_fixture::update_betting_market_group(betting_market_group_id_type fc::optional description, fc::optional event_id, fc::optional rules_id, - fc::optional freeze) + fc::optional freeze, + fc::optional delay_bets + ) { try { betting_market_group_update_operation betting_market_group_update_op; betting_market_group_update_op.betting_market_group_id = betting_market_group_id; @@ -1367,8 +1369,9 @@ void database_fixture::update_betting_market_group(betting_market_group_id_type betting_market_group_update_op.new_event_id = event_id; betting_market_group_update_op.new_rules_id = rules_id; betting_market_group_update_op.freeze = freeze; + betting_market_group_update_op.delay_bets = delay_bets; process_operation_by_witnesses(betting_market_group_update_op); -} FC_CAPTURE_AND_RETHROW( (betting_market_group_id)(description)(event_id)(rules_id)) } +} FC_CAPTURE_AND_RETHROW( (betting_market_group_id)(description)(event_id)(rules_id)(freeze)(delay_bets)) } const betting_market_object& database_fixture::create_betting_market(betting_market_group_id_type group_id, internationalized_string_type payout_condition) diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index 2bd40e9c..2e46c33f 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -311,7 +311,8 @@ struct database_fixture { fc::optional description, fc::optional event_id, fc::optional rules_id, - fc::optional freeze); + fc::optional freeze, + fc::optional delay_bets); const betting_market_object& create_betting_market(betting_market_group_id_type group_id, internationalized_string_type payout_condition); void update_betting_market(betting_market_id_type betting_market_id,