From c89d60ba92800967ce814d63813b976168fa4081 Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Thu, 10 Dec 2015 14:13:49 -0500 Subject: [PATCH] First implementation of get_account_history api changes. --- libraries/app/CMakeLists.txt | 2 +- libraries/app/api.cpp | 22 +++++++++++++ libraries/app/include/graphene/app/api.hpp | 5 +++ .../chain/operation_history_object.hpp | 31 +++++++++++++++++-- .../account_history_plugin.cpp | 24 -------------- .../account_history_plugin.hpp | 31 ++++++++++++++++++- 6 files changed, 87 insertions(+), 28 deletions(-) diff --git a/libraries/app/CMakeLists.txt b/libraries/app/CMakeLists.txt index caef157e..b01e3bde 100644 --- a/libraries/app/CMakeLists.txt +++ b/libraries/app/CMakeLists.txt @@ -11,7 +11,7 @@ add_library( graphene_app ${EGENESIS_HEADERS} ) -target_link_libraries( graphene_app graphene_market_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities ) +target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities ) target_include_directories( graphene_app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" ) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 9533588b..635867a4 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -357,6 +357,28 @@ 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 + { + FC_ASSERT(_app.chain_database()); + const auto& db = *_app.chain_database(); + FC_ASSERT(limit <= 100); + vector result; + if (start == 0) + start = account(db).statistics(db).total_ops; + 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 ) ); + + while ( itr != by_seq_idx.end() && itr->sequence > stop && result.size() < limit ) + { + result.push_back( itr->operation_id(db) ); + ++itr; + } + + return result; + } flat_set history_api::get_market_history_buckets()const { diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 46c6d457..9f092902 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -70,6 +70,11 @@ namespace graphene { namespace app { unsigned limit = 100, operation_history_id_type start = operation_history_id_type())const; + vector get_relative_account_history( account_id_type account, + uint32_t stop = 0, + unsigned limit = 100, + uint32_t start = 0) const; + vector get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const; vector get_market_history( asset_id_type a, asset_id_type b, uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const; diff --git a/libraries/chain/include/graphene/chain/operation_history_object.hpp b/libraries/chain/include/graphene/chain/operation_history_object.hpp index 4bf6b527..746d8eba 100644 --- a/libraries/chain/include/graphene/chain/operation_history_object.hpp +++ b/libraries/chain/include/graphene/chain/operation_history_object.hpp @@ -21,6 +21,7 @@ #pragma once #include #include +#include namespace graphene { namespace chain { @@ -91,9 +92,35 @@ namespace graphene { namespace chain { uint32_t sequence = 0; /// the operation position within the given account account_transaction_history_id_type next; - std::pair account_op()const { return std::tie( account, operation_id ); } - std::pair account_seq()const { return std::tie( account, sequence ); } + //std::pair account_op()const { return std::tie( account, operation_id ); } + //std::pair account_seq()const { return std::tie( account, sequence ); } }; + + struct by_id; +struct by_seq; +struct by_op; +typedef multi_index_container< + account_transaction_history_object, + indexed_by< + ordered_unique< tag, member< object, object_id_type, &object::id > >, + ordered_unique< tag, + composite_key< account_transaction_history_object, + member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, + member< account_transaction_history_object, uint32_t, &account_transaction_history_object::sequence> + > + >, + ordered_unique< tag, + composite_key< account_transaction_history_object, + member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, + member< account_transaction_history_object, operation_history_id_type, &account_transaction_history_object::operation_id> + > + > + > +> account_transaction_history_multi_index_type; + +typedef generic_index account_transaction_history_index; + + } } // graphene::chain FC_REFLECT_DERIVED( graphene::chain::operation_history_object, (graphene::chain::object), diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index 58d4293e..0d1c4f59 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -138,30 +138,6 @@ void account_history_plugin_impl::update_account_histories( const signed_block& } // end namespace detail -struct by_id; -struct by_seq; -struct by_op; -typedef multi_index_container< - account_transaction_history_object, - indexed_by< - ordered_unique< tag, - member< object, object_id_type, &object::id > >, - ordered_unique< tag, - composite_key< account_transaction_history_object, - member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, - member< account_transaction_history_object, uint32_t, &account_transaction_history_object::sequence> - > - >, - ordered_unique< tag, - composite_key< account_transaction_history_object, - member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, - member< account_transaction_history_object, operation_history_id_type, &account_transaction_history_object::operation_id> - > - > - > -> account_transaction_history_multi_index_type; - -typedef generic_index account_transaction_history_index; diff --git a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp index e6edc8a5..61e71c77 100644 --- a/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp +++ b/libraries/plugins/account_history/include/graphene/account_history/account_history_plugin.hpp @@ -23,10 +23,15 @@ #include #include +#include + #include namespace graphene { namespace account_history { -using namespace chain; + using namespace chain; + //using namespace graphene::db; + //using boost::multi_index_container; + //using namespace boost::multi_index; // // Plugins should #define their SPACE_ID's so plugins with @@ -75,3 +80,27 @@ class account_history_plugin : public graphene::app::plugin } } //graphene::account_history +/*struct by_id; +struct by_seq; +struct by_op; +typedef boost::multi_index_container< + graphene::chain::account_transaction_history_object, + boost::multi_index::indexed_by< + boost::multi_index::ordered_unique< tag, member< object, object_id_type, &object::id > >, + boost::multi_index::ordered_unique< tag, + composite_key< account_transaction_history_object, + member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, + member< account_transaction_history_object, uint32_t, &account_transaction_history_object::sequence> + > + >, + boost::multi_index::ordered_unique< tag, + composite_key< account_transaction_history_object, + member< account_transaction_history_object, account_id_type, &account_transaction_history_object::account>, + member< account_transaction_history_object, operation_history_id_type, &account_transaction_history_object::operation_id> + > + > + > +> account_transaction_history_multi_index_type; + +typedef graphene::account_history::generic_index account_transaction_history_index; +*/ \ No newline at end of file