Skip to content

Commit eadb2da

Browse files
committed
Merge #12213: Add address type option to addmultisigaddress
f523c6b [qa] Use address type in addmultisigaddress to avoid addwitnessaddress (João Barbosa) 886a92f [rpc] Add address type option to addmultisigaddress (João Barbosa) Pull request description: Adds the option `address_type` to `addmultisigaddress` and `createmultisg` RPC. This also allows to avoid `addwitnessaddress` to obtain an `p2sh-segwit` or `bech32` multsig address. Related to #12210 as this reduces `addwitnessaddress` usage. Tree-SHA512: 8f8f85dfcff66bb6c7e1e9865e37c285dead1d6dadb9672a89b92fa209d03cc35817ca1d656588c6c2146b728daaf7540b851929b640294653c62836cbefe7ee
2 parents cc5870a + f523c6b commit eadb2da

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,8 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
11691169
return NullUniValue;
11701170
}
11711171

1172-
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
1173-
{
1174-
std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
1172+
if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) {
1173+
std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" \"address_type\" )\n"
11751174
"\nAdd a nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.\n"
11761175
"Each key is a Bitcoin address or hex-encoded public key.\n"
11771176
"This functionality is only intended for use with non-watchonly addresses.\n"
@@ -1186,6 +1185,7 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
11861185
" ...,\n"
11871186
" ]\n"
11881187
"3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n"
1188+
"4. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is set by -addresstype.\n"
11891189

11901190
"\nResult:\n"
11911191
"{\n"
@@ -1224,10 +1224,18 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
12241224
}
12251225
}
12261226

1227+
OutputType output_type = g_address_type;
1228+
if (!request.params[3].isNull()) {
1229+
output_type = ParseOutputType(request.params[3].get_str(), output_type);
1230+
if (output_type == OUTPUT_TYPE_NONE) {
1231+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[3].get_str()));
1232+
}
1233+
}
1234+
12271235
// Construct using pay-to-script-hash:
12281236
CScript inner = CreateMultisigRedeemscript(required, pubkeys);
12291237
pwallet->AddCScript(inner);
1230-
CTxDestination dest = pwallet->AddAndGetDestinationForScript(inner, g_address_type);
1238+
CTxDestination dest = pwallet->AddAndGetDestinationForScript(inner, output_type);
12311239
pwallet->SetAddressBook(dest, strAccount, "send");
12321240

12331241
// Return old style interface
@@ -3077,7 +3085,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
30773085
" for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n"
30783086
"3. iswitness (boolean, optional) Whether the transaction hex is a serialized witness transaction \n"
30793087
" If iswitness is not present, heuristic tests will be used in decoding\n"
3080-
3088+
30813089
"\nResult:\n"
30823090
"{\n"
30833091
" \"hex\": \"value\", (string) The resulting raw transaction (hex-encoded string)\n"
@@ -3519,7 +3527,7 @@ static const CRPCCommand commands[] =
35193527
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} },
35203528
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} },
35213529
{ "wallet", "abortrescan", &abortrescan, {} },
3522-
{ "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","account"} },
3530+
{ "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","account","address_type"} },
35233531
{ "hidden", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} },
35243532
{ "wallet", "backupwallet", &backupwallet, {"destination"} },
35253533
{ "wallet", "bumpfee", &bumpfee, {"txid", "options"} },

test/functional/nulldummy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def run_test(self):
4848
self.address = self.nodes[0].getnewaddress()
4949
self.ms_address = self.nodes[0].addmultisigaddress(1,[self.address])['address']
5050
self.wit_address = self.nodes[0].addwitnessaddress(self.address)
51-
self.wit_ms_address = self.nodes[0].addwitnessaddress(self.ms_address)
51+
self.wit_ms_address = self.nodes[0].addmultisigaddress(1, [self.address], '', 'p2sh-segwit')['address']
5252

5353
network_thread_start()
5454
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2

test/functional/segwit.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ def run_test(self):
9595
for i in range(3):
9696
newaddress = self.nodes[i].getnewaddress()
9797
self.pubkey.append(self.nodes[i].validateaddress(newaddress)["pubkey"])
98-
multiaddress = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]])['address']
9998
multiscript = CScript([OP_1, hex_str_to_bytes(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
10099
p2sh_addr = self.nodes[i].addwitnessaddress(newaddress)
101100
bip173_addr = self.nodes[i].addwitnessaddress(newaddress, False)
102-
p2sh_ms_addr = self.nodes[i].addwitnessaddress(multiaddress)
103-
bip173_ms_addr = self.nodes[i].addwitnessaddress(multiaddress, False)
101+
p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address']
102+
bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address']
104103
assert_equal(p2sh_addr, key_to_p2sh_p2wpkh(self.pubkey[-1]))
105104
assert_equal(bip173_addr, key_to_p2wpkh(self.pubkey[-1]))
106105
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))

0 commit comments

Comments
 (0)