aboutsummaryrefslogtreecommitdiff
path: root/src/core_read.cpp
diff options
context:
space:
mode:
authorTheCharlatan <seb.kung@gmail.com>2023-07-21 13:47:43 +0200
committerTheCharlatan <seb.kung@gmail.com>2023-07-25 17:40:02 +0200
commit10eb3a9faa977371facacee937b2e6dc26f008e0 (patch)
tree1859279e30a7692bcb24f23ddca58b923c791ced /src/core_read.cpp
parent4a1aae67498ff8e9aa7ce97fef70b973c604f892 (diff)
kernel: Split ParseSighashString
This split is done in preparation for the next commit where the dependency on UniValue in the kernel library is removed.
Diffstat (limited to 'src/core_read.cpp')
-rw-r--r--src/core_read.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/core_read.cpp b/src/core_read.cpp
index 84cd559b7f..c40f04a824 100644
--- a/src/core_read.cpp
+++ b/src/core_read.cpp
@@ -11,6 +11,7 @@
#include <serialize.h>
#include <streams.h>
#include <univalue.h>
+#include <util/result.h>
#include <util/strencodings.h>
#include <version.h>
@@ -252,26 +253,21 @@ std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strN
return ParseHex(strHex);
}
-int ParseSighashString(const UniValue& sighash)
+util::Result<int> SighashFromStr(const std::string& sighash)
{
- int hash_type = SIGHASH_DEFAULT;
- if (!sighash.isNull()) {
- static std::map<std::string, int> map_sighash_values = {
- {std::string("DEFAULT"), int(SIGHASH_DEFAULT)},
- {std::string("ALL"), int(SIGHASH_ALL)},
- {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
- {std::string("NONE"), int(SIGHASH_NONE)},
- {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
- {std::string("SINGLE"), int(SIGHASH_SINGLE)},
- {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
- };
- const std::string& strHashType = sighash.get_str();
- const auto& it = map_sighash_values.find(strHashType);
- if (it != map_sighash_values.end()) {
- hash_type = it->second;
- } else {
- throw std::runtime_error(strHashType + " is not a valid sighash parameter.");
- }
+ static std::map<std::string, int> map_sighash_values = {
+ {std::string("DEFAULT"), int(SIGHASH_DEFAULT)},
+ {std::string("ALL"), int(SIGHASH_ALL)},
+ {std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
+ {std::string("NONE"), int(SIGHASH_NONE)},
+ {std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
+ {std::string("SINGLE"), int(SIGHASH_SINGLE)},
+ {std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
+ };
+ const auto& it = map_sighash_values.find(sighash);
+ if (it != map_sighash_values.end()) {
+ return it->second;
+ } else {
+ return util::Error{Untranslated(sighash + " is not a valid sighash parameter.")};
}
- return hash_type;
}