Skip to content

Commit

Permalink
Merge branch 'develop' into 551-hardfork16
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Nov 18, 2016
2 parents be9f160 + b3430db commit af50afd
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 179 deletions.
13 changes: 8 additions & 5 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <fc/rpc/api_connection.hpp>
#include <fc/rpc/websocket_api.hpp>
#include <fc/network/resolve.hpp>
#include <fc/string.hpp>

#include <boost/algorithm/string.hpp>
#include <boost/filesystem/path.hpp>
Expand Down Expand Up @@ -239,6 +240,8 @@ namespace detail {
void startup()
{ try {
_max_block_age =_options->at("max-block-age").as<int32_t>();
_shared_file_size = fc::parse_size( _options->at( "shared-file-size" ).as< string >() );
ilog( "shared_file_size is ${n} bytes", ("n", _shared_file_size) );
register_builtin_apis();

if( _options->count("resync-blockchain") )
Expand All @@ -260,26 +263,26 @@ namespace detail {
if( _options->count("replay-blockchain") )
{
ilog("Replaying blockchain on user request.");
_chain_db->reindex( _data_dir / "blockchain", _options->at( "shared-file-size" ).as< uint64_t >() );
_chain_db->reindex( _data_dir / "blockchain", _shared_file_size );
}
else
{
try
{
_chain_db->open(_data_dir / "blockchain", 0, _options->at( "shared-file-size" ).as< uint64_t >() );
_chain_db->open(_data_dir / "blockchain", 0, _shared_file_size );
}
catch( fc::assert_exception& )
{
wlog( "Error when opening database. Attempting reindex..." );

try
{
_chain_db->reindex( _data_dir / "blockchain", _options->at( "shared-file-size" ).as< uint64_t >() );
_chain_db->reindex( _data_dir / "blockchain", _shared_file_size );
}
catch( chain::block_log_exception& )
{
wlog( "Error opening block log. Having to resync from network..." );
_chain_db->open( _data_dir / "blockchain", 0, _options->at( "shared-file-size" ).as< uint64_t >() );
_chain_db->open( _data_dir / "blockchain", 0, _shared_file_size );
}
}
}
Expand Down Expand Up @@ -863,7 +866,7 @@ void application::set_program_options(boost::program_options::options_descriptio
("p2p-max-connections", bpo::value<uint32_t>(), "Maxmimum number of incoming connections on P2P endpoint")
("seed-node,s", bpo::value<vector<string>>()->composing(), "P2P nodes to connect to on startup (may specify multiple times)")
("checkpoint,c", bpo::value<vector<string>>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.")
("shared-file-size", bpo::value<uint64_t>()->default_value(34359738368), "Size of the shared memory file. Default: 34359738368 (32GB)")
("shared-file-size", bpo::value<string>()->default_value("32G"), "Size of the shared memory file. Default: 32G")
("rpc-endpoint", bpo::value<string>()->implicit_value("127.0.0.1:8090"), "Endpoint for websocket RPC to listen on")
("rpc-tls-endpoint", bpo::value<string>()->implicit_value("127.0.0.1:8089"), "Endpoint for TLS websocket RPC to listen on")
("server-pem,p", bpo::value<string>()->implicit_value("server.pem"), "The TLS certificate file for this server")
Expand Down
49 changes: 33 additions & 16 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,9 @@ void database_api::set_pending_payout( discussion& d )const
}
}

if( d.parent_author != STEEMIT_ROOT_POST_PARENT )
d.cashout_time = my->_db.calculate_discussion_payout_time( my->_db.get< comment_object >( d.id ) );

if( d.body.size() > 1024*128 )
d.body = "body pruned due to size";
if( d.parent_author.size() > 0 && d.body.size() > 1024*16 )
Expand Down Expand Up @@ -1057,17 +1060,31 @@ map< uint32_t, applied_operation > database_api::get_account_history( string acc
return result;
}

vector<tags::tag_stats_object> database_api::get_trending_tags( string after, uint32_t limit )const {
vector<tags::tag_stats_object> result;
const auto& tags_stats_idx = my->_db.get_index<tags::tag_stats_index>().indices().get<tags::by_tag>();
auto itr = tags_stats_idx.lower_bound(after);
vector<tag_api_obj> database_api::get_trending_tags( string after, uint32_t limit )const
{
limit = std::min( limit, uint32_t(100) );
vector<tag_api_obj> result;
result.reserve( limit );

while( itr != tags_stats_idx.end() && limit > 0 ) {
result.push_back(*itr);
--limit; ++itr;
}
const auto& nidx = my->_db.get_index<tags::tag_stats_index>().indices().get<tags::by_tag>();

return result;
const auto& ridx = my->_db.get_index<tags::tag_stats_index>().indices().get<tags::by_trending>();
auto itr = ridx.begin();
if( after != "" && nidx.size() )
{
auto nitr = nidx.lower_bound( after );
if( nitr == nidx.end() )
itr = ridx.end();
else
itr = ridx.iterator_to( *nitr );
}

while( itr != ridx.end() && result.size() < limit )
{
result.push_back( *itr );
++itr;
}
return result;
}

discussion database_api::get_discussion( comment_id_type id )const {
Expand Down Expand Up @@ -1566,12 +1583,12 @@ state database_api::get_state( string path )const
path = "trending";

/// FETCH CATEGORY STATE
auto trending_cat = get_trending_categories( "", 100 );
for( const auto& c : trending_cat )
auto trending_tags = get_trending_tags( "", 100 );
for( const auto& t : trending_tags )
{
string name = c.name;
_state.category_idx.trending.push_back( name );
_state.categories[ name ] = category_api_obj( c );
string name = t.name;
_state.tag_idx.trending.push_back( name );
_state.tags[ name ] = t;
}
auto best_cat = get_best_categories( "", 50 );
for( const auto& c : best_cat )
Expand Down Expand Up @@ -1660,14 +1677,14 @@ state database_api::get_state( string path )const
int count = 0;
const auto& pidx = my->_db.get_index<comment_index>().indices().get<by_author_last_update>();
auto itr = pidx.lower_bound( acnt );
eacnt.posts = vector<string>();
eacnt.comments = vector<string>();

while( itr != pidx.end() && itr->author == acnt && count < 20 )
{
if( itr->parent_author.size() )
{
const auto link = acnt + "/" + to_string( itr->permlink );
eacnt.posts->push_back( link );
eacnt.comments->push_back( link );
_state.content[ link ] = *itr;
set_pending_payout( _state.content[ link ] );
++count;
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/include/steemit/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class database_api
*/
void cancel_all_subscriptions();

vector<tags::tag_stats_object> get_trending_tags( string after_tag, uint32_t limit )const;
vector<tag_api_obj> get_trending_tags( string after_tag, uint32_t limit )const;

/**
* This API is a short-cut for returning all of the state required for a particular URL
Expand Down
19 changes: 14 additions & 5 deletions libraries/app/include/steemit/app/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ namespace steemit { namespace app {

struct category_index
{
vector< string > trending; /// pending payouts
vector< string > active; /// recent activity
vector< string > recent; /// recently created
vector< string > best; /// total lifetime payout
};

struct tag_index
{
vector< string > trending; /// pending payouts
};

struct vote_state
{
string voter;
Expand Down Expand Up @@ -97,7 +101,7 @@ namespace steemit { namespace app {
set<string> witness_votes;

optional<map<uint32_t,extended_limit_order>> open_orders;
optional<vector<string>> posts; /// permlinks for this user
optional<vector<string>> comments; /// 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
Expand Down Expand Up @@ -151,12 +155,16 @@ namespace steemit { namespace app {
*/
app::category_index category_idx;

app::tag_index tag_idx;

/**
* "" is the global discussion index, otherwise the indicies are ranked by category
*/
map<string, discussion_index> discussion_idx;

map< string, category_api_obj > categories;
map< string, tag_api_obj > tags;

/**
* map from account/slug to full nested discussion
*/
Expand All @@ -179,17 +187,18 @@ namespace steemit { namespace app {
FC_REFLECT_DERIVED( steemit::app::extended_account,
(steemit::app::account_api_obj),
(vesting_balance)(reputation)
(transfer_history)(market_history)(post_history)(vote_history)(other_history)(witness_votes)(open_orders)(posts)(feed)(blog)(recent_replies)(blog_category)(recommended) )
(transfer_history)(market_history)(post_history)(vote_history)(other_history)(witness_votes)(open_orders)(comments)(feed)(blog)(recent_replies)(blog_category)(recommended) )


FC_REFLECT( steemit::app::vote_state, (voter)(weight)(rshares)(percent)(reputation)(time) );
FC_REFLECT( steemit::app::account_vote, (authorperm)(weight)(rshares)(percent)(time) );

FC_REFLECT( steemit::app::discussion_index, (category)(trending)(trending30)(updated)(created)(responses)(active)(votes)(maturing)(best)(hot)(promoted)(cashout) )
FC_REFLECT( steemit::app::category_index, (trending)(active)(recent)(best) )
FC_REFLECT( steemit::app::category_index, (active)(recent)(best) )
FC_REFLECT( steemit::app::tag_index, (trending) )
FC_REFLECT_DERIVED( steemit::app::discussion, (steemit::app::comment_api_obj), (url)(root_title)(pending_payout_value)(total_pending_payout_value)(active_votes)(replies)(author_reputation)(promoted)(first_reblogged_by)(first_reblogged_on) )

FC_REFLECT( steemit::app::state, (current_route)(props)(category_idx)(categories)(content)(accounts)(pow_queue)(witnesses)(discussion_idx)(witness_schedule)(feed_price)(error)(market_data) )
FC_REFLECT( steemit::app::state, (current_route)(props)(category_idx)(tag_idx)(categories)(tags)(content)(accounts)(pow_queue)(witnesses)(discussion_idx)(witness_schedule)(feed_price)(error)(market_data) )

FC_REFLECT_DERIVED( steemit::app::extended_limit_order, (steemit::app::limit_order_api_obj), (real_price)(rewarded) )
FC_REFLECT( steemit::app::order_history_item, (time)(type)(sbd_quantity)(steem_quantity)(real_price) );
Expand Down
31 changes: 31 additions & 0 deletions libraries/app/include/steemit/app/steem_api_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <steemit/chain/transaction_object.hpp>
#include <steemit/chain/witness_objects.hpp>

#include <steemit/tags/tags_plugin.hpp>

namespace steemit { namespace app {

using namespace steemit::chain;
Expand Down Expand Up @@ -160,6 +162,26 @@ struct category_api_obj
time_point_sec last_update;
};

struct tag_api_obj
{
tag_api_obj( const tags::tag_stats_object& o ) :
name( o.tag ),
total_children_rshares2(o.total_children_rshares2),
total_payouts(o.total_payout),
net_votes(o.net_votes),
top_posts(o.top_posts),
comments(o.comments) {}

tag_api_obj() {}

string name;
fc::uint128_t total_children_rshares2;
asset total_payouts;
int32_t net_votes = 0;
uint32_t top_posts = 0;
uint32_t comments = 0;
};

struct account_api_obj
{
account_api_obj( const chain::account_object& a, const chain::account_authority_object& auth ) :
Expand Down Expand Up @@ -483,6 +505,15 @@ FC_REFLECT( steemit::app::feed_history_api_obj,
(price_history)
)

FC_REFLECT( steemit::app::tag_api_obj,
(name)
(total_children_rshares2)
(total_payouts)
(net_votes)
(top_posts)
(comments)
)

FC_REFLECT( steemit::app::witness_api_obj,
(id)
(owner)
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,8 @@ void database::cashout_comment_helper( const comment_object& comment )
c.last_payout = head_block_time();
} );

push_virtual_operation( comment_payout_update_operation( comment.author, to_string( comment.permlink ) ) );

const auto& vote_idx = get_index< comment_vote_index >().indices().get< by_comment_voter >();
auto vote_itr = vote_idx.lower_bound( comment.id );
while( vote_itr != vote_idx.end() && vote_itr->comment == comment.id )
Expand Down
Loading

0 comments on commit af50afd

Please sign in to comment.