Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Jul 14, 2016
2 parents 0ea6049 + c96fbd9 commit dfc550f
Show file tree
Hide file tree
Showing 37 changed files with 1,538 additions and 330 deletions.
2 changes: 1 addition & 1 deletion libraries/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_library( steemit_app
${HEADERS}
)

target_link_libraries( steemit_app steemit_chain steemit_tags steemit_mf_plugins fc graphene_db graphene_net graphene_time graphene_utilities )
target_link_libraries( steemit_app steemit_chain steemit_tags steemit_follow steemit_mf_plugins fc graphene_db graphene_net graphene_time graphene_utilities )
target_include_directories( steemit_app
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )

Expand Down
73 changes: 68 additions & 5 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>

// Market
order_book get_order_book( uint32_t limit )const;
vector< liquidity_balance > get_liquidity_queue( string start_account, uint32_t limit )const;

// Authority / validation
std::string get_transaction_hex(const signed_transaction& trx)const;
Expand Down Expand Up @@ -532,7 +533,11 @@ vector<extended_limit_order> database_api::get_open_orders( string owner )const
auto itr = idx.lower_bound( owner );
while( itr != idx.end() && itr->seller == owner ) {
result.push_back( *itr );
result.back().real_price = (~result.back().sell_price).to_real();

if( itr->sell_price.base.symbol == STEEM_SYMBOL )
result.back().real_price = (~result.back().sell_price).to_real();
else
result.back().real_price = (result.back().sell_price).to_real();
++itr;
}
return result;
Expand Down Expand Up @@ -583,6 +588,49 @@ order_book database_api_impl::get_order_book( uint32_t limit )const
return result;
}

vector< liquidity_balance > database_api::get_liquidity_queue( string start_account, uint32_t limit )const
{
return my->get_liquidity_queue( start_account, limit );
}

vector< liquidity_balance > database_api_impl::get_liquidity_queue( string start_account, uint32_t limit )const
{
FC_ASSERT( limit <= 1000 );

const auto& liq_idx = _db.get_index_type< liquidity_reward_index >().indices().get< by_volume_weight >();
auto itr = liq_idx.begin();
vector< liquidity_balance > result;

result.reserve( limit );

if( start_account.length() )
{
const auto& liq_by_acc = _db.get_index_type< liquidity_reward_index >().indices().get< by_owner >();
auto acc = liq_by_acc.find( _db.get_account( start_account ).id );

if( acc != liq_by_acc.end() )
{
itr = liq_idx.find( boost::make_tuple( acc->weight, acc->owner ) );
}
else
{
itr = liq_idx.end();
}
}

while( itr != liq_idx.end() && result.size() < limit )
{
liquidity_balance bal;
bal.account = itr->owner( _db ).name;
bal.weight = itr->weight;
result.push_back( bal );

++itr;
}

return result;
}

