added betting_market_rules_update_operation

This commit is contained in:
Roman Olearski 2017-07-20 14:28:12 +02:00
parent c13ba46b2b
commit 78100f9fb5
11 changed files with 104 additions and 0 deletions

View file

@ -216,6 +216,7 @@ struct get_impacted_account_visitor
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_rules_update_operation& op ) {}
void operator()( const betting_market_group_create_operation& op ) {}
void operator()( const betting_market_create_operation& op ) {}
void operator()( const betting_market_group_resolve_operation& op ) {}

View file

@ -49,6 +49,28 @@ object_id_type betting_market_rules_create_evaluator::do_apply(const betting_mar
return new_betting_market_rules.id;
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result betting_market_rules_update_evaluator::do_evaluate(const betting_market_rules_update_operation& op)
{ try {
FC_ASSERT(trx_state->_is_proposed_trx);
FC_ASSERT(op.new_name.valid() || op.new_description.valid());
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result betting_market_rules_update_evaluator::do_apply(const betting_market_rules_update_operation& op)
{ try {
database& _db = db();
_db.modify(
_db.get(op.betting_market_rules_id),
[&]( betting_market_rules_object& bmro )
{
if( op.new_name.valid() )
bmro.name = *op.new_name;
if( op.new_description.valid() )
bmro.description = *op.new_description;
});
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result betting_market_group_create_evaluator::do_evaluate(const betting_market_group_create_operation& op)
{ try {
FC_ASSERT(trx_state->_is_proposed_trx);

View file

@ -221,6 +221,7 @@ void database::initialize_evaluators()
register_evaluator<event_create_evaluator>();
register_evaluator<event_update_evaluator>();
register_evaluator<betting_market_rules_create_evaluator>();
register_evaluator<betting_market_rules_update_evaluator>();
register_evaluator<betting_market_group_create_evaluator>();
register_evaluator<betting_market_create_evaluator>();
register_evaluator<bet_place_evaluator>();

View file

@ -198,6 +198,7 @@ struct get_impacted_account_visitor
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_rules_update_operation& op ) {}
void operator()(const betting_market_group_create_operation&){}
void operator()(const betting_market_create_operation&){}
void operator()(const bet_place_operation&){}

View file

@ -38,6 +38,15 @@ namespace graphene { namespace chain {
object_id_type do_apply( const betting_market_rules_create_operation& o );
};
class betting_market_rules_update_evaluator : public evaluator<betting_market_rules_update_evaluator>
{
public:
typedef betting_market_rules_update_operation operation_type;
void_result do_evaluate( const betting_market_rules_update_operation& o );
void_result do_apply( const betting_market_rules_update_operation& o );
};
class betting_market_group_create_evaluator : public evaluator<betting_market_group_create_evaluator>
{
public:

View file

@ -51,6 +51,24 @@ struct betting_market_rules_create_operation : public base_operation
void validate()const;
};
struct betting_market_rules_update_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
asset fee;
betting_market_rules_id_type betting_market_rules_id;
fc::optional<internationalized_string_type> new_name;
fc::optional<internationalized_string_type> new_description;
extensions_type extensions;
account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; }
void validate()const;
};
struct betting_market_group_create_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; };
@ -311,6 +329,10 @@ FC_REFLECT( graphene::chain::betting_market_rules_create_operation::fee_paramete
FC_REFLECT( graphene::chain::betting_market_rules_create_operation,
(fee)(name)(description)(extensions) )
FC_REFLECT( graphene::chain::betting_market_rules_update_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::betting_market_rules_update_operation,
(fee)(new_name)(new_description)(extensions)(betting_market_rules_id) )
FC_REFLECT( graphene::chain::betting_market_group_create_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::betting_market_group_create_operation,
(fee)(description)(event_id)(rules_id)(asset_id)(extensions) )

View file

@ -106,6 +106,7 @@ namespace graphene { namespace chain {
event_create_operation,
event_update_operation,
betting_market_rules_create_operation,
betting_market_rules_update_operation,
betting_market_group_create_operation,
betting_market_create_operation,
bet_place_operation,

View file

@ -30,6 +30,11 @@ void betting_market_rules_create_operation::validate() const
FC_ASSERT( fee.amount >= 0 );
}
void betting_market_rules_update_operation::validate() const
{
FC_ASSERT( fee.amount >= 0 );
}
void betting_market_group_create_operation::validate() const
{
FC_ASSERT( fee.amount >= 0 );

View file

@ -241,6 +241,34 @@ BOOST_AUTO_TEST_CASE(peerplays_event_update_test)
} FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE(peerplays_betting_market_rules_update_test)
{
try
{
ACTORS( (alice) );
CREATE_ICE_HOCKEY_BETTING_MARKET();
internationalized_string_type n = {{"en", "NHL Rules v1.1"}};
internationalized_string_type d = {{"en", "The winner will be the team with the most points at the end of the game. The team with fewer points will not be the winner."}};
fc::optional<internationalized_string_type> empty;
fc::optional<internationalized_string_type> name = n;
fc::optional<internationalized_string_type> desc = d;
update_betting_market_rules(betting_market_rules.id, name, empty);
update_betting_market_rules(betting_market_rules.id, empty, desc);
update_betting_market_rules(betting_market_rules.id, name, desc);
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_betting_market_rules(betting_market_rules.id, empty, empty), fc::exception);
} FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE( cancel_unmatched_in_betting_group_test )
{

View file

@ -1265,6 +1265,17 @@ const betting_market_rules_object& database_fixture::create_betting_market_rules
return *betting_market_rules_index.rbegin();
} FC_CAPTURE_AND_RETHROW( (name) ) }
void database_fixture::update_betting_market_rules(betting_market_rules_id_type rules_id,
fc::optional<internationalized_string_type> name,
fc::optional<internationalized_string_type> description)
{ try {
betting_market_rules_update_operation betting_market_rules_update_op;
betting_market_rules_update_op.betting_market_rules_id = rules_id;
betting_market_rules_update_op.new_name = name;
betting_market_rules_update_op.new_description = description;
process_operation_by_witnesses(betting_market_rules_update_op);
} FC_CAPTURE_AND_RETHROW( (name)(description) ) }
const betting_market_group_object& database_fixture::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)
{ try {
betting_market_group_create_operation betting_market_group_create_op;

View file

@ -292,6 +292,9 @@ struct database_fixture {
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);
void update_betting_market_rules(betting_market_rules_id_type rules_id,
fc::optional<internationalized_string_type> name,
fc::optional<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);