segwit support for createmultisig RPC
This commit is contained in:
parent
d58055d25f
commit
b9024fdda3
2 changed files with 17 additions and 6 deletions
|
@ -226,6 +226,7 @@ libbitcoin_server_a_SOURCES = \
|
||||||
net.cpp \
|
net.cpp \
|
||||||
net_processing.cpp \
|
net_processing.cpp \
|
||||||
noui.cpp \
|
noui.cpp \
|
||||||
|
outputtype.cpp \
|
||||||
policy/fees.cpp \
|
policy/fees.cpp \
|
||||||
policy/policy.cpp \
|
policy/policy.cpp \
|
||||||
policy/rbf.cpp \
|
policy/rbf.cpp \
|
||||||
|
@ -266,7 +267,6 @@ libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||||
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||||
libbitcoin_wallet_a_SOURCES = \
|
libbitcoin_wallet_a_SOURCES = \
|
||||||
interfaces/wallet.cpp \
|
interfaces/wallet.cpp \
|
||||||
outputtype.cpp \
|
|
||||||
wallet/crypter.cpp \
|
wallet/crypter.cpp \
|
||||||
wallet/db.cpp \
|
wallet/db.cpp \
|
||||||
wallet/feebumper.cpp \
|
wallet/feebumper.cpp \
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include <httpserver.h>
|
#include <httpserver.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
#include <netbase.h>
|
#include <netbase.h>
|
||||||
|
#include <outputtype.h>
|
||||||
#include <rpc/blockchain.h>
|
#include <rpc/blockchain.h>
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
|
@ -91,9 +92,9 @@ class CWallet;
|
||||||
|
|
||||||
static UniValue createmultisig(const JSONRPCRequest& request)
|
static UniValue createmultisig(const JSONRPCRequest& request)
|
||||||
{
|
{
|
||||||
if (request.fHelp || request.params.size() < 2 || request.params.size() > 2)
|
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3)
|
||||||
{
|
{
|
||||||
std::string msg = "createmultisig nrequired [\"key\",...]\n"
|
std::string msg = "createmultisig nrequired [\"key\",...] ( \"address_type\" )\n"
|
||||||
"\nCreates a multi-signature address with n signature of m keys required.\n"
|
"\nCreates a multi-signature address with n signature of m keys required.\n"
|
||||||
"It returns a json object with the address and redeemScript.\n"
|
"It returns a json object with the address and redeemScript.\n"
|
||||||
"\nArguments:\n"
|
"\nArguments:\n"
|
||||||
|
@ -103,6 +104,7 @@ static UniValue createmultisig(const JSONRPCRequest& request)
|
||||||
" \"key\" (string) The hex-encoded public key\n"
|
" \"key\" (string) The hex-encoded public key\n"
|
||||||
" ,...\n"
|
" ,...\n"
|
||||||
" ]\n"
|
" ]\n"
|
||||||
|
"3. \"address_type\" (string, optional) The address type to use. Options are \"legacy\", \"p2sh-segwit\", and \"bech32\". Default is legacy.\n"
|
||||||
|
|
||||||
"\nResult:\n"
|
"\nResult:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -133,12 +135,21 @@ static UniValue createmultisig(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the output type
|
||||||
|
OutputType output_type = OutputType::LEGACY;
|
||||||
|
if (!request.params[2].isNull()) {
|
||||||
|
if (!ParseOutputType(request.params[2].get_str(), output_type)) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Unknown address type '%s'", request.params[2].get_str()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Construct using pay-to-script-hash:
|
// Construct using pay-to-script-hash:
|
||||||
CScript inner = CreateMultisigRedeemscript(required, pubkeys);
|
const CScript inner = CreateMultisigRedeemscript(required, pubkeys);
|
||||||
CScriptID innerID(inner);
|
CBasicKeyStore keystore;
|
||||||
|
const CTxDestination dest = AddAndGetDestinationForScript(keystore, inner, output_type);
|
||||||
|
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.pushKV("address", EncodeDestination(innerID));
|
result.pushKV("address", EncodeDestination(dest));
|
||||||
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
|
result.pushKV("redeemScript", HexStr(inner.begin(), inner.end()));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue