Skip to content

Commit

Permalink
Merge pull request cryptonomex#628 from oxarbitrage/issue613
Browse files Browse the repository at this point in the history
change get_account_history api call
  • Loading branch information
oxarbitrage authored Feb 22, 2018
2 parents 0da4ff2 + efe3310 commit 68a5390
Show file tree
Hide file tree
Showing 3 changed files with 469 additions and 26 deletions.
35 changes: 18 additions & 17 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,26 +302,27 @@ namespace graphene { namespace app {
const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 );
vector<operation_history_object> result;
const auto& stats = account(db).statistics(db);
if( stats.most_recent_op == account_transaction_history_id_type() ) return result;
const account_transaction_history_object* node = &stats.most_recent_op(db);
if( start == operation_history_id_type() )
start = node->operation_id;

while(node && node->operation_id.instance.value > stop.instance.value && result.size() < limit)
try {
const account_transaction_history_object& node = account(db).statistics(db).most_recent_op(db);
if(start == operation_history_id_type() || start.instance.value > node.operation_id.instance.value)
start = node.operation_id;
} catch(...) { return result; }

const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
const auto& by_op_idx = hist_idx.indices().get<by_op>();
auto index_start = by_op_idx.begin();
auto itr = by_op_idx.lower_bound(boost::make_tuple(account, start));

while(itr != index_start && itr->account == account && itr->operation_id.instance.value > stop.instance.value && result.size() < limit)
{
if( node->operation_id.instance.value <= start.instance.value )
result.push_back( node->operation_id(db) );
if( node->next == account_transaction_history_id_type() )
node = nullptr;
else node = &node->next(db);
if(itr->operation_id.instance.value <= start.instance.value)
result.push_back(itr->operation_id(db));
--itr;
}
if( stop.instance.value == 0 && result.size() < limit )
{
node = db.find(account_transaction_history_id_type());
if( node && node->account == account)
result.push_back( node->operation_id(db) );
if(stop.instance.value == 0 && result.size() < limit && itr->account == account) {
result.push_back(itr->operation_id(db));
}

return result;
}

Expand Down
18 changes: 17 additions & 1 deletion tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,23 @@ database_fixture::database_fixture()
genesis_state.initial_parameters.current_fees->zero_all_fees();
open_database();

// app.initialize();
// add account tracking for ahplugin for special test case with track-account enabled
if( !options.count("track-account") && boost::unit_test::framework::current_test_case().p_name.value == "track_account") {
std::vector<std::string> track_account;
std::string track = "\"1.2.17\"";
track_account.push_back(track);
options.insert(std::make_pair("track-account", boost::program_options::variable_value(track_account, false)));
}
// account tracking 2 accounts
if( !options.count("track-account") && boost::unit_test::framework::current_test_case().p_name.value == "track_account2") {
std::vector<std::string> track_account;
std::string track = "\"1.2.0\"";
track_account.push_back(track);
track = "\"1.2.16\"";
track_account.push_back(track);
options.insert(std::make_pair("track-account", boost::program_options::variable_value(track_account, false)));
}

ahplugin->plugin_set_app(&app);
ahplugin->plugin_initialize(options);

Expand Down
Loading

0 comments on commit 68a5390

Please sign in to comment.