From 4f501f6aaf2521f3f0c4460fa05c26525707e408 Mon Sep 17 00:00:00 2001 From: Apr Team Date: Fri, 11 May 2018 19:07:57 +0300 Subject: [PATCH] Added sport_delete operation, evaluator and API. Fixed various compilation issues. Added tests file. --- libraries/app/impacted.cpp | 1 + libraries/chain/db_init.cpp | 1 + libraries/chain/db_notify.cpp | 1 + .../graphene/chain/protocol/operations.hpp | 1 + .../include/graphene/chain/protocol/sport.hpp | 17 ++++++ .../graphene/chain/sport_evaluator.hpp | 9 ++++ libraries/chain/protocol/sport.cpp | 4 ++ libraries/chain/sport_evaluator.cpp | 6 +++ .../wallet/include/graphene/wallet/wallet.hpp | 6 +++ libraries/wallet/wallet.cpp | 27 ++++++++++ tests/tests/sports_and_events_tests.cpp | 54 +++++++++++++++++++ 11 files changed, 127 insertions(+) create mode 100644 tests/tests/sports_and_events_tests.cpp diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index c765de39..6da8a7c7 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -211,6 +211,7 @@ struct get_impacted_account_visitor void operator()( const sport_create_operation& op ) {} void operator()( const sport_update_operation& op ) {} + void operator()( const sport_delete_operation& op ) {} void operator()( const event_group_create_operation& op ) {} void operator()( const event_group_update_operation& op ) {} void operator()( const event_create_operation& op ) {} diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 4afea10f..613ee720 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -216,6 +216,7 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); + register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index c90bea08..93338089 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -193,6 +193,7 @@ struct get_impacted_account_visitor } void operator()(const sport_create_operation&){} void operator()(const sport_update_operation&){} + void operator()(const sport_delete_operation&){} void operator()(const event_group_create_operation&){} void operator()(const event_group_update_operation& op ) {} void operator()(const event_create_operation&){} diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index 58cc2cba..7b4429e4 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -106,6 +106,7 @@ namespace graphene { namespace chain { tournament_leave_operation, sport_create_operation, sport_update_operation, + sport_delete_operation, event_group_create_operation, event_group_update_operation, event_create_operation, diff --git a/libraries/chain/include/graphene/chain/protocol/sport.hpp b/libraries/chain/include/graphene/chain/protocol/sport.hpp index 2824044a..6a3ab3d6 100644 --- a/libraries/chain/include/graphene/chain/protocol/sport.hpp +++ b/libraries/chain/include/graphene/chain/protocol/sport.hpp @@ -58,6 +58,19 @@ struct sport_update_operation : public base_operation account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } void validate()const; }; + +struct sport_delete_operation : public base_operation +{ + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; + asset fee; + + sport_id_type sport_id; + + extensions_type extensions; + + account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + void validate()const; +}; } } @@ -68,3 +81,7 @@ FC_REFLECT( graphene::chain::sport_create_operation, FC_REFLECT( graphene::chain::sport_update_operation::fee_parameters_type, (fee) ) FC_REFLECT( graphene::chain::sport_update_operation, (fee)(sport_id)(new_name)(extensions) ) + +FC_REFLECT( graphene::chain::sport_delete_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::sport_delete_operation, + (fee)(sport_id)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/sport_evaluator.hpp b/libraries/chain/include/graphene/chain/sport_evaluator.hpp index a35dc4e7..d1371751 100644 --- a/libraries/chain/include/graphene/chain/sport_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/sport_evaluator.hpp @@ -47,4 +47,13 @@ namespace graphene { namespace chain { void_result do_apply( const sport_update_operation& o ); }; + class sport_delete_evaluator : public evaluator + { + public: + typedef sport_delete_operation operation_type; + + void_result do_evaluate( const sport_delete_operation& o ); + void_result do_apply( const sport_delete_operation& o ); + }; + } } // graphene::chain diff --git a/libraries/chain/protocol/sport.cpp b/libraries/chain/protocol/sport.cpp index 1ee07fa3..bc638f3d 100644 --- a/libraries/chain/protocol/sport.cpp +++ b/libraries/chain/protocol/sport.cpp @@ -35,6 +35,10 @@ void sport_update_operation::validate() const FC_ASSERT( fee.amount >= 0 ); } +void sport_delete_operation::validate() const +{ + FC_ASSERT( fee.amount >= 0 ); +} } } // graphene::chain diff --git a/libraries/chain/sport_evaluator.cpp b/libraries/chain/sport_evaluator.cpp index afc19da2..af7373aa 100644 --- a/libraries/chain/sport_evaluator.cpp +++ b/libraries/chain/sport_evaluator.cpp @@ -70,5 +70,11 @@ void_result sport_update_evaluator::do_evaluate(const sport_update_operation& op return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } + +void_result sport_delete_evaluator::do_evaluate( const sport_delete_operation& o ) +{} + +void_result sport_delete_evaluator::do_apply( const sport_delete_operation& o ) +{} } } // graphene::chain diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 909127b3..80df691f 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1605,6 +1605,12 @@ class wallet_api sport_id_type sport_id, fc::optional name, bool broadcast = false); + + signed_transaction propose_delete_sport( + const string& proposing_account, + fc::time_point_sec expiration_time, + sport_id_type sport_id, + bool broadcast = false); signed_transaction propose_create_event_group( const string& proposing_account, diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 1497a996..d075126d 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -5138,6 +5138,33 @@ signed_transaction wallet_api::propose_update_sport( return my->sign_transaction(tx, broadcast); } +signed_transaction wallet_api::propose_delete_sport( + const string& proposing_account, + fc::time_point_sec expiration_time, + sport_id_type sport_id, + bool broadcast /*= false*/) +{ + FC_ASSERT( !is_locked() ); + const chain_parameters& current_params = get_global_properties().parameters; + + sport_delete_operation sport_delete_op; + sport_delete_op.sport_id = sport_id; + + 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( sport_delete_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_event_group( const string& proposing_account, fc::time_point_sec expiration_time, diff --git a/tests/tests/sports_and_events_tests.cpp b/tests/tests/sports_and_events_tests.cpp new file mode 100644 index 00000000..8f26dd5a --- /dev/null +++ b/tests/tests/sports_and_events_tests.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Cryptonomex, Inc., and contributors. + * + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "../common/database_fixture.hpp" + +using namespace graphene::chain; +using namespace graphene::chain::test; + +BOOST_FIXTURE_TEST_SUITE( sports_and_events_tests, database_fixture ) + +BOOST_AUTO_TEST_CASE( propose_delete_sport ) +{ + +} + +BOOST_AUTO_TEST_SUITE_END()