aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-07-25 18:03:03 -0400
committerAndrew Chow <github@achow101.com>2023-07-25 18:13:16 -0400
commit1ed8a0f8d26439820554213f8ffead2d5d8ea864 (patch)
treef4bf4547573ecafcb644ea983521bdec578ee817 /src/rpc
parente35fb7bc48d360585b80d0c7f89ac5087c1d405e (diff)
parent6960c81cbfa6208d4098353e53b313e13a21cb49 (diff)
downloadbitcoin-1ed8a0f8d26439820554213f8ffead2d5d8ea864.tar.xz
Merge bitcoin/bitcoin#28113: kernel: Remove UniValue from kernel library
6960c81cbfa6208d4098353e53b313e13a21cb49 kernel: Remove Univalue from kernel library (TheCharlatan) 10eb3a9faa977371facacee937b2e6dc26f008e0 kernel: 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: ACK 6960c81cbfa6208d4098353e53b313e13a21cb49 theuni: Re-ACK 6960c81cbfa6208d4098353e53b313e13a21cb49 stickies-v: re-ACK https://github.com/bitcoin/bitcoin/commit/6960c81cbfa6208d4098353e53b313e13a21cb49 Tree-SHA512: d92e4cb4e12134c94b517751bd746d39f9b8da528ec3a1c94aaedcce93274a3bae9277832e8a7c0243c13df0397ca70ae7bbb24ede200018c569f8d81103c1da
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/util.cpp18
-rw-r--r--src/rpc/util.h3
2 files changed, 21 insertions, 0 deletions
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index 19e14f88df..377181dd81 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -3,8 +3,10 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <clientversion.h>
+#include <core_io.h>
#include <common/args.h>
#include <consensus/amount.h>
+#include <script/interpreter.h>
#include <key_io.h>
#include <outputtype.h>
#include <rpc/util.h>
@@ -12,6 +14,7 @@
#include <script/signingprovider.h>
#include <tinyformat.h>
#include <util/check.h>
+#include <util/result.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/translation.h>
@@ -310,6 +313,21 @@ UniValue DescribeAddress(const CTxDestination& 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)
{
const int target{value.getInt<int>()};
diff --git a/src/rpc/util.h b/src/rpc/util.h
index 4cba5a9818..02d26f1ab7 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -100,6 +100,9 @@ CTxDestination AddAndGetMultisigDestination(const int required, const std::vecto
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.
unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target);