changed cancel_all_bets to cancel_unmatched_bets
This commit is contained in:
parent
04985c2624
commit
67c134a138
14 changed files with 47 additions and 40 deletions
|
|
@ -217,7 +217,7 @@ struct get_impacted_account_visitor
|
|||
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 betting_market_group_cancel_all_bets_operation& op ) {}
|
||||
void operator()( const betting_market_group_cancel_unmatched_bets_operation& op ) {}
|
||||
|
||||
void operator()( const bet_place_operation& op )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -255,16 +255,16 @@ void_result betting_market_group_freeze_evaluator::do_apply(const betting_market
|
|||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
void_result betting_market_group_cancel_all_bets_evaluator::do_evaluate(const betting_market_group_cancel_all_bets_operation& op)
|
||||
void_result betting_market_group_cancel_unmatched_bets_evaluator::do_evaluate(const betting_market_group_cancel_unmatched_bets_operation& op)
|
||||
{ try {
|
||||
const database& d = db();
|
||||
_betting_market_group = &op.betting_market_group_id(d);
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
void_result betting_market_group_cancel_all_bets_evaluator::do_apply(const betting_market_group_cancel_all_bets_operation& op)
|
||||
void_result betting_market_group_cancel_unmatched_bets_evaluator::do_apply(const betting_market_group_cancel_unmatched_bets_operation& op)
|
||||
{ try {
|
||||
db().resolve_betting_market_group(*_betting_market_group, {}, true);
|
||||
db().cancel_all_unmatched_bets_on_betting_market_group(*_betting_market_group);
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
|
|
|
|||
|
|
@ -60,6 +60,19 @@ void database::validate_betting_market_group_resolutions(const betting_market_gr
|
|||
}
|
||||
}
|
||||
|
||||
void database::cancel_all_unmatched_bets_on_betting_market_group(const betting_market_group_object& betting_market_group)
|
||||
{
|
||||
auto& betting_market_index = get_index_type<betting_market_object_index>().indices().get<by_betting_market_group_id>();
|
||||
auto betting_market_itr = betting_market_index.lower_bound(betting_market_group.id);
|
||||
while (betting_market_itr != betting_market_index.end() && betting_market_itr->group_id == betting_market_group.id)
|
||||
{
|
||||
const betting_market_object& betting_market = *betting_market_itr;
|
||||
++betting_market_itr;
|
||||
cancel_all_unmatched_bets_on_betting_market(betting_market);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void database::resolve_betting_market_group(const betting_market_group_object& betting_market_group,
|
||||
const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions,
|
||||
bool do_not_remove)
|
||||
|
|
|
|||
|
|
@ -222,7 +222,7 @@ void database::initialize_evaluators()
|
|||
register_evaluator<betting_market_create_evaluator>();
|
||||
register_evaluator<bet_place_evaluator>();
|
||||
register_evaluator<betting_market_group_resolve_evaluator>();
|
||||
register_evaluator<betting_market_group_cancel_all_bets_evaluator>();
|
||||
register_evaluator<betting_market_group_cancel_unmatched_bets_evaluator>();
|
||||
register_evaluator<tournament_create_evaluator>();
|
||||
register_evaluator<tournament_join_evaluator>();
|
||||
register_evaluator<game_move_evaluator>();
|
||||
|
|
|
|||
|
|
@ -201,7 +201,7 @@ struct get_impacted_account_visitor
|
|||
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_cancel_all_bets_operation&){}
|
||||
void operator()(const betting_market_group_cancel_unmatched_bets_operation&){}
|
||||
void operator()(const bet_matched_operation &){}
|
||||
void operator()(const bet_cancel_operation&){}
|
||||
void operator()(const bet_canceled_operation &){}
|
||||
|
|
|
|||
|
|
@ -109,13 +109,13 @@ namespace graphene { namespace chain {
|
|||
};
|
||||
|
||||
|
||||
class betting_market_group_cancel_all_bets_evaluator : public evaluator<betting_market_group_cancel_all_bets_evaluator>
|
||||
class betting_market_group_cancel_unmatched_bets_evaluator : public evaluator<betting_market_group_cancel_unmatched_bets_evaluator>
|
||||
{
|
||||
public:
|
||||
typedef betting_market_group_cancel_all_bets_operation operation_type;
|
||||
typedef betting_market_group_cancel_unmatched_bets_operation operation_type;
|
||||
|
||||
void_result do_evaluate( const betting_market_group_cancel_all_bets_operation& o );
|
||||
void_result do_apply( const betting_market_group_cancel_all_bets_operation& o );
|
||||
void_result do_evaluate( const betting_market_group_cancel_unmatched_bets_operation& o );
|
||||
void_result do_apply( const betting_market_group_cancel_unmatched_bets_operation& o );
|
||||
private:
|
||||
const betting_market_group_object* _betting_market_group;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -380,6 +380,7 @@ namespace graphene { namespace chain {
|
|||
/// @{ @group Betting Market Helpers
|
||||
void cancel_bet(const bet_object& bet, bool create_virtual_op = true);
|
||||
void cancel_all_unmatched_bets_on_betting_market(const betting_market_object& betting_market);
|
||||
void cancel_all_unmatched_bets_on_betting_market_group(const betting_market_group_object& betting_market_group);
|
||||
void cancel_all_betting_markets_for_event(const event_object&);
|
||||
void validate_betting_market_group_resolutions(const betting_market_group_object& betting_market_group,
|
||||
const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions);
|
||||
|
|
|
|||
|
|
@ -173,7 +173,7 @@ struct betting_market_group_freeze_operation : public base_operation
|
|||
void validate()const;
|
||||
};
|
||||
|
||||
struct betting_market_group_cancel_all_bets_operation : public base_operation
|
||||
struct betting_market_group_cancel_unmatched_bets_operation : public base_operation
|
||||
{
|
||||
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
||||
asset fee;
|
||||
|
|
@ -333,8 +333,8 @@ FC_REFLECT( graphene::chain::betting_market_group_freeze_operation::fee_paramete
|
|||
FC_REFLECT( graphene::chain::betting_market_group_freeze_operation,
|
||||
(fee)(betting_market_group_id)(freeze)(extensions) )
|
||||
|
||||
FC_REFLECT( graphene::chain::betting_market_group_cancel_all_bets_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT( graphene::chain::betting_market_group_cancel_all_bets_operation,
|
||||
FC_REFLECT( graphene::chain::betting_market_group_cancel_unmatched_bets_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT( graphene::chain::betting_market_group_cancel_unmatched_bets_operation,
|
||||
(fee)(betting_market_group_id)(extensions) )
|
||||
|
||||
FC_REFLECT_ENUM( graphene::chain::bet_type, (back)(lay) )
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ namespace graphene { namespace chain {
|
|||
betting_market_group_resolve_operation,
|
||||
betting_market_group_resolved_operation, // VIRTUAL
|
||||
betting_market_group_freeze_operation,
|
||||
betting_market_group_cancel_all_bets_operation,
|
||||
betting_market_group_cancel_unmatched_bets_operation,
|
||||
bet_matched_operation, // VIRTUAL
|
||||
bet_cancel_operation,
|
||||
bet_canceled_operation, // VIRTUAL
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ void betting_market_group_freeze_operation::validate() const
|
|||
FC_ASSERT( fee.amount >= 0 );
|
||||
}
|
||||
|
||||
void betting_market_group_cancel_all_bets_operation::validate() const
|
||||
void betting_market_group_cancel_unmatched_bets_operation::validate() const
|
||||
{
|
||||
FC_ASSERT( fee.amount >= 0 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5231,14 +5231,14 @@ signed_transaction wallet_api::propose_cancel_betting_market_group(
|
|||
FC_ASSERT( !is_locked() );
|
||||
const chain_parameters& current_params = get_global_properties().parameters;
|
||||
|
||||
betting_market_group_cancel_all_bets_operation betting_market_group_cancel_all_bets_op;
|
||||
betting_market_group_cancel_all_bets_op.betting_market_group_id = betting_market_group_id;
|
||||
betting_market_group_cancel_unmatched_bets_operation betting_market_group_cancel_unmatched_bets_op;
|
||||
betting_market_group_cancel_unmatched_bets_op.betting_market_group_id = betting_market_group_id;
|
||||
|
||||
proposal_create_operation prop_op;
|
||||
prop_op.expiration_time = expiration_time;
|
||||
prop_op.review_period_seconds = current_params.committee_proposal_review_period;
|
||||
prop_op.fee_paying_account = get_account(proposing_account).id;
|
||||
prop_op.proposed_ops.emplace_back( betting_market_group_cancel_all_bets_op );
|
||||
prop_op.proposed_ops.emplace_back( betting_market_group_cancel_unmatched_bets_op );
|
||||
current_params.current_fees->set_fee( prop_op.proposed_ops.back().op );
|
||||
|
||||
signed_transaction tx;
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE( peerplays_sport_create_test )
|
|||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( cancel_betting_group_test )
|
||||
BOOST_AUTO_TEST_CASE( cancel_unmatched_in_betting_group_test )
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -195,26 +195,19 @@ BOOST_AUTO_TEST_CASE( cancel_betting_group_test )
|
|||
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 */);
|
||||
// have alice back a matching bet at 1:1 odds (also costing 1.02M)
|
||||
place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(1000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION, 1000000 / 50 /* chain defaults to 2% fees */);
|
||||
// place unmatched
|
||||
place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(500, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION, 10);
|
||||
place_bet(bob_id, blackhawks_win_market.id, bet_type::lay, asset(600, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION, 20);
|
||||
|
||||
BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000 - 20000 - 500 - 10);
|
||||
BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000 - 20000 - 600 - 20);
|
||||
|
||||
// cancel unmatched
|
||||
cancel_unmatched_bets(moneyline_betting_markets.id);
|
||||
|
||||
BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000 - 20000);
|
||||
BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000 - 20000);
|
||||
|
||||
// cancel
|
||||
cancel_all_bets_in_betting_market_group(moneyline_betting_markets.id);
|
||||
|
||||
BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000);
|
||||
BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000);
|
||||
|
||||
// bet again
|
||||
// have bob lay a bet for 1M (+20k fees) at 1:1 odds
|
||||
place_bet(bob_id, capitals_win_market.id, bet_type::lay, asset(2000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION, 1000000 / 50 /* chain defaults to 2% fees */);
|
||||
// have alice back a matching bet at 1:1 odds (also costing 1.02M)
|
||||
place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(2000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION, 1000000 / 50 /* chain defaults to 2% fees */);
|
||||
|
||||
BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 2000000 - 20000);
|
||||
BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 2000000 - 20000);
|
||||
|
||||
|
||||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1286,11 +1286,11 @@ void database_fixture::resolve_betting_market_group(betting_market_group_id_type
|
|||
process_operation_by_witnesses(betting_market_group_resolve_op);
|
||||
} FC_CAPTURE_AND_RETHROW( (betting_market_group_id)(resolutions) ) }
|
||||
|
||||
void database_fixture::cancel_all_bets_in_betting_market_group(betting_market_group_id_type betting_market_group_id)
|
||||
void database_fixture::cancel_unmatched_bets(betting_market_group_id_type betting_market_group_id)
|
||||
{ try {
|
||||
betting_market_group_cancel_all_bets_operation betting_market_group_cancel_all_bets_op;
|
||||
betting_market_group_cancel_all_bets_op.betting_market_group_id = betting_market_group_id;
|
||||
process_operation_by_witnesses(betting_market_group_cancel_all_bets_op);
|
||||
betting_market_group_cancel_unmatched_bets_operation betting_market_group_cancel_unmatched_bets_op;
|
||||
betting_market_group_cancel_unmatched_bets_op.betting_market_group_id = betting_market_group_id;
|
||||
process_operation_by_witnesses(betting_market_group_cancel_unmatched_bets_op);
|
||||
} FC_CAPTURE_AND_RETHROW( (betting_market_group_id) ) }
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -294,7 +294,7 @@ struct database_fixture {
|
|||
|
||||
void place_bet(account_id_type bettor_id, betting_market_id_type betting_market_id, bet_type back_or_lay, asset amount_to_bet, bet_multiplier_type backer_multiplier, share_type amount_reserved_for_fees);
|
||||
void resolve_betting_market_group(betting_market_group_id_type betting_market_group_id, std::map<betting_market_id_type, betting_market_resolution_type> resolutions);
|
||||
void cancel_all_bets_in_betting_market_group(betting_market_group_id_type betting_market_group_id);
|
||||
void cancel_unmatched_bets(betting_market_group_id_type betting_market_group_id);
|
||||
|
||||
proposal_id_type propose_operation(operation op);
|
||||
void process_proposal_by_witnesses(const std::vector<witness_id_type>& witnesses, proposal_id_type proposal_id, bool remove = false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue