From 065c9d1546cdb7860a5cf6e6cb4527ba7b98ff51 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Tue, 15 Feb 2022 16:44:02 +0300 Subject: [PATCH 01/17] #235 Fix game_object, match_object, tournament_object FC_REFLECT for writing to db --- .../chain/include/graphene/chain/game_object.hpp | 9 ++++++--- .../chain/include/graphene/chain/match_object.hpp | 12 ++++++++++-- .../include/graphene/chain/tournament_object.hpp | 14 +++++++++++--- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/libraries/chain/include/graphene/chain/game_object.hpp b/libraries/chain/include/graphene/chain/game_object.hpp index abef1444..863deff9 100644 --- a/libraries/chain/include/graphene/chain/game_object.hpp +++ b/libraries/chain/include/graphene/chain/game_object.hpp @@ -166,6 +166,9 @@ FC_REFLECT_ENUM(graphene::chain::game_state, (game_complete)) //FC_REFLECT_TYPENAME(graphene::chain::game_object) // manually serialized -FC_REFLECT(graphene::chain::game_object, (players)) - - +FC_REFLECT_DERIVED(graphene::chain::game_object, (graphene::db::object), + (match_id) + (players) + (winners) + (game_details) + (next_timeout)) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/match_object.hpp b/libraries/chain/include/graphene/chain/match_object.hpp index 72c346a7..381c5dca 100644 --- a/libraries/chain/include/graphene/chain/match_object.hpp +++ b/libraries/chain/include/graphene/chain/match_object.hpp @@ -163,5 +163,13 @@ FC_REFLECT_ENUM(graphene::chain::match_state, (match_complete)) //FC_REFLECT_TYPENAME(graphene::chain::match_object) // manually serialized -FC_REFLECT(graphene::chain::match_object, (players)) - +FC_REFLECT_DERIVED(graphene::chain::match_object, (graphene::db::object), + (tournament_id) + (players) + (games) + (game_winners) + (number_of_wins) + (number_of_ties) + (match_winners) + (start_time) + (end_time)) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/tournament_object.hpp b/libraries/chain/include/graphene/chain/tournament_object.hpp index 140770e2..1b673731 100644 --- a/libraries/chain/include/graphene/chain/tournament_object.hpp +++ b/libraries/chain/include/graphene/chain/tournament_object.hpp @@ -240,12 +240,20 @@ FC_REFLECT_DERIVED(graphene::chain::tournament_details_object, (graphene::db::ob (payers) (players_payers) (matches)) + //FC_REFLECT_TYPENAME(graphene::chain::tournament_object) // manually serialized -FC_REFLECT(graphene::chain::tournament_object, (creator)) +FC_REFLECT_DERIVED(graphene::chain::tournament_object, (graphene::db::object), + (creator) + (options) + (start_time) + (end_time) + (prize_pool) + (registered_players) + (tournament_details_id)) + FC_REFLECT_ENUM(graphene::chain::tournament_state, (accepting_registrations) (awaiting_start) (in_progress) (registration_period_expired) - (concluded)) - + (concluded)) \ No newline at end of file -- 2.45.2 From 4267e6323a3c1ca66c7e36059d061b3094117718 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 13:00:47 +0300 Subject: [PATCH 02/17] #235 tournament_object : delete custom variant and Stream operator functions --- .../graphene/chain/tournament_object.hpp | 86 +------------------ libraries/chain/small_objects.cpp | 2 + libraries/chain/tournament_object.cpp | 51 ----------- 3 files changed, 5 insertions(+), 134 deletions(-) diff --git a/libraries/chain/include/graphene/chain/tournament_object.hpp b/libraries/chain/include/graphene/chain/tournament_object.hpp index 1b673731..3dcc38ca 100644 --- a/libraries/chain/include/graphene/chain/tournament_object.hpp +++ b/libraries/chain/include/graphene/chain/tournament_object.hpp @@ -1,20 +1,8 @@ #pragma once #include -#include #include -#include +#include #include -#include -#include - -namespace graphene { namespace chain { - class tournament_object; -} } - -namespace fc { - void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth = 1); - void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth = 1); -} //end namespace fc namespace graphene { namespace chain { class database; @@ -99,21 +87,6 @@ namespace graphene { namespace chain { time_point_sec get_registration_deadline() const { return options.registration_deadline; } - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const tournament_object& tournament_obj ); - - template - friend Stream& operator>>( Stream& s, tournament_object& tournament_obj ); - - friend void ::fc::to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth); - - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); - /// called by database maintenance code when registration for this contest has expired void on_registration_deadline_passed(database& db); void on_player_registered(database& db, account_id_type payer_id, account_id_type player_id); @@ -154,59 +127,6 @@ namespace graphene { namespace chain { > tournament_details_object_multi_index_type; typedef generic_index tournament_details_index; - - template - inline Stream& operator<<( Stream& s, const tournament_object& tournament_obj ) - { - fc_elog(fc::logger::get("tournament"), "In tournament_obj to_raw"); - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, tournament_obj); - fc::raw::pack(s, tournament_obj.id); - fc::raw::pack(s, tournament_obj.creator); - fc::raw::pack(s, tournament_obj.options); - fc::raw::pack(s, tournament_obj.start_time); - fc::raw::pack(s, tournament_obj.end_time); - fc::raw::pack(s, tournament_obj.prize_pool); - fc::raw::pack(s, tournament_obj.registered_players); - fc::raw::pack(s, tournament_obj.tournament_details_id); - - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - tournament_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc_elog(fc::logger::get("tournament"), "Serialized state ${state} to bytes ${bytes}", - ("state", tournament_obj.get_state())("bytes", fc::to_hex(stringified_stream.c_str(), stringified_stream.size()))); - fc::raw::pack(s, stream.str()); - - return s; - } - template - inline Stream& operator>>( Stream& s, tournament_object& tournament_obj ) - { - fc_elog(fc::logger::get("tournament"), "In tournament_obj from_raw"); - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, tournament_obj); - fc::raw::unpack(s, tournament_obj.id); - fc::raw::unpack(s, tournament_obj.creator); - fc::raw::unpack(s, tournament_obj.options); - fc::raw::unpack(s, tournament_obj.start_time); - fc::raw::unpack(s, tournament_obj.end_time); - fc::raw::unpack(s, tournament_obj.prize_pool); - fc::raw::unpack(s, tournament_obj.registered_players); - fc::raw::unpack(s, tournament_obj.tournament_details_id); - - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - tournament_obj.unpack_impl(stream); - fc_elog(fc::logger::get("tournament"), "Deserialized state ${state} from bytes ${bytes}", - ("state", tournament_obj.get_state())("bytes", fc::to_hex(stringified_stream.c_str(), stringified_stream.size()))); - - return s; - } - /** * @brief This secondary index will allow a reverse lookup of all tournaments * a particular account has registered for. This will be attached @@ -230,8 +150,6 @@ namespace graphene { namespace chain { flat_set before_account_ids; }; - - } } FC_REFLECT_DERIVED(graphene::chain::tournament_details_object, (graphene::db::object), @@ -251,6 +169,8 @@ FC_REFLECT_DERIVED(graphene::chain::tournament_object, (graphene::db::object), (registered_players) (tournament_details_id)) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::tournament_object ) + FC_REFLECT_ENUM(graphene::chain::tournament_state, (accepting_registrations) (awaiting_start) diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 24166e4e..a08ff691 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include @@ -72,3 +73,4 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_object GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_scheduler ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedule_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index 056652e5..7babb1ba 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -28,8 +28,6 @@ #include #include -#include -#include #include namespace graphene { namespace chain { @@ -533,18 +531,6 @@ namespace graphene { namespace chain { return state; } - void tournament_object::pack_impl(std::ostream& stream) const - { - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; - } - - void tournament_object::unpack_impl(std::istream& stream) - { - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; - } - void tournament_object::on_registration_deadline_passed(database& db) { my->state_machine.process_event(registration_deadline_passed(db)); @@ -721,41 +707,4 @@ namespace graphene { namespace chain { } } } // graphene::chain -namespace fc { - // Manually reflect tournament_object to variant to properly reflect "state" - void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth) - { - fc_elog(fc::logger::get("tournament"), "In tournament_obj to_variant"); - elog("In tournament_obj to_variant"); - fc::mutable_variant_object o; - o("id", fc::variant(tournament_obj.id, max_depth)) - ("creator", fc::variant(tournament_obj.creator, max_depth)) - ("options", fc::variant(tournament_obj.options, max_depth)) - ("start_time", fc::variant(tournament_obj.start_time, max_depth)) - ("end_time", fc::variant(tournament_obj.end_time, max_depth)) - ("prize_pool", fc::variant(tournament_obj.prize_pool, max_depth)) - ("registered_players", fc::variant(tournament_obj.registered_players, max_depth)) - ("tournament_details_id", fc::variant(tournament_obj.tournament_details_id, max_depth)) - ("state", fc::variant(tournament_obj.get_state(), max_depth)); - - v = o; - } - - // Manually reflect tournament_object to variant to properly reflect "state" - void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth) - { - fc_elog(fc::logger::get("tournament"), "In tournament_obj from_variant"); - tournament_obj.id = v["id"].as( max_depth ); - tournament_obj.creator = v["creator"].as( max_depth ); - tournament_obj.options = v["options"].as( max_depth ); - tournament_obj.start_time = v["start_time"].as >( max_depth ); - tournament_obj.end_time = v["end_time"].as >( max_depth ); - tournament_obj.prize_pool = v["prize_pool"].as( max_depth ); - tournament_obj.registered_players = v["registered_players"].as( max_depth ); - tournament_obj.tournament_details_id = v["tournament_details_id"].as( max_depth ); - graphene::chain::tournament_state state = v["state"].as( max_depth ); - const_cast(tournament_obj.my->state_machine.current_state())[0] = (int)state; - } -} //end namespace fc - -- 2.45.2 From 7ae3138863480eba443870bc94da65bab85b36c4 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 13:02:05 +0300 Subject: [PATCH 03/17] #235 match_object : delete custom variant and Stream operator functions --- .../include/graphene/chain/match_object.hpp | 85 +------------------ .../include/graphene/chain/protocol/types.hpp | 1 + libraries/chain/match_object.cpp | 55 ------------ libraries/chain/small_objects.cpp | 2 + 4 files changed, 7 insertions(+), 136 deletions(-) diff --git a/libraries/chain/include/graphene/chain/match_object.hpp b/libraries/chain/include/graphene/chain/match_object.hpp index 381c5dca..2f5152cc 100644 --- a/libraries/chain/include/graphene/chain/match_object.hpp +++ b/libraries/chain/include/graphene/chain/match_object.hpp @@ -1,20 +1,6 @@ #pragma once -#include -#include -#include -#include +#include #include -#include -#include - -namespace graphene { namespace chain { - class match_object; -} } - -namespace fc { - void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth = 1); - void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth = 1); -} //end namespace fc namespace graphene { namespace chain { class database; @@ -75,20 +61,6 @@ namespace graphene { namespace chain { match_state get_state() const; - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const match_object& match_obj ); - - template - friend Stream& operator>>( Stream& s, match_object& match_obj ); - - friend void ::fc::to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth); - - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); void on_initiate_match(database& db); void on_game_complete(database& db, const game_object& game); game_id_type start_next_game(database& db, match_id_type match_id); @@ -104,57 +76,6 @@ namespace graphene { namespace chain { > match_object_multi_index_type; typedef generic_index match_index; - template - inline Stream& operator<<( Stream& s, const match_object& match_obj ) - { - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, match_obj); - fc::raw::pack(s, match_obj.id); - fc::raw::pack(s, match_obj.tournament_id); - fc::raw::pack(s, match_obj.players); - fc::raw::pack(s, match_obj.games); - fc::raw::pack(s, match_obj.game_winners); - fc::raw::pack(s, match_obj.number_of_wins); - fc::raw::pack(s, match_obj.number_of_ties); - fc::raw::pack(s, match_obj.match_winners); - fc::raw::pack(s, match_obj.start_time); - fc::raw::pack(s, match_obj.end_time); - - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - match_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc::raw::pack(s, stream.str()); - - return s; - } - - template - inline Stream& operator>>( Stream& s, match_object& match_obj ) - { - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, match_obj); - fc::raw::unpack(s, match_obj.id); - fc::raw::unpack(s, match_obj.tournament_id); - fc::raw::unpack(s, match_obj.players); - fc::raw::unpack(s, match_obj.games); - fc::raw::unpack(s, match_obj.game_winners); - fc::raw::unpack(s, match_obj.number_of_wins); - fc::raw::unpack(s, match_obj.number_of_ties); - fc::raw::unpack(s, match_obj.match_winners); - fc::raw::unpack(s, match_obj.start_time); - fc::raw::unpack(s, match_obj.end_time); - - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - match_obj.unpack_impl(stream); - - return s; - } - } } FC_REFLECT_ENUM(graphene::chain::match_state, @@ -172,4 +93,6 @@ FC_REFLECT_DERIVED(graphene::chain::match_object, (graphene::db::object), (number_of_ties) (match_winners) (start_time) - (end_time)) \ No newline at end of file + (end_time)) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::match_object ) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 321b08d9..701a4888 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -577,6 +577,7 @@ FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type ) FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type ) FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type ) FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::match_id_type ) FC_REFLECT_TYPENAME( graphene::chain::custom_permission_id_type ) FC_REFLECT_TYPENAME( graphene::chain::custom_account_authority_id_type ) FC_REFLECT_TYPENAME( graphene::chain::offer_history_id_type ) diff --git a/libraries/chain/match_object.cpp b/libraries/chain/match_object.cpp index e11f0e8a..c0b75755 100644 --- a/libraries/chain/match_object.cpp +++ b/libraries/chain/match_object.cpp @@ -28,8 +28,6 @@ #include #include -#include -#include #include #include @@ -327,18 +325,6 @@ namespace graphene { namespace chain { return state; } - void match_object::pack_impl(std::ostream& stream) const - { - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; - } - - void match_object::unpack_impl(std::istream& stream) - { - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; - } - void match_object::on_initiate_match(database& db) { my->state_machine.process_event(initiate_match(db)); @@ -362,45 +348,4 @@ namespace graphene { namespace chain { } } // graphene::chain -namespace fc { - // Manually reflect match_object to variant to properly reflect "state" - void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth) - { try { - fc_elog(fc::logger::get("tournament"), "In match_obj to_variant"); - elog("In match_obj to_variant"); - fc::mutable_variant_object o; - o("id", fc::variant(match_obj.id, max_depth)) - ("tournament_id", fc::variant(match_obj.tournament_id, max_depth)) - ("players", fc::variant(match_obj.players, max_depth)) - ("games", fc::variant(match_obj.games, max_depth)) - ("game_winners", fc::variant(match_obj.game_winners, max_depth)) - ("number_of_wins", fc::variant(match_obj.number_of_wins, max_depth)) - ("number_of_ties", fc::variant(match_obj.number_of_ties, max_depth)) - ("match_winners", fc::variant(match_obj.match_winners, max_depth)) - ("start_time", fc::variant(match_obj.start_time, max_depth)) - ("end_time", fc::variant(match_obj.end_time, max_depth)) - ("state", fc::variant(match_obj.get_state(), max_depth)); - - v = o; - } FC_RETHROW_EXCEPTIONS(warn, "") } - - // Manually reflect match_object to variant to properly reflect "state" - void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth) - { try { - fc_elog(fc::logger::get("tournament"), "In match_obj from_variant"); - match_obj.id = v["id"].as( max_depth ); - match_obj.tournament_id = v["tournament_id"].as( max_depth ); - match_obj.players = v["players"].as >( max_depth ); - match_obj.games = v["games"].as >( max_depth ); - match_obj.game_winners = v["game_winners"].as > >( max_depth ); - match_obj.number_of_wins = v["number_of_wins"].as >( max_depth ); - match_obj.number_of_ties = v["number_of_ties"].as( max_depth ); - match_obj.match_winners = v["match_winners"].as >( max_depth ); - match_obj.start_time = v["start_time"].as( max_depth ); - match_obj.end_time = v["end_time"].as >( max_depth ); - graphene::chain::match_state state = v["state"].as( max_depth ); - const_cast(match_obj.my->state_machine.current_state())[0] = (int)state; - } FC_RETHROW_EXCEPTIONS(warn, "") } -} //end namespace fc - diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index a08ff691..9c54fba3 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include @@ -74,3 +75,4 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedu GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedule_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object ) -- 2.45.2 From 1f6e6dc65a482f7cf7bdefd5f2436cd63955f169 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 13:02:52 +0300 Subject: [PATCH 04/17] #235 game_object : delete custom variant and Stream operator functions --- libraries/chain/game_object.cpp | 47 ----------- .../include/graphene/chain/game_object.hpp | 78 +------------------ .../include/graphene/chain/protocol/types.hpp | 1 + libraries/chain/small_objects.cpp | 2 + 4 files changed, 7 insertions(+), 121 deletions(-) diff --git a/libraries/chain/game_object.cpp b/libraries/chain/game_object.cpp index 5874fd9e..19f3613b 100644 --- a/libraries/chain/game_object.cpp +++ b/libraries/chain/game_object.cpp @@ -28,8 +28,6 @@ #include #include -#include -#include #include #include @@ -533,51 +531,6 @@ namespace graphene { namespace chain { my->state_machine.process_event(initiate_game(db, players)); } - void game_object::pack_impl(std::ostream& stream) const - { - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; - } - - void game_object::unpack_impl(std::istream& stream) - { - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; - } - } } // graphene::chain -namespace fc { - // Manually reflect game_object to variant to properly reflect "state" - void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth) - { - fc_elog(fc::logger::get("tournament"), "In game_obj to_variant"); - elog("In game_obj to_variant"); - fc::mutable_variant_object o; - o("id", fc::variant(game_obj.id, max_depth )) - ("match_id", fc::variant(game_obj.match_id, max_depth )) - ("players", fc::variant(game_obj.players, max_depth )) - ("winners", fc::variant(game_obj.winners, max_depth )) - ("game_details", fc::variant(game_obj.game_details, max_depth )) - ("next_timeout", fc::variant(game_obj.next_timeout, max_depth )) - ("state", fc::variant(game_obj.get_state(), max_depth )); - - v = o; - } - - // Manually reflect game_object to variant to properly reflect "state" - void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth) - { - fc_elog(fc::logger::get("tournament"), "In game_obj from_variant"); - game_obj.id = v["id"].as( max_depth ); - game_obj.match_id = v["match_id"].as( max_depth ); - game_obj.players = v["players"].as >( max_depth ); - game_obj.winners = v["winners"].as >( max_depth ); - game_obj.game_details = v["game_details"].as( max_depth ); - game_obj.next_timeout = v["next_timeout"].as >( max_depth ); - graphene::chain::game_state state = v["state"].as( max_depth ); - const_cast(game_obj.my->state_machine.current_state())[0] = (int)state; - } -} //end namespace fc - diff --git a/libraries/chain/include/graphene/chain/game_object.hpp b/libraries/chain/include/graphene/chain/game_object.hpp index 863deff9..1f326b90 100644 --- a/libraries/chain/include/graphene/chain/game_object.hpp +++ b/libraries/chain/include/graphene/chain/game_object.hpp @@ -23,22 +23,9 @@ */ #pragma once -#include #include -#include -#include +#include #include -#include -#include - -namespace graphene { namespace chain { - class game_object; -} } - -namespace fc { - void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth = 1); - void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth = 1); -} //end namespace fc namespace graphene { namespace chain { class database; @@ -82,21 +69,6 @@ namespace graphene { namespace chain { void on_move(database& db, const game_move_operation& op); void on_timeout(database& db); void start_game(database& db, const std::vector& players); - - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const game_object& game_obj ); - - template - friend Stream& operator>>( Stream& s, game_object& game_obj ); - - friend void ::fc::to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth); - - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); class impl; std::unique_ptr my; @@ -113,50 +85,6 @@ namespace graphene { namespace chain { member > > > > game_object_multi_index_type; typedef generic_index game_index; - - template - inline Stream& operator<<( Stream& s, const game_object& game_obj ) - { - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, game_obj); - fc::raw::pack(s, game_obj.id); - fc::raw::pack(s, game_obj.match_id); - fc::raw::pack(s, game_obj.players); - fc::raw::pack(s, game_obj.winners); - fc::raw::pack(s, game_obj.game_details); - fc::raw::pack(s, game_obj.next_timeout); - - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - game_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc::raw::pack(s, stream.str()); - - return s; - } - - template - inline Stream& operator>>( Stream& s, game_object& game_obj ) - { - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, game_obj); - fc::raw::unpack(s, game_obj.id); - fc::raw::unpack(s, game_obj.match_id); - fc::raw::unpack(s, game_obj.players); - fc::raw::unpack(s, game_obj.winners); - fc::raw::unpack(s, game_obj.game_details); - fc::raw::unpack(s, game_obj.next_timeout); - - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - game_obj.unpack_impl(stream); - - return s; - } - } } FC_REFLECT_ENUM(graphene::chain::game_state, @@ -171,4 +99,6 @@ FC_REFLECT_DERIVED(graphene::chain::game_object, (graphene::db::object), (players) (winners) (game_details) - (next_timeout)) \ No newline at end of file + (next_timeout)) + +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::game_object ) \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 701a4888..098e5dd1 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -577,6 +577,7 @@ FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_id_type ) FC_REFLECT_TYPENAME( graphene::chain::betting_market_position_id_type ) FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type ) FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::game_id_type ) FC_REFLECT_TYPENAME( graphene::chain::match_id_type ) FC_REFLECT_TYPENAME( graphene::chain::custom_permission_id_type ) FC_REFLECT_TYPENAME( graphene::chain::custom_account_authority_id_type ) diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 9c54fba3..ba0f5b79 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -74,5 +75,6 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_object GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_scheduler ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedule_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::game_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object ) -- 2.45.2 From 42504ab65b57d5a2a689e2f2c5bb72a9a695a02e Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 13:03:27 +0300 Subject: [PATCH 05/17] #235 event_object : delete custom variant and Stream operator functions --- libraries/chain/event_object.cpp | 44 ----------- .../include/graphene/chain/event_object.hpp | 76 +------------------ libraries/chain/small_objects.cpp | 2 + 3 files changed, 6 insertions(+), 116 deletions(-) diff --git a/libraries/chain/event_object.cpp b/libraries/chain/event_object.cpp index 4c2fce14..d00e1be8 100644 --- a/libraries/chain/event_object.cpp +++ b/libraries/chain/event_object.cpp @@ -31,8 +31,6 @@ #include #include #include -#include -#include #include namespace graphene { namespace chain { @@ -476,18 +474,6 @@ namespace graphene { namespace chain { }; } - void event_object::pack_impl(std::ostream& stream) const - { - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; - } - - void event_object::unpack_impl(std::istream& stream) - { - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; - } - void event_object::on_upcoming_event(database& db) { my->state_machine.process_event(upcoming_event(db)); @@ -551,34 +537,4 @@ namespace graphene { namespace chain { } } // graphene::chain -namespace fc { - // Manually reflect event_object to variant to properly reflect "state" - void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth) - { - fc::mutable_variant_object o; - o("id", fc::variant(event_obj.id, max_depth)) - ("name", fc::variant(event_obj.name, max_depth)) - ("season", fc::variant(event_obj.season, max_depth)) - ("start_time", fc::variant(event_obj.start_time, max_depth)) - ("event_group_id", fc::variant(event_obj.event_group_id, max_depth)) - ("scores", fc::variant(event_obj.scores, max_depth)) - ("status", fc::variant(event_obj.get_status(), max_depth)); - - v = o; - } - - // Manually reflect event_object to variant to properly reflect "state" - void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth) - { - event_obj.id = v["id"].as( max_depth ); - event_obj.name = v["name"].as( max_depth ); - event_obj.season = v["season"].as( max_depth ); - event_obj.start_time = v["start_time"].as >( max_depth ); - event_obj.event_group_id = v["event_group_id"].as( max_depth ); - event_obj.scores = v["scores"].as>( max_depth ); - graphene::chain::event_status status = v["status"].as( max_depth ); - const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; - } -} //end namespace fc - diff --git a/libraries/chain/include/graphene/chain/event_object.hpp b/libraries/chain/include/graphene/chain/event_object.hpp index 56330029..ae69dc0e 100644 --- a/libraries/chain/include/graphene/chain/event_object.hpp +++ b/libraries/chain/include/graphene/chain/event_object.hpp @@ -24,22 +24,12 @@ #pragma once #include +#include #include #include -#include -#include #include -namespace graphene { namespace chain { - class event_object; -} } - -namespace fc { - void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth = 1); - void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth = 1); -} //end namespace fc - namespace graphene { namespace chain { class database; @@ -68,21 +58,6 @@ class event_object : public graphene::db::abstract_object< event_object > event_status get_status() const; vector scores; - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const event_object& event_obj ); - - template - friend Stream& operator>>( Stream& s, event_object& event_obj ); - - friend void ::fc::to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth); - - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); - void on_upcoming_event(database& db); void on_in_progress_event(database& db); void on_frozen_event(database& db); @@ -111,53 +86,10 @@ typedef multi_index_container< member > > > > event_object_multi_index_type; typedef generic_index event_object_index; - - template - inline Stream& operator<<( Stream& s, const event_object& event_obj ) - { - fc_elog(fc::logger::get("event"), "In event_obj to_raw"); - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, event_obj); - fc::raw::pack(s, event_obj.id); - fc::raw::pack(s, event_obj.name); - fc::raw::pack(s, event_obj.season); - fc::raw::pack(s, event_obj.start_time); - fc::raw::pack(s, event_obj.event_group_id); - fc::raw::pack(s, event_obj.at_least_one_betting_market_group_settled); - fc::raw::pack(s, event_obj.scores); - - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - event_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc::raw::pack(s, stream.str()); - - return s; - } - template - inline Stream& operator>>( Stream& s, event_object& event_obj ) - { - fc_elog(fc::logger::get("event"), "In event_obj from_raw"); - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, event_obj); - fc::raw::unpack(s, event_obj.id); - fc::raw::unpack(s, event_obj.name); - fc::raw::unpack(s, event_obj.season); - fc::raw::unpack(s, event_obj.start_time); - fc::raw::unpack(s, event_obj.event_group_id); - fc::raw::unpack(s, event_obj.at_least_one_betting_market_group_settled); - fc::raw::unpack(s, event_obj.scores); - - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - event_obj.unpack_impl(stream); - - return s; - } } } // graphene::chain + FC_REFLECT(graphene::chain::event_object, (name)(season)(start_time)(event_group_id)(at_least_one_betting_market_group_settled)(scores)) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::event_object ) + diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index ba0f5b79..33e57271 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -77,4 +78,5 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedu GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::game_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::event_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object ) -- 2.45.2 From 3f205a572297fd8c33778d6147fb3fd4b927f524 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 13:04:00 +0300 Subject: [PATCH 06/17] #235 betting_market_object : delete custom variant and Stream operator functions --- .../chain/betting_market_group_object.cpp | 49 ------ libraries/chain/betting_market_object.cpp | 42 ------ .../graphene/chain/betting_market_object.hpp | 140 +----------------- libraries/chain/small_objects.cpp | 3 + 4 files changed, 9 insertions(+), 225 deletions(-) diff --git a/libraries/chain/betting_market_group_object.cpp b/libraries/chain/betting_market_group_object.cpp index 2ac7d7a4..393a9f3f 100644 --- a/libraries/chain/betting_market_group_object.cpp +++ b/libraries/chain/betting_market_group_object.cpp @@ -30,8 +30,6 @@ #include #include -#include -#include #include namespace graphene { namespace chain { @@ -460,18 +458,6 @@ betting_market_group_status betting_market_group_object::get_status() const }; } -void betting_market_group_object::pack_impl(std::ostream& stream) const -{ - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; -} - -void betting_market_group_object::unpack_impl(std::istream& stream) -{ - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; -} - void betting_market_group_object::on_upcoming_event(database& db) { my->state_machine.process_event(upcoming_event(db)); @@ -541,38 +527,3 @@ void betting_market_group_object::dispatch_new_status(database& db, betting_mark } } // graphene::chain -namespace fc { - // Manually reflect betting_market_group_object to variant to properly reflect "state" - void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth) - { - fc::mutable_variant_object o; - o("id", fc::variant(betting_market_group_obj.id, max_depth)) - ("description", fc::variant(betting_market_group_obj.description, max_depth)) - ("event_id", fc::variant(betting_market_group_obj.event_id, max_depth)) - ("rules_id", fc::variant(betting_market_group_obj.rules_id, max_depth)) - ("asset_id", fc::variant(betting_market_group_obj.asset_id, max_depth)) - ("total_matched_bets_amount", fc::variant(betting_market_group_obj.total_matched_bets_amount, max_depth)) - ("never_in_play", fc::variant(betting_market_group_obj.never_in_play, max_depth)) - ("delay_before_settling", fc::variant(betting_market_group_obj.delay_before_settling, max_depth)) - ("settling_time", fc::variant(betting_market_group_obj.settling_time, max_depth)) - ("status", fc::variant(betting_market_group_obj.get_status(), max_depth)); - - v = o; - } - - // Manually reflect betting_market_group_object to variant to properly reflect "state" - void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth) - { - betting_market_group_obj.id = v["id"].as( max_depth ); - betting_market_group_obj.description = v["description"].as( max_depth ); - betting_market_group_obj.event_id = v["event_id"].as( max_depth ); - betting_market_group_obj.asset_id = v["asset_id"].as( max_depth ); - betting_market_group_obj.total_matched_bets_amount = v["total_matched_bets_amount"].as( max_depth ); - betting_market_group_obj.never_in_play = v["never_in_play"].as( max_depth ); - betting_market_group_obj.delay_before_settling = v["delay_before_settling"].as( max_depth ); - betting_market_group_obj.settling_time = v["settling_time"].as>( max_depth ); - graphene::chain::betting_market_group_status status = v["status"].as( max_depth ); - const_cast(betting_market_group_obj.my->state_machine.current_state())[0] = (int)status; - } -} //end namespace fc - diff --git a/libraries/chain/betting_market_object.cpp b/libraries/chain/betting_market_object.cpp index d5efd56c..8f706458 100644 --- a/libraries/chain/betting_market_object.cpp +++ b/libraries/chain/betting_market_object.cpp @@ -29,8 +29,6 @@ #include #include -#include -#include #include namespace graphene { namespace chain { @@ -422,18 +420,6 @@ void betting_market_object::cancel_all_bets(database& db) const } } -void betting_market_object::pack_impl(std::ostream& stream) const -{ - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; -} - -void betting_market_object::unpack_impl(std::istream& stream) -{ - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; -} - void betting_market_object::on_unresolved_event(database& db) { my->state_machine.process_event(unresolved_event(db)); @@ -466,31 +452,3 @@ void betting_market_object::on_canceled_event(database& db) } } // graphene::chain -namespace fc { - // Manually reflect betting_market_object to variant to properly reflect "state" - void to_variant(const graphene::chain::betting_market_object& event_obj, fc::variant& v, uint32_t max_depth) - { - fc::mutable_variant_object o; - o("id", fc::variant(event_obj.id, max_depth) ) - ("group_id", fc::variant(event_obj.group_id, max_depth)) - ("description", fc::variant(event_obj.description, max_depth)) - ("payout_condition", fc::variant(event_obj.payout_condition, max_depth)) - ("resolution", fc::variant(event_obj.resolution, max_depth)) - ("status", fc::variant(event_obj.get_status(), max_depth)); - - v = o; - } - - // Manually reflect betting_market_object to variant to properly reflect "state" - void from_variant(const fc::variant& v, graphene::chain::betting_market_object& event_obj, uint32_t max_depth) - { - event_obj.id = v["id"].as( max_depth ); - event_obj.group_id = v["name"].as( max_depth ); - event_obj.description = v["description"].as( max_depth ); - event_obj.payout_condition = v["payout_condition"].as( max_depth ); - event_obj.resolution = v["resolution"].as>( max_depth ); - graphene::chain::betting_market_status status = v["status"].as( max_depth ); - const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; - } -} //end namespace fc - diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp index 2abe6b20..34946344 100644 --- a/libraries/chain/include/graphene/chain/betting_market_object.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -24,25 +24,12 @@ #pragma once #include +#include #include #include -#include -#include #include -namespace graphene { namespace chain { - class betting_market_object; - class betting_market_group_object; -} } - -namespace fc { - void to_variant(const graphene::chain::betting_market_object& betting_market_obj, fc::variant& v, uint32_t max_depth = 1); - void from_variant(const fc::variant& v, graphene::chain::betting_market_object& betting_market_obj, uint32_t max_depth = 1); - void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth = 1); - void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth = 1); -} //end namespace fc - namespace graphene { namespace chain { FC_DECLARE_EXCEPTION(no_transition, 100000, "Invalid state transition"); @@ -101,21 +88,6 @@ class betting_market_group_object : public graphene::db::abstract_object< bettin betting_market_group_status get_status() const; - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const betting_market_group_object& betting_market_group_obj ); - - template - friend Stream& operator>>( Stream& s, betting_market_group_object& betting_market_group_obj ); - - friend void ::fc::to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth); - - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); - void on_upcoming_event(database& db); void on_in_play_event(database& db); void on_frozen_event(database& db); @@ -157,21 +129,6 @@ class betting_market_object : public graphene::db::abstract_object< betting_mark void cancel_all_unmatched_bets(database& db) const; void cancel_all_bets(database& db) const; - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const betting_market_object& betting_market_obj ); - - template - friend Stream& operator>>( Stream& s, betting_market_object& betting_market_obj ); - - friend void ::fc::to_variant(const graphene::chain::betting_market_object& betting_market_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::betting_market_object& betting_market_obj, uint32_t max_depth); - - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); - void on_unresolved_event(database& db); void on_frozen_event(database& db); void on_closed_event(database& db); @@ -625,101 +582,16 @@ typedef multi_index_container< > > betting_market_position_multi_index_type; typedef generic_index betting_market_position_index; - - -template -inline Stream& operator<<( Stream& s, const betting_market_object& betting_market_obj ) -{ - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, betting_market_obj); - fc::raw::pack(s, betting_market_obj.id); - fc::raw::pack(s, betting_market_obj.group_id); - fc::raw::pack(s, betting_market_obj.description); - fc::raw::pack(s, betting_market_obj.payout_condition); - fc::raw::pack(s, betting_market_obj.resolution); - - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - betting_market_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc::raw::pack(s, stream.str()); - - return s; -} -template -inline Stream& operator>>( Stream& s, betting_market_object& betting_market_obj ) -{ - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, betting_market_obj); - fc::raw::unpack(s, betting_market_obj.id); - fc::raw::unpack(s, betting_market_obj.group_id); - fc::raw::unpack(s, betting_market_obj.description); - fc::raw::unpack(s, betting_market_obj.payout_condition); - fc::raw::unpack(s, betting_market_obj.resolution); - - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - betting_market_obj.unpack_impl(stream); - - return s; -} - - -template -inline Stream& operator<<( Stream& s, const betting_market_group_object& betting_market_group_obj ) -{ - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, betting_market_group_obj); - fc::raw::pack(s, betting_market_group_obj.id); - fc::raw::pack(s, betting_market_group_obj.description); - fc::raw::pack(s, betting_market_group_obj.event_id); - fc::raw::pack(s, betting_market_group_obj.rules_id); - fc::raw::pack(s, betting_market_group_obj.asset_id); - fc::raw::pack(s, betting_market_group_obj.total_matched_bets_amount); - fc::raw::pack(s, betting_market_group_obj.never_in_play); - fc::raw::pack(s, betting_market_group_obj.delay_before_settling); - fc::raw::pack(s, betting_market_group_obj.settling_time); - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - betting_market_group_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc::raw::pack(s, stream.str()); - - return s; -} -template -inline Stream& operator>>( Stream& s, betting_market_group_object& betting_market_group_obj ) -{ - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, betting_market_group_obj); - fc::raw::unpack(s, betting_market_group_obj.id); - fc::raw::unpack(s, betting_market_group_obj.description); - fc::raw::unpack(s, betting_market_group_obj.event_id); - fc::raw::unpack(s, betting_market_group_obj.rules_id); - fc::raw::unpack(s, betting_market_group_obj.asset_id); - fc::raw::unpack(s, betting_market_group_obj.total_matched_bets_amount); - fc::raw::unpack(s, betting_market_group_obj.never_in_play); - fc::raw::unpack(s, betting_market_group_obj.delay_before_settling); - fc::raw::unpack(s, betting_market_group_obj.settling_time); - - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - betting_market_group_obj.unpack_impl(stream); - - return s; -} - } } // graphene::chain FC_REFLECT_DERIVED( graphene::chain::betting_market_rules_object, (graphene::db::object), (name)(description) ) + FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (description)(event_id)(rules_id)(asset_id)(total_matched_bets_amount)(never_in_play)(delay_before_settling)(settling_time) ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::betting_market_group_object ) + FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id)(description)(payout_condition)(resolution) ) +GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::betting_market_object ) + FC_REFLECT_DERIVED( graphene::chain::bet_object, (graphene::db::object), (bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(back_or_lay)(end_of_delay) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_position_object, (graphene::db::object), (bettor_id)(betting_market_id)(pay_if_payout_condition)(pay_if_not_payout_condition)(pay_if_canceled)(pay_if_not_canceled)(fees_collected) ) diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 33e57271..58c63b80 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include @@ -80,3 +81,5 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::game_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::event_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_group_object ) +GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_object ) -- 2.45.2 From cca322573b229493622686ea951e3343aec212a7 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 14:48:40 +0300 Subject: [PATCH 07/17] #235 FC_REFLECT_DERIVED for event_object --- libraries/chain/include/graphene/chain/event_object.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/chain/include/graphene/chain/event_object.hpp b/libraries/chain/include/graphene/chain/event_object.hpp index ae69dc0e..199f38af 100644 --- a/libraries/chain/include/graphene/chain/event_object.hpp +++ b/libraries/chain/include/graphene/chain/event_object.hpp @@ -88,7 +88,13 @@ typedef multi_index_container< typedef generic_index event_object_index; } } // graphene::chain -FC_REFLECT(graphene::chain::event_object, (name)(season)(start_time)(event_group_id)(at_least_one_betting_market_group_settled)(scores)) +FC_REFLECT_DERIVED(graphene::chain::event_object, (graphene::db::object), + (name) + (season) + (start_time) + (event_group_id) + (at_least_one_betting_market_group_settled) + (scores)) GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::event_object ) -- 2.45.2 From ac1be63dddb7c7b4302392affc4b13307a5e1b03 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Mon, 21 Feb 2022 09:10:58 +0300 Subject: [PATCH 08/17] #235 - fix bookie plugin. Don't use db for secondary_index --- .../affiliate_stats/affiliate_stats_api.hpp | 1 - libraries/plugins/bookie/bookie_api.cpp | 126 +++++----- libraries/plugins/bookie/bookie_plugin.cpp | 233 ++++++------------ .../graphene/bookie/bookie_objects.hpp | 193 ++++++++------- 4 files changed, 246 insertions(+), 307 deletions(-) diff --git a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp index 29c45d9f..7ec1a088 100644 --- a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp +++ b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp @@ -29,7 +29,6 @@ #include #include -#include #include #include diff --git a/libraries/plugins/bookie/bookie_api.cpp b/libraries/plugins/bookie/bookie_api.cpp index 9caa9c62..98bd2d23 100644 --- a/libraries/plugins/bookie/bookie_api.cpp +++ b/libraries/plugins/bookie/bookie_api.cpp @@ -157,37 +157,45 @@ fc::variants bookie_api_impl::get_objects(const vector& ids) con { case event_id_type::type_id: { - auto& persistent_events_by_event_id = db->get_index_type().indices().get(); - auto iter = persistent_events_by_event_id.find(id.as()); - if (iter != persistent_events_by_event_id.end()) - return iter->ephemeral_event_object.to_variant(); + const auto &idx = db->get_index_type(); + const auto &aidx = dynamic_cast(idx); + const auto &refs = aidx.get_secondary_index(); + auto iter = refs.ephemeral_event_object.find(id.as()); + if (iter != refs.ephemeral_event_object.end()) + return iter->second.to_variant(); else return {}; } case bet_id_type::type_id: { - auto& persistent_bets_by_bet_id = db->get_index_type().indices().get(); - auto iter = persistent_bets_by_bet_id.find(id.as()); - if (iter != persistent_bets_by_bet_id.end()) - return iter->ephemeral_bet_object.to_variant(); + const auto &idx = db->get_index_type(); + const auto &aidx = dynamic_cast(idx); + const auto &refs = aidx.get_secondary_index(); + auto iter = refs.internal.find(id.as()); + if (iter != refs.internal.end()) + return iter->second.ephemeral_bet_object.to_variant(); else return {}; } case betting_market_object::type_id: - { - auto& persistent_betting_markets_by_betting_market_id = db->get_index_type().indices().get(); - auto iter = persistent_betting_markets_by_betting_market_id.find(id.as()); - if (iter != persistent_betting_markets_by_betting_market_id.end()) - return iter->ephemeral_betting_market_object.to_variant(); + { + const auto &idx = db->get_index_type(); + const auto &aidx = dynamic_cast(idx); + const auto &refs = aidx.get_secondary_index(); + auto iter = refs.ephemeral_betting_market_object.find(id.as()); + if (iter != refs.ephemeral_betting_market_object.end()) + return iter->second.to_variant(); else return {}; } case betting_market_group_object::type_id: - { - auto& persistent_betting_market_groups_by_betting_market_group_id = db->get_index_type().indices().get(); - auto iter = persistent_betting_market_groups_by_betting_market_group_id.find(id.as()); - if (iter != persistent_betting_market_groups_by_betting_market_group_id.end()) - return iter->ephemeral_betting_market_group_object.to_variant(); + { + const auto &idx = db->get_index_type(); + const auto &aidx = dynamic_cast(idx); + const auto &refs = aidx.get_secondary_index(); + auto iter = refs.internal.find(id.as()); + if (iter != refs.internal.end()) + return iter->second.ephemeral_betting_market_group_object.to_variant(); else return {}; } @@ -203,25 +211,28 @@ std::vector bookie_api_impl::get_matched_bets_for_bettor(acc { std::vector result; std::shared_ptr db = app.chain_database(); - auto& persistent_bets_by_bettor_id = db->get_index_type().indices().get(); - auto iter = persistent_bets_by_bettor_id.lower_bound(std::make_tuple(bettor_id, true)); - while (iter != persistent_bets_by_bettor_id.end() && - iter->get_bettor_id() == bettor_id && - iter->is_matched()) - { - matched_bet_object match; - match.id = iter->ephemeral_bet_object.id; - match.bettor_id = iter->ephemeral_bet_object.bettor_id; - match.betting_market_id = iter->ephemeral_bet_object.betting_market_id; - match.amount_to_bet = iter->ephemeral_bet_object.amount_to_bet; - match.back_or_lay = iter->ephemeral_bet_object.back_or_lay; - match.end_of_delay = iter->ephemeral_bet_object.end_of_delay; - match.amount_matched = iter->amount_matched; - match.associated_operations = iter->associated_operations; - result.emplace_back(std::move(match)); + const auto &idx = db->get_index_type(); + const auto &aidx = dynamic_cast(idx); + const auto &refs = aidx.get_secondary_index(); - ++iter; + for( const auto& bet_pair : refs.internal ) + { + const auto& bet = bet_pair.second; + if( bet.get_bettor_id() == bettor_id && bet.is_matched() ) + { + matched_bet_object match; + match.id = bet.ephemeral_bet_object.id; + match.bettor_id = bet.ephemeral_bet_object.bettor_id; + match.betting_market_id = bet.ephemeral_bet_object.betting_market_id; + match.amount_to_bet = bet.ephemeral_bet_object.amount_to_bet; + match.back_or_lay = bet.ephemeral_bet_object.back_or_lay; + match.end_of_delay = bet.ephemeral_bet_object.end_of_delay; + match.amount_matched = bet.amount_matched; + match.associated_operations = bet.associated_operations; + result.emplace_back(std::move(match)); + } } + return result; } @@ -231,29 +242,32 @@ std::vector bookie_api_impl::get_all_matched_bets_for_bettor std::vector result; std::shared_ptr db = app.chain_database(); - auto& persistent_bets_by_bettor_id = db->get_index_type().indices().get(); - persistent_bet_multi_index_type::index::type::iterator iter; - if (start == bet_id_type()) - iter = persistent_bets_by_bettor_id.lower_bound(std::make_tuple(bettor_id, true)); - else - iter = persistent_bets_by_bettor_id.lower_bound(std::make_tuple(bettor_id, true, start)); - while (iter != persistent_bets_by_bettor_id.end() && - iter->get_bettor_id() == bettor_id && - iter->is_matched() && - result.size() < limit) - { - matched_bet_object match; - match.id = iter->ephemeral_bet_object.id; - match.bettor_id = iter->ephemeral_bet_object.bettor_id; - match.betting_market_id = iter->ephemeral_bet_object.betting_market_id; - match.amount_to_bet = iter->ephemeral_bet_object.amount_to_bet; - match.back_or_lay = iter->ephemeral_bet_object.back_or_lay; - match.end_of_delay = iter->ephemeral_bet_object.end_of_delay; - match.amount_matched = iter->amount_matched; - result.emplace_back(std::move(match)); + const auto &idx = db->get_index_type(); + const auto &aidx = dynamic_cast(idx); + const auto &refs = aidx.get_secondary_index(); - ++iter; + for( const auto& bet_pair : refs.internal ) + { + const auto& bet_id = bet_pair.first; + const auto& bet = bet_pair.second; + if( bet.get_bettor_id() == bettor_id && + bet.is_matched() && + bet_id > start && + result.size() < limit ) + { + matched_bet_object match; + match.id = bet.ephemeral_bet_object.id; + match.bettor_id = bet.ephemeral_bet_object.bettor_id; + match.betting_market_id = bet.ephemeral_bet_object.betting_market_id; + match.amount_to_bet = bet.ephemeral_bet_object.amount_to_bet; + match.back_or_lay = bet.ephemeral_bet_object.back_or_lay; + match.end_of_delay = bet.ephemeral_bet_object.end_of_delay; + match.amount_matched = bet.amount_matched; + match.associated_operations = bet.associated_operations; + result.emplace_back(std::move(match)); + } } + return result; } diff --git a/libraries/plugins/bookie/bookie_plugin.cpp b/libraries/plugins/bookie/bookie_plugin.cpp index 5bc31f14..93b24c39 100644 --- a/libraries/plugins/bookie/bookie_plugin.cpp +++ b/libraries/plugins/bookie/bookie_plugin.cpp @@ -59,143 +59,67 @@ namespace detail * We do this by creating a secondary index on bet_object. We don't actually use it * to index any property of the bet, we just use it to register for callbacks. */ -class persistent_bet_object_helper : public secondary_index -{ - public: - virtual ~persistent_bet_object_helper() {} - virtual void object_inserted(const object& obj) override; - //virtual void object_removed( const object& obj ) override; - //virtual void about_to_modify( const object& before ) override; - virtual void object_modified(const object& after) override; - void set_plugin_instance(bookie_plugin* instance) { _bookie_plugin = instance; } - private: - bookie_plugin* _bookie_plugin; -}; - -void persistent_bet_object_helper::object_inserted(const object& obj) +void persistent_bet_index::object_inserted(const object& obj) { const bet_object& bet_obj = *boost::polymorphic_downcast(&obj); - _bookie_plugin->database().create([&](persistent_bet_object& saved_bet_obj) { - saved_bet_obj.ephemeral_bet_object = bet_obj; - }); + internal.insert( {bet_obj.id, bet_obj} ); } -void persistent_bet_object_helper::object_modified(const object& after) +void persistent_bet_index::object_modified(const object& after) { - database& db = _bookie_plugin->database(); - auto& persistent_bets_by_bet_id = db.get_index_type().indices().get(); const bet_object& bet_obj = *boost::polymorphic_downcast(&after); - auto iter = persistent_bets_by_bet_id.find(bet_obj.id); - assert (iter != persistent_bets_by_bet_id.end()); - if (iter != persistent_bets_by_bet_id.end()) - db.modify(*iter, [&](persistent_bet_object& saved_bet_obj) { - saved_bet_obj.ephemeral_bet_object = bet_obj; - }); + auto iter = internal.find(bet_obj.id); + assert (iter != internal.end()); + if (iter != internal.end()) + iter->second = bet_obj; } //////////// end bet_object /////////////////// -class persistent_betting_market_object_helper : public secondary_index -{ - public: - virtual ~persistent_betting_market_object_helper() {} - virtual void object_inserted(const object& obj) override; - //virtual void object_removed( const object& obj ) override; - //virtual void about_to_modify( const object& before ) override; - virtual void object_modified(const object& after) override; - void set_plugin_instance(bookie_plugin* instance) { _bookie_plugin = instance; } - private: - bookie_plugin* _bookie_plugin; -}; - -void persistent_betting_market_object_helper::object_inserted(const object& obj) +void persistent_betting_market_index::object_inserted(const object& obj) { const betting_market_object& betting_market_obj = *boost::polymorphic_downcast(&obj); - _bookie_plugin->database().create([&](persistent_betting_market_object& saved_betting_market_obj) { - saved_betting_market_obj.ephemeral_betting_market_object = betting_market_obj; - }); + ephemeral_betting_market_object.insert( {betting_market_obj.id, betting_market_obj} ); } -void persistent_betting_market_object_helper::object_modified(const object& after) +void persistent_betting_market_index::object_modified(const object& after) { - database& db = _bookie_plugin->database(); - auto& persistent_betting_markets_by_betting_market_id = db.get_index_type().indices().get(); const betting_market_object& betting_market_obj = *boost::polymorphic_downcast(&after); - auto iter = persistent_betting_markets_by_betting_market_id.find(betting_market_obj.id); - assert (iter != persistent_betting_markets_by_betting_market_id.end()); - if (iter != persistent_betting_markets_by_betting_market_id.end()) - db.modify(*iter, [&](persistent_betting_market_object& saved_betting_market_obj) { - saved_betting_market_obj.ephemeral_betting_market_object = betting_market_obj; - }); + auto iter = ephemeral_betting_market_object.find(betting_market_obj.id); + assert (iter != ephemeral_betting_market_object.end()); + if (iter != ephemeral_betting_market_object.end()) + iter->second = betting_market_obj; } //////////// end betting_market_object /////////////////// -class persistent_betting_market_group_object_helper : public secondary_index -{ - public: - virtual ~persistent_betting_market_group_object_helper() {} - virtual void object_inserted(const object& obj) override; - //virtual void object_removed( const object& obj ) override; - //virtual void about_to_modify( const object& before ) override; - virtual void object_modified(const object& after) override; - void set_plugin_instance(bookie_plugin* instance) { _bookie_plugin = instance; } - private: - bookie_plugin* _bookie_plugin; -}; - -void persistent_betting_market_group_object_helper::object_inserted(const object& obj) +void persistent_betting_market_group_index::object_inserted(const object& obj) { const betting_market_group_object& betting_market_group_obj = *boost::polymorphic_downcast(&obj); - _bookie_plugin->database().create([&](persistent_betting_market_group_object& saved_betting_market_group_obj) { - saved_betting_market_group_obj.ephemeral_betting_market_group_object = betting_market_group_obj; - }); + internal.insert( {betting_market_group_obj.id, betting_market_group_obj} ); } -void persistent_betting_market_group_object_helper::object_modified(const object& after) +void persistent_betting_market_group_index::object_modified(const object& after) { - database& db = _bookie_plugin->database(); - auto& persistent_betting_market_groups_by_betting_market_group_id = db.get_index_type().indices().get(); const betting_market_group_object& betting_market_group_obj = *boost::polymorphic_downcast(&after); - auto iter = persistent_betting_market_groups_by_betting_market_group_id.find(betting_market_group_obj.id); - assert (iter != persistent_betting_market_groups_by_betting_market_group_id.end()); - if (iter != persistent_betting_market_groups_by_betting_market_group_id.end()) - db.modify(*iter, [&](persistent_betting_market_group_object& saved_betting_market_group_obj) { - saved_betting_market_group_obj.ephemeral_betting_market_group_object = betting_market_group_obj; - }); + auto iter = internal.find(betting_market_group_obj.id); + assert (iter != internal.end()); + if (iter != internal.end()) + iter->second = betting_market_group_obj; } //////////// end betting_market_group_object /////////////////// -class persistent_event_object_helper : public secondary_index -{ - public: - virtual ~persistent_event_object_helper() {} - virtual void object_inserted(const object& obj) override; - //virtual void object_removed( const object& obj ) override; - //virtual void about_to_modify( const object& before ) override; - virtual void object_modified(const object& after) override; - void set_plugin_instance(bookie_plugin* instance) { _bookie_plugin = instance; } - private: - bookie_plugin* _bookie_plugin; -}; - -void persistent_event_object_helper::object_inserted(const object& obj) +void persistent_event_index::object_inserted(const object& obj) { const event_object& event_obj = *boost::polymorphic_downcast(&obj); - _bookie_plugin->database().create([&](persistent_event_object& saved_event_obj) { - saved_event_obj.ephemeral_event_object = event_obj; - }); + ephemeral_event_object.insert( {event_obj.id, event_obj} ); } -void persistent_event_object_helper::object_modified(const object& after) +void persistent_event_index::object_modified(const object& after) { - database& db = _bookie_plugin->database(); - auto& persistent_events_by_event_id = db.get_index_type().indices().get(); const event_object& event_obj = *boost::polymorphic_downcast(&after); - auto iter = persistent_events_by_event_id.find(event_obj.id); - assert (iter != persistent_events_by_event_id.end()); - if (iter != persistent_events_by_event_id.end()) - db.modify(*iter, [&](persistent_event_object& saved_event_obj) { - saved_event_obj.ephemeral_event_object = event_obj; - }); + auto iter = ephemeral_event_object.find(event_obj.id); + assert (iter != ephemeral_event_object.end()); + if (iter != ephemeral_event_object.end()) + iter->second = event_obj; } //////////// end event_object /////////////////// @@ -207,7 +131,6 @@ class bookie_plugin_impl { } virtual ~bookie_plugin_impl(); - /** * Called After a block has been applied and committed. The callback * should not yield and should execute quickly. @@ -299,27 +222,35 @@ void bookie_plugin_impl::on_block_applied( const signed_block& ) const asset& amount_bet = bet_matched_op.amount_bet; // object may no longer exist //const bet_object& bet = bet_matched_op.bet_id(db); - auto& persistent_bets_by_bet_id = db.get_index_type().indices().get(); - auto bet_iter = persistent_bets_by_bet_id.find(bet_matched_op.bet_id); - assert(bet_iter != persistent_bets_by_bet_id.end()); - if (bet_iter != persistent_bets_by_bet_id.end()) + const auto &idx_bet_object = db.get_index_type(); + const auto &aidx_bet_object = dynamic_cast(idx_bet_object); + const auto &refs_bet_object = aidx_bet_object.get_secondary_index(); + auto& nonconst_refs_bet_object = const_cast(refs_bet_object); + + auto bet_iter = nonconst_refs_bet_object.internal.find(bet_matched_op.bet_id); + assert(bet_iter != nonconst_refs_bet_object.internal.end()); + if (bet_iter != nonconst_refs_bet_object.internal.end()) { - db.modify(*bet_iter, [&]( persistent_bet_object& obj ) { - obj.amount_matched += amount_bet.amount; - if (is_operation_history_object_stored(op.id)) - obj.associated_operations.emplace_back(op.id); - }); - const bet_object& bet_obj = bet_iter->ephemeral_bet_object; + bet_iter->second.amount_matched += amount_bet.amount; + if (is_operation_history_object_stored(op.id)) + bet_iter->second.associated_operations.emplace_back(op.id); - auto& persistent_betting_market_idx = db.get_index_type().indices().get(); - auto persistent_betting_market_object_iter = persistent_betting_market_idx.find(bet_obj.betting_market_id); - FC_ASSERT(persistent_betting_market_object_iter != persistent_betting_market_idx.end()); - const betting_market_object& betting_market = persistent_betting_market_object_iter->ephemeral_betting_market_object; + const bet_object& bet_obj = bet_iter->second.ephemeral_bet_object; - auto& persistent_betting_market_group_idx = db.get_index_type().indices().get(); - auto persistent_betting_market_group_object_iter = persistent_betting_market_group_idx.find(betting_market.group_id); - FC_ASSERT(persistent_betting_market_group_object_iter != persistent_betting_market_group_idx.end()); - const betting_market_group_object& betting_market_group = persistent_betting_market_group_object_iter->ephemeral_betting_market_group_object; + const auto &idx_betting_market = db.get_index_type(); + const auto &aidx_betting_market = dynamic_cast(idx_betting_market); + const auto &refs_betting_market = aidx_betting_market.get_secondary_index(); + auto persistent_betting_market_object_iter = refs_betting_market.ephemeral_betting_market_object.find(bet_obj.betting_market_id); + FC_ASSERT(persistent_betting_market_object_iter != refs_betting_market.ephemeral_betting_market_object.end()); + const betting_market_object& betting_market = persistent_betting_market_object_iter->second; + + const auto &idx_betting_market_group = db.get_index_type(); + const auto &aidx_betting_market_group = dynamic_cast(idx_betting_market_group); + const auto &refs_betting_market_group = aidx_betting_market_group.get_secondary_index(); + auto& nonconst_refs_betting_market_group = const_cast(refs_betting_market_group); + auto persistent_betting_market_group_object_iter = nonconst_refs_betting_market_group.internal.find(betting_market.group_id); + FC_ASSERT(persistent_betting_market_group_object_iter != nonconst_refs_betting_market_group.internal.end()); + const betting_market_group_object& betting_market_group = persistent_betting_market_group_object_iter->second.ephemeral_betting_market_group_object; // if the object is still in the main database, keep the running total there // otherwise, add it directly to the persistent version @@ -330,9 +261,7 @@ void bookie_plugin_impl::on_block_applied( const signed_block& ) obj.total_matched_bets_amount += amount_bet.amount; }); else - db.modify( *persistent_betting_market_group_object_iter, [&]( persistent_betting_market_group_object& obj ){ - obj.ephemeral_betting_market_group_object.total_matched_bets_amount += amount_bet.amount; - }); + persistent_betting_market_group_object_iter->second.total_matched_bets_amount += amount_bet.amount; } } else if( op.op.which() == operation::tag::value ) @@ -364,33 +293,35 @@ void bookie_plugin_impl::on_block_applied( const signed_block& ) else if ( op.op.which() == operation::tag::value ) { const bet_canceled_operation& bet_canceled_op = op.op.get(); - auto& persistent_bets_by_bet_id = db.get_index_type().indices().get(); - auto bet_iter = persistent_bets_by_bet_id.find(bet_canceled_op.bet_id); - assert(bet_iter != persistent_bets_by_bet_id.end()); - if (bet_iter != persistent_bets_by_bet_id.end()) + const auto &idx_bet_object = db.get_index_type(); + const auto &aidx_bet_object = dynamic_cast(idx_bet_object); + const auto &refs_bet_object = aidx_bet_object.get_secondary_index(); + auto& nonconst_refs_bet_object = const_cast(refs_bet_object); + + auto bet_iter = nonconst_refs_bet_object.internal.find(bet_canceled_op.bet_id); + assert(bet_iter != nonconst_refs_bet_object.internal.end()); + if (bet_iter != nonconst_refs_bet_object.internal.end()) { // ilog("Adding bet_canceled_operation ${canceled_id} to bet ${bet_id}'s associated operations", // ("canceled_id", op.id)("bet_id", bet_canceled_op.bet_id)); - if (is_operation_history_object_stored(op.id)) - db.modify(*bet_iter, [&]( persistent_bet_object& obj ) { - obj.associated_operations.emplace_back(op.id); - }); + bet_iter->second.associated_operations.emplace_back(op.id); } } else if ( op.op.which() == operation::tag::value ) { const bet_adjusted_operation& bet_adjusted_op = op.op.get(); - auto& persistent_bets_by_bet_id = db.get_index_type().indices().get(); - auto bet_iter = persistent_bets_by_bet_id.find(bet_adjusted_op.bet_id); - assert(bet_iter != persistent_bets_by_bet_id.end()); - if (bet_iter != persistent_bets_by_bet_id.end()) + const auto &idx_bet_object = db.get_index_type(); + const auto &aidx_bet_object = dynamic_cast(idx_bet_object); + const auto &refs_bet_object = aidx_bet_object.get_secondary_index(); + auto& nonconst_refs_bet_object = const_cast(refs_bet_object); + + auto bet_iter = nonconst_refs_bet_object.internal.find(bet_adjusted_op.bet_id); + assert(bet_iter != nonconst_refs_bet_object.internal.end()); + if (bet_iter != nonconst_refs_bet_object.internal.end()) { // ilog("Adding bet_adjusted_operation ${adjusted_id} to bet ${bet_id}'s associated operations", // ("adjusted_id", op.id)("bet_id", bet_adjusted_op.bet_id)); - if (is_operation_history_object_stored(op.id)) - db.modify(*bet_iter, [&]( persistent_bet_object& obj ) { - obj.associated_operations.emplace_back(op.id); - }); + bet_iter->second.associated_operations.emplace_back(op.id); } } @@ -472,31 +403,21 @@ void bookie_plugin::plugin_initialize(const boost::program_options::variables_ma database().new_objects.connect([this](const vector& ids, const flat_set& impacted_accounts) { my->on_objects_new(ids); }); database().removed_objects.connect([this](const vector& ids, const vector& objs, const flat_set& impacted_accounts) { my->on_objects_removed(ids); }); - - //auto event_index = - database().add_index >(); - database().add_index >(); - database().add_index >(); - database().add_index >(); const primary_index& bet_object_idx = database().get_index_type >(); primary_index& nonconst_bet_object_idx = const_cast&>(bet_object_idx); - detail::persistent_bet_object_helper* persistent_bet_object_helper_index = nonconst_bet_object_idx.add_secondary_index(); - persistent_bet_object_helper_index->set_plugin_instance(this); + nonconst_bet_object_idx.add_secondary_index(); const primary_index& betting_market_object_idx = database().get_index_type >(); primary_index& nonconst_betting_market_object_idx = const_cast&>(betting_market_object_idx); - detail::persistent_betting_market_object_helper* persistent_betting_market_object_helper_index = nonconst_betting_market_object_idx.add_secondary_index(); - persistent_betting_market_object_helper_index->set_plugin_instance(this); + nonconst_betting_market_object_idx.add_secondary_index(); const primary_index& betting_market_group_object_idx = database().get_index_type >(); primary_index& nonconst_betting_market_group_object_idx = const_cast&>(betting_market_group_object_idx); - detail::persistent_betting_market_group_object_helper* persistent_betting_market_group_object_helper_index = nonconst_betting_market_group_object_idx.add_secondary_index(); - persistent_betting_market_group_object_helper_index->set_plugin_instance(this); + nonconst_betting_market_group_object_idx.add_secondary_index(); const primary_index& event_object_idx = database().get_index_type >(); primary_index& nonconst_event_object_idx = const_cast&>(event_object_idx); - detail::persistent_event_object_helper* persistent_event_object_helper_index = nonconst_event_object_idx.add_secondary_index(); - persistent_event_object_helper_index->set_plugin_instance(this); + nonconst_event_object_idx.add_secondary_index(); ilog("bookie plugin: plugin_startup() end"); } diff --git a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp index 1166ced3..b234709d 100644 --- a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp +++ b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp @@ -29,39 +29,21 @@ namespace graphene { namespace bookie { using namespace chain; -enum bookie_object_type -{ - persistent_event_object_type, - persistent_betting_market_group_object_type, - persistent_betting_market_object_type, - persistent_bet_object_type, - BOOKIE_OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types -}; - namespace detail { -class persistent_event_object : public graphene::db::abstract_object +/** + * @brief This secondary index will allow a reverse lookup of all events that happened + */ +class persistent_event_index : public secondary_index { - public: - static const uint8_t space_id = bookie_objects; - static const uint8_t type_id = persistent_event_object_type; +public: + virtual void object_inserted( const object& obj ) override; + virtual void object_modified( const object& after ) override; - event_object ephemeral_event_object; - - event_id_type get_event_id() const { return ephemeral_event_object.id; } + map< event_id_type, event_object > ephemeral_event_object; }; -typedef object_id persistent_event_id_type; - -struct by_event_id; -typedef multi_index_container< - persistent_event_object, - indexed_by< - ordered_unique, member >, - ordered_unique, const_mem_fun > > > persistent_event_multi_index_type; -typedef generic_index persistent_event_index; - #if 0 // we no longer have competitors, just leaving this here as an example of how to do a secondary index class events_by_competitor_index : public secondary_index { @@ -101,95 +83,118 @@ void events_by_competitor_index::object_modified( const object& after ) } #endif -//////////// betting_market_group_object ////////////////// -class persistent_betting_market_group_object : public graphene::db::abstract_object +/** + * @brief This secondary index will allow a reverse lookup of all betting_market_group that happened + */ +class persistent_betting_market_group_index : public secondary_index { - public: - static const uint8_t space_id = bookie_objects; - static const uint8_t type_id = persistent_betting_market_group_object_type; +public: + struct internal_type + { + internal_type(const betting_market_group_object& other) + : ephemeral_betting_market_group_object{other} + {} + + internal_type& operator=(const betting_market_group_object& other) + { + ephemeral_betting_market_group_object = other; + return *this; + } + + friend bool operator==(const internal_type& lhs, const internal_type& rhs); + friend bool operator<(const internal_type& lhs, const internal_type& rhs); + friend bool operator>(const internal_type& lhs, const internal_type& rhs); betting_market_group_object ephemeral_betting_market_group_object; - share_type total_matched_bets_amount; + }; - betting_market_group_id_type get_betting_market_group_id() const { return ephemeral_betting_market_group_object.id; } +public: + virtual void object_inserted( const object& obj ) override; + virtual void object_modified( const object& after ) override; + + map< betting_market_group_id_type, internal_type > internal; }; -struct by_betting_market_group_id; -typedef multi_index_container< - persistent_betting_market_group_object, - indexed_by< - ordered_unique, member >, - ordered_unique, const_mem_fun > > > persistent_betting_market_group_multi_index_type; - -typedef generic_index persistent_betting_market_group_index; - -//////////// betting_market_object ////////////////// -class persistent_betting_market_object : public graphene::db::abstract_object +inline bool operator==(const persistent_betting_market_group_index::internal_type& lhs, const persistent_betting_market_group_index::internal_type& rhs) { - public: - static const uint8_t space_id = bookie_objects; - static const uint8_t type_id = persistent_betting_market_object_type; + return lhs.ephemeral_betting_market_group_object == rhs.ephemeral_betting_market_group_object; +} - betting_market_object ephemeral_betting_market_object; +inline bool operator<(const persistent_betting_market_group_index::internal_type& lhs, const persistent_betting_market_group_index::internal_type& rhs) +{ + return lhs.ephemeral_betting_market_group_object < rhs.ephemeral_betting_market_group_object; +} - share_type total_matched_bets_amount; +inline bool operator>(const persistent_betting_market_group_index::internal_type& lhs, const persistent_betting_market_group_index::internal_type& rhs) +{ + return !operator<(lhs, rhs); +} - betting_market_id_type get_betting_market_id() const { return ephemeral_betting_market_object.id; } +/** + * @brief This secondary index will allow a reverse lookup of all betting_market_object that happened + */ +class persistent_betting_market_index : public secondary_index +{ +public: + virtual void object_inserted( const object& obj ) override; + virtual void object_modified( const object& after ) override; + + map< betting_market_id_type, betting_market_object > ephemeral_betting_market_object; }; -struct by_betting_market_id; -typedef multi_index_container< - persistent_betting_market_object, - indexed_by< - ordered_unique, member >, - ordered_unique, const_mem_fun > > > persistent_betting_market_multi_index_type; - -typedef generic_index persistent_betting_market_index; - -//////////// bet_object ////////////////// -class persistent_bet_object : public graphene::db::abstract_object +/** + * @brief This secondary index will allow a reverse lookup of all bet_object that happened + */ +class persistent_bet_index : public secondary_index { - public: - static const uint8_t space_id = bookie_objects; - static const uint8_t type_id = persistent_bet_object_type; +public: + struct internal_type + { + internal_type(const bet_object& other) + : ephemeral_bet_object{other} + {} - bet_object ephemeral_bet_object; + internal_type& operator=(const bet_object& other) + { + ephemeral_bet_object = other; + return *this; + } - // total amount of the bet that matched - share_type amount_matched; - - std::vector associated_operations; - - bet_id_type get_bet_id() const { return ephemeral_bet_object.id; } account_id_type get_bettor_id() const { return ephemeral_bet_object.bettor_id; } bool is_matched() const { return amount_matched != share_type(); } + + friend bool operator==(const internal_type& lhs, const internal_type& rhs); + friend bool operator<(const internal_type& lhs, const internal_type& rhs); + friend bool operator>(const internal_type& lhs, const internal_type& rhs); + + bet_object ephemeral_bet_object; + // total amount of the bet that matched + share_type amount_matched; + std::vector associated_operations; + }; + +public: + virtual void object_inserted( const object& obj ) override; + virtual void object_modified( const object& after ) override; + + map< bet_id_type, internal_type > internal; }; -struct by_bet_id; -struct by_bettor_id; -typedef multi_index_container< - persistent_bet_object, - indexed_by< - ordered_unique, member >, - ordered_unique, const_mem_fun >, - ordered_unique, - composite_key< - persistent_bet_object, - const_mem_fun, - const_mem_fun, - const_mem_fun >, - composite_key_compare< - std::less, - std::less, - std::greater > > > > persistent_bet_multi_index_type; +inline bool operator==(const persistent_bet_index::internal_type& lhs, const persistent_bet_index::internal_type& rhs) +{ + return lhs.ephemeral_bet_object == rhs.ephemeral_bet_object; +} -typedef generic_index persistent_bet_index; +inline bool operator<(const persistent_bet_index::internal_type& lhs, const persistent_bet_index::internal_type& rhs) +{ + return lhs.ephemeral_bet_object < rhs.ephemeral_bet_object; +} + +inline bool operator>(const persistent_bet_index::internal_type& lhs, const persistent_bet_index::internal_type& rhs) +{ + return !operator<(lhs, rhs); +} } } } //graphene::bookie::detail -FC_REFLECT_DERIVED( graphene::bookie::detail::persistent_event_object, (graphene::db::object), (ephemeral_event_object) ) -FC_REFLECT_DERIVED( graphene::bookie::detail::persistent_betting_market_group_object, (graphene::db::object), (ephemeral_betting_market_group_object)(total_matched_bets_amount) ) -FC_REFLECT_DERIVED( graphene::bookie::detail::persistent_betting_market_object, (graphene::db::object), (ephemeral_betting_market_object) ) -FC_REFLECT_DERIVED( graphene::bookie::detail::persistent_bet_object, (graphene::db::object), (ephemeral_bet_object)(amount_matched)(associated_operations) ) - -- 2.45.2 From 2cb470537446ddd0096e87d566b15db22b9c62f6 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Tue, 22 Feb 2022 08:23:32 +0300 Subject: [PATCH 09/17] #235 Assign new value to secondary index if it is already exists --- libraries/plugins/bookie/bookie_api.cpp | 1 + libraries/plugins/bookie/bookie_plugin.cpp | 21 +++++++++++++++---- .../graphene/bookie/bookie_objects.hpp | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libraries/plugins/bookie/bookie_api.cpp b/libraries/plugins/bookie/bookie_api.cpp index 98bd2d23..fd8b999e 100644 --- a/libraries/plugins/bookie/bookie_api.cpp +++ b/libraries/plugins/bookie/bookie_api.cpp @@ -171,6 +171,7 @@ fc::variants bookie_api_impl::get_objects(const vector& ids) con const auto &idx = db->get_index_type(); const auto &aidx = dynamic_cast(idx); const auto &refs = aidx.get_secondary_index(); + auto tmp = id.as(); auto iter = refs.internal.find(id.as()); if (iter != refs.internal.end()) return iter->second.ephemeral_bet_object.to_variant(); diff --git a/libraries/plugins/bookie/bookie_plugin.cpp b/libraries/plugins/bookie/bookie_plugin.cpp index 93b24c39..4e9a7710 100644 --- a/libraries/plugins/bookie/bookie_plugin.cpp +++ b/libraries/plugins/bookie/bookie_plugin.cpp @@ -63,7 +63,10 @@ namespace detail void persistent_bet_index::object_inserted(const object& obj) { const bet_object& bet_obj = *boost::polymorphic_downcast(&obj); - internal.insert( {bet_obj.id, bet_obj} ); + if(0 == internal.count(bet_obj.id)) + internal.insert( {bet_obj.id, bet_obj} ); + else + internal[bet_obj.id] = bet_obj; } void persistent_bet_index::object_modified(const object& after) { @@ -79,7 +82,11 @@ void persistent_bet_index::object_modified(const object& after) void persistent_betting_market_index::object_inserted(const object& obj) { const betting_market_object& betting_market_obj = *boost::polymorphic_downcast(&obj); - ephemeral_betting_market_object.insert( {betting_market_obj.id, betting_market_obj} ); + if(0 == ephemeral_betting_market_object.count(betting_market_obj.id)) + ephemeral_betting_market_object.insert( {betting_market_obj.id, betting_market_obj} ); + else + ephemeral_betting_market_object[betting_market_obj.id] = betting_market_obj; + } void persistent_betting_market_index::object_modified(const object& after) { @@ -95,7 +102,10 @@ void persistent_betting_market_index::object_modified(const object& after) void persistent_betting_market_group_index::object_inserted(const object& obj) { const betting_market_group_object& betting_market_group_obj = *boost::polymorphic_downcast(&obj); - internal.insert( {betting_market_group_obj.id, betting_market_group_obj} ); + if(0 == internal.count(betting_market_group_obj.id)) + internal.insert( {betting_market_group_obj.id, betting_market_group_obj} ); + else + internal[betting_market_group_obj.id] = betting_market_group_obj; } void persistent_betting_market_group_index::object_modified(const object& after) { @@ -111,7 +121,10 @@ void persistent_betting_market_group_index::object_modified(const object& after) void persistent_event_index::object_inserted(const object& obj) { const event_object& event_obj = *boost::polymorphic_downcast(&obj); - ephemeral_event_object.insert( {event_obj.id, event_obj} ); + if(0 == ephemeral_event_object.count(event_obj.id)) + ephemeral_event_object.insert( {event_obj.id, event_obj} ); + else + ephemeral_event_object[event_obj.id] = event_obj; } void persistent_event_index::object_modified(const object& after) { diff --git a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp index b234709d..8ec58bd6 100644 --- a/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp +++ b/libraries/plugins/bookie/include/graphene/bookie/bookie_objects.hpp @@ -91,6 +91,8 @@ class persistent_betting_market_group_index : public secondary_index public: struct internal_type { + internal_type() = default; + internal_type(const betting_market_group_object& other) : ephemeral_betting_market_group_object{other} {} @@ -151,6 +153,8 @@ class persistent_bet_index : public secondary_index public: struct internal_type { + internal_type() = default; + internal_type(const bet_object& other) : ephemeral_bet_object{other} {} -- 2.45.2 From a685a63453abc2312dafa1758c0ddb8779f2b9a2 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Tue, 22 Feb 2022 16:07:35 +0300 Subject: [PATCH 10/17] #235 Delete temp obj --- libraries/plugins/bookie/bookie_api.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/plugins/bookie/bookie_api.cpp b/libraries/plugins/bookie/bookie_api.cpp index fd8b999e..98bd2d23 100644 --- a/libraries/plugins/bookie/bookie_api.cpp +++ b/libraries/plugins/bookie/bookie_api.cpp @@ -171,7 +171,6 @@ fc::variants bookie_api_impl::get_objects(const vector& ids) con const auto &idx = db->get_index_type(); const auto &aidx = dynamic_cast(idx); const auto &refs = aidx.get_secondary_index(); - auto tmp = id.as(); auto iter = refs.internal.find(id.as()); if (iter != refs.internal.end()) return iter->second.ephemeral_bet_object.to_variant(); -- 2.45.2 From 6f9c6fa8f089e699de8305793c9ad560e83ca143 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 23 Feb 2022 12:54:09 +0300 Subject: [PATCH 11/17] #235 Add custom funtions for event_object --- libraries/chain/event_object.cpp | 1004 +++++++++-------- .../include/graphene/chain/event_object.hpp | 243 ++-- libraries/chain/small_objects.cpp | 2 - 3 files changed, 700 insertions(+), 549 deletions(-) diff --git a/libraries/chain/event_object.cpp b/libraries/chain/event_object.cpp index d00e1be8..b46d1e7b 100644 --- a/libraries/chain/event_object.cpp +++ b/libraries/chain/event_object.cpp @@ -1,26 +1,26 @@ /* - * Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. - */ +* Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. +*/ #define DEFAULT_LOGGER "betting" #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS @@ -31,510 +31,554 @@ #include #include #include +#include +#include #include namespace graphene { namespace chain { - enum class event_state { - upcoming, - frozen_upcoming, - in_progress, - frozen_in_progress, - finished, - canceled, - settled - }; +enum class event_state { + upcoming, + frozen_upcoming, + in_progress, + frozen_in_progress, + finished, + canceled, + settled +}; } } -FC_REFLECT_ENUM(graphene::chain::event_state, - (upcoming) - (frozen_upcoming) - (in_progress) - (frozen_in_progress) - (finished) - (canceled) - (settled)) +FC_REFLECT_ENUM(graphene::chain::event_state, + (upcoming) + (frozen_upcoming) + (in_progress) + (frozen_in_progress) + (finished) + (canceled) + (settled)) namespace graphene { namespace chain { - namespace msm = boost::msm; - namespace mpl = boost::mpl; +namespace msm = boost::msm; +namespace mpl = boost::mpl; - namespace - { +namespace +{ - // Events -- most events happen when the witnesses publish an event_update operation with a new - // status, so if they publish an event with the status set to `frozen`, we'll generate a `frozen_event` - struct upcoming_event - { - database& db; - upcoming_event(database& db) : db(db) {} - }; - struct in_progress_event - { - database& db; - in_progress_event(database& db) : db(db) {} - }; - struct frozen_event - { - database& db; - frozen_event(database& db) : db(db) {} - }; - struct finished_event - { - database& db; - finished_event(database& db) : db(db) {} - }; - struct canceled_event - { - database& db; - canceled_event(database& db) : db(db) {} - }; +// Events -- most events happen when the witnesses publish an event_update operation with a new +// status, so if they publish an event with the status set to `frozen`, we'll generate a `frozen_event` +struct upcoming_event +{ + database& db; + upcoming_event(database& db) : db(db) {} +}; +struct in_progress_event +{ + database& db; + in_progress_event(database& db) : db(db) {} +}; +struct frozen_event +{ + database& db; + frozen_event(database& db) : db(db) {} +}; +struct finished_event +{ + database& db; + finished_event(database& db) : db(db) {} +}; +struct canceled_event +{ + database& db; + canceled_event(database& db) : db(db) {} +}; - // event triggered when a betting market group in this event is resolved, - // when we get this, check and see if all betting market groups are now - // canceled/settled; if so, transition the event to canceled/settled, - // otherwise remain in the current state - struct betting_market_group_resolved_event - { - database& db; - betting_market_group_id_type resolved_group; - bool was_canceled; - betting_market_group_resolved_event(database& db, betting_market_group_id_type resolved_group, bool was_canceled) : db(db), resolved_group(resolved_group), was_canceled(was_canceled) {} - }; +// event triggered when a betting market group in this event is resolved, +// when we get this, check and see if all betting market groups are now +// canceled/settled; if so, transition the event to canceled/settled, +// otherwise remain in the current state +struct betting_market_group_resolved_event +{ + database& db; + betting_market_group_id_type resolved_group; + bool was_canceled; + betting_market_group_resolved_event(database& db, betting_market_group_id_type resolved_group, bool was_canceled) : db(db), resolved_group(resolved_group), was_canceled(was_canceled) {} +}; - // event triggered when a betting market group is closed. When we get this, - // if all child betting market groups are closed, transition to finished - struct betting_market_group_closed_event - { - database& db; - betting_market_group_id_type closed_group; - betting_market_group_closed_event(database& db, betting_market_group_id_type closed_group) : db(db), closed_group(closed_group) {} - }; +// event triggered when a betting market group is closed. When we get this, +// if all child betting market groups are closed, transition to finished +struct betting_market_group_closed_event +{ + database& db; + betting_market_group_id_type closed_group; + betting_market_group_closed_event(database& db, betting_market_group_id_type closed_group) : db(db), closed_group(closed_group) {} +}; - // Events - struct event_state_machine_ : public msm::front::state_machine_def +// Events +struct event_state_machine_ : public msm::front::state_machine_def - { - // disable a few state machine features we don't use for performance - typedef int no_exception_thrown; - typedef int no_message_queue; +{ + // disable a few state machine features we don't use for performance + typedef int no_exception_thrown; + typedef int no_message_queue; - // States - struct upcoming : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - void on_entry(const upcoming_event& event, event_state_machine_& fsm) { - dlog("event ${id} -> upcoming", ("id", fsm.event_obj->id)); - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_upcoming_event(event.db); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't freeze the group. just ignore the exception - } - } - }; - struct in_progress : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - void on_entry(const in_progress_event& event, event_state_machine_& fsm) { - dlog("event ${id} -> in_progress", ("id", fsm.event_obj->id)); - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_in_play_event(event.db); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't freeze the group. just ignore the exception - } - } - }; - struct frozen_upcoming : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> frozen_upcoming", ("id", fsm.event_obj->id)); - } - }; - struct frozen_in_progress : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> frozen_in_progress", ("id", fsm.event_obj->id)); - } - }; - struct finished : public msm::front::state<> { - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> finished", ("id", fsm.event_obj->id)); - } - }; - struct settled : public msm::front::state<>{ - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> settled", ("id", fsm.event_obj->id)); - } - }; - struct canceled : public msm::front::state<> { - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> canceled", ("id", fsm.event_obj->id)); - } - }; + // States + struct upcoming : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + void on_entry(const upcoming_event& event, event_state_machine_& fsm) { + dlog("event ${id} -> upcoming", ("id", fsm.event_obj->id)); + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_upcoming_event(event.db); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't freeze the group. just ignore the exception + } + } + }; + struct in_progress : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + void on_entry(const in_progress_event& event, event_state_machine_& fsm) { + dlog("event ${id} -> in_progress", ("id", fsm.event_obj->id)); + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_in_play_event(event.db); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't freeze the group. just ignore the exception + } + } + }; + struct frozen_upcoming : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> frozen_upcoming", ("id", fsm.event_obj->id)); + } + }; + struct frozen_in_progress : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> frozen_in_progress", ("id", fsm.event_obj->id)); + } + }; + struct finished : public msm::front::state<> { + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> finished", ("id", fsm.event_obj->id)); + } + }; + struct settled : public msm::front::state<>{ + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> settled", ("id", fsm.event_obj->id)); + } + }; + struct canceled : public msm::front::state<> { + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> canceled", ("id", fsm.event_obj->id)); + } + }; - // actions - void record_whether_group_settled_or_canceled(const betting_market_group_resolved_event& event) { - if (!event.was_canceled) - event_obj->at_least_one_betting_market_group_settled = true; - } + // actions + void record_whether_group_settled_or_canceled(const betting_market_group_resolved_event& event) { + if (!event.was_canceled) + event_obj->at_least_one_betting_market_group_settled = true; + } - void freeze_betting_market_groups(const frozen_event& event) { - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - { - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_frozen_event(event.db); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't freeze the group. just ignore the exception - } - } - } + void freeze_betting_market_groups(const frozen_event& event) { + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + { + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_frozen_event(event.db); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't freeze the group. just ignore the exception + } + } + } - void close_all_betting_market_groups(const finished_event& event) { - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - { - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_closed_event(event.db, true); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't close the group. just ignore the exception - } - } - } + void close_all_betting_market_groups(const finished_event& event) { + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + { + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_closed_event(event.db, true); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't close the group. just ignore the exception + } + } + } - void cancel_all_betting_market_groups(const canceled_event& event) { - auto& betting_market_group_index = event.db.template get_index_type().indices().template get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_canceled_event(event.db, true); - }); - } + void cancel_all_betting_market_groups(const canceled_event& event) { + auto& betting_market_group_index = event.db.template get_index_type().indices().template get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_canceled_event(event.db, true); + }); + } - // Guards - bool all_betting_market_groups_are_closed(const betting_market_group_closed_event& event) - { - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - if (betting_market_group.id != event.closed_group) - { - betting_market_group_status status = betting_market_group.get_status(); - if (status != betting_market_group_status::closed && - status != betting_market_group_status::graded && - status != betting_market_group_status::re_grading && - status != betting_market_group_status::settled && - status != betting_market_group_status::canceled) - return false; - } - return true; - } + // Guards + bool all_betting_market_groups_are_closed(const betting_market_group_closed_event& event) + { + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + if (betting_market_group.id != event.closed_group) + { + betting_market_group_status status = betting_market_group.get_status(); + if (status != betting_market_group_status::closed && + status != betting_market_group_status::graded && + status != betting_market_group_status::re_grading && + status != betting_market_group_status::settled && + status != betting_market_group_status::canceled) + return false; + } + return true; + } - bool all_betting_market_groups_are_canceled(const betting_market_group_resolved_event& event) - { - // if the bmg that just resolved was settled, obviously all didn't cancel - if (!event.was_canceled) - return false; - // if a previously-resolved group was settled, all didn't cancel - if (event_obj->at_least_one_betting_market_group_settled) - return false; - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - if (betting_market_group.id != event.resolved_group) - if (betting_market_group.get_status() != betting_market_group_status::canceled) - return false; - return true; - } + bool all_betting_market_groups_are_canceled(const betting_market_group_resolved_event& event) + { + // if the bmg that just resolved was settled, obviously all didn't cancel + if (!event.was_canceled) + return false; + // if a previously-resolved group was settled, all didn't cancel + if (event_obj->at_least_one_betting_market_group_settled) + return false; + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + if (betting_market_group.id != event.resolved_group) + if (betting_market_group.get_status() != betting_market_group_status::canceled) + return false; + return true; + } - bool all_betting_market_groups_are_resolved(const betting_market_group_resolved_event& event) - { - if (!event.was_canceled) - event_obj->at_least_one_betting_market_group_settled = true; + bool all_betting_market_groups_are_resolved(const betting_market_group_resolved_event& event) + { + if (!event.was_canceled) + event_obj->at_least_one_betting_market_group_settled = true; - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) { - if (betting_market_group.id != event.resolved_group) { - betting_market_group_status status = betting_market_group.get_status(); - if (status != betting_market_group_status::canceled && status != betting_market_group_status::settled) - return false; - } - } - return true; - } + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) { + if (betting_market_group.id != event.resolved_group) { + betting_market_group_status status = betting_market_group.get_status(); + if (status != betting_market_group_status::canceled && status != betting_market_group_status::settled) + return false; + } + } + return true; + } - typedef upcoming initial_state; - typedef event_state_machine_ x; // makes transition table cleaner + typedef upcoming initial_state; + typedef event_state_machine_ x; // makes transition table cleaner - // Transition table for tournament - struct transition_table : mpl::vector< - // Start Event Next Action Guard - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - _row < upcoming, in_progress_event, in_progress >, - a_row< upcoming, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< upcoming, frozen_event, frozen_upcoming, &x::freeze_betting_market_groups >, - a_row< upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< upcoming, betting_market_group_resolved_event,upcoming, &x::record_whether_group_settled_or_canceled >, - g_row< upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - _row < frozen_upcoming, upcoming_event, upcoming >, - _row < frozen_upcoming, in_progress_event, in_progress >, - a_row< frozen_upcoming, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< frozen_upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< frozen_upcoming, betting_market_group_resolved_event,frozen_upcoming, &x::record_whether_group_settled_or_canceled >, - g_row< frozen_upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - a_row< in_progress, frozen_event, frozen_in_progress, &x::freeze_betting_market_groups >, - a_row< in_progress, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< in_progress, betting_market_group_resolved_event,in_progress, &x::record_whether_group_settled_or_canceled >, - g_row< in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - _row < frozen_in_progress, in_progress_event, in_progress >, - a_row< frozen_in_progress, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< frozen_in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< frozen_in_progress, betting_market_group_resolved_event,frozen_in_progress, &x::record_whether_group_settled_or_canceled >, - g_row< frozen_in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - a_row< finished, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - g_row< finished, betting_market_group_resolved_event,settled, &x::all_betting_market_groups_are_resolved >, - g_row< finished, betting_market_group_resolved_event,canceled, &x::all_betting_market_groups_are_canceled > - > {}; + // Transition table for tournament + struct transition_table : mpl::vector< + // Start Event Next Action Guard + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + _row < upcoming, in_progress_event, in_progress >, + a_row< upcoming, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< upcoming, frozen_event, frozen_upcoming, &x::freeze_betting_market_groups >, + a_row< upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< upcoming, betting_market_group_resolved_event,upcoming, &x::record_whether_group_settled_or_canceled >, + g_row< upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + _row < frozen_upcoming, upcoming_event, upcoming >, + _row < frozen_upcoming, in_progress_event, in_progress >, + a_row< frozen_upcoming, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< frozen_upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< frozen_upcoming, betting_market_group_resolved_event,frozen_upcoming, &x::record_whether_group_settled_or_canceled >, + g_row< frozen_upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + a_row< in_progress, frozen_event, frozen_in_progress, &x::freeze_betting_market_groups >, + a_row< in_progress, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< in_progress, betting_market_group_resolved_event,in_progress, &x::record_whether_group_settled_or_canceled >, + g_row< in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + _row < frozen_in_progress, in_progress_event, in_progress >, + a_row< frozen_in_progress, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< frozen_in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< frozen_in_progress, betting_market_group_resolved_event,frozen_in_progress, &x::record_whether_group_settled_or_canceled >, + g_row< frozen_in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + a_row< finished, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + g_row< finished, betting_market_group_resolved_event,settled, &x::all_betting_market_groups_are_resolved >, + g_row< finished, betting_market_group_resolved_event,canceled, &x::all_betting_market_groups_are_canceled > + > {}; - template - void no_transition(Event const& e, Fsm&, int state) - { - FC_THROW_EXCEPTION(graphene::chain::no_transition, "No transition"); - } - - template - void no_transition(canceled_event const& e, Fsm&, int state) - { - //ignore transitions from settled to canceled state - //and from canceled to canceled state - } + template + void no_transition(Event const& e, Fsm&, int state) + { + FC_THROW_EXCEPTION(graphene::chain::no_transition, "No transition"); + } - event_object* event_obj; - event_state_machine_(event_object* event_obj) : event_obj(event_obj) {} - }; - typedef msm::back::state_machine event_state_machine; + template + void no_transition(canceled_event const& e, Fsm&, int state) + { + //ignore transitions from settled to canceled state + //and from canceled to canceled state + } - } // end anonymous namespace + event_object* event_obj; + event_state_machine_(event_object* event_obj) : event_obj(event_obj) {} +}; +typedef msm::back::state_machine event_state_machine; - class event_object::impl { - public: - event_state_machine state_machine; +} // end anonymous namespace - impl(event_object* self) : state_machine(self) {} - }; +class event_object::impl { +public: + event_state_machine state_machine; - event_object::event_object() : - at_least_one_betting_market_group_settled(false), - my(new impl(this)) - { - } + impl(event_object* self) : state_machine(self) {} +}; - event_object::event_object(const event_object& rhs) : - graphene::db::abstract_object(rhs), - name(rhs.name), - season(rhs.season), - start_time(rhs.start_time), - event_group_id(rhs.event_group_id), - at_least_one_betting_market_group_settled(rhs.at_least_one_betting_market_group_settled), - scores(rhs.scores), - my(new impl(this)) - { - my->state_machine = rhs.my->state_machine; - my->state_machine.event_obj = this; - } +event_object::event_object() : + at_least_one_betting_market_group_settled(false), + my(new impl(this)) +{ +} - event_object& event_object::operator=(const event_object& rhs) - { - //graphene::db::abstract_object::operator=(rhs); - id = rhs.id; - name = rhs.name; - season = rhs.season; - start_time = rhs.start_time; - event_group_id = rhs.event_group_id; - at_least_one_betting_market_group_settled = rhs.at_least_one_betting_market_group_settled; - scores = rhs.scores; +event_object::event_object(const event_object& rhs) : + graphene::db::abstract_object(rhs), + name(rhs.name), + season(rhs.season), + start_time(rhs.start_time), + event_group_id(rhs.event_group_id), + at_least_one_betting_market_group_settled(rhs.at_least_one_betting_market_group_settled), + scores(rhs.scores), + my(new impl(this)) +{ + my->state_machine = rhs.my->state_machine; + my->state_machine.event_obj = this; +} - my->state_machine = rhs.my->state_machine; - my->state_machine.event_obj = this; +event_object& event_object::operator=(const event_object& rhs) +{ + //graphene::db::abstract_object::operator=(rhs); + id = rhs.id; + name = rhs.name; + season = rhs.season; + start_time = rhs.start_time; + event_group_id = rhs.event_group_id; + at_least_one_betting_market_group_settled = rhs.at_least_one_betting_market_group_settled; + scores = rhs.scores; - return *this; - } + my->state_machine = rhs.my->state_machine; + my->state_machine.event_obj = this; - event_object::~event_object() - { - } + return *this; +} - namespace { - - bool verify_event_status_constants() - { - unsigned error_count = 0; - typedef msm::back::generate_state_set::type all_states; - static char const* filled_state_names[mpl::size::value]; - mpl::for_each > - (msm::back::fill_state_names(filled_state_names)); - for (unsigned i = 0; i < mpl::size::value; ++i) - { - try - { - // this is an approximate test, the state name provided by typeinfo will be mangled, but should - // at least contain the string we're looking for - const char* fc_reflected_value_name = fc::reflector::to_string((event_state)i); - if (!strstr(filled_state_names[i], fc_reflected_value_name)) - { - fc_elog(fc::logger::get("default"), - "Error, state string mismatch between fc and boost::msm for int value ${int_value}: boost::msm -> ${boost_string}, fc::reflect -> ${fc_string}", - ("int_value", i)("boost_string", filled_state_names[i])("fc_string", fc_reflected_value_name)); - ++error_count; - } - } - catch (const fc::bad_cast_exception&) - { - fc_elog(fc::logger::get("default"), - "Error, no reflection for value ${int_value} in enum event_status", - ("int_value", i)); - ++error_count; - } - } - if (error_count == 0) - dlog("Event status constants are correct"); - else - wlog("There were ${count} errors in the event status constants", ("count", error_count)); - - return error_count == 0; - } - } // end anonymous namespace - - event_status event_object::get_status() const - { - static bool state_constants_are_correct = verify_event_status_constants(); - (void)&state_constants_are_correct; - event_state state = (event_state)my->state_machine.current_state()[0]; - - ddump((state)); - - switch (state) - { - case event_state::upcoming: - return event_status::upcoming; - case event_state::frozen_upcoming: - case event_state::frozen_in_progress: - return event_status::frozen; - case event_state::in_progress: - return event_status::in_progress; - case event_state::finished: - return event_status::finished; - case event_state::canceled: - return event_status::canceled; - case event_state::settled: - return event_status::settled; - default: - FC_THROW("Unexpected event state"); - }; - } +event_object::~event_object() +{ +} - void event_object::on_upcoming_event(database& db) - { - my->state_machine.process_event(upcoming_event(db)); - } +namespace { - void event_object::on_in_progress_event(database& db) - { - my->state_machine.process_event(in_progress_event(db)); - } +bool verify_event_status_constants() +{ + unsigned error_count = 0; + typedef msm::back::generate_state_set::type all_states; + static char const* filled_state_names[mpl::size::value]; + mpl::for_each > + (msm::back::fill_state_names(filled_state_names)); + for (unsigned i = 0; i < mpl::size::value; ++i) + { + try + { + // this is an approximate test, the state name provided by typeinfo will be mangled, but should + // at least contain the string we're looking for + const char* fc_reflected_value_name = fc::reflector::to_string((event_state)i); + if (!strstr(filled_state_names[i], fc_reflected_value_name)) + { + fc_elog(fc::logger::get("default"), + "Error, state string mismatch between fc and boost::msm for int value ${int_value}: boost::msm -> ${boost_string}, fc::reflect -> ${fc_string}", + ("int_value", i)("boost_string", filled_state_names[i])("fc_string", fc_reflected_value_name)); + ++error_count; + } + } + catch (const fc::bad_cast_exception&) + { + fc_elog(fc::logger::get("default"), + "Error, no reflection for value ${int_value} in enum event_status", + ("int_value", i)); + ++error_count; + } + } + if (error_count == 0) + dlog("Event status constants are correct"); + else + wlog("There were ${count} errors in the event status constants", ("count", error_count)); - void event_object::on_frozen_event(database& db) - { - my->state_machine.process_event(frozen_event(db)); - } + return error_count == 0; +} +} // end anonymous namespace - void event_object::on_finished_event(database& db) - { - my->state_machine.process_event(finished_event(db)); - } +event_status event_object::get_status() const +{ + static bool state_constants_are_correct = verify_event_status_constants(); + (void)&state_constants_are_correct; + event_state state = (event_state)my->state_machine.current_state()[0]; - void event_object::on_canceled_event(database& db) - { - my->state_machine.process_event(canceled_event(db)); - } + ddump((state)); - void event_object::on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled) - { - my->state_machine.process_event(betting_market_group_resolved_event(db, resolved_group, was_canceled)); - } + switch (state) + { + case event_state::upcoming: + return event_status::upcoming; + case event_state::frozen_upcoming: + case event_state::frozen_in_progress: + return event_status::frozen; + case event_state::in_progress: + return event_status::in_progress; + case event_state::finished: + return event_status::finished; + case event_state::canceled: + return event_status::canceled; + case event_state::settled: + return event_status::settled; + default: + FC_THROW("Unexpected event state"); + }; +} - void event_object::on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group) - { - my->state_machine.process_event(betting_market_group_closed_event(db, closed_group)); - } +void event_object::pack_impl(std::ostream& stream) const +{ + boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + oa << my->state_machine; +} - // These are the only statuses that can be explicitly set by witness operations. The missing - // status, 'settled', is automatically set when all of the betting market groups have - // settled/canceled - void event_object::dispatch_new_status(database& db, event_status new_status) - { - switch (new_status) { - case event_status::upcoming: // by witnesses to unfreeze a frozen event - on_upcoming_event(db); - break; - case event_status::in_progress: // by witnesses when the event starts - on_in_progress_event(db); - break; - case event_status::frozen: // by witnesses when the event needs to be frozen - on_frozen_event(db); - break; - case event_status::finished: // by witnesses when the event is complete - on_finished_event(db); - break; - case event_status::canceled: // by witnesses to cancel the event - on_canceled_event(db); - break; - default: - FC_THROW("Status ${new_status} cannot be explicitly set", ("new_status", new_status)); - } - } +void event_object::unpack_impl(std::istream& stream) +{ + boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + ia >> my->state_machine; +} + +void event_object::on_upcoming_event(database& db) +{ + my->state_machine.process_event(upcoming_event(db)); +} + +void event_object::on_in_progress_event(database& db) +{ + my->state_machine.process_event(in_progress_event(db)); +} + +void event_object::on_frozen_event(database& db) +{ + my->state_machine.process_event(frozen_event(db)); +} + +void event_object::on_finished_event(database& db) +{ + my->state_machine.process_event(finished_event(db)); +} + +void event_object::on_canceled_event(database& db) +{ + my->state_machine.process_event(canceled_event(db)); +} + +void event_object::on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled) +{ + my->state_machine.process_event(betting_market_group_resolved_event(db, resolved_group, was_canceled)); +} + +void event_object::on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group) +{ + my->state_machine.process_event(betting_market_group_closed_event(db, closed_group)); +} + +// These are the only statuses that can be explicitly set by witness operations. The missing +// status, 'settled', is automatically set when all of the betting market groups have +// settled/canceled +void event_object::dispatch_new_status(database& db, event_status new_status) +{ + switch (new_status) { + case event_status::upcoming: // by witnesses to unfreeze a frozen event + on_upcoming_event(db); + break; + case event_status::in_progress: // by witnesses when the event starts + on_in_progress_event(db); + break; + case event_status::frozen: // by witnesses when the event needs to be frozen + on_frozen_event(db); + break; + case event_status::finished: // by witnesses when the event is complete + on_finished_event(db); + break; + case event_status::canceled: // by witnesses to cancel the event + on_canceled_event(db); + break; + default: + FC_THROW("Status ${new_status} cannot be explicitly set", ("new_status", new_status)); + } +} } } // graphene::chain +namespace fc { +// Manually reflect event_object to variant to properly reflect "state" +void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth) +{ + fc::mutable_variant_object o; + o("id", fc::variant(event_obj.id, max_depth)) + ("name", fc::variant(event_obj.name, max_depth)) + ("season", fc::variant(event_obj.season, max_depth)) + ("start_time", fc::variant(event_obj.start_time, max_depth)) + ("event_group_id", fc::variant(event_obj.event_group_id, max_depth)) + ("scores", fc::variant(event_obj.scores, max_depth)) + ("status", fc::variant(event_obj.get_status(), max_depth)); + + v = o; +} + +// Manually reflect event_object to variant to properly reflect "state" +void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth) +{ + event_obj.id = v["id"].as( max_depth ); + event_obj.name = v["name"].as( max_depth ); + event_obj.season = v["season"].as( max_depth ); + event_obj.start_time = v["start_time"].as >( max_depth ); + event_obj.event_group_id = v["event_group_id"].as( max_depth ); + event_obj.scores = v["scores"].as>( max_depth ); + graphene::chain::event_status status = v["status"].as( max_depth ); + const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; +} +} //end namespace fc + diff --git a/libraries/chain/include/graphene/chain/event_object.hpp b/libraries/chain/include/graphene/chain/event_object.hpp index 199f38af..30c6d5ca 100644 --- a/libraries/chain/include/graphene/chain/event_object.hpp +++ b/libraries/chain/include/graphene/chain/event_object.hpp @@ -1,101 +1,210 @@ /* - * Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. - */ +* Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. +*/ #pragma once #include -#include #include #include +#include +#include #include +namespace graphene { namespace chain { +class event_object; +} } + +namespace fc { +void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth = 1); +void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth = 1); +} //end namespace fc + namespace graphene { namespace chain { class database; class event_object : public graphene::db::abstract_object< event_object > { - public: - static const uint8_t space_id = protocol_ids; - static const uint8_t type_id = event_object_type; +public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = event_object_type; - event_object(); - event_object(const event_object& rhs); - ~event_object(); - event_object& operator=(const event_object& rhs); + event_object(); + event_object(const event_object& rhs); + ~event_object(); + event_object& operator=(const event_object& rhs); - internationalized_string_type name; - - internationalized_string_type season; + internationalized_string_type name; - optional start_time; + internationalized_string_type season; - event_group_id_type event_group_id; + optional start_time; - bool at_least_one_betting_market_group_settled; + event_group_id_type event_group_id; - event_status get_status() const; - vector scores; + bool at_least_one_betting_market_group_settled; - void on_upcoming_event(database& db); - void on_in_progress_event(database& db); - void on_frozen_event(database& db); - void on_finished_event(database& db); - void on_canceled_event(database& db); - void on_settled_event(database& db); - void on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled); - void on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group); - void dispatch_new_status(database& db, event_status new_status); - private: - class impl; - std::unique_ptr my; + event_status get_status() const; + vector scores; + + // serialization functions: + // for serializing to raw, go through a temporary sstream object to avoid + // having to implement serialization in the header file + template + friend Stream& operator<<( Stream& s, const event_object& event_obj ); + + template + friend Stream& operator>>( Stream& s, event_object& event_obj ); + + friend void ::fc::to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth); + friend void ::fc::from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth); + + void pack_impl(std::ostream& stream) const; + void unpack_impl(std::istream& stream); + + void on_upcoming_event(database& db); + void on_in_progress_event(database& db); + void on_frozen_event(database& db); + void on_finished_event(database& db); + void on_canceled_event(database& db); + void on_settled_event(database& db); + void on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled); + void on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group); + void dispatch_new_status(database& db, event_status new_status); +private: + class impl; + std::unique_ptr my; }; struct by_event_group_id; struct by_event_status; typedef multi_index_container< - event_object, - indexed_by< - ordered_unique< tag, member< object, object_id_type, &object::id > >, - ordered_unique< tag, composite_key, - member > >, - ordered_unique< tag, composite_key, - member > > > > event_object_multi_index_type; + event_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, composite_key, + member > >, + ordered_unique< tag, composite_key, + member > > > > event_object_multi_index_type; typedef generic_index event_object_index; + +template +inline Stream& operator<<( Stream& s, const event_object& event_obj ) +{ + fc_elog(fc::logger::get("event"), "In event_obj to_raw"); + // pack all fields exposed in the header in the usual way + // instead of calling the derived pack, just serialize the one field in the base class + // fc::raw::pack >(s, event_obj); + fc::raw::pack(s, event_obj.id); + fc::raw::pack(s, event_obj.name); + fc::raw::pack(s, event_obj.season); + fc::raw::pack(s, event_obj.start_time); + fc::raw::pack(s, event_obj.event_group_id); + fc::raw::pack(s, event_obj.at_least_one_betting_market_group_settled); + fc::raw::pack(s, event_obj.scores); + + // fc::raw::pack the contents hidden in the impl class + std::ostringstream stream; + event_obj.pack_impl(stream); + std::string stringified_stream(stream.str()); + fc::raw::pack(s, stream.str()); + + return s; +} +template +inline Stream& operator>>( Stream& s, event_object& event_obj ) +{ + fc_elog(fc::logger::get("event"), "In event_obj from_raw"); + // unpack all fields exposed in the header in the usual way + //fc::raw::unpack >(s, event_obj); + fc::raw::unpack(s, event_obj.id); + fc::raw::unpack(s, event_obj.name); + fc::raw::unpack(s, event_obj.season); + fc::raw::unpack(s, event_obj.start_time); + fc::raw::unpack(s, event_obj.event_group_id); + fc::raw::unpack(s, event_obj.at_least_one_betting_market_group_settled); + fc::raw::unpack(s, event_obj.scores); + + // fc::raw::unpack the contents hidden in the impl class + std::string stringified_stream; + fc::raw::unpack(s, stringified_stream); + std::istringstream stream(stringified_stream); + event_obj.unpack_impl(stream); + + return s; +} } } // graphene::chain -FC_REFLECT_DERIVED(graphene::chain::event_object, (graphene::db::object), - (name) - (season) - (start_time) - (event_group_id) - (at_least_one_betting_market_group_settled) - (scores)) +namespace fc { -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::event_object ) +template<> +template<> +inline void if_enum::from_variant(const variant &vo, graphene::chain::event_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); +} +template<> +template<> +inline void if_enum::to_variant(const graphene::chain::event_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); +} +namespace raw { namespace detail { + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::event_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::event_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::unpack(fc::datastream &s, graphene::chain::event_object &v, uint32_t) { + s >> v; +} + +} } + +template <> +struct get_typename { + static const char *name() { + return "graphene::chain::event_object"; + } +}; +template <> +struct reflector { + typedef graphene::chain::event_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; +}; +} // namespace fc \ No newline at end of file diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 58c63b80..75a3906f 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -45,7 +45,6 @@ #include #include #include -#include #include #include @@ -79,7 +78,6 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedu GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::game_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::event_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_group_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_object ) -- 2.45.2 From 224eedee394f2c7300c4cc405a3b8ac943bbf87e Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 24 Feb 2022 09:39:51 +0300 Subject: [PATCH 12/17] #235 Add custom funtions for match_object --- .../include/graphene/chain/match_object.hpp | 137 ++++++++++++++++-- libraries/chain/match_object.cpp | 55 +++++++ 2 files changed, 180 insertions(+), 12 deletions(-) diff --git a/libraries/chain/include/graphene/chain/match_object.hpp b/libraries/chain/include/graphene/chain/match_object.hpp index 2f5152cc..e1194e1e 100644 --- a/libraries/chain/include/graphene/chain/match_object.hpp +++ b/libraries/chain/include/graphene/chain/match_object.hpp @@ -1,6 +1,18 @@ #pragma once #include #include +#include +#include + +namespace graphene { namespace chain { +class match_object; +} } + +namespace fc { +void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth = 1); +void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth = 1); +} //end namespace fc + namespace graphene { namespace chain { class database; @@ -61,6 +73,21 @@ namespace graphene { namespace chain { match_state get_state() const; + // serialization functions: + // for serializing to raw, go through a temporary sstream object to avoid + // having to implement serialization in the header file + template + friend Stream& operator<<( Stream& s, const match_object& match_obj ); + + template + friend Stream& operator>>( Stream& s, match_object& match_obj ); + + friend void ::fc::to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth); + friend void ::fc::from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth); + + void pack_impl(std::ostream& stream) const; + void unpack_impl(std::istream& stream); + void on_initiate_match(database& db); void on_game_complete(database& db, const game_object& game); game_id_type start_next_game(database& db, match_id_type match_id); @@ -76,6 +103,56 @@ namespace graphene { namespace chain { > match_object_multi_index_type; typedef generic_index match_index; + template + inline Stream& operator<<( Stream& s, const match_object& match_obj ) + { + // pack all fields exposed in the header in the usual way + // instead of calling the derived pack, just serialize the one field in the base class + // fc::raw::pack >(s, match_obj); + fc::raw::pack(s, match_obj.id); + fc::raw::pack(s, match_obj.tournament_id); + fc::raw::pack(s, match_obj.players); + fc::raw::pack(s, match_obj.games); + fc::raw::pack(s, match_obj.game_winners); + fc::raw::pack(s, match_obj.number_of_wins); + fc::raw::pack(s, match_obj.number_of_ties); + fc::raw::pack(s, match_obj.match_winners); + fc::raw::pack(s, match_obj.start_time); + fc::raw::pack(s, match_obj.end_time); + + // fc::raw::pack the contents hidden in the impl class + std::ostringstream stream; + match_obj.pack_impl(stream); + std::string stringified_stream(stream.str()); + fc::raw::pack(s, stream.str()); + + return s; + } + + template + inline Stream& operator>>( Stream& s, match_object& match_obj ) + { + // unpack all fields exposed in the header in the usual way + //fc::raw::unpack >(s, match_obj); + fc::raw::unpack(s, match_obj.id); + fc::raw::unpack(s, match_obj.tournament_id); + fc::raw::unpack(s, match_obj.players); + fc::raw::unpack(s, match_obj.games); + fc::raw::unpack(s, match_obj.game_winners); + fc::raw::unpack(s, match_obj.number_of_wins); + fc::raw::unpack(s, match_obj.number_of_ties); + fc::raw::unpack(s, match_obj.match_winners); + fc::raw::unpack(s, match_obj.start_time); + fc::raw::unpack(s, match_obj.end_time); + + // fc::raw::unpack the contents hidden in the impl class + std::string stringified_stream; + fc::raw::unpack(s, stringified_stream); + std::istringstream stream(stringified_stream); + match_obj.unpack_impl(stream); + + return s; + } } } FC_REFLECT_ENUM(graphene::chain::match_state, @@ -83,16 +160,52 @@ FC_REFLECT_ENUM(graphene::chain::match_state, (match_in_progress) (match_complete)) -//FC_REFLECT_TYPENAME(graphene::chain::match_object) // manually serialized -FC_REFLECT_DERIVED(graphene::chain::match_object, (graphene::db::object), - (tournament_id) - (players) - (games) - (game_winners) - (number_of_wins) - (number_of_ties) - (match_winners) - (start_time) - (end_time)) +namespace fc { -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::match_object ) \ No newline at end of file +template<> +template<> +inline void if_enum::from_variant(const variant &vo, graphene::chain::match_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); +} + +template<> +template<> +inline void if_enum::to_variant(const graphene::chain::match_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); +} + +namespace raw { namespace detail { + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::match_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::match_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::unpack(fc::datastream &s, graphene::chain::match_object &v, uint32_t) { + s >> v; +} + +} } + +template <> +struct get_typename { + static const char *name() { + return "graphene::chain::match_object"; + } +}; +template <> +struct reflector { + typedef graphene::chain::match_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; +}; +} // namespace fc \ No newline at end of file diff --git a/libraries/chain/match_object.cpp b/libraries/chain/match_object.cpp index c0b75755..46313bff 100644 --- a/libraries/chain/match_object.cpp +++ b/libraries/chain/match_object.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include #include @@ -325,6 +327,18 @@ namespace graphene { namespace chain { return state; } + void match_object::pack_impl(std::ostream& stream) const + { + boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + oa << my->state_machine; + } + + void match_object::unpack_impl(std::istream& stream) + { + boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + ia >> my->state_machine; + } + void match_object::on_initiate_match(database& db) { my->state_machine.process_event(initiate_match(db)); @@ -348,4 +362,45 @@ namespace graphene { namespace chain { } } // graphene::chain +namespace fc { +// Manually reflect match_object to variant to properly reflect "state" +void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth) +{ try { + fc_elog(fc::logger::get("tournament"), "In match_obj to_variant"); + elog("In match_obj to_variant"); + fc::mutable_variant_object o; + o("id", fc::variant(match_obj.id, max_depth)) + ("tournament_id", fc::variant(match_obj.tournament_id, max_depth)) + ("players", fc::variant(match_obj.players, max_depth)) + ("games", fc::variant(match_obj.games, max_depth)) + ("game_winners", fc::variant(match_obj.game_winners, max_depth)) + ("number_of_wins", fc::variant(match_obj.number_of_wins, max_depth)) + ("number_of_ties", fc::variant(match_obj.number_of_ties, max_depth)) + ("match_winners", fc::variant(match_obj.match_winners, max_depth)) + ("start_time", fc::variant(match_obj.start_time, max_depth)) + ("end_time", fc::variant(match_obj.end_time, max_depth)) + ("state", fc::variant(match_obj.get_state(), max_depth)); + + v = o; + } FC_RETHROW_EXCEPTIONS(warn, "") } + +// Manually reflect match_object to variant to properly reflect "state" +void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth) +{ try { + fc_elog(fc::logger::get("tournament"), "In match_obj from_variant"); + match_obj.id = v["id"].as( max_depth ); + match_obj.tournament_id = v["tournament_id"].as( max_depth ); + match_obj.players = v["players"].as >( max_depth ); + match_obj.games = v["games"].as >( max_depth ); + match_obj.game_winners = v["game_winners"].as > >( max_depth ); + match_obj.number_of_wins = v["number_of_wins"].as >( max_depth ); + match_obj.number_of_ties = v["number_of_ties"].as( max_depth ); + match_obj.match_winners = v["match_winners"].as >( max_depth ); + match_obj.start_time = v["start_time"].as( max_depth ); + match_obj.end_time = v["end_time"].as >( max_depth ); + graphene::chain::match_state state = v["state"].as( max_depth ); + const_cast(match_obj.my->state_machine.current_state())[0] = (int)state; + } FC_RETHROW_EXCEPTIONS(warn, "") } +} //end namespace fc + -- 2.45.2 From a6d26572a1a0983e3b5a73c753399ea689838724 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 24 Feb 2022 09:41:03 +0300 Subject: [PATCH 13/17] #235 Add custom funtions for game_object --- libraries/chain/game_object.cpp | 45 +++++++ .../include/graphene/chain/game_object.hpp | 125 ++++++++++++++++-- 2 files changed, 162 insertions(+), 8 deletions(-) diff --git a/libraries/chain/game_object.cpp b/libraries/chain/game_object.cpp index 19f3613b..88c0cf3c 100644 --- a/libraries/chain/game_object.cpp +++ b/libraries/chain/game_object.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include #include @@ -531,6 +533,49 @@ namespace graphene { namespace chain { my->state_machine.process_event(initiate_game(db, players)); } + void game_object::pack_impl(std::ostream& stream) const + { + boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + oa << my->state_machine; + } + + void game_object::unpack_impl(std::istream& stream) + { + boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + ia >> my->state_machine; + } + } } // graphene::chain +namespace fc { +// Manually reflect game_object to variant to properly reflect "state" +void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth) +{ + fc_elog(fc::logger::get("tournament"), "In game_obj to_variant"); + elog("In game_obj to_variant"); + fc::mutable_variant_object o; + o("id", fc::variant(game_obj.id, max_depth )) + ("match_id", fc::variant(game_obj.match_id, max_depth )) + ("players", fc::variant(game_obj.players, max_depth )) + ("winners", fc::variant(game_obj.winners, max_depth )) + ("game_details", fc::variant(game_obj.game_details, max_depth )) + ("next_timeout", fc::variant(game_obj.next_timeout, max_depth )) + ("state", fc::variant(game_obj.get_state(), max_depth )); + v = o; +} + +// Manually reflect game_object to variant to properly reflect "state" +void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth) +{ + fc_elog(fc::logger::get("tournament"), "In game_obj from_variant"); + game_obj.id = v["id"].as( max_depth ); + game_obj.match_id = v["match_id"].as( max_depth ); + game_obj.players = v["players"].as >( max_depth ); + game_obj.winners = v["winners"].as >( max_depth ); + game_obj.game_details = v["game_details"].as( max_depth ); + game_obj.next_timeout = v["next_timeout"].as >( max_depth ); + graphene::chain::game_state state = v["state"].as( max_depth ); + const_cast(game_obj.my->state_machine.current_state())[0] = (int)state; +} +} //end namespace fc diff --git a/libraries/chain/include/graphene/chain/game_object.hpp b/libraries/chain/include/graphene/chain/game_object.hpp index 1f326b90..cca9ea5e 100644 --- a/libraries/chain/include/graphene/chain/game_object.hpp +++ b/libraries/chain/include/graphene/chain/game_object.hpp @@ -26,6 +26,17 @@ #include #include #include +#include +#include + +namespace graphene { namespace chain { +class game_object; +} } + +namespace fc { +void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth = 1); +void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth = 1); +} //end namespace fc namespace graphene { namespace chain { class database; @@ -70,6 +81,21 @@ namespace graphene { namespace chain { void on_timeout(database& db); void start_game(database& db, const std::vector& players); + // serialization functions: + // for serializing to raw, go through a temporary sstream object to avoid + // having to implement serialization in the header file + template + friend Stream& operator<<( Stream& s, const game_object& game_obj ); + + template + friend Stream& operator>>( Stream& s, game_object& game_obj ); + + friend void ::fc::to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth); + friend void ::fc::from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth); + + void pack_impl(std::ostream& stream) const; + void unpack_impl(std::istream& stream); + class impl; std::unique_ptr my; }; @@ -85,6 +111,49 @@ namespace graphene { namespace chain { member > > > > game_object_multi_index_type; typedef generic_index game_index; + + template + inline Stream& operator<<( Stream& s, const game_object& game_obj ) + { + // pack all fields exposed in the header in the usual way + // instead of calling the derived pack, just serialize the one field in the base class + // fc::raw::pack >(s, game_obj); + fc::raw::pack(s, game_obj.id); + fc::raw::pack(s, game_obj.match_id); + fc::raw::pack(s, game_obj.players); + fc::raw::pack(s, game_obj.winners); + fc::raw::pack(s, game_obj.game_details); + fc::raw::pack(s, game_obj.next_timeout); + + // fc::raw::pack the contents hidden in the impl class + std::ostringstream stream; + game_obj.pack_impl(stream); + std::string stringified_stream(stream.str()); + fc::raw::pack(s, stream.str()); + + return s; + } + + template + inline Stream& operator>>( Stream& s, game_object& game_obj ) + { + // unpack all fields exposed in the header in the usual way + //fc::raw::unpack >(s, game_obj); + fc::raw::unpack(s, game_obj.id); + fc::raw::unpack(s, game_obj.match_id); + fc::raw::unpack(s, game_obj.players); + fc::raw::unpack(s, game_obj.winners); + fc::raw::unpack(s, game_obj.game_details); + fc::raw::unpack(s, game_obj.next_timeout); + + // fc::raw::unpack the contents hidden in the impl class + std::string stringified_stream; + fc::raw::unpack(s, stringified_stream); + std::istringstream stream(stringified_stream); + game_obj.unpack_impl(stream); + + return s; + } } } FC_REFLECT_ENUM(graphene::chain::game_state, @@ -93,12 +162,52 @@ FC_REFLECT_ENUM(graphene::chain::game_state, (expecting_reveal_moves) (game_complete)) -//FC_REFLECT_TYPENAME(graphene::chain::game_object) // manually serialized -FC_REFLECT_DERIVED(graphene::chain::game_object, (graphene::db::object), - (match_id) - (players) - (winners) - (game_details) - (next_timeout)) +namespace fc { -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::game_object ) \ No newline at end of file +template<> +template<> +inline void if_enum::from_variant(const variant &vo, graphene::chain::game_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); +} + +template<> +template<> +inline void if_enum::to_variant(const graphene::chain::game_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); +} + +namespace raw { namespace detail { + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::game_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::game_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::unpack(fc::datastream &s, graphene::chain::game_object &v, uint32_t) { + s >> v; +} + +} } + +template <> +struct get_typename { + static const char *name() { + return "graphene::chain::game_object"; + } +}; +template <> +struct reflector { + typedef graphene::chain::game_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; +}; +} // namespace fc \ No newline at end of file -- 2.45.2 From 37c9b057df6d942bbca90dd42faa5740d25c5277 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 24 Feb 2022 09:41:25 +0300 Subject: [PATCH 14/17] #235 Add custom funtions for tournament_object --- .../graphene/chain/tournament_object.hpp | 143 ++++++++++++++++-- libraries/chain/tournament_object.cpp | 52 +++++++ 2 files changed, 182 insertions(+), 13 deletions(-) diff --git a/libraries/chain/include/graphene/chain/tournament_object.hpp b/libraries/chain/include/graphene/chain/tournament_object.hpp index 3dcc38ca..f3c8e610 100644 --- a/libraries/chain/include/graphene/chain/tournament_object.hpp +++ b/libraries/chain/include/graphene/chain/tournament_object.hpp @@ -3,6 +3,17 @@ #include #include #include +#include +#include + +namespace graphene { namespace chain { +class tournament_object; +} } + +namespace fc { +void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth = 1); +void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth = 1); +} //end namespace fc namespace graphene { namespace chain { class database; @@ -87,6 +98,21 @@ namespace graphene { namespace chain { time_point_sec get_registration_deadline() const { return options.registration_deadline; } + // serialization functions: + // for serializing to raw, go through a temporary sstream object to avoid + // having to implement serialization in the header file + template + friend Stream& operator<<( Stream& s, const tournament_object& tournament_obj ); + + template + friend Stream& operator>>( Stream& s, tournament_object& tournament_obj ); + + friend void ::fc::to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth); + friend void ::fc::from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth); + + void pack_impl(std::ostream& stream) const; + void unpack_impl(std::istream& stream); + /// called by database maintenance code when registration for this contest has expired void on_registration_deadline_passed(database& db); void on_player_registered(database& db, account_id_type payer_id, account_id_type player_id); @@ -127,6 +153,59 @@ namespace graphene { namespace chain { > tournament_details_object_multi_index_type; typedef generic_index tournament_details_index; + template + inline Stream& operator<<( Stream& s, const tournament_object& tournament_obj ) + { + fc_elog(fc::logger::get("tournament"), "In tournament_obj to_raw"); + // pack all fields exposed in the header in the usual way + // instead of calling the derived pack, just serialize the one field in the base class + // fc::raw::pack >(s, tournament_obj); + fc::raw::pack(s, tournament_obj.id); + fc::raw::pack(s, tournament_obj.creator); + fc::raw::pack(s, tournament_obj.options); + fc::raw::pack(s, tournament_obj.start_time); + fc::raw::pack(s, tournament_obj.end_time); + fc::raw::pack(s, tournament_obj.prize_pool); + fc::raw::pack(s, tournament_obj.registered_players); + fc::raw::pack(s, tournament_obj.tournament_details_id); + + // fc::raw::pack the contents hidden in the impl class + std::ostringstream stream; + tournament_obj.pack_impl(stream); + std::string stringified_stream(stream.str()); + fc_elog(fc::logger::get("tournament"), "Serialized state ${state} to bytes ${bytes}", + ("state", tournament_obj.get_state())("bytes", fc::to_hex(stringified_stream.c_str(), stringified_stream.size()))); + fc::raw::pack(s, stream.str()); + + return s; + } + + template + inline Stream& operator>>( Stream& s, tournament_object& tournament_obj ) + { + fc_elog(fc::logger::get("tournament"), "In tournament_obj from_raw"); + // unpack all fields exposed in the header in the usual way + //fc::raw::unpack >(s, tournament_obj); + fc::raw::unpack(s, tournament_obj.id); + fc::raw::unpack(s, tournament_obj.creator); + fc::raw::unpack(s, tournament_obj.options); + fc::raw::unpack(s, tournament_obj.start_time); + fc::raw::unpack(s, tournament_obj.end_time); + fc::raw::unpack(s, tournament_obj.prize_pool); + fc::raw::unpack(s, tournament_obj.registered_players); + fc::raw::unpack(s, tournament_obj.tournament_details_id); + + // fc::raw::unpack the contents hidden in the impl class + std::string stringified_stream; + fc::raw::unpack(s, stringified_stream); + std::istringstream stream(stringified_stream); + tournament_obj.unpack_impl(stream); + fc_elog(fc::logger::get("tournament"), "Deserialized state ${state} from bytes ${bytes}", + ("state", tournament_obj.get_state())("bytes", fc::to_hex(stringified_stream.c_str(), stringified_stream.size()))); + + return s; + } + /** * @brief This secondary index will allow a reverse lookup of all tournaments * a particular account has registered for. This will be attached @@ -159,21 +238,59 @@ FC_REFLECT_DERIVED(graphene::chain::tournament_details_object, (graphene::db::ob (players_payers) (matches)) -//FC_REFLECT_TYPENAME(graphene::chain::tournament_object) // manually serialized -FC_REFLECT_DERIVED(graphene::chain::tournament_object, (graphene::db::object), - (creator) - (options) - (start_time) - (end_time) - (prize_pool) - (registered_players) - (tournament_details_id)) - -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::tournament_object ) - FC_REFLECT_ENUM(graphene::chain::tournament_state, (accepting_registrations) (awaiting_start) (in_progress) (registration_period_expired) - (concluded)) \ No newline at end of file + (concluded)) + +namespace fc { + +template<> +template<> +inline void if_enum::from_variant(const variant &vo, graphene::chain::tournament_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); +} + +template<> +template<> +inline void if_enum::to_variant(const graphene::chain::tournament_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); +} + +namespace raw { namespace detail { + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::tournament_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::tournament_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::unpack(fc::datastream &s, graphene::chain::tournament_object &v, uint32_t) { + s >> v; +} + +} } + +template <> +struct get_typename { + static const char *name() { + return "graphene::chain::tournament_object"; + } +}; +template <> +struct reflector { + typedef graphene::chain::tournament_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; +}; +} // namespace fc \ No newline at end of file diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index 7babb1ba..680943bd 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -28,6 +28,8 @@ #include #include +#include +#include #include namespace graphene { namespace chain { @@ -531,6 +533,18 @@ namespace graphene { namespace chain { return state; } + void tournament_object::pack_impl(std::ostream& stream) const + { + boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + oa << my->state_machine; + } + + void tournament_object::unpack_impl(std::istream& stream) + { + boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + ia >> my->state_machine; + } + void tournament_object::on_registration_deadline_passed(database& db) { my->state_machine.process_event(registration_deadline_passed(db)); @@ -707,4 +721,42 @@ namespace graphene { namespace chain { } } } // graphene::chain +namespace fc { +// Manually reflect tournament_object to variant to properly reflect "state" +void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth) +{ + fc_elog(fc::logger::get("tournament"), "In tournament_obj to_variant"); + elog("In tournament_obj to_variant"); + fc::mutable_variant_object o; + o("id", fc::variant(tournament_obj.id, max_depth)) + ("creator", fc::variant(tournament_obj.creator, max_depth)) + ("options", fc::variant(tournament_obj.options, max_depth)) + ("start_time", fc::variant(tournament_obj.start_time, max_depth)) + ("end_time", fc::variant(tournament_obj.end_time, max_depth)) + ("prize_pool", fc::variant(tournament_obj.prize_pool, max_depth)) + ("registered_players", fc::variant(tournament_obj.registered_players, max_depth)) + ("tournament_details_id", fc::variant(tournament_obj.tournament_details_id, max_depth)) + ("state", fc::variant(tournament_obj.get_state(), max_depth)); + + v = o; +} + +// Manually reflect tournament_object to variant to properly reflect "state" +void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth) +{ + fc_elog(fc::logger::get("tournament"), "In tournament_obj from_variant"); + tournament_obj.id = v["id"].as( max_depth ); + tournament_obj.creator = v["creator"].as( max_depth ); + tournament_obj.options = v["options"].as( max_depth ); + tournament_obj.start_time = v["start_time"].as >( max_depth ); + tournament_obj.end_time = v["end_time"].as >( max_depth ); + tournament_obj.prize_pool = v["prize_pool"].as( max_depth ); + tournament_obj.registered_players = v["registered_players"].as( max_depth ); + tournament_obj.tournament_details_id = v["tournament_details_id"].as( max_depth ); + graphene::chain::tournament_state state = v["state"].as( max_depth ); + const_cast(tournament_obj.my->state_machine.current_state())[0] = (int)state; +} +} //end namespace fc + + -- 2.45.2 From 1d32b18102384fb731e3acd358471c94497c6cc4 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 24 Feb 2022 09:42:00 +0300 Subject: [PATCH 15/17] #235 Add custom funtions for betting_market_object and betting_market_group_object --- .../chain/betting_market_group_object.cpp | 49 ++++ libraries/chain/betting_market_object.cpp | 41 +++ .../graphene/chain/betting_market_object.hpp | 238 +++++++++++++++++- 3 files changed, 321 insertions(+), 7 deletions(-) diff --git a/libraries/chain/betting_market_group_object.cpp b/libraries/chain/betting_market_group_object.cpp index 393a9f3f..14c65626 100644 --- a/libraries/chain/betting_market_group_object.cpp +++ b/libraries/chain/betting_market_group_object.cpp @@ -30,6 +30,8 @@ #include #include +#include +#include #include namespace graphene { namespace chain { @@ -458,6 +460,18 @@ betting_market_group_status betting_market_group_object::get_status() const }; } +void betting_market_group_object::pack_impl(std::ostream& stream) const +{ + boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + oa << my->state_machine; +} + +void betting_market_group_object::unpack_impl(std::istream& stream) +{ + boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + ia >> my->state_machine; +} + void betting_market_group_object::on_upcoming_event(database& db) { my->state_machine.process_event(upcoming_event(db)); @@ -527,3 +541,38 @@ void betting_market_group_object::dispatch_new_status(database& db, betting_mark } } // graphene::chain +namespace fc { +// Manually reflect betting_market_group_object to variant to properly reflect "state" +void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth) +{ + fc::mutable_variant_object o; + o("id", fc::variant(betting_market_group_obj.id, max_depth)) + ("description", fc::variant(betting_market_group_obj.description, max_depth)) + ("event_id", fc::variant(betting_market_group_obj.event_id, max_depth)) + ("rules_id", fc::variant(betting_market_group_obj.rules_id, max_depth)) + ("asset_id", fc::variant(betting_market_group_obj.asset_id, max_depth)) + ("total_matched_bets_amount", fc::variant(betting_market_group_obj.total_matched_bets_amount, max_depth)) + ("never_in_play", fc::variant(betting_market_group_obj.never_in_play, max_depth)) + ("delay_before_settling", fc::variant(betting_market_group_obj.delay_before_settling, max_depth)) + ("settling_time", fc::variant(betting_market_group_obj.settling_time, max_depth)) + ("status", fc::variant(betting_market_group_obj.get_status(), max_depth)); + + v = o; +} + +// Manually reflect betting_market_group_object to variant to properly reflect "state" +void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth) +{ + betting_market_group_obj.id = v["id"].as( max_depth ); + betting_market_group_obj.description = v["description"].as( max_depth ); + betting_market_group_obj.event_id = v["event_id"].as( max_depth ); + betting_market_group_obj.asset_id = v["asset_id"].as( max_depth ); + betting_market_group_obj.total_matched_bets_amount = v["total_matched_bets_amount"].as( max_depth ); + betting_market_group_obj.never_in_play = v["never_in_play"].as( max_depth ); + betting_market_group_obj.delay_before_settling = v["delay_before_settling"].as( max_depth ); + betting_market_group_obj.settling_time = v["settling_time"].as>( max_depth ); + graphene::chain::betting_market_group_status status = v["status"].as( max_depth ); + const_cast(betting_market_group_obj.my->state_machine.current_state())[0] = (int)status; +} +} //end namespace fc + diff --git a/libraries/chain/betting_market_object.cpp b/libraries/chain/betting_market_object.cpp index 8f706458..62ed883a 100644 --- a/libraries/chain/betting_market_object.cpp +++ b/libraries/chain/betting_market_object.cpp @@ -29,6 +29,8 @@ #include #include +#include +#include #include namespace graphene { namespace chain { @@ -420,6 +422,18 @@ void betting_market_object::cancel_all_bets(database& db) const } } +void betting_market_object::pack_impl(std::ostream& stream) const +{ + boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + oa << my->state_machine; +} + +void betting_market_object::unpack_impl(std::istream& stream) +{ + boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + ia >> my->state_machine; +} + void betting_market_object::on_unresolved_event(database& db) { my->state_machine.process_event(unresolved_event(db)); @@ -452,3 +466,30 @@ void betting_market_object::on_canceled_event(database& db) } } // graphene::chain +namespace fc { +// Manually reflect betting_market_object to variant to properly reflect "state" +void to_variant(const graphene::chain::betting_market_object& event_obj, fc::variant& v, uint32_t max_depth) +{ + fc::mutable_variant_object o; + o("id", fc::variant(event_obj.id, max_depth) ) + ("group_id", fc::variant(event_obj.group_id, max_depth)) + ("description", fc::variant(event_obj.description, max_depth)) + ("payout_condition", fc::variant(event_obj.payout_condition, max_depth)) + ("resolution", fc::variant(event_obj.resolution, max_depth)) + ("status", fc::variant(event_obj.get_status(), max_depth)); + + v = o; +} + +// Manually reflect betting_market_object to variant to properly reflect "state" +void from_variant(const fc::variant& v, graphene::chain::betting_market_object& event_obj, uint32_t max_depth) +{ + event_obj.id = v["id"].as( max_depth ); + event_obj.group_id = v["name"].as( max_depth ); + event_obj.description = v["description"].as( max_depth ); + event_obj.payout_condition = v["payout_condition"].as( max_depth ); + event_obj.resolution = v["resolution"].as>( max_depth ); + graphene::chain::betting_market_status status = v["status"].as( max_depth ); + const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; +} +} //end namespace fc \ No newline at end of file diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp index 34946344..e2d2d6e1 100644 --- a/libraries/chain/include/graphene/chain/betting_market_object.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -27,8 +27,20 @@ #include #include #include - #include +#include + +namespace graphene { namespace chain { +class betting_market_object; +class betting_market_group_object; +} } + +namespace fc { +void to_variant(const graphene::chain::betting_market_object& betting_market_obj, fc::variant& v, uint32_t max_depth = 1); +void from_variant(const fc::variant& v, graphene::chain::betting_market_object& betting_market_obj, uint32_t max_depth = 1); +void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth = 1); +void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth = 1); +} //end namespace fc namespace graphene { namespace chain { @@ -88,6 +100,21 @@ class betting_market_group_object : public graphene::db::abstract_object< bettin betting_market_group_status get_status() const; + // serialization functions: + // for serializing to raw, go through a temporary sstream object to avoid + // having to implement serialization in the header file + template + friend Stream& operator<<( Stream& s, const betting_market_group_object& betting_market_group_obj ); + + template + friend Stream& operator>>( Stream& s, betting_market_group_object& betting_market_group_obj ); + + friend void ::fc::to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth); + friend void ::fc::from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth); + + void pack_impl(std::ostream& stream) const; + void unpack_impl(std::istream& stream); + void on_upcoming_event(database& db); void on_in_play_event(database& db); void on_frozen_event(database& db); @@ -129,6 +156,21 @@ class betting_market_object : public graphene::db::abstract_object< betting_mark void cancel_all_unmatched_bets(database& db) const; void cancel_all_bets(database& db) const; + // serialization functions: + // for serializing to raw, go through a temporary sstream object to avoid + // having to implement serialization in the header file + template + friend Stream& operator<<( Stream& s, const betting_market_object& betting_market_obj ); + + template + friend Stream& operator>>( Stream& s, betting_market_object& betting_market_obj ); + + friend void ::fc::to_variant(const graphene::chain::betting_market_object& betting_market_obj, fc::variant& v, uint32_t max_depth); + friend void ::fc::from_variant(const fc::variant& v, graphene::chain::betting_market_object& betting_market_obj, uint32_t max_depth); + + void pack_impl(std::ostream& stream) const; + void unpack_impl(std::istream& stream); + void on_unresolved_event(database& db); void on_frozen_event(database& db); void on_closed_event(database& db); @@ -582,16 +624,198 @@ typedef multi_index_container< > > betting_market_position_multi_index_type; typedef generic_index betting_market_position_index; + +template +inline Stream& operator<<( Stream& s, const betting_market_object& betting_market_obj ) +{ + // pack all fields exposed in the header in the usual way + // instead of calling the derived pack, just serialize the one field in the base class + // fc::raw::pack >(s, betting_market_obj); + fc::raw::pack(s, betting_market_obj.id); + fc::raw::pack(s, betting_market_obj.group_id); + fc::raw::pack(s, betting_market_obj.description); + fc::raw::pack(s, betting_market_obj.payout_condition); + fc::raw::pack(s, betting_market_obj.resolution); + + // fc::raw::pack the contents hidden in the impl class + std::ostringstream stream; + betting_market_obj.pack_impl(stream); + std::string stringified_stream(stream.str()); + fc::raw::pack(s, stream.str()); + + return s; +} +template +inline Stream& operator>>( Stream& s, betting_market_object& betting_market_obj ) +{ + // unpack all fields exposed in the header in the usual way + //fc::raw::unpack >(s, betting_market_obj); + fc::raw::unpack(s, betting_market_obj.id); + fc::raw::unpack(s, betting_market_obj.group_id); + fc::raw::unpack(s, betting_market_obj.description); + fc::raw::unpack(s, betting_market_obj.payout_condition); + fc::raw::unpack(s, betting_market_obj.resolution); + + // fc::raw::unpack the contents hidden in the impl class + std::string stringified_stream; + fc::raw::unpack(s, stringified_stream); + std::istringstream stream(stringified_stream); + betting_market_obj.unpack_impl(stream); + + return s; +} + + +template +inline Stream& operator<<( Stream& s, const betting_market_group_object& betting_market_group_obj ) +{ + // pack all fields exposed in the header in the usual way + // instead of calling the derived pack, just serialize the one field in the base class + // fc::raw::pack >(s, betting_market_group_obj); + fc::raw::pack(s, betting_market_group_obj.id); + fc::raw::pack(s, betting_market_group_obj.description); + fc::raw::pack(s, betting_market_group_obj.event_id); + fc::raw::pack(s, betting_market_group_obj.rules_id); + fc::raw::pack(s, betting_market_group_obj.asset_id); + fc::raw::pack(s, betting_market_group_obj.total_matched_bets_amount); + fc::raw::pack(s, betting_market_group_obj.never_in_play); + fc::raw::pack(s, betting_market_group_obj.delay_before_settling); + fc::raw::pack(s, betting_market_group_obj.settling_time); + // fc::raw::pack the contents hidden in the impl class + std::ostringstream stream; + betting_market_group_obj.pack_impl(stream); + std::string stringified_stream(stream.str()); + fc::raw::pack(s, stream.str()); + + return s; +} +template +inline Stream& operator>>( Stream& s, betting_market_group_object& betting_market_group_obj ) +{ + // unpack all fields exposed in the header in the usual way + //fc::raw::unpack >(s, betting_market_group_obj); + fc::raw::unpack(s, betting_market_group_obj.id); + fc::raw::unpack(s, betting_market_group_obj.description); + fc::raw::unpack(s, betting_market_group_obj.event_id); + fc::raw::unpack(s, betting_market_group_obj.rules_id); + fc::raw::unpack(s, betting_market_group_obj.asset_id); + fc::raw::unpack(s, betting_market_group_obj.total_matched_bets_amount); + fc::raw::unpack(s, betting_market_group_obj.never_in_play); + fc::raw::unpack(s, betting_market_group_obj.delay_before_settling); + fc::raw::unpack(s, betting_market_group_obj.settling_time); + + // fc::raw::unpack the contents hidden in the impl class + std::string stringified_stream; + fc::raw::unpack(s, stringified_stream); + std::istringstream stream(stringified_stream); + betting_market_group_obj.unpack_impl(stream); + + return s; +} } } // graphene::chain FC_REFLECT_DERIVED( graphene::chain::betting_market_rules_object, (graphene::db::object), (name)(description) ) -FC_REFLECT_DERIVED( graphene::chain::betting_market_group_object, (graphene::db::object), (description)(event_id)(rules_id)(asset_id)(total_matched_bets_amount)(never_in_play)(delay_before_settling)(settling_time) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::betting_market_group_object ) - -FC_REFLECT_DERIVED( graphene::chain::betting_market_object, (graphene::db::object), (group_id)(description)(payout_condition)(resolution) ) -GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::betting_market_object ) - FC_REFLECT_DERIVED( graphene::chain::bet_object, (graphene::db::object), (bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(back_or_lay)(end_of_delay) ) FC_REFLECT_DERIVED( graphene::chain::betting_market_position_object, (graphene::db::object), (bettor_id)(betting_market_id)(pay_if_payout_condition)(pay_if_not_payout_condition)(pay_if_canceled)(pay_if_not_canceled)(fees_collected) ) + +namespace fc { + +template<> +template<> +inline void if_enum::from_variant(const variant &vo, graphene::chain::betting_market_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); +} + +template<> +template<> +inline void if_enum::to_variant(const graphene::chain::betting_market_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); +} + +namespace raw { namespace detail { + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::unpack(fc::datastream &s, graphene::chain::betting_market_object &v, uint32_t) { + s >> v; +} + +} } + +template <> +struct get_typename { + static const char *name() { + return "graphene::chain::betting_market_object"; + } +}; +template <> +struct reflector { + typedef graphene::chain::betting_market_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; +}; +} // namespace fc + +namespace fc { + +template<> +template<> +inline void if_enum::from_variant(const variant &vo, graphene::chain::betting_market_group_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); +} + +template<> +template<> +inline void if_enum::to_variant(const graphene::chain::betting_market_group_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); +} + +namespace raw { namespace detail { + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_group_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_group_object &v, uint32_t) { + s << v; +} + +template<> +template<> +inline void if_enum::unpack(fc::datastream &s, graphene::chain::betting_market_group_object &v, uint32_t) { + s >> v; +} + +} } + +template <> +struct get_typename { + static const char *name() { + return "graphene::chain::betting_market_group_object"; + } +}; +template <> +struct reflector { + typedef graphene::chain::betting_market_group_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; +}; +} // namespace fc -- 2.45.2 From 82aedaf93767df8b3e2149f8c02565c11c2242a8 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 24 Feb 2022 09:44:25 +0300 Subject: [PATCH 16/17] #235 Delete small objects for game_object, tournament_object, match_object, betting_market_group_object, betting_market_object --- libraries/chain/small_objects.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 75a3906f..24166e4e 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -43,10 +43,6 @@ #include #include #include -#include -#include -#include -#include #include @@ -76,8 +72,3 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_object GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_scheduler ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedule_object ) GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::worker_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::game_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::match_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_group_object ) -GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_object ) -- 2.45.2 From cc0b26cd92368de58ef272356057286e1031aad2 Mon Sep 17 00:00:00 2001 From: serkixenos Date: Mon, 28 Feb 2022 12:39:09 -0400 Subject: [PATCH 17/17] Code formatting --- .../chain/betting_market_group_object.cpp | 60 +- libraries/chain/betting_market_object.cpp | 48 +- libraries/chain/event_object.cpp | 1017 ++++++++--------- libraries/chain/game_object.cpp | 58 +- .../graphene/chain/betting_market_object.hpp | 192 ++-- .../include/graphene/chain/event_object.hpp | 316 ++--- .../include/graphene/chain/game_object.hpp | 98 +- .../include/graphene/chain/match_object.hpp | 98 +- .../graphene/chain/tournament_object.hpp | 98 +- libraries/chain/match_object.cpp | 32 +- libraries/chain/tournament_object.cpp | 65 +- 11 files changed, 1041 insertions(+), 1041 deletions(-) diff --git a/libraries/chain/betting_market_group_object.cpp b/libraries/chain/betting_market_group_object.cpp index 14c65626..778c756e 100644 --- a/libraries/chain/betting_market_group_object.cpp +++ b/libraries/chain/betting_market_group_object.cpp @@ -542,37 +542,37 @@ void betting_market_group_object::dispatch_new_status(database& db, betting_mark } } // graphene::chain namespace fc { -// Manually reflect betting_market_group_object to variant to properly reflect "state" -void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth) -{ - fc::mutable_variant_object o; - o("id", fc::variant(betting_market_group_obj.id, max_depth)) - ("description", fc::variant(betting_market_group_obj.description, max_depth)) - ("event_id", fc::variant(betting_market_group_obj.event_id, max_depth)) - ("rules_id", fc::variant(betting_market_group_obj.rules_id, max_depth)) - ("asset_id", fc::variant(betting_market_group_obj.asset_id, max_depth)) - ("total_matched_bets_amount", fc::variant(betting_market_group_obj.total_matched_bets_amount, max_depth)) - ("never_in_play", fc::variant(betting_market_group_obj.never_in_play, max_depth)) - ("delay_before_settling", fc::variant(betting_market_group_obj.delay_before_settling, max_depth)) - ("settling_time", fc::variant(betting_market_group_obj.settling_time, max_depth)) - ("status", fc::variant(betting_market_group_obj.get_status(), max_depth)); + // Manually reflect betting_market_group_object to variant to properly reflect "state" + void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth) + { + fc::mutable_variant_object o; + o("id", fc::variant(betting_market_group_obj.id, max_depth)) + ("description", fc::variant(betting_market_group_obj.description, max_depth)) + ("event_id", fc::variant(betting_market_group_obj.event_id, max_depth)) + ("rules_id", fc::variant(betting_market_group_obj.rules_id, max_depth)) + ("asset_id", fc::variant(betting_market_group_obj.asset_id, max_depth)) + ("total_matched_bets_amount", fc::variant(betting_market_group_obj.total_matched_bets_amount, max_depth)) + ("never_in_play", fc::variant(betting_market_group_obj.never_in_play, max_depth)) + ("delay_before_settling", fc::variant(betting_market_group_obj.delay_before_settling, max_depth)) + ("settling_time", fc::variant(betting_market_group_obj.settling_time, max_depth)) + ("status", fc::variant(betting_market_group_obj.get_status(), max_depth)); - v = o; -} + v = o; + } -// Manually reflect betting_market_group_object to variant to properly reflect "state" -void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth) -{ - betting_market_group_obj.id = v["id"].as( max_depth ); - betting_market_group_obj.description = v["description"].as( max_depth ); - betting_market_group_obj.event_id = v["event_id"].as( max_depth ); - betting_market_group_obj.asset_id = v["asset_id"].as( max_depth ); - betting_market_group_obj.total_matched_bets_amount = v["total_matched_bets_amount"].as( max_depth ); - betting_market_group_obj.never_in_play = v["never_in_play"].as( max_depth ); - betting_market_group_obj.delay_before_settling = v["delay_before_settling"].as( max_depth ); - betting_market_group_obj.settling_time = v["settling_time"].as>( max_depth ); - graphene::chain::betting_market_group_status status = v["status"].as( max_depth ); - const_cast(betting_market_group_obj.my->state_machine.current_state())[0] = (int)status; -} + // Manually reflect betting_market_group_object to variant to properly reflect "state" + void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth) + { + betting_market_group_obj.id = v["id"].as( max_depth ); + betting_market_group_obj.description = v["description"].as( max_depth ); + betting_market_group_obj.event_id = v["event_id"].as( max_depth ); + betting_market_group_obj.asset_id = v["asset_id"].as( max_depth ); + betting_market_group_obj.total_matched_bets_amount = v["total_matched_bets_amount"].as( max_depth ); + betting_market_group_obj.never_in_play = v["never_in_play"].as( max_depth ); + betting_market_group_obj.delay_before_settling = v["delay_before_settling"].as( max_depth ); + betting_market_group_obj.settling_time = v["settling_time"].as>( max_depth ); + graphene::chain::betting_market_group_status status = v["status"].as( max_depth ); + const_cast(betting_market_group_obj.my->state_machine.current_state())[0] = (int)status; + } } //end namespace fc diff --git a/libraries/chain/betting_market_object.cpp b/libraries/chain/betting_market_object.cpp index 62ed883a..bd940862 100644 --- a/libraries/chain/betting_market_object.cpp +++ b/libraries/chain/betting_market_object.cpp @@ -467,29 +467,29 @@ void betting_market_object::on_canceled_event(database& db) } } // graphene::chain namespace fc { -// Manually reflect betting_market_object to variant to properly reflect "state" -void to_variant(const graphene::chain::betting_market_object& event_obj, fc::variant& v, uint32_t max_depth) -{ - fc::mutable_variant_object o; - o("id", fc::variant(event_obj.id, max_depth) ) - ("group_id", fc::variant(event_obj.group_id, max_depth)) - ("description", fc::variant(event_obj.description, max_depth)) - ("payout_condition", fc::variant(event_obj.payout_condition, max_depth)) - ("resolution", fc::variant(event_obj.resolution, max_depth)) - ("status", fc::variant(event_obj.get_status(), max_depth)); + // Manually reflect betting_market_object to variant to properly reflect "state" + void to_variant(const graphene::chain::betting_market_object& event_obj, fc::variant& v, uint32_t max_depth) + { + fc::mutable_variant_object o; + o("id", fc::variant(event_obj.id, max_depth) ) + ("group_id", fc::variant(event_obj.group_id, max_depth)) + ("description", fc::variant(event_obj.description, max_depth)) + ("payout_condition", fc::variant(event_obj.payout_condition, max_depth)) + ("resolution", fc::variant(event_obj.resolution, max_depth)) + ("status", fc::variant(event_obj.get_status(), max_depth)); - v = o; -} + v = o; + } -// Manually reflect betting_market_object to variant to properly reflect "state" -void from_variant(const fc::variant& v, graphene::chain::betting_market_object& event_obj, uint32_t max_depth) -{ - event_obj.id = v["id"].as( max_depth ); - event_obj.group_id = v["name"].as( max_depth ); - event_obj.description = v["description"].as( max_depth ); - event_obj.payout_condition = v["payout_condition"].as( max_depth ); - event_obj.resolution = v["resolution"].as>( max_depth ); - graphene::chain::betting_market_status status = v["status"].as( max_depth ); - const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; -} -} //end namespace fc \ No newline at end of file + // Manually reflect betting_market_object to variant to properly reflect "state" + void from_variant(const fc::variant& v, graphene::chain::betting_market_object& event_obj, uint32_t max_depth) + { + event_obj.id = v["id"].as( max_depth ); + event_obj.group_id = v["name"].as( max_depth ); + event_obj.description = v["description"].as( max_depth ); + event_obj.payout_condition = v["payout_condition"].as( max_depth ); + event_obj.resolution = v["resolution"].as>( max_depth ); + graphene::chain::betting_market_status status = v["status"].as( max_depth ); + const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; + } +} //end namespace fc diff --git a/libraries/chain/event_object.cpp b/libraries/chain/event_object.cpp index b46d1e7b..2040ad4b 100644 --- a/libraries/chain/event_object.cpp +++ b/libraries/chain/event_object.cpp @@ -1,26 +1,26 @@ /* -* Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. -*/ + * Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. + */ #define DEFAULT_LOGGER "betting" #define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS @@ -36,549 +36,548 @@ #include namespace graphene { namespace chain { -enum class event_state { - upcoming, - frozen_upcoming, - in_progress, - frozen_in_progress, - finished, - canceled, - settled -}; + enum class event_state { + upcoming, + frozen_upcoming, + in_progress, + frozen_in_progress, + finished, + canceled, + settled + }; } } FC_REFLECT_ENUM(graphene::chain::event_state, - (upcoming) - (frozen_upcoming) - (in_progress) - (frozen_in_progress) - (finished) - (canceled) - (settled)) + (upcoming) + (frozen_upcoming) + (in_progress) + (frozen_in_progress) + (finished) + (canceled) + (settled)) namespace graphene { namespace chain { -namespace msm = boost::msm; -namespace mpl = boost::mpl; + namespace msm = boost::msm; + namespace mpl = boost::mpl; -namespace -{ + namespace + { -// Events -- most events happen when the witnesses publish an event_update operation with a new -// status, so if they publish an event with the status set to `frozen`, we'll generate a `frozen_event` -struct upcoming_event -{ - database& db; - upcoming_event(database& db) : db(db) {} -}; -struct in_progress_event -{ - database& db; - in_progress_event(database& db) : db(db) {} -}; -struct frozen_event -{ - database& db; - frozen_event(database& db) : db(db) {} -}; -struct finished_event -{ - database& db; - finished_event(database& db) : db(db) {} -}; -struct canceled_event -{ - database& db; - canceled_event(database& db) : db(db) {} -}; + // Events -- most events happen when the witnesses publish an event_update operation with a new + // status, so if they publish an event with the status set to `frozen`, we'll generate a `frozen_event` + struct upcoming_event + { + database& db; + upcoming_event(database& db) : db(db) {} + }; + struct in_progress_event + { + database& db; + in_progress_event(database& db) : db(db) {} + }; + struct frozen_event + { + database& db; + frozen_event(database& db) : db(db) {} + }; + struct finished_event + { + database& db; + finished_event(database& db) : db(db) {} + }; + struct canceled_event + { + database& db; + canceled_event(database& db) : db(db) {} + }; -// event triggered when a betting market group in this event is resolved, -// when we get this, check and see if all betting market groups are now -// canceled/settled; if so, transition the event to canceled/settled, -// otherwise remain in the current state -struct betting_market_group_resolved_event -{ - database& db; - betting_market_group_id_type resolved_group; - bool was_canceled; - betting_market_group_resolved_event(database& db, betting_market_group_id_type resolved_group, bool was_canceled) : db(db), resolved_group(resolved_group), was_canceled(was_canceled) {} -}; + // event triggered when a betting market group in this event is resolved, + // when we get this, check and see if all betting market groups are now + // canceled/settled; if so, transition the event to canceled/settled, + // otherwise remain in the current state + struct betting_market_group_resolved_event + { + database& db; + betting_market_group_id_type resolved_group; + bool was_canceled; + betting_market_group_resolved_event(database& db, betting_market_group_id_type resolved_group, bool was_canceled) : db(db), resolved_group(resolved_group), was_canceled(was_canceled) {} + }; -// event triggered when a betting market group is closed. When we get this, -// if all child betting market groups are closed, transition to finished -struct betting_market_group_closed_event -{ - database& db; - betting_market_group_id_type closed_group; - betting_market_group_closed_event(database& db, betting_market_group_id_type closed_group) : db(db), closed_group(closed_group) {} -}; + // event triggered when a betting market group is closed. When we get this, + // if all child betting market groups are closed, transition to finished + struct betting_market_group_closed_event + { + database& db; + betting_market_group_id_type closed_group; + betting_market_group_closed_event(database& db, betting_market_group_id_type closed_group) : db(db), closed_group(closed_group) {} + }; -// Events -struct event_state_machine_ : public msm::front::state_machine_def + // Events + struct event_state_machine_ : public msm::front::state_machine_def -{ - // disable a few state machine features we don't use for performance - typedef int no_exception_thrown; - typedef int no_message_queue; + { + // disable a few state machine features we don't use for performance + typedef int no_exception_thrown; + typedef int no_message_queue; - // States - struct upcoming : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - void on_entry(const upcoming_event& event, event_state_machine_& fsm) { - dlog("event ${id} -> upcoming", ("id", fsm.event_obj->id)); - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_upcoming_event(event.db); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't freeze the group. just ignore the exception - } - } - }; - struct in_progress : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - void on_entry(const in_progress_event& event, event_state_machine_& fsm) { - dlog("event ${id} -> in_progress", ("id", fsm.event_obj->id)); - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_in_play_event(event.db); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't freeze the group. just ignore the exception - } - } - }; - struct frozen_upcoming : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> frozen_upcoming", ("id", fsm.event_obj->id)); - } - }; - struct frozen_in_progress : public msm::front::state<> { - void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> frozen_in_progress", ("id", fsm.event_obj->id)); - } - }; - struct finished : public msm::front::state<> { - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> finished", ("id", fsm.event_obj->id)); - } - }; - struct settled : public msm::front::state<>{ - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> settled", ("id", fsm.event_obj->id)); - } - }; - struct canceled : public msm::front::state<> { - template - void on_entry(const Event& event, event_state_machine_& fsm) { - dlog("event ${id} -> canceled", ("id", fsm.event_obj->id)); - } - }; + // States + struct upcoming : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + void on_entry(const upcoming_event& event, event_state_machine_& fsm) { + dlog("event ${id} -> upcoming", ("id", fsm.event_obj->id)); + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_upcoming_event(event.db); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't freeze the group. just ignore the exception + } + } + }; + struct in_progress : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + void on_entry(const in_progress_event& event, event_state_machine_& fsm) { + dlog("event ${id} -> in_progress", ("id", fsm.event_obj->id)); + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(fsm.event_obj->id))) + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_in_play_event(event.db); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't freeze the group. just ignore the exception + } + } + }; + struct frozen_upcoming : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> frozen_upcoming", ("id", fsm.event_obj->id)); + } + }; + struct frozen_in_progress : public msm::front::state<> { + void on_entry(const betting_market_group_resolved_event& event, event_state_machine_& fsm) {} // transition to self + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> frozen_in_progress", ("id", fsm.event_obj->id)); + } + }; + struct finished : public msm::front::state<> { + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> finished", ("id", fsm.event_obj->id)); + } + }; + struct settled : public msm::front::state<>{ + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> settled", ("id", fsm.event_obj->id)); + } + }; + struct canceled : public msm::front::state<> { + template + void on_entry(const Event& event, event_state_machine_& fsm) { + dlog("event ${id} -> canceled", ("id", fsm.event_obj->id)); + } + }; - // actions - void record_whether_group_settled_or_canceled(const betting_market_group_resolved_event& event) { - if (!event.was_canceled) - event_obj->at_least_one_betting_market_group_settled = true; - } + // actions + void record_whether_group_settled_or_canceled(const betting_market_group_resolved_event& event) { + if (!event.was_canceled) + event_obj->at_least_one_betting_market_group_settled = true; + } - void freeze_betting_market_groups(const frozen_event& event) { - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - { - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_frozen_event(event.db); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't freeze the group. just ignore the exception - } - } - } + void freeze_betting_market_groups(const frozen_event& event) { + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + { + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_frozen_event(event.db); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't freeze the group. just ignore the exception + } + } + } - void close_all_betting_market_groups(const finished_event& event) { - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - { - try - { - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_closed_event(event.db, true); - }); - } - catch (const graphene::chain::no_transition&) - { - // it's possible a betting market group has already been closed or canceled, - // in which case we can't close the group. just ignore the exception - } - } - } + void close_all_betting_market_groups(const finished_event& event) { + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + { + try + { + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_closed_event(event.db, true); + }); + } + catch (const graphene::chain::no_transition&) + { + // it's possible a betting market group has already been closed or canceled, + // in which case we can't close the group. just ignore the exception + } + } + } - void cancel_all_betting_market_groups(const canceled_event& event) { - auto& betting_market_group_index = event.db.template get_index_type().indices().template get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { - betting_market_group_obj.on_canceled_event(event.db, true); - }); - } + void cancel_all_betting_market_groups(const canceled_event& event) { + auto& betting_market_group_index = event.db.template get_index_type().indices().template get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + event.db.modify(betting_market_group, [&event](betting_market_group_object& betting_market_group_obj) { + betting_market_group_obj.on_canceled_event(event.db, true); + }); + } - // Guards - bool all_betting_market_groups_are_closed(const betting_market_group_closed_event& event) - { - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - if (betting_market_group.id != event.closed_group) - { - betting_market_group_status status = betting_market_group.get_status(); - if (status != betting_market_group_status::closed && - status != betting_market_group_status::graded && - status != betting_market_group_status::re_grading && - status != betting_market_group_status::settled && - status != betting_market_group_status::canceled) - return false; - } - return true; - } + // Guards + bool all_betting_market_groups_are_closed(const betting_market_group_closed_event& event) + { + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + if (betting_market_group.id != event.closed_group) + { + betting_market_group_status status = betting_market_group.get_status(); + if (status != betting_market_group_status::closed && + status != betting_market_group_status::graded && + status != betting_market_group_status::re_grading && + status != betting_market_group_status::settled && + status != betting_market_group_status::canceled) + return false; + } + return true; + } - bool all_betting_market_groups_are_canceled(const betting_market_group_resolved_event& event) - { - // if the bmg that just resolved was settled, obviously all didn't cancel - if (!event.was_canceled) - return false; - // if a previously-resolved group was settled, all didn't cancel - if (event_obj->at_least_one_betting_market_group_settled) - return false; - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) - if (betting_market_group.id != event.resolved_group) - if (betting_market_group.get_status() != betting_market_group_status::canceled) - return false; - return true; - } + bool all_betting_market_groups_are_canceled(const betting_market_group_resolved_event& event) + { + // if the bmg that just resolved was settled, obviously all didn't cancel + if (!event.was_canceled) + return false; + // if a previously-resolved group was settled, all didn't cancel + if (event_obj->at_least_one_betting_market_group_settled) + return false; + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) + if (betting_market_group.id != event.resolved_group) + if (betting_market_group.get_status() != betting_market_group_status::canceled) + return false; + return true; + } - bool all_betting_market_groups_are_resolved(const betting_market_group_resolved_event& event) - { - if (!event.was_canceled) - event_obj->at_least_one_betting_market_group_settled = true; + bool all_betting_market_groups_are_resolved(const betting_market_group_resolved_event& event) + { + if (!event.was_canceled) + event_obj->at_least_one_betting_market_group_settled = true; - auto& betting_market_group_index = event.db.get_index_type().indices().get(); - for (const betting_market_group_object& betting_market_group : - boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) { - if (betting_market_group.id != event.resolved_group) { - betting_market_group_status status = betting_market_group.get_status(); - if (status != betting_market_group_status::canceled && status != betting_market_group_status::settled) - return false; - } - } - return true; - } + auto& betting_market_group_index = event.db.get_index_type().indices().get(); + for (const betting_market_group_object& betting_market_group : + boost::make_iterator_range(betting_market_group_index.equal_range(event_obj->id))) { + if (betting_market_group.id != event.resolved_group) { + betting_market_group_status status = betting_market_group.get_status(); + if (status != betting_market_group_status::canceled && status != betting_market_group_status::settled) + return false; + } + } + return true; + } - typedef upcoming initial_state; - typedef event_state_machine_ x; // makes transition table cleaner + typedef upcoming initial_state; + typedef event_state_machine_ x; // makes transition table cleaner - // Transition table for tournament - struct transition_table : mpl::vector< - // Start Event Next Action Guard - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - _row < upcoming, in_progress_event, in_progress >, - a_row< upcoming, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< upcoming, frozen_event, frozen_upcoming, &x::freeze_betting_market_groups >, - a_row< upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< upcoming, betting_market_group_resolved_event,upcoming, &x::record_whether_group_settled_or_canceled >, - g_row< upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - _row < frozen_upcoming, upcoming_event, upcoming >, - _row < frozen_upcoming, in_progress_event, in_progress >, - a_row< frozen_upcoming, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< frozen_upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< frozen_upcoming, betting_market_group_resolved_event,frozen_upcoming, &x::record_whether_group_settled_or_canceled >, - g_row< frozen_upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - a_row< in_progress, frozen_event, frozen_in_progress, &x::freeze_betting_market_groups >, - a_row< in_progress, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< in_progress, betting_market_group_resolved_event,in_progress, &x::record_whether_group_settled_or_canceled >, - g_row< in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - _row < frozen_in_progress, in_progress_event, in_progress >, - a_row< frozen_in_progress, finished_event, finished, &x::close_all_betting_market_groups >, - a_row< frozen_in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - a_row< frozen_in_progress, betting_market_group_resolved_event,frozen_in_progress, &x::record_whether_group_settled_or_canceled >, - g_row< frozen_in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, - // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ - a_row< finished, canceled_event, canceled, &x::cancel_all_betting_market_groups >, - g_row< finished, betting_market_group_resolved_event,settled, &x::all_betting_market_groups_are_resolved >, - g_row< finished, betting_market_group_resolved_event,canceled, &x::all_betting_market_groups_are_canceled > - > {}; + // Transition table for tournament + struct transition_table : mpl::vector< + // Start Event Next Action Guard + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + _row < upcoming, in_progress_event, in_progress >, + a_row< upcoming, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< upcoming, frozen_event, frozen_upcoming, &x::freeze_betting_market_groups >, + a_row< upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< upcoming, betting_market_group_resolved_event,upcoming, &x::record_whether_group_settled_or_canceled >, + g_row< upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + _row < frozen_upcoming, upcoming_event, upcoming >, + _row < frozen_upcoming, in_progress_event, in_progress >, + a_row< frozen_upcoming, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< frozen_upcoming, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< frozen_upcoming, betting_market_group_resolved_event,frozen_upcoming, &x::record_whether_group_settled_or_canceled >, + g_row< frozen_upcoming, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + a_row< in_progress, frozen_event, frozen_in_progress, &x::freeze_betting_market_groups >, + a_row< in_progress, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< in_progress, betting_market_group_resolved_event,in_progress, &x::record_whether_group_settled_or_canceled >, + g_row< in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + _row < frozen_in_progress, in_progress_event, in_progress >, + a_row< frozen_in_progress, finished_event, finished, &x::close_all_betting_market_groups >, + a_row< frozen_in_progress, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + a_row< frozen_in_progress, betting_market_group_resolved_event,frozen_in_progress, &x::record_whether_group_settled_or_canceled >, + g_row< frozen_in_progress, betting_market_group_closed_event, finished, &x::all_betting_market_groups_are_closed >, + // +---------------------+-----------------------------+--------------------+--------------------------------+----------------------+ + a_row< finished, canceled_event, canceled, &x::cancel_all_betting_market_groups >, + g_row< finished, betting_market_group_resolved_event,settled, &x::all_betting_market_groups_are_resolved >, + g_row< finished, betting_market_group_resolved_event,canceled, &x::all_betting_market_groups_are_canceled > + > {}; - template - void no_transition(Event const& e, Fsm&, int state) - { - FC_THROW_EXCEPTION(graphene::chain::no_transition, "No transition"); - } + template + void no_transition(Event const& e, Fsm&, int state) + { + FC_THROW_EXCEPTION(graphene::chain::no_transition, "No transition"); + } + template + void no_transition(canceled_event const& e, Fsm&, int state) + { + //ignore transitions from settled to canceled state + //and from canceled to canceled state + } - template - void no_transition(canceled_event const& e, Fsm&, int state) - { - //ignore transitions from settled to canceled state - //and from canceled to canceled state - } + event_object* event_obj; + event_state_machine_(event_object* event_obj) : event_obj(event_obj) {} + }; + typedef msm::back::state_machine event_state_machine; - event_object* event_obj; - event_state_machine_(event_object* event_obj) : event_obj(event_obj) {} -}; -typedef msm::back::state_machine event_state_machine; + } // end anonymous namespace -} // end anonymous namespace + class event_object::impl { + public: + event_state_machine state_machine; -class event_object::impl { -public: - event_state_machine state_machine; + impl(event_object* self) : state_machine(self) {} + }; - impl(event_object* self) : state_machine(self) {} -}; + event_object::event_object() : + at_least_one_betting_market_group_settled(false), + my(new impl(this)) + { + } -event_object::event_object() : - at_least_one_betting_market_group_settled(false), - my(new impl(this)) -{ -} + event_object::event_object(const event_object& rhs) : + graphene::db::abstract_object(rhs), + name(rhs.name), + season(rhs.season), + start_time(rhs.start_time), + event_group_id(rhs.event_group_id), + at_least_one_betting_market_group_settled(rhs.at_least_one_betting_market_group_settled), + scores(rhs.scores), + my(new impl(this)) + { + my->state_machine = rhs.my->state_machine; + my->state_machine.event_obj = this; + } -event_object::event_object(const event_object& rhs) : - graphene::db::abstract_object(rhs), - name(rhs.name), - season(rhs.season), - start_time(rhs.start_time), - event_group_id(rhs.event_group_id), - at_least_one_betting_market_group_settled(rhs.at_least_one_betting_market_group_settled), - scores(rhs.scores), - my(new impl(this)) -{ - my->state_machine = rhs.my->state_machine; - my->state_machine.event_obj = this; -} + event_object& event_object::operator=(const event_object& rhs) + { + //graphene::db::abstract_object::operator=(rhs); + id = rhs.id; + name = rhs.name; + season = rhs.season; + start_time = rhs.start_time; + event_group_id = rhs.event_group_id; + at_least_one_betting_market_group_settled = rhs.at_least_one_betting_market_group_settled; + scores = rhs.scores; -event_object& event_object::operator=(const event_object& rhs) -{ - //graphene::db::abstract_object::operator=(rhs); - id = rhs.id; - name = rhs.name; - season = rhs.season; - start_time = rhs.start_time; - event_group_id = rhs.event_group_id; - at_least_one_betting_market_group_settled = rhs.at_least_one_betting_market_group_settled; - scores = rhs.scores; + my->state_machine = rhs.my->state_machine; + my->state_machine.event_obj = this; - my->state_machine = rhs.my->state_machine; - my->state_machine.event_obj = this; + return *this; + } - return *this; -} + event_object::~event_object() + { + } -event_object::~event_object() -{ -} + namespace { -namespace { + bool verify_event_status_constants() + { + unsigned error_count = 0; + typedef msm::back::generate_state_set::type all_states; + static char const* filled_state_names[mpl::size::value]; + mpl::for_each > + (msm::back::fill_state_names(filled_state_names)); + for (unsigned i = 0; i < mpl::size::value; ++i) + { + try + { + // this is an approximate test, the state name provided by typeinfo will be mangled, but should + // at least contain the string we're looking for + const char* fc_reflected_value_name = fc::reflector::to_string((event_state)i); + if (!strstr(filled_state_names[i], fc_reflected_value_name)) + { + fc_elog(fc::logger::get("default"), + "Error, state string mismatch between fc and boost::msm for int value ${int_value}: boost::msm -> ${boost_string}, fc::reflect -> ${fc_string}", + ("int_value", i)("boost_string", filled_state_names[i])("fc_string", fc_reflected_value_name)); + ++error_count; + } + } + catch (const fc::bad_cast_exception&) + { + fc_elog(fc::logger::get("default"), + "Error, no reflection for value ${int_value} in enum event_status", + ("int_value", i)); + ++error_count; + } + } + if (error_count == 0) + dlog("Event status constants are correct"); + else + wlog("There were ${count} errors in the event status constants", ("count", error_count)); -bool verify_event_status_constants() -{ - unsigned error_count = 0; - typedef msm::back::generate_state_set::type all_states; - static char const* filled_state_names[mpl::size::value]; - mpl::for_each > - (msm::back::fill_state_names(filled_state_names)); - for (unsigned i = 0; i < mpl::size::value; ++i) - { - try - { - // this is an approximate test, the state name provided by typeinfo will be mangled, but should - // at least contain the string we're looking for - const char* fc_reflected_value_name = fc::reflector::to_string((event_state)i); - if (!strstr(filled_state_names[i], fc_reflected_value_name)) - { - fc_elog(fc::logger::get("default"), - "Error, state string mismatch between fc and boost::msm for int value ${int_value}: boost::msm -> ${boost_string}, fc::reflect -> ${fc_string}", - ("int_value", i)("boost_string", filled_state_names[i])("fc_string", fc_reflected_value_name)); - ++error_count; - } - } - catch (const fc::bad_cast_exception&) - { - fc_elog(fc::logger::get("default"), - "Error, no reflection for value ${int_value} in enum event_status", - ("int_value", i)); - ++error_count; - } - } - if (error_count == 0) - dlog("Event status constants are correct"); - else - wlog("There were ${count} errors in the event status constants", ("count", error_count)); + return error_count == 0; + } + } // end anonymous namespace - return error_count == 0; -} -} // end anonymous namespace + event_status event_object::get_status() const + { + static bool state_constants_are_correct = verify_event_status_constants(); + (void)&state_constants_are_correct; + event_state state = (event_state)my->state_machine.current_state()[0]; -event_status event_object::get_status() const -{ - static bool state_constants_are_correct = verify_event_status_constants(); - (void)&state_constants_are_correct; - event_state state = (event_state)my->state_machine.current_state()[0]; + ddump((state)); - ddump((state)); + switch (state) + { + case event_state::upcoming: + return event_status::upcoming; + case event_state::frozen_upcoming: + case event_state::frozen_in_progress: + return event_status::frozen; + case event_state::in_progress: + return event_status::in_progress; + case event_state::finished: + return event_status::finished; + case event_state::canceled: + return event_status::canceled; + case event_state::settled: + return event_status::settled; + default: + FC_THROW("Unexpected event state"); + }; + } - switch (state) - { - case event_state::upcoming: - return event_status::upcoming; - case event_state::frozen_upcoming: - case event_state::frozen_in_progress: - return event_status::frozen; - case event_state::in_progress: - return event_status::in_progress; - case event_state::finished: - return event_status::finished; - case event_state::canceled: - return event_status::canceled; - case event_state::settled: - return event_status::settled; - default: - FC_THROW("Unexpected event state"); - }; -} + void event_object::pack_impl(std::ostream& stream) const + { + boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + oa << my->state_machine; + } -void event_object::pack_impl(std::ostream& stream) const -{ - boost::archive::binary_oarchive oa(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - oa << my->state_machine; -} + void event_object::unpack_impl(std::istream& stream) + { + boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); + ia >> my->state_machine; + } -void event_object::unpack_impl(std::istream& stream) -{ - boost::archive::binary_iarchive ia(stream, boost::archive::no_header|boost::archive::no_codecvt|boost::archive::no_xml_tag_checking); - ia >> my->state_machine; -} + void event_object::on_upcoming_event(database& db) + { + my->state_machine.process_event(upcoming_event(db)); + } -void event_object::on_upcoming_event(database& db) -{ - my->state_machine.process_event(upcoming_event(db)); -} + void event_object::on_in_progress_event(database& db) + { + my->state_machine.process_event(in_progress_event(db)); + } -void event_object::on_in_progress_event(database& db) -{ - my->state_machine.process_event(in_progress_event(db)); -} + void event_object::on_frozen_event(database& db) + { + my->state_machine.process_event(frozen_event(db)); + } -void event_object::on_frozen_event(database& db) -{ - my->state_machine.process_event(frozen_event(db)); -} + void event_object::on_finished_event(database& db) + { + my->state_machine.process_event(finished_event(db)); + } -void event_object::on_finished_event(database& db) -{ - my->state_machine.process_event(finished_event(db)); -} + void event_object::on_canceled_event(database& db) + { + my->state_machine.process_event(canceled_event(db)); + } -void event_object::on_canceled_event(database& db) -{ - my->state_machine.process_event(canceled_event(db)); -} + void event_object::on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled) + { + my->state_machine.process_event(betting_market_group_resolved_event(db, resolved_group, was_canceled)); + } -void event_object::on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled) -{ - my->state_machine.process_event(betting_market_group_resolved_event(db, resolved_group, was_canceled)); -} + void event_object::on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group) + { + my->state_machine.process_event(betting_market_group_closed_event(db, closed_group)); + } -void event_object::on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group) -{ - my->state_machine.process_event(betting_market_group_closed_event(db, closed_group)); -} - -// These are the only statuses that can be explicitly set by witness operations. The missing -// status, 'settled', is automatically set when all of the betting market groups have -// settled/canceled -void event_object::dispatch_new_status(database& db, event_status new_status) -{ - switch (new_status) { - case event_status::upcoming: // by witnesses to unfreeze a frozen event - on_upcoming_event(db); - break; - case event_status::in_progress: // by witnesses when the event starts - on_in_progress_event(db); - break; - case event_status::frozen: // by witnesses when the event needs to be frozen - on_frozen_event(db); - break; - case event_status::finished: // by witnesses when the event is complete - on_finished_event(db); - break; - case event_status::canceled: // by witnesses to cancel the event - on_canceled_event(db); - break; - default: - FC_THROW("Status ${new_status} cannot be explicitly set", ("new_status", new_status)); - } -} + // These are the only statuses that can be explicitly set by witness operations. The missing + // status, 'settled', is automatically set when all of the betting market groups have + // settled/canceled + void event_object::dispatch_new_status(database& db, event_status new_status) + { + switch (new_status) { + case event_status::upcoming: // by witnesses to unfreeze a frozen event + on_upcoming_event(db); + break; + case event_status::in_progress: // by witnesses when the event starts + on_in_progress_event(db); + break; + case event_status::frozen: // by witnesses when the event needs to be frozen + on_frozen_event(db); + break; + case event_status::finished: // by witnesses when the event is complete + on_finished_event(db); + break; + case event_status::canceled: // by witnesses to cancel the event + on_canceled_event(db); + break; + default: + FC_THROW("Status ${new_status} cannot be explicitly set", ("new_status", new_status)); + } + } } } // graphene::chain namespace fc { -// Manually reflect event_object to variant to properly reflect "state" -void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth) -{ - fc::mutable_variant_object o; - o("id", fc::variant(event_obj.id, max_depth)) - ("name", fc::variant(event_obj.name, max_depth)) - ("season", fc::variant(event_obj.season, max_depth)) - ("start_time", fc::variant(event_obj.start_time, max_depth)) - ("event_group_id", fc::variant(event_obj.event_group_id, max_depth)) - ("scores", fc::variant(event_obj.scores, max_depth)) - ("status", fc::variant(event_obj.get_status(), max_depth)); + // Manually reflect event_object to variant to properly reflect "state" + void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth) + { + fc::mutable_variant_object o; + o("id", fc::variant(event_obj.id, max_depth)) + ("name", fc::variant(event_obj.name, max_depth)) + ("season", fc::variant(event_obj.season, max_depth)) + ("start_time", fc::variant(event_obj.start_time, max_depth)) + ("event_group_id", fc::variant(event_obj.event_group_id, max_depth)) + ("scores", fc::variant(event_obj.scores, max_depth)) + ("status", fc::variant(event_obj.get_status(), max_depth)); - v = o; -} + v = o; + } -// Manually reflect event_object to variant to properly reflect "state" -void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth) -{ - event_obj.id = v["id"].as( max_depth ); - event_obj.name = v["name"].as( max_depth ); - event_obj.season = v["season"].as( max_depth ); - event_obj.start_time = v["start_time"].as >( max_depth ); - event_obj.event_group_id = v["event_group_id"].as( max_depth ); - event_obj.scores = v["scores"].as>( max_depth ); - graphene::chain::event_status status = v["status"].as( max_depth ); - const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; -} + // Manually reflect event_object to variant to properly reflect "state" + void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth) + { + event_obj.id = v["id"].as( max_depth ); + event_obj.name = v["name"].as( max_depth ); + event_obj.season = v["season"].as( max_depth ); + event_obj.start_time = v["start_time"].as >( max_depth ); + event_obj.event_group_id = v["event_group_id"].as( max_depth ); + event_obj.scores = v["scores"].as>( max_depth ); + graphene::chain::event_status status = v["status"].as( max_depth ); + const_cast(event_obj.my->state_machine.current_state())[0] = (int)status; + } } //end namespace fc diff --git a/libraries/chain/game_object.cpp b/libraries/chain/game_object.cpp index 88c0cf3c..4a35abfc 100644 --- a/libraries/chain/game_object.cpp +++ b/libraries/chain/game_object.cpp @@ -548,34 +548,36 @@ namespace graphene { namespace chain { } } // graphene::chain namespace fc { -// Manually reflect game_object to variant to properly reflect "state" -void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth) -{ - fc_elog(fc::logger::get("tournament"), "In game_obj to_variant"); - elog("In game_obj to_variant"); - fc::mutable_variant_object o; - o("id", fc::variant(game_obj.id, max_depth )) - ("match_id", fc::variant(game_obj.match_id, max_depth )) - ("players", fc::variant(game_obj.players, max_depth )) - ("winners", fc::variant(game_obj.winners, max_depth )) - ("game_details", fc::variant(game_obj.game_details, max_depth )) - ("next_timeout", fc::variant(game_obj.next_timeout, max_depth )) - ("state", fc::variant(game_obj.get_state(), max_depth )); + // Manually reflect game_object to variant to properly reflect "state" + void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth) + { + fc_elog(fc::logger::get("tournament"), "In game_obj to_variant"); + elog("In game_obj to_variant"); + fc::mutable_variant_object o; + o("id", fc::variant(game_obj.id, max_depth )) + ("match_id", fc::variant(game_obj.match_id, max_depth )) + ("players", fc::variant(game_obj.players, max_depth )) + ("winners", fc::variant(game_obj.winners, max_depth )) + ("game_details", fc::variant(game_obj.game_details, max_depth )) + ("next_timeout", fc::variant(game_obj.next_timeout, max_depth )) + ("state", fc::variant(game_obj.get_state(), max_depth )); - v = o; -} + v = o; + } -// Manually reflect game_object to variant to properly reflect "state" -void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth) -{ - fc_elog(fc::logger::get("tournament"), "In game_obj from_variant"); - game_obj.id = v["id"].as( max_depth ); - game_obj.match_id = v["match_id"].as( max_depth ); - game_obj.players = v["players"].as >( max_depth ); - game_obj.winners = v["winners"].as >( max_depth ); - game_obj.game_details = v["game_details"].as( max_depth ); - game_obj.next_timeout = v["next_timeout"].as >( max_depth ); - graphene::chain::game_state state = v["state"].as( max_depth ); - const_cast(game_obj.my->state_machine.current_state())[0] = (int)state; -} + // Manually reflect game_object to variant to properly reflect "state" + void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth) + { + fc_elog(fc::logger::get("tournament"), "In game_obj from_variant"); + game_obj.id = v["id"].as( max_depth ); + game_obj.match_id = v["match_id"].as( max_depth ); + game_obj.players = v["players"].as >( max_depth ); + game_obj.winners = v["winners"].as >( max_depth ); + game_obj.game_details = v["game_details"].as( max_depth ); + game_obj.next_timeout = v["next_timeout"].as >( max_depth ); + graphene::chain::game_state state = v["state"].as( max_depth ); + const_cast(game_obj.my->state_machine.current_state())[0] = (int)state; + } } //end namespace fc + + diff --git a/libraries/chain/include/graphene/chain/betting_market_object.hpp b/libraries/chain/include/graphene/chain/betting_market_object.hpp index e2d2d6e1..c16fe53d 100644 --- a/libraries/chain/include/graphene/chain/betting_market_object.hpp +++ b/libraries/chain/include/graphene/chain/betting_market_object.hpp @@ -31,15 +31,15 @@ #include namespace graphene { namespace chain { -class betting_market_object; -class betting_market_group_object; + class betting_market_object; + class betting_market_group_object; } } namespace fc { -void to_variant(const graphene::chain::betting_market_object& betting_market_obj, fc::variant& v, uint32_t max_depth = 1); -void from_variant(const fc::variant& v, graphene::chain::betting_market_object& betting_market_obj, uint32_t max_depth = 1); -void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth = 1); -void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth = 1); + void to_variant(const graphene::chain::betting_market_object& betting_market_obj, fc::variant& v, uint32_t max_depth = 1); + void from_variant(const fc::variant& v, graphene::chain::betting_market_object& betting_market_obj, uint32_t max_depth = 1); + void to_variant(const graphene::chain::betting_market_group_object& betting_market_group_obj, fc::variant& v, uint32_t max_depth = 1); + void from_variant(const fc::variant& v, graphene::chain::betting_market_group_object& betting_market_group_obj, uint32_t max_depth = 1); } //end namespace fc namespace graphene { namespace chain { @@ -722,100 +722,100 @@ FC_REFLECT_DERIVED( graphene::chain::betting_market_position_object, (graphene:: namespace fc { -template<> -template<> -inline void if_enum::from_variant(const variant &vo, graphene::chain::betting_market_object &v, uint32_t max_depth) { - from_variant(vo, v, max_depth); -} - -template<> -template<> -inline void if_enum::to_variant(const graphene::chain::betting_market_object &v, variant &vo, uint32_t max_depth) { - to_variant(v, vo, max_depth); -} - -namespace raw { namespace detail { - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::unpack(fc::datastream &s, graphene::chain::betting_market_object &v, uint32_t) { - s >> v; -} - -} } - -template <> -struct get_typename { - static const char *name() { - return "graphene::chain::betting_market_object"; + template<> + template<> + inline void if_enum::from_variant(const variant &vo, graphene::chain::betting_market_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); } -}; -template <> -struct reflector { - typedef graphene::chain::betting_market_object type; - typedef fc::true_type is_defined; - typedef fc::false_type is_enum; -}; + + template<> + template<> + inline void if_enum::to_variant(const graphene::chain::betting_market_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); + } + + namespace raw { namespace detail { + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::unpack(fc::datastream &s, graphene::chain::betting_market_object &v, uint32_t) { + s >> v; + } + + } } // namespace fc::raw::detail + + template <> + struct get_typename { + static const char *name() { + return "graphene::chain::betting_market_object"; + } + }; + template <> + struct reflector { + typedef graphene::chain::betting_market_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; + }; } // namespace fc namespace fc { -template<> -template<> -inline void if_enum::from_variant(const variant &vo, graphene::chain::betting_market_group_object &v, uint32_t max_depth) { - from_variant(vo, v, max_depth); -} - -template<> -template<> -inline void if_enum::to_variant(const graphene::chain::betting_market_group_object &v, variant &vo, uint32_t max_depth) { - to_variant(v, vo, max_depth); -} - -namespace raw { namespace detail { - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_group_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_group_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::unpack(fc::datastream &s, graphene::chain::betting_market_group_object &v, uint32_t) { - s >> v; -} - -} } - -template <> -struct get_typename { - static const char *name() { - return "graphene::chain::betting_market_group_object"; + template<> + template<> + inline void if_enum::from_variant(const variant &vo, graphene::chain::betting_market_group_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); } -}; -template <> -struct reflector { - typedef graphene::chain::betting_market_group_object type; - typedef fc::true_type is_defined; - typedef fc::false_type is_enum; -}; + + template<> + template<> + inline void if_enum::to_variant(const graphene::chain::betting_market_group_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); + } + + namespace raw { namespace detail { + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_group_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::betting_market_group_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::unpack(fc::datastream &s, graphene::chain::betting_market_group_object &v, uint32_t) { + s >> v; + } + + } } // namespace fc::raw:detail + + template <> + struct get_typename { + static const char *name() { + return "graphene::chain::betting_market_group_object"; + } + }; + template <> + struct reflector { + typedef graphene::chain::betting_market_group_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; + }; } // namespace fc diff --git a/libraries/chain/include/graphene/chain/event_object.hpp b/libraries/chain/include/graphene/chain/event_object.hpp index 30c6d5ca..ff75c286 100644 --- a/libraries/chain/include/graphene/chain/event_object.hpp +++ b/libraries/chain/include/graphene/chain/event_object.hpp @@ -1,26 +1,26 @@ /* -* Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. -*/ + * Copyright (c) 2018 Peerplays Blockchain Standards Association, 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. + */ #pragma once #include @@ -32,12 +32,12 @@ #include namespace graphene { namespace chain { -class event_object; + class event_object; } } namespace fc { -void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth = 1); -void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth = 1); + void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth = 1); + void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth = 1); } //end namespace fc namespace graphene { namespace chain { @@ -46,165 +46,165 @@ class database; class event_object : public graphene::db::abstract_object< event_object > { -public: - static const uint8_t space_id = protocol_ids; - static const uint8_t type_id = event_object_type; + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = event_object_type; - event_object(); - event_object(const event_object& rhs); - ~event_object(); - event_object& operator=(const event_object& rhs); + event_object(); + event_object(const event_object& rhs); + ~event_object(); + event_object& operator=(const event_object& rhs); - internationalized_string_type name; + internationalized_string_type name; - internationalized_string_type season; + internationalized_string_type season; - optional start_time; + optional start_time; - event_group_id_type event_group_id; + event_group_id_type event_group_id; - bool at_least_one_betting_market_group_settled; + bool at_least_one_betting_market_group_settled; - event_status get_status() const; - vector scores; + event_status get_status() const; + vector scores; - // serialization functions: - // for serializing to raw, go through a temporary sstream object to avoid - // having to implement serialization in the header file - template - friend Stream& operator<<( Stream& s, const event_object& event_obj ); + // serialization functions: + // for serializing to raw, go through a temporary sstream object to avoid + // having to implement serialization in the header file + template + friend Stream& operator<<( Stream& s, const event_object& event_obj ); - template - friend Stream& operator>>( Stream& s, event_object& event_obj ); + template + friend Stream& operator>>( Stream& s, event_object& event_obj ); - friend void ::fc::to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth); - friend void ::fc::from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth); + friend void ::fc::to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth); + friend void ::fc::from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth); - void pack_impl(std::ostream& stream) const; - void unpack_impl(std::istream& stream); + void pack_impl(std::ostream& stream) const; + void unpack_impl(std::istream& stream); - void on_upcoming_event(database& db); - void on_in_progress_event(database& db); - void on_frozen_event(database& db); - void on_finished_event(database& db); - void on_canceled_event(database& db); - void on_settled_event(database& db); - void on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled); - void on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group); - void dispatch_new_status(database& db, event_status new_status); -private: - class impl; - std::unique_ptr my; + void on_upcoming_event(database& db); + void on_in_progress_event(database& db); + void on_frozen_event(database& db); + void on_finished_event(database& db); + void on_canceled_event(database& db); + void on_settled_event(database& db); + void on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled); + void on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group); + void dispatch_new_status(database& db, event_status new_status); + private: + class impl; + std::unique_ptr my; }; struct by_event_group_id; struct by_event_status; typedef multi_index_container< - event_object, - indexed_by< - ordered_unique< tag, member< object, object_id_type, &object::id > >, - ordered_unique< tag, composite_key, - member > >, - ordered_unique< tag, composite_key, - member > > > > event_object_multi_index_type; + event_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, composite_key, + member > >, + ordered_unique< tag, composite_key, + member > > > > event_object_multi_index_type; typedef generic_index event_object_index; -template -inline Stream& operator<<( Stream& s, const event_object& event_obj ) -{ - fc_elog(fc::logger::get("event"), "In event_obj to_raw"); - // pack all fields exposed in the header in the usual way - // instead of calling the derived pack, just serialize the one field in the base class - // fc::raw::pack >(s, event_obj); - fc::raw::pack(s, event_obj.id); - fc::raw::pack(s, event_obj.name); - fc::raw::pack(s, event_obj.season); - fc::raw::pack(s, event_obj.start_time); - fc::raw::pack(s, event_obj.event_group_id); - fc::raw::pack(s, event_obj.at_least_one_betting_market_group_settled); - fc::raw::pack(s, event_obj.scores); + template + inline Stream& operator<<( Stream& s, const event_object& event_obj ) + { + fc_elog(fc::logger::get("event"), "In event_obj to_raw"); + // pack all fields exposed in the header in the usual way + // instead of calling the derived pack, just serialize the one field in the base class + // fc::raw::pack >(s, event_obj); + fc::raw::pack(s, event_obj.id); + fc::raw::pack(s, event_obj.name); + fc::raw::pack(s, event_obj.season); + fc::raw::pack(s, event_obj.start_time); + fc::raw::pack(s, event_obj.event_group_id); + fc::raw::pack(s, event_obj.at_least_one_betting_market_group_settled); + fc::raw::pack(s, event_obj.scores); - // fc::raw::pack the contents hidden in the impl class - std::ostringstream stream; - event_obj.pack_impl(stream); - std::string stringified_stream(stream.str()); - fc::raw::pack(s, stream.str()); + // fc::raw::pack the contents hidden in the impl class + std::ostringstream stream; + event_obj.pack_impl(stream); + std::string stringified_stream(stream.str()); + fc::raw::pack(s, stream.str()); - return s; -} -template -inline Stream& operator>>( Stream& s, event_object& event_obj ) -{ - fc_elog(fc::logger::get("event"), "In event_obj from_raw"); - // unpack all fields exposed in the header in the usual way - //fc::raw::unpack >(s, event_obj); - fc::raw::unpack(s, event_obj.id); - fc::raw::unpack(s, event_obj.name); - fc::raw::unpack(s, event_obj.season); - fc::raw::unpack(s, event_obj.start_time); - fc::raw::unpack(s, event_obj.event_group_id); - fc::raw::unpack(s, event_obj.at_least_one_betting_market_group_settled); - fc::raw::unpack(s, event_obj.scores); + return s; + } + template + inline Stream& operator>>( Stream& s, event_object& event_obj ) + { + fc_elog(fc::logger::get("event"), "In event_obj from_raw"); + // unpack all fields exposed in the header in the usual way + //fc::raw::unpack >(s, event_obj); + fc::raw::unpack(s, event_obj.id); + fc::raw::unpack(s, event_obj.name); + fc::raw::unpack(s, event_obj.season); + fc::raw::unpack(s, event_obj.start_time); + fc::raw::unpack(s, event_obj.event_group_id); + fc::raw::unpack(s, event_obj.at_least_one_betting_market_group_settled); + fc::raw::unpack(s, event_obj.scores); - // fc::raw::unpack the contents hidden in the impl class - std::string stringified_stream; - fc::raw::unpack(s, stringified_stream); - std::istringstream stream(stringified_stream); - event_obj.unpack_impl(stream); + // fc::raw::unpack the contents hidden in the impl class + std::string stringified_stream; + fc::raw::unpack(s, stringified_stream); + std::istringstream stream(stringified_stream); + event_obj.unpack_impl(stream); - return s; -} + return s; + } } } // graphene::chain namespace fc { -template<> -template<> -inline void if_enum::from_variant(const variant &vo, graphene::chain::event_object &v, uint32_t max_depth) { - from_variant(vo, v, max_depth); -} - -template<> -template<> -inline void if_enum::to_variant(const graphene::chain::event_object &v, variant &vo, uint32_t max_depth) { - to_variant(v, vo, max_depth); -} - -namespace raw { namespace detail { - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::event_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::event_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::unpack(fc::datastream &s, graphene::chain::event_object &v, uint32_t) { - s >> v; -} - -} } - -template <> -struct get_typename { - static const char *name() { - return "graphene::chain::event_object"; + template<> + template<> + inline void if_enum::from_variant(const variant &vo, graphene::chain::event_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); } -}; -template <> -struct reflector { - typedef graphene::chain::event_object type; - typedef fc::true_type is_defined; - typedef fc::false_type is_enum; -}; -} // namespace fc \ No newline at end of file + + template<> + template<> + inline void if_enum::to_variant(const graphene::chain::event_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); + } + + namespace raw { namespace detail { + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::event_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::event_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::unpack(fc::datastream &s, graphene::chain::event_object &v, uint32_t) { + s >> v; + } + + } } // namespace fc::raw::detail + + template <> + struct get_typename { + static const char *name() { + return "graphene::chain::event_object"; + } + }; + template <> + struct reflector { + typedef graphene::chain::event_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; + }; +} // namespace fc diff --git a/libraries/chain/include/graphene/chain/game_object.hpp b/libraries/chain/include/graphene/chain/game_object.hpp index cca9ea5e..cf31e49d 100644 --- a/libraries/chain/include/graphene/chain/game_object.hpp +++ b/libraries/chain/include/graphene/chain/game_object.hpp @@ -30,12 +30,12 @@ #include namespace graphene { namespace chain { -class game_object; + class game_object; } } namespace fc { -void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth = 1); -void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth = 1); + void to_variant(const graphene::chain::game_object& game_obj, fc::variant& v, uint32_t max_depth = 1); + void from_variant(const fc::variant& v, graphene::chain::game_object& game_obj, uint32_t max_depth = 1); } //end namespace fc namespace graphene { namespace chain { @@ -164,50 +164,50 @@ FC_REFLECT_ENUM(graphene::chain::game_state, namespace fc { -template<> -template<> -inline void if_enum::from_variant(const variant &vo, graphene::chain::game_object &v, uint32_t max_depth) { - from_variant(vo, v, max_depth); -} - -template<> -template<> -inline void if_enum::to_variant(const graphene::chain::game_object &v, variant &vo, uint32_t max_depth) { - to_variant(v, vo, max_depth); -} - -namespace raw { namespace detail { - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::game_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::game_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::unpack(fc::datastream &s, graphene::chain::game_object &v, uint32_t) { - s >> v; -} - -} } - -template <> -struct get_typename { - static const char *name() { - return "graphene::chain::game_object"; + template<> + template<> + inline void if_enum::from_variant(const variant &vo, graphene::chain::game_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); } -}; -template <> -struct reflector { - typedef graphene::chain::game_object type; - typedef fc::true_type is_defined; - typedef fc::false_type is_enum; -}; -} // namespace fc \ No newline at end of file + + template<> + template<> + inline void if_enum::to_variant(const graphene::chain::game_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); + } + + namespace raw { namespace detail { + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::game_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::game_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::unpack(fc::datastream &s, graphene::chain::game_object &v, uint32_t) { + s >> v; + } + + } } // namespace fc::raw::detail + + template <> + struct get_typename { + static const char *name() { + return "graphene::chain::game_object"; + } + }; + template <> + struct reflector { + typedef graphene::chain::game_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; + }; +} // namespace fc diff --git a/libraries/chain/include/graphene/chain/match_object.hpp b/libraries/chain/include/graphene/chain/match_object.hpp index e1194e1e..33df4d01 100644 --- a/libraries/chain/include/graphene/chain/match_object.hpp +++ b/libraries/chain/include/graphene/chain/match_object.hpp @@ -5,12 +5,12 @@ #include namespace graphene { namespace chain { -class match_object; + class match_object; } } namespace fc { -void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth = 1); -void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth = 1); + void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth = 1); + void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth = 1); } //end namespace fc @@ -162,50 +162,50 @@ FC_REFLECT_ENUM(graphene::chain::match_state, namespace fc { -template<> -template<> -inline void if_enum::from_variant(const variant &vo, graphene::chain::match_object &v, uint32_t max_depth) { - from_variant(vo, v, max_depth); -} - -template<> -template<> -inline void if_enum::to_variant(const graphene::chain::match_object &v, variant &vo, uint32_t max_depth) { - to_variant(v, vo, max_depth); -} - -namespace raw { namespace detail { - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::match_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::match_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::unpack(fc::datastream &s, graphene::chain::match_object &v, uint32_t) { - s >> v; -} - -} } - -template <> -struct get_typename { - static const char *name() { - return "graphene::chain::match_object"; + template<> + template<> + inline void if_enum::from_variant(const variant &vo, graphene::chain::match_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); } -}; -template <> -struct reflector { - typedef graphene::chain::match_object type; - typedef fc::true_type is_defined; - typedef fc::false_type is_enum; -}; -} // namespace fc \ No newline at end of file + + template<> + template<> + inline void if_enum::to_variant(const graphene::chain::match_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); + } + + namespace raw { namespace detail { + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::match_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::match_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::unpack(fc::datastream &s, graphene::chain::match_object &v, uint32_t) { + s >> v; + } + + } } // namespace fc::raw::detail + + template <> + struct get_typename { + static const char *name() { + return "graphene::chain::match_object"; + } + }; + template <> + struct reflector { + typedef graphene::chain::match_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; + }; +} // namespace fc diff --git a/libraries/chain/include/graphene/chain/tournament_object.hpp b/libraries/chain/include/graphene/chain/tournament_object.hpp index f3c8e610..53ac3876 100644 --- a/libraries/chain/include/graphene/chain/tournament_object.hpp +++ b/libraries/chain/include/graphene/chain/tournament_object.hpp @@ -7,12 +7,12 @@ #include namespace graphene { namespace chain { -class tournament_object; + class tournament_object; } } namespace fc { -void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth = 1); -void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth = 1); + void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth = 1); + void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth = 1); } //end namespace fc namespace graphene { namespace chain { @@ -247,50 +247,50 @@ FC_REFLECT_ENUM(graphene::chain::tournament_state, namespace fc { -template<> -template<> -inline void if_enum::from_variant(const variant &vo, graphene::chain::tournament_object &v, uint32_t max_depth) { - from_variant(vo, v, max_depth); -} - -template<> -template<> -inline void if_enum::to_variant(const graphene::chain::tournament_object &v, variant &vo, uint32_t max_depth) { - to_variant(v, vo, max_depth); -} - -namespace raw { namespace detail { - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::tournament_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::pack(fc::datastream &s, const graphene::chain::tournament_object &v, uint32_t) { - s << v; -} - -template<> -template<> -inline void if_enum::unpack(fc::datastream &s, graphene::chain::tournament_object &v, uint32_t) { - s >> v; -} - -} } - -template <> -struct get_typename { - static const char *name() { - return "graphene::chain::tournament_object"; + template<> + template<> + inline void if_enum::from_variant(const variant &vo, graphene::chain::tournament_object &v, uint32_t max_depth) { + from_variant(vo, v, max_depth); } -}; -template <> -struct reflector { - typedef graphene::chain::tournament_object type; - typedef fc::true_type is_defined; - typedef fc::false_type is_enum; -}; -} // namespace fc \ No newline at end of file + + template<> + template<> + inline void if_enum::to_variant(const graphene::chain::tournament_object &v, variant &vo, uint32_t max_depth) { + to_variant(v, vo, max_depth); + } + + namespace raw { namespace detail { + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::tournament_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::pack(fc::datastream &s, const graphene::chain::tournament_object &v, uint32_t) { + s << v; + } + + template<> + template<> + inline void if_enum::unpack(fc::datastream &s, graphene::chain::tournament_object &v, uint32_t) { + s >> v; + } + + } } // namespace fc::raw::detail + + template <> + struct get_typename { + static const char *name() { + return "graphene::chain::tournament_object"; + } + }; + template <> + struct reflector { + typedef graphene::chain::tournament_object type; + typedef fc::true_type is_defined; + typedef fc::false_type is_enum; + }; +} // namespace fc diff --git a/libraries/chain/match_object.cpp b/libraries/chain/match_object.cpp index 46313bff..c9e8ccb9 100644 --- a/libraries/chain/match_object.cpp +++ b/libraries/chain/match_object.cpp @@ -363,30 +363,30 @@ namespace graphene { namespace chain { } } // graphene::chain namespace fc { -// Manually reflect match_object to variant to properly reflect "state" -void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth) -{ try { + // Manually reflect match_object to variant to properly reflect "state" + void to_variant(const graphene::chain::match_object& match_obj, fc::variant& v, uint32_t max_depth) + { try { fc_elog(fc::logger::get("tournament"), "In match_obj to_variant"); elog("In match_obj to_variant"); fc::mutable_variant_object o; o("id", fc::variant(match_obj.id, max_depth)) - ("tournament_id", fc::variant(match_obj.tournament_id, max_depth)) - ("players", fc::variant(match_obj.players, max_depth)) - ("games", fc::variant(match_obj.games, max_depth)) - ("game_winners", fc::variant(match_obj.game_winners, max_depth)) - ("number_of_wins", fc::variant(match_obj.number_of_wins, max_depth)) - ("number_of_ties", fc::variant(match_obj.number_of_ties, max_depth)) - ("match_winners", fc::variant(match_obj.match_winners, max_depth)) - ("start_time", fc::variant(match_obj.start_time, max_depth)) - ("end_time", fc::variant(match_obj.end_time, max_depth)) - ("state", fc::variant(match_obj.get_state(), max_depth)); + ("tournament_id", fc::variant(match_obj.tournament_id, max_depth)) + ("players", fc::variant(match_obj.players, max_depth)) + ("games", fc::variant(match_obj.games, max_depth)) + ("game_winners", fc::variant(match_obj.game_winners, max_depth)) + ("number_of_wins", fc::variant(match_obj.number_of_wins, max_depth)) + ("number_of_ties", fc::variant(match_obj.number_of_ties, max_depth)) + ("match_winners", fc::variant(match_obj.match_winners, max_depth)) + ("start_time", fc::variant(match_obj.start_time, max_depth)) + ("end_time", fc::variant(match_obj.end_time, max_depth)) + ("state", fc::variant(match_obj.get_state(), max_depth)); v = o; } FC_RETHROW_EXCEPTIONS(warn, "") } -// Manually reflect match_object to variant to properly reflect "state" -void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth) -{ try { + // Manually reflect match_object to variant to properly reflect "state" + void from_variant(const fc::variant& v, graphene::chain::match_object& match_obj, uint32_t max_depth) + { try { fc_elog(fc::logger::get("tournament"), "In match_obj from_variant"); match_obj.id = v["id"].as( max_depth ); match_obj.tournament_id = v["tournament_id"].as( max_depth ); diff --git a/libraries/chain/tournament_object.cpp b/libraries/chain/tournament_object.cpp index 680943bd..0d9ef969 100644 --- a/libraries/chain/tournament_object.cpp +++ b/libraries/chain/tournament_object.cpp @@ -722,41 +722,40 @@ namespace graphene { namespace chain { } } // graphene::chain namespace fc { -// Manually reflect tournament_object to variant to properly reflect "state" -void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth) -{ - fc_elog(fc::logger::get("tournament"), "In tournament_obj to_variant"); - elog("In tournament_obj to_variant"); - fc::mutable_variant_object o; - o("id", fc::variant(tournament_obj.id, max_depth)) - ("creator", fc::variant(tournament_obj.creator, max_depth)) - ("options", fc::variant(tournament_obj.options, max_depth)) - ("start_time", fc::variant(tournament_obj.start_time, max_depth)) - ("end_time", fc::variant(tournament_obj.end_time, max_depth)) - ("prize_pool", fc::variant(tournament_obj.prize_pool, max_depth)) - ("registered_players", fc::variant(tournament_obj.registered_players, max_depth)) - ("tournament_details_id", fc::variant(tournament_obj.tournament_details_id, max_depth)) - ("state", fc::variant(tournament_obj.get_state(), max_depth)); + // Manually reflect tournament_object to variant to properly reflect "state" + void to_variant(const graphene::chain::tournament_object& tournament_obj, fc::variant& v, uint32_t max_depth) + { + fc_elog(fc::logger::get("tournament"), "In tournament_obj to_variant"); + elog("In tournament_obj to_variant"); + fc::mutable_variant_object o; + o("id", fc::variant(tournament_obj.id, max_depth)) + ("creator", fc::variant(tournament_obj.creator, max_depth)) + ("options", fc::variant(tournament_obj.options, max_depth)) + ("start_time", fc::variant(tournament_obj.start_time, max_depth)) + ("end_time", fc::variant(tournament_obj.end_time, max_depth)) + ("prize_pool", fc::variant(tournament_obj.prize_pool, max_depth)) + ("registered_players", fc::variant(tournament_obj.registered_players, max_depth)) + ("tournament_details_id", fc::variant(tournament_obj.tournament_details_id, max_depth)) + ("state", fc::variant(tournament_obj.get_state(), max_depth)); - v = o; -} + v = o; + } -// Manually reflect tournament_object to variant to properly reflect "state" -void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth) -{ - fc_elog(fc::logger::get("tournament"), "In tournament_obj from_variant"); - tournament_obj.id = v["id"].as( max_depth ); - tournament_obj.creator = v["creator"].as( max_depth ); - tournament_obj.options = v["options"].as( max_depth ); - tournament_obj.start_time = v["start_time"].as >( max_depth ); - tournament_obj.end_time = v["end_time"].as >( max_depth ); - tournament_obj.prize_pool = v["prize_pool"].as( max_depth ); - tournament_obj.registered_players = v["registered_players"].as( max_depth ); - tournament_obj.tournament_details_id = v["tournament_details_id"].as( max_depth ); - graphene::chain::tournament_state state = v["state"].as( max_depth ); - const_cast(tournament_obj.my->state_machine.current_state())[0] = (int)state; -} + // Manually reflect tournament_object to variant to properly reflect "state" + void from_variant(const fc::variant& v, graphene::chain::tournament_object& tournament_obj, uint32_t max_depth) + { + fc_elog(fc::logger::get("tournament"), "In tournament_obj from_variant"); + tournament_obj.id = v["id"].as( max_depth ); + tournament_obj.creator = v["creator"].as( max_depth ); + tournament_obj.options = v["options"].as( max_depth ); + tournament_obj.start_time = v["start_time"].as >( max_depth ); + tournament_obj.end_time = v["end_time"].as >( max_depth ); + tournament_obj.prize_pool = v["prize_pool"].as( max_depth ); + tournament_obj.registered_players = v["registered_players"].as( max_depth ); + tournament_obj.tournament_details_id = v["tournament_details_id"].as( max_depth ); + graphene::chain::tournament_state state = v["state"].as( max_depth ); + const_cast(tournament_obj.my->state_machine.current_state())[0] = (int)state; + } } //end namespace fc - -- 2.45.2