Skip to content

Commit 5e12f6b

Browse files
committed
Workaround conversion from double to string, related to issue bitshares#544.
1 parent a6d24bc commit 5e12f6b

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

libraries/wallet/wallet.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -3868,8 +3868,17 @@ signed_transaction wallet_api::sell( string seller_account,
38683868
double amount,
38693869
bool broadcast )
38703870
{
3871-
return my->sell_asset( seller_account, std::to_string( amount ), base,
3872-
std::to_string( rate * amount ), quote, 0, false, broadcast );
3871+
std::ostringstream amount_to_sell;
3872+
std::ostringstream min_to_receive;
3873+
3874+
uint8_t sell_precision = get_asset(base).precision;
3875+
uint8_t recv_precision = get_asset(quote).precision;
3876+
3877+
amount_to_sell << std::fixed << std::setprecision(sell_precision) << amount;
3878+
min_to_receive << std::fixed << std::setprecision(recv_precision) << rate * amount;
3879+
3880+
return my->sell_asset( seller_account, amount_to_sell.str(), base,
3881+
min_to_receive.str(), quote, 0, false, broadcast );
38733882
}
38743883

38753884
signed_transaction wallet_api::buy( string buyer_account,
@@ -3879,8 +3888,17 @@ signed_transaction wallet_api::buy( string buyer_account,
38793888
double amount,
38803889
bool broadcast )
38813890
{
3882-
return my->sell_asset( buyer_account, std::to_string( rate * amount ), quote,
3883-
std::to_string( amount ), base, 0, false, broadcast );
3891+
std::ostringstream amount_to_buy;
3892+
std::ostringstream min_to_receive;
3893+
3894+
uint8_t buy_precision = get_asset(quote).precision;
3895+
uint8_t recv_precision = get_asset(base).precision;
3896+
3897+
amount_to_buy << std::fixed << std::setprecision(buy_precision) << rate * amount;
3898+
min_to_receive << std::fixed << std::setprecision(recv_precision) << amount;
3899+
3900+
return my->sell_asset( buyer_account, amount_to_buy.str(), quote,
3901+
min_to_receive.str(), base, 0, false, broadcast );
38843902
}
38853903

38863904
signed_transaction wallet_api::borrow_asset(string seller_name, string amount_to_sell,

0 commit comments

Comments
 (0)