-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kernel: Remove UniValue from kernel library
Besides the build system changes, this is a move-only change for moving the few UniValue-related functions out of kernel files. UniValue is not required by any of the kernel components and a JSON library should not need to be part of a consensus library.
- Loading branch information
1 parent
4a1aae6
commit 03e06e5
Showing
10 changed files
with
73 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2023 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <script/interpreter.h> | ||
#include <univalue.h> | ||
#include <util/strencodings.h> | ||
|
||
#include <map> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName) | ||
{ | ||
std::string strHex; | ||
if (v.isStr()) | ||
strHex = v.getValStr(); | ||
if (!IsHex(strHex)) | ||
throw std::runtime_error(strName + " must be hexadecimal string (not '" + strHex + "')"); | ||
return ParseHex(strHex); | ||
} | ||
|
||
int ParseSighashString(const UniValue& 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."); | ||
} | ||
} | ||
return hash_type; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright (c) 2023 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#ifndef BITCOIN_COMMON_UNIVALUE_HELPERS_H | ||
#define BITCOIN_COMMON_UNIVALUE_HELPERS_H | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class UniValue; | ||
|
||
std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName); | ||
|
||
int ParseSighashString(const UniValue& sighash); | ||
|
||
#endif // BITCOIN_COMMON_UNIVALUE_HELPERS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters