Add an operation to freeze/unfreeze a betting market group

This commit is contained in:
Eric Frias 2017-07-09 13:52:01 -04:00
parent 5de1437d24
commit 4e2c6c303a
9 changed files with 64 additions and 8 deletions

View file

@ -216,6 +216,7 @@ struct get_impacted_account_visitor
void operator()( const betting_market_group_create_operation& op ) {} void operator()( const betting_market_group_create_operation& op ) {}
void operator()( const betting_market_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_resolve_operation& op ) {}
void operator()( const betting_market_group_freeze_operation& op ) {}
void operator()( const bet_place_operation& op ) void operator()( const bet_place_operation& op )
{ {
_impacted.insert( op.bettor_id ); _impacted.insert( op.bettor_id );

View file

@ -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.event_id = event_id;
betting_market_group_obj.rules_id = rules_id; betting_market_group_obj.rules_id = rules_id;
betting_market_group_obj.description = op.description; betting_market_group_obj.description = op.description;
betting_market_group_obj.frozen = false;
}); });
return new_betting_market_group.id; return new_betting_market_group.id;
} FC_CAPTURE_AND_RETHROW( (op) ) } } 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, FC_ASSERT( op.amount_to_bet.asset_id == _betting_market->asset_id,
"Asset type bet does not match the market's asset type" ); "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); _asset = &_betting_market->asset_id(d);
FC_ASSERT( is_authorized_asset( d, *fee_paying_account, *_asset ) ); 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(); return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) } } 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 } } // graphene::chain

View file

@ -199,6 +199,7 @@ struct get_impacted_account_visitor
void operator()(const betting_market_create_operation&){} void operator()(const betting_market_create_operation&){}
void operator()(const bet_place_operation&){} void operator()(const bet_place_operation&){}
void operator()(const betting_market_group_resolve_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 betting_market_group_resolved_operation &){}
void operator()(const bet_matched_operation &){} void operator()(const bet_matched_operation &){}
void operator()(const bet_cancel_operation&){} void operator()(const bet_cancel_operation&){}

View file

@ -97,5 +97,14 @@ namespace graphene { namespace chain {
const betting_market_group_object* _betting_market_group; const betting_market_group_object* _betting_market_group;
}; };
class betting_market_group_freeze_evaluator : public evaluator<betting_market_group_freeze_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 } } // graphene::chain

View file

@ -59,6 +59,8 @@ class betting_market_group_object : public graphene::db::abstract_object< bettin
event_id_type event_id; event_id_type event_id;
betting_market_rules_id_type rules_id; betting_market_rules_id_type rules_id;
bool frozen;
}; };
class betting_market_object : public graphene::db::abstract_object< betting_market_object > class betting_market_object : public graphene::db::abstract_object< betting_market_object >
@ -425,7 +427,7 @@ typedef generic_index<betting_market_position_object, betting_market_position_mu
} } // graphene::chain } } // graphene::chain
FC_REFLECT_DERIVED( graphene::chain::betting_market_rules_object, (graphene::db::object), (name)(description) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_rules_object, (graphene::db::object), (name)(description) )
FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (event_id)(description) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (description)(event_id)(rules_id)(frozen) )
FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id)(description)(payout_condition)(asset_id) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id)(description)(payout_condition)(asset_id) )
FC_REFLECT_DERIVED( graphene::chain::bet_object, (graphene::db::object), (bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(amount_reserved_for_fees)(back_or_lay) ) FC_REFLECT_DERIVED( graphene::chain::bet_object, (graphene::db::object), (bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(amount_reserved_for_fees)(back_or_lay) )

View file

@ -137,17 +137,16 @@ struct betting_market_group_resolved_operation : public base_operation
betting_market_group_resolved_operation() {} betting_market_group_resolved_operation() {}
betting_market_group_resolved_operation(account_id_type bettor_id, betting_market_group_resolved_operation(account_id_type bettor_id,
betting_market_group_id_type betting_market_group_id, betting_market_group_id_type betting_market_group_id,
const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions, const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions,
std::vector<asset> winnings, std::vector<asset> winnings,
std::vector<asset> fees_paid) : std::vector<asset> fees_paid) :
bettor_id(bettor_id), bettor_id(bettor_id),
betting_market_group_id(betting_market_group_id), betting_market_group_id(betting_market_group_id),
resolutions(resolutions), resolutions(resolutions),
winnings(winnings), winnings(winnings),
fees_paid(fees_paid) fees_paid(fees_paid)
{ {
// TODO ?
} }
account_id_type fee_payer()const { return bettor_id; } 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; } 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 }; enum class bet_type { back, lay };
struct bet_place_operation : public base_operation 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, FC_REFLECT( graphene::chain::betting_market_group_resolved_operation,
(bettor_id)(betting_market_group_id)(resolutions)(winnings)(fees_paid)(fee) ) (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_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::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::bet_place_operation, FC_REFLECT( graphene::chain::bet_place_operation,

View file

@ -62,6 +62,7 @@ enum class event_status
{ {
upcoming, upcoming,
in_progress, in_progress,
frozen,
completed, completed,
canceled, canceled,
STATUS_COUNT 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_parameters_type, (fee) )
FC_REFLECT( graphene::chain::event_create_operation, FC_REFLECT( graphene::chain::event_create_operation,
(fee)(name)(season)(start_time)(event_group_id)(extensions) ) (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_parameters_type, (fee) )
FC_REFLECT( graphene::chain::event_update_status_operation, FC_REFLECT( graphene::chain::event_update_status_operation,
(fee)(event_id)(status)(scores)(extensions) ) (fee)(event_id)(status)(scores)(extensions) )

View file

@ -107,6 +107,7 @@ namespace graphene { namespace chain {
bet_place_operation, bet_place_operation,
betting_market_group_resolve_operation, betting_market_group_resolve_operation,
betting_market_group_resolved_operation, // VIRTUAL betting_market_group_resolved_operation, // VIRTUAL
betting_market_group_freeze_operation,
bet_matched_operation, // VIRTUAL bet_matched_operation, // VIRTUAL
bet_cancel_operation, bet_cancel_operation,
bet_canceled_operation // VIRTUAL bet_canceled_operation // VIRTUAL

View file

@ -42,7 +42,12 @@ void betting_market_create_operation::validate() const
void betting_market_group_resolve_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 void bet_place_operation::validate() const