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

Commit

Permalink
Merge branch 'develop' into bitshares
Browse files Browse the repository at this point in the history
  • Loading branch information
vikramrajkumar committed Dec 16, 2014
2 parents cb20d5a + 4890557 commit 6d42fca
Show file tree
Hide file tree
Showing 16 changed files with 352,635 additions and 352,423 deletions.
2 changes: 1 addition & 1 deletion libraries/blockchain/chain_database.cpp
Expand Up @@ -2295,7 +2295,7 @@ namespace bts { namespace blockchain {

const signed_block_header head_block = get_head_block();

new_block.previous = head_block.id();
new_block.previous = head_block.block_num > 0 ? head_block.id() : block_id_type();
new_block.block_num = head_block.block_num + 1;
new_block.timestamp = block_timestamp;
new_block.transaction_digest = digest_block( new_block ).calculate_transaction_digest();
Expand Down
48 changes: 28 additions & 20 deletions libraries/blockchain/chain_interface.cpp
Expand Up @@ -292,31 +292,39 @@ namespace bts { namespace blockchain {

asset chain_interface::to_ugly_asset(const std::string& amount, const std::string& symbol) const
{ try {
auto record = get_asset_record( symbol );
const auto record = get_asset_record( symbol );
if( !record ) FC_CAPTURE_AND_THROW( unknown_asset_symbol, (symbol) );
asset ugly_asset(0, record->id);

auto decimal = amount.find(".");
if( decimal == string::npos )
return asset(atoll(amount.c_str()) * record->precision, record->id);
const auto decimal = amount.find(".");
ugly_asset.amount += atoll(amount.substr(0, decimal).c_str()) * record->precision;

share_type whole = atoll(amount.substr(0, decimal).c_str()) * record->precision;
string fraction_string = amount.substr(decimal+1);
share_type fraction = atoll(fraction_string.c_str());

if( fraction_string.empty() || fraction <= 0 )
return asset(whole, record->id);

while( fraction < record->precision )
fraction *= 10;
while( fraction > record->precision )
fraction /= 10;
while( fraction_string.size() && fraction_string[0] == '0')
if( decimal != string::npos )
{
fraction /= 10;
fraction_string.erase(0, 1);
string fraction_string = amount.substr(decimal+1);
share_type fraction = atoll(fraction_string.c_str());

if( !fraction_string.empty() && fraction > 0 )
{
while( fraction < record->precision )
fraction *= 10;
while( fraction >= record->precision )
fraction /= 10;
while( fraction_string.size() && fraction_string[0] == '0')
{
fraction /= 10;
fraction_string.erase(0, 1);
}

if( ugly_asset.amount >= 0 )
ugly_asset.amount += fraction;
else
ugly_asset.amount -= fraction;
}
}
return asset(whole >= 0? whole + fraction : whole - fraction, record->id);
} FC_CAPTURE_AND_RETHROW( (amount)(symbol) ) }

return ugly_asset;
} FC_CAPTURE_AND_RETHROW( (amount)(symbol) ) }

price chain_interface::to_ugly_price(const std::string& price_string,
const std::string& base_symbol,
Expand Down

0 comments on commit 6d42fca

Please sign in to comment.