mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
kernel: Split ParseSighashString
This split is done in preparation for the next commit where the dependency on UniValue in the kernel library is removed.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user