Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#463, Add API to query for open orders of one account in one market #849

Merged
merged 18 commits into from
Jul 21, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,13 +646,13 @@ vector<limit_order_object> database_api_impl::get_account_limit_orders( const st
account = _db.find(fc::variant(name_or_id, 1).as<account_id_type>(1));
else
{
const auto& idx = _db.get_index_type<account_index>().indices().get<by_name>();
auto itr = idx.find(name_or_id);
if (itr != idx.end())
account = &*itr;
const auto& idx = _db.get_index_type<account_index>().indices().get<by_name>();
auto itr = idx.find(name_or_id);
if (itr != idx.end())
account = &*itr;
}
if (account == nullptr)
return results;
return results;

auto assets = lookup_asset_symbols( {base, quote} );
FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) );
Expand All @@ -662,8 +662,8 @@ vector<limit_order_object> database_api_impl::get_account_limit_orders( const st
auto quote_id = assets[1]->id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the best place to check whether the start price is consistent with base and quote parameters. If not, IMHO best to throw out an exception.


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");
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<limit_order_index>().indices().get<by_account>();
Expand All @@ -680,12 +680,13 @@ vector<limit_order_object> database_api_impl::get_account_limit_orders( const st
{
// in case of the order been deleted during page querying
const limit_order_object *p_loo = _db.find(*ostart_id);
upper_itr = index_by_account.upper_bound(std::make_tuple(account->id, price::min(base_id, quote_id)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change slightly reduced performance under certain circumstances :)

Before this change, if an exception is thrown due to FC_ASSERT below, this database query won't be executed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

performance reduction means if run into FC_ASSERT, upper_itr initialization is vain here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.


if ( !p_loo )
{
if ( ostart_price.valid() )
{
lower_itr = index_by_account.lower_bound(std::make_tuple(account->id, *ostart_price, *ostart_id));
upper_itr = index_by_account.upper_bound(std::make_tuple(account->id, ostart_price->min()));
}
else
{
Expand All @@ -703,7 +704,6 @@ vector<limit_order_object> database_api_impl::get_account_limit_orders( const st
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));
upper_itr = index_by_account.upper_bound(std::make_tuple(account->id, loo.sell_price.min()));
}
}
else
Expand Down