Skip to content

Commit 536ddeb

Browse files
committed
[rpc] Add change_type option to fundrawtransaction
1 parent 31dbd5a commit 536ddeb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,6 +3057,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
30573057
" {\n"
30583058
" \"changeAddress\" (string, optional, default pool address) The bitcoin address to receive the change\n"
30593059
" \"changePosition\" (numeric, optional, default random) The index of the change output\n"
3060+
" \"change_type\" (string, optional) The output type to use. Only valid if changeAddress is not specified. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is set by -changetype.\n"
30603061
" \"includeWatching\" (boolean, optional, default false) Also select inputs which are watch only\n"
30613062
" \"lockUnspents\" (boolean, optional, default false) Lock selected unspent outputs\n"
30623063
" \"feeRate\" (numeric, optional, default not set: makes wallet determine the fee) Set a specific fee rate in " + CURRENCY_UNIT + "/kB\n"
@@ -3122,6 +3123,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
31223123
{
31233124
{"changeAddress", UniValueType(UniValue::VSTR)},
31243125
{"changePosition", UniValueType(UniValue::VNUM)},
3126+
{"change_type", UniValueType(UniValue::VSTR)},
31253127
{"includeWatching", UniValueType(UniValue::VBOOL)},
31263128
{"lockUnspents", UniValueType(UniValue::VBOOL)},
31273129
{"reserveChangeKey", UniValueType(UniValue::VBOOL)}, // DEPRECATED (and ignored), should be removed in 0.16 or so.
@@ -3146,6 +3148,16 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
31463148
if (options.exists("changePosition"))
31473149
changePosition = options["changePosition"].get_int();
31483150

3151+
if (options.exists("change_type")) {
3152+
if (options.exists("changeAddress")) {
3153+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot specify both changeAddress and address_type options");
3154+
}
3155+
coinControl.change_type = ParseOutputType(options["change_type"].get_str(), coinControl.change_type);
3156+
if (coinControl.change_type == OUTPUT_TYPE_NONE) {
3157+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown change type '%s'", options["change_type"].get_str()));
3158+
}
3159+
}
3160+
31493161
if (options.exists("includeWatching"))
31503162
coinControl.fAllowWatchOnly = options["includeWatching"].get_bool();
31513163

0 commit comments

Comments
 (0)