12
12
#include < httpserver.h>
13
13
#include < net.h>
14
14
#include < netbase.h>
15
+ #include < outputtype.h>
15
16
#include < rpc/blockchain.h>
16
17
#include < rpc/server.h>
17
18
#include < rpc/util.h>
@@ -91,9 +92,9 @@ class CWallet;
91
92
92
93
static UniValue createmultisig (const JSONRPCRequest& request)
93
94
{
94
- if (request.fHelp || request.params .size () < 2 || request.params .size () > 2 )
95
+ if (request.fHelp || request.params .size () < 2 || request.params .size () > 3 )
95
96
{
96
- std::string msg = " createmultisig nrequired [\" key\" ,...]\n "
97
+ std::string msg = " createmultisig nrequired [\" key\" ,...] ( \" address_type \" ) \n "
97
98
" \n Creates a multi-signature address with n signature of m keys required.\n "
98
99
" It returns a json object with the address and redeemScript.\n "
99
100
" \n Arguments:\n "
@@ -103,6 +104,7 @@ static UniValue createmultisig(const JSONRPCRequest& request)
103
104
" \" key\" (string) The hex-encoded public key\n "
104
105
" ,...\n "
105
106
" ]\n "
107
+ " 3. \" address_type\" (string, optional) The address type to use. Options are \" legacy\" , \" p2sh-segwit\" , and \" bech32\" . Default is legacy.\n "
106
108
107
109
" \n Result:\n "
108
110
" {\n "
@@ -133,12 +135,21 @@ static UniValue createmultisig(const JSONRPCRequest& request)
133
135
}
134
136
}
135
137
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
+
136
146
// 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);
139
150
140
151
UniValue result (UniValue::VOBJ);
141
- result.pushKV (" address" , EncodeDestination (innerID ));
152
+ result.pushKV (" address" , EncodeDestination (dest ));
142
153
result.pushKV (" redeemScript" , HexStr (inner.begin (), inner.end ()));
143
154
144
155
return result;
0 commit comments