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 )