extended event_group_update_operation

This commit is contained in:
Roman Olearski 2017-07-20 21:01:10 +02:00
parent 78100f9fb5
commit cd40ef0715
7 changed files with 88 additions and 8 deletions

View file

@ -63,7 +63,19 @@ object_id_type event_group_create_evaluator::do_apply(const event_group_create_o
void_result event_group_update_evaluator::do_evaluate(const event_group_update_operation& op)
{ try {
FC_ASSERT(trx_state->_is_proposed_trx);
FC_ASSERT(op.new_name.valid());
FC_ASSERT(op.new_sport_id.valid() || op.new_name.valid());
if( op.new_sport_id.valid() )
{
object_id_type resolved_id = *op.new_sport_id;
if (is_relative(*op.new_sport_id))
resolved_id = get_relative_id(*op.new_sport_id);
FC_ASSERT(resolved_id.space() == sport_id_type::space_id &&
resolved_id.type() == sport_id_type::type_id, "sport_id must refer to a sport_id_type");
sport_id = resolved_id;
FC_ASSERT( db().find_object(sport_id), "Invalid sport specified" );
}
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
@ -76,6 +88,8 @@ void_result event_group_update_evaluator::do_apply(const event_group_update_oper
{
if( op.new_name.valid() )
ego.name = *op.new_name;
if( op.new_sport_id.valid() )
ego.sport_id = sport_id;
});
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -57,6 +57,12 @@ struct event_group_update_operation : public base_operation
event_group_id_type event_group_id;
/**
* This can be a sport_id_type, or a
* relative object id that resolves to a sport_id_type
*/
optional<object_id_type> new_sport_id;
optional<internationalized_string_type> new_name;
extensions_type extensions;
@ -74,4 +80,4 @@ FC_REFLECT( graphene::chain::event_group_create_operation,
FC_REFLECT( graphene::chain::event_group_update_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::event_group_update_operation,
(fee)(new_name)(event_group_id)(extensions) )
(fee)(new_sport_id)(new_name)(event_group_id)(extensions) )

View file

@ -1600,6 +1600,7 @@ class wallet_api
const string& proposing_account,
fc::time_point_sec expiration_time,
event_group_id_type event_group,
fc::optional<object_id_type> sport_id,
fc::optional<internationalized_string_type> name,
bool broadcast = false);

View file

@ -5109,6 +5109,7 @@ signed_transaction wallet_api::propose_update_event_group(
const string& proposing_account,
fc::time_point_sec expiration_time,
event_group_id_type event_group,
fc::optional<object_id_type> sport_id,
fc::optional<internationalized_string_type> name,
bool broadcast /*= false*/)
{
@ -5116,6 +5117,7 @@ signed_transaction wallet_api::propose_update_event_group(
const chain_parameters& current_params = get_global_properties().parameters;
event_group_update_operation event_group_update_op;
event_group_update_op.new_sport_id = sport_id;
event_group_update_op.new_name = name;
event_group_update_op.event_group_id = event_group;

View file

@ -200,16 +200,72 @@ BOOST_AUTO_TEST_CASE(peerplays_event_group_update_test)
{
try
{
ACTORS( (alice) );
ACTORS( (alice)(bob) );
CREATE_ICE_HOCKEY_BETTING_MARKET();
update_event_group(nhl.id, {{"en", "IBM"}, {"zh_Hans", "國家冰球聯"}, {"ja", "ナショナルホッケーリー"}}); \
transfer(account_id_type(), alice_id, asset(10000000));
transfer(account_id_type(), bob_id, asset(10000000));
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 */);
BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000 - 20000);
internationalized_string_type n = {{"en", "IBM"}, {"zh_Hans", "國家冰球聯"}, {"ja", "ナショナルホッケーリー"}};
const sport_object& ice_on_hockey = create_sport({{"en", "Hockey on Ice"}, {"zh_Hans", "冰球"}, {"ja", "アイスホッケー"}}); \
fc::optional<internationalized_string_type> name = n;
object_id_type object_id = ice_on_hockey.id;
fc::optional<object_id_type> sport_id = object_id;
update_event_group(nhl.id, fc::optional<object_id_type>(), name);
update_event_group(nhl.id, sport_id, fc::optional<internationalized_string_type>());
update_event_group(nhl.id, sport_id, name);
#if 0
// nothing to change
//GRAPHENE_REQUIRE_THROW(update_event_group(nhl.id, fc::optional<object_id_type>(), fc::optional<internationalized_string_type>()), fc::assert_exception);
try
{
update_event_group(nhl.id, fc::optional<object_id_type>(), fc::optional<internationalized_string_type>());
FC_ASSERT(false, "expected error hasn't occured");
}
catch (fc::exception& e)
{
edump((e.code()));
}
// no sport object
//object_id = capitals_win_market.id;
//sport_id = object_id;
//GRAPHENE_REQUIRE_THROW(update_event_group(nhl.id, sport_id, name), fc::assert_exception);
// sport object doesn't exist
#endif
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 */);
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
resolve_betting_market_group(moneyline_betting_markets.id,
{{capitals_win_market.id, betting_market_resolution_type::win},
{blackhawks_win_market.id, betting_market_resolution_type::cancel}});
uint16_t rake_fee_percentage = db.get_global_properties().parameters.betting_rake_fee_percentage;
uint32_t rake_value = (-1000000 + 2000000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100;
BOOST_TEST_MESSAGE("Rake value " + std::to_string(rake_value));
BOOST_CHECK_EQUAL(get_balance(alice_id, asset_id_type()), 10000000 - 1000000 - 20000 + 2000000 - rake_value);
BOOST_CHECK_EQUAL(get_balance(bob_id, asset_id_type()), 10000000 - 1000000 - 20000);
}
catch (fc::exception& e)
{
edump((e.to_detail_string()));
throw;
}
//} FC_LOG_AND_RETHROW()
} FC_LOG_AND_RETHROW()
}

View file

@ -1227,10 +1227,11 @@ const event_group_object& database_fixture::create_event_group(internationalized
} FC_CAPTURE_AND_RETHROW( (name) ) }
void database_fixture::update_event_group(event_group_id_type event_group_id, internationalized_string_type name)
void database_fixture::update_event_group(event_group_id_type event_group_id, fc::optional<object_id_type> sport_id, fc::optional<internationalized_string_type> name)
{ try {
event_group_update_operation event_group_update_op;
event_group_update_op.new_name = name;
event_group_update_op.new_sport_id = sport_id;
event_group_update_op.event_group_id = event_group_id;
process_operation_by_witnesses(event_group_update_op);
} FC_CAPTURE_AND_RETHROW( (name) ) }

View file

@ -288,7 +288,7 @@ struct database_fixture {
const sport_object& create_sport(internationalized_string_type name);
void update_sport(sport_id_type sport_id, internationalized_string_type name);
const event_group_object& create_event_group(internationalized_string_type name, sport_id_type sport_id);
void update_event_group(event_group_id_type event_group_id, internationalized_string_type name);
void update_event_group(event_group_id_type event_group_id, fc::optional<object_id_type> sport_id, fc::optional<internationalized_string_type> name);
const event_object& create_event(internationalized_string_type name, internationalized_string_type season, event_group_id_type event_group_id);
void update_event(event_id_type event_id, fc::optional<internationalized_string_type> name, fc::optional<internationalized_string_type> season);
const betting_market_rules_object& create_betting_market_rules(internationalized_string_type name, internationalized_string_type description);