32{
33 try {
35
36
37 auto space_pos =
s.find(
' ');
38 SYS_ASSERT((space_pos != string::npos), asset_type_exception,
"Asset's amount and symbol should be separated with space");
39 auto symbol_str =
fc::trim(
s.substr(space_pos + 1));
40 auto amount_str =
s.substr(0, space_pos);
41
42
43 auto dot_pos = amount_str.find('.');
44 if (dot_pos != string::npos) {
45 SYS_ASSERT((dot_pos != amount_str.size() - 1), asset_type_exception,
"Missing decimal fraction after decimal point");
46 }
47
48
49 string precision_digit_str;
50 if (dot_pos != string::npos) {
52 } else {
53 precision_digit_str = "0";
54 }
55
56 string symbol_part = precision_digit_str + ',' + symbol_str;
58
59
60 safe<int64_t> int_part, fract_part;
61 if (dot_pos != string::npos) {
63 fract_part =
fc::to_int64(amount_str.substr(dot_pos + 1));
64 if (amount_str[0] == '-') fract_part *= -1;
65 } else {
67 }
68
69 safe<int64_t> amount = int_part;
70 amount *= safe<int64_t>(sym.precision());
71 amount += fract_part;
72
73 return asset(amount.value, sym);
74 }
76}
static symbol from_string(const string &from)
#define FC_CAPTURE_LOG_AND_RETHROW(...)
fc::string to_string(double)
fc::string trim(const fc::string &)
int64_t to_int64(const fc::string &)
asset(share_type a=0, symbol id=symbol(CORE_SYMBOL))