added event_update_operation
This commit is contained in:
parent
7b8fad0bfa
commit
2acd4dd187
13 changed files with 156 additions and 0 deletions
|
|
@ -214,6 +214,7 @@ struct get_impacted_account_visitor
|
|||
void operator()( const event_group_create_operation& op ) {}
|
||||
void operator()( const event_group_update_operation& op ) {}
|
||||
void operator()( const event_create_operation& op ) {}
|
||||
void operator()( const event_update_operation& op ) {}
|
||||
void operator()( const betting_market_rules_create_operation& op ) {}
|
||||
void operator()( const betting_market_group_create_operation& op ) {}
|
||||
void operator()( const betting_market_create_operation& op ) {}
|
||||
|
|
|
|||
|
|
@ -219,6 +219,7 @@ void database::initialize_evaluators()
|
|||
register_evaluator<event_group_create_evaluator>();
|
||||
register_evaluator<event_group_update_evaluator>();
|
||||
register_evaluator<event_create_evaluator>();
|
||||
register_evaluator<event_update_evaluator>();
|
||||
register_evaluator<betting_market_rules_create_evaluator>();
|
||||
register_evaluator<betting_market_group_create_evaluator>();
|
||||
register_evaluator<betting_market_create_evaluator>();
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ struct get_impacted_account_visitor
|
|||
void operator()(const event_group_create_operation&){}
|
||||
void operator()(const event_group_update_operation& op ) {}
|
||||
void operator()(const event_create_operation&){}
|
||||
void operator()(const event_update_operation& op ) {}
|
||||
void operator()(const betting_market_rules_create_operation&){}
|
||||
void operator()(const betting_market_group_create_operation&){}
|
||||
void operator()(const betting_market_create_operation&){}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,30 @@ object_id_type event_create_evaluator::do_apply(const event_create_operation& op
|
|||
return new_event.id;
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
void_result event_update_evaluator::do_evaluate(const event_update_operation& op)
|
||||
{ try {
|
||||
FC_ASSERT(trx_state->_is_proposed_trx);
|
||||
FC_ASSERT(op.new_name.valid() || op.new_season.valid() || op.new_start_time.valid());
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
void_result event_update_evaluator::do_apply(const event_update_operation& op)
|
||||
{ try {
|
||||
database& _db = db();
|
||||
_db.modify(
|
||||
_db.get(op.event_id),
|
||||
[&]( event_object& eo )
|
||||
{
|
||||
if( op.new_name.valid() )
|
||||
eo.name = *op.new_name;
|
||||
if( op.new_season.valid() )
|
||||
eo.season = *op.new_season;
|
||||
if( op.new_start_time.valid() )
|
||||
eo.start_time = *op.new_start_time;
|
||||
});
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
void_result event_update_status_evaluator::do_evaluate(const event_update_status_operation& op)
|
||||
{ try {
|
||||
FC_ASSERT(trx_state->_is_proposed_trx);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,17 @@ namespace graphene { namespace chain {
|
|||
event_group_id_type event_group_id;
|
||||
};
|
||||
|
||||
class event_update_evaluator : public evaluator<event_update_evaluator>
|
||||
{
|
||||
public:
|
||||
typedef event_update_operation operation_type;
|
||||
|
||||
void_result do_evaluate( const event_update_operation& o );
|
||||
void_result do_apply( const event_update_operation& o );
|
||||
private:
|
||||
event_group_id_type event_group_id;
|
||||
};
|
||||
|
||||
class event_update_status_evaluator : public evaluator<event_update_status_evaluator>
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -54,6 +54,25 @@ struct event_create_operation : public base_operation
|
|||
void validate()const;
|
||||
};
|
||||
|
||||
struct event_update_operation : public base_operation
|
||||
{
|
||||
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
|
||||
asset fee;
|
||||
|
||||
event_id_type event_id;
|
||||
|
||||
optional<internationalized_string_type> new_name;
|
||||
|
||||
optional<internationalized_string_type> new_season;
|
||||
|
||||
optional<time_point_sec> new_start_time;
|
||||
|
||||
extensions_type extensions;
|
||||
|
||||
account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; }
|
||||
void validate()const;
|
||||
};
|
||||
|
||||
/**
|
||||
* The status of an event; this is only used for display, the blockchain does
|
||||
* not care about the event's status
|
||||
|
|
@ -106,6 +125,11 @@ struct event_update_status_operation : public base_operation
|
|||
FC_REFLECT( graphene::chain::event_create_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT( graphene::chain::event_create_operation,
|
||||
(fee)(name)(season)(start_time)(event_group_id)(extensions) )
|
||||
|
||||
FC_REFLECT( graphene::chain::event_update_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT( graphene::chain::event_update_operation,
|
||||
(fee)(event_id)(new_name)(new_season)(new_start_time)(extensions) )
|
||||
|
||||
FC_REFLECT_ENUM( graphene::chain::event_status, (upcoming)(in_progress)(frozen)(completed)(canceled)(STATUS_COUNT) )
|
||||
FC_REFLECT( graphene::chain::event_update_status_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT( graphene::chain::event_update_status_operation,
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ namespace graphene { namespace chain {
|
|||
event_group_create_operation,
|
||||
event_group_update_operation,
|
||||
event_create_operation,
|
||||
event_update_operation,
|
||||
betting_market_rules_create_operation,
|
||||
betting_market_group_create_operation,
|
||||
betting_market_create_operation,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ void event_create_operation::validate() const
|
|||
FC_ASSERT( fee.amount >= 0 );
|
||||
}
|
||||
|
||||
void event_update_operation::validate() const
|
||||
{
|
||||
FC_ASSERT( fee.amount >= 0 );
|
||||
}
|
||||
|
||||
} } // graphene::chain
|
||||
|
||||
|
|
|
|||
|
|
@ -1606,10 +1606,21 @@ class wallet_api
|
|||
signed_transaction propose_create_event(
|
||||
const string& proposing_account,
|
||||
fc::time_point_sec expiration_time,
|
||||
internationalized_string_type name,
|
||||
internationalized_string_type season,
|
||||
fc::optional<time_point_sec> start_time,
|
||||
event_group_id_type event_group_id,
|
||||
bool broadcast = false);
|
||||
|
||||
signed_transaction propose_update_event(
|
||||
const string& proposing_account,
|
||||
event_id_type event_id,
|
||||
fc::time_point_sec expiration_time,
|
||||
fc::optional<internationalized_string_type> name,
|
||||
fc::optional<internationalized_string_type> season,
|
||||
fc::optional<time_point_sec> start_time,
|
||||
bool broadcast = false);
|
||||
|
||||
signed_transaction propose_create_betting_market_group(
|
||||
const string& proposing_account,
|
||||
fc::time_point_sec expiration_time,
|
||||
|
|
|
|||
|
|
@ -5137,7 +5137,9 @@ signed_transaction wallet_api::propose_update_event_group(
|
|||
signed_transaction wallet_api::propose_create_event(
|
||||
const string& proposing_account,
|
||||
fc::time_point_sec expiration_time,
|
||||
internationalized_string_type name,
|
||||
internationalized_string_type season,
|
||||
fc::optional<time_point_sec> start_time,
|
||||
event_group_id_type event_group_id,
|
||||
bool broadcast /*= false*/)
|
||||
{
|
||||
|
|
@ -5145,6 +5147,8 @@ signed_transaction wallet_api::propose_create_event(
|
|||
const chain_parameters& current_params = get_global_properties().parameters;
|
||||
|
||||
event_create_operation event_create_op;
|
||||
event_create_op.start_time = start_time;
|
||||
event_create_op.name = name;
|
||||
event_create_op.season = season;
|
||||
event_create_op.event_group_id = event_group_id;
|
||||
|
||||
|
|
@ -5163,6 +5167,40 @@ signed_transaction wallet_api::propose_create_event(
|
|||
return my->sign_transaction(tx, broadcast);
|
||||
}
|
||||
|
||||
signed_transaction wallet_api::propose_update_event(
|
||||
const string& proposing_account,
|
||||
event_id_type event_id,
|
||||
fc::time_point_sec expiration_time,
|
||||
fc::optional<internationalized_string_type> name,
|
||||
fc::optional<internationalized_string_type> season,
|
||||
fc::optional<time_point_sec> start_time,
|
||||
bool broadcast /*= false*/)
|
||||
{
|
||||
FC_ASSERT( !is_locked() );
|
||||
const chain_parameters& current_params = get_global_properties().parameters;
|
||||
|
||||
event_update_operation event_update_op;
|
||||
event_update_op.event_id = event_id;
|
||||
event_update_op.new_start_time = start_time;
|
||||
event_update_op.new_name = name;
|
||||
event_update_op.new_season = season;
|
||||
|
||||
proposal_create_operation prop_op;
|
||||
prop_op.expiration_time = expiration_time;
|
||||
prop_op.review_period_seconds = current_params.committee_proposal_review_period;
|
||||
prop_op.fee_paying_account = get_account(proposing_account).id;
|
||||
prop_op.proposed_ops.emplace_back( event_update_op );
|
||||
current_params.current_fees->set_fee( prop_op.proposed_ops.back().op );
|
||||
|
||||
signed_transaction tx;
|
||||
tx.operations.push_back(prop_op);
|
||||
my->set_operation_fees(tx, current_params.current_fees);
|
||||
tx.validate();
|
||||
|
||||
return my->sign_transaction(tx, broadcast);
|
||||
}
|
||||
|
||||
|
||||
signed_transaction wallet_api::propose_create_betting_market_group(
|
||||
const string& proposing_account,
|
||||
fc::time_point_sec expiration_time,
|
||||
|
|
|
|||
|
|
@ -212,6 +212,36 @@ BOOST_AUTO_TEST_CASE(peerplays_event_group_update_test)
|
|||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(peerplays_event_update_test)
|
||||
{
|
||||
try
|
||||
{
|
||||
ACTORS( (alice) );
|
||||
CREATE_ICE_HOCKEY_BETTING_MARKET();
|
||||
|
||||
internationalized_string_type n = {{"en", "Washington Capitals vs. Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホーク"}};
|
||||
internationalized_string_type s = {{"en", "2017-18"}};
|
||||
|
||||
fc::optional<internationalized_string_type> empty;
|
||||
fc::optional<internationalized_string_type> name = n;
|
||||
fc::optional<internationalized_string_type> season = s;
|
||||
|
||||
update_event(capitals_vs_blackhawks.id, name, empty);
|
||||
update_event(capitals_vs_blackhawks.id, empty, season);
|
||||
update_event(capitals_vs_blackhawks.id, name, season);
|
||||
|
||||
transfer(account_id_type(), alice_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);
|
||||
|
||||
//GRAPHENE_REQUIRE_THROW(update_event(capitals_vs_blackhawks.id, empty, empty), fc::exception);
|
||||
|
||||
} FC_LOG_AND_RETHROW()
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( cancel_unmatched_in_betting_group_test )
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1246,6 +1246,15 @@ const event_object& database_fixture::create_event(internationalized_string_type
|
|||
return *event_index.rbegin();
|
||||
} FC_CAPTURE_AND_RETHROW( (event_group_id) ) }
|
||||
|
||||
void database_fixture::update_event(event_id_type event_id, fc::optional<internationalized_string_type> name, fc::optional<internationalized_string_type> season)
|
||||
{ try {
|
||||
event_update_operation event_update_op;
|
||||
event_update_op.event_id = event_id;
|
||||
event_update_op.new_name = name;
|
||||
event_update_op.new_season = season;
|
||||
process_operation_by_witnesses(event_update_op);
|
||||
} FC_CAPTURE_AND_RETHROW( (name)(season) ) }
|
||||
|
||||
const betting_market_rules_object& database_fixture::create_betting_market_rules(internationalized_string_type name, internationalized_string_type description)
|
||||
{ try {
|
||||
betting_market_rules_create_operation betting_market_rules_create_op;
|
||||
|
|
|
|||
|
|
@ -290,6 +290,7 @@ struct database_fixture {
|
|||
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);
|
||||
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);
|
||||
const betting_market_group_object& create_betting_market_group(internationalized_string_type description, event_id_type event_id, betting_market_rules_id_type rules_id, asset_id_type asset_id);
|
||||
const betting_market_object& create_betting_market(betting_market_group_id_type group_id, internationalized_string_type payout_condition);
|
||||
|
|
|
|||
Loading…
Reference in a new issue