#235 Add custom funtions for betting_market_object and betting_market_group_object
This commit is contained in:
parent
37c9b057df
commit
1d32b18102
3 changed files with 321 additions and 7 deletions
|
|
@ -30,6 +30,8 @@
|
|||
|
||||
#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 {
|
||||
|
|
@ -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<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
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#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 {
|
||||
|
|
@ -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<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
|
||||
|
|
@ -27,8 +27,20 @@
|
|||
#include <graphene/chain/protocol/betting_market.hpp>
|
||||
#include <graphene/db/object.hpp>
|
||||
#include <graphene/db/generic_index.hpp>
|
||||
|
||||
#include <boost/multi_index/composite_key.hpp>
|
||||
#include <sstream>
|
||||
|
||||
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<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);
|
||||
|
|
@ -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<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);
|
||||
|
|
@ -582,16 +624,198 @@ 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) )
|
||||
|
||||
namespace fc {
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void if_enum<fc::false_type>::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<fc::false_type>::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<fc::false_type>::pack(fc::datastream<size_t> &s, const graphene::chain::betting_market_object &v, uint32_t) {
|
||||
s << v;
|
||||
}
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void if_enum<fc::false_type>::pack(fc::datastream<char*> &s, const graphene::chain::betting_market_object &v, uint32_t) {
|
||||
s << v;
|
||||
}
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void if_enum<fc::false_type>::unpack(fc::datastream<const char*> &s, graphene::chain::betting_market_object &v, uint32_t) {
|
||||
s >> v;
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
template <>
|
||||
struct get_typename<graphene::chain::betting_market_object> {
|
||||
static const char *name() {
|
||||
return "graphene::chain::betting_market_object";
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct reflector<graphene::chain::betting_market_object> {
|
||||
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<fc::false_type>::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<fc::false_type>::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<fc::false_type>::pack(fc::datastream<size_t> &s, const graphene::chain::betting_market_group_object &v, uint32_t) {
|
||||
s << v;
|
||||
}
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void if_enum<fc::false_type>::pack(fc::datastream<char*> &s, const graphene::chain::betting_market_group_object &v, uint32_t) {
|
||||
s << v;
|
||||
}
|
||||
|
||||
template<>
|
||||
template<>
|
||||
inline void if_enum<fc::false_type>::unpack(fc::datastream<const char*> &s, graphene::chain::betting_market_group_object &v, uint32_t) {
|
||||
s >> v;
|
||||
}
|
||||
|
||||
} }
|
||||
|
||||
template <>
|
||||
struct get_typename<graphene::chain::betting_market_group_object> {
|
||||
static const char *name() {
|
||||
return "graphene::chain::betting_market_group_object";
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct reflector<graphene::chain::betting_market_group_object> {
|
||||
typedef graphene::chain::betting_market_group_object type;
|
||||
typedef fc::true_type is_defined;
|
||||
typedef fc::false_type is_enum;
|
||||
};
|
||||
} // namespace fc
|
||||
|
|
|
|||
Loading…
Reference in a new issue