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 #83 from vikramrajkumar/btsx
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
bitsha256 committed Oct 23, 2014
2 parents 97e5538 + 8f8da95 commit 74e3290
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 42 deletions.
Expand Up @@ -13,5 +13,5 @@ const static std::map<uint32_t, bts::blockchain::block_id_type> CHECKPOINT_BLOCK
{ 600000, bts::blockchain::block_id_type( "f278db8722235343c9db9f077fe67c54a5f25f3b" ) },
{ 700000, bts::blockchain::block_id_type( "f120ff9b159661b9ac084a0a69c58dcbd79cbb49" ) },
{ 800000, bts::blockchain::block_id_type( "0e94ad17c598e42e5ec2f522a05bf4df6a1778da" ) },
{ 804000, bts::blockchain::block_id_type( "796a88a21e443c0655479d879e8ac4acd875d12d" ) }
{ 821000, bts::blockchain::block_id_type( "74826a14c0281ac7ff6bdc66d25a522287e565d7" ) }
};
4 changes: 3 additions & 1 deletion libraries/blockchain/include/bts/blockchain/fork_blocks.hpp
Expand Up @@ -3,6 +3,8 @@
#include <stdint.h>
#include <vector>

#define BTSX_MARKET_COVER_SOFT_FORK 828000

/** @file bts/blockchain/fork_blocks.hpp
* @brief Defines global block number constants for when hardforks take effect
*/
Expand Down Expand Up @@ -45,4 +47,4 @@
namespace bts { namespace blockchain {
uint32_t estimate_last_known_fork_from_git_revision_timestamp(uint32_t revision_time);
std::vector<uint32_t> get_list_of_fork_block_numbers();
} }
} }
12 changes: 12 additions & 0 deletions libraries/blockchain/market_engine.cpp
@@ -1,6 +1,8 @@
#include <bts/blockchain/market_engine.hpp>
#include <fc/real128.hpp>

#include <bts/blockchain/fork_blocks.hpp>

