/* * 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 namespace graphene { namespace affiliate_stats { namespace detail { class affiliate_stats_api_impl { public: affiliate_stats_api_impl(graphene::app::application& _app); std::vector list_top_referred_accounts( asset_id_type asset, uint16_t limit )const { std::vector result; result.reserve( limit ); auto& idx = app.chain_database()->get_index_type().indices().get(); auto itr = idx.lower_bound( boost::make_tuple( asset, share_type(GRAPHENE_MAX_SHARE_SUPPLY) ) ); while( itr != idx.end() && itr->get_asset_id() == asset && limit-- > 0 ) result.push_back( *itr++ ); return result; } std::vector list_top_rewards_per_app( asset_id_type asset, uint16_t limit )const { std::vector result; result.reserve( limit ); auto& idx = app.chain_database()->get_index_type().indices().get(); auto itr = idx.lower_bound( boost::make_tuple( asset, share_type(GRAPHENE_MAX_SHARE_SUPPLY) ) ); while( itr != idx.end() && itr->get_asset_id() == asset && limit-- > 0 ) result.push_back( *itr++ ); return result; } std::vector list_historic_referral_rewards( account_id_type affiliate, operation_history_id_type start, uint16_t limit )const { shared_ptr plugin = app.get_plugin( "affiliate_stats" ); std::vector result; const auto& list = plugin->get_reward_history( affiliate ); result.reserve( limit ); auto inner = list.lower_bound( start ); while( inner != list.end() && result.size() < limit ) result.push_back( referral_payment( (*inner++)(*app.chain_database()) ) ); return result; } graphene::app::application& app; }; affiliate_stats_api_impl::affiliate_stats_api_impl(graphene::app::application& _app) : app(_app) {} } // detail top_referred_account::top_referred_account() {} top_referred_account::top_referred_account( const referral_reward_object& rro ) : referral( rro.referral ), total_payout( rro.total_payout ) {} top_app::top_app() {} top_app::top_app( const app_reward_object& aro ) : app( aro.app ), total_payout( aro.total_payout ) {} affiliate_stats_api::affiliate_stats_api(graphene::app::application& app) : my(std::make_shared(app)) {} std::vector affiliate_stats_api::list_top_referred_accounts( asset_id_type asset, uint16_t limit )const { FC_ASSERT( limit <= 100 ); return my->list_top_referred_accounts( asset, limit ); } std::vector affiliate_stats_api::list_top_rewards_per_app( asset_id_type asset, uint16_t limit )const { FC_ASSERT( limit <= 100 ); return my->list_top_rewards_per_app( asset, limit ); } std::vector affiliate_stats_api::list_historic_referral_rewards( account_id_type affiliate, operation_history_id_type start, uint16_t limit )const { FC_ASSERT( limit <= 100 ); return my->list_historic_referral_rewards( affiliate, start, limit ); } referral_payment::referral_payment() {} referral_payment::referral_payment( const operation_history_object& oho ) : id(oho.id), block_num(oho.block_num), tag(oho.op.get().tag), payout(oho.op.get().payout) {} } } // graphene::affiliate_stats