get_account_history does not return the first element when index> -1

in #utopian-io8 years ago (edited)

Expected behavior

The account history starts from index=0. E.g. the account test has 13 account related operation.

https://api.steemjs.com/get_account_history?account=test&from=-1&limit=13

or

from steem.account import Account
acc = Account("test")
for h in acc.get_account_history(-1,13): print(h["index"])

Returns 13 operation starting from index 0 to 12.


image.png

When specifying from it is expected that operation up to index 0 can be retrieved.

https://api.steemjs.com/get_account_history?account=test&from=5&limit=6

or

from steem.account import Account
acc = Account("test")
for h in acc.get_account_history(5, 6): print(h["index"])

Should return 6 operations from index 0 to index 5.

Actual behavior

The first element with index 0 can only be obtained when set from=-1. This may be work for the account test, but cannot work when the number of account operations is higher than 1000. When setting the from parameter to a value other than -1, the first operation with index 0 cannot be fetched.

When trying to receive the first 6 operation, including operation with index 0, an error Exception:args.start >= args.limit: start must be greater than limit occurs.


image.png

How to reproduce

from steem.account import Account
acc = Account("test")
for h in acc.get_account_history(5, 6): print(h["index"])

or

https://api.steemjs.com/get_account_history?account=test&from=5&limit=6
  • Python 3.6 / Anaconda with python-steem 1.0.0
  • Browser: Chrome 65.0.3325.181
  • Operating system: Windows 10
  • Node: https://api.steemit.com with version 0.19.4

Possible solution

https://github.com/steemit/steem/blob/master/libraries/plugins/apis/account_history_api/account_history_api.cpp
Change line 74:

if( n >= args.limit )

to

if( n > args.limit )

Complete listing of the function:

DEFINE_API_IMPL( account_history_api_impl, get_account_history )
{
   FC_ASSERT( args.limit <= 10000, "limit of ${l} is greater than maxmimum allowed", ("l",args.limit) );
   FC_ASSERT( args.start >= args.limit, "start must be greater than limit" );

   const auto& idx = _db.get_index< chain::account_history_index, chain::by_account >();
   auto itr = idx.lower_bound( boost::make_tuple( args.account, args.start ) );
   uint32_t n = 0;

   get_account_history_return result;
   while( true )
   {
      if( itr == idx.end() )
         break;
      if( itr->account != args.account )
         break;
      if( n > args.limit )
         break;
      result.history[ itr->sequence ] = _db.get( itr->op );
      ++itr;
      ++n;
   }

   return result;
}



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thanks it has been approved .
It would be better if you submit it to the github .


Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.

[utopian-moderator]

Hey @cha0s0000, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

.

Loading...

Hey @crokkon, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

You have a minor misspelling in the following sentence:

When trying to recieve the first 6 operation, including operation with index 0, an error `Exception:args.
It should be receive instead of recieve.

Hey @holger80! Thank you for the great work you've done!

We're already looking forward to your next contribution!

Fully Decentralized Rewards

We hope you will take the time to share your expertise and knowledge by rating contributions made by others on Utopian.io to help us reward the best contributions together.

Utopian Witness!

Vote for Utopian Witness! We are made of developers, system administrators, entrepreneurs, artists, content creators, thinkers. We embrace every nationality, mindset and belief.

Want to chat? Join us on Discord https://discord.me/utopian-io

Loading...