From 270355333966658fec655e473d5ecfb5a8bafba8 Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Sun, 30 Sep 2018 21:18:23 +0300 Subject: [PATCH 1/2] Change call_order_update_operation to return order_id #1269 --- .../include/graphene/chain/market_evaluator.hpp | 2 +- libraries/chain/market_evaluator.cpp | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/chain/include/graphene/chain/market_evaluator.hpp b/libraries/chain/include/graphene/chain/market_evaluator.hpp index a5ba098189..96a4ac07ed 100644 --- a/libraries/chain/include/graphene/chain/market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/market_evaluator.hpp @@ -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; diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index ed7c55351b..3c272439ad 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -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(); @@ -220,6 +220,7 @@ void_result call_order_update_evaluator::do_apply(const call_order_update_operat auto& call_idx = d.get_index_type().indices().get(); 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 old_collateralization; optional old_debt; @@ -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; } FC_ASSERT( new_collateral > 0 && new_debt > 0, @@ -264,13 +267,12 @@ 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; } // 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, @@ -331,7 +333,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) From 73e9b9da509d146f2d469ad11fcab0e1346a6f6e Mon Sep 17 00:00:00 2001 From: Valera Cogut Date: Mon, 1 Oct 2018 15:45:01 +0300 Subject: [PATCH 2/2] removed superfluous line of code --- libraries/chain/market_evaluator.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index 3c272439ad..62dfc7c7b4 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -267,7 +267,6 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope _bitasset_data->current_feed.maintenance_collateral_ratio ); call.target_collateral_ratio = o.extensions.value.target_collateral_ratio; }); - call_order_id = call_obj->id; } // then we must check for margin calls and other issues