Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workaround conversion from double to string, related to issue #544. #558

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3868,8 +3868,17 @@ signed_transaction wallet_api::sell( string seller_account,
double amount,
bool broadcast )
{
return my->sell_asset( seller_account, std::to_string( amount ), base,
std::to_string( rate * amount ), quote, 0, false, broadcast );
std::ostringstream amount_to_sell;
std::ostringstream min_to_receive;

uint8_t sell_precision = get_asset(base).precision;
uint8_t recv_precision = get_asset(quote).precision;

amount_to_sell << std::fixed << std::setprecision(sell_precision) << amount;
min_to_receive << std::fixed << std::setprecision(recv_precision) << rate * amount;

return my->sell_asset( seller_account, amount_to_sell.str(), base,
min_to_receive.str(), quote, 0, false, broadcast );
}

signed_transaction wallet_api::buy( string buyer_account,
Expand All @@ -3879,8 +3888,17 @@ signed_transaction wallet_api::buy( string buyer_account,
double amount,
bool broadcast )
{
return my->sell_asset( buyer_account, std::to_string( rate * amount ), quote,
std::to_string( amount ), base, 0, false, broadcast );
std::ostringstream amount_to_buy;
std::ostringstream min_to_receive;

uint8_t buy_precision = get_asset(quote).precision;
uint8_t recv_precision = get_asset(base).precision;

amount_to_buy << std::fixed << std::setprecision(buy_precision) << rate * amount;
min_to_receive << std::fixed << std::setprecision(recv_precision) << amount;

return my->sell_asset( buyer_account, amount_to_buy.str(), quote,
min_to_receive.str(), base, 0, false, broadcast );
}

signed_transaction wallet_api::borrow_asset(string seller_name, string amount_to_sell,
Expand Down