From ec77685264a365be2b21495e6dde9b6c8e295b14 Mon Sep 17 00:00:00 2001 From: Roman Olearski Date: Wed, 9 Aug 2017 17:58:01 +0200 Subject: [PATCH] added is_live_market to event_update operation --- libraries/chain/betting_market_evaluator.cpp | 2 +- libraries/chain/event_evaluator.cpp | 14 +++++++++++++- .../chain/include/graphene/chain/event_object.hpp | 4 +++- .../include/graphene/chain/protocol/event.hpp | 4 +++- .../wallet/include/graphene/wallet/wallet.hpp | 1 + libraries/wallet/wallet.cpp | 2 ++ tests/betting/betting_tests.cpp | 11 ++++++----- tests/common/database_fixture.cpp | 4 +++- tests/common/database_fixture.hpp | 3 ++- 9 files changed, 34 insertions(+), 11 deletions(-) diff --git a/libraries/chain/betting_market_evaluator.cpp b/libraries/chain/betting_market_evaluator.cpp index 1cf73d8a..f41778c0 100644 --- a/libraries/chain/betting_market_evaluator.cpp +++ b/libraries/chain/betting_market_evaluator.cpp @@ -154,7 +154,7 @@ void_result betting_market_group_update_evaluator::do_evaluate(const betting_mar if (op.freeze.valid()) { const auto& _betting_market_group = &op.betting_market_group_id(db()); - FC_ASSERT(_betting_market_group->frozen != *op.freeze, "Freeze operation would not change the state of the betting market group"); + FC_ASSERT(_betting_market_group->frozen != *op.freeze, "freeze would not change the state of the betting market group"); } return void_result(); diff --git a/libraries/chain/event_evaluator.cpp b/libraries/chain/event_evaluator.cpp index ee9f7e03..41e104f2 100644 --- a/libraries/chain/event_evaluator.cpp +++ b/libraries/chain/event_evaluator.cpp @@ -74,7 +74,11 @@ object_id_type event_create_evaluator::do_apply(const event_create_operation& op void_result event_update_evaluator::do_evaluate(const event_update_operation& op) { try { FC_ASSERT(trx_state->_is_proposed_trx); - FC_ASSERT(op.new_event_group_id.valid() || op.new_name.valid() || op.new_season.valid() || op.new_start_time.valid(), "nothing to change"); + FC_ASSERT(op.new_event_group_id.valid() || + op.new_name.valid() || + op.new_season.valid() || + op.new_start_time.valid() || + op.is_live_market.valid(), "nothing to change"); if (op.new_event_group_id.valid()) { @@ -88,6 +92,12 @@ void_result event_update_evaluator::do_evaluate(const event_update_operation& op event_group_id = resolved_event_group_id; } + if (op.is_live_market.valid()) + { + const auto& _event_object = &op.event_id(db()); + FC_ASSERT(_event_object->is_live_market != *op.is_live_market, "is_live_market would not change the state of the event"); + } + return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -108,6 +118,8 @@ void_result event_update_evaluator::do_apply(const event_update_operation& op) eo.start_time = *op.new_start_time; if( op.new_event_group_id.valid() ) eo.event_group_id = event_group_id; + if( op.is_live_market.valid() ) + eo.is_live_market = *op.is_live_market; }); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/chain/include/graphene/chain/event_object.hpp b/libraries/chain/include/graphene/chain/event_object.hpp index 3a69b974..f866540f 100644 --- a/libraries/chain/include/graphene/chain/event_object.hpp +++ b/libraries/chain/include/graphene/chain/event_object.hpp @@ -45,6 +45,8 @@ class event_object : public graphene::db::abstract_object< event_object > event_group_id_type event_group_id; + bool is_live_market; + event_status status; vector scores; }; @@ -57,4 +59,4 @@ typedef multi_index_container< typedef generic_index event_object_index; } } // graphene::chain -FC_REFLECT_DERIVED( graphene::chain::event_object, (graphene::db::object), (name)(season)(start_time)(event_group_id)(status)(scores) ) +FC_REFLECT_DERIVED( graphene::chain::event_object, (graphene::db::object), (name)(season)(start_time)(event_group_id)(is_live_market)(status)(scores) ) diff --git a/libraries/chain/include/graphene/chain/protocol/event.hpp b/libraries/chain/include/graphene/chain/protocol/event.hpp index 4a1ee896..6f50e612 100644 --- a/libraries/chain/include/graphene/chain/protocol/event.hpp +++ b/libraries/chain/include/graphene/chain/protocol/event.hpp @@ -69,6 +69,8 @@ struct event_update_operation : public base_operation optional new_start_time; + optional is_live_market; + extensions_type extensions; account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } @@ -130,7 +132,7 @@ FC_REFLECT( graphene::chain::event_create_operation, FC_REFLECT( graphene::chain::event_update_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::event_update_operation, - (fee)(event_id)(new_event_group_id)(new_name)(new_season)(new_start_time)(extensions) ) + (fee)(event_id)(new_event_group_id)(new_name)(new_season)(new_start_time)(is_live_market)(extensions) ) FC_REFLECT_ENUM( graphene::chain::event_status, (upcoming)(in_progress)(frozen)(completed)(canceled)(STATUS_COUNT) ) FC_REFLECT( graphene::chain::event_update_status_operation::fee_parameters_type, (fee) ) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index fec081cb..3342564e 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1625,6 +1625,7 @@ class wallet_api fc::optional event_group_id, fc::optional name, fc::optional season, + fc::optional is_live_market, fc::optional start_time, bool broadcast = false); diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 08459abc..9d23f816 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -5180,6 +5180,7 @@ signed_transaction wallet_api::propose_update_event( fc::optional event_group_id, fc::optional name, fc::optional season, + fc::optional is_live_market, fc::optional start_time, bool broadcast /*= false*/) { @@ -5192,6 +5193,7 @@ signed_transaction wallet_api::propose_update_event( event_update_op.new_start_time = start_time; event_update_op.new_name = name; event_update_op.new_season = season; + event_update_op.is_live_market = is_live_market; proposal_create_operation prop_op; prop_op.expiration_time = expiration_time; diff --git a/tests/betting/betting_tests.cpp b/tests/betting/betting_tests.cpp index 49053ceb..f2921b19 100644 --- a/tests/betting/betting_tests.cpp +++ b/tests/betting/betting_tests.cpp @@ -619,16 +619,17 @@ BOOST_AUTO_TEST_CASE(event_update_test) fc::optional name = internationalized_string_type({{"en", "Washington Capitals vs. Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホーク"}}); fc::optional season = internationalized_string_type({{"en", "2017-18"}}); fc::optional empty_object_id; + fc::optional empty_bool; - update_event(capitals_vs_blackhawks.id, empty_object_id, name, empty); - update_event(capitals_vs_blackhawks.id, empty_object_id, empty, season); - update_event(capitals_vs_blackhawks.id, empty_object_id, name, season); + update_event(capitals_vs_blackhawks.id, empty_object_id, name, empty, empty_bool); + update_event(capitals_vs_blackhawks.id, empty_object_id, empty, season, empty_bool); + update_event(capitals_vs_blackhawks.id, empty_object_id, name, season, empty_bool); const sport_object& ice_on_hockey = create_sport({{"en", "Hockey on Ice"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \ const event_group_object& nhl2 = create_event_group({{"en", "NHL2"}, {"zh_Hans", "國家冰球聯盟"}, {"ja", "ナショナルホッケーリーグ"}}, ice_on_hockey.id); \ fc::optional event_group_id = nhl2.id; - update_event(capitals_vs_blackhawks.id, event_group_id , empty, empty); + update_event(capitals_vs_blackhawks.id, event_group_id , empty, empty, empty_bool); place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION, 1000000 / 50 /* chain defaults to 2% fees */); @@ -958,7 +959,7 @@ BOOST_AUTO_TEST_CASE( wimbledon_2017_gentelmen_singles_final_test ) update_event(cilic_vs_federer.id, fc::optional(), internationalized_string_type({{"en", "R. Federer vs. M. Cilic"}}), - fc::optional()); + fc::optional(), fc::optional()); generate_blocks(13); diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index f6881f36..aa113972 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -1310,13 +1310,15 @@ const event_object& database_fixture::create_event(internationalized_string_type void database_fixture::update_event(event_id_type event_id, fc::optional event_group_id, fc::optional name, - fc::optional season) + fc::optional season, + fc::optional is_live_market) { try { event_update_operation event_update_op; event_update_op.event_id = event_id; event_update_op.new_event_group_id = event_group_id; event_update_op.new_name = name; event_update_op.new_season = season; + event_update_op.is_live_market = is_live_market; process_operation_by_witnesses(event_update_op); } FC_CAPTURE_AND_RETHROW( (name)(season) ) } diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index a8241a96..849c8992 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -300,7 +300,8 @@ struct database_fixture { void update_event(event_id_type event_id, fc::optional event_group_id, fc::optional name, - fc::optional season); + fc::optional season, + fc::optional is_live_market); const betting_market_rules_object& create_betting_market_rules(internationalized_string_type name, internationalized_string_type description); void update_betting_market_rules(betting_market_rules_id_type rules_id, fc::optional name,