Skip to content

Commit b9024fd

Browse files
committed
segwit support for createmultisig RPC
1 parent d58055d commit b9024fd

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ libbitcoin_server_a_SOURCES = \
226226
net.cpp \
227227
net_processing.cpp \
228228
noui.cpp \
229+
outputtype.cpp \
229230
policy/fees.cpp \
230231
policy/policy.cpp \
231232
policy/rbf.cpp \
@@ -266,7 +267,6 @@ libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
266267
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
267268
libbitcoin_wallet_a_SOURCES = \
268269
interfaces/wallet.cpp \
269-
outputtype.cpp \
270270
wallet/crypter.cpp \
271271
wallet/db.cpp \
272272
wallet/feebumper.cpp \

src/rpc/misc.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <httpserver.h>
1313
#include <net.h>
1414
#include <netbase.h>
15+
#include <outputtype.h>
1516
#include <rpc/blockchain.h>
1617
#include <rpc/server.h>
1718
#include <rpc/util.h>
@@ -91,9 +92,9 @@ class CWallet;
9192

9293
static UniValue createmultisig(const JSONRPCRequest& request)
9394
{
94-
if (request.fHelp || request.params.size() < 2 || request.params.size() > 2)
95+
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
9596
{
96-
std::string msg = "createmultisig nrequired [\"key\",...]\n"
97+
std::string msg = "createmultisig nrequired [\"key\",...] ( \"address_type\" )\n"
9798
"\nCreates a multi-signature address with n signature of m keys required.\n"
9899
"It returns a json object with the address and redeemScript.\n"
99100
"\nArguments:\n"
@@ -103,6 +104,7 @@ static UniValue createmultisig(const JSONRPCRequest& request)
103104
" \"key\" (string) The hex-encoded public key\n"
104105
" ,...\n"
105106
" ]\n"
107+
"3. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is legacy.\n"
106108

107109
"\nResult:\n"
108110
"{\n"
@@ -133,12 +135,21 @@ static UniValue createmultisig(const JSONRPCRequest& request)
133135
}
134136
}
135137

138+
// Get the output type
139+
OutputType output_type = OutputType::LEGACY;
140+
if (!request.params[2].isNull()) {
141+
if (!ParseOutputType(request.params[2].get_str(), output_type)) {
142+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[2].get_str()));
143+
}
144+
}
145+
136146
// Construct using pay-to-script-hash:
137-
CScript inner = CreateMultisigRedeemscript(required, pubkeys);
138-
CScriptID innerID(inner);
147+
const CScript inner = CreateMultisigRedeemscript(required, pubkeys);
148+
CBasicKeyStore keystore;
149+
const CTxDestination dest = AddAndGetDestinationForScript(keystore, inner, output_type);
139150

140151
UniValue result(UniValue::VOBJ);
141-
result.pushKV("address", EncodeDestination(innerID));
152+
result.pushKV("address", EncodeDestination(dest));
142153
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
143154

144155
return result;

0 commit comments

Comments
 (0)