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

Change call_order_update_operation to return order_id #1269 #1352

Merged
merged 2 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace graphene { namespace chain {
typedef call_order_update_operation operation_type;

void_result do_evaluate( const call_order_update_operation& o );
void_result do_apply( const call_order_update_operation& o );
object_id_type do_apply( const call_order_update_operation& o );

bool _closing_order = false;
const asset_object* _debt_asset = nullptr;
Expand Down
11 changes: 6 additions & 5 deletions libraries/chain/market_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void_result call_order_update_evaluator::do_evaluate(const call_order_update_ope
} FC_CAPTURE_AND_RETHROW( (o) ) }


void_result call_order_update_evaluator::do_apply(const call_order_update_operation& o)
object_id_type call_order_update_evaluator::do_apply(const call_order_update_operation& o)
{ try {
database& d = db();

Expand Down Expand Up @@ -220,6 +220,7 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
auto& call_idx = d.get_index_type<call_order_index>().indices().get<by_account>();
auto itr = call_idx.find( boost::make_tuple(o.funding_account, o.delta_debt.asset_id) );
const call_order_object* call_obj = nullptr;
call_order_id_type call_order_id;

optional<price> old_collateralization;
optional<share_type> old_debt;
Expand All @@ -237,18 +238,20 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
_bitasset_data->current_feed.maintenance_collateral_ratio);
call.target_collateral_ratio = o.extensions.value.target_collateral_ratio;
});
call_order_id = call_obj->id;
}
else // updating existing debt position
{
call_obj = &*itr;
auto new_collateral = call_obj->collateral + o.delta_collateral.amount;
auto new_debt = call_obj->debt + o.delta_debt.amount;
call_order_id = call_obj->id;

if( new_debt == 0 )
{
FC_ASSERT( new_collateral == 0, "Should claim all collateral when closing debt position" );
d.remove( *call_obj );
return void_result();
return call_order_id;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return the id of a deleted object?

Copy link
Member Author

Choose a reason for hiding this comment

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

why not ? :) IMHO the id of a deleted object may be helpful for looking history of that object, even it is better than return nothing ...

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree, makes sense to return it.

}

FC_ASSERT( new_collateral > 0 && new_debt > 0,
Expand All @@ -269,8 +272,6 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
// then we must check for margin calls and other issues
if( !_bitasset_data->is_prediction_market )
{
call_order_id_type call_order_id = call_obj->id;

// check to see if the order needs to be margin called now, but don't allow black swans and require there to be
// limit orders available that could be used to fill the order.
// Note: due to https://github.com/bitshares/bitshares-core/issues/649, before core-343 hard fork,
Expand Down Expand Up @@ -331,7 +332,7 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat
}
}

return void_result();
return call_order_id;
} FC_CAPTURE_AND_RETHROW( (o) ) }

void_result bid_collateral_evaluator::do_evaluate(const bid_collateral_operation& o)
Expand Down