Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change get_account_history api call #628

Merged
merged 16 commits into from
Feb 22, 2018
26 changes: 13 additions & 13 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,19 @@ namespace graphene { namespace app {
if( start == operation_history_id_type() )
start = node->operation_id;

while(node && node->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( 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) );
const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
const auto& by_op_idx = hist_idx.indices().get<by_op>();

if( start.instance.value >= stop.instance.value) {
auto itr = by_op_idx.lower_bound(boost::make_tuple(account, start));
auto itr_stop = by_op_idx.upper_bound(boost::make_tuple(account, stop));

do {
--itr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe with an appropriate choice of account_id, start and stop you can force itr to step before the first element of the index at this point. The subsequent dereference of itr could crash the node.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, some changes made in this PR didn't follow best practice, so may be error-prone.

The code structure in this PR is copied from get_relative_account_history. However, this API (get_account_history) uses operation_history_id which is harder to check in comparison to sequence used in the other API. Perhaps better refactor it.

if(itr->account == account)
result.push_back(itr->operation_id(db));

} while (itr != itr_stop && itr->operation_id.instance.value > stop.instance.value && itr->operation_id.instance.value <= start.instance.value && result.size() < limit);
}
return result;
}
Expand Down