Skip to content

Commit 2c2a144

Browse files
committed
[rpc] add snake case aliases for transaction methods
1 parent 1bc8d0f commit 2c2a144

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2956,12 +2956,17 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
29562956
{
29572957
{"add_inputs", UniValueType(UniValue::VBOOL)},
29582958
{"changeAddress", UniValueType(UniValue::VSTR)},
2959+
{"change_address", UniValueType(UniValue::VSTR)},
29592960
{"changePosition", UniValueType(UniValue::VNUM)},
2961+
{"change_position", UniValueType(UniValue::VNUM)},
29602962
{"change_type", UniValueType(UniValue::VSTR)},
29612963
{"includeWatching", UniValueType(UniValue::VBOOL)},
2964+
{"include_watching", UniValueType(UniValue::VBOOL)},
29622965
{"lockUnspents", UniValueType(UniValue::VBOOL)},
2966+
{"lock_unspents", UniValueType(UniValue::VBOOL)},
29632967
{"feeRate", UniValueType()}, // will be checked below
29642968
{"subtractFeeFromOutputs", UniValueType(UniValue::VARR)},
2969+
{"subtract_fee_from_outputs", UniValueType(UniValue::VARR)},
29652970
{"replaceable", UniValueType(UniValue::VBOOL)},
29662971
{"conf_target", UniValueType(UniValue::VNUM)},
29672972
{"estimate_mode", UniValueType(UniValue::VSTR)},
@@ -2972,22 +2977,24 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
29722977
coinControl.m_add_inputs = options["add_inputs"].get_bool();
29732978
}
29742979

2975-
if (options.exists("changeAddress")) {
2976-
CTxDestination dest = DecodeDestination(options["changeAddress"].get_str());
2980+
if (options.exists("changeAddress") || options.exists("change_address")) {
2981+
const std::string change_address_str = (options.exists("change_address") ? options["change_address"] : options["changeAddress"]).get_str();
2982+
CTxDestination dest = DecodeDestination(change_address_str);
29772983

29782984
if (!IsValidDestination(dest)) {
2979-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "changeAddress must be a valid bitcoin address");
2985+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Change address must be a valid bitcoin address");
29802986
}
29812987

29822988
coinControl.destChange = dest;
29832989
}
29842990

2985-
if (options.exists("changePosition"))
2986-
change_position = options["changePosition"].get_int();
2991+
if (options.exists("changePosition") || options.exists("change_position")) {
2992+
change_position = (options.exists("change_position") ? options["change_position"] : options["changePosition"]).get_int();
2993+
}
29872994

29882995
if (options.exists("change_type")) {
2989-
if (options.exists("changeAddress")) {
2990-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both changeAddress and address_type options");
2996+
if (options.exists("changeAddress") || options.exists("change_address")) {
2997+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both change address and address type options");
29912998
}
29922999
OutputType out_type;
29933000
if (!ParseOutputType(options["change_type"].get_str(), out_type)) {
@@ -2996,10 +3003,12 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
29963003
coinControl.m_change_type.emplace(out_type);
29973004
}
29983005

2999-
coinControl.fAllowWatchOnly = ParseIncludeWatchonly(options["includeWatching"], *pwallet);
3006+
const UniValue include_watching_option = options.exists("include_watching") ? options["include_watching"] : options["includeWatching"];
3007+
coinControl.fAllowWatchOnly = ParseIncludeWatchonly(include_watching_option, *pwallet);
30003008

3001-
if (options.exists("lockUnspents"))
3002-
lockUnspents = options["lockUnspents"].get_bool();
3009+
if (options.exists("lockUnspents") || options.exists("lock_unspents")) {
3010+
lockUnspents = (options.exists("lock_unspents") ? options["lock_unspents"] : options["lockUnspents"]).get_bool();
3011+
}
30033012

30043013
if (options.exists("feeRate"))
30053014
{
@@ -3013,8 +3022,8 @@ void FundTransaction(CWallet* const pwallet, CMutableTransaction& tx, CAmount& f
30133022
coinControl.fOverrideFeeRate = true;
30143023
}
30153024

3016-
if (options.exists("subtractFeeFromOutputs"))
3017-
subtractFeeFromOutputs = options["subtractFeeFromOutputs"].get_array();
3025+
if (options.exists("subtractFeeFromOutputs") || options.exists("subtract_fee_from_outputs") )
3026+
subtractFeeFromOutputs = (options.exists("subtract_fee_from_outputs") ? options["subtract_fee_from_outputs"] : options["subtractFeeFromOutputs"]).get_array();
30183027

30193028
if (options.exists("replaceable")) {
30203029
coinControl.m_signal_bip125_rbf = options["replaceable"].get_bool();

test/functional/rpc_fundrawtransaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_invalid_change_address(self):
224224
dec_tx = self.nodes[2].decoderawtransaction(rawtx)
225225
assert_equal(utx['txid'], dec_tx['vin'][0]['txid'])
226226

227-
assert_raises_rpc_error(-5, "changeAddress must be a valid bitcoin address", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':'foobar'})
227+
assert_raises_rpc_error(-5, "Change address must be a valid bitcoin address", self.nodes[2].fundrawtransaction, rawtx, {'changeAddress':'foobar'})
228228

229229
def test_valid_change_address(self):
230230
self.log.info("Test fundrawtxn with a provided change address")

0 commit comments

Comments
 (0)