diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index e68c271892..c5aa195f6b 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -445,94 +445,6 @@ vector> database_api_impl::get_accounts( const vector database_api::get_account_limit_orders( - const string& account_name_or_id, const string &base, const string "e, - uint32_t limit, optional ostart_id, optional ostart_price ) -{ - return my->get_account_limit_orders( account_name_or_id, base, quote, limit, ostart_id, ostart_price ); -} - -vector database_api_impl::get_account_limit_orders( - const string& account_name_or_id, const string &base, const string "e, - uint32_t limit, optional ostart_id, optional ostart_price ) -{ - FC_ASSERT( limit <= 101 ); - - vector results; - uint32_t count = 0; - - const account_object* account = get_account_from_string(account_name_or_id); - if (account == nullptr) - return results; - - auto assets = lookup_asset_symbols( {base, quote} ); - FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) ); - FC_ASSERT( assets[1], "Invalid quote asset symbol: ${s}", ("s",quote) ); - - auto base_id = assets[0]->id; - auto quote_id = assets[1]->id; - - if (ostart_price.valid()) { - FC_ASSERT(ostart_price->base.asset_id == base_id, "Base asset inconsistent with start price"); - FC_ASSERT(ostart_price->quote.asset_id == quote_id, "Quote asset inconsistent with start price"); - } - - const auto& index_by_account = _db.get_index_type().indices().get(); - limit_order_multi_index_type::index::type::const_iterator lower_itr; - limit_order_multi_index_type::index::type::const_iterator upper_itr; - - // if both order_id and price are invalid, query the first page - if ( !ostart_id.valid() && !ostart_price.valid() ) - { - lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, price::max(base_id, quote_id))); - } - else if ( ostart_id.valid() ) - { - // in case of the order been deleted during page querying - const limit_order_object *p_loo = _db.find(*ostart_id); - - if ( !p_loo ) - { - if ( ostart_price.valid() ) - { - lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, *ostart_price, *ostart_id)); - } - else - { - // start order id been deleted, yet not provided price either - FC_THROW("Order id invalid (maybe just been canceled?), and start price not provided"); - } - } - else - { - const limit_order_object &loo = *p_loo; - - // in case of the order not belongs to specified account or market - FC_ASSERT(loo.sell_price.base.asset_id == base_id, "Order base asset inconsistent"); - FC_ASSERT(loo.sell_price.quote.asset_id == quote_id, "Order quote asset inconsistent with order"); - FC_ASSERT(loo.seller == account->get_id(), "Order not owned by specified account"); - - lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, loo.sell_price, *ostart_id)); - } - } - else - { - // if reach here start_price must be valid - lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, *ostart_price)); - } - - upper_itr = index_by_account.upper_bound(std::make_tuple(account->id, price::min(base_id, quote_id))); - - // Add the account's orders - for ( ; lower_itr != upper_itr && count < limit; ++lower_itr, ++count) - { - const limit_order_object &order = *lower_itr; - results.emplace_back(order); - } - - return results; -} - std::map database_api::get_full_accounts( const vector& names_or_ids, optional subscribe ) { @@ -1062,6 +974,94 @@ vector database_api_impl::get_limit_orders( const std::strin return get_limit_orders(asset_a_id, asset_b_id, limit); } +vector database_api::get_account_limit_orders( + const string& account_name_or_id, const string &base, const string "e, + uint32_t limit, optional ostart_id, optional ostart_price ) +{ + return my->get_account_limit_orders( account_name_or_id, base, quote, limit, ostart_id, ostart_price ); +} + +vector database_api_impl::get_account_limit_orders( + const string& account_name_or_id, const string &base, const string "e, + uint32_t limit, optional ostart_id, optional ostart_price ) +{ + FC_ASSERT( limit <= 101 ); + + vector results; + uint32_t count = 0; + + const account_object* account = get_account_from_string(account_name_or_id); + if (account == nullptr) + return results; + + auto assets = lookup_asset_symbols( {base, quote} ); + FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) ); + FC_ASSERT( assets[1], "Invalid quote asset symbol: ${s}", ("s",quote) ); + + auto base_id = assets[0]->id; + auto quote_id = assets[1]->id; + + if (ostart_price.valid()) { + FC_ASSERT(ostart_price->base.asset_id == base_id, "Base asset inconsistent with start price"); + FC_ASSERT(ostart_price->quote.asset_id == quote_id, "Quote asset inconsistent with start price"); + } + + const auto& index_by_account = _db.get_index_type().indices().get(); + limit_order_multi_index_type::index::type::const_iterator lower_itr; + limit_order_multi_index_type::index::type::const_iterator upper_itr; + + // if both order_id and price are invalid, query the first page + if ( !ostart_id.valid() && !ostart_price.valid() ) + { + lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, price::max(base_id, quote_id))); + } + else if ( ostart_id.valid() ) + { + // in case of the order been deleted during page querying + const limit_order_object *p_loo = _db.find(*ostart_id); + + if ( !p_loo ) + { + if ( ostart_price.valid() ) + { + lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, *ostart_price, *ostart_id)); + } + else + { + // start order id been deleted, yet not provided price either + FC_THROW("Order id invalid (maybe just been canceled?), and start price not provided"); + } + } + else + { + const limit_order_object &loo = *p_loo; + + // in case of the order not belongs to specified account or market + FC_ASSERT(loo.sell_price.base.asset_id == base_id, "Order base asset inconsistent"); + FC_ASSERT(loo.sell_price.quote.asset_id == quote_id, "Order quote asset inconsistent with order"); + FC_ASSERT(loo.seller == account->get_id(), "Order not owned by specified account"); + + lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, loo.sell_price, *ostart_id)); + } + } + else + { + // if reach here start_price must be valid + lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, *ostart_price)); + } + + upper_itr = index_by_account.upper_bound(std::make_tuple(account->id, price::min(base_id, quote_id))); + + // Add the account's orders + for ( ; lower_itr != upper_itr && count < limit; ++lower_itr, ++count) + { + const limit_order_object &order = *lower_itr; + results.emplace_back(order); + } + + return results; +} + vector database_api::get_call_orders(const std::string& a, uint32_t limit)const { return my->get_call_orders( a, limit );