Bitcoin Core 28.99.0
P2P Digital Currency
parse_univalue.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <chainparams.h>
6#include <rpc/client.h>
7#include <rpc/util.h>
8#include <test/fuzz/fuzz.h>
9#include <util/chaintype.h>
10
11#include <limits>
12#include <string>
13
15{
17}
18
20{
21 const std::string random_string(buffer.begin(), buffer.end());
22 bool valid = true;
23 const UniValue univalue = [&] {
24 UniValue uv;
25 if (!uv.read(random_string)) valid = false;
26 return valid ? uv : UniValue{};
27 }();
28 if (!valid) {
29 return;
30 }
31 try {
32 (void)ParseHashO(univalue, "A");
33 } catch (const UniValue&) {
34 } catch (const std::runtime_error&) {
35 }
36 try {
37 (void)ParseHashO(univalue, random_string);
38 } catch (const UniValue&) {
39 } catch (const std::runtime_error&) {
40 }
41 try {
42 (void)ParseHashV(univalue, "A");
43 } catch (const UniValue&) {
44 } catch (const std::runtime_error&) {
45 }
46 try {
47 (void)ParseHashV(univalue, random_string);
48 } catch (const UniValue&) {
49 } catch (const std::runtime_error&) {
50 }
51 try {
52 (void)ParseHexO(univalue, "A");
53 } catch (const UniValue&) {
54 }
55 try {
56 (void)ParseHexO(univalue, random_string);
57 } catch (const UniValue&) {
58 }
59 try {
60 (void)ParseHexV(univalue, "A");
61 } catch (const UniValue&) {
62 } catch (const std::runtime_error&) {
63 }
64 try {
65 (void)ParseHexV(univalue, random_string);
66 } catch (const UniValue&) {
67 } catch (const std::runtime_error&) {
68 }
69 try {
70 if (univalue.isNull() || univalue.isStr()) (void)ParseSighashString(univalue);
71 } catch (const UniValue&) {
72 }
73 try {
74 (void)AmountFromValue(univalue);
75 } catch (const UniValue&) {
76 } catch (const std::runtime_error&) {
77 }
78 try {
79 FlatSigningProvider provider;
80 if (buffer.size() < 10'000) (void)EvalDescriptorStringOrObject(univalue, provider);
81 } catch (const UniValue&) {
82 } catch (const std::runtime_error&) {
83 }
84 try {
85 (void)ParseConfirmTarget(univalue, std::numeric_limits<unsigned int>::max());
86 } catch (const UniValue&) {
87 } catch (const std::runtime_error&) {
88 }
89 try {
90 (void)ParseDescriptorRange(univalue);
91 } catch (const UniValue&) {
92 } catch (const std::runtime_error&) {
93 }
94}
static CAmount AmountFromValue(const UniValue &value)
Definition: bitcoin-tx.cpp:561
void SelectParams(const ChainType chain)
Sets the params returned by Params() to those for the given chain type.
bool isNull() const
Definition: univalue.h:79
bool read(std::string_view raw)
bool isStr() const
Definition: univalue.h:83
void initialize_parse_univalue()
FUZZ_TARGET(parse_univalue,.init=initialize_parse_univalue)
std::vector< CScript > EvalDescriptorStringOrObject(const UniValue &scanobject, FlatSigningProvider &provider, const bool expand_priv)
Evaluate a descriptor given as a string, or as a {"desc":...,"range":...} object, with default range ...
Definition: util.cpp:1345
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
Definition: util.cpp:1329
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
Definition: util.cpp:131
int ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
Definition: util.cpp:379
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
Definition: util.cpp:140
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
Definition: util.cpp:127
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
Definition: util.cpp:391
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
Definition: util.cpp:118