diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 53cb6c36..9533588b 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -310,7 +310,7 @@ namespace graphene { namespace app { return result; } // end get_relevant_accounts( obj ) - vector history_api::get_fill_order_history( asset_id_type a, asset_id_type b )const + vector history_api::get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const { FC_ASSERT(_app.chain_database()); const auto& db = *_app.chain_database(); @@ -319,15 +319,18 @@ namespace graphene { namespace app { history_key hkey; hkey.base = a; hkey.quote = b; - hkey.sequence = 0; + hkey.sequence = std::numeric_limits::min(); + uint32_t count = 0; auto itr = history_idx.lower_bound( hkey ); - vector result; + vector result; while( itr != history_idx.end() ) { if( itr->key.base != a || itr->key.quote != b ) break; - result.push_back( itr->op ); + result.push_back( *itr ); ++itr; + ++count; + if( count > limit ) break; } return result; diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index 1b800b46..46c6d457 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -70,7 +70,7 @@ namespace graphene { namespace app { unsigned limit = 100, operation_history_id_type start = operation_history_id_type())const; - vector get_fill_order_history( asset_id_type a, asset_id_type b )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; flat_set get_market_history_buckets()const; diff --git a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp index 9b2b855d..a29c2e74 100644 --- a/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp +++ b/libraries/plugins/market_history/include/graphene/market_history/market_history_plugin.hpp @@ -87,7 +87,7 @@ struct bucket_object : public abstract_object struct history_key { asset_id_type base; asset_id_type quote; - uint64_t sequence = 0; + int64_t sequence = 0; friend bool operator < ( const history_key& a, const history_key& b ) { return std::tie( a.base, a.quote, a.sequence ) < std::tie( b.base, b.quote, b.sequence ); @@ -99,6 +99,7 @@ struct history_key { struct order_history_object : public abstract_object { history_key key; + fc::time_point_sec time; fill_order_operation op; }; @@ -159,7 +160,7 @@ class market_history_plugin : public graphene::app::plugin } } //graphene::market_history FC_REFLECT( graphene::market_history::history_key, (base)(quote)(sequence) ) -FC_REFLECT_DERIVED( graphene::market_history::order_history_object, (graphene::db::object), (key)(op) ) +FC_REFLECT_DERIVED( graphene::market_history::order_history_object, (graphene::db::object), (key)(time)(op) ) FC_REFLECT( graphene::market_history::bucket_key, (base)(quote)(seconds)(open) ) FC_REFLECT_DERIVED( graphene::market_history::bucket_object, (graphene::db::object), (key) diff --git a/libraries/plugins/market_history/market_history_plugin.cpp b/libraries/plugins/market_history/market_history_plugin.cpp index 0a6fe88d..5fe98b93 100644 --- a/libraries/plugins/market_history/market_history_plugin.cpp +++ b/libraries/plugins/market_history/market_history_plugin.cpp @@ -83,37 +83,39 @@ struct operation_process_fill_order const auto& bucket_idx = db.get_index_type(); const auto& history_idx = db.get_index_type().indices().get(); + auto time = db.head_block_time(); + history_key hkey; hkey.base = o.pays.asset_id; hkey.quote = o.receives.asset_id; if( hkey.base > hkey.quote ) std::swap( hkey.base, hkey.quote ); - hkey.sequence = uint64_t(-1); + hkey.sequence = std::numeric_limits::min(); - auto itr = history_idx.upper_bound( hkey ); - if( itr != history_idx.begin() ) - --itr; + auto itr = history_idx.lower_bound( hkey ); if( itr->key.base == hkey.base && itr->key.quote == hkey.quote ) - hkey.sequence = itr->key.sequence + 1; + hkey.sequence = itr->key.sequence - 1; else hkey.sequence = 0; db.create( [&]( order_history_object& ho ) { ho.key = hkey; + ho.time = time; ho.op = o; }); - if( hkey.sequence > 200 ) - { - auto end = hkey.sequence - 200; - itr = history_idx.lower_bound( hkey ); - while( itr != history_idx.end() && itr->key.sequence < end ) + hkey.sequence += 200; + itr = history_idx.lower_bound( hkey ); + + while( itr != history_idx.end() ) + { + if( itr->key.base == hkey.base && itr->key.quote == hkey.quote ) { - auto delete_me = itr; - ++itr; - db.remove( *delete_me ); + db.remove( *itr ); + itr = history_idx.lower_bound( hkey ); } + else break; }