#235 Add custom funtions for event_object
This commit is contained in:
parent
a685a63453
commit
6f9c6fa8f0
3 changed files with 700 additions and 549 deletions
|
|
@ -1,26 +1,26 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
||||||
*
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DEFAULT_LOGGER "betting"
|
#define DEFAULT_LOGGER "betting"
|
||||||
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
|
#define BOOST_MPL_CFG_NO_PREPROCESSED_HEADERS
|
||||||
|
|
@ -31,10 +31,12 @@
|
||||||
#include <graphene/chain/betting_market_object.hpp>
|
#include <graphene/chain/betting_market_object.hpp>
|
||||||
#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 {
|
||||||
enum class event_state {
|
enum class event_state {
|
||||||
upcoming,
|
upcoming,
|
||||||
frozen_upcoming,
|
frozen_upcoming,
|
||||||
in_progress,
|
in_progress,
|
||||||
|
|
@ -42,7 +44,7 @@ namespace graphene { namespace chain {
|
||||||
finished,
|
finished,
|
||||||
canceled,
|
canceled,
|
||||||
settled
|
settled
|
||||||
};
|
};
|
||||||
} }
|
} }
|
||||||
|
|
||||||
FC_REFLECT_ENUM(graphene::chain::event_state,
|
FC_REFLECT_ENUM(graphene::chain::event_state,
|
||||||
|
|
@ -56,65 +58,65 @@ FC_REFLECT_ENUM(graphene::chain::event_state,
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
namespace msm = boost::msm;
|
namespace msm = boost::msm;
|
||||||
namespace mpl = boost::mpl;
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
// Events -- most events happen when the witnesses publish an event_update operation with a new
|
// Events -- most events happen when the witnesses publish an event_update operation with a new
|
||||||
// status, so if they publish an event with the status set to `frozen`, we'll generate a `frozen_event`
|
// status, so if they publish an event with the status set to `frozen`, we'll generate a `frozen_event`
|
||||||
struct upcoming_event
|
struct upcoming_event
|
||||||
{
|
{
|
||||||
database& db;
|
database& db;
|
||||||
upcoming_event(database& db) : db(db) {}
|
upcoming_event(database& db) : db(db) {}
|
||||||
};
|
};
|
||||||
struct in_progress_event
|
struct in_progress_event
|
||||||
{
|
{
|
||||||
database& db;
|
database& db;
|
||||||
in_progress_event(database& db) : db(db) {}
|
in_progress_event(database& db) : db(db) {}
|
||||||
};
|
};
|
||||||
struct frozen_event
|
struct frozen_event
|
||||||
{
|
{
|
||||||
database& db;
|
database& db;
|
||||||
frozen_event(database& db) : db(db) {}
|
frozen_event(database& db) : db(db) {}
|
||||||
};
|
};
|
||||||
struct finished_event
|
struct finished_event
|
||||||
{
|
{
|
||||||
database& db;
|
database& db;
|
||||||
finished_event(database& db) : db(db) {}
|
finished_event(database& db) : db(db) {}
|
||||||
};
|
};
|
||||||
struct canceled_event
|
struct canceled_event
|
||||||
{
|
{
|
||||||
database& db;
|
database& db;
|
||||||
canceled_event(database& db) : db(db) {}
|
canceled_event(database& db) : db(db) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// event triggered when a betting market group in this event is resolved,
|
// event triggered when a betting market group in this event is resolved,
|
||||||
// when we get this, check and see if all betting market groups are now
|
// when we get this, check and see if all betting market groups are now
|
||||||
// canceled/settled; if so, transition the event to canceled/settled,
|
// canceled/settled; if so, transition the event to canceled/settled,
|
||||||
// otherwise remain in the current state
|
// otherwise remain in the current state
|
||||||
struct betting_market_group_resolved_event
|
struct betting_market_group_resolved_event
|
||||||
{
|
{
|
||||||
database& db;
|
database& db;
|
||||||
betting_market_group_id_type resolved_group;
|
betting_market_group_id_type resolved_group;
|
||||||
bool was_canceled;
|
bool was_canceled;
|
||||||
betting_market_group_resolved_event(database& db, betting_market_group_id_type resolved_group, bool was_canceled) : db(db), resolved_group(resolved_group), was_canceled(was_canceled) {}
|
betting_market_group_resolved_event(database& db, betting_market_group_id_type resolved_group, bool was_canceled) : db(db), resolved_group(resolved_group), was_canceled(was_canceled) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// event triggered when a betting market group is closed. When we get this,
|
// event triggered when a betting market group is closed. When we get this,
|
||||||
// if all child betting market groups are closed, transition to finished
|
// if all child betting market groups are closed, transition to finished
|
||||||
struct betting_market_group_closed_event
|
struct betting_market_group_closed_event
|
||||||
{
|
{
|
||||||
database& db;
|
database& db;
|
||||||
betting_market_group_id_type closed_group;
|
betting_market_group_id_type closed_group;
|
||||||
betting_market_group_closed_event(database& db, betting_market_group_id_type closed_group) : db(db), closed_group(closed_group) {}
|
betting_market_group_closed_event(database& db, betting_market_group_id_type closed_group) : db(db), closed_group(closed_group) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
struct event_state_machine_ : public msm::front::state_machine_def<event_state_machine_>
|
struct event_state_machine_ : public msm::front::state_machine_def<event_state_machine_>
|
||||||
|
|
||||||
{
|
{
|
||||||
// disable a few state machine features we don't use for performance
|
// disable a few state machine features we don't use for performance
|
||||||
typedef int no_exception_thrown;
|
typedef int no_exception_thrown;
|
||||||
typedef int no_message_queue;
|
typedef int no_message_queue;
|
||||||
|
|
@ -352,25 +354,25 @@ namespace graphene { namespace chain {
|
||||||
|
|
||||||
event_object* event_obj;
|
event_object* event_obj;
|
||||||
event_state_machine_(event_object* event_obj) : event_obj(event_obj) {}
|
event_state_machine_(event_object* event_obj) : event_obj(event_obj) {}
|
||||||
};
|
};
|
||||||
typedef msm::back::state_machine<event_state_machine_> event_state_machine;
|
typedef msm::back::state_machine<event_state_machine_> event_state_machine;
|
||||||
|
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
class event_object::impl {
|
class event_object::impl {
|
||||||
public:
|
public:
|
||||||
event_state_machine state_machine;
|
event_state_machine state_machine;
|
||||||
|
|
||||||
impl(event_object* self) : state_machine(self) {}
|
impl(event_object* self) : state_machine(self) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
event_object::event_object() :
|
event_object::event_object() :
|
||||||
at_least_one_betting_market_group_settled(false),
|
at_least_one_betting_market_group_settled(false),
|
||||||
my(new impl(this))
|
my(new impl(this))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
event_object::event_object(const event_object& rhs) :
|
event_object::event_object(const event_object& rhs) :
|
||||||
graphene::db::abstract_object<event_object>(rhs),
|
graphene::db::abstract_object<event_object>(rhs),
|
||||||
name(rhs.name),
|
name(rhs.name),
|
||||||
season(rhs.season),
|
season(rhs.season),
|
||||||
|
|
@ -379,13 +381,13 @@ namespace graphene { namespace chain {
|
||||||
at_least_one_betting_market_group_settled(rhs.at_least_one_betting_market_group_settled),
|
at_least_one_betting_market_group_settled(rhs.at_least_one_betting_market_group_settled),
|
||||||
scores(rhs.scores),
|
scores(rhs.scores),
|
||||||
my(new impl(this))
|
my(new impl(this))
|
||||||
{
|
{
|
||||||
my->state_machine = rhs.my->state_machine;
|
my->state_machine = rhs.my->state_machine;
|
||||||
my->state_machine.event_obj = this;
|
my->state_machine.event_obj = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_object& event_object::operator=(const event_object& rhs)
|
event_object& event_object::operator=(const event_object& rhs)
|
||||||
{
|
{
|
||||||
//graphene::db::abstract_object<event_object>::operator=(rhs);
|
//graphene::db::abstract_object<event_object>::operator=(rhs);
|
||||||
id = rhs.id;
|
id = rhs.id;
|
||||||
name = rhs.name;
|
name = rhs.name;
|
||||||
|
|
@ -399,16 +401,16 @@ namespace graphene { namespace chain {
|
||||||
my->state_machine.event_obj = this;
|
my->state_machine.event_obj = this;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
event_object::~event_object()
|
event_object::~event_object()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool verify_event_status_constants()
|
bool verify_event_status_constants()
|
||||||
{
|
{
|
||||||
unsigned error_count = 0;
|
unsigned error_count = 0;
|
||||||
typedef msm::back::generate_state_set<event_state_machine::stt>::type all_states;
|
typedef msm::back::generate_state_set<event_state_machine::stt>::type all_states;
|
||||||
static char const* filled_state_names[mpl::size<all_states>::value];
|
static char const* filled_state_names[mpl::size<all_states>::value];
|
||||||
|
|
@ -443,11 +445,11 @@ namespace graphene { namespace chain {
|
||||||
wlog("There were ${count} errors in the event status constants", ("count", error_count));
|
wlog("There were ${count} errors in the event status constants", ("count", error_count));
|
||||||
|
|
||||||
return error_count == 0;
|
return error_count == 0;
|
||||||
}
|
}
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
event_status event_object::get_status() const
|
event_status event_object::get_status() const
|
||||||
{
|
{
|
||||||
static bool state_constants_are_correct = verify_event_status_constants();
|
static bool state_constants_are_correct = verify_event_status_constants();
|
||||||
(void)&state_constants_are_correct;
|
(void)&state_constants_are_correct;
|
||||||
event_state state = (event_state)my->state_machine.current_state()[0];
|
event_state state = (event_state)my->state_machine.current_state()[0];
|
||||||
|
|
@ -472,48 +474,60 @@ namespace graphene { namespace chain {
|
||||||
default:
|
default:
|
||||||
FC_THROW("Unexpected event state");
|
FC_THROW("Unexpected event state");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_object::on_upcoming_event(database& db)
|
void event_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 event_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 event_object::on_upcoming_event(database& db)
|
||||||
|
{
|
||||||
my->state_machine.process_event(upcoming_event(db));
|
my->state_machine.process_event(upcoming_event(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_object::on_in_progress_event(database& db)
|
void event_object::on_in_progress_event(database& db)
|
||||||
{
|
{
|
||||||
my->state_machine.process_event(in_progress_event(db));
|
my->state_machine.process_event(in_progress_event(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_object::on_frozen_event(database& db)
|
void event_object::on_frozen_event(database& db)
|
||||||
{
|
{
|
||||||
my->state_machine.process_event(frozen_event(db));
|
my->state_machine.process_event(frozen_event(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_object::on_finished_event(database& db)
|
void event_object::on_finished_event(database& db)
|
||||||
{
|
{
|
||||||
my->state_machine.process_event(finished_event(db));
|
my->state_machine.process_event(finished_event(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_object::on_canceled_event(database& db)
|
void event_object::on_canceled_event(database& db)
|
||||||
{
|
{
|
||||||
my->state_machine.process_event(canceled_event(db));
|
my->state_machine.process_event(canceled_event(db));
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_object::on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled)
|
void event_object::on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled)
|
||||||
{
|
{
|
||||||
my->state_machine.process_event(betting_market_group_resolved_event(db, resolved_group, was_canceled));
|
my->state_machine.process_event(betting_market_group_resolved_event(db, resolved_group, was_canceled));
|
||||||
}
|
}
|
||||||
|
|
||||||
void event_object::on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group)
|
void event_object::on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group)
|
||||||
{
|
{
|
||||||
my->state_machine.process_event(betting_market_group_closed_event(db, closed_group));
|
my->state_machine.process_event(betting_market_group_closed_event(db, closed_group));
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are the only statuses that can be explicitly set by witness operations. The missing
|
// These are the only statuses that can be explicitly set by witness operations. The missing
|
||||||
// status, 'settled', is automatically set when all of the betting market groups have
|
// status, 'settled', is automatically set when all of the betting market groups have
|
||||||
// settled/canceled
|
// settled/canceled
|
||||||
void event_object::dispatch_new_status(database& db, event_status new_status)
|
void event_object::dispatch_new_status(database& db, event_status new_status)
|
||||||
{
|
{
|
||||||
switch (new_status) {
|
switch (new_status) {
|
||||||
case event_status::upcoming: // by witnesses to unfreeze a frozen event
|
case event_status::upcoming: // by witnesses to unfreeze a frozen event
|
||||||
on_upcoming_event(db);
|
on_upcoming_event(db);
|
||||||
|
|
@ -533,8 +547,38 @@ namespace graphene { namespace chain {
|
||||||
default:
|
default:
|
||||||
FC_THROW("Status ${new_status} cannot be explicitly set", ("new_status", new_status));
|
FC_THROW("Status ${new_status} cannot be explicitly set", ("new_status", new_status));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
|
namespace fc {
|
||||||
|
// Manually reflect event_object to variant to properly reflect "state"
|
||||||
|
void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth)
|
||||||
|
{
|
||||||
|
fc::mutable_variant_object o;
|
||||||
|
o("id", fc::variant(event_obj.id, max_depth))
|
||||||
|
("name", fc::variant(event_obj.name, max_depth))
|
||||||
|
("season", fc::variant(event_obj.season, max_depth))
|
||||||
|
("start_time", fc::variant(event_obj.start_time, max_depth))
|
||||||
|
("event_group_id", fc::variant(event_obj.event_group_id, max_depth))
|
||||||
|
("scores", fc::variant(event_obj.scores, max_depth))
|
||||||
|
("status", fc::variant(event_obj.get_status(), max_depth));
|
||||||
|
|
||||||
|
v = o;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Manually reflect event_object to variant to properly reflect "state"
|
||||||
|
void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth)
|
||||||
|
{
|
||||||
|
event_obj.id = v["id"].as<graphene::chain::event_id_type>( max_depth );
|
||||||
|
event_obj.name = v["name"].as<graphene::chain::internationalized_string_type>( max_depth );
|
||||||
|
event_obj.season = v["season"].as<graphene::chain::internationalized_string_type>( max_depth );
|
||||||
|
event_obj.start_time = v["start_time"].as<optional<time_point_sec> >( max_depth );
|
||||||
|
event_obj.event_group_id = v["event_group_id"].as<graphene::chain::event_group_id_type>( max_depth );
|
||||||
|
event_obj.scores = v["scores"].as<std::vector<std::string>>( max_depth );
|
||||||
|
graphene::chain::event_status status = v["status"].as<graphene::chain::event_status>( max_depth );
|
||||||
|
const_cast<int*>(event_obj.my->state_machine.current_state())[0] = (int)status;
|
||||||
|
}
|
||||||
|
} //end namespace fc
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,42 +1,52 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
||||||
*
|
*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <graphene/chain/protocol/types.hpp>
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
#include <graphene/chain/protocol/event.hpp>
|
|
||||||
#include <graphene/db/object.hpp>
|
#include <graphene/db/object.hpp>
|
||||||
#include <graphene/db/generic_index.hpp>
|
#include <graphene/db/generic_index.hpp>
|
||||||
|
#include <graphene/chain/protocol/event.hpp>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <boost/multi_index/composite_key.hpp>
|
#include <boost/multi_index/composite_key.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
class event_object;
|
||||||
|
} }
|
||||||
|
|
||||||
|
namespace fc {
|
||||||
|
void to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth = 1);
|
||||||
|
void from_variant(const fc::variant& v, graphene::chain::event_object& event_obj, uint32_t max_depth = 1);
|
||||||
|
} //end namespace fc
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
class database;
|
class database;
|
||||||
|
|
||||||
class event_object : public graphene::db::abstract_object< event_object >
|
class event_object : public graphene::db::abstract_object< event_object >
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static const uint8_t space_id = protocol_ids;
|
static const uint8_t space_id = protocol_ids;
|
||||||
static const uint8_t type_id = event_object_type;
|
static const uint8_t type_id = event_object_type;
|
||||||
|
|
||||||
|
|
@ -58,6 +68,21 @@ class event_object : public graphene::db::abstract_object< event_object >
|
||||||
event_status get_status() const;
|
event_status get_status() const;
|
||||||
vector<string> scores;
|
vector<string> scores;
|
||||||
|
|
||||||
|
// 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 event_object& event_obj );
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
friend Stream& operator>>( Stream& s, event_object& event_obj );
|
||||||
|
|
||||||
|
friend void ::fc::to_variant(const graphene::chain::event_object& event_obj, fc::variant& v, uint32_t max_depth);
|
||||||
|
friend void ::fc::from_variant(const fc::variant& v, graphene::chain::event_object& event_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_upcoming_event(database& db);
|
||||||
void on_in_progress_event(database& db);
|
void on_in_progress_event(database& db);
|
||||||
void on_frozen_event(database& db);
|
void on_frozen_event(database& db);
|
||||||
|
|
@ -67,7 +92,7 @@ class event_object : public graphene::db::abstract_object< event_object >
|
||||||
void on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled);
|
void on_betting_market_group_resolved(database& db, betting_market_group_id_type resolved_group, bool was_canceled);
|
||||||
void on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group);
|
void on_betting_market_group_closed(database& db, betting_market_group_id_type closed_group);
|
||||||
void dispatch_new_status(database& db, event_status new_status);
|
void dispatch_new_status(database& db, event_status new_status);
|
||||||
private:
|
private:
|
||||||
class impl;
|
class impl;
|
||||||
std::unique_ptr<impl> my;
|
std::unique_ptr<impl> my;
|
||||||
};
|
};
|
||||||
|
|
@ -86,16 +111,100 @@ typedef multi_index_container<
|
||||||
member<object, object_id_type, &object::id> > > > > event_object_multi_index_type;
|
member<object, object_id_type, &object::id> > > > > event_object_multi_index_type;
|
||||||
|
|
||||||
typedef generic_index<event_object, event_object_multi_index_type> event_object_index;
|
typedef generic_index<event_object, event_object_multi_index_type> event_object_index;
|
||||||
|
|
||||||
|
template<typename Stream>
|
||||||
|
inline Stream& operator<<( Stream& s, const event_object& event_obj )
|
||||||
|
{
|
||||||
|
fc_elog(fc::logger::get("event"), "In event_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<event_object> >(s, event_obj);
|
||||||
|
fc::raw::pack(s, event_obj.id);
|
||||||
|
fc::raw::pack(s, event_obj.name);
|
||||||
|
fc::raw::pack(s, event_obj.season);
|
||||||
|
fc::raw::pack(s, event_obj.start_time);
|
||||||
|
fc::raw::pack(s, event_obj.event_group_id);
|
||||||
|
fc::raw::pack(s, event_obj.at_least_one_betting_market_group_settled);
|
||||||
|
fc::raw::pack(s, event_obj.scores);
|
||||||
|
|
||||||
|
// fc::raw::pack the contents hidden in the impl class
|
||||||
|
std::ostringstream stream;
|
||||||
|
event_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, event_object& event_obj )
|
||||||
|
{
|
||||||
|
fc_elog(fc::logger::get("event"), "In event_obj from_raw");
|
||||||
|
// unpack all fields exposed in the header in the usual way
|
||||||
|
//fc::raw::unpack<Stream, graphene::db::abstract_object<event_object> >(s, event_obj);
|
||||||
|
fc::raw::unpack(s, event_obj.id);
|
||||||
|
fc::raw::unpack(s, event_obj.name);
|
||||||
|
fc::raw::unpack(s, event_obj.season);
|
||||||
|
fc::raw::unpack(s, event_obj.start_time);
|
||||||
|
fc::raw::unpack(s, event_obj.event_group_id);
|
||||||
|
fc::raw::unpack(s, event_obj.at_least_one_betting_market_group_settled);
|
||||||
|
fc::raw::unpack(s, event_obj.scores);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
event_obj.unpack_impl(stream);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
FC_REFLECT_DERIVED(graphene::chain::event_object, (graphene::db::object),
|
namespace fc {
|
||||||
(name)
|
|
||||||
(season)
|
|
||||||
(start_time)
|
|
||||||
(event_group_id)
|
|
||||||
(at_least_one_betting_market_group_settled)
|
|
||||||
(scores))
|
|
||||||
|
|
||||||
GRAPHENE_EXTERNAL_SERIALIZATION( extern, graphene::chain::event_object )
|
template<>
|
||||||
|
template<>
|
||||||
|
inline void if_enum<fc::false_type>::from_variant(const variant &vo, graphene::chain::event_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::event_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::event_object &v, uint32_t) {
|
||||||
|
s << v;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
template<>
|
||||||
|
inline void if_enum<fc::false_type>::pack(fc::datastream<char*> &s, const graphene::chain::event_object &v, uint32_t) {
|
||||||
|
s << v;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
template<>
|
||||||
|
inline void if_enum<fc::false_type>::unpack(fc::datastream<const char*> &s, graphene::chain::event_object &v, uint32_t) {
|
||||||
|
s >> v;
|
||||||
|
}
|
||||||
|
|
||||||
|
} }
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct get_typename<graphene::chain::event_object> {
|
||||||
|
static const char *name() {
|
||||||
|
return "graphene::chain::event_object";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
struct reflector<graphene::chain::event_object> {
|
||||||
|
typedef graphene::chain::event_object type;
|
||||||
|
typedef fc::true_type is_defined;
|
||||||
|
typedef fc::false_type is_enum;
|
||||||
|
};
|
||||||
|
} // namespace fc
|
||||||
|
|
@ -45,7 +45,6 @@
|
||||||
#include <graphene/chain/worker_object.hpp>
|
#include <graphene/chain/worker_object.hpp>
|
||||||
#include <graphene/chain/game_object.hpp>
|
#include <graphene/chain/game_object.hpp>
|
||||||
#include <graphene/chain/tournament_object.hpp>
|
#include <graphene/chain/tournament_object.hpp>
|
||||||
#include <graphene/chain/event_object.hpp>
|
|
||||||
#include <graphene/chain/match_object.hpp>
|
#include <graphene/chain/match_object.hpp>
|
||||||
#include <graphene/chain/betting_market_object.hpp>
|
#include <graphene/chain/betting_market_object.hpp>
|
||||||
|
|
||||||
|
|
@ -79,7 +78,6 @@ GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::witness_schedu
|
||||||
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::game_object )
|
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::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::match_object )
|
||||||
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_group_object )
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_group_object )
|
||||||
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_object )
|
GRAPHENE_EXTERNAL_SERIALIZATION( /*not extern*/, graphene::chain::betting_market_object )
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue