improving cancel_all_bets operation

This commit is contained in:
Roman Olearski 2017-07-18 19:17:13 +02:00
parent 86b909da44
commit 04985c2624
4 changed files with 19 additions and 5 deletions

View file

@ -264,7 +264,7 @@ void_result betting_market_group_cancel_all_bets_evaluator::do_evaluate(const be
void_result betting_market_group_cancel_all_bets_evaluator::do_apply(const betting_market_group_cancel_all_bets_operation& op)
{ try {
db().resolve_betting_market_group(*_betting_market_group, {});
db().resolve_betting_market_group(*_betting_market_group, {}, true);
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -61,7 +61,8 @@ void database::validate_betting_market_group_resolutions(const betting_market_gr
}
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)
const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions,
bool do_not_remove)
{
bool cancel = resolutions.size() == 0;
@ -174,9 +175,11 @@ void database::resolve_betting_market_group(const betting_market_group_object& b
{
const betting_market_object& betting_market = *betting_market_itr;
++betting_market_itr;
remove(betting_market);
if (!do_not_remove)
remove(betting_market);
}
remove(betting_market_group);
if (!do_not_remove)
remove(betting_market_group);
}
#if 0

View file

@ -384,7 +384,8 @@ namespace graphene { namespace chain {
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);
void resolve_betting_market_group(const betting_market_group_object& betting_market_group,
const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions);
const std::map<betting_market_id_type, betting_market_resolution_type>& resolutions,
bool do_not_remove = false);
/**
* @brief Process a new bet
* @param new_bet_object The new bet to process

View file

@ -205,6 +205,16 @@ BOOST_AUTO_TEST_CASE( cancel_betting_group_test )
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()
}