50const std::string
EXAMPLE_ADDRESS[2] = {
"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl",
"bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"};
54 std::vector<std::string>
ret;
55 using U = std::underlying_type_t<TxoutType>;
63 const std::map<std::string, UniValueType>& typesExpected,
67 for (
const auto&
t : typesExpected) {
69 if (!fAllowNull && v.
isNull())
72 if (!(
t.second.typeAny || v.
type() ==
t.second.type || (fAllowNull && v.
isNull())))
78 for (
const std::string&
k : o.
getKeys())
80 if (!typesExpected.contains(
k))
82 std::string err =
strprintf(
"Unexpected key %s",
k);
101 return default_verbosity;
125 const std::string& strHex(v.
get_str());
127 if (
auto expected_len{
uint256::size() * 2}; strHex.length() != expected_len) {
157std::string ShellQuote(
const std::string&
s)
160 result.reserve(
s.size() * 2);
161 for (
const char ch:
s) {
168 return "'" + result +
"'";
176std::string ShellQuoteIfNeeded(
const std::string&
s)
178 for (
const char ch:
s) {
179 if (ch ==
' ' || ch ==
'\'' || ch ==
'"') {
180 return ShellQuote(
s);
191 return "> bitcoin-cli " + methodname +
" " +
args +
"\n";
196 std::string result =
"> bitcoin-cli -named " + methodname;
197 for (
const auto& argpair:
args) {
198 const auto& value = argpair.second.isStr()
199 ? argpair.second.get_str()
200 : argpair.second.write();
201 result +=
" " + argpair.first +
"=" + ShellQuoteIfNeeded(value);
209 return "> curl --user myusername --data-binary '{\"jsonrpc\": \"2.0\", \"id\": \"curltest\", "
210 "\"method\": \"" + methodname +
"\", \"params\": [" +
args +
"]}' -H 'content-type: application/json' http://127.0.0.1:8332/\n";
216 for (
const auto& param:
args) {
217 params.
pushKV(param.first, param.second);
220 return "> curl --user myusername --data-binary '{\"jsonrpc\": \"2.0\", \"id\": \"curltest\", "
221 "\"method\": \"" + methodname +
"\", \"params\": " + params.
write() +
"}' -H 'content-type: application/json' http://127.0.0.1:8332/\n";
227 if (!
IsHex(hex_in)) {
230 if (hex_in.length() != 66 && hex_in.length() != 130) {
247 if ((
int)pubkeys.size() < required) {
258 if (!
pk.IsCompressed()) {
292 obj.
pushKV(
"isscript",
false);
293 obj.
pushKV(
"iswitness",
false);
300 obj.
pushKV(
"isscript",
true);
301 obj.
pushKV(
"iswitness",
false);
308 obj.
pushKV(
"isscript",
false);
309 obj.
pushKV(
"iswitness",
true);
310 obj.
pushKV(
"witness_version", 0);
318 obj.
pushKV(
"isscript",
true);
319 obj.
pushKV(
"iswitness",
true);
320 obj.
pushKV(
"witness_version", 0);
328 obj.
pushKV(
"isscript",
true);
329 obj.
pushKV(
"iswitness",
true);
330 obj.
pushKV(
"witness_version", 1);
338 obj.
pushKV(
"isscript",
true);
339 obj.
pushKV(
"iswitness",
true);
346 obj.
pushKV(
"iswitness",
true);
347 obj.
pushKV(
"witness_version",
id.GetWitnessVersion());
348 obj.
pushKV(
"witness_program",
HexStr(
id.GetWitnessProgram()));
372 return result.value();
377 const int target{value.
getInt<
int>()};
378 const unsigned int unsigned_target{
static_cast<unsigned int>(target)};
379 if (target < 1 || unsigned_target > max_target) {
382 return unsigned_target;
388 case PSBTError::UNSUPPORTED:
390 case PSBTError::SIGHASH_MISMATCH:
400 case TransactionError::MEMPOOL_REJECTED:
402 case TransactionError::ALREADY_IN_UTXO_SET:
404 case TransactionError::PRIVATE_BROADCAST_FULL:
418 if (err_string.length() > 0) {
430 Section(
const std::string& left,
const std::string& right)
456 const auto indent = std::string(current_indent,
' ');
457 const auto indent_next = std::string(current_indent + 2,
' ');
469 if (is_top_level_arg)
return;
483 PushSection({indent + (push_name ?
"\"" + arg.
GetName() +
"\": " :
"") +
"{", right});
484 for (
const auto& arg_inner : arg.
m_inner) {
490 PushSection({indent +
"}" + (is_top_level_arg ?
"" :
","),
""});
495 left += push_name ?
"\"" + arg.
GetName() +
"\": " :
"";
499 for (
const auto& arg_inner : arg.
m_inner) {
503 PushSection({indent +
"]" + (is_top_level_arg ?
"" :
","),
""});
520 if (
s.m_right.empty()) {
526 std::string left =
s.m_left;
527 left.resize(pad,
' ');
533 size_t new_line_pos =
s.m_right.find_first_of(
'\n');
535 right +=
s.m_right.substr(begin, new_line_pos - begin);
536 if (new_line_pos == std::string::npos) {
539 right +=
"\n" + std::string(pad,
' ');
540 begin =
s.m_right.find_first_not_of(
' ', new_line_pos + 1);
541 if (begin == std::string::npos) {
544 new_line_pos =
s.m_right.find_first_of(
'\n', begin + 1);
558 m_fun{
std::move(fun)},
559 m_description{
std::move(description)},
561 m_results{
std::move(results)},
562 m_examples{
std::move(examples)}
567 enum ParamType { POSITIONAL = 1, NAMED = 2, NAMED_ONLY = 4 };
568 std::map<std::string, int> param_names;
570 for (
const auto& arg :
m_args) {
571 std::vector<std::string> names =
SplitString(arg.m_names,
'|');
573 for (
const std::string&
name : names) {
574 auto& param_type = param_names[
name];
577 param_type |= POSITIONAL;
580 for (
const auto& inner : arg.m_inner) {
581 std::vector<std::string> inner_names =
SplitString(inner.m_names,
'|');
582 for (
const std::string& inner_name : inner_names) {
583 auto& param_type = param_names[inner_name];
584 CHECK_NONFATAL(!(param_type & POSITIONAL) || inner.m_opts.also_positional);
587 param_type |= inner.m_opts.also_positional ? NAMED : NAMED_ONLY;
592 if (arg.m_fallback.index() == 2) {
595 switch (std::get<RPCArg::Default>(arg.m_fallback).getType()) {
626 r.ToSections(sections);
630 if (r.m_cond.empty()) {
631 result +=
"\nResult:\n";
633 result +=
"\nResult (" + r.m_cond +
"):\n";
658 for (
size_t i{0}; i <
m_args.size(); ++i) {
659 const auto& arg{
m_args.at(i)};
661 if (!match.isTrue()) {
662 arg_mismatch.
pushKV(
strprintf(
"Position %s (%s)", i + 1, arg.m_names), std::move(match));
665 if (!arg_mismatch.empty()) {
676 if (match.isTrue()) {
680 mismatch.push_back(std::move(match));
682 if (!mismatch.isNull()) {
684 mismatch.empty() ?
"no possible results defined" :
685 mismatch.size() == 1 ? mismatch[0].write(4) :
687 throw std::runtime_error{
700 const RPCArg& param{params.at(i)};
703 if (!arg.isNull())
return &arg;
704 if (!std::holds_alternative<RPCArg::Default>(param.m_fallback))
return nullptr;
705 return &std::get<RPCArg::Default>(param.m_fallback);
717#define TMPL_INST(check_param, ret_type, return_code) \
719 ret_type RPCMethod::ArgValue<ret_type>(size_t i) const \
721 const UniValue* maybe_arg{ \
722 DetailMaybeArg(check_param, m_args, m_req, i), \
726 void force_semicolon(ret_type)
730TMPL_INST(
nullptr, std::optional<double>, maybe_arg ? std::optional{maybe_arg->get_real()} : std::nullopt;);
731TMPL_INST(
nullptr, std::optional<bool>, maybe_arg ? std::optional{maybe_arg->get_bool()} : std::nullopt;);
732TMPL_INST(
nullptr, std::optional<int64_t>, maybe_arg ? std::optional{maybe_arg->getInt<int64_t>()} : std::nullopt;);
733TMPL_INST(
nullptr, std::optional<std::string_view>, maybe_arg ? std::optional<std::string_view>{maybe_arg->get_str()} : std::nullopt;);
745 size_t num_required_args = 0;
746 for (
size_t n =
m_args.size(); n > 0; --n) {
747 if (!
m_args.at(n - 1).IsOptional()) {
748 num_required_args = n;
752 return num_required_args <= num_args && num_args <=
m_args.size();
757 std::vector<std::pair<std::string, bool>>
ret;
759 for (
const auto& arg :
m_args) {
761 for (
const auto& inner : arg.m_inner) {
762 ret.emplace_back(inner.m_names,
true);
765 ret.emplace_back(arg.m_names,
false);
772 auto it{std::find_if(
773 m_args.begin(),
m_args.end(), [&key](
const auto& arg) { return arg.GetName() == key;}
777 return std::distance(
m_args.begin(), it);
786 bool was_optional{
false};
787 for (
const auto& arg :
m_args) {
788 if (arg.m_opts.hidden)
break;
789 const bool optional = arg.IsOptional();
792 if (!was_optional)
ret +=
"( ";
795 if (was_optional)
ret +=
") ";
796 was_optional =
false;
798 ret += arg.ToString(
true);
800 if (was_optional)
ret +=
" )";
809 for (
size_t i{0}; i <
m_args.size(); ++i) {
810 const auto& arg =
m_args.at(i);
811 if (arg.m_opts.hidden)
break;
822 for (
const auto& arg_inner : arg.m_inner) {
823 named_only_sections.
PushSection({arg_inner.GetFirstName(), arg_inner.ToDescriptionString(
true)});
824 named_only_sections.
Push(arg_inner);
831 if (!named_only_sections.
m_sections.empty())
ret +=
"\nNamed Arguments:\n";
847 auto push_back_arg_info = [&arr](
const std::string& rpc_name,
int pos,
const std::string& arg_name,
const RPCArg::Type& type) {
849 map.push_back(rpc_name);
851 map.push_back(arg_name);
854 arr.push_back(std::move(map));
857 for (
int i{0}; i < int(
m_args.size()); ++i) {
858 const auto& arg =
m_args.at(i);
859 std::vector<std::string> arg_names =
SplitString(arg.m_names,
'|');
860 for (
const auto& arg_name : arg_names) {
861 push_back_arg_info(
m_name, i, arg_name, arg.m_type);
863 for (
const auto& inner : arg.m_inner) {
864 std::vector<std::string> inner_names =
SplitString(inner.m_names,
'|');
865 for (
const std::string& inner_name : inner_names) {
866 push_back_arg_info(
m_name, i, inner_name, inner.m_type);
898 case Type::OBJ_NAMED_PARAMS:
899 case Type::OBJ_USER_KEYS: {
914 if (!exp_type)
return true;
916 if (*exp_type != request.
getType()) {
960 ret +=
"numeric or string";
964 ret +=
"numeric or array";
974 ret +=
"json object";
984 ret +=
", optional, default=" + std::get<RPCArg::DefaultHint>(
m_fallback);
986 ret +=
", optional, default=" + std::get<RPCArg::Default>(
m_fallback).write();
988 switch (std::get<RPCArg::Optional>(
m_fallback)) {
990 if (is_named_arg)
ret +=
", optional";
1010 const std::string indent(current_indent,
' ');
1011 const std::string indent_next(current_indent + 2,
' ');
1014 const std::string maybe_separator{outer_type !=
OuterType::NONE ?
"," :
""};
1017 const std::string maybe_key{
1023 const auto Description = [&](
const std::string& type) {
1024 return "(" + type + (this->
m_optional ?
", optional" :
"") +
")" +
1029 const auto elision_has_description{[](
const std::vector<RPCResult>& inner) {
1030 return std::ranges::any_of(inner, [](
const auto& res) {
1031 return !std::holds_alternative<HelpElisionSkip>(res.m_opts.print_elision);
1036 sections.
PushSection({indent +
"..." + maybe_separator, *text});
1045 sections.
PushSection({indent + maybe_key +
"xxx" + maybe_separator, Description(
"any")});
1049 sections.
PushSection({indent +
"null" + maybe_separator, Description(
"json null")});
1053 sections.
PushSection({indent + maybe_key +
"\"str\"" + maybe_separator, Description(
"string")});
1057 sections.
PushSection({indent + maybe_key +
"n" + maybe_separator, Description(
"numeric")});
1061 sections.
PushSection({indent + maybe_key +
"\"hex\"" + maybe_separator, Description(
"string")});
1065 sections.
PushSection({indent + maybe_key +
"n" + maybe_separator, Description(
"numeric")});
1069 sections.
PushSection({indent + maybe_key +
"xxx" + maybe_separator, Description(
"numeric")});
1073 sections.
PushSection({indent + maybe_key +
"true|false" + maybe_separator, Description(
"boolean")});
1078 sections.
PushSection({indent + maybe_key +
"[", Description(
"json array")});
1079 for (
const auto& i :
m_inner) {
1088 sections.
m_sections.back().m_left.pop_back();
1090 sections.
PushSection({indent +
"]" + maybe_separator,
""});
1096 sections.
PushSection({indent + maybe_key +
"{}", Description(
"empty JSON object")});
1100 sections.
PushSection({indent + maybe_key +
"{", Description(
"json object")});
1101 for (
const auto& i :
m_inner) {
1109 sections.
m_sections.back().m_left.pop_back();
1111 sections.
PushSection({indent +
"}" + maybe_separator,
""});
1123 return std::nullopt;
1129 case Type::STR_HEX: {
1133 case Type::STR_AMOUNT:
1134 case Type::NUM_TIME: {
1140 case Type::ARR_FIXED:
1160 if (!exp_type)
return true;
1162 if (*exp_type != result.
getType()) {
1168 for (
size_t i{0}; i < result.
get_array().size(); ++i) {
1172 if (!match.isTrue()) errors.
pushKV(
strprintf(
"%d", i), std::move(match));
1174 if (errors.
empty())
return true;
1182 for (
size_t i{0}; i < result.
get_obj().size(); ++i) {
1184 if (!match.isTrue()) errors.
pushKV(result.
getKeys()[i], std::move(match));
1186 if (errors.
empty())
return true;
1189 std::set<std::string> doc_keys;
1190 for (
const auto& doc_entry :
m_inner) {
1191 doc_keys.insert(doc_entry.m_key_name);
1193 std::map<std::string, UniValue> result_obj;
1195 for (
const auto& result_entry : result_obj) {
1196 if (!doc_keys.contains(result_entry.first)) {
1197 errors.
pushKV(result_entry.first,
"key returned that was not in doc");
1201 for (
const auto& doc_entry :
m_inner) {
1202 const auto result_it{result_obj.find(doc_entry.m_key_name)};
1203 if (result_it == result_obj.end()) {
1204 if (!doc_entry.m_optional) {
1205 errors.
pushKV(doc_entry.m_key_name,
"key missing, despite not being optional in doc");
1209 UniValue match{doc_entry.MatchesType(result_it->second)};
1210 if (!match.isTrue()) errors.
pushKV(doc_entry.m_key_name, std::move(match));
1212 if (errors.
empty())
return true;
1243 return res +
"\"str\"";
1245 return res +
"\"hex\"";
1249 return res +
"n or [n,n]";
1251 return res +
"amount";
1253 return res +
"bool";
1256 for (
const auto& i :
m_inner) {
1257 res += i.ToString(oneline) +
",";
1259 return res +
"...]";
1274 throw std::runtime_error{
1299 return "{" + res +
"}";
1301 return "{" + res +
",...}";
1306 for (
const auto& i :
m_inner) {
1307 res += i.ToString(oneline) +
",";
1309 return "[" + res +
"...]";
1317 if (value.
isNum()) {
1318 return {0, value.
getInt<int64_t>()};
1321 int64_t low = value[0].
getInt<int64_t>();
1322 int64_t high = value[1].
getInt<int64_t>();
1340 std::string desc_str;
1341 std::pair<int64_t, int64_t> range = {0, 1000};
1342 if (scanobject.
isStr()) {
1343 desc_str = scanobject.
get_str();
1344 }
else if (scanobject.
isObject()) {
1347 desc_str = desc_uni.get_str();
1349 if (!range_uni.isNull()) {
1358 if (descs.empty()) {
1361 if (!descs.at(0)->IsRange()) {
1365 std::vector<CScript>
ret;
1366 for (int64_t i = range.first; i <= range.second; ++i) {
1367 for (
const auto& desc : descs) {
1368 std::vector<CScript> scripts;
1375 std::move(scripts.begin(), scripts.end(), std::back_inserter(
ret));
1383 std::vector<uint32_t>
out;
1395 for (
const auto&
s : bilingual_strings) {
1396 result.push_back(
s.original);
1403 if (warnings.
empty())
return;
1404 obj.
pushKV(
"warnings", warnings);
1409 if (warnings.empty())
return;
1419 {
RPCResult::Type::STR,
"address",
true,
"The Bitcoin address (only if a well-defined address exists)"},
1430std::vector<RPCResult>
ElideGroup(std::vector<RPCResult> fields, std::string summary)
1432 if (fields.empty())
return fields;
1433 std::vector<RPCResult> result;
1434 result.reserve(fields.size());
1435 for (
size_t i = 0; i < fields.size(); ++i) {
1442 result.emplace_back(fields[i], std::move(opts));
std::variant< CNoDestination, PubKeyDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, PayToAnchor, WitnessUnknown > CTxDestination
A txout script categorized into standard templates.
bool MoneyRange(const CAmount &nValue)
int64_t CAmount
Amount in satoshis (Can be negative)
constexpr CAmount COIN
The amount of satoshis in one BTC.
uint256 ArithToUint256(const arith_uint256 &a)
bool ParseHDKeypath(const std::string &keypath_str, std::vector< uint32_t > &keypath)
Parse an HD keypaths like "m/7/0'/2000".
#define CHECK_NONFATAL(condition)
Identity function.
#define NONFATAL_UNREACHABLE()
NONFATAL_UNREACHABLE() is a macro that is used to mark unreachable code.
#define STR_INTERNAL_BUG(msg)
bool GetBoolArg(const std::string &strArg, bool fDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return boolean argument or default value.
The block chain is a tree shaped structure starting with the genesis block at the root,...
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
An encapsulated public key.
bool IsFullyValid() const
fully validate whether this is a valid public key (more expensive than IsValid())
Serialized script, used inside transaction inputs and outputs.
UniValue operator()(const WitnessUnknown &id) const
UniValue operator()(const WitnessV0KeyHash &id) const
UniValue operator()(const WitnessV0ScriptHash &id) const
DescribeAddressVisitor()=default
UniValue operator()(const CNoDestination &dest) const
UniValue operator()(const PubKeyDestination &dest) const
UniValue operator()(const WitnessV1Taproot &tap) const
UniValue operator()(const ScriptHash &scriptID) const
UniValue operator()(const PKHash &keyID) const
UniValue operator()(const PayToAnchor &anchor) const
enum JSONRPCRequest::Mode mode
const RPCExamples m_examples
const std::string m_description
const JSONRPCRequest * m_req
std::function< UniValue(const RPCMethod &, const JSONRPCRequest &)> RPCMethodImpl
RPCMethod(std::string name, std::string description, std::vector< RPCArg > args, RPCResults results, RPCExamples examples)
const RPCMethodImpl m_fun
bool IsValidNumArgs(size_t num_args) const
If the supplied number of args is neither too small nor too high.
std::vector< std::pair< std::string, bool > > GetArgNames() const
Return list of arguments and whether they are named-only.
const RPCResults m_results
const std::vector< RPCArg > m_args
size_t GetParamIndex(std::string_view key) const
Return positional index of a parameter using its name as key.
UniValue HandleRequest(const JSONRPCRequest &request) const
UniValue GetArgMap() const
Return the named args that need to be converted from string to another JSON type.
std::string ToString() const
const std::string & get_str() const
const UniValue & find_value(std::string_view key) const
enum VType getType() const
std::string write(unsigned int prettyIndent=0, unsigned int indentLevel=0) const
const std::string & getValStr() const
const UniValue & get_obj() const
const std::vector< std::string > & getKeys() const
const UniValue & get_array() const
void pushKV(std::string key, UniValue val)
void getObjMap(std::map< std::string, UniValue > &kv) const
256-bit unsigned big integer.
static constexpr unsigned int size()
static std::optional< uint256 > FromHex(std::string_view str)
static UniValue Parse(std::string_view raw, ParamFormat format=ParamFormat::JSON)
Parse string to UniValue or throw runtime_error if string contains invalid JSON.
is a home for simple enum and struct type definitions that can be used internally by functions in the...
util::Result< int > SighashFromStr(const std::string &sighash)
std::string HexStr(const std::span< const uint8_t > s)
Convert a span of bytes to a lower-case hexadecimal string.
is a home for simple string functions returning descriptive messages that are used in RPC and GUI int...
char const * json() noexcept
Template to generate JSON data.
bilingual_str PSBTErrorString(PSBTError err)
bilingual_str TransactionErrorString(const TransactionError err)
std::vector< std::string > SplitString(std::string_view str, char sep)
bilingual_str ErrorString(const Result< T > &result)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
is a home for public enum and struct type definitions that are used internally by node code,...
CTxDestination AddAndGetDestinationForScript(FlatSigningProvider &keystore, const CScript &script, OutputType type)
Get a destination of the requested type (if possible) to the specified script.
std::optional< arith_uint256 > DeriveTarget(unsigned int nBits, const uint256 pow_limit)
Convert nBits value to target.
UniValue JSONRPCError(int code, const std::string &message)
RPCErrorCode
Bitcoin RPC error codes.
@ RPC_LIMIT_EXCEEDED
A bounded resource is currently at capacity.
@ RPC_VERIFY_ALREADY_IN_UTXO_SET
Transaction already in utxo set.
@ RPC_TYPE_ERROR
Unexpected type was passed as parameter.
@ RPC_TRANSACTION_REJECTED
@ RPC_TRANSACTION_ERROR
Aliases for backward compatibility.
@ RPC_INVALID_PARAMETER
Invalid, missing or duplicate parameter.
@ RPC_DESERIALIZATION_ERROR
Error parsing or validating structure in raw format.
@ RPC_INVALID_ADDRESS_OR_KEY
Invalid address or key.
static const UniValue * DetailMaybeArg(CheckFn *check, const std::vector< RPCArg > ¶ms, const JSONRPCRequest *req, size_t i)
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 ...
std::vector< uint32_t > ParsePathBIP32(const std::string &path)
Parse BIP32 path.
void(const RPCArg &) CheckFn
std::pair< int64_t, int64_t > ParseDescriptorRange(const UniValue &value)
Parse a JSON range specified as int64, or [int64, int64].
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
std::string HelpExampleRpcNamed(const std::string &methodname, const RPCArgList &args)
CAmount AmountFromValue(const UniValue &value, int decimals)
Validate and return a CAmount from a UniValue number or string.
RPCErrorCode RPCErrorFromPSBTError(PSBTError err)
std::vector< unsigned char > ParseHexV(const UniValue &v, std::string_view name)
static UniValue BilingualStringsToUniValue(const std::vector< bilingual_str > &bilingual_strings)
Convert a vector of bilingual strings to a UniValue::VARR containing their original untranslated valu...
void PushWarnings(const UniValue &warnings, UniValue &obj)
Push warning messages to an RPC "warnings" field as a JSON array of strings.
UniValue JSONRPCTransactionError(TransactionError terr, const std::string &err_string)
std::vector< RPCResult > ElideGroup(std::vector< RPCResult > fields, std::string summary)
Stamp elision onto an entire vector of RPCResult fields at once.
#define TMPL_INST(check_param, ret_type, return_code)
std::vector< unsigned char > ParseHexO(const UniValue &o, std::string_view strKey)
uint256 GetTarget(const CBlockIndex &blockindex, const uint256 pow_limit)
UniValue JSONRPCPSBTError(PSBTError err)
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
CFeeRate ParseFeeRate(const UniValue &json)
Parse a json number or string, denoting BTC/kvB, into a CFeeRate (sat/kvB).
static std::optional< UniValue::VType > ExpectedType(RPCArg::Type type)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string UNIX_EPOCH_TIME
String used to describe UNIX epoch time in documentation, factored out to a constant for consistency.
std::string GetAllOutputTypes()
Gets all existing output types formatted for RPC help sections.
int ParseVerbosity(const UniValue &arg, int default_verbosity, bool allow_bool)
Parses verbosity from provided UniValue.
CPubKey HexToPubKey(const std::string &hex_in)
std::optional< int > ParseSighashString(const UniValue &sighash)
Returns a sighash value corresponding to the passed in argument.
const std::string EXAMPLE_ADDRESS[2]
Example bech32 addresses for the RPCExamples help documentation.
CTxDestination AddAndGetMultisigDestination(const int required, const std::vector< CPubKey > &pubkeys, OutputType type, FlatSigningProvider &keystore, CScript &script_out)
static std::pair< int64_t, int64_t > ParseRange(const UniValue &value)
uint256 ParseHashO(const UniValue &o, std::string_view strKey)
unsigned int ParseConfirmTarget(const UniValue &value, unsigned int max_target)
Parse a confirm target option and raise an RPC error if it is invalid.
void RPCTypeCheckObj(const UniValue &o, const std::map< std::string, UniValueType > &typesExpected, bool fAllowNull, bool fStrict)
std::string HelpExampleCliNamed(const std::string &methodname, const RPCArgList &args)
uint256 ParseHashV(const UniValue &v, std::string_view name)
Utilities: convert hex-encoded Values (throws error if not hex).
static void CheckRequiredOrDefault(const RPCArg ¶m)
UniValue DescribeAddress(const CTxDestination &dest)
std::vector< RPCResult > ScriptPubKeyDoc()
std::vector< std::pair< std::string, UniValue > > RPCArgList
constexpr bool DEFAULT_RPC_DOC_CHECK
OuterType
Serializing JSON objects depends on the outer type.
util::Expected< void, std::string > CheckDescriptorRangeBounds(int64_t low, int64_t high)
Validate the numeric bounds of a descriptor key-expression range [low, high] (high inclusive).
constexpr unsigned int MAX_SCRIPT_ELEMENT_SIZE
constexpr int MAX_PUBKEYS_PER_MULTISIG
CScript GetScriptForMultisig(int nRequired, const std::vector< CPubKey > &keys)
Generate a multisig script.
std::string GetTxnOutputType(TxoutType t)
Get the name of a TxoutType as a string.
@ WITNESS_UNKNOWN
Only for Witness versions not already defined above.
std::vector< Byte > ParseHex(std::string_view hex_str)
Like TryParseHex, but returns an empty vector on invalid input.
@ RANGE
Special type that is a NUM or [NUM,NUM].
@ OBJ_USER_KEYS
Special type where the user must set the keys e.g. to define multiple addresses; as opposed to e....
@ STR_HEX
Special type that is a STR with only hex chars.
@ AMOUNT
Special type representing a floating point amount (can be either NUM or STR)
@ OBJ_NAMED_PARAMS
Special type that behaves almost exactly like OBJ, defining an options object with a list of pre-defi...
const std::vector< RPCArg > m_inner
Only used for arrays or dicts.
const RPCArgOptions m_opts
const std::string m_names
The name of the arg (can be empty for inner args, can contain multiple aliases separated by | for nam...
const Fallback m_fallback
std::string ToString(bool oneline) const
Return the type string of the argument.
UniValue MatchesType(const UniValue &request) const
Check whether the request JSON type matches.
const std::string m_description
std::string ToDescriptionString(bool is_named_arg) const
Return the description string, including the argument type and whether the argument is required.
std::string GetName() const
Return the name, throws when there are aliases.
std::string GetFirstName() const
Return the first of all aliases.
std::string ToStringObj(bool oneline) const
Return the type string of the argument when it is in an object (dict).
@ OMITTED
Optional argument for which the default value is omitted from help text for one of two reasons:
std::vector< std::string > type_str
Should be empty unless it is supposed to override the auto-generated type strings....
std::string oneline_description
Should be empty unless it is supposed to override the auto-generated summary line.
std::string ToDescriptionString() const
const std::string m_examples
const std::string m_description
void ToSections(Sections §ions, OuterType outer_type=OuterType::NONE, int current_indent=0) const
Append the sections of the result.
@ NUM_TIME
Special numeric to denote unix epoch time.
@ ANY
Special type to disable type checks.
@ ARR_FIXED
Special array that has a fixed number of entries.
@ OBJ_DYN
Special dictionary with keys that are not literals.
@ STR_HEX
Special string with only hex chars.
@ STR_AMOUNT
Special string to represent a floating point amount.
const std::vector< RPCResult > m_inner
Only used for arrays or dicts.
UniValue MatchesType(const UniValue &result) const
Check whether the result JSON type matches.
void CheckInnerDoc() const
const RPCResultOptions m_opts
const std::string m_key_name
Only used for dicts.
HelpElision print_elision
std::string ToDescriptionString() const
Return the description string.
const std::vector< RPCResult > m_results
A pair of strings that can be aligned (through padding) with other Sections later on.
Section(const std::string &left, const std::string &right)
const std::string m_right
Keeps track of RPCArgs by transforming them into sections for the purpose of serializing everything t...
void PushSection(const Section &s)
std::vector< Section > m_sections
void Push(const RPCArg &arg, const size_t current_indent=5, const OuterType outer_type=OuterType::NONE)
Recursive helper to translate an RPCArg into sections.
std::string ToString() const
Concatenate all sections with proper padding.
CTxDestination subtype to encode any future Witness version.
FuzzedDataProvider provider
const char * uvTypeName(UniValue::VType t)
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
bool IsHex(std::string_view str)