From 4267e6323a3c1ca66c7e36059d061b3094117718 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Wed, 16 Feb 2022 13:00:47 +0300 Subject: [PATCH] #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 -