Fix missing const qualifier, payouts for betting market wins
This commit is contained in:
parent
c8a9c86ca6
commit
e74a505622
4 changed files with 25 additions and 20 deletions
|
|
@ -21,9 +21,15 @@ void database::cancel_bet( const bet_object& bet, bool create_virtual_op )
|
|||
|
||||
void database::cancel_all_unmatched_bets_on_betting_market(const betting_market_object& betting_market)
|
||||
{
|
||||
auto& bet_index = get_index_type<bet_object_index>().indices().get<by_betting_market>();
|
||||
for (const bet_object& bet : bet_index)
|
||||
cancel_bet(bet, true);
|
||||
const auto& bet_odds_idx = get_index_type<bet_object_index>().indices().get<by_odds>();
|
||||
auto book_itr = bet_odds_idx.lower_bound(std::make_tuple(betting_market.id));
|
||||
auto book_end = bet_odds_idx.upper_bound(std::make_tuple(betting_market.id));
|
||||
while (book_itr != book_end)
|
||||
{
|
||||
auto old_book_itr = book_itr;
|
||||
++book_itr;
|
||||
cancel_bet(*old_book_itr, true);
|
||||
}
|
||||
}
|
||||
|
||||
void database::resolve_betting_market(const betting_market_object& betting_market,
|
||||
|
|
@ -82,7 +88,7 @@ bool maybe_cull_small_bet( database& db, const bet_object& bet_object_to_cull )
|
|||
return false;
|
||||
}
|
||||
|
||||
share_type adjust_betting_position(database& db, account_id_type bettor_id, betting_market_id_type betting_market_id, bet_type back_or_lay, share_type bet_amount, share_type fees_collected)
|
||||
share_type adjust_betting_position(database& db, account_id_type bettor_id, betting_market_id_type betting_market_id, bet_type back_or_lay, share_type bet_amount, share_type matched_amount, share_type fees_collected)
|
||||
{ try {
|
||||
assert(bet_amount >= 0);
|
||||
|
||||
|
|
@ -98,8 +104,8 @@ share_type adjust_betting_position(database& db, account_id_type bettor_id, bett
|
|||
db.create<betting_market_position_object>([&](betting_market_position_object& position) {
|
||||
position.bettor_id = bettor_id;
|
||||
position.betting_market_id = betting_market_id;
|
||||
position.pay_if_payout_condition = back_or_lay == bet_type::back ? bet_amount : 0;
|
||||
position.pay_if_not_payout_condition = back_or_lay == bet_type::lay ? bet_amount : 0;
|
||||
position.pay_if_payout_condition = back_or_lay == bet_type::back ? bet_amount + matched_amount : 0;
|
||||
position.pay_if_not_payout_condition = back_or_lay == bet_type::lay ? bet_amount + matched_amount : 0;
|
||||
position.pay_if_canceled = bet_amount;
|
||||
position.pay_if_not_canceled = 0;
|
||||
position.fees_collected = fees_collected;
|
||||
|
|
@ -109,8 +115,8 @@ share_type adjust_betting_position(database& db, account_id_type bettor_id, bett
|
|||
db.modify(*itr, [&](betting_market_position_object& position) {
|
||||
assert(position.bettor_id == bettor_id);
|
||||
assert(position.betting_market_id == betting_market_id);
|
||||
position.pay_if_payout_condition += back_or_lay == bet_type::back ? bet_amount : 0;
|
||||
position.pay_if_not_payout_condition += back_or_lay == bet_type::lay ? bet_amount : 0;
|
||||
position.pay_if_payout_condition += back_or_lay == bet_type::back ? bet_amount + matched_amount : 0;
|
||||
position.pay_if_not_payout_condition += back_or_lay == bet_type::lay ? bet_amount + matched_amount : 0;
|
||||
position.pay_if_canceled += bet_amount;
|
||||
position.fees_collected += fees_collected;
|
||||
|
||||
|
|
@ -121,7 +127,7 @@ share_type adjust_betting_position(database& db, account_id_type bettor_id, bett
|
|||
} FC_CAPTURE_AND_RETHROW((bettor_id)(betting_market_id)(bet_amount)) }
|
||||
|
||||
|
||||
bool bet_was_matched(database& db, const bet_object& bet, share_type amount_bet, bet_multiplier_type actual_multiplier, bool cull_if_small)
|
||||
bool bet_was_matched(database& db, const bet_object& bet, share_type amount_bet, share_type amount_matched, bet_multiplier_type actual_multiplier, bool cull_if_small)
|
||||
{
|
||||
// calculate the percentage fee paid
|
||||
fc::uint128_t percentage_fee_128 = bet.amount_reserved_for_fees.value;
|
||||
|
|
@ -132,7 +138,7 @@ bool bet_was_matched(database& db, const bet_object& bet, share_type amount_bet,
|
|||
|
||||
// record their bet, modifying their position, and return any winnings
|
||||
share_type guaranteed_winnings_returned = adjust_betting_position(db, bet.bettor_id, bet.betting_market_id,
|
||||
bet.back_or_lay, amount_bet, fee_paid);
|
||||
bet.back_or_lay, amount_bet, amount_matched, fee_paid);
|
||||
db.adjust_balance(bet.bettor_id, asset(guaranteed_winnings_returned, bet.amount_to_bet.asset_id));
|
||||
|
||||
// generate a virtual "match" op
|
||||
|
|
@ -184,8 +190,8 @@ int match_bet(database& db, const bet_object& taker_bet, const bet_object& maker
|
|||
if (maximum_amount_to_match <= maker_bet.amount_to_bet.amount)
|
||||
{
|
||||
// we will consume the entire taker bet
|
||||
result |= bet_was_matched(db, taker_bet, taker_bet.amount_to_bet.amount, maker_bet.backer_multiplier, true);
|
||||
result |= bet_was_matched(db, maker_bet, maximum_amount_to_match, maker_bet.backer_multiplier, true) << 1;
|
||||
result |= bet_was_matched(db, taker_bet, taker_bet.amount_to_bet.amount, maximum_amount_to_match, maker_bet.backer_multiplier, true);
|
||||
result |= bet_was_matched(db, maker_bet, maximum_amount_to_match, taker_bet.amount_to_bet.amount, maker_bet.backer_multiplier, true) << 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -193,8 +199,8 @@ int match_bet(database& db, const bet_object& taker_bet, const bet_object& maker
|
|||
share_type taker_amount = maker_bet.get_matching_amount();
|
||||
share_type maker_amount = bet_object::get_matching_amount(taker_amount, maker_bet.backer_multiplier, taker_bet.back_or_lay);
|
||||
|
||||
result |= bet_was_matched(db, taker_bet, taker_amount, maker_bet.backer_multiplier, true);
|
||||
result |= bet_was_matched(db, maker_bet, maker_amount, maker_bet.backer_multiplier, true) << 1;
|
||||
result |= bet_was_matched(db, taker_bet, taker_amount, maker_amount, maker_bet.backer_multiplier, true);
|
||||
result |= bet_was_matched(db, maker_bet, maker_amount, taker_amount, maker_bet.backer_multiplier, true) << 1;
|
||||
}
|
||||
|
||||
assert(result != 0);
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ struct compare_bet_by_odds {
|
|||
return compare(lhs.betting_market_id, lhs.back_or_lay, lhs.backer_multiplier, lhs.id,
|
||||
std::get<0>(rhs), std::get<1>(rhs), std::get<2>(rhs), std::get<3>(rhs));
|
||||
}
|
||||
bool compare(const betting_market_id_type& lhs_betting_market_id, const betting_market_id_type& rhs_betting_market_id)
|
||||
bool compare(const betting_market_id_type& lhs_betting_market_id, const betting_market_id_type& rhs_betting_market_id) const
|
||||
{
|
||||
return lhs_betting_market_id < rhs_betting_market_id;
|
||||
}
|
||||
|
|
@ -226,14 +226,11 @@ struct compare_bet_by_odds {
|
|||
};
|
||||
|
||||
struct by_odds {};
|
||||
struct by_betting_market {};
|
||||
typedef multi_index_container<
|
||||
bet_object,
|
||||
indexed_by<
|
||||
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
||||
ordered_unique< tag<by_odds>, identity<bet_object>, compare_bet_by_odds >,
|
||||
ordered_non_unique< tag<by_betting_market>, member< bet_object, betting_market_id_type, &bet_object::betting_market_id > >
|
||||
> > bet_object_multi_index_type;
|
||||
ordered_unique< tag<by_odds>, identity<bet_object>, compare_bet_by_odds > > > bet_object_multi_index_type;
|
||||
|
||||
typedef generic_index<bet_object, bet_object_multi_index_type> bet_object_index;
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 57d14c7de849c567d753fc5cab5465d68602ff95
|
||||
Subproject commit 9d408aa53267834542279490eac4c25878107967
|
||||
|
|
@ -1842,6 +1842,8 @@ BOOST_AUTO_TEST_CASE( peerplays_sport_create_test )
|
|||
db.push_transaction(tx);
|
||||
}
|
||||
|
||||
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);
|
||||
// caps win
|
||||
{
|
||||
proposal_create_operation proposal_op;
|
||||
|
|
|
|||
Loading…
Reference in a new issue