aboutsummaryrefslogtreecommitdiff
path: root/src/univalue/lib/univalue.cpp
diff options
context:
space:
mode:
authorMacroFake <falke.marco@gmail.com>2022-07-06 11:46:41 +0200
committerMacroFake <falke.marco@gmail.com>2022-07-13 18:05:39 +0200
commitfa277cd55dd105018e7d1220b4c3d96779e6b0f4 (patch)
tree7b07f6268287e14da3bd5184f40b7975a9459582 /src/univalue/lib/univalue.cpp
parentccccc17b91698aa09ac85f7efea298f3938594ad (diff)
downloadbitcoin-fa277cd55dd105018e7d1220b4c3d96779e6b0f4.tar.xz
univalue: Throw exception on invalid pushes over silent ignore
Diffstat (limited to 'src/univalue/lib/univalue.cpp')
-rw-r--r--src/univalue/lib/univalue.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/src/univalue/lib/univalue.cpp b/src/univalue/lib/univalue.cpp
index 3553995c28..ac6f31a5a9 100644
--- a/src/univalue/lib/univalue.cpp
+++ b/src/univalue/lib/univalue.cpp
@@ -108,53 +108,45 @@ bool UniValue::setObject()
return true;
}
-bool UniValue::push_back(const UniValue& val_)
+void UniValue::push_back(const UniValue& val_)
{
- if (typ != VARR)
- return false;
+ if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"};
values.push_back(val_);
- return true;
}
-bool UniValue::push_backV(const std::vector<UniValue>& vec)
+void UniValue::push_backV(const std::vector<UniValue>& vec)
{
- if (typ != VARR)
- return false;
+ if (typ != VARR) throw std::runtime_error{"JSON value is not an array as expected"};
values.insert(values.end(), vec.begin(), vec.end());
-
- return true;
}
void UniValue::__pushKV(const std::string& key, const UniValue& val_)
{
+ if (typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"};
+
keys.push_back(key);
values.push_back(val_);
}
-bool UniValue::pushKV(const std::string& key, const UniValue& val_)
+void UniValue::pushKV(const std::string& key, const UniValue& val_)
{
- if (typ != VOBJ)
- return false;
+ if (typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"};
size_t idx;
if (findKey(key, idx))
values[idx] = val_;
else
__pushKV(key, val_);
- return true;
}
-bool UniValue::pushKVs(const UniValue& obj)
+void UniValue::pushKVs(const UniValue& obj)
{
- if (typ != VOBJ || obj.typ != VOBJ)
- return false;
+ if (typ != VOBJ || obj.typ != VOBJ) throw std::runtime_error{"JSON value is not an object as expected"};
for (size_t i = 0; i < obj.keys.size(); i++)
__pushKV(obj.keys[i], obj.values.at(i));
-
- return true;
}
void UniValue::getObjMap(std::map<std::string,UniValue>& kv) const