Seems odd to silently accept arbitrary strings that don't even represent integral values.
Fix that.
Seems odd to silently accept arbitrary strings that don't even represent integral values.
Fix that.
Concept ACK
Code review ACK fa334a8765a88f18e7a63d908b672b27343d8219.
My only suggestion is to create a helper to avoid duplicate code, like:
template <typename T>
T ParseIntegral(const std::string& str, const std::string& error_msg)
{
const auto parsed{ToIntegral<T>(TrimString(str))};
if (!parsed.has_value()) {
throw std::runtime_error(error_msg + " '" + str + "'");
}
return parsed.value();
}
Thanks, done
Code review ACK fa6f29de516c7af5206b91b59ada466032329250.
cr ACK fa6f29de516c7af5206b91b59ada466032329250
234 | @@ -235,6 +235,16 @@ static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInId 235 | } 236 | } 237 | 238 | +template <typename T> 239 | +static T TrimAndParse(const std::string& int_str, const std::string& err) 240 | +{ 241 | + const auto parsed{ToIntegral<T>(TrimString(int_str))}; 242 | + if (!parsed.has_value()) { 243 | + throw std::runtime_error(err + " '" + int_str + "'");
It is very un-us to throw an exception for a parse error here. But as this is local to bitcoin-tx where this is explicitly caught I think it's acceptable.
Code review ACK fa6f29de516c7af5206b91b59ada466032329250