update global_betting_statistics when new events created, change scores representation to simple vector of strings, working on evaluator for event_update_status_operation
This commit is contained in:
parent
c0776eb1dc
commit
239d8ee885
4 changed files with 48 additions and 6 deletions
|
|
@ -29,6 +29,7 @@
|
||||||
#include <graphene/chain/exceptions.hpp>
|
#include <graphene/chain/exceptions.hpp>
|
||||||
#include <graphene/chain/hardfork.hpp>
|
#include <graphene/chain/hardfork.hpp>
|
||||||
#include <graphene/chain/is_authorized_asset.hpp>
|
#include <graphene/chain/is_authorized_asset.hpp>
|
||||||
|
#include <graphene/chain/global_betting_statistics_object.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
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)
|
object_id_type event_create_evaluator::do_apply(const event_create_operation& op)
|
||||||
{ try {
|
{ try {
|
||||||
|
database& d = db();
|
||||||
const event_object& new_event =
|
const event_object& new_event =
|
||||||
db().create<event_object>( [&]( event_object& event_obj ) {
|
d.create<event_object>( [&]( event_object& event_obj ) {
|
||||||
event_obj.name = op.name;
|
event_obj.name = op.name;
|
||||||
event_obj.season = op.season;
|
event_obj.season = op.season;
|
||||||
event_obj.start_time = op.start_time;
|
event_obj.start_time = op.start_time;
|
||||||
event_obj.event_group_id = event_group_id;
|
event_obj.event_group_id = event_group_id;
|
||||||
event_obj.competitors = competitors;
|
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;
|
return new_event.id;
|
||||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
} 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
|
} } // graphene::chain
|
||||||
|
|
|
||||||
|
|
@ -41,4 +41,15 @@ namespace graphene { namespace chain {
|
||||||
vector<competitor_id_type> competitors;
|
vector<competitor_id_type> competitors;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class event_update_status_evaluator : public evaluator<event_update_status_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
|
} } // graphene::chain
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,6 @@ enum class event_status
|
||||||
* For a game like football, this may be a score like "3". For races,
|
* For a game like football, this may be a score like "3". For races,
|
||||||
* it could be a time like "1:53.4".
|
* it could be a time like "1:53.4".
|
||||||
*/
|
*/
|
||||||
typedef map<competitor_id_type, string> scores_map_type;
|
|
||||||
struct event_update_status_operation : public base_operation
|
struct event_update_status_operation : public base_operation
|
||||||
{
|
{
|
||||||
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
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;
|
event_status status;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the new scores to be merged with the existing scores (if this operation
|
* scores for each ompetitor stored in same order as competitors in event_object
|
||||||
* does not provide scores for all competitors, they will keep their
|
|
||||||
* previous score
|
|
||||||
*/
|
*/
|
||||||
scores_map_type scores;
|
vector<string> scores;
|
||||||
|
|
||||||
extensions_type extensions;
|
extensions_type extensions;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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::buyback_id_type )
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_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::betting_market_position_id_type )
|
||||||
|
FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::void_t, )
|
FC_REFLECT( graphene::chain::void_t, )
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue