Skip to content

Commit

Permalink
Merge pull request cryptonomex#237 from oxarbitrage/issue222
Browse files Browse the repository at this point in the history
added api function get_account_history_operations
  • Loading branch information
vikramrajkumar committed Feb 28, 2017
2 parents b3a023e + 3d349fb commit c1b45f1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
31 changes: 31 additions & 0 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,37 @@ namespace graphene { namespace app {
return result;
}

vector<operation_history_object> 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<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)
{
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<operation_history_object> history_api::get_relative_account_history( account_id_type account,
uint32_t stop,
unsigned limit,
Expand Down
17 changes: 17 additions & 0 deletions libraries/app/include/graphene/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<operation_history_object> 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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1b45f1

Please sign in to comment.