| 154 | |
| 155 | |
| 156 | bool BitcoinUnits::parse(int unit, const QString &value, CAmount *val_out) |
| 157 | { |
| 158 | if(!valid(unit) || value.isEmpty()) |
| 159 | return false; // Refuse to parse invalid unit or empty string |
| 160 | int num_decimals = decimals(unit); |
| 161 | |
| 162 | // Ignore spaces and thin spaces when parsing |
| 163 | QStringList parts = removeSpaces(value).split("."); |
| 164 | |
| 165 | if(parts.size() > 2) |
| 166 | { |
| 167 | return false; // More than one dot |
| 168 | } |
| 169 | QString whole = parts[0]; |
| 170 | QString decimals; |
| 171 | |
| 172 | if(parts.size() > 1) |
| 173 | { |
| 174 | decimals = parts[1]; |
| 175 | } |
| 176 | if(decimals.size() > num_decimals) |
| 177 | { |
| 178 | return false; // Exceeds max precision |
| 179 | } |
| 180 | bool ok = false; |
| 181 | QString str = whole + decimals.leftJustified(num_decimals, '0'); |
| 182 | |
| 183 | if(str.size() > 18) |
| 184 | { |
| 185 | return false; // Longer numbers will exceed 63 bits |
| 186 | } |
| 187 | CAmount retvalue(str.toLongLong(&ok)); |
| 188 | if(val_out) |
| 189 | { |
| 190 | *val_out = retvalue; |
| 191 | } |
| 192 | return ok; |
| 193 | } |
| 194 | |
| 195 | QString BitcoinUnits::getAmountColumnTitle(int unit) |
| 196 | { |