diff options
author | MacroFake <falke.marco@gmail.com> | 2022-07-29 15:23:04 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-07-29 15:24:42 +0200 |
commit | fa7bef2e80c9c290b3e97114cfa7afdea5cbd53c (patch) | |
tree | 77d1892a411678c4b943110d35384c27cb9e4705 /src/univalue/lib/univalue.cpp | |
parent | 7f79746bf046d0028bb68f265804b9774dec2acb (diff) | |
download | bitcoin-fa7bef2e80c9c290b3e97114cfa7afdea5cbd53c.tar.xz |
univalue: Remove unused and confusing set*() return value
Diffstat (limited to 'src/univalue/lib/univalue.cpp')
-rw-r--r-- | src/univalue/lib/univalue.cpp | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp index 051bc8eba6..55e777b8ae 100644 --- a/src/univalue/lib/univalue.cpp +++ b/src/univalue/lib/univalue.cpp @@ -23,19 +23,17 @@ void UniValue::clear() values.clear(); } -bool UniValue::setNull() +void UniValue::setNull() { clear(); - return true; } -bool UniValue::setBool(bool val_) +void UniValue::setBool(bool val_) { clear(); typ = VBOOL; if (val_) val = "1"; - return true; } static bool validNumStr(const std::string& s) @@ -46,18 +44,18 @@ static bool validNumStr(const std::string& s) return (tt == JTOK_NUMBER); } -bool UniValue::setNumStr(const std::string& val_) +void UniValue::setNumStr(const std::string& val_) { - if (!validNumStr(val_)) - return false; + if (!validNumStr(val_)) { + throw std::runtime_error{"The string '" + val_ + "' is not a valid JSON number"}; + } clear(); typ = VNUM; val = val_; - return true; } -bool UniValue::setInt(uint64_t val_) +void UniValue::setInt(uint64_t val_) { std::ostringstream oss; @@ -66,7 +64,7 @@ bool UniValue::setInt(uint64_t val_) return setNumStr(oss.str()); } -bool UniValue::setInt(int64_t val_) +void UniValue::setInt(int64_t val_) { std::ostringstream oss; @@ -75,37 +73,32 @@ bool UniValue::setInt(int64_t val_) return setNumStr(oss.str()); } -bool UniValue::setFloat(double val_) +void UniValue::setFloat(double val_) { std::ostringstream oss; oss << std::setprecision(16) << val_; - bool ret = setNumStr(oss.str()); - typ = VNUM; - return ret; + return setNumStr(oss.str()); } -bool UniValue::setStr(const std::string& val_) +void UniValue::setStr(const std::string& val_) { clear(); typ = VSTR; val = val_; - return true; } -bool UniValue::setArray() +void UniValue::setArray() { clear(); typ = VARR; - return true; } -bool UniValue::setObject() +void UniValue::setObject() { clear(); typ = VOBJ; - return true; } void UniValue::push_back(const UniValue& val_) |