From 663036f2aa98ef650f31cf0afaaf115e235f5a4e Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 16 Jun 2015 10:14:10 -0400 Subject: [PATCH] it builds --- libraries/chain/CMakeLists.txt | 2 +- libraries/chain/asset.cpp | 11 +- libraries/chain/asset_evaluator.cpp | 2 +- libraries/chain/call_order_evaluator.cpp | 22 +-- libraries/chain/db_debug.cpp | 9 +- libraries/chain/db_init.cpp | 7 +- libraries/chain/db_market.cpp | 148 +----------------- libraries/chain/db_update.cpp | 12 +- libraries/chain/evaluator.cpp | 2 +- .../graphene/chain/call_order_evaluator.hpp | 2 +- .../graphene/chain/call_order_object.hpp | 4 +- .../chain/include/graphene/chain/database.hpp | 2 - libraries/chain/limit_order_evaluator.cpp | 42 +---- 13 files changed, 35 insertions(+), 230 deletions(-) diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index 17635897..100fd8a3 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -16,7 +16,7 @@ add_library( graphene_chain asset_evaluator.cpp transfer_evaluator.cpp proposal_evaluator.cpp - short_order_evaluator.cpp + call_order_evaluator.cpp limit_order_evaluator.cpp vesting_balance_evaluator.cpp withdraw_permission_evaluator.cpp diff --git a/libraries/chain/asset.cpp b/libraries/chain/asset.cpp index cb1f6fdb..bb36910d 100644 --- a/libraries/chain/asset.cpp +++ b/libraries/chain/asset.cpp @@ -122,18 +122,11 @@ namespace graphene { namespace chain { { try { if( !call_limit.is_null() ) call_limit.validate(); - if( !short_limit.is_null() ) - short_limit.validate(); if( !settlement_price.is_null() ) settlement_price.validate(); - FC_ASSERT( call_limit.is_null() == short_limit.is_null() ); - FC_ASSERT( call_limit.base.asset_id == short_limit.quote.asset_id ); - FC_ASSERT( call_limit.quote.asset_id == short_limit.base.asset_id ); FC_ASSERT( max_margin_period_sec > 0 ); - FC_ASSERT( required_maintenance_collateral < required_initial_collateral ); FC_ASSERT( required_maintenance_collateral >= 1000 ); - FC_ASSERT( call_limit.is_null() || call_limit < ~short_limit ); - } FC_CAPTURE_AND_RETHROW( (call_limit.is_null())(short_limit.is_null())(call_limit)(short_limit) - (max_margin_period_sec)(required_maintenance_collateral)(required_initial_collateral) ) } + } FC_CAPTURE_AND_RETHROW( (call_limit.is_null())(call_limit) + (max_margin_period_sec)(required_maintenance_collateral) ) } } } // graphene::chain diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 096d05db..1bda2aed 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/libraries/chain/call_order_evaluator.cpp b/libraries/chain/call_order_evaluator.cpp index 743fe634..45005365 100644 --- a/libraries/chain/call_order_evaluator.cpp +++ b/libraries/chain/call_order_evaluator.cpp @@ -16,9 +16,9 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include -#include +#include #include -#include +#include #include #include @@ -47,17 +47,17 @@ asset call_order_update_evaluator::do_evaluate(const call_order_update_operation o.maintenance_collateral_ratio > _bitasset_data->current_feed.required_maintenance_collateral ); } - if( o.amount_to_cover > 0 ) + if( o.amount_to_cover.amount > 0 ) { FC_ASSERT( d.get_balance(*_paying_account, *_debt_asset) >= o.amount_to_cover, "Cannot cover by ${c} when payer only has ${b}", ("c", o.amount_to_cover.amount)("b", d.get_balance(*_paying_account, *_debt_asset).amount) ); } - if( o.collateral_to_add > 0 ) + if( o.collateral_to_add.amount > 0 ) { - FC_ASSERT( d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)) >= o.collateral_to_add, + FC_ASSERT( d.get_balance(*_paying_account, _bitasset_data->options.short_backing_asset(d)) >= o.collateral_to_add, "Cannot increase collateral by ${c} when payer only has ${b}", ("c", o.amount_to_cover.amount) - ("b", d.get_balance(*_paying_account, bitasset_data.options.short_backing_asset(d)).amount) ); + ("b", d.get_balance(*_paying_account, _bitasset_data->options.short_backing_asset(d)).amount) ); } return asset(); @@ -73,7 +73,7 @@ asset call_order_update_evaluator::do_apply(const call_order_update_operation& o d.adjust_balance( o.funding_account, -o.collateral_to_add); // Deduct the debt paid from the total supply of the debt asset. - if( o.amount_to_cover != 0 ) + if( o.amount_to_cover.amount != 0 ) { d.modify(_debt_asset->dynamic_asset_data_id(d), [&](asset_dynamic_data_object& dynamic_asset) { dynamic_asset.current_supply -= o.amount_to_cover.amount; @@ -88,7 +88,7 @@ asset call_order_update_evaluator::do_apply(const call_order_update_operation& o FC_ASSERT( o.collateral_to_add.amount > 0 ); FC_ASSERT( o.amount_to_cover.amount < 0 ); d.create( [&](call_order_object& call ){ - call.owner = o.funding_account; + call.borrower = o.funding_account; call.collateral = o.collateral_to_add.amount; call.debt = -o.amount_to_cover.amount; call.maintenance_collateral_ratio = o.maintenance_collateral_ratio; @@ -99,11 +99,11 @@ asset call_order_update_evaluator::do_apply(const call_order_update_operation& o } else { - if( itr->debt - o.amount_to_cover == 0 ) + if( itr->debt - o.amount_to_cover.amount == 0 ) { - FC_ASSERT( o.collateral_to_add == 0 ); + FC_ASSERT( o.collateral_to_add.amount == 0 ); collateral_returned = itr->get_collateral(); - d.adjust_balance( o.funding_account, call. + d.adjust_balance( o.funding_account, collateral_returned ); d.remove( *itr ); } else diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index d7d8f4e0..34f12b58 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -60,13 +60,6 @@ void database::debug_dump() if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount; total_balances[for_sale.asset_id] += for_sale.amount; } - for( const short_order_object& o : db.get_index_type().indices() ) - { - idump(("short_order")(o)); - auto col = o.get_collateral(); - if( col.asset_id == asset_id_type() ) core_in_orders += col.amount; - total_balances[col.asset_id] += col.amount; - } for( const call_order_object& o : db.get_index_type().indices() ) { idump(("call_order")(o)); diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 57c3cd37..f4ae2196 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -42,7 +42,7 @@ #include #include #include -#include +#include #include #include #include @@ -75,8 +75,6 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); - register_evaluator(); - register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); @@ -108,7 +106,6 @@ void database::initialize_indexes() add_index< primary_index> >(); add_index< primary_index> >(); add_index< primary_index >(); - add_index< primary_index >(); add_index< primary_index >(); add_index< primary_index >(); add_index< primary_index >(); diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 22fb778d..0ffb9d31 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include @@ -225,10 +225,6 @@ int database::match( const limit_order_object& bid, const limit_order_object& as return match( bid, ask, match_price ); } -int database::match( const limit_order_object& bid, const short_order_object& ask, const price& match_price ) -{ - return match( bid, ask, match_price ); -} asset database::match( const call_order_object& call, const force_settlement_object& settle, const price& match_price, asset max_settlement ) @@ -290,107 +286,6 @@ bool database::fill_order( const limit_order_object& order, const asset& pays, c } } -bool database::fill_order( const short_order_object& order, const asset& pays, const asset& receives ) -{ try { - assert( order.amount_for_sale().asset_id == pays.asset_id ); - assert( pays.asset_id != receives.asset_id ); - - const call_order_index& call_index = get_index_type(); - - const account_object& seller = order.seller(*this); - const asset_object& recv_asset = receives.asset_id(*this); - const asset_object& pays_asset = pays.asset_id(*this); - assert( pays_asset.is_market_issued() ); - - auto issuer_fees = pay_market_fees( recv_asset, receives ); - - bool filled = pays == order.amount_for_sale(); - asset seller_to_collateral; - if( (*pays_asset.bitasset_data_id)(*this).is_prediction_market ) - { - assert( pays.amount >= receives.amount ); - seller_to_collateral = pays.amount - receives.amount; - } - else - { - seller_to_collateral = filled ? order.get_collateral() : pays * order.sell_price; - } - auto buyer_to_collateral = receives - issuer_fees; - - if( receives.asset_id == asset_id_type() ) - { - const auto& statistics = seller.statistics(*this); - modify( statistics, [&]( account_statistics_object& b ){ - b.total_core_in_orders += buyer_to_collateral.amount; - }); - } - - modify( pays_asset.dynamic_asset_data_id(*this), [&]( asset_dynamic_data_object& obj ){ - obj.current_supply += pays.amount; - }); - - const auto& call_account_index = call_index.indices().get(); - auto call_itr = call_account_index.find( boost::make_tuple(order.seller, pays.asset_id) ); - if( call_itr == call_account_index.end() ) - { - create( [&]( call_order_object& c ){ - c.borrower = seller.id; - c.collateral = seller_to_collateral.amount + buyer_to_collateral.amount; - c.debt = pays.amount; - c.maintenance_collateral_ratio = order.maintenance_collateral_ratio; - c.call_price = price::max(seller_to_collateral.asset_id, pays.asset_id); - c.update_call_price(); - }); - } - else - { - modify( *call_itr, [&]( call_order_object& c ){ - c.debt += pays.amount; - c.collateral += seller_to_collateral.amount + buyer_to_collateral.amount; - c.maintenance_collateral_ratio = order.maintenance_collateral_ratio; - c.update_call_price(); - }); - } - - if( filled ) - { - remove( order ); - } - else - { - modify( order, [&]( short_order_object& b ) { - b.for_sale -= pays.amount; - b.available_collateral -= seller_to_collateral.amount; - assert( b.available_collateral > 0 ); - assert( b.for_sale > 0 ); - }); - - /** - * There are times when the AMOUNT_FOR_SALE * SALE_PRICE == 0 which means that we - * have hit the limit where the seller is asking for nothing in return. When this - * happens we must refund any balance back to the seller, it is too small to be - * sold at the sale price. - */ - if( order.amount_to_receive().amount == 0 ) - { - adjust_balance(seller.get_id(), order.get_collateral()); - if( order.get_collateral().asset_id == asset_id_type() ) - { - const auto& statistics = seller.statistics(*this); - modify( statistics, [&]( account_statistics_object& b ){ - b.total_core_in_orders -= order.available_collateral; - }); - } - - remove( order ); - filled = true; - } - } - - push_applied_operation( fill_order_operation{ order.id, order.seller, pays, receives, issuer_fees } ); - - return filled; -} FC_CAPTURE_AND_RETHROW( (order)(pays)(receives) ) } bool database::fill_order( const call_order_object& order, const asset& pays, const asset& receives ) { try { @@ -483,11 +378,6 @@ bool database::check_call_orders( const asset_object& mia ) const limit_order_index& limit_index = get_index_type(); const auto& limit_price_index = limit_index.indices().get(); - const short_order_index& short_index = get_index_type(); - const auto& short_price_index = short_index.indices().get(); - - auto short_itr = short_price_index.lower_bound( price::max( mia.id, bitasset.options.short_backing_asset ) ); - auto short_end = short_price_index.upper_bound( ~bitasset.current_feed.call_limit ); auto limit_itr = limit_price_index.lower_bound( price::max( mia.id, bitasset.options.short_backing_asset ) ); auto limit_end = limit_price_index.upper_bound( ~bitasset.current_feed.call_limit ); @@ -499,33 +389,14 @@ bool database::check_call_orders( const asset_object& mia ) while( call_itr != call_end ) { - bool current_is_limit = true; bool filled_call = false; price match_price; asset usd_for_sale; if( limit_itr != limit_end ) { assert( limit_itr != limit_price_index.end() ); - if( short_itr != short_end && limit_itr->sell_price < short_itr->sell_price ) - { - assert( short_itr != short_price_index.end() ); - current_is_limit = false; - match_price = short_itr->sell_price; - usd_for_sale = short_itr->amount_for_sale(); - } - else - { - current_is_limit = true; - match_price = limit_itr->sell_price; - usd_for_sale = limit_itr->amount_for_sale(); - } - } - else if( short_itr != short_end ) - { - assert( short_itr != short_price_index.end() ); - current_is_limit = false; - match_price = short_itr->sell_price; - usd_for_sale = short_itr->amount_for_sale(); + match_price = limit_itr->sell_price; + usd_for_sale = limit_itr->amount_for_sale(); } else return filled_short_or_limit; @@ -569,16 +440,9 @@ bool database::check_call_orders( const asset_object& mia ) auto old_call_itr = call_itr; if( filled_call ) ++call_itr; fill_order( *old_call_itr, call_pays, call_receives ); - if( current_is_limit ) - { - auto old_limit_itr = !filled_call ? limit_itr++ : limit_itr; - fill_order( *old_limit_itr, order_pays, order_receives ); - } - else - { - auto old_short_itr = !filled_call ? short_itr++ : short_itr; - fill_order( *old_short_itr, order_pays, order_receives ); - } + + auto old_limit_itr = !filled_call ? limit_itr++ : limit_itr; + fill_order( *old_limit_itr, order_pays, order_receives ); } // whlie call_itr != call_end return filled_short_or_limit; diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index 1ba5b95e..cd4dc03c 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -131,16 +131,6 @@ void database::clear_expired_orders() apply_operation(cancel_context, canceler); } - //Cancel expired short orders - auto& short_index = get_index_type().indices().get(); - while( !short_index.empty() && short_index.begin()->expiration <= head_block_time() ) - { - const short_order_object& order = *short_index.begin(); - short_order_cancel_operation canceler; - canceler.fee_paying_account = order.seller; - canceler.order = order.id; - apply_operation(cancel_context, canceler); - } //Process expired force settlement orders auto& settlement_index = get_index_type().indices().get(); diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index 46117211..61803be7 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include diff --git a/libraries/chain/include/graphene/chain/call_order_evaluator.hpp b/libraries/chain/include/graphene/chain/call_order_evaluator.hpp index 485424fb..d7d6cc0c 100644 --- a/libraries/chain/include/graphene/chain/call_order_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/call_order_evaluator.hpp @@ -34,7 +34,7 @@ namespace graphene { namespace chain { const asset_object* _debt_asset = nullptr; const account_object* _paying_account = nullptr; const call_order_object* _order = nullptr; - const bitasset_data_object* _bitasset_data = nullptr; + const asset_bitasset_data_object* _bitasset_data = nullptr; }; } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/call_order_object.hpp b/libraries/chain/include/graphene/chain/call_order_object.hpp index 5c1f8b67..becbc781 100644 --- a/libraries/chain/include/graphene/chain/call_order_object.hpp +++ b/libraries/chain/include/graphene/chain/call_order_object.hpp @@ -74,6 +74,9 @@ namespace graphene { namespace chain { { return balance.asset_id; } }; + struct by_collateral; + struct by_account; + struct by_price; typedef multi_index_container< call_order_object, indexed_by< @@ -101,7 +104,6 @@ namespace graphene { namespace chain { > > call_order_multi_index_type; - struct by_account; struct by_expiration; typedef multi_index_container< force_settlement_object, diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 469a78ad..ba6a3a14 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -281,7 +281,6 @@ namespace graphene { namespace chain { template int match( const limit_order_object& bid, const OrderType& ask, const price& match_price ); int match( const limit_order_object& bid, const limit_order_object& ask, const price& trade_price ); - int match( const limit_order_object& bid, const short_order_object& ask, const price& trade_price ); /// @return the amount of asset settled asset match(const call_order_object& call, const force_settlement_object& settle, @@ -293,7 +292,6 @@ namespace graphene { namespace chain { * @return true if the order was completely filled and thus freed. */ bool fill_order( const limit_order_object& order, const asset& pays, const asset& receives ); - bool fill_order( const short_order_object& order, const asset& pays, const asset& receives ); bool fill_order( const call_order_object& order, const asset& pays, const asset& receives ); bool fill_order( const force_settlement_object& settle, const asset& pays, const asset& receives ); diff --git a/libraries/chain/limit_order_evaluator.cpp b/libraries/chain/limit_order_evaluator.cpp index d3429567..0e8a0d2e 100644 --- a/libraries/chain/limit_order_evaluator.cpp +++ b/libraries/chain/limit_order_evaluator.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include namespace graphene { namespace chain { @@ -104,44 +103,13 @@ object_id_type limit_order_create_evaluator::do_apply( const limit_order_create_ if( converted_some && !db().find(result) ) // then we were filled by call order return result; } - const auto& short_order_idx = db().get_index_type(); - const auto& sell_price_idx = short_order_idx.indices().get(); - - FC_ASSERT( max_price.max() >= max_price ); - auto short_itr = sell_price_idx.lower_bound( max_price.max() ); - auto short_end = sell_price_idx.upper_bound( max_price ); - - while( !filled ) - { - if( limit_itr != limit_end ) - { - if( short_itr != short_end && limit_itr->sell_price < short_itr->sell_price ) - { - auto old_short_itr = short_itr; - ++short_itr; - filled = (db().match( new_order_object, *old_short_itr, old_short_itr->sell_price ) != 2 ); - } - else - { - auto old_limit_itr = limit_itr; - ++limit_itr; - filled = (db().match( new_order_object, *old_limit_itr, old_limit_itr->sell_price ) != 2 ); - } - } - else if( short_itr != short_end ) - { - auto old_short_itr = short_itr; - ++short_itr; - filled = (db().match( new_order_object, *old_short_itr, old_short_itr->sell_price ) != 2 ); - } - else break; - } } - else while( !filled && limit_itr != limit_end ) + + while( !filled && limit_itr != limit_end ) { - auto old_itr = limit_itr; - ++limit_itr; - filled = (db().match( new_order_object, *old_itr, old_itr->sell_price ) != 2); + auto old_limit_itr = limit_itr; + ++limit_itr; + filled = (db().match( new_order_object, *old_limit_itr, old_limit_itr->sell_price ) != 2 ); } //Possible optimization: only check calls if the new order completely filled some old order