//////////////////////////////////////////////////////////////////////
// //
// Authority / validation //
Expand Down Expand Up @@ -935,7 +983,7 @@ vector<discussion> database_api::get_discussions( const discussion_query& query,
} catch ( const fc::exception& e ) {
edump((e.to_detail_string()));
}
++tidx_itr;
++tidx_itr;
}
return result;
}
Expand Down Expand Up @@ -1190,7 +1238,7 @@ state database_api::get_state( string path )const
_state.accounts[acnt] = my->_db.get_account(acnt);
auto& eacnt = _state.accounts[acnt];
if( part[1] == "recommended" ) {
auto discussions = get_recommended_for( acnt, 100 );
auto discussions = get_recommended_for( acnt, 50 );
eacnt.recommended = vector<string>();
for( const auto& d : discussions ) {
auto ref = d.author+"/"+d.permlink;
Expand Down Expand Up @@ -1247,7 +1295,7 @@ state database_api::get_state( string path )const
const auto& pidx = my->_db.get_index_type<comment_index>().indices().get<by_author_last_update>();
auto itr = pidx.lower_bound( boost::make_tuple(acnt, time_point_sec::maximum() ) );
eacnt.posts = vector<string>();
while( itr != pidx.end() && itr->author == acnt && count < 100 ) {
while( itr != pidx.end() && itr->author == acnt && count < 20 ) {
eacnt.posts->push_back(itr->permlink);
_state.content[acnt+"/"+itr->permlink] = *itr;
set_pending_payout( _state.content[acnt+"/"+itr->permlink] );
Expand All @@ -1259,13 +1307,28 @@ state database_api::get_state( string path )const
const auto& pidx = my->_db.get_index_type<comment_index>().indices().get<by_blog>();
auto itr = pidx.lower_bound( boost::make_tuple(acnt, std::string(""), time_point_sec::maximum() ) );
eacnt.blog = vector<string>();
while( itr != pidx.end() && itr->author == acnt && count < 100 && !itr->parent_author.size() ) {
while( itr != pidx.end() && itr->author == acnt && count < 20 && !itr->parent_author.size() ) {
eacnt.blog->push_back(itr->permlink);
_state.content[acnt+"/"+itr->permlink] = *itr;
set_pending_payout( _state.content[acnt+"/"+itr->permlink] );
++itr;
++count;
}
} else if( part[1].size() == 0 || part[1] == "feed" ) {
const auto& fidxs = my->_db.get_index_type<follow::feed_index>().indices();
const auto& fidx = fidxs.get<steemit::follow::by_account>();

auto itr = fidx.lower_bound( eacnt.id );
int count = 0;
while( itr != fidx.end() && itr->account == eacnt.id && count < 100 ) {
const auto& c = itr->comment( my->_db );
const auto link = c.author + "/" + c.permlink;
_state.content[link] = c;
eacnt.feed->push_back( link );
set_pending_payout( _state.content[link] );
++itr;
++count;
}
}
}
/// pull a complete discussion
Expand Down
15 changes: 15 additions & 0 deletions libraries/app/include/steemit/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <steemit/chain/steem_objects.hpp>
#include <steemit/chain/history_object.hpp>
#include <steemit/tags/tags_plugin.hpp>
#include <steemit/follow/follow_plugin.hpp>

#include <fc/api.hpp>
#include <fc/optional.hpp>
Expand Down Expand Up @@ -48,6 +49,12 @@ struct scheduled_hardfork
fc::time_point_sec live_time;
};

struct liquidity_balance
{
string account;
fc::uint128_t weight;
};


class database_api_impl;

Expand Down Expand Up @@ -242,6 +249,12 @@ class database_api
order_book get_order_book( uint32_t limit = 1000 )const;
vector<extended_limit_order> get_open_orders( string owner )const;

/**
* @breif Gets the current liquidity reward queue.
* @param start_account The account to start the list from, or "" to get the head of the queue
* @param limit Maxmimum number of accounts to return -- Must not exceed 1000
*/
vector< liquidity_balance > get_liquidity_queue( string start_account, uint32_t limit = 1000 )const;

////////////////////////////
// Authority / validation //
Expand Down Expand Up @@ -372,6 +385,7 @@ class database_api
FC_REFLECT( steemit::app::order, (order_price)(real_price)(steem)(sbd)(created) );
FC_REFLECT( steemit::app::order_book, (asks)(bids) );
FC_REFLECT( steemit::app::scheduled_hardfork, (hf_version)(live_time) );
FC_REFLECT( steemit::app::liquidity_balance, (account)(weight) );

FC_REFLECT( steemit::app::discussion_query, (tag)(filter_tags)(start_author)(start_permlink)(parent_author)(parent_permlink)(limit) );

Expand Down Expand Up @@ -428,6 +442,7 @@ FC_API(steemit::app::database_api,
// Market
(get_order_book)
(get_open_orders)
(get_liquidity_queue)

// Authority / validation
(get_transaction_hex)
Expand Down
3 changes: 2 additions & 1 deletion libraries/app/include/steemit/app/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ namespace steemit { namespace app {
optional<map<uint32_t,extended_limit_order>> open_orders;
optional<vector<string>> posts; /// permlinks for this user
optional<vector<string>> blog; /// blog posts for this user
optional<vector<string>> feed; /// feed posts for this user
optional<vector<string>> recent_replies; /// blog posts for this user
map<string,vector<string>> blog_category; /// blog posts for this user
optional<vector<string>> recommended; /// posts recommened for this user
Expand Down Expand Up @@ -161,7 +162,7 @@ namespace steemit { namespace app {
FC_REFLECT_DERIVED( steemit::app::extended_account,
(steemit::chain::account_object),
(vesting_balance)
(transfer_history)(market_history)(post_history)(vote_history)(other_history)(witness_votes)(open_orders)(posts)(blog)(recent_replies)(blog_category)(recommended) )
(transfer_history)(market_history)(post_history)(vote_history)(other_history)(witness_votes)(open_orders)(posts)(feed)(blog)(recent_replies)(blog_category)(recommended) )


FC_REFLECT( steemit::app::vote_state, (voter)(weight)(rshares)(percent)(time) );
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_library( steemit_chain
protocol/types.cpp
protocol/authority.cpp
protocol/operations.cpp
protocol/sign_state.cpp
protocol/steem_operations.cpp
protocol/transaction.cpp
protocol/block.cpp
Expand Down
Loading

0 comments on commit dfc550f

Please sign in to comment.