namespace bts { namespace blockchain { namespace detail {

market_engine::market_engine( pending_chain_state_ptr ps, chain_database_impl& cdi )
Expand Down Expand Up @@ -444,6 +446,14 @@ namespace bts { namespace blockchain { namespace detail {
FC_ASSERT( _current_ask->type == cover_order );
FC_ASSERT( mtrx.ask_type == cover_order );

if( _pending_state->get_head_block_num() >= BTSX_MARKET_COVER_SOFT_FORK )
{
if( _current_collat_record.interest_rate.quote_asset_id == 0 && _current_collat_record.interest_rate.base_asset_id == 0 )
{
_current_collat_record.interest_rate.quote_asset_id = quote_asset.id;
}
}

const asset principle = asset( _current_collat_record.payoff_balance, quote_asset.id );
const auto cover_age = get_current_cover_age();
const asset total_debt = get_current_cover_debt();
Expand Down Expand Up @@ -692,6 +702,7 @@ namespace bts { namespace blockchain { namespace detail {
{
auto old_record = *opt;
old_record.volume += new_record.volume;
old_record.closing_price = new_record.closing_price;
if( new_record.highest_bid > old_record.highest_bid || new_record.lowest_ask < old_record.lowest_ask )
{
old_record.highest_bid = std::max(new_record.highest_bid, old_record.highest_bid);
Expand All @@ -708,6 +719,7 @@ namespace bts { namespace blockchain { namespace detail {
{
auto old_record = *opt;
old_record.volume += new_record.volume;
old_record.closing_price = new_record.closing_price;
if( new_record.highest_bid > old_record.highest_bid || new_record.lowest_ask < old_record.lowest_ask )
{
old_record.highest_bid = std::max(new_record.highest_bid, old_record.highest_bid);
Expand Down
10 changes: 9 additions & 1 deletion libraries/blockchain/market_operations.cpp
Expand Up @@ -220,6 +220,14 @@ namespace bts { namespace blockchain {
auto asset_to_cover = eval_state._current_state->get_asset_record( cover_index.order_price.quote_asset_id );
FC_ASSERT( asset_to_cover.valid() );

if( eval_state._current_state->get_head_block_num() >= BTSX_MARKET_COVER_SOFT_FORK )
{
if( current_cover->interest_rate.quote_asset_id == 0 && current_cover->interest_rate.base_asset_id == 0 )
{
current_cover->interest_rate.quote_asset_id = asset_to_cover->id;
}
}

const auto start_time = current_cover->expiration - fc::seconds( BTS_BLOCKCHAIN_MAX_SHORT_PERIOD_SEC );
auto elapsed_sec = ( eval_state._current_state->now() - start_time ).to_seconds();
if( elapsed_sec < 0 ) elapsed_sec = 0;
Expand Down Expand Up @@ -258,7 +266,7 @@ namespace bts { namespace blockchain {
eval_state._current_state->store_collateral_record( this->cover_index, collateral_record() );

FC_ASSERT( current_cover->interest_rate.quote_asset_id > current_cover->interest_rate.base_asset_id,
"Somehow an evil cover has snuck its way past our defenses.", ("cover", *current_cover) );
"Rejecting cover order with invalid interest rate.", ("cover", *current_cover) );

if( current_cover->payoff_balance > 0 )
{
Expand Down
2 changes: 1 addition & 1 deletion libraries/client/client.cpp
Expand Up @@ -2763,7 +2763,7 @@ config load_config( const fc::path& datadir, bool enable_ulog )
my->_chain_downloader_blocks_remaining = blocks_left;
}, my->_chain_db->get_head_block_num() + 1);
my->_chain_downloader_future.on_complete([this,chain_downloader,network_started_callback](const fc::exception_ptr& e) {
if( e->code() == fc::canceled_exception::code_value )
if( e && e->code() == fc::canceled_exception::code_value )
{
delete chain_downloader;
return;
Expand Down
2 changes: 1 addition & 1 deletion programs/web_wallet
Expand Up @@ -18,7 +18,7 @@ wallet_multipart_transfer <amount_to_transfer> <asset_symbol> <from_account_name
Sends given amount to the given address. This transfer will occur using multiple transactions as necessary to maximize your privacy, but will be more costly.

Parameters:
amount_to_transfer (real_amount, required): the amount of shares to transfer, will be multiplied by the precision associated by asset_symbol
amount_to_transfer (string, required): the amount of shares to transfer, will be multiplied by the precision associated by asset_symbol
asset_symbol (asset_symbol, required): the asset to transfer
from_account_name (sending_account_name, required): the source account to draw the shares from
to_account_name (receive_account_name, required): the account to transfer the shares to
Expand Down
24 changes: 13 additions & 11 deletions tests/regression_tests/blockchain_markets/blockchain_markets.log
Expand Up @@ -12,6 +12,8 @@ default (unlocked) >>> wallet_transfer 100 XTS delegate0 testaccount1
TIMESTAMP BLOCK FROM TO AMOUNT MEMO FEE ID
======================================================================================================================================================================
<d-ign></d-ign>PENDING delegate0 testaccount1 100.00000 XTS 0.50000 XTS <d-ign></d-ign>
default (unlocked) >>> debug_wait_for_block_by_number 1 relative
OK
default (unlocked) >>> wallet_transfer 10000 XTS delegate0 testaccount2
TIMESTAMP BLOCK FROM TO AMOUNT MEMO FEE ID
======================================================================================================================================================================
Expand All @@ -22,7 +24,7 @@ default (unlocked) >>> blockchain_list_assets
ID SYMBOL NAME DESCRIPTION ISSUER ISSUED SUPPLY
===========================================================================================================================================================
1 XMO DIGITAL_DEVICE1 AN ASSET delegate0 0.00 % 0.00 XMO
0 XTS BitShares XTS BitShares X Test Network GENESIS N/A 1,999,999,997.29241 XTS
0 XTS BitShares XTS BitShares X Test Network GENESIS N/A 1,999,999,997.29341 XTS
default (unlocked) >>> blockchain_list_pending_transactions
No pending transactions.
default (unlocked) >>> balance
Expand Down Expand Up @@ -51,13 +53,13 @@ TIMESTAMP BLOCK FROM TO AMOUNT
<d-ign></d-ign>0 GENESIS delegate1 19,801,980.19801 XTS claim Pf8LAwjSFbjX3mzYhzThhcFqo1SweKsD6c 0.00000 XTS <d-ign></d-ign>
<d-ign></d-ign>1 delegate0 delegate0 0.00000 XTS create XMO (DIGITAL_DEVICE1) 1.70960 XTS <d-ign></d-ign>
<d-ign></d-ign>2 delegate0 testaccount1 100.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>2 delegate0 testaccount2 10,000.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>4 delegate0 testaccount1 10,000.00 XMO issue 10,000.00 XMO 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>3 delegate0 testaccount2 10,000.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>5 delegate0 testaccount1 10,000.00 XMO issue 10,000.00 XMO 0.50000 XTS <d-ign></d-ign>
default (unlocked) >>> blockchain_list_assets
ID SYMBOL NAME DESCRIPTION ISSUER ISSUED SUPPLY
===========================================================================================================================================================
1 XMO DIGITAL_DEVICE1 AN ASSET delegate0 0.20 % 10,000.00 XMO
0 XTS BitShares XTS BitShares X Test Network GENESIS N/A 1,999,999,996.79441 XTS
0 XTS BitShares XTS BitShares X Test Network GENESIS N/A 1,999,999,996.79541 XTS
default (unlocked) >>> help wallet_market_submit_bid
Usage:
wallet_market_submit_bid <from_account_name> <quantity> <quantity_symbol> <base_price> <base_symbol> [allow_stupid_bid] Used to place a request to buy a quantity of assets at a price specified in another asset
Expand Down Expand Up @@ -102,9 +104,9 @@ TIMESTAMP BLOCK FROM TO AMOUNT
<d-ign></d-ign>0 GENESIS delegate1 19,801,980.19801 XTS claim Pf8LAwjSFbjX3mzYhzThhcFqo1SweKsD6c 0.00000 XTS <d-ign></d-ign>
<d-ign></d-ign>1 delegate0 delegate0 0.00000 XTS create XMO (DIGITAL_DEVICE1) 1.70960 XTS <d-ign></d-ign>
<d-ign></d-ign>2 delegate0 testaccount1 100.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>2 delegate0 testaccount2 10,000.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>4 delegate0 testaccount1 10,000.00 XMO issue 10,000.00 XMO 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>6 testaccount1 BID-00992b6d 1,500.00 XMO buy XTS @ 3. XMO / XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>3 delegate0 testaccount2 10,000.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>5 delegate0 testaccount1 10,000.00 XMO issue 10,000.00 XMO 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>7 testaccount1 BID-00992b6d 1,500.00 XMO buy XTS @ 3. XMO / XTS 0.50000 XTS <d-ign></d-ign>
default (unlocked) >>> blockchain_market_list_bids XMO XTS
TYPE QUANTITY PRICE BALANCE COST COLLATERAL ID
==================================================================================================================================================================
Expand Down Expand Up @@ -157,10 +159,10 @@ TIMESTAMP BLOCK FROM TO AMOUNT
<d-ign></d-ign>0 GENESIS delegate1 19,801,980.19801 XTS claim Pf8LAwjSFbjX3mzYhzThhcFqo1SweKsD6c 0.00000 XTS <d-ign></d-ign>
<d-ign></d-ign>1 delegate0 delegate0 0.00000 XTS create XMO (DIGITAL_DEVICE1) 1.70960 XTS <d-ign></d-ign>
<d-ign></d-ign>2 delegate0 testaccount1 100.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>2 delegate0 testaccount2 10,000.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>4 delegate0 testaccount1 10,000.00 XMO issue 10,000.00 XMO 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>6 testaccount1 BID-00992b6d 1,500.00 XMO buy XTS @ 3. XMO / XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>8 testaccount2 ASK-9863da2e 100.00000 XTS sell XTS @ 4. XMO / XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>3 delegate0 testaccount2 10,000.00000 XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>5 delegate0 testaccount1 10,000.00 XMO issue 10,000.00 XMO 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>7 testaccount1 BID-00992b6d 1,500.00 XMO buy XTS @ 3. XMO / XTS 0.50000 XTS <d-ign></d-ign>
<d-ign></d-ign>9 testaccount2 ASK-9863da2e 100.00000 XTS sell XTS @ 4. XMO / XTS 0.50000 XTS <d-ign></d-ign>
default (unlocked) >>> blockchain_market_list_asks XMO XTS
TYPE QUANTITY PRICE BALANCE COST COLLATERAL ID
==================================================================================================================================================================
Expand Down

0 comments on commit 74e3290

Please sign in to comment.