#235 betting_market_object : delete custom variant and Stream operator functions

This commit is contained in:
Vlad Dobromyslov 2022-02-16 13:04:00 +03:00
parent 42504ab65b
commit 3f205a5722
4 changed files with 9 additions and 225 deletions

View file

@ -30,8 +30,6 @@
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/msm/back/tools.hpp>
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<graphene::chain::betting_market_group_id_type>( max_depth );
betting_market_group_obj.description = v["description"].as<graphene::chain::internationalized_string_type>( max_depth );
betting_market_group_obj.event_id = v["event_id"].as<graphene::chain::event_id_type>( max_depth );
betting_market_group_obj.asset_id = v["asset_id"].as<graphene::chain::asset_id_type>( max_depth );
betting_market_group_obj.total_matched_bets_amount = v["total_matched_bets_amount"].as<graphene::chain::share_type>( max_depth );
betting_market_group_obj.never_in_play = v["never_in_play"].as<bool>( max_depth );
betting_market_group_obj.delay_before_settling = v["delay_before_settling"].as<uint32_t>( max_depth );
betting_market_group_obj.settling_time = v["settling_time"].as<fc::optional<fc::time_point_sec>>( max_depth );
graphene::chain::betting_market_group_status status = v["status"].as<graphene::chain::betting_market_group_status>( max_depth );
const_cast<int*>(betting_market_group_obj.my->state_machine.current_state())[0] = (int)status;
}
} //end namespace fc

View file

@ -29,8 +29,6 @@
#include <boost/msm/back/state_machine.hpp>
#include <boost/msm/front/state_machine_def.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/msm/back/tools.hpp>
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<graphene::chain::betting_market_id_type>( max_depth );
event_obj.group_id = v["name"].as<graphene::chain::betting_market_group_id_type>( max_depth );
event_obj.description = v["description"].as<graphene::chain::internationalized_string_type>( max_depth );
event_obj.payout_condition = v["payout_condition"].as<graphene::chain::internationalized_string_type>( max_depth );
event_obj.resolution = v["resolution"].as<fc::optional<graphene::chain::betting_market_resolution_type>>( max_depth );
graphene::chain::betting_market_status status = v["status"].as<graphene::chain::betting_market_status>( max_depth );
const_cast<int*>(event_obj.my->state_machine.current_state())[0] = (int)status;
}
} //end namespace fc

View file

@ -24,25 +24,12 @@
#pragma once
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/protocol/betting_market.hpp>
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>
#include <graphene/chain/protocol/betting_market.hpp>
#include <sstream>
#include <boost/multi_index/composite_key.hpp>
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<typename Stream>
friend Stream& operator<<( Stream& s, const betting_market_group_object& betting_market_group_obj );
template<typename Stream>
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<typename Stream>
friend Stream& operator<<( Stream& s, const betting_market_object& betting_market_obj );
template<typename Stream>
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_object, betting_market_position_multi_index_type> betting_market_position_index;
template<typename Stream>
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<Stream, const graphene::db::abstract_object<betting_market_object> >(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<typename Stream>
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<Stream, graphene::db::abstract_object<betting_market_object> >(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<typename Stream>
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<Stream, const graphene::db::abstract_object<betting_market_group_object> >(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<typename Stream>
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<Stream, graphene::db::abstract_object<betting_market_group_object> >(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) )

View file

@ -47,6 +47,7 @@
#include <graphene/chain/tournament_object.hpp>
#include <graphene/chain/event_object.hpp>
#include <graphene/chain/match_object.hpp>
#include <graphene/chain/betting_market_object.hpp>
#include <fc/io/raw.hpp>
@ -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 )