diff options
Diffstat (limited to 'src/util/moneystr.cpp')
-rw-r--r-- | src/util/moneystr.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp index 3f9ce7dce4..d72164f3bf 100644 --- a/src/util/moneystr.cpp +++ b/src/util/moneystr.cpp @@ -5,10 +5,13 @@ #include <util/moneystr.h> +#include <amount.h> #include <tinyformat.h> #include <util/strencodings.h> #include <util/string.h> +#include <optional> + std::string FormatMoney(const CAmount n) { // Note: not using straight sprintf here because we do NOT want @@ -35,14 +38,14 @@ std::string FormatMoney(const CAmount n) } -bool ParseMoney(const std::string& money_string, CAmount& nRet) +std::optional<CAmount> ParseMoney(const std::string& money_string) { if (!ValidAsCString(money_string)) { - return false; + return std::nullopt; } const std::string str = TrimString(money_string); if (str.empty()) { - return false; + return std::nullopt; } std::string strWhole; @@ -62,21 +65,21 @@ bool ParseMoney(const std::string& money_string, CAmount& nRet) break; } if (IsSpace(*p)) - return false; + return std::nullopt; if (!IsDigit(*p)) - return false; + return std::nullopt; strWhole.insert(strWhole.end(), *p); } if (*p) { - return false; + return std::nullopt; } if (strWhole.size() > 10) // guard against 63 bit overflow - return false; + return std::nullopt; if (nUnits < 0 || nUnits > COIN) - return false; + return std::nullopt; int64_t nWhole = atoi64(strWhole); - CAmount nValue = nWhole*COIN + nUnits; - nRet = nValue; - return true; + CAmount value = nWhole * COIN + nUnits; + + return value; } |