From 4cee2ca608f3accdf04eceea174fe7937da35e71 Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 16 Jun 2015 11:22:28 -0400 Subject: [PATCH] Update plugins and wallet to remove shorts --- libraries/app/api.cpp | 20 -------- libraries/app/include/graphene/app/api.hpp | 10 +--- .../account_history_plugin.cpp | 2 - libraries/wallet/cache.cpp | 4 +- .../wallet/include/graphene/wallet/wallet.hpp | 10 ++-- libraries/wallet/wallet.cpp | 46 +++++-------------- 6 files changed, 20 insertions(+), 72 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 98d25611..241678b3 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -215,22 +215,6 @@ namespace graphene { namespace app { return result; } - vector database_api::get_short_orders(asset_id_type a, uint32_t limit)const - { - const auto& short_order_idx = _db.get_index_type(); - const auto& sell_price_idx = short_order_idx.indices().get(); - const asset_object& mia = _db.get(a); - - FC_ASSERT( mia.is_market_issued(), "must be a market issued asset" ); - - price index_price = price::min(mia.get_id(), mia.bitasset_data(_db).options.short_backing_asset); - - auto short_itr = sell_price_idx.lower_bound(index_price.max()); - auto short_end = sell_price_idx.upper_bound(index_price.min()); - - return vector(short_itr, short_end); - } - vector database_api::get_call_orders(asset_id_type a, uint32_t limit)const { const auto& call_index = _db.get_index_type().indices().get(); @@ -358,15 +342,11 @@ namespace graphene { namespace app { case operation::tag::value: market = op.op.get().get_market(); break; - case operation::tag::value: - market = op.op.get().get_market(); - break; case operation::tag::value: market = op.op.get().get_market(); break; /* case operation::tag::value: - case operation::tag::value: */ default: break; } diff --git a/libraries/app/include/graphene/app/api.hpp b/libraries/app/include/graphene/app/api.hpp index e34f290c..e4729c3d 100644 --- a/libraries/app/include/graphene/app/api.hpp +++ b/libraries/app/include/graphene/app/api.hpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -142,13 +142,6 @@ namespace graphene { namespace app { * @return The limit orders, ordered from least price to greatest */ vector get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const; - /** - * @brief Get short orders in a given asset - * @param a ID of asset being sold - * @param limit Maximum number of orders to retrieve - * @return The short orders, ordered from least price to greatest - */ - vector get_short_orders(asset_id_type a, uint32_t limit)const; /** * @brief Get call orders in a given asset * @param a ID of asset being called @@ -342,7 +335,6 @@ FC_API(graphene::app::database_api, (get_named_account_balances) (lookup_asset_symbols) (get_limit_orders) - (get_short_orders) (get_call_orders) (get_settle_orders) (list_assets) diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index d8e1148e..0fd4fac5 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -141,9 +141,7 @@ struct operation_get_impacted_accounts } void operator()( const limit_order_create_operation& o )const { } - void operator()( const short_order_create_operation& o )const { } void operator()( const limit_order_cancel_operation& o )const { } - void operator()( const short_order_cancel_operation& o )const { } void operator()( const call_order_update_operation& o )const { } void operator()( const key_create_operation& o )const { } void operator()( const custom_operation& o )const { } diff --git a/libraries/wallet/cache.cpp b/libraries/wallet/cache.cpp index d5c3f382..18b1d7b0 100644 --- a/libraries/wallet/cache.cpp +++ b/libraries/wallet/cache.cpp @@ -22,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -72,8 +72,6 @@ object* create_object( const variant& v ) return create_object_of_type< witness_object >( v ); case limit_order_object_type: return create_object_of_type< limit_order_object >( v ); - case short_order_object_type: - return create_object_of_type< short_order_object >( v ); case call_order_object_type: return create_object_of_type< call_order_object >( v ); /* diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index fc1f0a9f..3359e2b5 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -114,7 +114,6 @@ class wallet_api vector list_assets(const string& lowerbound, uint32_t limit)const; vector get_account_history(string name, int limit)const; vector get_limit_orders(string a, string b, uint32_t limit)const; - vector get_short_orders(string a, uint32_t limit)const; vector get_call_orders(string a, uint32_t limit)const; vector get_settle_orders(string a, uint32_t limit)const; global_property_object get_global_properties() const; @@ -204,7 +203,11 @@ class wallet_api bool fill_or_kill = false, bool broadcast = false); - signed_transaction short_sell_asset(string seller_name, string amount_to_sell, string asset_symbol, + /** + * This method will create a transaction with two operations, the first one will borrow amount_to_sell + * given amount of collateral + */ + signed_transaction borrow_asset(string seller_name, string amount_to_sell, string asset_symbol, string amount_of_collateral, bool broadcast = false); signed_transaction create_asset(string issuer, @@ -272,7 +275,7 @@ FC_API( graphene::wallet::wallet_api, (upgrade_account) (create_account_with_brain_key) (sell_asset) - (short_sell_asset) + (borrow_asset) (transfer) (create_asset) (issue_asset) @@ -289,7 +292,6 @@ FC_API( graphene::wallet::wallet_api, (load_wallet_file) (normalize_brain_key) (get_limit_orders) - (get_short_orders) (get_call_orders) (get_settle_orders) (save_wallet_file) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 2d0d6dec..9f2d255a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1011,7 +1011,7 @@ public: return sign_transaction( tx, broadcast ); } - signed_transaction short_sell_asset(string seller_name, string amount_to_sell, string asset_symbol, + signed_transaction borrow_asset(string seller_name, string amount_to_sell, string asset_symbol, string amount_of_collateral, bool broadcast = false) { account_object seller = get_account(seller_name); @@ -1019,11 +1019,10 @@ public: FC_ASSERT(mia.is_market_issued()); asset_object collateral = get_asset(get_object(*mia.bitasset_data_id).options.short_backing_asset); - short_order_create_operation op; - op.seller = seller.id; - op.expiration = fc::time_point::now() + fc::days(365*10); - op.amount_to_sell = mia.amount_from_string(amount_to_sell); - op.collateral = collateral.amount_from_string(amount_of_collateral); + call_order_update_operation op; + op.funding_account = seller.id; + op.amount_to_cover = -mia.amount_from_string(amount_to_sell); + op.collateral_to_add = collateral.amount_from_string(amount_of_collateral); signed_transaction trx; trx.operations = {op}; @@ -1040,27 +1039,11 @@ public: FC_ASSERT(order_id.space() == protocol_ids, "Invalid order ID ${id}", ("id", order_id)); signed_transaction trx; - switch( order_id.type() ) - { - case short_order_object_type: { - short_order_cancel_operation op; - op.fee_paying_account = get_object(order_id).seller; - op.order = order_id; - op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees); - trx.operations = {op}; - break; - } - case limit_order_object_type: { - limit_order_cancel_operation op; - op.fee_paying_account = get_object(order_id).seller; - op.order = order_id; - op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees); - trx.operations = {op}; - break; - } - default: - FC_THROW("Invalid order ID ${id}", ("id", order_id)); - } + limit_order_cancel_operation op; + op.fee_paying_account = get_object(order_id).seller; + op.order = order_id; + op.fee = op.calculate_fee(_remote_db->get_global_properties().parameters.current_fees); + trx.operations = {op}; trx.validate(); return sign_transaction(trx, broadcast); @@ -1384,11 +1367,6 @@ vector wallet_api::get_limit_orders(string a, string b, uint return my->_remote_db->get_limit_orders(get_asset(a).id, get_asset(b).id, limit); } -vector wallet_api::get_short_orders(string a, uint32_t limit)const -{ - return my->_remote_db->get_short_orders(get_asset(a).id, limit); -} - vector wallet_api::get_call_orders(string a, uint32_t limit)const { return my->_remote_db->get_call_orders(get_asset(a).id, limit); @@ -1740,11 +1718,11 @@ signed_transaction wallet_api::sell_asset(string seller_account, symbol_to_receive, expiration, fill_or_kill, broadcast); } -signed_transaction wallet_api::short_sell_asset(string seller_name, string amount_to_sell, +signed_transaction wallet_api::borrow_asset(string seller_name, string amount_to_sell, string asset_symbol, string amount_of_collateral, bool broadcast) { FC_ASSERT(!is_locked()); - return my->short_sell_asset(seller_name, amount_to_sell, asset_symbol, amount_of_collateral, broadcast); + return my->borrow_asset(seller_name, amount_to_sell, asset_symbol, amount_of_collateral, broadcast); } } }