From d482273addfda67ece29911d9cff2f5cb9791750 Mon Sep 17 00:00:00 2001 From: oxarbitrage Date: Tue, 9 May 2017 20:58:42 -0300 Subject: [PATCH] Expose get_relative_account_history to cli_wallet (#277) --- .../wallet/include/graphene/wallet/wallet.hpp | 10 +++++ libraries/wallet/wallet.cpp | 41 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index b27057f7..4db655ff 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -354,6 +354,15 @@ class wallet_api */ vector get_account_history(string name, int limit)const; + /** Returns the relative operations on the named account from start number. + * + * @param name the name or id of the account + * @param stop Sequence number of earliest operation. + * @param limit the number of entries to return + * @param start the sequence number where to start looping back throw the history + * @returns a list of \c operation_history_objects + */ + vector get_relative_account_history(string name, uint32_t stop, int limit, uint32_t start)const; vector get_market_history(string symbol, string symbol2, uint32_t bucket, fc::time_point_sec start, fc::time_point_sec end)const; vector get_limit_orders(string a, string b, uint32_t limit)const; @@ -1651,6 +1660,7 @@ FC_API( graphene::wallet::wallet_api, (get_block) (get_account_count) (get_account_history) + (get_relative_account_history) (is_public_key_registered) (get_market_history) (get_global_properties) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 16a30893..eb6bc887 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2088,6 +2088,23 @@ public: return ss.str(); }; + m["get_relative_account_history"] = [this](variant result, const fc::variants& a) + { + auto r = result.as>(); + std::stringstream ss; + + for( operation_detail& d : r ) + { + operation_history_object& i = d.op; + auto b = _remote_db->get_block_header(i.block_num); + FC_ASSERT(b); + ss << b->timestamp.to_iso_string() << " "; + i.op.visit(operation_printer(ss, *this, i.result)); + ss << " \n"; + } + + return ss.str(); + }; m["list_account_balances"] = [this](variant result, const fc::variants& a) { @@ -2818,6 +2835,30 @@ vector wallet_api::get_account_history(string name, int limit) return result; } +vector wallet_api::get_relative_account_history(string name, uint32_t stop, int limit, uint32_t start)const +{ + + FC_ASSERT( start > 0 || limit <= 100 ); + + vector result; + auto account_id = get_account(name).get_id(); + + while( limit > 0 ) + { + vector current = my->_remote_hist->get_relative_account_history(account_id, stop, std::min(100, limit), start); + for (auto &o : current) { + std::stringstream ss; + auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); + result.push_back(operation_detail{memo, ss.str(), o}); + } + if (current.size() < std::min(100, limit)) + break; + limit -= current.size(); + start -= 100; + if( start == 0 ) break; + } + return result; +} vector wallet_api::get_market_history( string symbol1, string symbol2, uint32_t bucket , fc::time_point_sec start, fc::time_point_sec end )const {