#235 tournament_object : delete custom variant and Stream operator functions
This commit is contained in:
parent
065c9d1546
commit
4267e6323a
3 changed files with 5 additions and 134 deletions
|
|
@ -1,20 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <graphene/chain/protocol/tournament.hpp>
|
#include <graphene/chain/protocol/tournament.hpp>
|
||||||
#include <graphene/chain/rock_paper_scissors.hpp>
|
|
||||||
#include <boost/multi_index/composite_key.hpp>
|
#include <boost/multi_index/composite_key.hpp>
|
||||||
#include <graphene/db/flat_index.hpp>
|
#include <graphene/db/object.hpp>
|
||||||
#include <graphene/db/generic_index.hpp>
|
#include <graphene/db/generic_index.hpp>
|
||||||
#include <fc/crypto/hex.hpp>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
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 {
|
namespace graphene { namespace chain {
|
||||||
class database;
|
class database;
|
||||||
|
|
@ -99,21 +87,6 @@ namespace graphene { namespace chain {
|
||||||
|
|
||||||
time_point_sec get_registration_deadline() const { return options.registration_deadline; }
|
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<typename Stream>
|
|
||||||
friend Stream& operator<<( Stream& s, const tournament_object& tournament_obj );
|
|
||||||
|
|
||||||
template<typename Stream>
|
|
||||||
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
|
/// called by database maintenance code when registration for this contest has expired
|
||||||
void on_registration_deadline_passed(database& db);
|
void on_registration_deadline_passed(database& db);
|
||||||
void on_player_registered(database& db, account_id_type payer_id, account_id_type player_id);
|
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;
|
> tournament_details_object_multi_index_type;
|
||||||
typedef generic_index<tournament_details_object, tournament_details_object_multi_index_type> tournament_details_index;
|
typedef generic_index<tournament_details_object, tournament_details_object_multi_index_type> tournament_details_index;
|
||||||
|
|
||||||
|
|
||||||
template<typename Stream>
|
|
||||||
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<Stream, const graphene::db::abstract_object<tournament_object> >(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<typename Stream>
|
|
||||||
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<Stream, graphene::db::abstract_object<tournament_object> >(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
|
* @brief This secondary index will allow a reverse lookup of all tournaments
|
||||||
* a particular account has registered for. This will be attached
|
* a particular account has registered for. This will be attached
|
||||||
|
|
@ -230,8 +150,6 @@ namespace graphene { namespace chain {
|
||||||
|
|
||||||
flat_set<account_id_type> before_account_ids;
|
flat_set<account_id_type> before_account_ids;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
||||||
FC_REFLECT_DERIVED(graphene::chain::tournament_details_object, (graphene::db::object),
|
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)
|
(registered_players)
|
||||||
(tournament_details_id))
|
(tournament_details_id))
|
||||||
|
|
||||||
|
GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::tournament_object )
|
||||||
|
|
||||||
FC_REFLECT_ENUM(graphene::chain::tournament_state,
|
FC_REFLECT_ENUM(graphene::chain::tournament_state,
|
||||||
(accepting_registrations)
|
(accepting_registrations)
|
||||||
(awaiting_start)
|
(awaiting_start)
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@
|
||||||
#include <graphene/chain/witness_schedule_object.hpp>
|
#include <graphene/chain/witness_schedule_object.hpp>
|
||||||
#include <graphene/chain/witness_scheduler.hpp>
|
#include <graphene/chain/witness_scheduler.hpp>
|
||||||
#include <graphene/chain/worker_object.hpp>
|
#include <graphene/chain/worker_object.hpp>
|
||||||
|
#include <graphene/chain/tournament_object.hpp>
|
||||||
|
|
||||||
#include <fc/io/raw.hpp>
|
#include <fc/io/raw.hpp>
|
||||||
|
|
||||||
|
|
@ -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_scheduler )
|
||||||
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedule_object )
|
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::worker_object )
|
||||||
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::tournament_object )
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,6 @@
|
||||||
|
|
||||||
#include <boost/msm/back/state_machine.hpp>
|
#include <boost/msm/back/state_machine.hpp>
|
||||||
#include <boost/msm/front/state_machine_def.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>
|
#include <boost/msm/back/tools.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
@ -533,18 +531,6 @@ namespace graphene { namespace chain {
|
||||||
return state;
|
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)
|
void tournament_object::on_registration_deadline_passed(database& db)
|
||||||
{
|
{
|
||||||
my->state_machine.process_event(registration_deadline_passed(db));
|
my->state_machine.process_event(registration_deadline_passed(db));
|
||||||
|
|
@ -721,41 +707,4 @@ namespace graphene { namespace chain {
|
||||||
}
|
}
|
||||||
} } // graphene::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<graphene::chain::tournament_id_type>( max_depth );
|
|
||||||
tournament_obj.creator = v["creator"].as<graphene::chain::account_id_type>( max_depth );
|
|
||||||
tournament_obj.options = v["options"].as<graphene::chain::tournament_options>( max_depth );
|
|
||||||
tournament_obj.start_time = v["start_time"].as<optional<time_point_sec> >( max_depth );
|
|
||||||
tournament_obj.end_time = v["end_time"].as<optional<time_point_sec> >( max_depth );
|
|
||||||
tournament_obj.prize_pool = v["prize_pool"].as<graphene::chain::share_type>( max_depth );
|
|
||||||
tournament_obj.registered_players = v["registered_players"].as<uint32_t>( max_depth );
|
|
||||||
tournament_obj.tournament_details_id = v["tournament_details_id"].as<graphene::chain::tournament_details_id_type>( max_depth );
|
|
||||||
graphene::chain::tournament_state state = v["state"].as<graphene::chain::tournament_state>( max_depth );
|
|
||||||
const_cast<int*>(tournament_obj.my->state_machine.current_state())[0] = (int)state;
|
|
||||||
}
|
|
||||||
} //end namespace fc
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue