aboutsummaryrefslogtreecommitdiff
path: root/src/univalue
diff options
context:
space:
mode:
authorRyan Ofsky <ryan@ofsky.org>2022-09-30 15:05:35 +0200
committerRyan Ofsky <ryan@ofsky.org>2022-12-09 10:03:26 -0500
commit293849a26088a16f6187dfdc36bef1d4d83ebb9d (patch)
treeb49d1b47a61a95a388098d519764aa748ef5a64b /src/univalue
parent16624e6ff3af4429e571f7a606bbbcac336e067a (diff)
univalue: Remove confusing getBool method
Drop UniValue::getBool method because it is easy to confuse with the UniValue::get_bool method, and could potentially cause bugs. Unlike get_bool, getBool doesn't ensure that the value is a boolean and returns false for all integer, string, array, and object values instead of throwing an exceptions. The getBool method is also redundant because it is an alias for isTrue. There were only 5 getBool() calls in the codebase, so this commit replaces them with isTrue() or get_bool() calls as appropriate. These changes were originally made by MarcoFalke in https://github.com/bitcoin/bitcoin/pull/26213 but were dropped to limit the scope of that PR. Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz>
Diffstat (limited to 'src/univalue')
-rw-r--r--src/univalue/include/univalue.h1
-rw-r--r--src/univalue/lib/univalue_get.cpp2
-rw-r--r--src/univalue/test/object.cpp4
3 files changed, 3 insertions, 4 deletions
diff --git a/src/univalue/include/univalue.h b/src/univalue/include/univalue.h
index 1af7df079e..16853260b8 100644
--- a/src/univalue/include/univalue.h
+++ b/src/univalue/include/univalue.h
@@ -66,7 +66,6 @@ public:
size_t size() const { return values.size(); }
- bool getBool() const { return isTrue(); }
void getObjMap(std::map<std::string,UniValue>& kv) const;
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes) const;
const UniValue& operator[](const std::string& key) const;
diff --git a/src/univalue/lib/univalue_get.cpp b/src/univalue/lib/univalue_get.cpp
index 5c58f388dd..037449ca08 100644
--- a/src/univalue/lib/univalue_get.cpp
+++ b/src/univalue/lib/univalue_get.cpp
@@ -60,7 +60,7 @@ const std::vector<UniValue>& UniValue::getValues() const
bool UniValue::get_bool() const
{
checkType(VBOOL);
- return getBool();
+ return isTrue();
}
const std::string& UniValue::get_str() const
diff --git a/src/univalue/test/object.cpp b/src/univalue/test/object.cpp
index 65e82543e4..eeaadae3e2 100644
--- a/src/univalue/test/object.cpp
+++ b/src/univalue/test/object.cpp
@@ -193,13 +193,13 @@ void univalue_set()
BOOST_CHECK_EQUAL(v.isBool(), true);
BOOST_CHECK_EQUAL(v.isTrue(), false);
BOOST_CHECK_EQUAL(v.isFalse(), true);
- BOOST_CHECK_EQUAL(v.getBool(), false);
+ BOOST_CHECK_EQUAL(v.get_bool(), false);
v.setBool(true);
BOOST_CHECK_EQUAL(v.isBool(), true);
BOOST_CHECK_EQUAL(v.isTrue(), true);
BOOST_CHECK_EQUAL(v.isFalse(), false);
- BOOST_CHECK_EQUAL(v.getBool(), true);
+ BOOST_CHECK_EQUAL(v.get_bool(), true);
BOOST_CHECK_THROW(v.setNumStr("zombocom"), std::runtime_error);