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

Commit

Permalink
Merge pull request #75 from vikramrajkumar/btsx
Browse files Browse the repository at this point in the history
Merge fixes
  • Loading branch information
bitsha256 committed Oct 1, 2014
2 parents c844ba8 + 6c0ca96 commit e96d22b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Expand Up @@ -11,5 +11,5 @@ const static std::map<uint32_t, bts::blockchain::block_id_type> CHECKPOINT_BLOCK
{ 400000, bts::blockchain::block_id_type( "053d398b6597d5c61365afd100d87b824bf49f65" ) },
{ 500000, bts::blockchain::block_id_type( "f02910a7115fb826984ce3a432cb371d5d7a99b8" ) },
{ 600000, bts::blockchain::block_id_type( "f278db8722235343c9db9f077fe67c54a5f25f3b" ) },
{ 622000, bts::blockchain::block_id_type( "8e9880bd7bb1fb49d2aa0fc98b7da8debe0b4de7" ) }
{ 632000, bts::blockchain::block_id_type( "aa6526cc642f531b160de4505c4bd6c7a8add026" ) }
};
37 changes: 37 additions & 0 deletions libraries/blockchain/market_operations.cpp
Expand Up @@ -53,6 +53,13 @@ namespace bts { namespace blockchain {
current_bid->last_update = eval_state._current_state->now();
current_bid->balance += this->amount;

// bids do not count toward depth... they can set any price they like and create arbitrary depth
//auto market_stat = eval_state._current_state->get_market_status( bid_index.order_price.quote_asset_id, bid_index.order_price.base_asset_id );
//if( !market_stat )
// market_stat = market_status(0,0);
// market_stat->bid_depth += (delta_amount * bid_index.order_price).amount;
//eval_state._current_state->store_market_status( *market_stat );

eval_state._current_state->store_bid_record( this->bid_index, *current_bid );

//auto check = eval_state._current_state->get_bid_record( this->bid_index );
Expand Down Expand Up @@ -104,7 +111,17 @@ namespace bts { namespace blockchain {
current_ask->balance += this->amount;
FC_ASSERT( current_ask->balance >= 0, "", ("current_ask",current_ask) );

auto market_stat = eval_state._current_state->get_market_status( ask_index.order_price.quote_asset_id, ask_index.order_price.base_asset_id );

if( !market_stat )
market_stat = market_status( ask_index.order_price.quote_asset_id, ask_index.order_price.base_asset_id, 0, 0 );
market_stat->ask_depth += delta_amount.amount;

eval_state._current_state->store_market_status( *market_stat );

eval_state._current_state->store_ask_record( this->ask_index, *current_ask );

//auto check = eval_state._current_state->get_ask_record( this->ask_index );
} FC_CAPTURE_AND_RETHROW( (*this) ) }

void short_operation::evaluate( transaction_evaluation_state& eval_state )
Expand Down Expand Up @@ -164,6 +181,14 @@ namespace bts { namespace blockchain {
current_short->balance += this->amount;
FC_ASSERT( current_short->balance >= 0 );

auto market_stat = eval_state._current_state->get_market_status( short_index.order_price.quote_asset_id, short_index.order_price.base_asset_id );
if( !market_stat )
market_stat = market_status( short_index.order_price.quote_asset_id, short_index.order_price.base_asset_id, 0, 0 );

market_stat->bid_depth += delta_amount.amount;

eval_state._current_state->store_market_status( *market_stat );

eval_state._current_state->store_short_record( this->short_index, *current_short );
}

Expand Down Expand Up @@ -231,6 +256,12 @@ namespace bts { namespace blockchain {
else // withdraw the collateral to the transaction to be deposited at owners discretion / cover fees
{
eval_state.add_balance( asset( current_cover->collateral_balance, cover_index.order_price.base_asset_id ) );

auto market_stat = eval_state._current_state->get_market_status( cover_index.order_price.quote_asset_id, cover_index.order_price.base_asset_id );
FC_ASSERT( market_stat, "this should be valid for there to even be a position to cover" );
market_stat->ask_depth -= current_cover->collateral_balance;

eval_state._current_state->store_market_status( *market_stat );
}
}

Expand Down Expand Up @@ -264,6 +295,12 @@ namespace bts { namespace blockchain {

eval_state._current_state->store_collateral_record( market_index_key( new_call_price, this->cover_index.owner),
*current_cover );

auto market_stat = eval_state._current_state->get_market_status( cover_index.order_price.quote_asset_id, cover_index.order_price.base_asset_id );
FC_ASSERT( market_stat, "this should be valid for there to even be a position to cover" );
market_stat->ask_depth += delta_amount.amount;

eval_state._current_state->store_market_status( *market_stat );
}

void remove_collateral_operation::evaluate( transaction_evaluation_state& eval_state )
Expand Down
16 changes: 16 additions & 0 deletions libraries/net/node.cpp
Expand Up @@ -2334,6 +2334,8 @@ namespace bts { namespace net { namespace detail {
( "type", fetch_items_message_received.item_type )
( "endpoint", originating_peer->get_remote_endpoint() ) );

fc::optional<message> last_block_message_sent;

std::list<message> reply_messages;
for( const item_hash_t& item_hash : fetch_items_message_received.items_to_fetch )
{
Expand All @@ -2344,6 +2346,8 @@ namespace bts { namespace net { namespace detail {
( "endpoint", originating_peer->get_remote_endpoint() )
( "id", requested_message.id() ) );
reply_messages.push_back( requested_message );
if (fetch_items_message_received.item_type == block_message_type)
last_block_message_sent = requested_message;
continue;
}
catch ( fc::key_not_found_exception& )
Expand All @@ -2360,6 +2364,8 @@ namespace bts { namespace net { namespace detail {
( "size", requested_message.size )
( "endpoint", originating_peer->get_remote_endpoint() ) );
reply_messages.push_back( requested_message );
if (fetch_items_message_received.item_type == block_message_type)
last_block_message_sent = requested_message;
continue;
}
catch ( fc::key_not_found_exception& )
Expand All @@ -2369,6 +2375,16 @@ namespace bts { namespace net { namespace detail {
( "endpoint", originating_peer->get_remote_endpoint() ) );
}
}

// if we sent them a block, update our record of the last block they've seen accordingly
if (last_block_message_sent)
{
bts::client::block_message block = last_block_message_sent->as<bts::client::block_message>();
originating_peer->last_block_delegate_has_seen = block.block_id;
originating_peer->last_block_number_delegate_has_seen = _delegate->get_block_number(block.block_id);
originating_peer->last_block_time_delegate_has_seen = _delegate->get_block_time(block.block_id);
}

for( const message& reply : reply_messages )
originating_peer->send_message( reply );
}
Expand Down

0 comments on commit e96d22b

Please sign in to comment.