Browse Source

Merge #12213: Add address type option to addmultisigaddress

f523c6bec [qa] Use address type in addmultisigaddress to avoid addwitnessaddress (João Barbosa)
886a92f25 [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
0.16
Jonas Schnelli 7 years ago
parent
commit
eadb2dacc3
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
  1. 18
      src/wallet/rpcwallet.cpp
  2. 2
      test/functional/nulldummy.py
  3. 5
      test/functional/segwit.py

18
src/wallet/rpcwallet.cpp

@ -1169,9 +1169,8 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
return NullUniValue; return NullUniValue;
} }
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3) if (request.fHelp || request.params.size() < 2 || request.params.size() > 4) {
{ std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" \"address_type\" )\n"
std::string msg = "addmultisigaddress nrequired [\"key\",...] ( \"account\" )\n"
"\nAdd a nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.\n" "\nAdd a nrequired-to-sign multisignature address to the wallet. Requires a new wallet backup.\n"
"Each key is a Bitcoin address or hex-encoded public key.\n" "Each key is a Bitcoin address or hex-encoded public key.\n"
"This functionality is only intended for use with non-watchonly addresses.\n" "This functionality is only intended for use with non-watchonly addresses.\n"
@ -1186,6 +1185,7 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
" ...,\n" " ...,\n"
" ]\n" " ]\n"
"3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n" "3. \"account\" (string, optional) DEPRECATED. An account to assign the addresses to.\n"
"4. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is set by -addresstype.\n"
"\nResult:\n" "\nResult:\n"
"{\n" "{\n"
@ -1224,10 +1224,18 @@ UniValue addmultisigaddress(const JSONRPCRequest& request)
} }
} }
OutputType output_type = g_address_type;
if (!request.params[3].isNull()) {
output_type = ParseOutputType(request.params[3].get_str(), output_type);
if (output_type == OUTPUT_TYPE_NONE) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[3].get_str()));
}
}
// Construct using pay-to-script-hash: // Construct using pay-to-script-hash:
CScript inner = CreateMultisigRedeemscript(required, pubkeys); CScript inner = CreateMultisigRedeemscript(required, pubkeys);
pwallet->AddCScript(inner); pwallet->AddCScript(inner);
CTxDestination dest = pwallet->AddAndGetDestinationForScript(inner, g_address_type); CTxDestination dest = pwallet->AddAndGetDestinationForScript(inner, output_type);
pwallet->SetAddressBook(dest, strAccount, "send"); pwallet->SetAddressBook(dest, strAccount, "send");
// Return old style interface // Return old style interface
@ -3519,7 +3527,7 @@ static const CRPCCommand commands[] =
{ "hidden", "resendwallettransactions", &resendwallettransactions, {} }, { "hidden", "resendwallettransactions", &resendwallettransactions, {} },
{ "wallet", "abandontransaction", &abandontransaction, {"txid"} }, { "wallet", "abandontransaction", &abandontransaction, {"txid"} },
{ "wallet", "abortrescan", &abortrescan, {} }, { "wallet", "abortrescan", &abortrescan, {} },
{ "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","account"} }, { "wallet", "addmultisigaddress", &addmultisigaddress, {"nrequired","keys","account","address_type"} },
{ "hidden", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} }, { "hidden", "addwitnessaddress", &addwitnessaddress, {"address","p2sh"} },
{ "wallet", "backupwallet", &backupwallet, {"destination"} }, { "wallet", "backupwallet", &backupwallet, {"destination"} },
{ "wallet", "bumpfee", &bumpfee, {"txid", "options"} }, { "wallet", "bumpfee", &bumpfee, {"txid", "options"} },

2
test/functional/nulldummy.py

@ -48,7 +48,7 @@ class NULLDUMMYTest(BitcoinTestFramework):
self.address = self.nodes[0].getnewaddress() self.address = self.nodes[0].getnewaddress()
self.ms_address = self.nodes[0].addmultisigaddress(1,[self.address])['address'] self.ms_address = self.nodes[0].addmultisigaddress(1,[self.address])['address']
self.wit_address = self.nodes[0].addwitnessaddress(self.address) self.wit_address = self.nodes[0].addwitnessaddress(self.address)
self.wit_ms_address = self.nodes[0].addwitnessaddress(self.ms_address) self.wit_ms_address = self.nodes[0].addmultisigaddress(1, [self.address], '', 'p2sh-segwit')['address']
network_thread_start() network_thread_start()
self.coinbase_blocks = self.nodes[0].generate(2) # Block 2 self.coinbase_blocks = self.nodes[0].generate(2) # Block 2

5
test/functional/segwit.py

@ -95,12 +95,11 @@ class SegWitTest(BitcoinTestFramework):
for i in range(3): for i in range(3):
newaddress = self.nodes[i].getnewaddress() newaddress = self.nodes[i].getnewaddress()
self.pubkey.append(self.nodes[i].validateaddress(newaddress)["pubkey"]) self.pubkey.append(self.nodes[i].validateaddress(newaddress)["pubkey"])
multiaddress = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]])['address']
multiscript = CScript([OP_1, hex_str_to_bytes(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG]) multiscript = CScript([OP_1, hex_str_to_bytes(self.pubkey[-1]), OP_1, OP_CHECKMULTISIG])
p2sh_addr = self.nodes[i].addwitnessaddress(newaddress) p2sh_addr = self.nodes[i].addwitnessaddress(newaddress)
bip173_addr = self.nodes[i].addwitnessaddress(newaddress, False) bip173_addr = self.nodes[i].addwitnessaddress(newaddress, False)
p2sh_ms_addr = self.nodes[i].addwitnessaddress(multiaddress) p2sh_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'p2sh-segwit')['address']
bip173_ms_addr = self.nodes[i].addwitnessaddress(multiaddress, False) bip173_ms_addr = self.nodes[i].addmultisigaddress(1, [self.pubkey[-1]], '', 'bech32')['address']
assert_equal(p2sh_addr, key_to_p2sh_p2wpkh(self.pubkey[-1])) assert_equal(p2sh_addr, key_to_p2sh_p2wpkh(self.pubkey[-1]))
assert_equal(bip173_addr, key_to_p2wpkh(self.pubkey[-1])) assert_equal(bip173_addr, key_to_p2wpkh(self.pubkey[-1]))
assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript)) assert_equal(p2sh_ms_addr, script_to_p2sh_p2wsh(multiscript))

Loading…
Cancel
Save