update fill order history
This commit is contained in:
parent
7378fb80bc
commit
867e87196b
4 changed files with 26 additions and 20 deletions
|
|
@ -310,7 +310,7 @@ namespace graphene { namespace app {
|
|||
return result;
|
||||
} // end get_relevant_accounts( obj )
|
||||
|
||||
vector<fill_order_operation> history_api::get_fill_order_history( asset_id_type a, asset_id_type b )const
|
||||
vector<order_history_object> 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<int64_t>::min();
|
||||
|
||||
uint32_t count = 0;
|
||||
auto itr = history_idx.lower_bound( hkey );
|
||||
vector<fill_order_operation> result;
|
||||
vector<order_history_object> 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;
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ namespace graphene { namespace app {
|
|||
unsigned limit = 100,
|
||||
operation_history_id_type start = operation_history_id_type())const;
|
||||
|
||||
vector<fill_order_operation> get_fill_order_history( asset_id_type a, asset_id_type b )const;
|
||||
vector<order_history_object> get_fill_order_history( asset_id_type a, asset_id_type b, uint32_t limit )const;
|
||||
vector<bucket_object> 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<uint32_t> get_market_history_buckets()const;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ struct bucket_object : public abstract_object<bucket_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<order_history_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)
|
||||
|
|
|
|||
|
|
@ -83,37 +83,39 @@ struct operation_process_fill_order
|
|||
const auto& bucket_idx = db.get_index_type<bucket_index>();
|
||||
const auto& history_idx = db.get_index_type<history_index>().indices().get<by_key>();
|
||||
|
||||
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<int64_t>::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>( [&]( 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue