diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index a5543cc1..10d17fcb 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -216,6 +216,7 @@ struct get_impacted_account_visitor void operator()( const betting_market_group_create_operation& op ) {} void operator()( const betting_market_create_operation& op ) {} void operator()( const betting_market_group_resolve_operation& op ) {} + void operator()( const betting_market_group_freeze_operation& op ) {} void operator()( const bet_place_operation& op ) { _impacted.insert( op.bettor_id ); diff --git a/libraries/chain/betting_market_evaluator.cpp b/libraries/chain/betting_market_evaluator.cpp index f5a9f778..8823e160 100644 --- a/libraries/chain/betting_market_evaluator.cpp +++ b/libraries/chain/betting_market_evaluator.cpp @@ -84,6 +84,7 @@ object_id_type betting_market_group_create_evaluator::do_apply(const betting_mar betting_market_group_obj.event_id = event_id; betting_market_group_obj.rules_id = rules_id; betting_market_group_obj.description = op.description; + betting_market_group_obj.frozen = false; }); return new_betting_market_group.id; } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -129,6 +130,8 @@ void_result bet_place_evaluator::do_evaluate(const bet_place_operation& op) FC_ASSERT( op.amount_to_bet.asset_id == _betting_market->asset_id, "Asset type bet does not match the market's asset type" ); + FC_ASSERT( !_betting_market_group->frozen, "Unable to place bets while the market is frozen" ); + _asset = &_betting_market->asset_id(d); FC_ASSERT( is_authorized_asset( d, *fee_paying_account, *_asset ) ); @@ -232,5 +235,21 @@ void_result betting_market_group_resolve_evaluator::do_apply(const betting_marke return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } +void_result betting_market_group_freeze_evaluator::do_evaluate(const betting_market_group_freeze_operation& op) +{ try { + const database& d = db(); + _betting_market_group = &op.betting_market_group_id(d); + FC_ASSERT(_betting_market_group->frozen != op.freeze, "Freeze operation would not change the state of the betting market group"); + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +void_result betting_market_group_freeze_evaluator::do_apply(const betting_market_group_freeze_operation& op) +{ try { + db().modify(*_betting_market_group, [&]( betting_market_group_object& betting_market_group_obj ) { + betting_market_group_obj.frozen = op.freeze; + }); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } } } // graphene::chain diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index 9c2f1ee7..5cdbbf25 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -199,6 +199,7 @@ struct get_impacted_account_visitor void operator()(const betting_market_create_operation&){} void operator()(const bet_place_operation&){} void operator()(const betting_market_group_resolve_operation&){} + void operator()(const betting_market_group_freeze_operation&){} void operator()(const betting_market_group_resolved_operation &){} void operator()(const bet_matched_operation &){} void operator()(const bet_cancel_operation&){} diff --git a/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp b/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp index 3b4ae42e..d4020e88 100644 --- a/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_evaluator.hpp @@ -97,5 +97,14 @@ namespace graphene { namespace chain { const betting_market_group_object* _betting_market_group; }; + class betting_market_group_freeze_evaluator : public evaluator + { + public: + typedef betting_market_group_freeze_operation operation_type; + void_result do_evaluate( const betting_market_group_freeze_operation& o ); + void_result do_apply( const betting_market_group_freeze_operation& o ); + private: + const betting_market_group_object* _betting_market_group; + }; } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp index f1e13661..71c3cd34 100644 --- a/libraries/chain/include/graphene/chain/betting_market_object.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -59,6 +59,8 @@ class betting_market_group_object : public graphene::db::abstract_object< bettin event_id_type event_id; betting_market_rules_id_type rules_id; + + bool frozen; }; class betting_market_object : public graphene::db::abstract_object< betting_market_object > @@ -425,7 +427,7 @@ typedef generic_index& resolutions, - std::vector winnings, - std::vector fees_paid) : + betting_market_group_id_type betting_market_group_id, + const std::map& resolutions, + std::vector winnings, + std::vector fees_paid) : bettor_id(bettor_id), betting_market_group_id(betting_market_group_id), resolutions(resolutions), winnings(winnings), fees_paid(fees_paid) { - // TODO ? } account_id_type fee_payer()const { return bettor_id; } @@ -156,6 +155,20 @@ struct betting_market_group_resolved_operation : public base_operation share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; +struct betting_market_group_freeze_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + betting_market_group_id_type betting_market_group_id; + bool freeze; // the new state of the betting market + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; + enum class bet_type { back, lay }; struct bet_place_operation : public base_operation @@ -299,6 +312,10 @@ FC_REFLECT( graphene::chain::betting_market_group_resolved_operation::fee_parame FC_REFLECT( graphene::chain::betting_market_group_resolved_operation, (bettor_id)(betting_market_group_id)(resolutions)(winnings)(fees_paid)(fee) ) +FC_REFLECT( graphene::chain::betting_market_group_freeze_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::betting_market_group_freeze_operation, + (fee)(betting_market_group_id)(freeze)(extensions) ) + FC_REFLECT_ENUM( graphene::chain::bet_type, (back)(lay) ) FC_REFLECT( graphene::chain::bet_place_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::bet_place_operation, diff --git a/libraries/chain/include/graphene/chain/protocol/event.hpp b/libraries/chain/include/graphene/chain/protocol/event.hpp index f736eefc..cf809f33 100644 --- a/libraries/chain/include/graphene/chain/protocol/event.hpp +++ b/libraries/chain/include/graphene/chain/protocol/event.hpp @@ -62,6 +62,7 @@ enum class event_status { upcoming, in_progress, + frozen, completed, canceled, STATUS_COUNT @@ -105,7 +106,7 @@ struct event_update_status_operation : public base_operation FC_REFLECT( graphene::chain::event_create_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::event_create_operation, (fee)(name)(season)(start_time)(event_group_id)(extensions) ) -FC_REFLECT_ENUM( graphene::chain::event_status, (upcoming)(in_progress)(completed)(canceled)(STATUS_COUNT) ) +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) ) FC_REFLECT( graphene::chain::event_update_status_operation, (fee)(event_id)(status)(scores)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index b26fbcf3..7d9ccc2a 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -107,6 +107,7 @@ namespace graphene { namespace chain { bet_place_operation, betting_market_group_resolve_operation, betting_market_group_resolved_operation, // VIRTUAL + betting_market_group_freeze_operation, bet_matched_operation, // VIRTUAL bet_cancel_operation, bet_canceled_operation // VIRTUAL diff --git a/libraries/chain/protocol/betting_market.cpp b/libraries/chain/protocol/betting_market.cpp index 70a44acd..ce85ab30 100644 --- a/libraries/chain/protocol/betting_market.cpp +++ b/libraries/chain/protocol/betting_market.cpp @@ -42,7 +42,12 @@ void betting_market_create_operation::validate() const void betting_market_group_resolve_operation::validate() const { - //FC_ASSERT( fee.amount >= 0 ); + FC_ASSERT( fee.amount >= 0 ); +} + +void betting_market_group_freeze_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); } void bet_place_operation::validate() const