Skip to content

Commit

Permalink
kernel: Remove Univalue from kernel library
Browse files Browse the repository at this point in the history
It is not required by any of the kernel components.
A JSON library should not need to be part of a consensus library.
  • Loading branch information
TheCharlatan committed Jul 25, 2023
1 parent 10eb3a9 commit 6960c81
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,8 @@ if BUILD_BITCOIN_KERNEL_LIB
lib_LTLIBRARIES += $(LIBBITCOINKERNEL)

libbitcoinkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS)
libbitcoinkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1)
libbitcoinkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
libbitcoinkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1)
libbitcoinkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS)

# libbitcoinkernel requires default symbol visibility, explicitly specify that
# here so that things still work even when user configures with
Expand Down
10 changes: 10 additions & 0 deletions src/bitcoin-tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,16 @@ static CAmount AmountFromValue(const UniValue& value)
return amount;
}

static 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);
}

static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
{
int nHashType = SIGHASH_ALL;
Expand Down
1 change: 0 additions & 1 deletion src/core_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header);
* @see ParseHashV for an RPC-oriented version of this
*/
bool ParseHashStr(const std::string& strHex, uint256& result);
std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName);
[[nodiscard]] util::Result<int> SighashFromStr(const std::string& sighash);

// core_write.cpp
Expand Down
11 changes: 0 additions & 11 deletions src/core_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <script/sign.h>
#include <serialize.h>
#include <streams.h>
#include <univalue.h>
#include <util/result.h>
#include <util/strencodings.h>
#include <version.h>
Expand Down Expand Up @@ -243,16 +242,6 @@ bool ParseHashStr(const std::string& strHex, uint256& result)
return true;
}

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);
}

util::Result<int> SighashFromStr(const std::string& sighash)
{
static std::map<std::string, int> map_sighash_values = {
Expand Down
7 changes: 0 additions & 7 deletions src/test/fuzz/parse_univalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <chainparams.h>
#include <core_io.h>
#include <rpc/client.h>
#include <rpc/util.h>
#include <test/fuzz/fuzz.h>
Expand Down Expand Up @@ -57,12 +56,6 @@ FUZZ_TARGET_INIT(parse_univalue, initialize_parse_univalue)
(void)ParseHexO(univalue, random_string);
} catch (const UniValue&) {
}
try {
(void)ParseHexUV(univalue, "A");
(void)ParseHexUV(univalue, random_string);
} catch (const UniValue&) {
} catch (const std::runtime_error&) {
}
try {
(void)ParseHexV(univalue, "A");
} catch (const UniValue&) {
Expand Down

0 comments on commit 6960c81

Please sign in to comment.