Skip to content

Commit

Permalink
Resolved conflict between PR and develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jmjatlanta committed Mar 15, 2018
2 parents aaee5ad + f287324 commit adde3fa
Show file tree
Hide file tree
Showing 34 changed files with 1,641 additions and 570 deletions.
6 changes: 0 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ if( WIN32 )

else( WIN32 ) # Apple AND Linux

find_library(READLINE_LIBRARIES NAMES readline)
find_path(READLINE_INCLUDE_DIR readline/readline.h)
#if(NOT READLINE_INCLUDE_DIR OR NOT READLINE_LIBRARIES)
# MESSAGE(FATAL_ERROR "Could not find lib readline.")
#endif()

if( APPLE )
# Apple Specific Options Here
message( STATUS "Configuring BitShares on OS X" )
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_library( graphene_app
)

# need to link graphene_debug_witness because plugins aren't sufficiently isolated #246
target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness )
target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_grouped_orders graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness )
target_include_directories( graphene_app
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" )
Expand Down
81 changes: 64 additions & 17 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ namespace graphene { namespace app {
{
_asset_api = std::make_shared< asset_api >( std::ref( *_app.chain_database() ) );
}
else if( api_name == "orders_api" )
{
_orders_api = std::make_shared< orders_api >( std::ref( _app ) );
}
else if( api_name == "debug_api" )
{
// can only enable this API if the plugin was loaded
Expand Down Expand Up @@ -262,6 +266,12 @@ namespace graphene { namespace app {
return *_asset_api;
}

fc::api<orders_api> login_api::orders() const
{
FC_ASSERT(_orders_api);
return *_orders_api;
}

fc::api<graphene::debug_witness::debug_api> login_api::debug() const
{
FC_ASSERT(_debug_api);
Expand Down Expand Up @@ -302,26 +312,27 @@ namespace graphene { namespace app {
const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 );
vector<operation_history_object> result;
const auto& stats = account(db).statistics(db);
if( stats.most_recent_op == account_transaction_history_id_type() ) return result;
const account_transaction_history_object* node = &stats.most_recent_op(db);
if( start == operation_history_id_type() )
start = node->operation_id;

while(node && node->operation_id.instance.value > stop.instance.value && result.size() < limit)
try {
const account_transaction_history_object& node = account(db).statistics(db).most_recent_op(db);
if(start == operation_history_id_type() || start.instance.value > node.operation_id.instance.value)
start = node.operation_id;
} catch(...) { return result; }

const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
const auto& by_op_idx = hist_idx.indices().get<by_op>();
auto index_start = by_op_idx.begin();
auto itr = by_op_idx.lower_bound(boost::make_tuple(account, start));

while(itr != index_start && itr->account == account && itr->operation_id.instance.value > stop.instance.value && result.size() < limit)
{
if( node->operation_id.instance.value <= start.instance.value )
result.push_back( node->operation_id(db) );
if( node->next == account_transaction_history_id_type() )
node = nullptr;
else node = &node->next(db);
if(itr->operation_id.instance.value <= start.instance.value)
result.push_back(itr->operation_id(db));
--itr;
}
if( stop.instance.value == 0 && result.size() < limit )
{
node = db.find(account_transaction_history_id_type());
if( node && node->account == account)
result.push_back( node->operation_id(db) );
if(stop.instance.value == 0 && result.size() < limit && itr->account == account) {
result.push_back(itr->operation_id(db));
}

return result;
}

Expand Down Expand Up @@ -587,4 +598,40 @@ namespace graphene { namespace app {
return result;
}

// orders_api
flat_set<uint16_t> orders_api::get_tracked_groups()const
{
auto plugin = _app.get_plugin<grouped_orders_plugin>( "grouped_orders" );
FC_ASSERT( plugin );
return plugin->tracked_groups();
}

vector< limit_order_group > orders_api::get_grouped_limit_orders( asset_id_type base_asset_id,
asset_id_type quote_asset_id,
uint16_t group,
optional<price> start,
uint32_t limit )const
{
FC_ASSERT( limit <= 101 );
auto plugin = _app.get_plugin<grouped_orders_plugin>( "grouped_orders" );
FC_ASSERT( plugin );
const auto& limit_groups = plugin->limit_order_groups();
vector< limit_order_group > result;

price max_price = price::max( base_asset_id, quote_asset_id );
price min_price = price::min( base_asset_id, quote_asset_id );
if( start.valid() && !start->is_null() )
max_price = std::max( std::min( max_price, *start ), min_price );

auto itr = limit_groups.lower_bound( limit_order_group_key( group, max_price ) );
// use an end itrator to try to avoid expensive price comparison
auto end = limit_groups.upper_bound( limit_order_group_key( group, min_price ) );
while( itr != end && result.size() < limit )
{
result.emplace_back( *itr );
++itr;
}
return result;
}

} } // graphene::app
4 changes: 3 additions & 1 deletion libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ namespace detail {
wild_access.allowed_apis.push_back( "network_broadcast_api" );
wild_access.allowed_apis.push_back( "history_api" );
wild_access.allowed_apis.push_back( "crypto_api" );
wild_access.allowed_apis.push_back( "orders_api" );
_apiaccess.permission_map["*"] = wild_access;
}

Expand Down Expand Up @@ -537,7 +538,7 @@ namespace detail {
_is_finished_syncing = true;
_self->syncing_finished();
}
} FC_CAPTURE_AND_RETHROW( (blk_msg)(sync_mode) ) }
} FC_CAPTURE_AND_RETHROW( (blk_msg)(sync_mode) ) return false; }

virtual void handle_transaction(const graphene::net::trx_message& transaction_message) override
{ try {
Expand Down Expand Up @@ -988,6 +989,7 @@ void application::initialize(const fc::path& data_dir, const boost::program_opti
wanted.push_back("witness");
wanted.push_back("account_history");
wanted.push_back("market_history");
wanted.push_back("grouped_orders");
}
int es_ah_conflict_counter = 0;
for (auto& it : wanted)
Expand Down
5 changes: 0 additions & 5 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
return;

if( !is_subscribed_to_item(i) )
{
idump((i));
_subscribe_filter.insert( vec.data(), vec.size() );//(vecconst char*)&i, sizeof(i) );
}
}

template<typename T>
Expand Down Expand Up @@ -318,7 +315,6 @@ void database_api::set_subscribe_callback( std::function<void(const variant&)> c

void database_api_impl::set_subscribe_callback( std::function<void(const variant&)> cb, bool notify_remove_create )
{
//edump((clear_filter));
_subscribe_callback = cb;
_notify_remove_create = notify_remove_create;
_subscribed_accounts.clear();
Expand Down Expand Up @@ -613,7 +609,6 @@ std::map<string,full_account> database_api::get_full_accounts( const vector<stri

std::map<std::string, full_account> database_api_impl::get_full_accounts( const vector<std::string>& names_or_ids, bool subscribe)
{
idump((names_or_ids));
std::map<std::string, full_account> results;

for (const std::string& account_name_or_id : names_or_ids)
Expand Down
65 changes: 65 additions & 0 deletions libraries/app/include/graphene/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#include <graphene/market_history/market_history_plugin.hpp>

#include <graphene/grouped_orders/grouped_orders_plugin.hpp>

#include <graphene/debug_witness/debug_api.hpp>

#include <graphene/net/node.hpp>
Expand All @@ -49,6 +51,7 @@
namespace graphene { namespace app {
using namespace graphene::chain;
using namespace graphene::market_history;
using namespace graphene::grouped_orders;
using namespace fc::ecc;
using namespace std;

Expand Down Expand Up @@ -87,6 +90,23 @@ namespace graphene { namespace app {
uint32_t total_count = 0;
vector<operation_history_object> operation_history_objs;
};

/**
* @brief summary data of a group of limit orders
*/
struct limit_order_group
{
limit_order_group( const std::pair<limit_order_group_key,limit_order_group_data>& p )
: min_price( p.first.min_price ),
max_price( p.second.max_price ),
total_for_sale( p.second.total_for_sale )
{}
limit_order_group() {}

price min_price; ///< possible lowest price in the group
price max_price; ///< possible highest price in the group
share_type total_for_sale; ///< total amount of asset for sale, asset id is min_price.base.asset_id
};

/**
* @brief The history_api class implements the RPC API for account history
Expand Down Expand Up @@ -337,6 +357,41 @@ namespace graphene { namespace app {
graphene::chain::database& _db;
};

/**
* @brief the orders_api class exposes access to data processed with grouped orders plugin.
*/
class orders_api
{
public:
orders_api(application& app):_app(app){}
//virtual ~orders_api() {}

/**
* @breif Get tracked groups configured by the server.
* @return A list of numbers which indicate configured groups, of those, 1 means 0.01% diff on price.
*/
flat_set<uint16_t> get_tracked_groups()const;

/**
* @breif Get grouped limit orders in given market.
*
* @param base_asset_id ID of asset being sold
* @param quote_asset_id ID of asset being purchased
* @param group Maximum price diff within each order group, have to be one of configured values
* @param start Optional price to indicate the first order group to retrieve
* @param limit Maximum number of order groups to retrieve (must not exceed 101)
* @return The grouped limit orders, ordered from best offered price to worst
*/
vector< limit_order_group > get_grouped_limit_orders( asset_id_type base_asset_id,
asset_id_type quote_asset_id,
uint16_t group,
optional<price> start,
uint32_t limit )const;

private:
application& _app;
};

/**
* @brief The login_api class implements the bottom layer of the RPC API
*
Expand Down Expand Up @@ -372,6 +427,8 @@ namespace graphene { namespace app {
fc::api<crypto_api> crypto()const;
/// @brief Retrieve the asset API
fc::api<asset_api> asset()const;
/// @brief Retrieve the orders API
fc::api<orders_api> orders()const;
/// @brief Retrieve the debug API (if available)
fc::api<graphene::debug_witness::debug_api> debug()const;

Expand All @@ -387,6 +444,7 @@ namespace graphene { namespace app {
optional< fc::api<history_api> > _history_api;
optional< fc::api<crypto_api> > _crypto_api;
optional< fc::api<asset_api> > _asset_api;
optional< fc::api<orders_api> > _orders_api;
optional< fc::api<graphene::debug_witness::debug_api> > _debug_api;
};

Expand All @@ -400,6 +458,8 @@ FC_REFLECT( graphene::app::verify_range_proof_rewind_result,
(success)(min_val)(max_val)(value_out)(blind_out)(message_out) )
FC_REFLECT( graphene::app::history_operation_detail,
(total_count)(operation_history_objs) )
FC_REFLECT( graphene::app::limit_order_group,
(min_price)(max_price)(total_for_sale) )
//FC_REFLECT_TYPENAME( fc::ecc::compact_signature );
//FC_REFLECT_TYPENAME( fc::ecc::commitment_type );

Expand Down Expand Up @@ -448,6 +508,10 @@ FC_API(graphene::app::asset_api,
(get_asset_holders_count)
(get_all_asset_holders)
)
FC_API(graphene::app::orders_api,
(get_tracked_groups)
(get_grouped_limit_orders)
)
FC_API(graphene::app::login_api,
(login)
(block)
Expand All @@ -457,5 +521,6 @@ FC_API(graphene::app::login_api,
(network_node)
(crypto)
(asset)
(orders)
(debug)
)
7 changes: 6 additions & 1 deletion libraries/chain/db_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ void database::reindex( fc::path data_dir )
void database::wipe(const fc::path& data_dir, bool include_blocks)
{
ilog("Wiping database", ("include_blocks", include_blocks));
close();
if (_opened) {
close();
}
object_database::wipe(data_dir);
if( include_blocks )
fc::remove_all( data_dir / "database" );
Expand Down Expand Up @@ -171,6 +173,7 @@ void database::open(
("last_block->id", last_block)("head_block_id",head_block_num()) );
reindex( data_dir );
}
_opened = true;
}
FC_CAPTURE_LOG_AND_RETHROW( (data_dir) )
}
Expand Down Expand Up @@ -214,6 +217,8 @@ void database::close(bool rewind)
_block_id_to_block.close();

_fork_db.reset();

_opened = false;
}

} }
8 changes: 7 additions & 1 deletion libraries/chain/db_market.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,15 @@ bool database::check_call_orders(const asset_object& mia, bool enable_black_swan
fill_order(*old_call_itr, call_pays, call_receives, match_price, for_new_limit_order );

auto old_limit_itr = limit_itr;
auto next_limit_itr = std::next( limit_itr );
if( filled_limit ) ++limit_itr;
// when for_new_limit_order is true, the limit order is taker, otherwise the limit order is maker
fill_order(*old_limit_itr, order_pays, order_receives, true, match_price, !for_new_limit_order );
bool really_filled = fill_order(*old_limit_itr, order_pays, order_receives, true, match_price, !for_new_limit_order );
if( !filled_limit && really_filled )
{
wlog( "Cull_small issue occurred at block #${block}", ("block",head_block_num()) );
limit_itr = next_limit_itr;
}

} // whlie call_itr != call_end

Expand Down
1 change: 1 addition & 0 deletions libraries/chain/db_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ void database::clear_expired_orders()
price settlement_price = pays / receives;

// Calculate fill_price with a bigger volume to reduce impacts of rounding
// TODO replace the calculation with new operator*() and/or operator/()
if( settlement_fill_price.base.asset_id != current_asset ) // only calculate once per asset
{
asset tmp_pays = max_settlement_volume;
Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ namespace graphene { namespace chain {
flat_map<uint32_t,block_id_type> _checkpoints;

node_property_object _node_property_object;

/**
* Whether database is successfully opened or not.
*
* The database is considered open when there's no exception
* or assertion fail during database::open() method, and
* database::close() has not been called, or failed during execution.
*/
bool _opened = false;
};

namespace detail
Expand Down
8 changes: 8 additions & 0 deletions libraries/chain/include/graphene/chain/protocol/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ namespace graphene { namespace chain {
bool operator != ( const price& a, const price& b );
asset operator * ( const asset& a, const price& b );

price operator * ( const price& p, const ratio_type& r );
price operator / ( const price& p, const ratio_type& r );

inline price& operator *= ( price& p, const ratio_type& r )
{ return p = p * r; }
inline price& operator /= ( price& p, const ratio_type& r )
{ return p = p / r; }

/**
* @class price_feed
* @brief defines market parameters for margin positions
Expand Down
Loading

0 comments on commit adde3fa

Please sign in to comment.