mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-18 13:17:55 +02:00
Merge bitcoin/bitcoin#28113: kernel: Remove UniValue from kernel library
6960c81cbfkernel: Remove Univalue from kernel library (TheCharlatan)10eb3a9faakernel: Split ParseSighashString (TheCharlatan) Pull request description: Besides the build system changes, this is a mostly 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. ACKs for top commit: achow101: ACK6960c81cbftheuni: Re-ACK6960c81cbfstickies-v: re-ACK6960c81cbfTree-SHA512: d92e4cb4e12134c94b517751bd746d39f9b8da528ec3a1c94aaedcce93274a3bae9277832e8a7c0243c13df0397ca70ae7bbb24ede200018c569f8d81103c1da
This commit is contained in:
commit
1ed8a0f8d2
8 changed files with 59 additions and 43 deletions
7
doc/release-notes-28113.md
Normal file
7
doc/release-notes-28113.md
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
RPC Wallet
|
||||||
|
----------
|
||||||
|
|
||||||
|
- The `signrawtransactionwithkey`, `signrawtransactionwithwallet`,
|
||||||
|
`walletprocesspsbt` and `descriptorprocesspsbt` calls now return more
|
||||||
|
specific RPC_INVALID_PARAMETER instead of RPC_PARSE_ERROR if their
|
||||||
|
sighashtype argument is malformed or not a string.
|
||||||
|
|
@ -898,8 +898,8 @@ if BUILD_BITCOIN_KERNEL_LIB
|
||||||
lib_LTLIBRARIES += $(LIBBITCOINKERNEL)
|
lib_LTLIBRARIES += $(LIBBITCOINKERNEL)
|
||||||
|
|
||||||
libbitcoinkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS)
|
libbitcoinkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS)
|
||||||
libbitcoinkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1)
|
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) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
|
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
|
# libbitcoinkernel requires default symbol visibility, explicitly specify that
|
||||||
# here so that things still work even when user configures with
|
# here so that things still work even when user configures with
|
||||||
|
|
|
||||||
|
|
@ -562,6 +562,16 @@ static CAmount AmountFromValue(const UniValue& value)
|
||||||
return amount;
|
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)
|
static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
|
||||||
{
|
{
|
||||||
int nHashType = SIGHASH_ALL;
|
int nHashType = SIGHASH_ALL;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#define BITCOIN_CORE_IO_H
|
#define BITCOIN_CORE_IO_H
|
||||||
|
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
|
#include <util/result.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -45,8 +46,7 @@ bool DecodeHexBlockHeader(CBlockHeader&, const std::string& hex_header);
|
||||||
* @see ParseHashV for an RPC-oriented version of this
|
* @see ParseHashV for an RPC-oriented version of this
|
||||||
*/
|
*/
|
||||||
bool ParseHashStr(const std::string& strHex, uint256& result);
|
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);
|
||||||
int ParseSighashString(const UniValue& sighash);
|
|
||||||
|
|
||||||
// core_write.cpp
|
// core_write.cpp
|
||||||
UniValue ValueFromAmount(const CAmount amount);
|
UniValue ValueFromAmount(const CAmount amount);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <script/sign.h>
|
#include <script/sign.h>
|
||||||
#include <serialize.h>
|
#include <serialize.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
#include <univalue.h>
|
#include <util/result.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
|
|
@ -242,36 +242,21 @@ bool ParseHashStr(const std::string& strHex, uint256& result)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char> ParseHexUV(const UniValue& v, const std::string& strName)
|
util::Result<int> SighashFromStr(const std::string& sighash)
|
||||||
{
|
{
|
||||||
std::string strHex;
|
static std::map<std::string, int> map_sighash_values = {
|
||||||
if (v.isStr())
|
{std::string("DEFAULT"), int(SIGHASH_DEFAULT)},
|
||||||
strHex = v.getValStr();
|
{std::string("ALL"), int(SIGHASH_ALL)},
|
||||||
if (!IsHex(strHex))
|
{std::string("ALL|ANYONECANPAY"), int(SIGHASH_ALL|SIGHASH_ANYONECANPAY)},
|
||||||
throw std::runtime_error(strName + " must be hexadecimal string (not '" + strHex + "')");
|
{std::string("NONE"), int(SIGHASH_NONE)},
|
||||||
return ParseHex(strHex);
|
{std::string("NONE|ANYONECANPAY"), int(SIGHASH_NONE|SIGHASH_ANYONECANPAY)},
|
||||||
}
|
{std::string("SINGLE"), int(SIGHASH_SINGLE)},
|
||||||
|
{std::string("SINGLE|ANYONECANPAY"), int(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY)},
|
||||||
int ParseSighashString(const UniValue& sighash)
|
};
|
||||||
{
|
const auto& it = map_sighash_values.find(sighash);
|
||||||
int hash_type = SIGHASH_DEFAULT;
|
if (it != map_sighash_values.end()) {
|
||||||
if (!sighash.isNull()) {
|
return it->second;
|
||||||
static std::map<std::string, int> map_sighash_values = {
|
} else {
|
||||||
{std::string("DEFAULT"), int(SIGHASH_DEFAULT)},
|
return util::Error{Untranslated(sighash + " is not a valid sighash parameter.")};
|
||||||
{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;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
|
#include <core_io.h>
|
||||||
#include <common/args.h>
|
#include <common/args.h>
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
|
#include <script/interpreter.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <outputtype.h>
|
#include <outputtype.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
|
|
@ -12,6 +14,7 @@
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
|
#include <util/result.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
@ -310,6 +313,21 @@ UniValue DescribeAddress(const CTxDestination& dest)
|
||||||
return std::visit(DescribeAddressVisitor(), dest);
|
return std::visit(DescribeAddressVisitor(), dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ParseSighashString(const UniValue& sighash)
|
||||||
|
{
|
||||||
|
if (sighash.isNull()) {
|
||||||
|
return SIGHASH_DEFAULT;
|
||||||
|
}
|
||||||
|
if (!sighash.isStr()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "sighash needs to be null or string");
|
||||||
|
}
|
||||||
|
const auto result{SighashFromStr(sighash.get_str())};
|
||||||
|
if (!result) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_PARAMETER, util::ErrorString(result).original);
|
||||||
|
}
|
||||||
|
return result.value();
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target)
|
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target)
|
||||||
{
|
{
|
||||||
const int target{value.getInt<int>()};
|
const int target{value.getInt<int>()};
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,9 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vecto
|
||||||
|
|
||||||
UniValue DescribeAddress(const CTxDestination& dest);
|
UniValue DescribeAddress(const CTxDestination& dest);
|
||||||
|
|
||||||
|
/** Parse a sighash string representation and raise an RPC error if it is invalid. */
|
||||||
|
int ParseSighashString(const UniValue& sighash);
|
||||||
|
|
||||||
//! Parse a confirm target option and raise an RPC error if it is invalid.
|
//! Parse a confirm target option and raise an RPC error if it is invalid.
|
||||||
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target);
|
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <chainparams.h>
|
#include <chainparams.h>
|
||||||
#include <core_io.h>
|
|
||||||
#include <rpc/client.h>
|
#include <rpc/client.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
|
|
@ -57,12 +56,6 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue)
|
||||||
(void)ParseHexO(univalue, random_string);
|
(void)ParseHexO(univalue, random_string);
|
||||||
} catch (const UniValue&) {
|
} catch (const UniValue&) {
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
(void)ParseHexUV(univalue, "A");
|
|
||||||
(void)ParseHexUV(univalue, random_string);
|
|
||||||
} catch (const UniValue&) {
|
|
||||||
} catch (const std::runtime_error&) {
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
(void)ParseHexV(univalue, "A");
|
(void)ParseHexV(univalue, "A");
|
||||||
} catch (const UniValue&) {
|
} catch (const UniValue&) {
|
||||||
|
|
@ -75,7 +68,7 @@ FUZZ_TARGET(parse_univalue, .init = initialize_parse_univalue)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
(void)ParseSighashString(univalue);
|
(void)ParseSighashString(univalue);
|
||||||
} catch (const std::runtime_error&) {
|
} catch (const UniValue&) {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
(void)AmountFromValue(univalue);
|
(void)AmountFromValue(univalue);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue