| 221 | } |
| 222 | |
| 223 | bool BitcoinUnits::parse(int unit, const QString& value, CAmount* val_out) |
| 224 | { |
| 225 | if (!valid(unit) || value.isEmpty()) |
| 226 | return false; // Refuse to parse invalid unit or empty string |
| 227 | int num_decimals = decimals(unit); |
| 228 | |
| 229 | // Ignore spaces and thin spaces when parsing |
| 230 | QStringList parts = removeSpaces(value).split("."); |
| 231 | |
| 232 | if (parts.size() > 2) { |
| 233 | return false; // More than one dot |
| 234 | } |
| 235 | QString whole = parts[0]; |
| 236 | QString decimals; |
| 237 | |
| 238 | if (parts.size() > 1) { |
| 239 | decimals = parts[1]; |
| 240 | } |
| 241 | if (decimals.size() > num_decimals) { |
| 242 | return false; // Exceeds max precision |
| 243 | } |
| 244 | bool ok = false; |
| 245 | QString str = whole + decimals.leftJustified(num_decimals, '0'); |
| 246 | |
| 247 | if (str.size() > 18) { |
| 248 | return false; // Longer numbers will exceed 63 bits |
| 249 | } |
| 250 | CAmount retvalue(str.toLongLong(&ok)); |
| 251 | if(val_out) |
| 252 | { |
| 253 | *val_out = retvalue; |
| 254 | } |
| 255 | return ok; |
| 256 | } |
| 257 | |
| 258 | bool BitcoinUnits::parseToken(int decimal_units, const QString &value, int256_t *val_out) |
| 259 | { |