Skip to content

Commit 35ed094

Browse files
committed
Extract prevention of outdated option names
This will be reused in `sendall` so we extract it to avoid duplication.
1 parent 9344697 commit 35ed094

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/wallet/rpc/spend.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222

2323
namespace wallet {
24-
static void ParseRecipients(const UniValue& address_amounts, const UniValue& subtract_fee_outputs, std::vector<CRecipient> &recipients) {
24+
static void ParseRecipients(const UniValue& address_amounts, const UniValue& subtract_fee_outputs, std::vector<CRecipient> &recipients)
25+
{
2526
std::set<CTxDestination> destinations;
2627
int i = 0;
2728
for (const std::string& address: address_amounts.getKeys()) {
@@ -51,6 +52,28 @@ static void ParseRecipients(const UniValue& address_amounts, const UniValue& sub
5152
}
5253
}
5354

55+
static void PreventOutdatedOptions(const UniValue& options)
56+
{
57+
if (options.exists("feeRate")) {
58+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use fee_rate (" + CURRENCY_ATOM + "/vB) instead of feeRate");
59+
}
60+
if (options.exists("changeAddress")) {
61+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use change_address");
62+
}
63+
if (options.exists("changePosition")) {
64+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use change_position");
65+
}
66+
if (options.exists("includeWatching")) {
67+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use include_watching");
68+
}
69+
if (options.exists("lockUnspents")) {
70+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use lock_unspents");
71+
}
72+
if (options.exists("subtractFeeFromOutputs")) {
73+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use subtract_fee_from_outputs");
74+
}
75+
}
76+
5477
UniValue SendMoney(CWallet& wallet, const CCoinControl &coin_control, std::vector<CRecipient> &recipients, mapValue_t map_value, bool verbose)
5578
{
5679
EnsureWalletIsUnlocked(wallet);
@@ -1144,24 +1167,7 @@ RPCHelpMan send()
11441167
if (!options["conf_target"].isNull() && (options["estimate_mode"].isNull() || (options["estimate_mode"].get_str() == "unset"))) {
11451168
throw JSONRPCError(RPC_INVALID_PARAMETER, "Specify estimate_mode");
11461169
}
1147-
if (options.exists("feeRate")) {
1148-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use fee_rate (" + CURRENCY_ATOM + "/vB) instead of feeRate");
1149-
}
1150-
if (options.exists("changeAddress")) {
1151-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use change_address");
1152-
}
1153-
if (options.exists("changePosition")) {
1154-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use change_position");
1155-
}
1156-
if (options.exists("includeWatching")) {
1157-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use include_watching");
1158-
}
1159-
if (options.exists("lockUnspents")) {
1160-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use lock_unspents");
1161-
}
1162-
if (options.exists("subtractFeeFromOutputs")) {
1163-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Use subtract_fee_from_outputs");
1164-
}
1170+
PreventOutdatedOptions(options);
11651171

11661172
const bool psbt_opt_in = options.exists("psbt") && options["psbt"].get_bool();
11671173

0 commit comments

Comments
 (0)