2 #include <boost/rational.hpp>
3 #include <boost/multiprecision/cpp_int.hpp>
19 void asset::_check_symbol()
22 "Invalid asset symbol received. ${1} not either ${2} or ${3}.",
26 void asset::_set_decimals(uint8_t d)
29 auto a = (
char*)&_symbol;
35 auto a = (
const char*)&_symbol;
36 uint8_t
result = uint8_t(a[0]);
43 auto a = (
const char*)&_symbol;
50 static int64_t table[] = { 1,
75 auto fract =
amount.value % prec;
80 result +=
"." + fc::to_string(prec + fract).erase(0, 1);
89 std::string s = fc::trim(from);
90 auto space_pos = s.find(
" ");
91 auto dot_pos = s.find(
".");
93 FC_ASSERT(space_pos != std::string::npos);
96 result._symbol = uint64_t(0);
97 auto sy = (
char*)&
result._symbol;
99 if (dot_pos != std::string::npos)
101 FC_ASSERT(space_pos > dot_pos);
103 auto intpart = s.substr(0, dot_pos);
104 auto fractpart =
"1" + s.substr(dot_pos + 1, space_pos - dot_pos - 1);
105 result._set_decimals(fractpart.size() - 1);
107 result.amount = fc::to_int64(intpart);
109 result.amount.value += fc::to_int64(fractpart);
114 auto intpart = s.substr(0, space_pos);
115 result.amount = fc::to_int64(intpart);
118 auto symbol = s.substr(space_pos + 1);
119 size_t symbol_size =
symbol.size();
123 FC_ASSERT(symbol_size <= 6);
124 memcpy(sy + 1,
symbol.c_str(), symbol_size);
130 FC_CAPTURE_AND_RETHROW((from))
boost::multiprecision::int128_t int128_t
asset_symbol_type symbol() const
std::string to_string() const
int64_t precision() const
static asset from_string(const std::string &from)
std::string symbol_name() const