diff --git a/libraries/chain/event_evaluator.cpp b/libraries/chain/event_evaluator.cpp index dae85357..59aa5d64 100644 --- a/libraries/chain/event_evaluator.cpp +++ b/libraries/chain/event_evaluator.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace graphene { namespace chain { @@ -72,15 +73,47 @@ void_result event_create_evaluator::do_evaluate(const event_create_operation& op object_id_type event_create_evaluator::do_apply(const event_create_operation& op) { try { + database& d = db(); const event_object& new_event = - db().create( [&]( event_object& event_obj ) { + d.create( [&]( event_object& event_obj ) { event_obj.name = op.name; event_obj.season = op.season; event_obj.start_time = op.start_time; event_obj.event_group_id = event_group_id; event_obj.competitors = competitors; + // There should be exactly one score for each competitor (score is initially just an empty string). + event_obj.scores.resize( competitors.size() ); }); + //increment number of active events in global betting statistics object + const global_betting_statistics_object& betting_statistics = global_betting_statistics_id_type()(d); + d.modify( betting_statistics, [&](global_betting_statistics_object& bso) { + bso.number_of_active_events += 1; + }); return new_event.id; } FC_CAPTURE_AND_RETHROW( (op) ) } +void_result event_update_status_evaluator::do_evaluate(const event_update_status_operation& op) +{ try { + FC_ASSERT(trx_state->_is_proposed_trx); + + database& d = db(); + //check that the event to update exists + _event_to_update = &op.event_id(d); + //if scores are reported, there must be a score for every competitor + FC_ASSERT( op.scores.empty() || _event_to_update->scores.size() == op.scores.size() ); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +void_result event_update_status_evaluator::do_apply(const event_update_status_operation& op) +{ try { + database& d = db(); + //TODO: cancel_all_betting_markets_for_event() //should we put this in event or just here in evaluator? + d.modify( *_event_to_update, [&]( event_object& event_obj) { + event_obj.scores = op.scores; + event_obj.status = op.status; + }); + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/event_evaluator.hpp b/libraries/chain/include/graphene/chain/event_evaluator.hpp index 5f82966f..656b5d00 100644 --- a/libraries/chain/include/graphene/chain/event_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/event_evaluator.hpp @@ -41,4 +41,15 @@ namespace graphene { namespace chain { vector competitors; }; + class event_update_status_evaluator : public evaluator + { + public: + typedef event_update_status_operation operation_type; + + void_result do_evaluate( const event_update_status_operation& o ); + void_result do_apply( const event_update_status_operation& o ); + private: + const event_object* _event_to_update = nullptr; + }; + } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/protocol/event.hpp b/libraries/chain/include/graphene/chain/protocol/event.hpp index bfe06483..b02135e0 100644 --- a/libraries/chain/include/graphene/chain/protocol/event.hpp +++ b/libraries/chain/include/graphene/chain/protocol/event.hpp @@ -81,7 +81,6 @@ enum class event_status * For a game like football, this may be a score like "3". For races, * it could be a time like "1:53.4". */ -typedef map scores_map_type; struct event_update_status_operation : public base_operation { struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; @@ -97,11 +96,9 @@ struct event_update_status_operation : public base_operation event_status status; /* - * the new scores to be merged with the existing scores (if this operation - * does not provide scores for all competitors, they will keep their - * previous score + * scores for each ompetitor stored in same order as competitors in event_object */ - scores_map_type scores; + vector scores; extensions_type extensions; diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 2d544509..b4d42d47 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -439,6 +439,7 @@ FC_REFLECT_TYPENAME( graphene::chain::special_authority_id_type ) FC_REFLECT_TYPENAME( graphene::chain::buyback_id_type ) FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type ) FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type ) FC_REFLECT( graphene::chain::void_t, )