diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index a6157560..077eb4aa 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -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" ) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 6c6359c2..077ad0d1 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -117,6 +117,12 @@ namespace graphene { namespace app { if( _app.get_plugin( "bookie" ) ) _bookie_api = std::make_shared(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(std::ref(_app)); + } return; } @@ -281,6 +287,12 @@ namespace graphene { namespace app { return *_bookie_api; } + fc::api login_api::affiliate_stats() const + { + FC_ASSERT(_affiliate_stats_api); + return *_affiliate_stats_api; + } + #if 0 vector get_relevant_accounts( const object* obj ) { diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 5b079b94..9572af5e 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -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; } diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index d4532b42..2fe0c938 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -362,6 +363,8 @@ namespace graphene { namespace app { fc::api debug()const; /// @brief Retrieve the bookie API (if available) fc::api bookie()const; + /// @brief Retrieve the affiliate_stats API (if available) + fc::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; optional< fc::api > _debug_api; optional< fc::api > _bookie_api; + optional< fc::api > _affiliate_stats_api; }; }} // graphene::app @@ -446,4 +450,5 @@ FC_API(graphene::app::login_api, (asset) (debug) (bookie) + (affiliate_stats) ) diff --git a/libraries/plugins/CMakeLists.txt b/libraries/plugins/CMakeLists.txt index 8bf98141..01079fe2 100644 --- a/libraries/plugins/CMakeLists.txt +++ b/libraries/plugins/CMakeLists.txt @@ -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 ) diff --git a/libraries/plugins/affiliate_stats/CMakeLists.txt b/libraries/plugins/affiliate_stats/CMakeLists.txt new file mode 100644 index 00000000..fec2544c --- /dev/null +++ b/libraries/plugins/affiliate_stats/CMakeLists.txt @@ -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" ) + diff --git a/libraries/plugins/affiliate_stats/affiliate_stats_api.cpp b/libraries/plugins/affiliate_stats/affiliate_stats_api.cpp new file mode 100644 index 00000000..0b072cca --- /dev/null +++ b/libraries/plugins/affiliate_stats/affiliate_stats_api.cpp @@ -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 +#include +#include + +#include + +#include +#include +#include + +#include + +#include + +#include +#include + +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(app)) {} + +} } // graphene::affiliate_stats + + diff --git a/libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp b/libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp new file mode 100644 index 00000000..ee4f7df5 --- /dev/null +++ b/libraries/plugins/affiliate_stats/affiliate_stats_plugin.cpp @@ -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 + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +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 >& 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 diff --git a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp new file mode 100644 index 00000000..b3a27475 --- /dev/null +++ b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_api.hpp @@ -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 +#include + +#include +#include +#include + +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 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, + ) diff --git a/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_plugin.hpp b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_plugin.hpp new file mode 100644 index 00000000..2262cfab --- /dev/null +++ b/libraries/plugins/affiliate_stats/include/graphene/affiliate_stats/affiliate_stats_plugin.hpp @@ -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 +#include + +#include + +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 my; +}; + +} } //graphene::affiliate_stats diff --git a/programs/witness_node/CMakeLists.txt b/programs/witness_node/CMakeLists.txt index b3fa5c88..3d03253b 100644 --- a/programs/witness_node/CMakeLists.txt +++ b/programs/witness_node/CMakeLists.txt @@ -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 diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index 426113c4..4d080aa4 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -29,6 +29,7 @@ #include //#include //#include +#include #include #include #include @@ -84,6 +85,7 @@ int main(int argc, char** argv) { //auto generate_genesis_plug = node->register_plugin(); //auto generate_uia_sharedrop_genesis_plug = node->register_plugin(); auto list_plug = node->register_plugin(); + auto affiliate_stats_plug = node->register_plugin(); auto bookie_plug = node->register_plugin(); auto snapshot_plug = node->register_plugin();