aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/blockchain.cpp7
-rw-r--r--src/rpc/fees.cpp5
-rw-r--r--src/rpc/mempool.cpp9
-rw-r--r--src/rpc/mining.cpp3
-rw-r--r--src/rpc/net.cpp4
-rw-r--r--src/rpc/output_script.cpp3
-rw-r--r--src/rpc/rawtransaction.cpp22
-rw-r--r--src/rpc/rawtransaction_util.cpp6
-rw-r--r--src/rpc/rawtransaction_util.h4
-rw-r--r--src/rpc/request.cpp1
-rw-r--r--src/rpc/request.h1
-rw-r--r--src/rpc/server.cpp2
-rw-r--r--src/rpc/signmessage.cpp2
-rw-r--r--src/rpc/util.cpp45
-rw-r--r--src/rpc/util.h50
15 files changed, 97 insertions, 67 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index a6c959797a..46b0ae161f 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -61,6 +61,9 @@ using kernel::CoinStatsHashType;
using node::BlockManager;
using node::NodeContext;
using node::SnapshotMetadata;
+using util::Join;
+using util::MakeUnorderedList;
+using util::ToString;
struct CUpdatedBlock
{
@@ -2697,7 +2700,7 @@ UniValue CreateUTXOSnapshot(
tip->nHeight, tip->GetBlockHash().ToString(),
fs::PathToString(path), fs::PathToString(temppath)));
- SnapshotMetadata metadata{tip->GetBlockHash(), tip->nHeight, maybe_stats->coins_count};
+ SnapshotMetadata metadata{chainstate.m_chainman.GetParams().MessageStart(), tip->GetBlockHash(), tip->nHeight, maybe_stats->coins_count};
afile << metadata;
@@ -2809,7 +2812,7 @@ static RPCHelpMan loadtxoutset()
"Couldn't open file " + path.utf8string() + " for reading.");
}
- SnapshotMetadata metadata;
+ SnapshotMetadata metadata{chainman.GetParams().MessageStart()};
try {
afile >> metadata;
} catch (const std::ios_base::failure& e) {
diff --git a/src/rpc/fees.cpp b/src/rpc/fees.cpp
index a7cec96746..aefe78162b 100644
--- a/src/rpc/fees.cpp
+++ b/src/rpc/fees.cpp
@@ -3,6 +3,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <common/messages.h>
#include <core_io.h>
#include <node/context.h>
#include <policy/feerate.h>
@@ -14,7 +15,6 @@
#include <rpc/util.h>
#include <txmempool.h>
#include <univalue.h>
-#include <util/fees.h>
#include <validationinterface.h>
#include <algorithm>
@@ -22,6 +22,9 @@
#include <cmath>
#include <string>
+using common::FeeModeFromString;
+using common::FeeModes;
+using common::InvalidEstimateModeErrorMessage;
using node::NodeContext;
static RPCHelpMan estimatesmartfee()
diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp
index edd45d9731..fd11f6cfeb 100644
--- a/src/rpc/mempool.cpp
+++ b/src/rpc/mempool.cpp
@@ -11,6 +11,7 @@
#include <core_io.h>
#include <kernel/mempool_entry.h>
#include <node/mempool_persist_args.h>
+#include <node/types.h>
#include <policy/rbf.h>
#include <policy/settings.h>
#include <primitives/transaction.h>
@@ -32,6 +33,8 @@ using node::DEFAULT_MAX_BURN_AMOUNT;
using node::DEFAULT_MAX_RAW_TX_FEE_RATE;
using node::MempoolPath;
using node::NodeContext;
+using node::TransactionError;
+using util::ToString;
static RPCHelpMan sendrawtransaction()
{
@@ -82,7 +85,7 @@ static RPCHelpMan sendrawtransaction()
CTransactionRef tx(MakeTransactionRef(std::move(mtx)));
- const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>(1))};
+ const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
int64_t virtual_size = GetVirtualTransactionSize(*tx);
CAmount max_raw_tx_fee = max_raw_tx_fee_rate.GetFee(virtual_size);
@@ -162,7 +165,7 @@ static RPCHelpMan testmempoolaccept()
"Array must contain between 1 and " + ToString(MAX_PACKAGE_COUNT) + " transactions.");
}
- const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>(1))};
+ const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
std::vector<CTransactionRef> txns;
txns.reserve(raw_transactions.size());
@@ -873,7 +876,7 @@ static RPCHelpMan submitpackage()
}
// Fee check needs to be run with chainstate and package context
- const CFeeRate max_raw_tx_fee_rate = ParseFeeRate(self.Arg<UniValue>(1));
+ const CFeeRate max_raw_tx_fee_rate{ParseFeeRate(self.Arg<UniValue>("maxfeerate"))};
std::optional<CFeeRate> client_maxfeerate{max_raw_tx_fee_rate};
// 0-value is special; it's mapped to no sanity check
if (max_raw_tx_fee_rate == CFeeRate(0)) {
diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp
index 606fc62dbe..6412fb35ec 100644
--- a/src/rpc/mining.cpp
+++ b/src/rpc/mining.cpp
@@ -47,6 +47,7 @@ using node::CBlockTemplate;
using node::NodeContext;
using node::RegenerateCommitments;
using node::UpdateTime;
+using util::ToString;
/**
* Return average network hashes per second based on the last 'lookup' blocks,
@@ -485,7 +486,7 @@ static RPCHelpMan prioritisetransaction()
LOCK(cs_main);
uint256 hash(ParseHashV(request.params[0], "txid"));
- const auto dummy{self.MaybeArg<double>(1)};
+ const auto dummy{self.MaybeArg<double>("dummy")};
CAmount nAmount = request.params[2].getInt<int64_t>();
if (dummy && *dummy != 0) {
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index 4fc93291f5..1cc55f891a 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -35,6 +35,8 @@
#include <univalue.h>
using node::NodeContext;
+using util::Join;
+using util::TrimString;
const std::vector<std::string> CONNECTION_TYPE_DOC{
"outbound-full-relay (default automatic connections)",
@@ -401,7 +403,7 @@ static RPCHelpMan addconnection()
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
}
- bool use_v2transport = self.Arg<bool>(2);
+ bool use_v2transport{self.Arg<bool>("v2transport")};
NodeContext& node = EnsureAnyNodeContext(request.context);
CConnman& connman = EnsureConnman(node);
diff --git a/src/rpc/output_script.cpp b/src/rpc/output_script.cpp
index f771b31db0..65a9be2762 100644
--- a/src/rpc/output_script.cpp
+++ b/src/rpc/output_script.cpp
@@ -139,8 +139,7 @@ static RPCHelpMan createmultisig()
output_type = parsed.value();
}
- // Construct using pay-to-script-hash:
- FillableSigningProvider keystore;
+ FlatSigningProvider keystore;
CScript inner;
const CTxDestination dest = AddAndGetMultisigDestination(required, pubkeys, output_type, keystore, inner);
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp
index 7fa6652f9e..75b538061d 100644
--- a/src/rpc/rawtransaction.cpp
+++ b/src/rpc/rawtransaction.cpp
@@ -16,6 +16,7 @@
#include <node/context.h>
#include <node/psbt.h>
#include <node/transaction.h>
+#include <node/types.h>
#include <policy/packages.h>
#include <policy/policy.h>
#include <policy/rbf.h>
@@ -785,7 +786,7 @@ static RPCHelpMan signrawtransactionwithkey()
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed. Make sure the tx has at least one input.");
}
- FillableSigningProvider keystore;
+ FlatSigningProvider keystore;
const UniValue& keys = request.params[1].get_array();
for (unsigned int idx = 0; idx < keys.size(); ++idx) {
UniValue k = keys[idx];
@@ -793,7 +794,11 @@ static RPCHelpMan signrawtransactionwithkey()
if (!key.IsValid()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
}
- keystore.AddKey(key);
+
+ CPubKey pubkey = key.GetPubKey();
+ CKeyID key_id = pubkey.GetID();
+ keystore.pubkeys.emplace(key_id, pubkey);
+ keystore.keys.emplace(key_id, key);
}
// Fetch previous transactions (inputs):
@@ -1485,9 +1490,8 @@ static RPCHelpMan combinepsbt()
}
PartiallySignedTransaction merged_psbt;
- const TransactionError error = CombinePSBTs(merged_psbt, psbtxs);
- if (error != TransactionError::OK) {
- throw JSONRPCTransactionError(error);
+ if (!CombinePSBTs(merged_psbt, psbtxs)) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "PSBTs not compatible (different transactions)");
}
DataStream ssTx{};
@@ -1744,8 +1748,8 @@ static RPCHelpMan joinpsbts()
}
psbtxs.push_back(psbtx);
// Choose the highest version number
- if (static_cast<uint32_t>(psbtx.tx->nVersion) > best_version) {
- best_version = static_cast<uint32_t>(psbtx.tx->nVersion);
+ if (psbtx.tx->version > best_version) {
+ best_version = psbtx.tx->version;
}
// Choose the lowest lock time
if (psbtx.tx->nLockTime < best_locktime) {
@@ -1756,7 +1760,7 @@ static RPCHelpMan joinpsbts()
// Create a blank psbt where everything will be added
PartiallySignedTransaction merged_psbt;
merged_psbt.tx = CMutableTransaction();
- merged_psbt.tx->nVersion = static_cast<int32_t>(best_version);
+ merged_psbt.tx->version = best_version;
merged_psbt.tx->nLockTime = best_locktime;
// Merge
@@ -1791,7 +1795,7 @@ static RPCHelpMan joinpsbts()
PartiallySignedTransaction shuffled_psbt;
shuffled_psbt.tx = CMutableTransaction();
- shuffled_psbt.tx->nVersion = merged_psbt.tx->nVersion;
+ shuffled_psbt.tx->version = merged_psbt.tx->version;
shuffled_psbt.tx->nLockTime = merged_psbt.tx->nLockTime;
for (int i : input_indices) {
shuffled_psbt.AddInput(merged_psbt.tx->vin[i], merged_psbt.inputs[i]);
diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp
index a62f90215a..53f943bb9e 100644
--- a/src/rpc/rawtransaction_util.cpp
+++ b/src/rpc/rawtransaction_util.cpp
@@ -181,7 +181,7 @@ static void TxInErrorToJSON(const CTxIn& txin, UniValue& vErrorsRet, const std::
vErrorsRet.push_back(std::move(entry));
}
-void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keystore, std::map<COutPoint, Coin>& coins)
+void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins)
{
if (!prevTxsUnival.isNull()) {
const UniValue& prevTxs = prevTxsUnival.get_array();
@@ -247,11 +247,11 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst
// work from witnessScript when possible
std::vector<unsigned char> scriptData(!ws.isNull() ? ParseHexV(ws, "witnessScript") : ParseHexV(rs, "redeemScript"));
CScript script(scriptData.begin(), scriptData.end());
- keystore->AddCScript(script);
+ keystore->scripts.emplace(CScriptID(script), script);
// Automatically also add the P2WSH wrapped version of the script (to deal with P2SH-P2WSH).
// This is done for redeemScript only for compatibility, it is encouraged to use the explicit witnessScript field instead.
CScript witness_output_script{GetScriptForDestination(WitnessV0ScriptHash(script))};
- keystore->AddCScript(witness_output_script);
+ keystore->scripts.emplace(CScriptID(witness_output_script), witness_output_script);
if (!ws.isNull() && !rs.isNull()) {
// if both witnessScript and redeemScript are provided,
diff --git a/src/rpc/rawtransaction_util.h b/src/rpc/rawtransaction_util.h
index 964d0b095b..40d6bbba87 100644
--- a/src/rpc/rawtransaction_util.h
+++ b/src/rpc/rawtransaction_util.h
@@ -12,7 +12,7 @@
#include <optional>
struct bilingual_str;
-class FillableSigningProvider;
+struct FlatSigningProvider;
class UniValue;
struct CMutableTransaction;
class Coin;
@@ -38,7 +38,7 @@ void SignTransactionResultToJSON(CMutableTransaction& mtx, bool complete, const
* @param keystore A pointer to the temporary keystore if there is one
* @param coins Map of unspent outputs - coins in mempool and current chain UTXO set, may be extended by previous txns outputs after call
*/
-void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keystore, std::map<COutPoint, Coin>& coins);
+void ParsePrevouts(const UniValue& prevTxsUnival, FlatSigningProvider* keystore, std::map<COutPoint, Coin>& coins);
/** Normalize univalue-represented inputs and add them to the transaction */
void AddInputs(CMutableTransaction& rawTx, const UniValue& inputs_in, bool rbf);
diff --git a/src/rpc/request.cpp b/src/rpc/request.cpp
index d35782189e..87b9f18b33 100644
--- a/src/rpc/request.cpp
+++ b/src/rpc/request.cpp
@@ -45,6 +45,7 @@ UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params,
request.pushKV("method", strMethod);
request.pushKV("params", params);
request.pushKV("id", id);
+ request.pushKV("jsonrpc", "2.0");
return request;
}
diff --git a/src/rpc/request.h b/src/rpc/request.h
index e47f90af86..9968426636 100644
--- a/src/rpc/request.h
+++ b/src/rpc/request.h
@@ -17,6 +17,7 @@ enum class JSONRPCVersion {
V2
};
+/** JSON-RPC 2.0 request, only used in bitcoin-cli **/
UniValue JSONRPCRequestObj(const std::string& strMethod, const UniValue& params, const UniValue& id);
UniValue JSONRPCReplyObj(UniValue result, UniValue error, std::optional<UniValue> id, JSONRPCVersion jsonrpc_version);
UniValue JSONRPCError(int code, const std::string& message);
diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp
index 838068bc19..19063fa5be 100644
--- a/src/rpc/server.cpp
+++ b/src/rpc/server.cpp
@@ -27,6 +27,8 @@
#include <mutex>
#include <unordered_map>
+using util::SplitString;
+
static GlobalMutex g_rpc_warmup_mutex;
static std::atomic<bool> g_rpc_running{false};
static bool fRPCInWarmup GUARDED_BY(g_rpc_warmup_mutex) = true;
diff --git a/src/rpc/signmessage.cpp b/src/rpc/signmessage.cpp
index 9f3c24efcf..83462738c5 100644
--- a/src/rpc/signmessage.cpp
+++ b/src/rpc/signmessage.cpp
@@ -3,6 +3,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <common/signmessage.h>
#include <key.h>
#include <key_io.h>
#include <rpc/protocol.h>
@@ -10,7 +11,6 @@
#include <rpc/server.h>
#include <rpc/util.h>
#include <univalue.h>
-#include <util/message.h>
#include <string>
diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp
index ed32af7646..bb1aef63f4 100644
--- a/src/rpc/util.cpp
+++ b/src/rpc/util.cpp
@@ -7,9 +7,12 @@
#include <clientversion.h>
#include <core_io.h>
#include <common/args.h>
+#include <common/messages.h>
+#include <common/types.h>
#include <consensus/amount.h>
#include <script/interpreter.h>
#include <key_io.h>
+#include <node/types.h>
#include <outputtype.h>
#include <rpc/util.h>
#include <script/descriptor.h>
@@ -30,6 +33,14 @@
#include <tuple>
#include <utility>
+using common::PSBTError;
+using common::PSBTErrorString;
+using common::TransactionErrorString;
+using node::TransactionError;
+using util::Join;
+using util::SplitString;
+using util::TrimString;
+
const std::string UNIX_EPOCH_TIME = "UNIX epoch time";
const std::string EXAMPLE_ADDRESS[2] = {"bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl", "bc1q02ad21edsxd23d32dfgqqsz4vv4nmtfzuklhy3"};
@@ -176,7 +187,7 @@ std::string HelpExampleCliNamed(const std::string& methodname, const RPCArgList&
std::string HelpExampleRpc(const std::string& methodname, const std::string& args)
{
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"2.0\", \"id\": \"curltest\", "
- "\"method\": \"" + methodname + "\", \"params\": [" + args + "]}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
+ "\"method\": \"" + methodname + "\", \"params\": [" + args + "]}' -H 'content-type: application/json' http://127.0.0.1:8332/\n";
}
std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList& args)
@@ -187,7 +198,7 @@ std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList&
}
return "> curl --user myusername --data-binary '{\"jsonrpc\": \"2.0\", \"id\": \"curltest\", "
- "\"method\": \"" + methodname + "\", \"params\": " + params.write() + "}' -H 'content-type: text/plain;' http://127.0.0.1:8332/\n";
+ "\"method\": \"" + methodname + "\", \"params\": " + params.write() + "}' -H 'content-type: application/json' http://127.0.0.1:8332/\n";
}
// Converts a hex string to a public key if possible
@@ -228,7 +239,7 @@ CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string&
}
// Creates a multisig address from a given list of public keys, number of signatures required, and the address type
-CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FillableSigningProvider& keystore, CScript& script_out)
+CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FlatSigningProvider& keystore, CScript& script_out)
{
// Gather public keys
if (required < 1) {
@@ -364,6 +375,18 @@ unsigned int ParseConfirmTarget(const UniValue& value, unsigned int max_target)
return unsigned_target;
}
+RPCErrorCode RPCErrorFromPSBTError(PSBTError err)
+{
+ switch (err) {
+ case PSBTError::UNSUPPORTED:
+ return RPC_INVALID_PARAMETER;
+ case PSBTError::SIGHASH_MISMATCH:
+ return RPC_DESERIALIZATION_ERROR;
+ default: break;
+ }
+ return RPC_TRANSACTION_ERROR;
+}
+
RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
{
switch (terr) {
@@ -371,18 +394,16 @@ RPCErrorCode RPCErrorFromTransactionError(TransactionError terr)
return RPC_TRANSACTION_REJECTED;
case TransactionError::ALREADY_IN_CHAIN:
return RPC_TRANSACTION_ALREADY_IN_CHAIN;
- case TransactionError::P2P_DISABLED:
- return RPC_CLIENT_P2P_DISABLED;
- case TransactionError::INVALID_PSBT:
- case TransactionError::PSBT_MISMATCH:
- return RPC_INVALID_PARAMETER;
- case TransactionError::SIGHASH_MISMATCH:
- return RPC_DESERIALIZATION_ERROR;
default: break;
}
return RPC_TRANSACTION_ERROR;
}
+UniValue JSONRPCPSBTError(PSBTError err)
+{
+ return JSONRPCError(RPCErrorFromPSBTError(err), PSBTErrorString(err).original);
+}
+
UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string)
{
if (err_string.length() > 0) {
@@ -677,7 +698,7 @@ static const UniValue* DetailMaybeArg(CheckFn* check, const std::vector<RPCArg>&
static void CheckRequiredOrDefault(const RPCArg& param)
{
- // Must use `Arg<Type>(i)` to get the argument or its default value.
+ // Must use `Arg<Type>(key)` to get the argument or its default value.
const bool required{
std::holds_alternative<RPCArg::Optional>(param.m_fallback) && RPCArg::Optional::NO == std::get<RPCArg::Optional>(param.m_fallback),
};
@@ -778,7 +799,7 @@ std::string RPCHelpMan::ToString() const
if (arg.m_opts.hidden) break; // Any arg that follows is also hidden
// Push named argument name and description
- sections.m_sections.emplace_back(::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true));
+ sections.m_sections.emplace_back(util::ToString(i + 1) + ". " + arg.GetFirstName(), arg.ToDescriptionString(/*is_named_arg=*/true));
sections.m_max_pad = std::max(sections.m_max_pad, sections.m_sections.back().m_left.size());
// Recursively push nested args
diff --git a/src/rpc/util.h b/src/rpc/util.h
index 0e4dcc27b5..ca6ca6007b 100644
--- a/src/rpc/util.h
+++ b/src/rpc/util.h
@@ -34,9 +34,14 @@
class JSONRPCRequest;
enum ServiceFlags : uint64_t;
enum class OutputType;
-enum class TransactionError;
struct FlatSigningProvider;
struct bilingual_str;
+namespace common {
+enum class PSBTError;
+} // namespace common
+namespace node {
+enum class TransactionError;
+} // namespace node
static constexpr bool DEFAULT_RPC_DOC_CHECK{
#ifdef RPC_DOC_CHECK
@@ -117,7 +122,7 @@ std::string HelpExampleRpcNamed(const std::string& methodname, const RPCArgList&
CPubKey HexToPubKey(const std::string& hex_in);
CPubKey AddrToPubKey(const FillableSigningProvider& keystore, const std::string& addr_in);
-CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FillableSigningProvider& keystore, CScript& script_out);
+CTxDestination AddAndGetMultisigDestination(const int required, const std::vector<CPubKey>& pubkeys, OutputType type, FlatSigningProvider& keystore, CScript& script_out);
UniValue DescribeAddress(const CTxDestination& dest);
@@ -127,8 +132,9 @@ 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);
-RPCErrorCode RPCErrorFromTransactionError(TransactionError terr);
-UniValue JSONRPCTransactionError(TransactionError terr, const std::string& err_string = "");
+RPCErrorCode RPCErrorFromTransactionError(node::TransactionError terr);
+UniValue JSONRPCPSBTError(common::PSBTError err);
+UniValue JSONRPCTransactionError(node::TransactionError terr, const std::string& err_string = "");
//! Parse a JSON range specified as int64, or [int64, int64]
std::pair<int64_t, int64_t> ParseDescriptorRange(const UniValue& value);
@@ -414,19 +420,16 @@ public:
* argument isNull() and parses (from JSON) and returns the user-passed argument,
* or the default value derived from the RPCArg documentation.
*
- * There are two overloads of this function:
- * - Use Arg<Type>(size_t i) to get the argument (or the default value) by index.
- * - Use Arg<Type>(const std::string& key) to get the argument (or the default value) by key.
- *
- * The Type passed to this helper must match the corresponding RPCArg::Type.
+ * The instantiation of this helper for type R must match the corresponding RPCArg::Type.
*
- * @return The value of the RPC argument (or the default value) cast to type Type.
+ * @return The value of the RPC argument (or the default value) cast to type R.
*
* @see MaybeArg for handling optional arguments without default values.
*/
template <typename R>
- auto Arg(size_t i) const
+ auto Arg(std::string_view key) const
{
+ auto i{GetParamIndex(key)};
// Return argument (required or with default value).
if constexpr (std::is_integral_v<R> || std::is_floating_point_v<R>) {
// Return numbers by value.
@@ -436,11 +439,6 @@ public:
return ArgValue<const R&>(i);
}
}
- template<typename R>
- auto Arg(std::string_view key) const
- {
- return Arg<R>(GetParamIndex(key));
- }
/**
* @brief Helper to get an optional request argument.
*
@@ -452,21 +450,18 @@ public:
* argument isNull() and parses (from JSON) and returns the user-passed argument,
* or a falsy value if no argument was passed.
*
- * There are two overloads of this function:
- * - Use MaybeArg<Type>(size_t i) to get the optional argument by index.
- * - Use MaybeArg<Type>(const std::string& key) to get the optional argument by key.
+ * The instantiation of this helper for type R must match the corresponding RPCArg::Type.
*
- * The Type passed to this helper must match the corresponding RPCArg::Type.
+ * @return For integral and floating-point types, a std::optional<R> is returned.
+ * For other types, a R* pointer to the argument is returned. If the
+ * argument is not provided, std::nullopt or a null pointer is returned.
*
- * @return For integral and floating-point types, a std::optional<Type> is returned.
- * For other types, a Type* pointer to the argument is returned. If the
- * argument is not provided, std::nullopt or a null pointer is returned.
- *
* @see Arg for handling arguments that are required or have a default value.
*/
template <typename R>
- auto MaybeArg(size_t i) const
+ auto MaybeArg(std::string_view key) const
{
+ auto i{GetParamIndex(key)};
// Return optional argument (without default).
if constexpr (std::is_integral_v<R> || std::is_floating_point_v<R>) {
// Return numbers by value, wrapped in optional.
@@ -476,11 +471,6 @@ public:
return ArgValue<const R*>(i);
}
}
- template<typename R>
- auto MaybeArg(std::string_view key) const
- {
- return MaybeArg<R>(GetParamIndex(key));
- }
std::string ToString() const;
/** Return the named args that need to be converted from string to another JSON type */
UniValue GetArgMap() const;