Generate a virtual op when a market is resolved
This commit is contained in:
parent
094004db7b
commit
69192a889d
4 changed files with 57 additions and 9 deletions
|
|
@ -226,6 +226,10 @@ struct get_impacted_account_visitor
|
||||||
{
|
{
|
||||||
_impacted.insert( op.bettor_id );
|
_impacted.insert( op.bettor_id );
|
||||||
}
|
}
|
||||||
|
void operator()( const betting_market_resolved_operation& op )
|
||||||
|
{
|
||||||
|
_impacted.insert( op.bettor_id );
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
#include <graphene/chain/betting_market_object.hpp>
|
#include <graphene/chain/betting_market_object.hpp>
|
||||||
#include <graphene/chain/event_object.hpp>
|
#include <graphene/chain/event_object.hpp>
|
||||||
|
|
||||||
|
#include <boost/range/iterator_range.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
void database::cancel_bet( const bet_object& bet, bool create_virtual_op )
|
void database::cancel_bet( const bet_object& bet, bool create_virtual_op )
|
||||||
|
|
@ -35,22 +37,24 @@ void database::cancel_all_unmatched_bets_on_betting_market(const betting_market_
|
||||||
|
|
||||||
void database::cancel_all_betting_markets_for_event(const event_object& event_obj)
|
void database::cancel_all_betting_markets_for_event(const event_object& event_obj)
|
||||||
{
|
{
|
||||||
//for each betting market group of event
|
|
||||||
auto& betting_market_group_index = get_index_type<betting_market_group_object_index>().indices().get<by_event_id>();
|
auto& betting_market_group_index = get_index_type<betting_market_group_object_index>().indices().get<by_event_id>();
|
||||||
auto betting_market_group_itr = betting_market_group_index.lower_bound(event_obj.id);
|
auto& betting_market_index = get_index_type<betting_market_object_index>().indices().get<by_betting_market_group_id>();
|
||||||
while (betting_market_group_itr != betting_market_group_index.end() &&
|
|
||||||
betting_market_group_itr->event_id == event_obj.id)
|
//for each betting market group of event
|
||||||
|
for (const betting_market_group_object& betting_market_group :
|
||||||
|
boost::make_iterator_range(betting_market_group_index.equal_range(event_obj.id)))
|
||||||
{
|
{
|
||||||
//for each betting market in the betting market group
|
//for each betting market in the 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);
|
||||||
auto betting_market_itr = betting_market_index.lower_bound(betting_market_group_itr->id);
|
|
||||||
while (betting_market_itr != betting_market_index.end() &&
|
while (betting_market_itr != betting_market_index.end() &&
|
||||||
betting_market_itr->group_id == betting_market_group_itr->id)
|
betting_market_itr->group_id == betting_market_group.id)
|
||||||
{
|
{
|
||||||
resolve_betting_market(*betting_market_itr, betting_market_resolution_type::cancel);
|
auto old_betting_market_itr = betting_market_itr;
|
||||||
++betting_market_itr;
|
++betting_market_itr;
|
||||||
|
resolve_betting_market(*old_betting_market_itr, betting_market_resolution_type::cancel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO: should we remove market groups once all their markets are resolved?
|
||||||
}
|
}
|
||||||
|
|
||||||
void database::resolve_betting_market(const betting_market_object& betting_market,
|
void database::resolve_betting_market(const betting_market_object& betting_market,
|
||||||
|
|
@ -85,7 +89,12 @@ void database::resolve_betting_market(const betting_market_object& betting_marke
|
||||||
adjust_balance(position.bettor_id, asset(payout_amount, betting_market.asset_id));
|
adjust_balance(position.bettor_id, asset(payout_amount, betting_market.asset_id));
|
||||||
//TODO: pay the fees to the correct (dividend-distribution) account
|
//TODO: pay the fees to the correct (dividend-distribution) account
|
||||||
adjust_balance(account_id_type(), asset(position.fees_collected, betting_market.asset_id));
|
adjust_balance(account_id_type(), asset(position.fees_collected, betting_market.asset_id));
|
||||||
//TODO: generate a virtual op to notify the bettor that they won or lost
|
|
||||||
|
push_applied_operation(betting_market_resolved_operation(position.bettor_id,
|
||||||
|
betting_market.id,
|
||||||
|
resolution,
|
||||||
|
payout_amount,
|
||||||
|
position.fees_collected));
|
||||||
|
|
||||||
remove(position);
|
remove(position);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,37 @@ struct betting_market_resolve_operation : public base_operation
|
||||||
void validate()const;
|
void validate()const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct betting_market_resolved_operation : public base_operation
|
||||||
|
{
|
||||||
|
struct fee_parameters_type {};
|
||||||
|
|
||||||
|
account_id_type bettor_id;
|
||||||
|
betting_market_id_type betting_market_id;
|
||||||
|
betting_market_resolution_type resolution;
|
||||||
|
asset winnings;
|
||||||
|
share_type fees_paid;
|
||||||
|
|
||||||
|
asset fee; // unused in a virtual operation
|
||||||
|
|
||||||
|
betting_market_resolved_operation() {}
|
||||||
|
betting_market_resolved_operation(account_id_type bettor_id,
|
||||||
|
betting_market_id_type betting_market_id,
|
||||||
|
betting_market_resolution_type resolution,
|
||||||
|
asset winnings,
|
||||||
|
share_type fees_paid) :
|
||||||
|
bettor_id(bettor_id),
|
||||||
|
betting_market_id(betting_market_id),
|
||||||
|
resolution(resolution),
|
||||||
|
winnings(winnings),
|
||||||
|
fees_paid(fees_paid)
|
||||||
|
{}
|
||||||
|
|
||||||
|
account_id_type fee_payer()const { return bettor_id; }
|
||||||
|
void validate()const { FC_ASSERT(false, "virtual operation"); }
|
||||||
|
/// This is a virtual operation; there is no fee
|
||||||
|
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
||||||
|
};
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -252,6 +283,9 @@ FC_REFLECT( graphene::chain::betting_market_resolve_operation::fee_parameters_ty
|
||||||
FC_REFLECT( graphene::chain::betting_market_resolve_operation,
|
FC_REFLECT( graphene::chain::betting_market_resolve_operation,
|
||||||
(fee)(betting_market_id)(resolution)(extensions) )
|
(fee)(betting_market_id)(resolution)(extensions) )
|
||||||
|
|
||||||
|
FC_REFLECT( graphene::chain::betting_market_resolved_operation::fee_parameters_type, )
|
||||||
|
FC_REFLECT( graphene::chain::betting_market_resolved_operation,
|
||||||
|
(bettor_id)(betting_market_id)(resolution)(winnings)(fees_paid)(fee) )
|
||||||
|
|
||||||
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) )
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ namespace graphene { namespace chain {
|
||||||
betting_market_create_operation,
|
betting_market_create_operation,
|
||||||
bet_place_operation,
|
bet_place_operation,
|
||||||
betting_market_resolve_operation,
|
betting_market_resolve_operation,
|
||||||
|
betting_market_resolved_operation, // VIRTUAL
|
||||||
bet_matched_operation, // VIRTUAL
|
bet_matched_operation, // VIRTUAL
|
||||||
bet_cancel_operation,
|
bet_cancel_operation,
|
||||||
bet_canceled_operation // VIRTUAL
|
bet_canceled_operation // VIRTUAL
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue