Skip to content

Commit

Permalink
Merge branch 'staging' v0.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Jun 28, 2016
2 parents ae6d87c + daa3ce7 commit f566957
Show file tree
Hide file tree
Showing 53 changed files with 3,036 additions and 581 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ programs/util/inflation_model
tests/app_test
tests/chain_bench
tests/chain_test
tests/plugin_test
tests/intense_test
tests/performance_test

Expand Down
12 changes: 9 additions & 3 deletions libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ namespace steemit { namespace app {
}

idump((acc->allowed_apis));
std::map< std::string, api_ptr >& _api_map = _ctx.connection->api_map;
std::shared_ptr< api_session_data > session = _ctx.session.lock();
FC_ASSERT( session );

std::map< std::string, api_ptr >& _api_map = session->api_map;

for( const std::string& api_name : acc->allowed_apis )
{
Expand All @@ -80,15 +83,18 @@ namespace steemit { namespace app {
continue;
}
idump((api_name));
api_context new_ctx( _ctx.app, api_name, _ctx.connection );
api_context new_ctx( _ctx.app, api_name, _ctx.session );
_api_map[ api_name ] = _ctx.app.create_api_by_name( new_ctx );
}
return true;
}

fc::api_ptr login_api::get_api_by_name( const string& api_name )const
{
const std::map< std::string, api_ptr >& _api_map = _ctx.connection->api_map;
std::shared_ptr< api_session_data > session = _ctx.session.lock();
FC_ASSERT( session );

const std::map< std::string, api_ptr >& _api_map = session->api_map;
auto it = _api_map.find( api_name );
if( it == _api_map.end() )
{
Expand Down
18 changes: 8 additions & 10 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ using std::vector;

namespace bpo = boost::program_options;

api_context::api_context( application& _app, const std::string& _api_name, std::weak_ptr< api_connection_context > _connection )
: app(_app), api_name(_api_name), connection(_connection) {}
api_context::api_context( application& _app, const std::string& _api_name, std::weak_ptr< api_session_data > _session )
: app(_app), api_name(_api_name), session(_session) {}

namespace detail {

Expand Down Expand Up @@ -191,22 +191,22 @@ namespace detail {

void on_connection( const fc::http::websocket_connection_ptr& c )
{
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(*c);
std::shared_ptr< api_connection_context > conn_ctx = std::make_shared< api_connection_context >();
std::shared_ptr< api_session_data > session = std::make_shared<api_session_data>();
session->wsc = std::make_shared<fc::rpc::websocket_api_connection>(*c);

for( const std::string& name : _public_apis )
{
api_context ctx( *_self, name, conn_ctx );
api_context ctx( *_self, name, session );
fc::api_ptr api = create_api_by_name( ctx );
if( !api )
{
elog( "Couldn't create API ${name}", ("name", name) );
continue;
}
conn_ctx->api_map[name] = api;
api->register_api( *wsc );
session->api_map[name] = api;
api->register_api( *session->wsc );
}
c->set_session_data( wsc );
c->set_session_data( session );
}

application_impl(application* self)
Expand Down Expand Up @@ -328,8 +328,6 @@ namespace detail {
wild_access.password_salt_b64 = "*";
wild_access.allowed_apis.push_back( "database_api" );
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( "tag_api" );
_apiaccess.permission_map["*"] = wild_access;
}
Expand Down
82 changes: 57 additions & 25 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ void database_api::set_block_applied_callback( std::function<void(const variant&

void database_api_impl::on_applied_block( const chain::signed_block& b )
{
_block_applied_callback( fc::variant(signed_block_header(b) ) );
try
{
_block_applied_callback( fc::variant(signed_block_header(b) ) );
}
catch( ... )
{
_block_applied_connection.release();
}
}

void database_api_impl::set_block_applied_callback( std::function<void(const variant& block_header)> cb )
Expand Down Expand Up @@ -385,7 +392,7 @@ set<string> database_api::lookup_accounts(const string& lower_bound_name, uint32

set<string> database_api_impl::lookup_accounts(const string& lower_bound_name, uint32_t limit)const
{
FC_ASSERT( limit <= 1000 );
//FC_ASSERT( limit <= 1000 );
const auto& accounts_by_name = _db.get_index_type<account_index>().indices().get<by_name>();
set<string> result;

Expand Down Expand Up @@ -519,42 +526,60 @@ order_book database_api::get_order_book( uint32_t limit )const
{
return my->get_order_book( limit );
}
vector<extended_limit_order> database_api::get_open_orders( string owner )const {
vector<extended_limit_order> result;
const auto& idx = my->_db.get_index_type<limit_order_index>().indices().get<by_account>();
auto itr = idx.lower_bound( owner );
while( itr != idx.end() && itr->seller == owner ) {
result.push_back( *itr );
result.back().real_price = (~result.back().sell_price).to_real();
++itr;
}
return result;
}

order_book database_api_impl::get_order_book( uint32_t limit )const
{
FC_ASSERT( limit <= 1000 );
order_book result;
const auto& order_idx = _db.get_index_type< limit_order_index >().indices().get< by_price >();
auto end = order_idx.lower_bound( std::make_tuple( price( asset( 0, SBD_SYMBOL ), asset( 1, STEEM_SYMBOL ) ) ) );
auto itr = order_idx.upper_bound( std::make_tuple( price( asset( ~0, SBD_SYMBOL ), asset( 1, STEEM_SYMBOL ) ) ) );

while( itr != end && itr->sell_price.base.symbol == SBD_SYMBOL && result.bids.size() < limit )
auto max_sell = price::max( SBD_SYMBOL, STEEM_SYMBOL );
auto max_buy = price::max( STEEM_SYMBOL, SBD_SYMBOL );

const auto& limit_price_idx = _db.get_index_type<limit_order_index>().indices().get<by_price>();
auto sell_itr = limit_price_idx.lower_bound(max_sell);
auto buy_itr = limit_price_idx.lower_bound(max_buy);
auto end = limit_price_idx.end();
idump((max_sell)(max_buy));
if( sell_itr != end ) idump((*sell_itr));
if( buy_itr != end ) idump((*buy_itr));

while( sell_itr != end && sell_itr->sell_price.base.symbol == SBD_SYMBOL && result.bids.size() < limit )
{
auto itr = sell_itr;
order cur;
cur.order_price = itr->sell_price;
cur.real_price = (~cur.order_price).to_real();
cur.sbd = itr->for_sale;
cur.steem = ( asset( itr->for_sale, SBD_SYMBOL ) * cur.order_price ).amount;
cur.created = itr->created;
result.bids.push_back( cur );

itr--;
++sell_itr;
}

end = order_idx.lower_bound( std::make_tuple( price( asset( 0, STEEM_SYMBOL ), asset( 1, SBD_SYMBOL ) ) ) );
itr = order_idx.upper_bound( std::make_tuple( price( asset( ~0, STEEM_SYMBOL ), asset( 1, SBD_SYMBOL ) ) ) );

while( itr != end && itr->sell_price.base.symbol == STEEM_SYMBOL && result.asks.size() < limit )
while( buy_itr != end && buy_itr->sell_price.base.symbol == STEEM_SYMBOL && result.asks.size() < limit )
{
auto itr = buy_itr;
order cur;
cur.order_price = itr->sell_price;
cur.steem = itr->for_sale;
cur.sbd = ( asset( itr->for_sale, STEEM_SYMBOL ) * cur.order_price ).amount;
cur.real_price = (~cur.order_price).to_real();
cur.steem = itr->for_sale;
cur.sbd = ( asset( itr->for_sale, STEEM_SYMBOL ) * cur.order_price ).amount;
cur.created = itr->created;
result.asks.push_back( cur );

itr--;
++buy_itr;
}


return result;
}

Expand Down Expand Up @@ -750,10 +775,14 @@ void database_api::set_pending_payout( discussion& d )const
u256 total_r2 = to256( props.total_reward_shares2 );

if( props.total_reward_shares2 > 0 ){
int64_t abs_net_rshares = llabs(d.net_rshares.value);
auto vshares = my->_db.calculate_vshares( d.net_rshares.value > 0 ? d.net_rshares.value : 0 );

//int64_t abs_net_rshares = llabs(d.net_rshares.value);

u256 r2 = to256(abs_net_rshares);
u256 r2 = to256(vshares); //to256(abs_net_rshares);
/*
r2 *= r2;
*/
r2 *= pot.amount.value;
r2 /= total_r2;

Expand All @@ -763,10 +792,6 @@ void database_api::set_pending_payout( discussion& d )const

d.pending_payout_value = asset( static_cast<uint64_t>(r2), pot.symbol );
d.total_pending_payout_value = asset( static_cast<uint64_t>(tpp), pot.symbol );

if( d.net_rshares.value < 0 ) {
d.pending_payout_value.amount.value *= -1;
}
}
set_url(d);
}
Expand Down Expand Up @@ -866,13 +891,14 @@ discussion database_api::get_discussion( comment_id_type id )const {
discussion d = id(my->_db);
set_url( d );
set_pending_payout( d );
d.active_votes = get_active_votes( d.author, d.permlink );
return d;
}


template<typename Index, typename StartItr>
vector<discussion> database_api::get_discussions( const discussion_query& query,
const string& tag,
vector<discussion> database_api::get_discussions( const discussion_query& query,
const string& tag,
comment_id_type parent,
const Index& tidx, StartItr tidx_itr )const
{
Expand All @@ -899,7 +925,11 @@ vector<discussion> database_api::get_discussions( const discussion_query& query,
while( count > 0 && tidx_itr != tidx.end() ) {
if( tidx_itr->tag != tag || tidx_itr->parent != parent )
break;
try {
result.push_back( get_discussion( tidx_itr->comment ) );
} catch ( const fc::exception& e ) {
edump((e.to_detail_string()));
}

++tidx_itr; --count;
}
Expand Down Expand Up @@ -968,6 +998,7 @@ vector<discussion> database_api::get_discussions_by_votes( const discussion_quer

return get_discussions( query, tag, parent, tidx, tidx_itr );
}

vector<discussion> database_api::get_discussions_by_children( const discussion_query& query )const {
query.validate();
auto tag = fc::to_lower( query.tag );
Expand All @@ -978,6 +1009,7 @@ vector<discussion> database_api::get_discussions_by_children( const discussion_q

return get_discussions( query, tag, parent, tidx, tidx_itr );
}

vector<discussion> database_api::get_discussions_by_hot( const discussion_query& query )const {
query.validate();
auto tag = fc::to_lower( query.tag );
Expand Down
3 changes: 2 additions & 1 deletion libraries/app/impacted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ struct get_impacted_account_visitor

void operator()( const fill_vesting_withdraw_operation& op )
{
_impacted.insert( op.account );
_impacted.insert( op.from_account );
_impacted.insert( op.to_account );
}

void operator()( const custom_operation& op )
Expand Down
16 changes: 12 additions & 4 deletions libraries/app/include/steemit/app/api_context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,25 @@

#include <fc/api.hpp>

namespace fc { namespace rpc {

class websocket_api_connection;

} }

namespace steemit { namespace app {

class application;

/**
* Contains state shared by all API's on the same connection.
* Anything in here is owned by FC and cleaned up when the connection dies.
*/

struct api_connection_context
struct api_session_data
{
std::map< std::string, fc::api_ptr > api_map;
std::shared_ptr< fc::rpc::websocket_api_connection > wsc;
std::map< std::string, fc::api_ptr > api_map;
};

/**
Expand All @@ -25,11 +33,11 @@ struct api_connection_context

struct api_context
{
api_context( application& _app, const std::string& _api_name, std::weak_ptr< api_connection_context > _connection );
api_context( application& _app, const std::string& _api_name, std::weak_ptr< api_session_data > _session );

application& app;
std::string api_name;
std::shared_ptr< api_connection_context > connection;
std::weak_ptr< api_session_data > session;
};

} }
5 changes: 4 additions & 1 deletion libraries/app/include/steemit/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ using namespace std;
struct order
{
price order_price;
double real_price; // dollars per steem
share_type steem;
share_type sbd;
fc::time_point_sec created;
Expand Down Expand Up @@ -239,6 +240,7 @@ class database_api
* @param limit Maximum number of orders for each side of the spread to return -- Must not exceed 1000
*/
order_book get_order_book( uint32_t limit = 1000 )const;
vector<extended_limit_order> get_open_orders( string owner )const;


////////////////////////////
Expand Down Expand Up @@ -366,7 +368,7 @@ class database_api

} }

FC_REFLECT( steemit::app::order, (order_price)(steem)(sbd)(created) );
FC_REFLECT( steemit::app::order, (order_price)(real_price)(steem)(sbd)(created) );
FC_REFLECT( steemit::app::order_book, (asks)(bids) );
FC_REFLECT( steemit::app::scheduled_hardfork, (hf_version)(live_time) );

Expand Down Expand Up @@ -424,6 +426,7 @@ FC_API(steemit::app::database_api,

// Market
(get_order_book)
(get_open_orders)

// Authority / validation
(get_transaction_hex)
Expand Down
Loading

0 comments on commit f566957

Please sign in to comment.