Skip to content

Commit

Permalink
Merge pull request steemit#640 from GolosChain/639-account_votes-pagi…
Browse files Browse the repository at this point in the history
…nations

Add paginations to social_network::get_account_votes. steemit#639
  • Loading branch information
afalaleev authored May 14, 2018
2 parents 0302b59 + 2372aa0 commit 7b3e68d
Show file tree
Hide file tree
Showing 40 changed files with 1,140 additions and 943 deletions.
2 changes: 1 addition & 1 deletion libraries/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ list(APPEND CURRENT_TARGET_HEADERS
list(APPEND CURRENT_TARGET_SOURCES
account_api_object.cpp
discussion_helper.cpp

comment_api_object.cpp
)

if(BUILD_SHARED_LIBRARIES)
Expand Down
54 changes: 54 additions & 0 deletions libraries/api/comment_api_object.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <golos/api/comment_api_object.hpp>

namespace golos { namespace api {

using namespace golos::chain;

comment_api_object::comment_api_object(const golos::chain::comment_object &o, const golos::chain::database &db)
: id(o.id),
parent_author(o.parent_author),
parent_permlink(to_string(o.parent_permlink)),
author(o.author),
permlink(to_string(o.permlink)),
last_update(o.last_update),
created(o.created),
active(o.active),
last_payout(o.last_payout),
depth(o.depth),
children(o.children),
children_rshares2(o.children_rshares2),
net_rshares(o.net_rshares),
abs_rshares(o.abs_rshares),
vote_rshares(o.vote_rshares),
children_abs_rshares(o.children_abs_rshares),
cashout_time(o.cashout_time),
max_cashout_time(o.max_cashout_time),
total_vote_weight(o.total_vote_weight),
reward_weight(o.reward_weight),
total_payout_value(o.total_payout_value),
curator_payout_value(o.curator_payout_value),
author_rewards(o.author_rewards),
net_votes(o.net_votes),
mode(o.mode),
root_comment(o.root_comment),
max_accepted_payout(o.max_accepted_payout),
percent_steem_dollars(o.percent_steem_dollars),
allow_replies(o.allow_replies),
allow_votes(o.allow_votes),
allow_curation_rewards(o.allow_curation_rewards) {

for (auto& route : o.beneficiaries) {
beneficiaries.push_back(route);
}
#ifndef IS_LOW_MEM
auto& content = db.get_comment_content(o.id);

title = to_string(content.title);
body = to_string(content.body);
json_metadata = to_string(content.json_metadata);
#endif
}

comment_api_object::comment_api_object() = default;

} } // golos::api
3 changes: 1 addition & 2 deletions libraries/api/include/golos/api/account_vote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
#include <fc/reflect/reflect.hpp>
#include <fc/time.hpp>

namespace golos {
namespace api {
namespace golos { namespace api {

struct account_vote {
std::string authorperm;
Expand Down
45 changes: 10 additions & 35 deletions libraries/api/include/golos/api/comment_api_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,8 @@ namespace golos { namespace api {
using namespace golos::chain;

struct comment_api_object {
comment_api_object(const golos::chain::comment_object &o, const golos::chain::database &db) :
id(o.id),
parent_author(o.parent_author), parent_permlink(to_string(o.parent_permlink)), author(o.author),
permlink(to_string(o.permlink)), last_update(o.last_update), created(o.created),
active(o.active), last_payout(o.last_payout), depth(o.depth), children(o.children),
children_rshares2(o.children_rshares2), net_rshares(o.net_rshares), abs_rshares(o.abs_rshares),
vote_rshares(o.vote_rshares), children_abs_rshares(o.children_abs_rshares),
cashout_time(o.cashout_time), max_cashout_time(o.max_cashout_time),
total_vote_weight(o.total_vote_weight), reward_weight(o.reward_weight),
total_payout_value(o.total_payout_value), curator_payout_value(o.curator_payout_value),
author_rewards(o.author_rewards), net_votes(o.net_votes), mode(o.mode),
root_comment(o.root_comment), max_accepted_payout(o.max_accepted_payout),
percent_steem_dollars(o.percent_steem_dollars), allow_replies(o.allow_replies),
allow_votes(o.allow_votes), allow_curation_rewards(o.allow_curation_rewards) {

for (auto& route : o.beneficiaries) {
beneficiaries.push_back(route);
}
auto content = db.get_comment_content(o.id);

title = to_string(content.title);
body = to_string(content.body);
json_metadata = to_string(content.json_metadata);
}

comment_api_object() {
}
comment_api_object(const golos::chain::comment_object &o, const golos::chain::database &db);
comment_api_object();

comment_object::id_type id;

Expand Down Expand Up @@ -92,13 +67,13 @@ namespace golos { namespace api {

} } // golos::api

FC_REFLECT((golos::api::comment_api_object),
(id)(author)(permlink)(parent_author)(parent_permlink)(title)(body)(json_metadata)(last_update)(
created)(active)(last_payout)(depth)(children)(children_rshares2)(net_rshares)(abs_rshares)(
vote_rshares)(children_abs_rshares)(cashout_time)(max_cashout_time)(total_vote_weight)(
reward_weight)(total_payout_value)(curator_payout_value)(author_rewards)(net_votes)(
mode)(root_comment)(max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)(
allow_curation_rewards)(beneficiaries))

FC_REFLECT(
(golos::api::comment_api_object),
(id)(author)(permlink)(parent_author)(parent_permlink)(title)(body)(json_metadata)(last_update)
(created)(active)(last_payout)(depth)(children)(children_rshares2)(net_rshares)(abs_rshares)
(vote_rshares)(children_abs_rshares)(cashout_time)(max_cashout_time)(total_vote_weight)
(reward_weight)(total_payout_value)(curator_payout_value)(author_rewards)(net_votes)
(mode)(root_comment)(max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)
(allow_curation_rewards)(beneficiaries))

#endif //GOLOS_COMMENT_API_OBJ_H
11 changes: 5 additions & 6 deletions libraries/api/include/golos/api/extended_account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ namespace golos { namespace api {
* Convert's vesting shares
*/
struct extended_account : public account_api_object {
extended_account() {
}
extended_account() = default;

extended_account(const account_object &a, const golos::chain::database &db)
: account_api_object(a, db) {
Expand All @@ -19,7 +18,7 @@ namespace golos { namespace api {

} } // golos::api

FC_REFLECT_DERIVED((golos::api::extended_account),
((golos::api::account_api_object)),
(reputation)
)
FC_REFLECT_DERIVED(
(golos::api::extended_account),
((golos::api::account_api_object)),
(reputation))
2 changes: 1 addition & 1 deletion libraries/chain/include/golos/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace golos {
/**
* This signal is emitted for plugins to process every operation after it has been fully applied.
*/
fc::signal<void(const operation_notification &)> pre_apply_operation;
fc::signal<void(operation_notification &)> pre_apply_operation;
fc::signal<void(const operation_notification &)> post_apply_operation;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace golos {
operation_notification(const operation &o) : op(o) {
}

bool stored_in_db = false;
int64_t db_id = 0;
transaction_id_type trx_id;
uint32_t block = 0;
uint32_t trx_in_block = 0;
Expand Down
16 changes: 6 additions & 10 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,10 @@ namespace golos { namespace chain {
}
}
}

auto* content = _db.find_comment_content(comment.id);

if (content) {
_db.remove(*content);
}
#ifndef IS_LOW_MEM
auto& content = _db.get_comment_content(comment.id);
_db.remove(content);
#endif
_db.remove(comment);
}

Expand Down Expand Up @@ -643,10 +641,9 @@ namespace golos { namespace chain {

});
id = new_comment.id;

#ifndef IS_LOW_MEM
_db.create<comment_content_object>([&](comment_content_object& con) {
con.comment = id;
#ifndef IS_LOW_MEM
from_string(con.title, o.title);
if (o.body.size() < 1024*1024*128) {
from_string(con.body, o.body);
Expand All @@ -657,9 +654,8 @@ namespace golos { namespace chain {
wlog("Comment ${a}/${p} contains invalid UTF-8 metadata",
("a", o.author)("p", o.permlink));
}
#endif
});

#endif
/// this loop can be skiped for validate-only nodes as it is merely gathering stats for indicies
auto now = _db.head_block_time();
while (parent) {
Expand Down
1 change: 1 addition & 0 deletions libraries/wallet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ target_link_libraries(
golos::network_broadcast_api
golos::database_api
golos::account_history
golos::operation_history
golos::market_history
golos::social_network
golos::tags
Expand Down
40 changes: 33 additions & 7 deletions libraries/wallet/include/golos/wallet/remote_node_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <golos/plugins/database_api/plugin.hpp>
#include <golos/plugins/database_api/forward.hpp>
#include <golos/plugins/database_api/state.hpp>
#include <golos/plugins/account_history/applied_operation.hpp>
#include <golos/plugins/operation_history/applied_operation.hpp>
#include <fc/api.hpp>
#include <golos/plugins/network_broadcast_api/network_broadcast_api_plugin.hpp>
#include <golos/plugins/tags/tag_api_object.hpp>
Expand Down Expand Up @@ -46,7 +46,6 @@ using namespace plugins::witness_api;
struct remote_database_api {
optional< database_api::signed_block > get_block( uint32_t );
optional< block_header > get_block_header( uint32_t );
vector< golos::plugins::account_history::applied_operation > get_ops_in_block( uint32_t, bool only_virtual = true );
fc::variant_object get_config();
database_api::dynamic_global_property_object get_dynamic_global_properties();
chain_properties get_chain_properties();
Expand All @@ -66,17 +65,32 @@ struct remote_database_api {
vector< database_api::convert_request_api_object > get_conversion_requests( account_name_type );
vector< database_api::extended_limit_order > get_open_orders( account_name_type );
string get_transaction_hex( signed_transaction );
annotated_signed_transaction get_transaction( transaction_id_type );
set< public_key_type > get_required_signatures( signed_transaction, flat_set< public_key_type > );
set< public_key_type > get_potential_signatures( signed_transaction );
bool verify_authority( signed_transaction );
bool verify_account_authority( string, flat_set< public_key_type > );
vector< golos::api::account_api_object > get_accounts( vector< account_name_type > );
map<uint32_t, golos::plugins::account_history::applied_operation> get_account_history( account_name_type, uint64_t, uint32_t );
database_api::database_info get_database_info();
std::vector<proposal_api_object> get_proposed_transactions(account_name_type, uint32_t, uint32_t);
};

/**
* This is a dummy class exists only to provide method signature information to fc::api, not to execute calls.
* Class is used by wallet to send formatted API calls to operation_history plugin on remote node.
*/
struct remote_operation_history {
vector< golos::plugins::operation_history::applied_operation > get_ops_in_block( uint32_t, bool only_virtual = true );
annotated_signed_transaction get_transaction( transaction_id_type );
};

/**
* This is a dummy class exists only to provide method signature information to fc::api, not to execute calls.
* Class is used by wallet to send formatted API calls to operation_history plugin on remote node.
*/
struct remote_account_history {
map<uint32_t, golos::plugins::operation_history::applied_operation> get_account_history( account_name_type, uint64_t, uint32_t );
};

/**
* This is a dummy class exists only to provide method signature information to fc::api, not to execute calls.
* Class is used by wallet to send formatted API calls to social_network plugin on remote node.
Expand Down Expand Up @@ -198,7 +212,6 @@ struct remote_witness_api {
FC_API( golos::wallet::remote_database_api,
(get_block)
(get_block_header)
(get_ops_in_block)
(get_config)
(get_dynamic_global_properties)
(get_chain_properties)
Expand All @@ -217,17 +230,30 @@ FC_API( golos::wallet::remote_database_api,
(get_conversion_requests)
(get_open_orders)
(get_transaction_hex)
(get_transaction)
(get_required_signatures)
(get_potential_signatures)
(verify_authority)
(verify_account_authority)
(get_accounts)
(get_account_history)
(get_database_info)
(get_proposed_transactions)
)

/**
* Declaration of remote API formatter to operation_history plugin on remote node
*/
FC_API( golos::wallet::remote_operation_history,
(get_ops_in_block)
(get_transaction)
)

/**
* Declaration of remote API formatter to account_history plugin on remote node
*/
FC_API( golos::wallet::remote_account_history,
(get_account_history)
)

/**
* Declaration of remote API formatter to social_network plugin on remote node
*/
Expand Down
4 changes: 2 additions & 2 deletions libraries/wallet/include/golos/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ namespace golos { namespace wallet {
* @param block_num Block height of specified block
* @param only_virtual Whether to only return virtual operations
*/
vector<golos::plugins::account_history::applied_operation> get_ops_in_block( uint32_t block_num, bool only_virtual = true );
vector<golos::plugins::operation_history::applied_operation> get_ops_in_block( uint32_t block_num, bool only_virtual = true );

/** Return the current price feed history
*
Expand Down Expand Up @@ -1013,7 +1013,7 @@ namespace golos { namespace wallet {
* @param from - the absolute sequence number, -1 means most recent, limit is the number of operations before from.
* @param limit - the maximum number of items that can be queried (0 to 1000], must be less than from
*/
map< uint32_t, golos::plugins::account_history::applied_operation >
map< uint32_t, golos::plugins::operation_history::applied_operation >
get_account_history( string account, uint32_t from, uint32_t limit );


Expand Down
30 changes: 17 additions & 13 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,16 @@ namespace golos { namespace wallet {
wallet_api& self;
wallet_api_impl( wallet_api& s, const wallet_data& initial_data, const golos::protocol::chain_id_type& _steem_chain_id, fc::api_connection& con ):
self( s ),
_remote_database_api( con.get_remote_api< golos::wallet::remote_database_api >( 0, "database_api" ) ),
_remote_social_network( con.get_remote_api< golos::wallet::remote_social_network >( 0, "social_network" ) ),
_remote_network_broadcast_api( con.get_remote_api< golos::wallet::remote_network_broadcast_api >( 0, "network_broadcast_api" ) ),
_remote_follow( con.get_remote_api< golos::wallet::remote_follow >( 0, "follow" ) ),
_remote_market_history( con.get_remote_api< golos::wallet::remote_market_history >( 0, "market_history" ) ),
_remote_private_message( con.get_remote_api< golos::wallet::remote_private_message>( 0, "private_message" ) ),
_remote_account_by_key( con.get_remote_api< golos::wallet::remote_account_by_key>( 0, "account_by_key" ) ) ,
_remote_witness_api( con.get_remote_api< golos::wallet::remote_witness_api >( 0, "witness_api" ) )
_remote_database_api( con.get_remote_api< remote_database_api >( 0, "database_api" ) ),
_remote_operation_history( con.get_remote_api< remote_operation_history >( 0, "operation_history" ) ),
_remote_account_history( con.get_remote_api< remote_account_history >( 0, "account_history" ) ),
_remote_social_network( con.get_remote_api< remote_social_network >( 0, "social_network" ) ),
_remote_network_broadcast_api( con.get_remote_api< remote_network_broadcast_api >( 0, "network_broadcast_api" ) ),
_remote_follow( con.get_remote_api< remote_follow >( 0, "follow" ) ),
_remote_market_history( con.get_remote_api< remote_market_history >( 0, "market_history" ) ),
_remote_private_message( con.get_remote_api< remote_private_message>( 0, "private_message" ) ),
_remote_account_by_key( con.get_remote_api< remote_account_by_key>( 0, "account_by_key" ) ) ,
_remote_witness_api( con.get_remote_api< remote_witness_api >( 0, "witness_api" ) )
{
init_prototype_ops();

Expand Down Expand Up @@ -982,6 +984,8 @@ namespace golos { namespace wallet {
map<public_key_type,string> _keys;
fc::sha512 _checksum;
fc::api< remote_database_api > _remote_database_api;
fc::api< remote_operation_history > _remote_operation_history;
fc::api< remote_account_history > _remote_account_history;
fc::api< remote_social_network > _remote_social_network;
fc::api< remote_network_broadcast_api> _remote_network_broadcast_api;
fc::api< remote_follow > _remote_follow;
Expand Down Expand Up @@ -1022,8 +1026,8 @@ namespace golos { namespace wallet {
return my->_remote_database_api->get_block( num );
}

vector< golos::plugins::account_history::applied_operation > wallet_api::get_ops_in_block(uint32_t block_num, bool only_virtual) {
return my->_remote_database_api->get_ops_in_block( block_num, only_virtual );
vector< golos::plugins::operation_history::applied_operation > wallet_api::get_ops_in_block(uint32_t block_num, bool only_virtual) {
return my->_remote_operation_history->get_ops_in_block( block_num, only_virtual );
}

vector< golos::api::account_api_object > wallet_api::list_my_accounts() {
Expand Down Expand Up @@ -2265,8 +2269,8 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
return my->sign_transaction( tx, broadcast );
}

map< uint32_t, golos::plugins::account_history::applied_operation> wallet_api::get_account_history( string account, uint32_t from, uint32_t limit ) {
auto result = my->_remote_database_api->get_account_history( account, from, limit );
map< uint32_t, golos::plugins::operation_history::applied_operation> wallet_api::get_account_history( string account, uint32_t from, uint32_t limit ) {
auto result = my->_remote_account_history->get_account_history( account, from, limit );
if( !is_locked() ) {
for( auto& item : result ) {
if( item.second.op.which() == operation::tag<transfer_operation>::value ) {
Expand Down Expand Up @@ -2369,7 +2373,7 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
}

annotated_signed_transaction wallet_api::get_transaction( transaction_id_type id )const {
return my->_remote_database_api->get_transaction( id );
return my->_remote_operation_history->get_transaction( id );
}

vector<extended_message_object> wallet_api::get_inbox(const std::string& to, time_point newest, uint16_t limit, std::uint64_t offset) {
Expand Down
Loading

0 comments on commit 7b3e68d

Please sign in to comment.