enhancing tournament_payout operation according issues 8 9
This commit is contained in:
parent
2320be1f55
commit
a66af8b072
4 changed files with 56 additions and 17 deletions
|
|
@ -224,7 +224,7 @@ struct get_impacted_account_visitor
|
|||
}
|
||||
void operator()( const tournament_payout_operation& op )
|
||||
{
|
||||
_impacted.insert( op.winner_account_id );
|
||||
_impacted.insert( op.payout_account_id );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,13 @@
|
|||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
enum class payout_type
|
||||
{
|
||||
prize_award,
|
||||
buyin_refund,
|
||||
rake_fee
|
||||
};
|
||||
|
||||
typedef fc::static_variant<rock_paper_scissors_game_options> game_specific_options;
|
||||
|
||||
/**
|
||||
|
|
@ -169,24 +176,32 @@ namespace graphene { namespace chain {
|
|||
|
||||
asset fee;
|
||||
|
||||
/// The account of the the tournament winner
|
||||
account_id_type winner_account_id;
|
||||
/// The account received payout
|
||||
account_id_type payout_account_id;
|
||||
|
||||
/// The won tournament
|
||||
/// The tournament generated payout
|
||||
tournament_id_type tournament_id;
|
||||
|
||||
/// The buy-in paid by the `payer_account_id`
|
||||
asset won_prize;
|
||||
/// The payout amount
|
||||
asset payout_amount;
|
||||
|
||||
payout_type type;
|
||||
|
||||
extensions_type extensions;
|
||||
|
||||
account_id_type fee_payer()const { return winner_account_id; }
|
||||
account_id_type fee_payer()const { return payout_account_id; }
|
||||
share_type calculate_fee(const fee_parameters_type&)const { return 0; }
|
||||
void validate()const {}
|
||||
};
|
||||
|
||||
} }
|
||||
|
||||
FC_REFLECT_ENUM(graphene::chain::payout_type,
|
||||
(prize_award)
|
||||
(buyin_refund)
|
||||
(rake_fee)
|
||||
)
|
||||
|
||||
FC_REFLECT_TYPENAME( graphene::chain::game_specific_options )
|
||||
FC_REFLECT_TYPENAME( graphene::chain::game_specific_moves )
|
||||
FC_REFLECT( graphene::chain::tournament_options,
|
||||
|
|
@ -220,9 +235,10 @@ FC_REFLECT( graphene::chain::game_move_operation,
|
|||
(extensions))
|
||||
FC_REFLECT( graphene::chain::tournament_payout_operation,
|
||||
(fee)
|
||||
(winner_account_id)
|
||||
(payout_account_id)
|
||||
(tournament_id)
|
||||
(won_prize)
|
||||
(payout_amount)
|
||||
(type)
|
||||
(extensions))
|
||||
|
||||
FC_REFLECT( graphene::chain::tournament_create_operation::fee_parameters_type, (fee) )
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ namespace graphene { namespace chain {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
void on_entry(const match_completed& event, tournament_state_machine_& fsm)
|
||||
{
|
||||
|
|
@ -266,7 +267,16 @@ namespace graphene { namespace chain {
|
|||
// for a period of time, not as a transfer back to the user; it doesn't matter
|
||||
// if they are currently authorized to transfer this asset, they never really
|
||||
// transferred it in the first place
|
||||
event.db.adjust_balance(payer_pair.first, asset(payer_pair.second, fsm.tournament_obj->options.buy_in.asset_id));
|
||||
asset amount(payer_pair.second, fsm.tournament_obj->options.buy_in.asset_id);
|
||||
event.db.adjust_balance(payer_pair.first, amount);
|
||||
|
||||
// Generating a virtual operation that shows the payment
|
||||
tournament_payout_operation op;
|
||||
op.tournament_id = fsm.tournament_obj->id;
|
||||
op.payout_amount = amount;
|
||||
op.payout_account_id = payer_pair.first;
|
||||
op.type = payout_type::buyin_refund;
|
||||
event.db.push_applied_operation(op);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -294,17 +304,25 @@ namespace graphene { namespace chain {
|
|||
const account_id_type& winner = *event.match.match_winners.begin();
|
||||
uint16_t rake_fee_percentage = event.db.get_global_properties().parameters.rake_fee_percentage;
|
||||
share_type rake_amount = (fc::uint128_t(tournament_obj.prize_pool.value) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100).to_uint64();
|
||||
event.db.adjust_balance(account_id_type(TOURNAMENT_RAKE_FEE_ACCOUNT_ID),
|
||||
asset(rake_amount, tournament_obj.options.buy_in.asset_id));
|
||||
|
||||
asset rake(rake_amount, tournament_obj.options.buy_in.asset_id);
|
||||
event.db.adjust_balance(account_id_type(TOURNAMENT_RAKE_FEE_ACCOUNT_ID), rake);
|
||||
|
||||
asset won_prize(tournament_obj.prize_pool - rake_amount, tournament_obj.options.buy_in.asset_id);
|
||||
event.db.adjust_balance(winner, won_prize);
|
||||
tournament_obj.end_time = event.db.head_block_time();
|
||||
|
||||
// Generating a virtual operation that shows the payment
|
||||
// Generating a virtual operations that show the payments
|
||||
tournament_payout_operation op;
|
||||
op.tournament_id = tournament_obj.id;
|
||||
op.won_prize = won_prize;
|
||||
op.winner_account_id = winner;
|
||||
op.payout_amount = won_prize;
|
||||
op.payout_account_id = winner;
|
||||
op.type = payout_type::prize_award;
|
||||
event.db.push_applied_operation(op);
|
||||
|
||||
op.payout_amount = rake;
|
||||
op.payout_account_id = TOURNAMENT_RAKE_FEE_ACCOUNT_ID;
|
||||
op.type = payout_type::rake_fee;
|
||||
event.db.push_applied_operation(op);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3208,8 +3208,13 @@ std::string operation_printer::operator()(const asset_dividend_distribution_oper
|
|||
|
||||
std::string operation_printer::operator()(const tournament_payout_operation& op)const
|
||||
{
|
||||
out << "Tournament Payout Account '" << wallet.get_account(op.winner_account_id).name
|
||||
<< "', Amount " << std::to_string(op.won_prize.amount.value) << " " << wallet.get_asset(op.won_prize.asset_id).symbol;
|
||||
asset_object payout_asset = wallet.get_asset(op.payout_amount.asset_id);
|
||||
|
||||
out << "Tournament #" << std::string(object_id_type(op.tournament_id)) << " Payout : "
|
||||
<< "Account '" << wallet.get_account(op.payout_account_id).name
|
||||
<< "', Amount " << payout_asset.amount_to_pretty_string(op.payout_amount) << ", Type "
|
||||
<< (op.type == payout_type::buyin_refund ? "buyin refund" : (op.type == payout_type::rake_fee ? "rake fee" : "prize award"))
|
||||
<< ".";
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue