Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
merge upstream master
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsha256 committed Aug 20, 2014
2 parents 4226bb0 + ec1e5b5 commit b9e967b
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 35 deletions.
5 changes: 3 additions & 2 deletions libraries/blockchain/chain_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -851,10 +851,11 @@ namespace bts { namespace blockchain {
}

// just in case something changes while calling observer
for( const auto& o : _observers )
const auto observers = _observers;
for( const auto& o : observers )
{
try {
ilog( "... block applied ... " );
//ilog( "... block applied ... " );
//Schedule the observer notifications for later; the chain is in a
//non-premptable state right now, and observers may yield.
fc::async([o,summary]{o->block_applied( summary );});
Expand Down
2 changes: 1 addition & 1 deletion libraries/blockchain/include/bts/blockchain/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @brief Defines global constants that determine blockchain behavior
*/
#define BTS_BLOCKCHAIN_VERSION 109
#define BTS_BLOCKCHAIN_DATABASE_VERSION 125
#define BTS_BLOCKCHAIN_DATABASE_VERSION 126

/**
* The address prepended to string representation of
Expand Down
17 changes: 9 additions & 8 deletions libraries/blockchain/market_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,19 +330,20 @@ class market_engine
market_stat->avg_price_24h.ratio *= (BTS_BLOCKCHAIN_BLOCKS_PER_HOUR-1);

// limit the maximum movement rate of the price.
if( _current_bid->get_price() > min_cover_ask )
market_stat->avg_price_24h.ratio += _current_bid->get_price().ratio;
else if( _current_bid->get_price() < max_short_bid )
if( _current_bid->get_price() < min_cover_ask )
market_stat->avg_price_24h.ratio += min_cover_ask.ratio;
else if( _current_bid->get_price() > max_short_bid )
market_stat->avg_price_24h.ratio += max_short_bid.ratio;
else
market_stat->avg_price_24h.ratio += min_cover_ask.ratio;
market_stat->avg_price_24h.ratio += _current_bid->get_price().ratio;

if( _current_ask->get_price() < max_short_bid )
market_stat->avg_price_24h.ratio += _current_ask->get_price().ratio;
else if( _current_ask->get_price() > min_cover_ask )
if( _current_ask->get_price() < min_cover_ask )
market_stat->avg_price_24h.ratio += min_cover_ask.ratio;
else
else if( _current_ask->get_price() > max_short_bid )
market_stat->avg_price_24h.ratio += max_short_bid.ratio;
else
market_stat->avg_price_24h.ratio += _current_ask->get_price().ratio;


market_stat->avg_price_24h.ratio /= (BTS_BLOCKCHAIN_BLOCKS_PER_HOUR+1);
}
Expand Down
9 changes: 7 additions & 2 deletions libraries/cli/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace bts { namespace cli {
}
catch( const fc::canceled_exception&)
{
*_out << "Command aborted.\n";
throw;
}
catch( const fc::exception& e)
{
Expand Down Expand Up @@ -917,7 +917,9 @@ namespace bts { namespace cli {

auto quote_asset_record = _client->get_chain()->get_asset_record( quote_id );
// fee order is the market order to convert fees from other asset classes to XTS
bool show_fee_order_record = base_id == 0 && quote_asset_record->collected_fees > 0;
bool show_fee_order_record = base_id == 0
&& !quote_asset_record->is_market_issued()
&& quote_asset_record->collected_fees > 0;

while( bid_itr != bids_asks.first.end() || ask_itr != bids_asks.second.end() )
{
Expand Down Expand Up @@ -1033,6 +1035,9 @@ namespace bts { namespace cli {
}
}
}

// TODO: print insurance fund for market issued assets

} // end call section that only applies to market issued assets vs XTS
else
{
Expand Down
51 changes: 32 additions & 19 deletions libraries/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,20 +551,11 @@ config load_config( const fc::path& datadir )
{
_chain_db = std::make_shared<chain_database>();
} FC_RETHROW_EXCEPTIONS(warn,"chain_db")
_rebroadcast_pending_loop = fc::async( [=]() { rebroadcast_pending(); },
"rebroadcast_pending");
} FC_RETHROW_EXCEPTIONS( warn, "" ) }

virtual ~client_impl() override
{
try
{
_rebroadcast_pending_loop.cancel_and_wait();
}
catch (const fc::exception& e)
{
wlog("Unexpected error from rebroadcast_pending(): ${e}", ("e", e));
}
cancel_rebroadcast_pending_loop();
_p2p_node.reset();
delete _cli;
}
Expand All @@ -580,8 +571,10 @@ config load_config( const fc::path& datadir )
void delegate_loop();
void set_target_connections( uint32_t target );

void rebroadcast_pending();
fc::future<void> _rebroadcast_pending_loop;
void start_rebroadcast_pending_loop();
void cancel_rebroadcast_pending_loop();
void rebroadcast_pending_loop();
fc::future<void> _rebroadcast_pending_loop_done;

void configure_rpc_server(config& cfg,
const program_options::variables_map& option_variables);
Expand Down Expand Up @@ -958,7 +951,27 @@ config load_config( const fc::path& datadir )
return trxs;
}

void client_impl::rebroadcast_pending()
void client_impl::start_rebroadcast_pending_loop()
{
if (!_rebroadcast_pending_loop_done.valid() || _rebroadcast_pending_loop_done.ready())
_rebroadcast_pending_loop_done = fc::schedule( [=](){ rebroadcast_pending_loop(); },
fc::time_point::now() + fc::seconds((int64_t)(BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC * 1.3)),
"rebroadcast_pending" );
}

void client_impl::cancel_rebroadcast_pending_loop()
{
try
{
_rebroadcast_pending_loop_done.cancel_and_wait();
}
catch (const fc::exception& e)
{
wlog("Unexpected error from rebroadcast_pending(): ${e}", ("e", e));
}
}

void client_impl::rebroadcast_pending_loop()
{
#ifndef NDEBUG
static bool currently_running = false;
Expand Down Expand Up @@ -988,10 +1001,10 @@ config load_config( const fc::path& datadir )
wlog( "error rebroadcasting transacation: ${e}", ("e",e.to_detail_string() ) );
}
}
if (!_rebroadcast_pending_loop.canceled())
_rebroadcast_pending_loop = fc::schedule( [=](){ rebroadcast_pending(); },
fc::time_point::now() + fc::seconds((int64_t)(BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC*1.3)),
"rebroadcast_pending" );
if (!_rebroadcast_pending_loop_done.canceled())
_rebroadcast_pending_loop_done = fc::schedule( [=](){ rebroadcast_pending_loop(); },
fc::time_point::now() + fc::seconds((int64_t)(BTS_BLOCKCHAIN_BLOCK_INTERVAL_SEC * 1.3)),
"rebroadcast_pending" );
}

///////////////////////////////////////////////////////
Expand Down Expand Up @@ -1552,10 +1565,10 @@ config load_config( const fc::path& datadir )

//if we are using a simulated network, _p2p_node will already be set by client's constructor
if (!my->_p2p_node)
{
my->_p2p_node = std::make_shared<bts::net::node>();
}
my->_p2p_node->set_node_delegate(my.get());

my->start_rebroadcast_pending_loop();
} FC_RETHROW_EXCEPTIONS( warn, "", ("data_dir",data_dir) ) }

client::~client()
Expand Down
2 changes: 2 additions & 0 deletions libraries/wallet/include/bts/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace bts { namespace wallet {
fc::signal<void( bool )> wallet_lock_state_changed;
//Emitted when wallet claims a new transaction. Argument is new ledger entry.
fc::signal<void( ledger_entry )> wallet_claimed_transaction;
//Emitted when someone (partially or fully) fills your short, thereby giving you a margin position
fc::signal<void( ledger_entry )> update_margin_position;

/**
* To generate predictable test results we need an option
Expand Down
10 changes: 8 additions & 2 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ namespace bts { namespace wallet {
entry.amount = trx.bid_received;
entry.memo = "bid proceeds @ " + _blockchain->to_pretty_price( trx.bid_price );
record.ledger_entries.push_back( entry );
self->wallet_claimed_transaction( entry );
}
}
else /* if( trx.bid_type == short_order ) */
Expand Down Expand Up @@ -265,6 +266,7 @@ namespace bts { namespace wallet {
entry.amount = trx.bid_paid;
entry.memo = "short proceeds @ " + _blockchain->to_pretty_price( trx.bid_price );
record.ledger_entries.push_back( entry );
self->update_margin_position( entry );
}
}

Expand Down Expand Up @@ -318,6 +320,7 @@ namespace bts { namespace wallet {
entry.amount = trx.ask_received;
entry.memo = "ask proceeds @ " + _blockchain->to_pretty_price( trx.ask_price );
record.ledger_entries.push_back( entry );
self->wallet_claimed_transaction( entry );
}
}
else /* if( trx.ask_type == cover_order ) */
Expand Down Expand Up @@ -346,6 +349,7 @@ namespace bts { namespace wallet {
entry.amount = trx.fees_collected * 19;
entry.memo = "cover proceeds - 5% margin call fee";
record.ledger_entries.push_back( entry );
self->wallet_claimed_transaction( entry );
record.fee = trx.fees_collected;
}
}
Expand Down Expand Up @@ -610,12 +614,14 @@ namespace bts { namespace wallet {

// Force scanning all deposits next because ledger reconstruction assumes such an ordering
auto has_deposit = false;
bool is_deposit = false;
for( const auto& op : transaction.operations )
{
switch( operation_type_enum( op.type ) )
{
case deposit_op_type:
has_deposit |= scan_deposit( op.as<deposit_operation>(), keys, *transaction_record, total_fee );
is_deposit = scan_deposit( op.as<deposit_operation>(), keys, *transaction_record, total_fee );
has_deposit |= is_deposit;
break;
case bid_op_type:
{
Expand Down Expand Up @@ -644,7 +650,7 @@ namespace bts { namespace wallet {
}
store_record |= has_deposit;

if( new_transaction && has_deposit )
if( new_transaction && is_deposit )
self->wallet_claimed_transaction( transaction_record->ledger_entries.back() );

/* Reconstruct fee */
Expand Down
2 changes: 1 addition & 1 deletion programs/web_wallet

0 comments on commit b9e967b

Please sign in to comment.