Created plugin stub for affiliate statistics
This commit is contained in:
parent
2428383466
commit
ade7cf2d87
12 changed files with 359 additions and 2 deletions
|
|
@ -13,7 +13,7 @@ add_library( graphene_app
|
|||
|
||||
# need to link graphene_debug_witness because plugins aren't sufficiently isolated #246
|
||||
#target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness )
|
||||
target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_accounts_list graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness graphene_bookie )
|
||||
target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness graphene_bookie )
|
||||
target_include_directories( graphene_app
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" )
|
||||
|
|
|
|||
|
|
@ -117,6 +117,12 @@ namespace graphene { namespace app {
|
|||
if( _app.get_plugin( "bookie" ) )
|
||||
_bookie_api = std::make_shared<graphene::bookie::bookie_api>(std::ref(_app));
|
||||
}
|
||||
else if( api_name == "affiliate_stats_api" )
|
||||
{
|
||||
// can only enable this API if the plugin was loaded
|
||||
if( _app.get_plugin( "affiliate_stats" ) )
|
||||
_affiliate_stats_api = std::make_shared<graphene::affiliate_stats::affiliate_stats_api>(std::ref(_app));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -281,6 +287,12 @@ namespace graphene { namespace app {
|
|||
return *_bookie_api;
|
||||
}
|
||||
|
||||
fc::api<graphene::affiliate_stats::affiliate_stats_api> login_api::affiliate_stats() const
|
||||
{
|
||||
FC_ASSERT(_affiliate_stats_api);
|
||||
return *_affiliate_stats_api;
|
||||
}
|
||||
|
||||
#if 0
|
||||
vector<account_id_type> get_relevant_accounts( const object* obj )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -493,6 +493,7 @@ namespace detail {
|
|||
wild_access.allowed_apis.push_back( "history_api" );
|
||||
wild_access.allowed_apis.push_back( "crypto_api" );
|
||||
wild_access.allowed_apis.push_back( "bookie_api" );
|
||||
wild_access.allowed_apis.push_back( "affiliate_stats_api" );
|
||||
_apiaccess.permission_map["*"] = wild_access;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <graphene/accounts_list/accounts_list_plugin.hpp>
|
||||
|
||||
#include <graphene/debug_witness/debug_api.hpp>
|
||||
#include <graphene/affiliate_stats/affiliate_stats_api.hpp>
|
||||
#include <graphene/bookie/bookie_api.hpp>
|
||||
|
||||
#include <graphene/net/node.hpp>
|
||||
|
|
@ -362,6 +363,8 @@ namespace graphene { namespace app {
|
|||
fc::api<graphene::debug_witness::debug_api> debug()const;
|
||||
/// @brief Retrieve the bookie API (if available)
|
||||
fc::api<graphene::bookie::bookie_api> bookie()const;
|
||||
/// @brief Retrieve the affiliate_stats API (if available)
|
||||
fc::api<graphene::affiliate_stats::affiliate_stats_api> affiliate_stats()const;
|
||||
|
||||
/// @brief Called to enable an API, not reflected.
|
||||
void enable_api( const string& api_name );
|
||||
|
|
@ -377,6 +380,7 @@ namespace graphene { namespace app {
|
|||
optional< fc::api<asset_api> > _asset_api;
|
||||
optional< fc::api<graphene::debug_witness::debug_api> > _debug_api;
|
||||
optional< fc::api<graphene::bookie::bookie_api> > _bookie_api;
|
||||
optional< fc::api<graphene::affiliate_stats::affiliate_stats_api> > _affiliate_stats_api;
|
||||
};
|
||||
|
||||
}} // graphene::app
|
||||
|
|
@ -446,4 +450,5 @@ FC_API(graphene::app::login_api,
|
|||
(asset)
|
||||
(debug)
|
||||
(bookie)
|
||||
(affiliate_stats)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
add_subdirectory( witness )
|
||||
add_subdirectory( account_history )
|
||||
add_subdirectory( accounts_list )
|
||||
add_subdirectory( affiliate_stats )
|
||||
add_subdirectory( market_history )
|
||||
add_subdirectory( delayed_node )
|
||||
add_subdirectory( bookie )
|
||||
|
|
|
|||
24
libraries/plugins/affiliate_stats/CMakeLists.txt
Normal file
24
libraries/plugins/affiliate_stats/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
file(GLOB HEADERS "include/graphene/affiliate_stats/*.hpp")
|
||||
|
||||
add_library( graphene_affiliate_stats
|
||||
affiliate_stats_api.cpp
|
||||
affiliate_stats_plugin.cpp
|
||||
)
|
||||
|
||||
target_link_libraries( graphene_affiliate_stats graphene_chain graphene_app )
|
||||
target_include_directories( graphene_affiliate_stats
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
||||
|
||||
if(MSVC)
|
||||
set_source_files_properties( affiliate_stats_plugin.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
|
||||
endif(MSVC)
|
||||
|
||||
install( TARGETS
|
||||
graphene_affiliate_stats
|
||||
|
||||
RUNTIME DESTINATION bin
|
||||
LIBRARY DESTINATION lib
|
||||
ARCHIVE DESTINATION lib
|
||||
)
|
||||
INSTALL( FILES ${HEADERS} DESTINATION "include/graphene/affiliate_stats" )
|
||||
|
||||
64
libraries/plugins/affiliate_stats/affiliate_stats_api.cpp
Normal file
64
libraries/plugins/affiliate_stats/affiliate_stats_api.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* 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
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <fc/optional.hpp>
|
||||
#include <fc/variant_object.hpp>
|
||||
#include <fc/smart_ref_impl.hpp>
|
||||
|
||||
#include <graphene/app/application.hpp>
|
||||
|
||||
#include <graphene/chain/block_database.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/betting_market_object.hpp>
|
||||
|
||||
#include <graphene/chain/witness_object.hpp>
|
||||
|
||||
#include <graphene/utilities/key_conversion.hpp>
|
||||
|
||||
#include <graphene/affiliate_stats/affiliate_stats_api.hpp>
|
||||
#include <graphene/affiliate_stats/affiliate_stats_plugin.hpp>
|
||||
|
||||
namespace graphene { namespace affiliate_stats {
|
||||
|
||||
namespace detail {
|
||||
|
||||
class affiliate_stats_api_impl
|
||||
{
|
||||
public:
|
||||
affiliate_stats_api_impl(graphene::app::application& _app);
|
||||
|
||||
graphene::app::application& app;
|
||||
};
|
||||
|
||||
affiliate_stats_api_impl::affiliate_stats_api_impl(graphene::app::application& _app)
|
||||
: app(_app) {}
|
||||
|
||||
} // detail
|
||||
|
||||
affiliate_stats_api::affiliate_stats_api(graphene::app::application& app)
|
||||
: my(std::make_shared<detail::affiliate_stats_api_impl>(app)) {}
|
||||
|
||||
} } // graphene::affiliate_stats
|
||||
|
||||
|
||||
117
libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp
Normal file
117
libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* 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
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <graphene/affiliate_stats/affiliate_stats_plugin.hpp>
|
||||
|
||||
#include <graphene/app/impacted.hpp>
|
||||
|
||||
#include <graphene/chain/account_evaluator.hpp>
|
||||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/config.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/evaluator.hpp>
|
||||
#include <graphene/chain/operation_history_object.hpp>
|
||||
#include <graphene/chain/transaction_evaluation_state.hpp>
|
||||
|
||||
#include <fc/smart_ref_impl.hpp>
|
||||
#include <fc/thread/thread.hpp>
|
||||
|
||||
namespace graphene { namespace affiliate_stats {
|
||||
|
||||
namespace detail {
|
||||
|
||||
class affiliate_stats_plugin_impl
|
||||
{
|
||||
public:
|
||||
affiliate_stats_plugin_impl(affiliate_stats_plugin& _plugin)
|
||||
: _self( _plugin )
|
||||
{ }
|
||||
virtual ~affiliate_stats_plugin_impl();
|
||||
|
||||
|
||||
/** this method is called as a callback after a block is applied
|
||||
* and will process/index all operations that were applied in the block.
|
||||
*/
|
||||
void update_affiliate_stats( const signed_block& b );
|
||||
|
||||
graphene::chain::database& database()
|
||||
{
|
||||
return _self.database();
|
||||
}
|
||||
|
||||
affiliate_stats_plugin& _self;
|
||||
private:
|
||||
};
|
||||
|
||||
affiliate_stats_plugin_impl::~affiliate_stats_plugin_impl() {}
|
||||
|
||||
void affiliate_stats_plugin_impl::update_affiliate_stats( const signed_block& b )
|
||||
{
|
||||
graphene::chain::database& db = database();
|
||||
vector<optional< operation_history_object > >& hist = db.get_applied_operations();
|
||||
for( optional< operation_history_object >& o_op : hist )
|
||||
{
|
||||
if( !o_op.valid() )
|
||||
continue;
|
||||
|
||||
const operation_history_object& op = *o_op;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace detail
|
||||
|
||||
|
||||
affiliate_stats_plugin::affiliate_stats_plugin()
|
||||
: my( new detail::affiliate_stats_plugin_impl(*this) ) {}
|
||||
|
||||
affiliate_stats_plugin::~affiliate_stats_plugin() {}
|
||||
|
||||
std::string affiliate_stats_plugin::plugin_name()const
|
||||
{
|
||||
return "affiliate_stats";
|
||||
}
|
||||
|
||||
void affiliate_stats_plugin::plugin_set_program_options(
|
||||
boost::program_options::options_description& cli,
|
||||
boost::program_options::options_description& cfg
|
||||
)
|
||||
{
|
||||
cli.add_options()
|
||||
;
|
||||
cfg.add(cli);
|
||||
}
|
||||
|
||||
void affiliate_stats_plugin::plugin_initialize(const boost::program_options::variables_map& options)
|
||||
{
|
||||
database().applied_block.connect( [this]( const signed_block& b){ my->update_affiliate_stats(b); } );
|
||||
|
||||
// FIXME
|
||||
// my->_oho_index = database().add_index< primary_index< simple_index< operation_history_object > > >();
|
||||
// database().add_index< primary_index< account_transaction_history_index > >();
|
||||
}
|
||||
|
||||
void affiliate_stats_plugin::plugin_startup() {}
|
||||
|
||||
} } // graphene::affiliate_stats
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* 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
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fc/api.hpp>
|
||||
#include <fc/variant_object.hpp>
|
||||
|
||||
#include <graphene/chain/protocol/types.hpp>
|
||||
#include <graphene/chain/protocol/asset.hpp>
|
||||
#include <graphene/chain/event_object.hpp>
|
||||
|
||||
using namespace graphene::chain;
|
||||
|
||||
namespace graphene { namespace app {
|
||||
class application;
|
||||
} }
|
||||
|
||||
namespace graphene { namespace affiliate_stats {
|
||||
|
||||
namespace detail {
|
||||
class affiliate_stats_api_impl;
|
||||
}
|
||||
|
||||
class affiliate_stats_api
|
||||
{
|
||||
public:
|
||||
affiliate_stats_api(graphene::app::application& app);
|
||||
|
||||
std::shared_ptr<detail::affiliate_stats_api_impl> my;
|
||||
};
|
||||
|
||||
} } // graphene::affiliate_stats
|
||||
/*
|
||||
FC_REFLECT(graphene::bookie::order_bin, (amount_to_bet)(backer_multiplier))
|
||||
FC_REFLECT(graphene::bookie::binned_order_book, (aggregated_back_bets)(aggregated_lay_bets))
|
||||
FC_REFLECT(graphene::bookie::matched_bet_object, (id)(bettor_id)(betting_market_id)(amount_to_bet)(backer_multiplier)(back_or_lay)(end_of_delay)(amount_matched)(associated_operations))
|
||||
*/
|
||||
FC_API(graphene::affiliate_stats::affiliate_stats_api,
|
||||
)
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Peerplays Blockchain Standards Association, and contributors.
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* 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
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <graphene/app/plugin.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
|
||||
#include <fc/thread/future.hpp>
|
||||
|
||||
namespace graphene { namespace affiliate_stats {
|
||||
using namespace chain;
|
||||
|
||||
//
|
||||
// Plugins should #define their SPACE_ID's so plugins with
|
||||
// conflicting SPACE_ID assignments can be compiled into the
|
||||
// same binary (by simply re-assigning some of the conflicting #defined
|
||||
// SPACE_ID's in a build script).
|
||||
//
|
||||
// Assignment of SPACE_ID's cannot be done at run-time because
|
||||
// various template automagic depends on them being known at compile
|
||||
// time.
|
||||
//
|
||||
#ifndef AFFILIATE_STATS_SPACE_ID
|
||||
#define AFFILIATE_STATS_SPACE_ID 7
|
||||
#endif
|
||||
|
||||
namespace detail
|
||||
{
|
||||
class affiliate_stats_plugin_impl;
|
||||
}
|
||||
|
||||
class affiliate_stats_plugin : public graphene::app::plugin
|
||||
{
|
||||
public:
|
||||
affiliate_stats_plugin();
|
||||
virtual ~affiliate_stats_plugin();
|
||||
|
||||
std::string plugin_name()const override;
|
||||
virtual void plugin_set_program_options(
|
||||
boost::program_options::options_description& cli,
|
||||
boost::program_options::options_description& cfg) override;
|
||||
virtual void plugin_initialize(const boost::program_options::variables_map& options) override;
|
||||
virtual void plugin_startup() override;
|
||||
|
||||
friend class detail::affiliate_stats_plugin_impl;
|
||||
std::unique_ptr<detail::affiliate_stats_plugin_impl> my;
|
||||
};
|
||||
|
||||
} } //graphene::affiliate_stats
|
||||
|
|
@ -11,7 +11,7 @@ endif()
|
|||
|
||||
# We have to link against graphene_debug_witness because deficiency in our API infrastructure doesn't allow plugins to be fully abstracted #246
|
||||
target_link_libraries( witness_node
|
||||
PRIVATE graphene_app graphene_account_history graphene_market_history graphene_witness graphene_chain graphene_debug_witness graphene_bookie graphene_egenesis_full graphene_snapshot fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
||||
PRIVATE graphene_app graphene_account_history graphene_affiliate_stats graphene_market_history graphene_witness graphene_chain graphene_debug_witness graphene_bookie graphene_egenesis_full fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
||||
# also add dependencies to graphene_generate_genesis graphene_generate_uia_sharedrop_genesis if you want those plugins
|
||||
|
||||
install( TARGETS
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include <graphene/market_history/market_history_plugin.hpp>
|
||||
//#include <graphene/generate_genesis/generate_genesis_plugin.hpp>
|
||||
//#include <graphene/generate_uia_sharedrop_genesis/generate_uia_sharedrop_genesis.hpp>
|
||||
#include <graphene/affiliate_stats/affiliate_stats_plugin.hpp>
|
||||
#include <graphene/bookie/bookie_plugin.hpp>
|
||||
#include <graphene/utilities/git_revision.hpp>
|
||||
#include <graphene/snapshot/snapshot.hpp>
|
||||
|
|
@ -84,6 +85,7 @@ int main(int argc, char** argv) {
|
|||
//auto generate_genesis_plug = node->register_plugin<generate_genesis_plugin::generate_genesis_plugin>();
|
||||
//auto generate_uia_sharedrop_genesis_plug = node->register_plugin<generate_uia_sharedrop_genesis::generate_uia_sharedrop_genesis_plugin>();
|
||||
auto list_plug = node->register_plugin<accounts_list::accounts_list_plugin>();
|
||||
auto affiliate_stats_plug = node->register_plugin<affiliate_stats::affiliate_stats_plugin>();
|
||||
auto bookie_plug = node->register_plugin<bookie::bookie_plugin>();
|
||||
auto snapshot_plug = node->register_plugin<snapshot_plugin::snapshot_plugin>();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue