From 3d349fbde4e58f27fd740a66ca8ac0e27fbd8b8d Mon Sep 17 00:00:00 2001 From: root Date: Wed, 22 Feb 2017 15:35:37 -0800 Subject: [PATCH] added api function get_account_history_operations --- libraries/app/api.cpp | 31 ++++++++++++++++++++++ libraries/app/include/graphene/app/api.hpp | 17 ++++++++++++ 2 files changed, 48 insertions(+) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 40aa7b97..8520a8be 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -453,6 +453,37 @@ namespace graphene { namespace app { return result; } + vector history_api::get_account_history_operations( account_id_type account, + int operation_id, + operation_history_id_type start, + operation_history_id_type stop, + unsigned limit) const + { + FC_ASSERT( _app.chain_database() ); + const auto& db = *_app.chain_database(); + 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; + 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) + { + if( node->operation_id.instance.value <= start.instance.value ) { + + if(node->operation_id(db).op.which() == operation_id) + result.push_back( node->operation_id(db) ); + } + if( node->next == account_transaction_history_id_type() ) + node = nullptr; + else node = &node->next(db); + } + return result; + } + + vector history_api::get_relative_account_history( account_id_type account, uint32_t stop, unsigned limit, diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index be0e0a23..be511d3a 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -105,6 +105,22 @@ 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; + + /** + * @brief Get only asked operations relevant to the specified account + * @param account The account whose history should be queried + * @param operation_id The ID of the operation we want to get operations in the account( 0 = transfer , 1 = limit order create, ...) + * @param stop ID of the earliest operation to retrieve + * @param limit Maximum number of operations to retrieve (must not exceed 100) + * @param start ID of the most recent operation to retrieve + * @return A list of operations performed by account, ordered from most recent to oldest. + */ + vector get_account_history_operations(account_id_type account, + int operation_id, + operation_history_id_type start = operation_history_id_type(), + operation_history_id_type stop = operation_history_id_type(), + unsigned limit = 100)const; + /** * @breif Get operations relevant to the specified account referenced * by an event numbering specific to the account. The current number of operations @@ -366,6 +382,7 @@ FC_REFLECT( graphene::app::asset_holders, (asset_id)(count) ); FC_API(graphene::app::history_api, (get_account_history) + (get_account_history_operations) (get_relative_account_history) (get_fill_order_history) (get_market_history)