diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index e9f7d197..5e6d57cb 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -336,23 +336,26 @@ namespace graphene { namespace app { return result; } - vector history_api::get_account_history(account_id_type account, operation_history_id_type stop, unsigned limit, operation_history_id_type start) const + vector history_api::get_account_history( account_id_type account, + operation_history_id_type stop, + unsigned limit, + operation_history_id_type start ) const { - FC_ASSERT(_app.chain_database()); + FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); - FC_ASSERT(limit <= 100); + FC_ASSERT( limit <= 100 ); vector result; const auto& stats = account(db).statistics(db); - if(stats.most_recent_op == account_transaction_history_id_type()) return result; + 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()) + 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()) + 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); } @@ -360,23 +363,29 @@ namespace graphene { namespace app { return result; } - vector history_api::get_relative_account_history( account_id_type account, uint32_t stop, unsigned limit, uint32_t start) const + vector history_api::get_relative_account_history( account_id_type account, + uint32_t stop, + unsigned limit, + uint32_t start) const { - FC_ASSERT(_app.chain_database()); + FC_ASSERT( _app.chain_database() ); const auto& db = *_app.chain_database(); FC_ASSERT(limit <= 100); vector result; - if (start == 0) + if( start == 0 ) start = account(db).statistics(db).total_ops; + else start = min( account(db).statistics(db).total_ops, start ); const auto& hist_idx = db.get_index_type(); const auto& by_seq_idx = hist_idx.indices().get(); auto itr = by_seq_idx.upper_bound( boost::make_tuple( account, start ) ); + auto itr_stop = by_seq_idx.lower_bound( boost::make_tuple( account, stop ) ); + --itr; - while ( itr != by_seq_idx.end() && itr->sequence > stop && result.size() < limit ) + while ( itr != itr_stop && result.size() < limit ) { result.push_back( itr->operation_id(db) ); - ++itr; + --itr; } return result; diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 9f092902..fb31033a 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -69,7 +69,18 @@ namespace graphene { namespace app { operation_history_id_type stop = operation_history_id_type(), unsigned limit = 100, operation_history_id_type start = operation_history_id_type())const; - + /** + * @breif Get operations relevant to the specified account referenced + * by an event numbering specific to the account. The current number of operations + * for the account can be found in the account statistics (or use 0 for start). + * @param account The account whose history should be queried + * @param stop Sequence number of earliest operation. 0 is default and will + * query 'limit' number of operations. + * @param limit Maximum number of operations to retrieve (must not exceed 100) + * @param start Sequence number of the most recent operation to retrieve. + * 0 is default, which will start querying from the most recent operation. + * @return A list of operations performed by account, ordered from most recent to oldest. + */ vector get_relative_account_history( account_id_type account, uint32_t stop = 0, unsigned limit = 100, @@ -209,6 +220,7 @@ FC_REFLECT( graphene::app::network_broadcast_api::transaction_confirmation, FC_API(graphene::app::history_api, (get_account_history) + (get_relative_account_history) (get_fill_order_history) (get_market_history) (get_market_history_buckets)